<!--
  @description: 变更采购方式列表
  @Modifier: 肖文龙
  @routerPath: /bidding/projectDrive/changePurchase/changePurchase-list
  @date: 2020/12/24
  isCanOperate: true可以操作 false不可以查看只有查看权限
-->
<template>
  <div class="main">
    <el-button
      v-if="tenderBase.isCanOperate"
      type="primary"
      class="mb10"
      @click="addChangeBulletin('')"
    >
      新增
    </el-button>
    <div>
      <el-table
        v-loading="loading"
        :data="tableData"
        width="100%"
      >
        <el-table-column
          type="index"
          label="序号"
          width="60px"
          align="center"
        />
        <el-table-column
          header-align="center"
          label="标段（包）编号"
          prop="packNo"
          align="left"
          min-width="200"
        />
        <el-table-column
          prop="createTime"
          align="center"
          label="提交时间"
          width="160"
        />
        <el-table-column
          prop="newProcurementMethod"
          align="center"
          label="拟变更采购方式"
          width="140"
        >
          <template slot-scope="scope">
            {{ filterDictText(newProcurementMethodTypeList,scope.row.newProcurementMethod) }}
          </template>
        </el-table-column>
        <el-table-column
          label="状态"
          prop="auditStatus"
          align="center"
          width="100"
        >
          <template slot-scope="scope">
            <span v-if="scope.row.useStatus==='00' && scope.row.auditStatus!=='02'" class="status4">草稿</span>
            <span v-if="scope.row.auditStatus==='00'" class="status2">待审核</span>
            <span v-if="scope.row.auditStatus==='01'" class="status1">审核通过</span>
            <span v-if="scope.row.auditStatus==='02'" class="status3">审核不通过</span>
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          label="操作"
          width="180"
        >
          <template slot-scope="scope">
            <template v-if="tenderBase.isCanOperate">
              <el-link
                v-if="scope.row.auditStatus==='02'||!scope.row.auditStatus"
                type="primary"
                @click="addChangeBulletin(scope.row)"
              >
                [编辑]
              </el-link>
              <el-link
                v-if="scope.row.auditStatus==='02'||!scope.row.auditStatus"
                type="primary"
                @click="deleteProject(scope.row,scope.$index)"
              >
                [删除]
              </el-link>
            </template>
            <el-link
              v-if="scope.row.auditStatus==='00'||scope.row.auditStatus==='01'"
              type="primary"
              @click="preview(scope.row)"
            >
              [查看]
            </el-link>
            <template v-if="changeBulletinConfigType">
              <el-link
                v-if="scope.row.auditStatus"
                type="primary"
                @click="handleDetail(scope.row.changeBulletinId)"
              >
                [流程追踪]
              </el-link>
            </template>
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination :pagination-data="paginationData" @change="loadData" />
    </div>
    <!--流程追踪查看弹框-->
    <flow-detail-dialog ref="tracingFlow" />
  </div>
</template>

<script>
/* 接口*/
import { getExceptionList, deleteExpectionInfo } from '@/api/bidding/changePurchase'// 公告列表
/* 公用方法*/
import { filterDictText } from '@assets/js/utils' // 常用方法/* 组件*/
import pagination from '@comp/common/pagination/pagination'// 分页
import flowDetailDialog from '@views/work/process/flowDetail-dialog' //  流程追踪组件
/* 混合开发方法-参数字段*/
import { ListMixin } from '@/mixins/ListMixin'// 分页
export default {
  name: 'ChangePurchaseList',
  components: {
    pagination, // 分页
    flowDetailDialog
  },
  mixins: [ListMixin],
  data() {
    return {
      /* 字典信息-start */
      newProcurementMethodTypeList: [], // 变更采购方式
      /* 字典信息-end */
      changeBulletinConfigType: this.$store.getters.systemConfigVo.configType, // true走工作流 false隐藏流程追踪
      tenderBase: this.$store.getters.tenderBase, // 项目信息
      tenderId: this.$route.query.id,
      loading: true,
      tableData: []
    }
  },
  created() {
    // 获取列表信息
    this.loadData()
    this.initGroup()// 获取字典
    sessionStorage.removeItem('bizId')
  },
  methods: {
    filterDictText,
    // 获取字典方法
    initGroup() {
      const data = [
        'newProcurementMethodType' // 变更采购方式
      ]
      this.$store.dispatch('getGroupType', data).then(res => {
        Object.keys(res.bidTypeData).forEach((key) => {
          this[key] = res.bidTypeData[key]
        })
      })
    },
    // 获取数据
    loadData() {
      const params = {
        tenderId: this.tenderId,
        pageNo: this.paginationData.pageNo,
        pageSize: this.paginationData.pageSize
      }
      getExceptionList(params).then(response => {
        this.loading = false
        this.tableData = response.data.records
        this.paginationData.total = response.data.total
      }).catch(() => {

      })
    },
    // 新增/编辑变更采购方式
    addChangeBulletin(row) {
      this.$router.push({
        path: '/bidding/projectDrive/changePurchase/changePurchase-add',
        query: {
          ...this.$route.query,
          exceptionId: row && row.exceptionId
        }
      })
    },
    // 查看
    preview(row) {
      this.$router.push({
        path: '/bidding/projectDrive/changePurchase/changePurchase-detail',
        query: {
          ...this.$route.query,
          exceptionId: row.exceptionId
        }
      })
    },
    // 删除
    deleteProject(row, index) {
      this.$confirm('此操作将永久删除该记录, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        confirmButtonClass: 'confirmBtn',
        cancelButtonClass: 'cancelBtn',
        type: 'warning'
      }).then(() => {
        deleteExpectionInfo({ exceptionId: row.exceptionId }).then(res => {
          this.tableData.splice(index, 1)
          this.$message({
            type: 'success',
            message: '删除成功'
          })
          this.loadData()
        }).catch(() => {
        })
      }).catch(() => {
      })
    },
    // 流程追踪详情
    handleDetail(id) {
      this.$refs.tracingFlow.openDialogInitData(id)
    }
  }
}
</script>

<style scoped lang="less">

</style>
