<!--
  @description:未审核
  @Modifier: haofengxian/肖文龙
  @routerPath:
  @date: 2020-6-1-20:03
-->
<template>
  <div>
    <p class="mb10">
      <el-button v-if="configData.configType" type="primary" plain @click="batchReview()">
        批量审核
      </el-button>
      <span style="color: red;margin-left: 10px">当前分配规则为{{ configData.configText }}分配</span>
    </p>
    <section>
      <el-table
        ref="smallTable"
        v-loading="loading"
        :data="tableData"
        @selection-change="selectionChange"
      >
        <el-table-column
          type="selection"
          width="55"
          align="center"
        />
        <el-table-column
          type="index"
          label="序号"
          align="center"
          width="60"
        />
        <el-table-column
          prop="schemeNo"
          align="center"
          label="招标汇总/计划号"
          min-width="160"
        />
        <el-table-column

          header-align="center"
          prop="schemeName"
          label="招标汇总/计划名称"
          min-width="300"
        />
        <el-table-column

          header-align="center"
          prop="schemeDeptname"
          label="招标人"
          min-width="230"
        />
        <el-table-column
          header-align="center"
          prop="schemeBudget"
          label="概算金额（元）"
          min-width="140"
          align="right"
        />
        <el-table-column
          header-align="center"
          prop="purchaseClassName"
          label="采购品类"
          min-width="300"
        />
        <el-table-column
          prop="purchasLevel"
          label="采购级别"
          align="center"
          width="100"
        >
          <template slot-scope="scope">
            <span
              v-for="(item,index) in purchaseSchemeLevelList"
              v-if="scope.row.purchasLevel === item.typecode"
              :key="index"
            >{{ item.typename }}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="bidEvaluationMethod"
          label="评标办法"
          min-width="150px"
          align="center"
        >
          <template slot-scope="scope">
            <span
              v-for="(item,index) in purchasesSchemeProEvalMethodList"
              v-if="scope.row.bidEvaluationMethod === item.typecode"
              :key="index"
            >{{ item.typename }}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="biddingSchemeType"
          label="采购类别"
          align="center"
          width="100"
        >
          <template slot-scope="scope">
            <span
              v-for="(item,index) in purchaseSchemeProjectTypeList"
              v-if="scope.row.biddingSchemeType === item.typecode"
              :key="index"
            >{{ item.typename }}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="purchasType"
          label="采购类型"
          align="center"
          width="100"
        >
          <template slot-scope="scope">
            <span
              v-for="(item,index) in purchaseSchemeTypeList"
              v-if="scope.row.purchasType === item.typecode"
              :key="index"
            >{{ item.typename }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" width="180" fixed="right">
          <template slot-scope="scope">
            <el-link
              v-if="configData.configType"
              type="primary"
              @click="passAudit(scope.row)"
            >
              [通过]
            </el-link>
            <el-link
              v-if="configData.configType"
              type="primary"
              @click="noPassAudit(scope.row)"
            >
              [不通过]
            </el-link>
            <el-link type="primary" @click="view(scope.row.id)">
              [查看]
            </el-link>
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination :pagination-data="paginationData" @change="loadData" />
    </section>
  </div>
</template>

<script>
/* api */
import { getPretenderingPurchasesSchemeSystemPlanAdminPages, systemManualAssignScheme, systemAutoAssignScheme } from '@/api/purchasePlan/pretcloudPurchasescheme'
/* 组件*/
import pagination from '@comp/common/pagination/pagination' // 分页组件
/* 常用公共方法*/
import { filterObj } from '@/assets/js/utils'
/* 混入公共方法*/
import { ListMixin } from '@/mixins/ListMixin'
import { tenderPlan } from '../../../mixins/tenderPlan'
import { tenderPlanAllotMixin } from '../../../mixins/tenderPlanAllotMixin'
export default {
  name: 'UnBidInvitationPlanAuditComp',
  components: {
    pagination
  },
  mixins: [ListMixin, tenderPlan, tenderPlanAllotMixin],
  props: {
    // 搜索参数
    searchForm: {
      type: Object,
      default: function() {
        return {}
      }
    }
  },
  data() {
    return {
      loading: false,
      ids: [], // 选中的招标计划id
      tableData: [] // 获取获取招标计划已分配列表
    }
  },
  created() {
    this.initDataType('systemCurrentAssignedType', this.$store.getters.info.companyId)// 查询当前节点分配状态-mixins
    // 招标计划-字典信息
    this.initPurchaseSchemeWebTypeGroup()
  },
  methods: {
    // 搜索
    onSearch() {
      this.paginationData.pageNo = 1
      this.paginationData.pageSize = 10
      this.loadData()
    },
    // 系统级计划管理员分页获取获取招标计划列表
    loadData() {
      const params = this.getQueryParams(this.searchForm)// 查询条件
      getPretenderingPurchasesSchemeSystemPlanAdminPages(params).then(response => {
        this.loading = false
        this.tableData = response.data.records
        this.paginationData.total = response.data.total
      }).catch(() => {

      })
    },
    // 分配招标计划复选框事件
    selectionChange(val) {
      const data = [...val]
      this.ids = []
      data.forEach(item => {
        this.ids.push(item.id)
      })
    },
    // 查询条件
    getQueryParams(searchForm) {
      const param = Object.assign({}, searchForm)
      param.pageNo = this.paginationData.pageNo
      param.pageSize = this.paginationData.pageSize
      param.sysAssignedStatus = '00'// 系统级审核状态，00未审核，01已审核(必填)
      return filterObj(param)
    },
    // 批量审核
    batchReview() {
      if (this.ids.length > 0) {
        this.$confirm('确认审核通过本条方案吗？', '提示', {
          distinguishCancelAndClose: true,
          confirmButtonText: '通过',
          cancelButtonText: '不通过',
          confirmButtonClass: 'confirmBtn',
          cancelButtonClass: 'cancelBtn',
          type: 'warning'
        }).then(() => {
          this.systemManualAssignScheme('00')// 系统级手动分配招标计划信息
        }).catch((actiion) => {
          if (actiion === 'cancel') { // 审核不通过
            this.systemManualAssignScheme('01')// 系统级手动分配招标计划信息
          }
        })
      } else {
        this.$message({
          message: '请选择招标方案',
          type: 'warning'
        })
      }
    },
    // 系统自动审核招标计划信息
    assignScheme() {
      systemAutoAssignScheme().then(() => {
        this.$message({
          type: 'success',
          message: '自动分配成功'
        })
        this.onSearch()// 查询招标计划分配列表
      })
    },
    // 系统级手动分配招标计划信息
    // operation 操作类型 00:通过 01:不通过(只有系统级手动分配时候必填)
    systemManualAssignScheme(operation, row) {
      const data = {
        ids: [], // 选中的招标计划id-审批
        operation: operation// 操作类型
      }
      if (row) { // 如果有数据则是单选
        data.ids = [row.id]
      } else {
        data.ids = [...this.ids]
      }
      systemManualAssignScheme(data).then((res) => {
        this.$message.success(res.header.msg)
        this.ids = []// 清空已选
        this.paginationData.pageNo = 1
        this.paginationData.pageSize = 10
        this.loadData()// 查询数据
      })
    },
    // 审核不通过
    noPassAudit(row) {
      this.$confirm('确认审核不通过本条方案吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        confirmButtonClass: 'confirmBtn',
        cancelButtonClass: 'cancelBtn',
        type: 'warning'
      }).then(() => {
        this.systemManualAssignScheme('01', row)// 系统级手动分配招标计划信息
      }).catch(() => {
      })
    },
    // 审核通过
    passAudit(row) {
      this.$confirm('确认审核通过本条方案吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        confirmButtonClass: 'confirmBtn',
        cancelButtonClass: 'cancelBtn',
        type: 'warning'
      }).then(() => {
        this.systemManualAssignScheme('00', row)// 系统级手动分配招标计划信息
      }).catch(() => {
      })
    },
    // 查看
    view(id) {
      this.$router.push({
        name: 'BidInvitationPlanAuditDetail',
        params: { id }
      })
    }
  }
}
</script>

<style scoped>

</style>
