<!--
  @description:供应商管理-代办任务
  @Modifier:肖文龙
  @routerPath:supper/supplierAudit-list
  @date:2020/2/17-17:27
-->
<template>
  <div>
    <!--标题-->
    <div class="title title_border p0-16">
      <i class="el-icon-s-home" />
      代办任务
    </div>
    <section class="p0-16">
      <!--查询条件-->
      <div class="crud_menu_title clearfix">
        <span class="icon-line fl">查询条件</span>
        <span class="fr pointer" @click="handleToggleSearch">
          <el-link
            :underline="false"
            :class="toggleSearchStatus?'arrow-is-active':''"
            type="primary"
            class="toggleSearchStatus icon el-icon-arrow-down"
          />
          {{ toggleSearchStatus?'收起高级查询' :'展开高级查询' }}
        </span>
      </div>
      <div :class="{'SearchContent_show':toggleSearchStatus}" class="clearfix SearchContent">
        <div class="SearchContent_leftInput fl">
          <el-form
            ref="searchForm"
            :model="searchForm"
            inline
          >
            <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" />
            </el-form-item>
            <el-form-item ref="supplierName" label="业务名称" prop="supplierName">
              <el-input v-model="searchForm.supplierName" placeholder="请输入供应商名称" style="width:228px" />
            </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" />
            </el-form-item>
          </el-form>
        </div>
        <div class="fr">
          <el-button type="primary" @click="onSearch">
            搜 索
          </el-button>
          <el-button plain type="info" @click="resetForm('searchForm')">
            重 置
          </el-button>
        </div>
      </div>
      <!--查询结果-->
      <div class="crud_menu_title">
        <span class="icon-line">查询结果</span>
      </div>
      <div v-if="pageType === '01'" class="mb10">
        <el-button type="primary" @click="batchAudit">
          批量审核
        </el-button>
      </div>
      <div class="mt10">
        <el-table
          ref="smallTable"
          v-loading="loading"
          :data="tableData"
          @selection-change="selectionChange"
        >
          <el-table-column
            type="selection"
            width="55"
          />
          <el-table-column
            type="index"
            label="序号"
            width="60px"
            align="center"
          />
          <el-table-column
            prop="bizType"
            header-align="center"
            label="审核类型"
            width="200"
          >
            <template slot-scope="scope">
              <span
                v-for="(item,index) in supplierBizTypeGroupList"
                v-if="scope.row.bizType===item.typecode"
                :key="index"
              >{{ item.typename }}</span>
            </template>
          </el-table-column>
          <el-table-column
            header-align="center"
            prop="businesslicence"
            label="业务编号"
            min-width="110"
          />
          <el-table-column
            header-align="center"
            prop="supplierName"
            label="业务名称"
            min-width="300"
          >
            <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
            header-align="center"
            label="发起人"
            prop="createUserName"
            align="left"
            min-width="110"
          />
          <el-table-column
            label="提交时间"
            prop="createTime"
            align="center"
            min-width="140"
          />
          <el-table-column
            header-align="center"
            label="操作"
            align="center"
            width="146"
          >
            <template slot-scope="scope">
              <el-link
                type="primary"
                @click.stop="sureAudit(scope.row)"
              >
                [审核]
              </el-link>
              <!--            <el-link
                type="primary"
                @click.stop="intoSee(scope.row)">[审核进度]
              </el-link>-->
            </template>
          </el-table-column>
        </el-table>
        <!--分页组件-->
        <pagination :pagination-data="paginationData" @change="loadData" />
      </div>
    </section>
    <!-- 批量审核弹框 -->
    <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, listRuTaskCurrentDepartPages } from '@/api/supplier/wareHousingApprovalaudit'// 列表
/* 公用方法*/
import { filterObj, restoreInitialValue } from '@/assets/js/utils'// 常用方法
/* 组件*/
import pagination from '@comp/common/pagination/pagination'// 分页
import supplierAuditAll from './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 {
      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: ''
    }
  },
  created() {
    // 页面类型 00申报 01代办
    if (this.$route.path === '/supperManagement/supplierOurCompanyAudit-list') {
      this.pageType = '00'
    } else {
      this.pageType = '01'
    }
    // 获取列表信息
    this.loadData()
    // 获取字典
    this.initGetTaskDictionaries()
  },
  methods: {
    // 选择批量审批的数据
    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() {
      const path = this.$route.meta.path
      // 判断用户点击路由分别请求对应的接口
      if (path === 'supplierAuditList') {
        this.getListRuTaskPages()
      } else {
        this.getListRuTaskCurrentDepartPages()
      }
    },
    // 供应商审核代办列表
    getListRuTaskPages() {
      const params = this.getQueryParams()// 查询条件
      listRuTaskPages(params).then(response => {
        this.loading = false// 列表查询Loading
        this.paginationData.total = 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() {
      const params = this.getQueryParams()// 查询条件
      delete params.updateDepartId
      listRuTaskCurrentDepartPages(params).then(response => {
        this.loading = false// 列表查询Loading
        this.paginationData.total = 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(() => {

      })
    },
    // 查询条件
    getQueryParams() {
      const param = Object.assign({}, this.searchForm)
      param.pageNo = this.paginationData.pageNo
      param.pageSize = this.paginationData.pageSize
      param.createTimeBegin = param.createTime[0]// 审核时间开始
      param.createTimeEnd = param.createTime[1]// 审核时间结束
      // 删除不传给后端的参数字段
      delete param.createTime// 审核时间
      return filterObj(param)
    },
    // 供应商审核和供应商本单位审核 跳转分配不同路由
    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: {
            fileBizId: row.fileBizId,
            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
    },
    // 搜索
    onSearch() {
      this.paginationData.pageNo = 1
      this.paginationData.pageSize = 10
      this.loadData()
    },
    // 重置
    resetForm() {
      restoreInitialValue(this.searchForm)
      this.onSearch()
    },
    // 不合格供应商审核弹框
    AuditOpen(row) {
      this.$refs.reviewUnqualifiedAudit.openDialog(row)
    }
  }
}
</script>
<style lang="less" scoped>
</style>
