<!--
  @description: 采购计划-计划审核
  @author: lxl
  @routerPath:/procurement/procurementPlanAuditList
  @date： 2020-11-5 17:52
-->
<template>
  <table-crud
    ref="tableCrud"
    :menu="true"
    :tabs="tabList"
    :search-form="searchForm"
    search-label-width="100px"
    @on-load="loadData"
  >
    <template v-slot:header>
      <span>计划审核</span>
    </template>
    <template v-slot:search="search">
      <!-- 计划名称 -->
      <el-form-item
        ref="purchasePlanName"
        label="采购计划名称"
        prop="purchasePlanName"
      >
        <el-input
          v-model.trim="searchForm.purchasePlanName"
          placeholder="计划名称"
          @keyup.enter.native="search.onSearch"
        />
      </el-form-item>
      <!-- 计划编号 -->
      <el-form-item
        ref="purchasePlanNo"
        label="计划编号"
        prop="purchasePlanNo"
      >
        <el-input
          v-model.trim="searchForm.purchasePlanNo"
          placeholder="计划编号"
          @keyup.enter.native="search.onSearch"
        />
      </el-form-item>
      <!--提交人-->
      <el-form-item
        ref="createUserRealName"
        label="提交人"
        prop="purchaseNo"
      >
        <el-input
          v-model.trim="searchForm.createUserRealName"
          placeholder="提交人"
          @keyup.enter.native="search.onSearch"
        />
      </el-form-item>
      <!-- 创建日期 -->
      <el-form-item
        label="开始日期"
      >
        <el-date-picker
          v-model="searchForm.datePicker"
          :value-format="elValueFormatDate"
          type="daterange"
          placeholder="选择开始日期时间"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          style="width:200px;"
          @change="onHandelTime"
        />
      </el-form-item>
    </template>
    <template v-slot:GXTable>
      <el-table
        ref="smallTable"
        v-loading="loading"
        :data="tableData"
        select-on-indeterminate
      >
        <el-table-column
          key="2"
          type="index"
          label="序号"
          width="60px"
          align="center"
          fixed="left"
        />
        <el-table-column
          prop="purchasePlanNo"
          label="计划编号"
          min-width="110"
          header-align="center"
        />
        <el-table-column
          prop="purchasePlanName"
          label="计划名称"
          min-width="150"
          header-align="center"
        />
        <el-table-column
          prop="purchasePlanType"
          label="计划类型"
          min-width="150"
        />
        <el-table-column
          prop="purchaseDetailNum"
          label="行项目数量"
          min-width="80"
        />
        <el-table-column
          prop="createUserRealName"
          label="提交人"
          min-width="120"
          header-align="center"
        />
        <el-table-column
          key="8"
          prop="commitTime"
          label="提交时间"
          min-width="150"
          align="center"
        />
        <!-- 操作 -->
        <el-table-column
          label="操作"
          min-width="120"
          align="center"
        >
          <template slot-scope="scope">
            <template v-if="searchForm.planAuditStatus==='00'">
              <el-link type="primary" @click.stop="onAudit(scope.row)">
                审核
              </el-link>
            </template>
            <template v-else>
              <el-link type="primary" @click.stop="onAudit(scope.row)">
                查看
              </el-link>
            </template>
          </template>
        </el-table-column>
      </el-table>
    </template>
  </table-crud>
</template>
<script>
// api
import { getPurchasePlanAuditList } from '@/api/procurement/purchasplan'
export default {
  name: 'ProcurementPlanAuditList',
  data() {
    return {
      loading: false,
      tableData: [],
      searchForm: {
        datePicker: [], // 选择开始时间结束时间
        purchasePlanName: '', // 采购计划名称
        purchasePlanNo: '', // 计划编号
        createUserRealName: '', // 提交人
        commitTimeStart: '', // 创建开始时间
        commitTimeEnd: '', // 创建结束时间
        planAuditStatus: '00' // tabs默认值
      },
      tabList: [
        { name: '待审核', index: '00' },
        { name: '审核通过', index: '01' },
        { name: '审核不通过', index: '02' }
      ]
    }
  },
  methods: {
    // 选择时间触发事件
    onHandelTime(val) {
      if (val) {
        this.searchForm.commitTimeStart	 = val[0]
        this.searchForm.commitTimeEnd = val[1]
      }
    },
    // 数据请求
    loadData(params, callback, tabData) {
      if (tabData) {
        params.planAuditStatus = tabData.index
        this.searchForm.planAuditStatus = tabData.index
      }
      getPurchasePlanAuditList(params).then(response => {
        this.loading = false
        this.tableData = response.data.records
        callback(response.data.total)
      }).catch(() => {
        this.loading = false
      })
    },
    // 审核/查看事件
    onAudit(row) {
      this.$router.push({
        name: 'auditProcurementPlanContent',
        params: {
          planMainId: row.planMainId,
          planAuditStatus: this.searchForm.planAuditStatus // 00 待审核 01审核通过 02审核不通过
        }
      })
    }
  }
}
</script>
