<!--
  @description: 供应商合同确认
  @Modifier: haofengxian
  @routerPath:
  @date: 2021-12-30-11:41
-->
<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>
    </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="合同名称"
          width="170"
        />
        <el-table-column
          header-align="center"
          prop="contractTypeName"
          label="合同类型"
          width="120"
        />
        <el-table-column
          key="purchaseDepartName"
          header-align="center"
          prop="purchaseDepartName"
          label="采购方"
          align="center"
          min-width="220"
        >
        <!--          <template slot-scope="scope">-->
        <!--            <span>北京太阳宫燃气热电有限公司</span>-->
        <!--          </template>-->
        </el-table-column>
        <el-table-column
          label="合同状态"
          header-align="center"
          prop="contractStatus"
          align="center"
          width="130"
        >
          <template slot-scope="scope">
            <!--            {{ filterDictText(contractStatusList, scope.row.contractStatus) }}-->
            <span>{{ scope.row.contractStatus=='02'?'待确认':'已签订' }}</span>
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          label="操作"
          min-width="80"
        >
          <template slot-scope="scope">
            <el-link
              type="primary"
              @click.stop="see(scope.row)"
            >
              {{ scope.row.contractStatus=='02'?'[确认]':'[查看]' }}
            </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 '../contractSigning/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>
