<!--
  @description: 集约化评分组列表
  @author:肖文龙
  @routerPath:/intensiveeval/intensiveevalPlanContent/intensiveevalGroup-list
  @date: 2020年3月16日10:58:21
-->
<template>
  <div>
    <!--查询条件-->
    <div class="crud_menu_title clearfix">
      <span class="icon-line fl">查询条件</span>
    </div>
    <div :class="{'SearchContent_show':toggleSearchStatus}" class="clearfix SearchContent">
      <div class="SearchContent_leftInput fl">
        <el-form
          ref="searchForm"
          :model="searchForm"
          inline
          label-position="right"
        >
          <!--批次号-->
          <el-form-item ref="batchNumber" label="批次号" prop="batchNumber">
            <el-input v-model="searchForm.batchNumber" maxlength="200" placeholder="批次号" />
          </el-form-item>
          <!--分组名称-->
          <el-form-item ref="groupName" label="分组名称" prop="groupName">
            <el-input v-model="searchForm.groupName" maxlength="600" placeholder="分组名称" />
          </el-form-item>
          <!--分组状态-->
          <el-form-item ref="groupedStatus" label="分组状态" prop="groupedStatus">
            <el-select v-model="searchForm.groupedStatus" style="width: 228px" placeholder="请选择">
              <el-option v-for="(item,index) in groupingStateList" :key="index" :label="item.typename" :value="item.typecode" />
            </el-select>
          </el-form-item>
        </el-form>
      </div>
      <div class="fr">
        <el-button type="primary" size="small" @click="onSearch">
          搜索
        </el-button>
        <el-button plain type="info" size="small" @click="resetForm('searchForm')">
          重置
        </el-button>
      </div>
    </div>
    <section
      :class="{'SearchContent_show':true}"
      style="margin-top: 10px;"
      class="clearfix SearchContent"
    >
      <el-button
        type="primary"
        @click="evaluationGroupAllAudit"
      >
        提交审批
      </el-button>
      <!--editStatus==='01'工作流进入不显示-->
      <el-button
        v-if="editStatus!=='01'"
        @click="exportGroupCase"
      >
        导出分组情况
      </el-button>
    </section>
    <section style="margin-top: 10px;">
      <el-table
        ref="smallTable"
        v-loading="loading"
        :data="tableData"
        @selection-change="selectionChange"
      >
        <el-table-column
          :selectable="isDisabled"
          type="selection"
          width="45"
        />
        <el-table-column
          type="index"
          label="序号"
          width="45px"
          fixed="left"
          align="center"
        />
        <el-table-column
          prop="batchNumber"
          align="center"
          label="批次号"
          fixed="left"
          width="100"
        />
        <el-table-column
          header-align="center"
          prop="groupName"
          label="分组名称"
          fixed="left"
          min-width="200"
        />
        <el-table-column
          header-align="center"
          prop="judgesNumber"
          label="评标委员会个数"
          min-width="110"
        >
          <template slot-scope="scope">
            <!--评委会是否分组(00否 01是)-->
            <span>{{ scope.row.judgesGroupedStatus==='00'?scope.row.judgesNumber:'-' }}</span>
          </template>
        </el-table-column>
        <el-table-column
          header-align="center"
          prop="expertsSelectedNumber"
          label="抽取专家人数"
          min-width="100"
        >
          <template slot-scope="scope">
            <!--评委会是否分组(00否 01是)-->
            <span>{{ scope.row.judgesGroupedStatus==='00'?scope.row.expertsSelectedNumber:'-' }}</span>
          </template>
        </el-table-column>
        <el-table-column
          header-align="center"
          prop="technicalGroupsNumber"
          label="技术组数"
          min-width="80"
        >
          <template slot-scope="scope">
            <!--评委会是否分组(00否 01是)-->
            <span>{{ scope.row.judgesGroupedStatus==='01'?scope.row.technicalGroupsNumber:'-' }}</span>
          </template>
        </el-table-column>
        <el-table-column
          header-align="center"
          prop="technicalExpertsSelectedNumber"
          label="技术抽取专家人数"
          min-width="120"
        >
          <template slot-scope="scope">
            <!--评委会是否分组(00否 01是)-->
            <span>{{ scope.row.judgesGroupedStatus==='01'?scope.row.technicalExpertsSelectedNumber:'-' }}</span>
          </template>
        </el-table-column>
        <el-table-column
          header-align="center"
          prop="businessGroupNumber"
          label="商务组数"
          min-width="80"
        >
          <template slot-scope="scope">
            <!--评委会是否分组(00否 01是)-->
            <span>{{ scope.row.judgesGroupedStatus==='01'?scope.row.businessGroupNumber:'-' }}</span>
          </template>
        </el-table-column>
        <el-table-column
          header-align="center"
          prop="businessExpertsSelectedNumber"
          label="商务抽取专家人数"
          min-width="120"
        >
          <template slot-scope="scope">
            <!--评委会是否分组(00否 01是)-->
            <span>{{ scope.row.judgesGroupedStatus==='01'?scope.row.businessExpertsSelectedNumber:'-' }}</span>
          </template>
        </el-table-column>
        <el-table-column
          header-align="center"
          label="项目单位个数"
          prop="projectDepartNumber"
          min-width="110"
        />
        <el-table-column
          label="部门分工"
          prop="leadDepartment"
          min-width="70"
          align="center"
        >
          <template slot-scope="scope">
            <span
              v-for="(item,index) in businessList"
              v-if="scope.row.leadDepartment===item.typecode"
              :key="index"
            >{{ item.typename }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="分组状态"
          prop="groupedStatus"
          align="center"
          min-width="110"
        >
          <template slot-scope="scope">
            <span
              v-for="(item,index) in groupingStateList"
              v-if="scope.row.groupedStatus===item.typecode"
              :key="index"
            >{{ item.typename }}</span>
          </template>
        </el-table-column>
        <el-table-column
          header-align="center"
          label="操作"
          width="230"
        >
          <template slot-scope="scope">
            <!--
            评分组状态(00未分组 01评标分组待编辑 02评标分组已保存 03评标分组待审批 04评标分组审批通过 05评标分组审批驳回 06已指定牵头人 07已创建评委会申请 08已抽取完成)
            -->
            <template>
              <!--
             评标分组状态为：01 评标分组待编辑 ||02 评标分组已保存 || 05 评标分组审批不通过
            -->
              <el-link
                v-if="scope.row.groupedStatus==='01'||scope.row.groupedStatus==='02'||scope.row.groupedStatus==='05'"
                type="primary"
                @click="editGrouping(scope.row)"
              >
                [编辑]
              </el-link>
              <!--
              评标分组状态为：04评标分组审批通过 || 06 已指定牵头人
               -->
              <el-link
                v-if="scope.row.groupedStatus==='04'||scope.row.groupedStatus==='06'"
                type="primary"
                @click="editGrouping(scope.row)"
              >
                [修改]
              </el-link>
              <!--
              评标分组状态为： 05 评标分组审批不通过
               -->
              <el-link
                v-if="scope.row.groupedStatus!=='05'"
                type="primary"
                @click="seeGrouping(scope.row)"
              >
                [查看]
              </el-link>
            </template>
            <!--
            评分组状态：01评标分组待编辑 02评标分组已保存  05评标分组审批驳回
            -->
            <el-link
              v-if="scope.row.groupedStatus==='01'||scope.row.groupedStatus==='02'||scope.row.groupedStatus==='05'"
              type="primary"
              @click="deleteGrouping(scope.row)"
            >
              [删除]
            </el-link>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <pagination :pagination-data="paginationData" @change="loadData" />
    </section>
    <!--工作流选择节点组件-->
    <processNode-com
      ref="processNode"
      :process-definition-key="processDefinitionKey"
      @processNodeData="processNodeData"
    />
    <!--工作流流程节点/获取审核用户-->
    <depart-dialog
      ref="departDialog"
      :process-node="processNode"
      @isSingleUser="isSingleUser"
      @processInitData="processInitData"
      @submit="submit"
    />
  </div>
</template>

<script>
/* api*/
import { queryIntensiveevalPlansToGroupPages, exportIntensiveevalGroupList, deleteGroupInfo, groupListAudit } from
  '@/api/intensiveeval/intensiveeval'
/* 混合开发*/
import { groupMixin } from '@/views/intensiveeval/mixins/intensiveevalGroupMixin'// 字典信息
import { ListMixin } from '@/mixins/ListMixin'// 分页
import { workCommonMixins } from '@views/work/mixins/workCommonMixins'
/* 公用方法*/
import { filterObj, download } from '@/assets/js/utils'// 常用方法
import workconstant from '@/assets/js/workutils/workconstant'

/* 组件*/
import pagination from '@comp/common/pagination/pagination'// 分页
import processNodeCom from '@views/work/processNodeCom'
import departDialog from '@views/work/depart-dialog'
export default {
  name: 'IntensiveevalGroupList',
  components: {
    pagination,
    'processNode-com': processNodeCom, // 工作流节点信息组件
    'depart-dialog': departDialog // 工作流审批人组件
  },
  mixins: [groupMixin, ListMixin, workCommonMixins],
  data() {
    return {
      editStatus: this.$route.meta.editStatus, // 01 工作流进入
      loading: false, // 刷新loading
      processDefinitionKey: '', // 工作流流程id
      searchForm: {
        batchNumber: '', // 批次号
        groupName: '', // 分组名称
        groupedStatus: '' // 分组状态
      },
      // 提交审批
      dialogData: {
        dialog: false
      },
      // 评标委员会列表
      tableData: [],
      // 已选中的评标委员会列表
      selectList: []
    }
  },
  created() {
    // 获取数据
    this.loadData()
  },
  mounted() {
    this.processDefinitionKey = workconstant.intensiveeval // 工作流流程key
  },
  methods: {
    /*
    * 当前选中的信息
    * val list
    * */
    selectionChange(val) {
      this.selectList = val
    },
    /*
    *提交审批
    * fromData 审批信息
    * */
    evaluationGroupAllAudit() {
      if (this.selectList.length > 0) {
        this.$confirm('当前选中' + this.selectList.length + '条，确认提交审批。', '提示', {
          confirmButtonClass: 'confirmBtn',
          cancelButtonClass: 'cancelBtn',
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          if (JSON.stringify(this.processNode) !== '{}' && this.processNode.nodeId) {
            this.$refs.departDialog.getUserDepart(this.processNode)
          }
        }).catch(() => {
        })
      } else {
        this.$message({
          message: '必须选中一条记录。',
          type: 'warning'
        })
      }
    },
    submit() {
      const data = {
        auditStatus: '00', // 审核状态 00审核中,01通过,02驳回
        submitType: '00', // 00提交 01审核
        groupIds: [], // 分组id集合
        processInitDto: this.processInitDto // 审核人信息传回得信息
      }
      // 循环取分组id
      this.selectList.map(item => {
        data.groupIds.push(item.id)
      })
      data.groupIds = data.groupIds.join(',')// 转字符串逗号拼接
      data.processInitDto.type = '01' // 01：初次提交 02：审核驳回再次提交
      groupListAudit(data).then(res => {
        this.$message({
          type: 'success',
          message: '提交成功'
        })
        // 清空已选择信息
        this.selectList = []
        this.$refs.smallTable.clearSelection()
        this.paginationData.pageNo = 1
        this.paginationData.pageSize = 10
        // 获取列表信息
        this.loadData()
      })
    },
    /*
    * 导出分组情况
    * */
    exportGroupCase() {
      const params = this.getQueryParams()// 查询条件
      exportIntensiveevalGroupList(params).then(res => {
        download(res, '集约化评标分组情况.xls')
      })
    },
    /*
    * 编辑分组信息
    * row当前选中的信息
    * */
    editGrouping(row) {
      this.$router.push(
        { path: '/intensiveeval/intensiveevalGroup-add',
          query: {
            groupId: row.id, // 分组Id
            batchNumber: row.batchNumber// 批次号
          }}
      )
    },
    /*
    * 查看分组信息
    * row当前选中的信息
    * */
    seeGrouping(row) {
      this.$router.push(
        { path: '/intensiveeval/intensiveevalGroup-detail',
          query: {
            groupId: row.id, // 分组Id
            batchNumber: row.batchNumber// 批次号
          }}
      )
    },
    // 复选框部分禁用
    isDisabled(row, index) {
      if (row.groupedStatus === '01' || row.groupedStatus === '02' || row.groupedStatus === '05') {
        /*
        * 评标分组状态为： 01 评标分组待编辑 ||02 评标分组已保存 || 05 评标分组审批不通过
        * */
        return true
      } else {
        return false
      }
    },
    /*
    * 删除分组信息
    * row当前选中的信息
    * */
    deleteGrouping(row) {
      this.$confirm('确定删除该记录吗？', '提示', {
        confirmButtonClass: 'confirmBtn',
        cancelButtonClass: 'cancelBtn',
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        const data = {
          groupId: row.id// 分组id
        }
        deleteGroupInfo(data).then(res => {
          this.$message({
            type: 'success',
            message: '删除成功!'
          })
          this.loadData()// 获取数据
        })
      }).catch(() => {
      })
    },
    // 搜索
    onSearch() {
      this.paginationData.pageNo = 1
      this.paginationData.pageSize = 10
      // 获取列表信息
      this.loadData()
    },
    // 重置
    resetForm(formName) {
      this.paginationData.pageNo = 1
      this.paginationData.pageSize = 10
      this.$refs[formName].resetFields()
      // 获取列表信息
      this.loadData()
    },
    // 获取数据
    loadData() {
      this.loading = true
      const params = this.getQueryParams()// 查询条件
      queryIntensiveevalPlansToGroupPages(params).then(response => {
        this.tableData = response.data.records
        this.paginationData.total = response.data.total
        this.loading = false
      }).catch(() => {

      })
    },
    // 查询条件
    getQueryParams() {
      const param = Object.assign({}, this.searchForm)
      param.pageNo = this.paginationData.pageNo
      param.pageSize = this.paginationData.pageSize
      return filterObj(param)
    }
  }
}
</script>

<style lang="less" scoped>

</style>
