<!--
  @description:协议采购列表
  @Modifier:zyy
  @routerPath:
  @date:2021/8/13-17:52
-->
<template>
  <table-crud
    ref="tableCrud"
    :search-form="searchForm"
    search-label-width="100px"
    :menu="true"
    @on-load="loadData"
  >
    <template v-slot:header>
      协议采购列表
    </template>
    <template v-slot:search="search">
      <el-form-item label="合同名称">
        <el-input
          v-model.trim="searchForm.contractName"
          placeholder="合同名称"
          @keyup.enter.native="search.onSearch"
        />
      </el-form-item>
      <el-form-item label="合同编号">
        <el-input
          v-model.trim="searchForm.contractNo"
          placeholder="合同编号"
          @keyup.enter.native="search.onSearch"
        />
      </el-form-item>
      <el-form-item v-if="isleader" label="采购经办人">
        <el-input
          v-model.trim="searchForm.purchaseUserRealName"
          placeholder="采购经办人"
          @keyup.enter.native="search.purchaseUserRealName"
        />
      </el-form-item>
      <el-form-item
        v-if="isleader"
        label="审核状态"
        prop="auditStatus"
      >
        <el-select v-model="searchForm.auditStatus" placeholder="请选择" style="width: 120px" @change="search.onSearch">
          <el-option
            v-for="(item,index) in auditStatusList"
            :key="index"
            :label="item.typename"
            :value="item.typecode"
          />
        </el-select>
      </el-form-item>
      <!--<el-form-item
        label="合同类型"
        prop="contractType"
      >
        <el-select v-model="search.contractType" placeholder="请选择" style="width: 120px">
          <el-option
            v-for="(item,index) in contractTypeList"
            :key="index"
            :label="item.typename"
            :value="item.typecode"
          />
        </el-select>
      </el-form-item>-->
    </template>
    <template v-slot:menuLeft>
      <el-button v-if="!isleader" type="primary" @click="sign('01')">
        <!-- 协议采购 -->
        框架协议下单
      </el-button>
    </template>
    <template v-slot:GXTable>
      <el-table
        ref="smallTable"
        v-loading="loading"
        :data="tableData"
      >
        <el-table-column
          type="index"
          label="序号"
          width="60px"
          align="center"
        />
        <el-table-column
          prop="contractNo"
          align="center"
          label="合同编号"
          width="170"
        />
        <el-table-column
          prop="contractName"
          align="center"
          label="合同名称"
          min-width="230"
        />
        <el-table-column
          prop="contractTotalMoney"
          align="center"
          label="合同总价"
          width="170"
        />
        <!--<el-table-column
          key="tenderMethod"
          header-align="center"
          prop="tenderMethod"
          label="合同类型"
          width="80"
          align="center"
        >
          <template slot-scope="scope">
            {{ filterDictText(contractTypeList, scope.row.tenderMethod) }}
          </template>
        </el-table-column>-->
        <el-table-column
          prop="supplyDepartName"
          align="center"
          label="供方"
          width="170"
        />
        <el-table-column
          prop="demandDepartName"
          align="center"
          label="需方"
          width="170"
        />
        <el-table-column
          v-if="isleader"
          key="purchaseUserRealName"
          header-align="center"
          prop="purchaseUserRealName"
          label="采购经办人"
          align="center"
          min-width="220"
        />
        <el-table-column
          prop="createTime"
          align="center"
          label="创建日期"
          width="170"
        />
        <!--<el-table-column
          prop="contractStartTime"
          align="center"
          label="合同期限开始时间"
          width="170"
        />
        <el-table-column
          prop="contractEndTime"
          align="center"
          label="合同期限结束时间"
          width="170"
        />
        <el-table-column
          header-align="center"
          prop="execStatus"
          label="执行状态"
          width="80"
          align="center"
        >
          <template slot-scope="scope">
            {{ filterDictText(execStatusList, scope.row.execStatus) }}
          </template>
        </el-table-column>-->
        <el-table-column
          label="审核状态"
          align="center"
          prop="auditStatus"
          width="130"
        >
          <template slot-scope="scope">
            <!--审核状态 00:待审核 01:审核通过 02:审核不通过-->
            {{ filterDictText(auditStatusList, scope.row.auditStatus) }}
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          label="操作"
          width="100"
        >
          <template slot-scope="scope">
            <!--00保存，01已提交-->
            <el-link
              v-if="!isleader && (scope.row.useStatus =='00'||scope.row.auditStatus === '02')"
              type="primary"
              @click.stop="sign(scope.row)"
            >
              [编辑]
            </el-link>
            <el-link
              v-if="scope.row.useStatus!== '00' || (isleader && scope.row.auditStatus) "
              type="primary"
              @click.stop="see(scope.row)"
            >
              [查看]
            </el-link>
          </template>
        </el-table-column>
      </el-table>
    </template>
  </table-crud>
</template>
<script>
/* 接口*/
import { getAgreementPurchaseList } from '@/api/contractManagement/index'// 招标项目-签订列表
/* 公用方法*/
import { filterDictText } from '@/assets/js/utils'// 常用方法
/* 混入-字典信息 */
import { purchaseAgreementMixins } from './mixins/purchaseAgreementMixins'// 招标/采购签订合同-公用方法
export default {
  name: 'PurchaseAgreementList',
  mixins: [purchaseAgreementMixins],
  data() {
    return {
    }
  },
  watch: {
  },
  created() {
  },
  methods: {
    filterDictText, // 字典值替换文本通用方法
    // 获取数据
    loadData(params, callback) {
      const data = {
        ...params
      }
      getAgreementPurchaseList(data).then(response => {
        this.loading = false
        this.tableData = response.data.records
        callback(response.data.total)
      }).catch(() => {
        this.loading = false
      })
    },
    // 签订
    sign(row) {
      this.$router.push({
        name: 'PurchaseAgreement',
        params: {
          id: row && row.id ? row.id : ''
        }
      })
    },
    // 查看
    see(row) {
      this.$router.push({
        name: 'PurchaseAgreementDetail',
        params: {
          id: row && row.id ? row.id : ''
        }
      })
    }
  }
}
</script>
<style lang="less" scoped>
</style>
