<!--
  @description: 评标委员会-选择组长弹框
  @Modifier：yf
  @routerPath:
  @date：  2020-08-12 10:00:28
-->
<template>
  <el-dialog
    v-dialogDrag
    :visible.sync="leaderDialogData.dialog"
    :close-on-click-modal="false"
    :lock-scroll="false"
    :before-close="close"
    title="选择组长类型"
    width="600px"
    custom-class="el-dialog__body-p8 el-dialog_table"
  >
    <el-form
      ref="form"
      :model="formData"
      :rules="rules"
      :inline-message="true"
    >
      <table class="from_table">
        <tr>
          <td>
            <el-form-item label="组长类型" prop="expertType" />
          </td>
          <td>
            <el-checkbox-group v-model="formData.expertType">
              <el-checkbox label="01">
                商务组长
              </el-checkbox>
              <el-checkbox label="02">
                技术组长
              </el-checkbox>
            </el-checkbox-group>
          </td>
        </tr>
      </table>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submit">确认</el-button>
      <el-button @click="close">取消</el-button>
    </span>
  </el-dialog>
</template>

<script>
// api
import { appointProcurementExpertdrawOffOfLeader } from '@api/procurement/procurementEvaluation'
import { restoreInitialValue } from '@assets/js/utils'
export default {
  name: 'LeaveDialog',
  mixins: [],
  props: {
    leaderDialogData: {
      type: Object,
      default: function() {
        return {
          dialog: false, // false 关闭弹框  true 打开弹框
          expertId: '' // 专家id
        }
      }
    },
    getTenderBase: {
      type: Object,
      default: function() {
        return {}
      }
    }
  },
  data() {
    return {
      formData: {
        expertType: [] // 组长类型
      },
      rules: {
        expertType: [
          { required: true, message: '请选择', trigger: 'blur' }
        ] // 组长类型
      }
    }
  },
  watch: {
    // 弹框打开状态
    'leaderDialogData.dialog'(val) {
      if (!val) {
        // 清空 value
        restoreInitialValue(this.formData)
        // 清空校验
        this.$refs.form.clearValidate()
      }
    }
  },
  created() {
  },
  methods: {
    // 确认设定组长
    submit() {
      this.$refs.form.validate(valid => {
        if (valid) {
          // 商务组长技术组长排序
          if (this.formData.expertType.length === 2 && this.formData.expertType[0] !== '01') {
            this.formData.expertType.reverse()
          }
          const data = {
            packId: this.getTenderBase.packId,
            expertId: this.leaderDialogData.expertId,
            expertLeaderType: this.formData.expertType.toString()
          }
          appointProcurementExpertdrawOffOfLeader(data).then(res => {
            this.$message.success('设定组长成功')
            this.leaderDialogData.dialog = false
            this.$emit('reload')
          })
        }
      })
    },
    // 关闭弹框
    close() {
      this.leaderDialogData.dialog = false
    }
  }
}
</script>

<style scoped lang="less">
  /deep/.el-dialog__body-p8 .el-dialog__body{
    height: 10vh;
    overflow: auto;
    padding: 8px;
  }
</style>
