<template>
  <div class="successful-bidder-confirm-content">
    <el-form ref="ruleForm" :key="key" :model="ruleForm" :rules="rules" label-width="150px" label-position="top" class="rule-form-orange">
      <cy-info-title>中标信息</cy-info-title>
      <el-form-item label="是否中标" prop="winTheBidding">
        <el-radio-group v-model="ruleForm.winTheBidding" :disabled="disabled">
          <el-radio :label="1">是</el-radio>
          <el-radio :label="0">否</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item
        v-if="ruleForm.winTheBidding === 1"
        label="中标通知书："
        prop="desc"
        style="width: 100%;"
        class="form-required"
      >
        <cy-upload
          ref="biddingAwardNotificationFiles"
          :upload-params="{
            mouldName: 'biddingAwardNotificationFiles'
          }"
          :file-data="ruleForm.biddingAwardNotificationFiles"
          :upload-from-orange-status="true"
          placeholder="请上传中标通知书"
          :disabled="disabled"
        />
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
module.exports = {
  props: {
    disabled: {
      type: Boolean,
      default: false
    },
    deatailsInfo: {
      type: Object,
      default: () => {}
    }
  },
  data() {
    return {
      key: 0,
      uploadParams: {},
      ruleForm: {
        winTheBidding: '',
        biddingAwardNotificationFiles: []
      },
      rules: {
        winTheBidding: [
          { required: true, message: '请选择是否中标', trigger: 'change' }
        ]
      }
    }
  },
  watch: {
    deatailsInfo: {
      handler(newV) {
        const { winTheBidding, awardNotificationFiles } = JSON.parse(JSON.stringify(newV))
        this.ruleForm.winTheBidding = winTheBidding
        this.ruleForm.biddingAwardNotificationFiles = awardNotificationFiles || []
      },
      immediate: true,
      deep: true
    }
  },
  methods: {
    getParams() {
      return new Promise((resolve, reject) => {
        this.$refs.ruleForm.validate(valid => {
          if (valid) {
            const { id, taskId } = this.$route.query
            const params = {
              winTheBidding: this.ruleForm.winTheBidding,
              biddingBasicInfoId: id,
              taskId
            }
            if (this.ruleForm.winTheBidding === 1) {
              const biddingAwardNotificationList = this.$refs.biddingAwardNotificationFiles.getFileLists
              if (!biddingAwardNotificationList.length) {
                this.$message.warning('请上传中标通知书')
                return
              }
              params.awardNotificationFileIds = biddingAwardNotificationList.map(item => item.id)
            }
            resolve(params)
          } else {
            reject()
          }
        })
      })
    }
  }
}
</script>

<style  scoped>

</style>
