<!--
  @description:招标项目/采购项目-合同签订列表
  @Modifier:zyy
  @routerPath:
  @date:2021/4/21-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.contractNo"
          placeholder="合同编号"
          @keyup.enter.native="search.onSearch"
        />
      </el-form-item>
      <el-form-item label="合同名称">
        <el-input
          v-model.trim="searchForm.contractName"
          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="中标人">
        <el-input
          v-model.trim="searchForm.supplyDepartName"
          placeholder="中标人"
          @keyup.enter.native="search.supplyDepartName"
        />
      </el-form-item> -->
      <!--必填项，不可以重置-->
      <!-- <el-form-item
        label="项目类型"
        prop="contractSource"
      >
        <el-select v-model="contractSource" placeholder="请选择" style="width: 120px" @change="search.onSearch">
          <el-option
            v-for="(item,index) in contractSourceList"
            :key="index"
            :label="item.typename"
            :value="item.typecode"
          />
        </el-select>
      </el-form-item> -->
      <!-- <el-form-item
        label="合同类型"
        prop="contractTypeNo"
      >
        <el-select v-model="searchForm.contractTypeNo" placeholder="请选择" style="width: 120px" @change="search.onSearch">
          <el-option
            v-for="(item,index) in contractTypeList"
            :key="index"
            :label="item.typename"
            :value="item.typecode"
          />
        </el-select>
      </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> -->
    </template>
    <template v-slot:menuLeft>
      <el-button type="primary" @click="sign('01')">
        {{ contractSource == '00' ? '采购项目合同' : '招标项目合同' }}签订
      </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
          header-align="center"
          prop="contractNo"
          label="合同编号"
          width="170"
        />
        <el-table-column
          header-align="center"
          prop="contractName"
          label="合同名称"
          min-width="220"
        />
        <el-table-column
          header-align="center"
          prop="contractTypeName"
          label="合同类型"
          width="120"
        />
        <!--        <el-table-column-->
        <!--          prop="tenderNo"-->
        <!--          align="center"-->
        <!--          label="项目编号"-->
        <!--          width="170"-->
        <!--        />-->
        <!--        <el-table-column-->
        <!--          header-align="center"-->
        <!--          prop="payStatus"-->
        <!--          label="支付状态"-->
        <!--          width="100"-->
        <!--        >-->
        <!--          <template slot-scope="scope">-->
        <!--            <span v-if="scope.row.payStatus === '00'">未支付</span>-->
        <!--            <span v-else-if="scope.row.payStatus === '01'">已支付</span>-->
        <!--            <span v-else-if="scope.row.payStatus === '02'">部分支付</span>-->
        <!--          </template>-->
        <!--        </el-table-column>-->
        <el-table-column
          key="supplyDepartName"
          header-align="center"
          prop="supplyDepartName"
          label="中标人"
          min-width="220"
        />
        <el-table-column
          v-if="isleader"
          key="purchaseUserRealName"
          header-align="center"
          prop="purchaseUserRealName"
          label="采购经办人"
          align="center"
          min-width="220"
        />
        <!--招标显示01-->
        <el-table-column
          v-if="contractSource == '01'"
          key="packName"
          header-align="center"
          label="标段（包）名称"
          prop="packName"
          align="center"
          min-width="200"
        />
        <el-table-column
          label="合同状态"
          header-align="center"
          prop="contractStatus"
          align="center"
          width="130"
        >
          <template slot-scope="scope">
            {{ filterDictText(contractStatusList, scope.row.contractStatus) }}
          </template>
        </el-table-column>
        <!-- <el-table-column
          label="审核状态"
          header-align="center"
          prop="auditStatus"
          width="130"
        >
          <template slot-scope="scope"> -->
        <!--审核状态 00:待审核 01:审核通过 02:审核不通过-->
        <!-- <span v-if="scope.row.auditStatus === '00'">待审核</span>
            <span v-else-if="scope.row.auditStatus === '01'">审核通过</span>
            <span v-else-if="scope.row.auditStatus === '02'">审核不通过</span>
          </template>
        </el-table-column> -->
        <el-table-column
          align="center"
          label="操作"
          min-width="80"
        >
          <template slot-scope="scope">
            <!--00保存，01已提交-->
            <!--领导监察不可以编辑-->
            <el-link
              v-if="scope.row.contractStatus === '00'"
              type="primary"
              @click.stop="sign(scope.row)"
            >
              [编辑]
            </el-link>
            <el-link
              v-if="scope.row.contractStatus === '00'"
              type="primary"
              @click.stop="del(scope.row)"
            >
              [刪除]
            </el-link>
            <el-link
              v-if="scope.row.contractStatus !== '00'"
              type="primary"
              @click.stop="see(scope.row)"
            >
              [查看]
            </el-link>
            <!-- 审核通过后显示验收按钮  -->
            <!--            <el-link
              v-if="scope.row.contractStatus == '02'"
              type="primary"
              @click.stop="acceptance(scope.row)"
            >
              [验收]
            </el-link>
            <el-link
              v-if="scope.row.contractStatus == '02'"
              type="primary"
              @click.stop="payment(scope.row)"
            >
              [付款]
            </el-link>-->
          </template>
        </el-table-column>
      </el-table>
    </template>
  </table-crud>
</template>
<script>
/* 接口*/
import { listBidtCalibrationTenderContract, delOrderContract } from '@/api/contractManagement/index'// 招标项目-签订列表
/* 公用方法*/
import { filterDictText } from '@/assets/js/utils'// 常用方法
/* 混入-字典信息 */
import { contractSigningMixin } from './mixins/contractSigningMixin'// 招标/采购签订合同-公用方法
import { procurementGroupMixins } from '@/views/procurement/mixins/procurementGrounpMixins'
// import { initGroupMixin } from '@/mixins/initGroupMixin' // 字典
export default {
  name: 'ContractSigningList',
  mixins: [procurementGroupMixins, contractSigningMixin],
  data() {
    return {
      contractStatusList: [],
      tabList: [
        {
          typecode: '00', // 采购
          name: '采购'
        },
        {
          typecode: '01', // 采购
          name: '招标'
        }
      ],
      dictionaryType: ['contractStatus']
    }
  },
  watch: {
    '$route'(to, from) {
    }
  },
  created() {
    this.getGroupType()
    this.contractSource = '00' // 默认00采购
    // 字典信息
    this.initWebTypeGroup() // 采购方式
  },
  methods: {
    filterDictText, // 字典值替换文本通用方法
    getGroupType() {
      // 获取字典信息
      this.$store.dispatch('getGroupType', this.dictionaryType).then((data) => {
      // 遍历key存储相应的数据
        for (const key in data.bidTypeData) {
        /* 是否有数据*/
          if (data.bidTypeData[key]) {
            this[key] = data.bidTypeData[key]
          }
        }
      })
    },
    // 获取数据
    loadData(params, callback, tabData) {
      // if (tabData) {
      //   this.contractSource = params.contractSource = tabData.typecode
      // }
      const data = {
        ...params
        // contractSource: this.contractSource // 合同来源
      }
      listBidtCalibrationTenderContract(data).then(response => {
        this.loading = false
        this.tableData = response.data.records
        callback(response.data.total)
      }).catch(() => {
        this.loading = false
      })
    },
    // 签订
    sign(row) {
      this.$router.push({
        path: '/contractManagement/contractSigningStepAdd',
        query: {
          id: row && row.id ? row.id : '',
          contractSource: this.contractSource
        }
      })
      // this.$router.push({
      //   name: 'ContractSigning',
      //   params: {
      //     id: row && row.id ? row.id : '',
      //     contractSource: this.contractSource
      //   }
      // })
      // this.$router.push({
      //   name: 'contractPaymentProvisionAdd',
      //   params: {
      //     id: row && row.id ? row.id : '',
      //     contractSource: this.contractSource
      //   }
      // })
    },
    del(row) {
      delOrderContract(row.id).then(response => {
        this.loading = false
        this.$refs.tableCrud.onSearchChange()
      }).catch(() => {
        this.loading = false
      })
    },
    // 查看
    see(row) {
      const path = this.$route.meta.path
      let name = ''
      if (path === 'leaderContractSigning-list') {
        name = 'LeaderContractSigningDetail'
      } else {
        name = 'ContractSigningDetail'
      }
      this.$router.push({
        name,
        params: {
          id: row && row.id ? row.id : '',
          contractSource: row.contractSource
        }
      })
    },
    // 验收
    acceptance(row) {
      this.$router.push({
        name: 'acceptanceAdd',
        params: {
          id: row.id,
          contractSource: row.contractSource
        }
      })
    },
    payment(row) {
      this.$router.push({
        name: 'contractPaymentAdd',
        params: {
          id: row.id,
          contractSource: row.contractSource
        }
      })
    }
  }
}
</script>
<style lang="less" scoped>

</style>
