<template>
  <div class="due-distribution-content">
    <cy-info-title>尽调分配</cy-info-title>
    <el-form ref="ruleForm" :model="ruleForm" :rules="rules" label-position="top" label-width="120px" class="rule-form-orange">
      <el-form-item label="供应商名称" prop="name" class="one-form-item">
        <el-input v-model="ruleForm.name" placeholder="请输入供应商名称" :disabled="disabled" />
      </el-form-item>
      <el-form-item label="统一社会信用代码" prop="socialCreditCode" class="one-form-item">
        <el-input v-model="ruleForm.socialCreditCode" placeholder="请输入统一社会信用代码" :disabled="disabled" />
      </el-form-item>
      <el-form-item label="风险经理" prop="riskManagerId" class="one-form-item">
        <el-select v-model="ruleForm.riskManagerId" placeholder="请选择风险经理" :disabled="disabled">
          <el-option
            v-for="item in constant.roleUserList"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="分配日期" prop="assignDate" class="one-form-item">
        <el-date-picker
          v-model="ruleForm.assignDate"
          type="date"
          placeholder="选择日期"
          :disabled="disabled"
          value-format="yyyy-MM-dd"
        >
        </el-date-picker>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
export default {
  props: {
    disabled: {
      type: Boolean,
      default: false
    },
    detailsInfo: {
      type: Object,
      default: () => {}
    }
  },
  data() {
    return {
      ruleForm: {
        name: '',
        socialCreditCode: '',
        riskManagerId: '',
        assignDate: new Date()
      },
      rules: {
        riskManagerId: [
          { required: true, message: '请选择风控经理', trigger: 'change' }
        ]
      }
    }
  },
  computed: {
    ...mapGetters(['constant'])
  },
  watch: {
    detailsInfo: {
      handler(newV) {
        if (newV && Object.keys(newV)) {
          const { name, socialCreditCode, riskManagerId, assignDate, cSupplierInfoId } = newV
          this.ruleForm = {
            cSupplierInfoId,
            name,
            socialCreditCode,
            riskManagerId: riskManagerId || '',
            assignDate: assignDate || new Date()
          }
        }
      },
      immediate: true,
      deep: true
    }
  },
  created() {
    this.$store.dispatch('getConstant', [{ query: '风控经理', type: 'roleUserList' }])
  },
  methods: {
    validate() {
      return new Promise((resolve, reject) => {
        this.$refs.ruleForm.validate((valid) => {
          if (valid) {
            resolve(this.ruleForm)
          } else {
            reject()
            return false
          }
        })
      })
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
