<template>
  <div class="purchase-contract-upload">
    <el-form
      ref="ruleFormRef"
      :model="ruleForm"
      :rules="rules"
      label-position="top"
      label-width="150px"
      class="rule-form-orange list-form"
    >
      <el-form-item label="采购合同" prop="contractFile">
        <span slot="label" class="required-label">采购合同</span>
        <cy-upload
          ref="contractFile"
          :upload-params="{
            fileType: 'contractFile'
          }"
          :file-data="ruleForm.contractFile"
          :upload-from-orange-status="true"
          placeholder="请上传已签署的采购合同"
          :file-type="'pdf'"
          :limit="1"
          :file-size="20"
        />
      </el-form-item>
      <el-form-item label="签署日期" prop="signDate" :rules="[{ required: true, message: `请输选择签署日期`, trigger: 'change' }]">
        <el-date-picker v-model="ruleForm.signDate" value-format="yyyy-MM-dd" type="date" placeholder="选择签署日期" style="width: 100%;" />
      </el-form-item>

    </el-form>
  </div>
</template>

<script>
export default {
  data() {
    return {
      // 合同上传
      ruleForm: {
        contractFile: [],
        signDate: ''
      },
      rules: {}
    }
  },
  methods: {
    async getParams() {
      var params = {
        Loading: true,
        signDate: this.ruleForm.signDate
      }
      return new Promise((resolve, reject) => {
        this.$refs.ruleFormRef.validate(valid => {
          if (valid) {
            const contractFiles = this.$refs.contractFile.getFileLists
            if (!contractFiles.length) {
              this.$message.warning('请上传采购合同')
              return
            } else {
              params.fileId = contractFiles.length ? contractFiles.map(item => item.id)[0] : null
            }

            return resolve(params)
          } else {
            reject()
            return false
          }
        })
      })
    }
  }
}

</script>

    <style lang="scss" scoped>
    </style>
