<template>
  <div class="change-create-sales-contract-content">
    <cy-info-title>基础信息</cy-info-title>
    <basic-information :basic-information="basicInformation" :business-name="businessName" />
    <personnel-information v-if="basicInformation.changeType" ref="personnelInformation" :person-info="personInfo" :personnel-disabled="personnelDisabled" />
    <el-form
      ref="ruleFormRef"
      :model="ruleForm"
      :rules="rules"
      label-position="top"
      label-width="150px"
      class="rule-form-orange"
      style="margin-top: 20px"
    >
      <cy-info-title v-if="basicInformation.changeType === 0">合同模板</cy-info-title>
      <el-form-item
        v-if="basicInformation.changeType === 0"
        label="合同模板"
        prop="desc"
        class="form-required"
      >
        <cy-upload
          ref="salesSupplementContractTemplateFile"
          :upload-params="{
            fileType: 'salesSupplementContractTemplateFile'
          }"
          :file-data="ruleForm.salesSupplementContractTemplateFile"
          :upload-from-orange-status="true"
          placeholder="请上传销售合同模板"
          :disabled="disabled"
        />
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
// import { salesContractChangeAdd } from '@/api/myTrade/salesContractManagement/salesContractManagement'
export default {
  components: {
    BasicInformation: () => import('./BasicInformation.vue'),
    PersonnelInformation: () => import('./PersonnelInformation.vue')
  },
  props: {
    disabled: {
      type: Boolean,
      default: false
    },
    changeCreate: {
      type: Object,
      default: () => {}
    }
  },
  data() {
    return {
      ruleForm: {
        detailsId: '',
        salesSupplementContractTemplateFile: []
      },
      uploadParams: {},
      rules: {
        name: [{ required: true, message: '请输入公司名称', trigger: 'change' }]
      },
      basicInformation: {},
      personInfo: [],
      changeType: '',
      personnelDisabled: false,
      businessName: ''
    }
  },
  watch: {
    changeCreate: {
      handler(newV) {
        if (Object.keys(newV).length) {
          const { salesContractBasicVo, changeType, fileStorageList, personInfoHistoryList } = JSON.parse(JSON.stringify(newV))
          this.basicInformation = {
            projectName: salesContractBasicVo.projectName,
            enterprise: salesContractBasicVo.enterprise,
            mainEnterprise: salesContractBasicVo.mainEnterprise,
            businessNumber: salesContractBasicVo.businessNumber,
            platform: salesContractBasicVo.platform,
            changeType
          }
          this.personInfo = personInfoHistoryList
          this.ruleForm.salesSupplementContractTemplateFile = fileStorageList || []
          // this.ruleForm.approvalComments = approvalComments
          this.personnelDisabled = true
          this.businessName = '变更合同创建'
        }
      },
      immediate: true,
      deep: true
    }
  },
  created() {
    // this.salesContractChangeAdd()
  },
  methods: {
    // getParams() {
    //   return new Promise((resolve, reject) => {
    //     this.$refs.ruleFormRef.validate(valid => {
    //       if (valid) {
    //         const { detailsId } = this.ruleForm
    //         const { id } = this.$route.query
    //         if (this.changeType === 0) {
    //           const salesSupplementContractTemplateList = this.$refs.salesSupplementContractTemplateFile.getFileLists
    //           if (!salesSupplementContractTemplateList.length) {
    //             this.$message.warning('请上传合同模板')
    //             return
    //           }
    //           const params = {
    //             id: detailsId === 0 ? null : detailsId,
    //             cSalesContractManagementId: id,
    //             changeType: this.changeType,
    //             fileIds: salesSupplementContractTemplateList.map(item => item.id)
    //           }
    //           resolve(params)
    //         }
    //         if (this.changeType === 1) {
    //           this.$refs.personnelInformation.getParams().then(data => {
    //             const params = {
    //               id: detailsId === 0 ? null : detailsId,
    //               cSalesContractManagementId: id,
    //               changeType: this.changeType,
    //               supplementPersonInfos: data.supplementPersonInfos
    //             }
    //             resolve(params)
    //           })
    //         }
    //       } else {
    //         reject()
    //         return false
    //       }
    //     })
    //   })
    // }
  }
}
</script>

<style lang="scss" scoped>
.change-create-sales-contract-content {

}
</style>
