<!--
  @description: 检测认证-职业资格人员信息-录入资格信息
  @Modifier: 张慢慢
  @routerPath:/testAndCertify/professionalQualificationAdd
  @date: 2020/12/05
-->
<template>
  <div>
    <section class="title p0-16 clearfix">
      <template>
        <div class="title-back pointer" @click="back">
          <i class="iconfont icon-fanhui mr10" />录入职业资格信息
        </div>
      </template>
    </section>
    <section class="p0-16">
      <el-form
        ref="fromData"
        :rules="rules"
        :inline-message="true"
        :model="formData"
      >
        <table class="from_table">
          <tr>
            <td>
              <el-form-item label="姓名" prop="rewardPunishmentPersonName" />
            </td>
            <td>
              <gx-input
                v-model="formData.rewardPunishmentPersonName"
                gx-maxlength="varchar200"
                placeholder="姓名"
              />
            </td>
            <td>
              <el-form-item label="出生日期" prop="rewardPunishmentPersonName" />
            </td>
            <td>
              <gx-input
                v-model="formData.rewardPunishmentPersonName"
                gx-maxlength="varchar200"
                placeholder="出生日期"
              />
            </td>
          </tr>
          <tr>
            <td>
              <el-form-item label="性别" prop="rewardPunishmentCodeType" />
            </td>
            <td>
              <el-select v-model="formData.rewardPunishmentStatus" style="width: 100%;" placeholder="请选择">
                <el-option
                  label="男"
                  value="1"
                />
                <el-option
                  label="女"
                  value="2"
                />
              </el-select>
            </td>
            <td>
              <el-form-item label="最高学历" prop="rewardPunishmentCode" />
            </td>
            <td>
              <gx-input
                v-model="formData.rewardPunishmentCode"
                gx-maxlength="varchar200"
                placeholder="最高学历"
              />
            </td>
          </tr>
          <tr>
            <td>
              <el-form-item label="联系电话" prop="rewardPunishmentAddress" />
            </td>
            <td>
              <gx-input
                v-model="formData.rewardPunishmentAddress"
                gx-maxlength="varchar200"
                placeholder="联系电话"
              />
            </td>
            <td>
              <el-form-item label="所在行政区域" prop="rewardPunishmentDepartPhone" />
            </td>
            <td>
              <gx-input
                v-model="formData.rewardPunishmentDepartPhone"
                gx-maxlength="varchar200"
                placeholder="所在行政区域"
              />
            </td>
          </tr>
          <tr>
            <td>
              <el-form-item label="身份证号码" prop="rewardPunishmentStatus" />
            </td>
            <td>
              <gx-input
                v-model="formData.rewardPunishmentInstruction"
                gx-maxlength="varchar200"
                placeholder="身份证号码"
              />
            </td>
            <td>
              <el-form-item label="工作年限" prop="rewardPunishmentInstruction" />
            </td>
            <td>
              <gx-input
                v-model="formData.rewardPunishmentInstruction"
                gx-maxlength="varchar200"
                placeholder="工作年限"
              />
            </td>
          </tr>
          <tr>
            <td>
              <el-form-item label="通讯地址" prop="rewardPunishmentStatus" />
            </td>
            <td>
              <gx-input
                v-model="formData.rewardPunishmentInstruction"
                gx-maxlength="varchar200"
                placeholder="通讯地址"
              />
            </td>
            <td>
              <el-form-item label="邮政编码" prop="rewardPunishmentInstruction" />
            </td>
            <td>
              <gx-input
                v-model="formData.rewardPunishmentInstruction"
                gx-maxlength="varchar200"
                placeholder="邮政编码"
              />
            </td>
          </tr>
          <tr>
            <td>
              <el-form-item label="通讯地址" prop="rewardPunishmentStatus" />
            </td>
            <td>
              <gx-input
                v-model="formData.rewardPunishmentInstruction"
                gx-maxlength="varchar200"
                placeholder="通讯地址"
              />
            </td>
            <td>
              <el-form-item label="邮政编码" prop="rewardPunishmentInstruction" />
            </td>
            <td>
              <gx-input
                v-model="formData.rewardPunishmentInstruction"
                gx-maxlength="varchar200"
                placeholder="邮政编码"
              />
            </td>
          </tr>
          <tr>
            <td>
              <el-form-item label="所在单位代码" prop="rewardPunishmentStatus" />
            </td>
            <td>
              <gx-input
                v-model="formData.rewardPunishmentInstruction"
                gx-maxlength="varchar200"
                placeholder="所在单位代码"
              />
            </td>
            <td>
              <el-form-item label="所在单位名称" prop="rewardPunishmentInstruction" />
            </td>
            <td>
              <gx-input
                v-model="formData.rewardPunishmentInstruction"
                gx-maxlength="varchar200"
                placeholder="所在单位名称"
              />
            </td>
          </tr>
          <tr>
            <td>
              <el-form-item label="是否在职" prop="rewardPunishmentStatus" />
            </td>
            <td>
              <gx-input
                v-model="formData.rewardPunishmentInstruction"
                gx-maxlength="varchar200"
                placeholder="是否在职"
              />
            </td>
            <td>
              <el-form-item label="职务" prop="rewardPunishmentInstruction" />
            </td>
            <td>
              <gx-input
                v-model="formData.rewardPunishmentInstruction"
                gx-maxlength="varchar200"
                placeholder="职务"
              />
            </td>
          </tr>
          <tr>
            <td>
              <el-form-item label="技术职称" prop="rewardPunishmentStatus" />
            </td>
            <td>
              <gx-input
                v-model="formData.rewardPunishmentInstruction"
                gx-maxlength="varchar200"
                placeholder="技术职称"
              />
            </td>
            <td>
              <el-form-item label="从业经历" prop="rewardPunishmentInstruction" />
            </td>
            <td>
              <gx-input
                v-model="formData.rewardPunishmentInstruction"
                gx-maxlength="varchar200"
                placeholder="从业经历"
              />
            </td>
          </tr>
        </table>
      </el-form>
    </section>
    <!--保存按钮-->
    <div class="but_footer">
      <div class="but_footer-h" />
      <div class="but_footer-but">
        <el-button :loading="confirmLoading" @click="submit('00')">
          保存
        </el-button>
        <el-button @click="back">
          返回
        </el-button>
      </div>
    </div>
  </div>
</template>

<script>
/* 接口*/
import {
  addRewardPunishment, // 新增
  getRewardPunishmentListById, // 获取详情
  updateRewardPunishment // 修改
} from '@/api/bidding/bidCalibration'
/* 公用方法*/
import { validateInput, phone, characters1_auto } from '@/assets/js/validate'// 校验输入内容
/* 组件*/
/* 组件*/
import { randomData } from '@/assets/js/utils' // 随机生成id
/* 组件*/
import { getTime } from '@api/common/tools.js' // 获取服务器时间
export default {
  name: 'ClarificationAdd',
  components: {
  },
  data() {
    return {
      confirmLoading: false,
      options: [{
        value: '00',
        label: '奖励'
      }, {
        value: '01',
        label: '惩罚'
      }],
      /* 字典信息-end */
      formData: {
        id: '', // 主键Id
        rewardPunishmentStatus: '', // 奖惩类型状态
        rewardPunishmentCodeType: '', // 中标人代码类型
        rewardPunishmentBiderName: '', // 中标人名称
        rewardPunishmentPersonName: '', // 法人代表
        rewardPunishmentCode: '', // 中标人代码
        rewardPunishmentAddress: '', // 中标人联系地址
        rewardPunishmentDepartPhone: '', // 机构联系电话
        rewardPunishmentInstruction: '', // 奖惩说明
        rewardPunishmentDate: '' // 最后登录时间结束
      },
      // 校验
      rules: {
        rewardPunishmentBiderName: [{ required: true, validator: characters1_auto, trigger: 'change' }], // 中标人名称
        rewardPunishmentPersonName: [{ required: true, validator: validateInput, trigger: 'blur' }], // 法人代表
        rewardPunishmentCodeType: [{ required: true, validator: validateInput, trigger: 'blur' }], // 中标人代码类型
        rewardPunishmentCode: [{ required: true, validator: validateInput, trigger: 'blur' }], // 中标人代码
        rewardPunishmentAddress: [{ required: true, validator: validateInput, trigger: 'blur' }], // 中标人联系地址
        rewardPunishmentDepartPhone: [{ required: true, validator: phone, trigger: 'blur' }], // 机构联系电话
        rewardPunishmentStatus: [{ required: true, message: '请选择', trigger: 'change' }], // 奖惩类型
        rewardPunishmentInstruction: [{ required: true, validator: validateInput, trigger: 'blur' }] // 奖惩说明
      }
    }
  },
  created() {
    this.init()
  },
  methods: {
    // 初始化
    init() {
      // 获取系统时间
      this.getNowTimes()
      if (this.$route.params.id) {
        this.queryRepresentInfo(this.$route.params.id)
      } else {
        this.formData.id = randomData()// 随机生成Id
      }
    },
    getNowTimes() {
      // 调用获取当前时间异步方法
      getTime().then((res) => {
        this.nowTimes = res.data.time
        this.formData.rewardPunishmentDate = this.$Moment(this.nowTimes).format(this.momentDate)
      })
    },
    // 获取详情
    queryRepresentInfo(id) {
      getRewardPunishmentListById(id).then(res => {
        this.formData = res.data
      }).catch(() => {

      })
    },
    // 返回
    back() {
      this.$router.push({
        path: '/testAndCertify/professionalQualificationList'
      })
    },
    // 中标人名称-打开弹框
    rewardPunishmentBiderNameOpen() {
      this.$refs.rewardPunishmentBiderName.open()
    },
    // 中标人名称数据操作
    rewardPunishmentBiderNameChange(data) {
      if (data === 'clear') { // 清空
        this.formData.rewardPunishmentBiderName = ''// 中标人名称
      } else { // 选择
        this.formData.rewardPunishmentBiderName = data.code// 中标人名称
        // this.formData.rewardPunishmentPersonName = data.Name
        // this.formData.rewardPunishmentAddress = data.Address
        // this.formData.rewardPunishmentDepartPhone = data.Phone
      }
    },
    /*
    * 保存接口
    * type 01 生效 00 保存
    * */
    saveData(type) {
      this.getNowTimes()
      this.confirmLoading = true// btnLoding
      // 判断项目id是否存在 不存在走新增 存在走修改
      if (!this.$route.params.id) {
        this.addRewardPunishment(type)
      } else {
        this.updateRewardPunishment(type)
      }
    },
    // 新增
    addRewardPunishment(type) {
      addRewardPunishment(this.formData).then(response => {
        this.$message.success('操作成功')
        this.confirmLoading = false// btnLoding
        // 生效
        if (type === '01') {
        // 生效成功后返回列表
          this.back()
        }
      }).catch(() => {
        this.confirmLoading = false// btnLoding
      })
    },
    // 修改
    updateRewardPunishment(type) {
      updateRewardPunishment(this.formData).then(response => {
        this.$message.success('操作成功')
        this.confirmLoading = false// btnLoding
        // 生效
        if (type === '01') {
          // 生效成功后返回列表
          this.back()
        }
      }).catch(() => {
        this.confirmLoading = false// btnLoding
      })
    },
    // 提交
    submit() {
      this.$refs.fromData.validate((valid, field) => {
        if (valid) { // 校验通过
          this.$confirm('确定生效吗?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            confirmButtonClass: 'confirmBtn',
            cancelButtonClass: 'cancelBtn',
            type: 'warning'
          }).then(() => {
            this.saveData('01')
          })
        }
      })
    }
  }
}
</script>

<style scoped lang="less">

</style>
