<template>
  <div class="basic-info">
    <el-form ref="ruleForm" :model="ruleForm" :rules="rules" label-position="top" label-width="150px" class="rule-form-orange">
      <el-form-item label="项目名称">
        <el-input v-model="detailInfo.projectInformation.projectName" placeholder="请输入项目名称" disabled />
      </el-form-item>
      <el-form-item label="核心企业名称">
        <el-input v-model="detailInfo.coreEnterprise.corporateName" placeholder="请输入核心企业名称" disabled />
      </el-form-item>
      <el-form-item label="供应商（主体）名称">
        <el-input v-model="detailInfo.supplierEnterprise.corporateName" placeholder="请输入供应商（主体）名称" disabled />
      </el-form-item>
      <el-form-item label="业务编号">
        <el-input v-model="detailInfo.projectInformation.businessNumber" placeholder="请输入项目名称" disabled />
      </el-form-item>
      <el-form-item label="申请理由" prop="reason" class="two-form-item">
        <el-input v-model="ruleForm.reason" type="textarea" autosize placeholder="请输入申请理由" :disabled="isView" />
      </el-form-item>
      <el-form-item label="调整类型" :prop="ruleForm.adjustType == 'reviewAndAdjustmentTypes_H' ? 'adjustTypeDetail' : 'adjustType'" class="select-input-item">
        <el-select v-model="ruleForm.adjustType" placeholder="请选择调整类型" style="width: 100%;" :disabled="isView">
          <el-option v-for="item in typeList" :key="item.code" :label="item.name" :value="item.code" />
        </el-select>
        <el-input v-model="ruleForm.adjustTypeDetail" v-show="ruleForm.adjustType == 'reviewAndAdjustmentTypes_H'" placeholder="请输入调整类型" :disabled="isView" />
      </el-form-item>
      <el-form-item label="附件" prop="files" style="width: calc(66% - 15px);">
        <cy-upload
          ref="fileStorage"
          :upload-params="{ fileType: 'reconsiderAdjustFile' }"
          :file-data="ruleForm.files"
          :upload-from-orange-status="true"
          placeholder="请上传附件"
          :disabled="isView"
        />
      </el-form-item>
      <el-form-item label="备注" prop="remark" style="width: 100%">
        <el-input v-model="ruleForm.remark" type="textarea" rows="3" placeholder="请输入备注" :disabled="isView" />
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import request from '@/utils/request'
export default {
  data() {
    return {
      ruleForm: {
        reason: '',
        adjustType: '',
        adjustTypeDetail: '',
        remark: '',
        files: []
      },
      rules: {
        reason: [
          {required: true, trigger: 'blur', message: '请输入申请理由'}
        ],
        adjustType: [
          {required: true, trigger: 'change', message: '请选择调整类型'}
        ],
        adjustTypeDetail: [
          {required: true, trigger: 'blur', message: '请输入调整类型'}
        ]
      },
      detailInfo: {
        projectInformation: {},
        coreEnterprise: {},
        supplierEnterprise: {}
      },
      typeList: []
    }
  },
  props: ["info", "isView"],
  mounted() {
    this.getTypeList()
  },
  methods: {
    getTypeList() {
      request({
        url: '/dictionary/do_findByParentCode',
        method: 'get',
        params: { parentCode: 'reviewAndAdjustmentTypes' }
      }).then(({ data }) => {
        this.typeList = data || []
      })
    },
    confirm() {
      return new Promise((resolve, reject) => {
        this.$refs.ruleForm.validate(flag => {
          if(flag) {
            let data = { ...this.ruleForm }
            data.creditResolutionId = this.$route.params.infoId
            data.taskId = this.$route.params.taskId
            data.files = this.$refs.fileStorage.getFileLists.map(item => item.id)
            resolve(data)
          } else {
            reject()
          }
        })
      })
    }
  },
  watch: {
    'info.id': {
      handler: function(val) {
        if(val) {
          Object.keys(this.ruleForm).forEach(key => {
            if(this.info[key] || this.info[key] === 0) {
              this.ruleForm[key] = this.info[key]
            }
          })
          this.ruleForm.files = this.info.fileStorages || []
          this.detailInfo = { ...this.info }
        }
      },
      immediate: true
    }
  }
}
</script>

<style lang="scss" scoped>

.select-input-item {
  position: relative;
  .el-input {
    width: 90%;
    position: absolute;
    top: 0;
    left: 0;
  }
 }

</style>
