<template>
  <div class="contract-files">
    <cy-info-title>合同文件</cy-info-title>
    <el-form
      ref="ruleFormRef"
      :model="ruleForm"
      :rules="rules"
      label-position="top"
      label-width="150px"
      class="rule-form-orange"
    >
      <el-form-item
        label="销售合同文件"
        prop="salesContract"
        style="width: 100%;"
        class="form-required"
      >
        <cy-upload
          ref="fileStorage"
          :upload-params="{}"
          :file-data="ruleForm.salesContract"
          :upload-from-orange-status="true"
          placeholder="请上传销售合同文件"
          :disabled="true"
        />
      </el-form-item>
      <el-form-item
        label="采购合同文件"
        prop="purchContract"
        style="width: 100%;"
        class="form-required"
      >
        <cy-upload
          ref="fileStorage"
          :upload-params="{}"
          :file-data="ruleForm.purchContract"
          :upload-from-orange-status="true"
          placeholder="请上传采购合同文件"
          :disabled="true"
        />
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  props: {
    details: {
      type: Object,
      default: () => {}
    }
  },
  data() {
    return {
      ruleForm: {
        purchContract: [],
        salesContract: []
      },
      rules: {

      }
    }
  },
  watch: {
    details: {
      handler: function(newV) {
        if (newV && Object.keys(newV)) {
          const { purchContract, salesContract } = JSON.parse(JSON.stringify(newV))
          this.ruleForm.purchContract = purchContract
          this.ruleForm.salesContract = salesContract
        }
      },
      immediate: true,
      deep: true
    }
  },
  methods: {
    validate(submitType) {
      return new Promise((resolve, reject) => {
        if (submitType === 'submit') {
          this.$refs.ruleFormRef.validate(valid => {
            if (valid) {
              return resolve(this.ruleForm)
            } else {
              reject()
              return false
            }
          })
        } else {
          resolve(this.ruleForm)
        }
      })
    }
  }

}
</script>

  <style lang="scss" scoped>
  .contract-files {
  .el-form {
    padding: 10px 20px;
  }
  }
  </style>
