<!--
  @description:供应商管理-代办任务
  @Modifier:肖文龙
  @routerPath:supper/supplierAudit-list
  @date:2020/2/17-17:27
-->
<template>
  <div>
    <table-crud
      ref="tableCrud"
      :menu="true"
      :search-form="searchForm"
      :tabs="assignStatusList"
      search-label-width="100px"
      @on-load="loadData"
    >
      <template v-slot:header>
        <span>代办任务</span>
      </template>
      <template v-slot:search="search">
        <el-form-item v-if="pageType !== '00'" ref="bizType" label="审批类型" prop="bizType">
          <el-select v-model="searchForm.bizType" style="width:228px" placeholder="请选择">
            <el-option
              v-for="item in supplierBizTypeGroupList"
              v-if="item.typecode !== '01'"
              :key="item.typecode"
              :label="item.typename"
              :value="item.typecode"
            />
          </el-select>
        </el-form-item>
        <el-form-item ref="businesslicence" label="业务编号" prop="businesslicence">
          <el-input v-model="searchForm.businesslicence" placeholder="请输入业务编号" style="width:228px" @keyup.enter.native="search.onSearch" />
        </el-form-item>
        <el-form-item ref="supplierName" label="业务名称" prop="supplierName">
          <el-input v-model="searchForm.supplierName" placeholder="请输入供应商名称" style="width:228px" @keyup.enter.native="search.onSearch" />
        </el-form-item>
        <el-form-item ref="date" label="提交时间" prop="date">
          <el-date-picker
            v-model="searchForm.createTime"
            :value-format="elValueSaveFormat"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            style="width:228px"
            end-placeholder="结束日期"
          />
        </el-form-item>
        <el-form-item ref="createUserName" label="发起人" prop="createUserName">
          <el-input v-model="searchForm.createUserName" placeholder="请输入当前发起人" style="width:228px" @keyup.enter.native="search.onSearch" />
        </el-form-item>
      </template>
      <template v-slot:menuLeft>
        <div class="mb10">
          <el-button v-if="pageType === '01' && auditStatus === '00'" type="primary" @click="batchAudit">
            批量审核
          </el-button>
        </div>
      </template>
      <template v-slot:GXTable>
        <el-table
          ref="smallTable"
          v-loading="loading"
          :data="tableData"
          @selection-change="selectionChange"
        >
          <el-table-column
            v-if="auditStatus === '00'"
            key="1"
            type="selection"
            width="55"
          />
          <el-table-column
            key="2"
            type="index"
            label="序号"
            width="60px"
            align="center"
          />
          <!--<el-table-column
            key="3"
            header-align="center"
            prop="no"
            label="编号"
            min-width="110"
          />-->
          <el-table-column
            key="3"
            prop="bizType"
            header-align="center"
            label="审核类型"
            width="200"
          >
            <template slot-scope="scope">
              <span>
                {{ filterDictText(supplierBizTypeGroupList, scope.row.bizType) }}
              </span>
            </template>
          </el-table-column>
          <!--<el-table-column
            key="4"
            header-align="center"
            prop="supplierName"
            label="供应商名称"
            align="center"
            min-width="110"
          />
          <el-table-column
            key="5"
            header-align="center"
            prop="businesslicence"
            label="统一社会信用代码"
            min-width="110"
          />
          <el-table-column
            key="6"
            header-align="center"
            prop="departName"
            label="申报单位"
            min-width="110"
          />
          <el-table-column
            key="7"
            header-align="center"
            prop="supplyScopeComment"
            :label="$store.state.user.info.currentRol.roleCode === '12'?'供货范围备注':'投标范围备注'"
            min-width="110"
          />-->
          <el-table-column
            key="4"
            header-align="center"
            prop="businesslicence"
            label="统一社会信用代码"
            min-width="110"
          />
          <el-table-column
            key="5"
            header-align="center"
            prop="supplierName"
            label="业务名称"
            min-width="200"
          >
            <template slot-scope="scope">
              <el-link
                :underline="false"
                type="primary"
                @click="examineSupplierInfo(scope.row)"
              >
                {{ scope.row.supplierName }}
              </el-link>
            </template>
          </el-table-column>
          <el-table-column
            key="6"
            header-align="center"
            label="申请人"
            prop="createUserName"
            align="left"
            min-width="80"
          />
          <el-table-column
            key="7"
            label="提交时间"
            prop="createTime"
            align="center"
            min-width="200"
          />
          <!--<el-table-column
            key="9"
            label="申报状态"
            prop="auditStatus"
            align="center"
            min-width="140"
          />-->
          <el-table-column
            v-if="auditStatus === '00'"
            key="8"
            header-align="center"
            label="操作"
            align="center"
            width="150"
          >
            <template slot-scope="scope">
              <el-link
                type="primary"
                @click.stop="audit(scope.row)"
              >
                [审核]
              </el-link>
              <!--
              <el-link type="primary" @click.stop="toDetail(scope.row)">
                [查看]
              </el-link>
              <el-link type="primary" @click.stop="showUsers(scope.row)">
                [查看成员]
              </el-link>-->
            </template>
          </el-table-column>
        </el-table>
      </template>
    </table-crud>
    <!-- 批量审核弹框 -->
    <supplierAuditAll :dialog-data="batchAuditData" @call-back="batchAuditChange" />
    <!-- 供应商信息查看-弹框 -->
    <editorDeclarationDetailDialong ref="supplierInfo" />
    <!--不合格供应商审核弹框-->
    <reviewUnqualifiedAudit ref="reviewUnqualifiedAudit" :head-title="headTitle" :biz-id="bizId" />
  </div>
</template>
<script>
/* api*/
import { listRuTaskPages, listHiTaskPages, listRuTaskCurrentDepartPages, listHiTaskCurrentDepartPages } from '@/api/supplier/wareHousingApprovalaudit'// 列表
/* 公用方法*/
import { filterDictText } from '@/assets/js/utils'// 常用方法
/* 组件*/
import pagination from '@comp/common/pagination/pagination'// 分页
import supplierAuditAll from '../supplierAuditTodo/supplierAuditAll-dialog'// 批量审核
import editorDeclarationDetailDialong from '@/views/supplier/editorDeclaration/editorDeclarationContent/editorDeclarationDetail-dialog'// 供应商信息查看
import reviewUnqualifiedAudit from '@/views/supplier/reviewUnqualifiedAudit/reviewUnqualifiedAudit-dialog.vue' // 不合格供应商审核弹框
/* 混合开发方法-参数字段*/
import { ListMixin } from '@/mixins/ListMixin'// 分页
import { supplierGroupMixin } from '../../mixins/supplierGroupMixin'

export default {
  name: 'SupplierAuditList',
  components: {
    pagination, // 分页
    editorDeclarationDetailDialong, // 供应商信息查看-弹框
    supplierAuditAll, // 批量审核
    reviewUnqualifiedAudit // 不合格供应商审核-弹框
  },
  mixins: [ListMixin, supplierGroupMixin],
  data() {
    return {
      auditStatus: '00', // 审核状态
      pageType: '', // 页面类型 00申报 01代办
      headTitle: '',
      bizId: '',
      loading: true, // 列表查询Loading
      // 批量审核-弹窗-展示/隐藏状态 true 展示/false 隐藏
      batchAuditData: {
        dialog: false, // 弹框展示状态
        departInfoIds: []// 供应商departInfoId
      },
      // 搜索
      searchForm: {
        bizType: '', // 审批类型
        bizId: '',
        createUserName: '', // 发起人
        businesslicence: '', // 业务编号
        supplierName: '', // 业务名称
        createTimeBegin: '', // 审核时间开始
        createTimeEnd: '', // 审核时间结束
        createTime: [], // 审核时间不传给后端
        updateDepartId: '00',
        supplierId: '',
        departId: '',
        departName: ''
      },
      tableData: [], // 列表信息
      selectionData: [], // 选择批量审批的数据
      paths: '',
      assignStatusList: [{
        name: '待审核',
        typecode: '00'
      }, {
        name: '审核通过',
        typecode: '01'
      }, {
        name: '审核不通过',
        typecode: '02'
      }]
    }
  },
  created() {
    // 页面类型 00申报 01代办
    if (this.$route.path === '/supperManagement/supplierOurCompanyAudit-list') {
      this.pageType = '00'
    } else {
      this.pageType = '01'
    }
    // 获取字典
    this.initGetTaskDictionaries()
  },
  methods: {
    filterDictText,
    // 选择批量审批的数据
    selectionChange(val) {
      this.selectionData = [] // 初始化
      val.forEach(item => {
        this.selectionData.push(item.bizId) // 供应商departInfoId
      })
    },
    // 批量审核
    batchAudit() {
      if (this.selectionData.length < 1) {
        this.$message({
          message: '请选择需要审核的数据',
          type: 'warning'
        })
      } else {
        this.batchAuditData.dialog = true// 打开弹框
        this.batchAuditData.departInfoIds = this.selectionData.join(',') // 供应商departInfoId
      }
    },
    // 批量审批弹框回填数据
    batchAuditChange() {
      this.selectionData = []// 供应商departInfoId
      this.loadData()// 获取列表数据
    },
    // 获取数据
    loadData(params, callback, tabData) {
      this.auditStatus = tabData.typecode
      const path = this.$route.meta.path
      // 判断用户点击路由分别请求对应的接口
      if (path === 'supplierAuditList') {
        if (tabData.typecode === '00') {
          this.getListRuTaskPages(params, callback)
        } else {
          this.getListHiTaskPages(params, callback, tabData)
        }
      } else {
        if (tabData.typecode === '00') {
          this.getListRuTaskCurrentDepartPages(params, callback)
        } else {
          // 供应商本单位审核已办列表
          this.listHiTaskCurrentDepartPages(params, callback, tabData)
        }
      }
    },
    // 获取审批历史列表
    getListHiTaskPages(params, callback, tabData) {
      params.auditStatus = tabData.typecode
      listHiTaskPages(params).then(response => {
        this.loading = false// 列表查询Loading
        callback(response.data.total)
        this.tableData = response.data.records
        this.tableData.forEach(item => {
          item.createTime = this.$Moment(item.createTime).format(this.momentDateTime)
          // this.searchForm.bizType = item.bizType
        })
      }).catch(() => {

      })
    },
    // 供应商审核代办列表
    getListRuTaskPages(params, callback) {
      listRuTaskPages(params).then(response => {
        this.loading = false// 列表查询Loading
        callback(response.data.total)
        this.tableData = response.data.records
        this.tableData.forEach(item => {
          item.createTime = this.$Moment(item.createTime).format(this.momentDateTime)
          // this.searchForm.bizType = item.bizType
        })
      }).catch(() => {

      })
    },
    // 供应商本单位审核已办列表
    listHiTaskCurrentDepartPages(params, callback, tabData) {
      params.auditStatus = tabData.typecode
      delete params.updateDepartId
      listHiTaskCurrentDepartPages(params).then(response => {
        this.loading = false// 列表查询Loading
        callback(response.data.total)
        this.tableData = response.data.records
        this.tableData.forEach(item => {
          item.createTime = this.$Moment(item.createTime).format(this.momentDateTime)
          // this.searchForm.bizType = item.bizType
        })
      }).catch(() => {

      })
    },
    // 供应商本单位审核代办列表
    getListRuTaskCurrentDepartPages(params, callback) {
      delete params.updateDepartId
      params['auditStatus'] = '00'
      listRuTaskCurrentDepartPages(params).then(response => {
        this.loading = false// 列表查询Loading
        callback(response.data.total)
        this.tableData = response.data.records
        this.tableData.forEach(item => {
          item.createTime = this.$Moment(item.createTime).format(this.momentDateTime)
          // this.searchForm.bizType = item.bizType
        })
      }).catch(() => {

      })
    },
    // 供应商审核和供应商本单位审核 跳转分配不同路由
    sureAudit(row) {
      const path = this.$route.meta.path
      if (path === 'supplierAuditList') {
        this.audit(row)
      } else if (path === 'supplierOurCompanyAudit-list') {
        this.ourCompanyAudit(row)
      }
    },
    // 审核
    audit(row) {
      // 00：初审，01：申报审核，02：审核变更，03：不合格供应商（加入），04：不合格供应商（移除黑名单）
      if (row.bizType === '00' || row.bizType === '01') {
        this.$router.push({
          name: 'EditorDeclarationAuditDetail',
          params: {
            bizId: row.bizId,
            supplierId: row.supplierId, // 供应商主键id
            bizType: row.bizType, // 审核类型
            departId: row.supplierId,
            departName: row.departName,
            id: row.id,
            type: 'audit',
            isViewPage: '01'
          }
        })
      } else if (row.bizType === '03' || row.bizType === '04') {
        this.headTitle = row.bizType === '03' ? '不合格供应商（加入）' : '不合格供应商（移除黑名单）'
        this.$router.push({
          name: 'ReviewUnqualifiedAuditDetail',
          params: {
            id: row.bizId, // 业务Id
            supplierId: row.supplierId, // 供应商id
            bizType: row.bizType, // 审核类型
            isViewPage: '01'
          }
        })
      } else {
        this.$router.push({
          // path: '/supperManagement/editorDeclarationAudit-detail',
          name: 'EditorDeclarationAuditDetail',
          params: {
            bizId: row.bizId,
            supplierId: row.supplierId, // 供应商主键id
            bizType: row.bizType, // 审核类型
            departId: row.supplierId,
            departName: row.departName,
            id: row.id,
            type: 'audit'
          }
        })
      }
    },
    // 本单位审核
    ourCompanyAudit(row) {
      // 00：初审，01：申报审核，02：审核变更，03：不合格供应商（加入），04：不合格供应商（移除黑名单）
      if (row.bizType === '00' || row.bizType === '01') {
        this.$router.push({
          name: 'EditorDeclarationOurCompanyAuditDetail',
          params: {
            bizId: row.bizId,
            supplierId: row.supplierId, // 供应商主键id
            bizType: row.bizType, // 审核类型
            departId: row.supplierId,
            departName: row.departName,
            id: row.id,
            type: 'audit',
            isViewPage: '01'
          }
        })
      } else if (row.bizType === '03' || row.bizType === '04') {
        this.headTitle = row.bizType === '03' ? '不合格供应商（加入）' : '不合格供应商（移除黑名单）'
        this.$router.push({
          name: 'ReviewUnqualifiedOurCompanyAuditDetail',
          params: {
            id: row.bizId, // 业务Id
            supplierId: row.supplierId, // 供应商id
            bizType: row.bizType, // 审核类型
            isViewPage: '01'
          }
        })
      } else {
        this.$router.push({
          // path: '/supperManagement/editorDeclarationAudit-detail',
          name: 'EditorDeclarationOurCompanyAuditDetail',
          params: {
            bizId: row.bizId,
            supplierId: row.supplierId, // 供应商主键id
            bizType: row.bizType, // 审核类型
            departId: row.supplierId,
            departName: row.departName,
            id: row.id,
            type: 'audit'
          }
        })
      }
    },
    // 供应商信息-弹框
    examineSupplierInfo(row) {
      this.$refs.supplierInfo.open(row.supplierId)// 供应商主键id
    },
    // 不合格供应商审核弹框
    AuditOpen(row) {
      this.$refs.reviewUnqualifiedAudit.openDialog(row)
    }
  }
}
</script>
<style lang="less" scoped>
</style>
