<!--
  @description:集约化评标计划—集约化评标分组信息编辑/查看
  @Modifier: 肖文龙
  @routerPath:
  @date: 2020年3月16日14:27:31
-->
<template>
  <div>
    <div>
      <el-form ref="formData" :model="formData" :rules="rules">
        <table class="tableData">
          <tr>
            <td>批次号</td>
            <td>{{ formData.batchNumber }}</td>
            <td>分组名称</td>
            <td>{{ formData.groupName }}</td>
          </tr>
          <tr>
            <td>评标计划数量</td>
            <td>{{ formData.schemeNumber }}</td>
            <td>一部开评标计划数量</td>
            <td>{{ formData.deptOneNumber }}</td>
          </tr>
          <tr>
            <td>二部开评标计划数量</td>
            <td>{{ formData.deptTwoNumber }}</td>
            <td>
              三部开评标计划数量
            </td>
            <td>{{ formData.deptThreeNumber }}</td>
          </tr>
          <tr>
            <td>项目单位个数</td>
            <td>{{ formData.projectDepartNumber }}</td>
            <td>
              <span v-if="isEdit&&functionType=='00'" class="red-star">*</span>
              评委会是否分组
            </td>
            <td>
              <el-form-item v-if="isEdit&&functionType=='00'" ref="judgesGroupedStatus" prop="judgesGroupedStatus">
                <el-radio-group v-model="formData.judgesGroupedStatus">
                  <el-radio v-for="(item,index) in judgingPanelTypeList" :key="index" :label="item.typecode">
                    {{ item.typename }}
                  </el-radio>
                </el-radio-group>
              </el-form-item>
              <span v-else>
                <span v-for="(item,index) in judgingPanelTypeList" v-if="formData.judgesGroupedStatus===item.typecode" :key="index">
                  {{ item.typename }}
                </span>
              </span>
            </td>
          </tr>
          <!--
          评委会是否分组 01 分组
          -->
          <template v-if="formData.judgesGroupedStatus==='01'">
            <tr>
              <td>
                <span v-if="isEdit&&functionType=='00'" class="red-star">*</span>
                技术组数
              </td>
              <td>
                <el-form-item v-if="isEdit&&functionType=='00'" ref="technicalGroupsNumber" prop="technicalGroupsNumber">
                  <el-input
                    v-model="formData.technicalGroupsNumber"
                    oninput="value=value.replace(/[^\d]/g,'')"
                    maxlength="15"
                    placeholder="技术组数"
                  />
                </el-form-item>
                <span v-else>{{ formData.technicalGroupsNumber }}</span>
              </td>
              <td>
                <span v-if="isEdit&&functionType=='00'" class="red-star">*</span>
                技术抽取专家人数
              </td>
              <td>
                <el-form-item v-if="isEdit&&functionType=='00'" ref="technicalExpertsSelectedNumber" prop="technicalExpertsSelectedNumber">
                  <el-input
                    v-model="formData.technicalExpertsSelectedNumber"
                    oninput="value=value.replace(/[^\d]/g,'')"
                    maxlength="20"
                    style="width:200px"
                    placeholder="技术抽取专家人数"
                  />
                </el-form-item>
                <span v-else>{{ formData.technicalExpertsSelectedNumber }}</span>
              </td>
            </tr>
            <tr>
              <td>
                <span v-if="isEdit&&functionType=='00'" class="red-star">*</span>
                商务组数
              </td>
              <td>
                <el-form-item v-if="isEdit&&functionType=='00'" ref="businessGroupNumber" prop="businessGroupNumber">
                  <el-input
                    v-model="formData.businessGroupNumber"
                    oninput="value=value.replace(/[^\d]/g,'')"
                    maxlength="15"
                    placeholder="商务组数"
                  />
                </el-form-item>
                <span v-else>{{ formData.businessGroupNumber }}</span>
              </td>
              <td>
                <span v-if="isEdit&&functionType=='00'" class="red-star">*</span>
                商务抽取专家人数
              </td>
              <td>
                <el-form-item v-if="isEdit&&functionType=='00'" ref="businessExpertsSelectedNumber" prop="businessExpertsSelectedNumber">
                  <el-input
                    v-model="formData.businessExpertsSelectedNumber"
                    oninput="value=value.replace(/[^\d]/g,'')"
                    maxlength="20"
                    style="width:200px"
                    placeholder="商务抽取专家人数"
                  />
                </el-form-item>
                <span v-else>{{ formData.businessExpertsSelectedNumber }}</span>
              </td>
            </tr>
          </template>
          <!--
          评委会是否分组 00 不分组
          -->
          <template v-if="formData.judgesGroupedStatus==='00'">
            <tr>
              <td>
                <span v-if="isEdit&&functionType=='00'" class="red-star">*</span>
                评标委员会个数
              </td>
              <td>
                <el-form-item v-if="isEdit&&functionType=='00'" ref="judgesNumber" prop="judgesNumber">
                  <el-input
                    v-model="formData.judgesNumber"
                    oninput="value=value.replace(/[^\d]/g,'')"
                    maxlength="15"
                    placeholder="评标委员会个数"
                  />
                </el-form-item>
                <span v-else>{{ formData.judgesNumber }}</span>
              </td>
              <td>
                <span v-if="isEdit&&functionType=='00'" class="red-star">*</span>
                抽取专家人数
              </td>
              <td>
                <el-form-item v-if="isEdit&&functionType=='00'" ref="expertsSelectedNumber" prop="expertsSelectedNumber">
                  <el-input
                    v-model="formData.expertsSelectedNumber"
                    oninput="value=value.replace(/[^\d]/g,'')"
                    maxlength="20"
                    style="width:200px"
                    placeholder="抽取专家人数"
                  />
                </el-form-item>
                <span v-else>{{ formData.expertsSelectedNumber }}</span>
              </td>
            </tr>
          </template>
          <tr>
            <td>
              <span v-if="isEdit&&functionType=='00'" class="red-star">*</span>
              牵头部门
            </td>
            <td>
              <el-form-item v-if="isEdit&&functionType=='00'" ref="leadDepartment" prop="leadDepartment">
                <el-radio-group v-model="formData.leadDepartment">
                  <el-radio v-for="(item,index) in businessList" :key="index" :label="item.typecode">
                    {{ item.typename }}
                  </el-radio>
                </el-radio-group>
              </el-form-item>
              <span v-else>
                <span v-for="(item,index) in businessList" v-if="formData.leadDepartment===item.typecode" :key="index">
                  {{ item.typename }}
                </span>
              </span>
            </td>
            <!--
            当前页面所处功能 functionType === 01 部门主任设置牵头人
            -->
            <template v-if="functionType=='01'">
              <td>
                <span v-if="isEdit" class="red-star">*</span>
                牵头项目经理
              </td>
              <!--可编辑状态-->
              <td>
                <el-form-item v-if="isEdit&&functionType=='01'" ref="leadTenderManager" prop="leadTenderManager">
                  <el-input
                    v-model="formData.leadTenderManager"
                    disabled
                    show-word-limit
                    maxlength="200"
                    style="width: calc(100% - 156px)"
                    placeholder="请选择"
                  />
                  <el-button type="primary" @click="dialogData.dialog=true">
                    选择
                  </el-button>
                  <el-button type="primary" plain @click="leadProjectManagerInfo('clear')">
                    清空
                  </el-button>
                </el-form-item>
                <span v-else>{{ formData.leadTenderManager }}</span>
              </td>
            </template>
          </tr>
        </table>
      </el-form>
    </div>
    <!--选择牵头项目经理-->
    <leadProjectManagerSelectDalog v-if="leadDepartment.id" :dialog-data="dialogData" :lead-department="leadDepartment" role-codes="11" @leadProjectManagerInfo="leadProjectManagerInfo" />
    <!--可编辑状态时-->
    <div v-if="isEdit">
      <!--保存按钮-->
      <div class="but_footer">
        <div class="but_footer-h" />
        <div class="but_footer-but">
          <el-button type="primary" @click="submit()">
            确定
          </el-button>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
/* api*/
import { queryGroupInfoByGroupId, saveGroupInfo } from '@/api/intensiveeval/intensiveeval'
/* 公共方法*/
import { checkRate } from '@/assets/js/validate'// 校验
/* 混合开发*/
import { groupMixin } from '@/views/intensiveeval/mixins/intensiveevalGroupMixin'// 字典信息
/* 组件*/
import leadProjectManagerSelectDalog from './leadProjectManagerSelect-dialog'// 选择项目经理-弹框
export default {
  name: 'IntensiveevalGroupInfoEditView',
  components: {
    leadProjectManagerSelectDalog
  },
  mixins: [groupMixin],
  data() {
    return {
      flowStatus: this.$route.query.flowStatus, // true 工作流进入
      isEdit: false, // 是否可编辑 布尔值
      functionType: '', // 当前页面所处功能 00 计划管理员-集约化评标分组-编辑分组 01 部门主任设置牵头人
      // 选择牵头人项目经理-弹框
      dialogData: {
        dialog: false// 打开状态
      },
      // 牵头部门-传给选择牵头人项目经理
      leadDepartment: {
        typename: '', // 名称
        rogCode: '', // code编号
        id: ''// 牵头人部门Id
      },
      /* 参数*/
      formData: {
        batchNumber: '', // 批次号
        businessExpertsSelectedNumber: '', // 商务抽取专家人数
        businessGroupNumber: '', // 商务组数
        deptOneNumber: '', // 一部数量
        deptThreeNumber: '', // 三部数量
        deptTwoNumber: '', // 二部数量
        judgesNumber: '', // 评标委员会个数
        expertsSelectedNumber: '', // 抽取专家人数
        groupName: '', // 分组名称
        groupedStatus: '', // 分组状态
        id: '', // 主键id
        judgesGroupedStatus: '', // 评委会是否分组(00否 01是)
        leadDepartment: '', // 牵头部门
        leadTenderManager: '', // 牵头项目经理
        leadTenderManagerId: '', // 牵头项目经理Id
        projectDepartNumber: '', // 项目单位个数
        schemeNumber: '', // 评标计划数量
        technicalExpertsSelectedNumber: '', // 技术抽取专家人数
        technicalGroupsNumber: '' // 技术组数
      },
      // 校验
      rules: {
        judgesGroupedStatus: [{ required: true, message: '请选择', trigger: 'change' }], // // 评委会是否分组
        technicalGroupsNumber: [{ required: true, validator: checkRate, trigger: 'blur' }], // 商务组人数
        businessGroupNumber: [{ required: true, validator: checkRate, trigger: 'blur' }], // 技术组人数
        technicalExpertsSelectedNumber: [{ required: true, validator: checkRate, trigger: 'blur' }], // 商务抽取专家人数
        businessExpertsSelectedNumber: [{ required: true, validator: checkRate, trigger: 'blur' }], // 技术抽取专家人数
        judgesNumber: [{ required: true, validator: checkRate, trigger: 'blur' }], // 评标委员会个数
        expertsSelectedNumber: [{ required: true, validator: checkRate, trigger: 'blur' }], // 抽取专家人数
        leadDepartment: [{ required: true, message: '请选择', trigger: 'change' }], // 牵头部门
        leadTenderManager: [{ required: true, message: '请选择', trigger: 'change' }]// 牵头项目经理
      }
    }
  },
  watch: {
    // 监听牵头部门value改变
    'formData.leadDepartment'(val) {
      this.initLeadDepartment()// 获取牵头部门信息
    },
    // 监听牵头人字典信息变化
    businessList() {
      this.initLeadDepartment()// 获取牵头部门信息
    }
  },
  created() {
    this.initWebTypeGroup()// 集约化评标计划-集约化评标明细(立项-字典信息)
    this.getQueryAllDepartPage()// 查询集约化评标所有的部门
    this.setTing()// 初始化设置
    this.loadData()// 获取数据
  },
  methods: {
    // 初始化设置
    setTing() {
      // 是否可编辑 布尔值
      this.isEdit = this.$route.meta.isEdit
      /*
        *当前页面所处功能
        *  00 计划管理员-集约化评标分组-编辑分组 01 部门主任设置牵头人 02 集约化评标—集约化评标记录-查看分组信息
        * */
      this.functionType = this.$route.meta.functionType
    },
    // 获取牵头部门信息
    initLeadDepartment() {
      // 循环遍历当前所选的信息
      this.businessList.forEach(item => {
        if (this.formData.leadDepartment === item.typecode) {
          this.leadDepartment = item
        }
      })
    },
    // 获取数据
    loadData() {
      // 工作流进入bizId  否则取groupId
      const data = {
        groupId: this.flowStatus ? this.$route.query.bizId : this.$route.query.groupId // 分组Id
      }
      queryGroupInfoByGroupId(data).then(res => {
        this.formData = res.data
        //  初始数据
        // 评委会是否分组
        if (!this.formData.judgesGroupedStatus) {
          this.formData.judgesGroupedStatus = '01'// 不分组
        }
        // 牵头部门
        if (!this.formData.leadDepartment) {
          this.formData.leadDepartment = '00'// 业务一部
        }
      })
    },
    // 选择牵头项目经理
    leadProjectManagerInfo(data) {
      if (data === 'clear') { // 清空
        this.formData.leadTenderManager = ''// 牵头项目经理
        this.formData.leadTenderManagerId = ''// 牵头项目经理Id
      } else { // 选择
        this.formData.leadTenderManager = data.realName// 牵头项目经理
        this.formData.leadTenderManagerId = data.id// 牵头项目经理Id
      }
    },

    // 保存组装数据
    assemblyData() {
      const data = {
        technicalGroupsNumber: '', // 商务组人数
        businessGroupNumber: '', // 技术组人数
        technicalExpertsSelectedNumber: '', // 商务抽取专家人数
        businessExpertsSelectedNumber: '', // 技术抽取专家人数
        judgesNumber: '', // 评标委员会个数
        expertsSelectedNumber: '' // 抽取专家人数
      }
      for (const key in data) {
        if (this.formData[key]) {
          data[key] = Number(this.formData[key])
        } else {
          data[key] = this.formData[key]
        }
      }
      data.id = this.formData.id // 主键Id
      data.judgesGroupedStatus = this.formData.judgesGroupedStatus // // 评委会是否分组
      data.leadDepartment = this.formData.leadDepartment // 牵头部门
      data.leadTenderManager = this.formData.leadTenderManager // 牵头项目经理
      data.leadTenderManagerId = this.formData.leadTenderManagerId// 牵头项目经理
      return data
    },
    // 确定
    submit() {
      this.$refs.formData.validate((valid, field) => {
        if (valid) {
          const data = this.assemblyData()// 保存组装数据
          saveGroupInfo(data).then(res => {
            this.$message({
              message: '提交成功',
              type: 'success'
            })
            if (this.functionType === '00') { // 00 计划管理员-集约化评标分组-编辑分组
              this.$router.push({ path: '/intensiveeval/intensiveevalPlanContent/intensiveevalGroup-list' })
            } else if (this.functionType === '01') { // 01 部门主任设置牵头人
              this.$router.push({ path: '/intensiveeval/intensiveevalLeadPerson-list' })
            }
          })
        }
      })
    }
  }
}
</script>
<style lang="less" scoped>
  /deep/.tableData{
    .el-form-item{
      margin: 0;
    }
  }

</style>
