<template>
  <div>
    <el-row>
      <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="88px">
        <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">
      <el-table-column label="项目名称" align="center" key="tender.projectName" prop="tender.projectName"
        min-width="150px" />
      <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-column label="拟稿人" align="center" prop="draftUser.nickName" min-width="100px" />
      <el-table-column label="合同备注" align="center" prop="remark" min-width="100px" />
    </el-table>
    <div style="text-align: right;" class="mt20 mr20">
      <el-pagination @current-change="getList" :current-page.sync="queryParams.pageNum"
        :page-size="queryParams.pageSize" layout="total, prev, pager, next" :total="total">
      </el-pagination>
    </div>
    <div>
      已选项目：<el-tag>{{ choosePContract.tender.projectName }}</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;
    },
    confirmChoose() {
      this.$emit('choose', this.choosePContract)
    },
  },

}
</script>

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