<template>
  <div class="create-bidding-content">
    <cy-info-title>基础信息</cy-info-title>
    <basic-information ref="basicInformation" :basic-information="basicInformation" :disabled="disabled" />
    <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>合同模板</cy-info-title>
      <el-form-item
        label="合同模板"
        prop="desc"
        class="form-required"
      >
        <cy-upload
          ref="salesContractManagementFile"
          :upload-params="{
            fileType: 'salesContractManagementFile'
          }"
          :file-data="ruleForm.salesContractManagementFile"
          :upload-from-orange-status="true"
          placeholder="请上传销售合同模板"
          :disabled="disabled"
        />
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  components: {
    BasicInformation: () => import('../../components/BasicInformation.vue')
  },
  props: {
    disabled: {
      type: Boolean,
      default: false
    },
    salesContract: {
      type: Object,
      default: () => {}
    }
  },
  data() {
    return {
      ruleForm: {
        id: '',
        salesContractManagementFile: []
      },
      uploadParams: {},
      rules: {
        name: [{ required: true, message: '请输入公司名称', trigger: 'change' }]
      },
      basicInformation: {}
    }
  },
  watch: {
    salesContract: {
      handler(newV) {
        if (Object.keys(newV).length) {
          const { id, files, projectName, enterprise, mainEnterprise, platform, businessNumber } = JSON.parse(JSON.stringify(newV))
          this.ruleForm = {
            id,
            salesContractManagementFile: files || []
          }
          this.basicInformation = {
            projectName,
            enterprise,
            mainEnterprise,
            platform,
            businessNumber
          }
        }
      },
      immediate: true,
      deep: true
    }
  },
  methods: {
    getParams() {
      return new Promise((resolve, reject) => {
        const salesContractManagementList = this.$refs.salesContractManagementFile.getFileLists
        if (!salesContractManagementList.length) {
          this.$message.warning('请选择合同模板')
          return
        }
        this.$refs.basicInformation.getParams().then((data) => {
          const params = {
            ...data,
            id: this.ruleForm.id,
            fileIds: salesContractManagementList.map(item => item.id)
          }
          resolve(params)
        })
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.create-bidding {

}
</style>
