<!--
 * @Author: ysh
 * @Date: 2024-05-22 11:12:57
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2025-02-21 10:03:23
-->
<template>
  <div>
    <el-row>
      <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="88px">
        <el-form-item label="合同名称" prop="contractName">
          <el-input v-model="queryParams.contractName" placeholder="请输入合同名称" clearable
            @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item label="合同编码" prop="contractCode">
          <el-input v-model="queryParams.contractCode" placeholder="请输入合同编码" clearable
            @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item label="合同编号" prop="contractNumber">
          <el-input v-model="queryParams.contractNumber" placeholder="请输入合同编号" clearable
            @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" @click="handleQuery()">搜索</el-button>
        </el-form-item>
      </el-form>
    </el-row>
    <el-table ref="choosePContract" v-loading="loading" :data="contractList" highlight-current-row
      @current-change="handleCurrentChange" :row-key="getRowKeys" @row-dblclick="confirmChoose" @row-click="selectRow">
      <el-table-column label="序号" align="center" type="index" width="55" />
      <el-table-column label="关联项目" align="center" prop="project.projectName"/>
      <el-table-column label="合同名称" align="center" key="contractName" prop="contractName" min-width="100px" />
      <el-table-column label="合同编码" align="center" key="contractCode" prop="contractCode" />
      <el-table-column label="合同编号" align="center" prop="contractNumber" min-width="100px" />
      <el-table-column label="合同金额" align="center" prop="amount" min-width="100px" />
    </el-table>
    <div style="text-align: right;" class="mt20 mr20">
      <el-pagination @current-change="getList" :current-page.sync="queryParams.pageNum" :autoScroll="false"
        :page-size="queryParams.pageSize" layout="total, prev, pager, next" :total="total">
      </el-pagination>
    </div>
    <div>
      已选合同：<el-tag>{{ choosePContract.contractName }}</el-tag>
    </div>
    <div style="text-align: center;margin-top: 20px;">
      <el-button type="primary" @click="confirmChoose">确认选择</el-button>
      <el-button @click="$emit('close')">取消</el-button>
    </div>
  </div>
</template>

<script>
import { listProjectContract, addProjectContract } from "@/api/oa/contract/projectContract";
import { listContract, getContract, delContract, addContract, updateContract } from "@/api/oa/contract/contract";
export default {
  data() {
    return {
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10
      },
      contractList: [],
      userList: [],
      total: 0,
      loading: true,
      choosePContract: {
        tender: {
          projectName: ''
        }
      },
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      listContract(this.queryParams).then(response => {
        this.contractList = response.rows;
        this.total = response.total;
        this.loading = false;
      })
    },
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    handleCurrentChange(val) {
      this.choosePContract = val
    },
    getRowKeys(row) {
      return row.contractId;
    },
    selectRow(row){
      this.choosePContract = row
    },
    confirmChoose() {
      this.$emit('choose', this.choosePContract)
    },
  },

}
</script>

<style lang="scss" scoped></style>