<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="68px">
      <el-form-item label="合同名称" prop="subContractName">
        <el-input v-model="queryParams.subContractName" placeholder="请输入合同名称" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="承接单位" prop="partnerId">
        <el-select v-model="queryParams.partnerId" clearable filterable remote reserve-keyword placeholder="请输入承接单位"
          :remote-method="remoteMethod" :loading="loading" style="width: 400px;" @change="handleQuery">
          <el-option v-for="partner in partnerList" :key="partner.partnerId" :label="partner.partnerName"
            :value="partner.partnerId">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
      </el-form-item>
    </el-form>

    <el-table ref="chooseRef" v-loading="loading" border :data="subContractList" :row-key="getRowKeys"
      @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" :reserve-selection="true" />
      <el-table-column type="index" label="序号" width="55" align="center" />
      <el-table-column label="合同名称" align="center" prop="subContractName" />
      <el-table-column label="承接单位" align="center" prop="partner.partnerName" />
      <el-table-column label="分包合同金额" align="center" prop="subAmount" width="120" />
    </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>
    <el-divider></el-divider>
    <div>
      已选合同：
      <el-tag v-for="item in chooseList" style="margin: 5px;" :key="item.subContractId">
        {{ item.subContractName }}
      </el-tag>
    </div>
    <div style="text-align: center;margin-top: 20px;">
      <el-button type="primary" @click="confirmChoose">确认选择</el-button>
      <el-button @click="clearChoose">清空选择</el-button>
    </div>
  </div>
</template>

<script>
import { listSubContract, getSubContract, delSubContract, addSubContract, updateSubContract } from "@/api/oa/contract/subContract";
import { listPartner } from "@/api/oa/partner/partner";
export default {
  data() {
    return {
      loading: false,
      total: 0,
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        contractId: null,
        subContractName: null,
        subAmount: null,
        partnerId: null,
        contactPerson: null,
        drafter: null,
        draftTime: null,
        signDate: null,
        signRemark: null,
        signScan: null,
        commentType: null
      },
      subContractList: [],
      chooseList: [],
      partnerList: [],
    }
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询cmc分包合同评审列表 */
    getList() {
      this.loading = true;
      listSubContract(this.queryParams).then(response => {
        this.subContractList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    remoteMethod(val) {
      listPartner({
        pageNum: 1,
        pageSize: 20,
        partnerName: val
      }).then(res => {
        this.partnerList = res.rows;
      })
    },
    handleSelectionChange(val) {
      this.chooseList = val
    },
    setCommentType(commentType) {
      if (commentType == '2') {
        return '线上评审'
      } else if (commentType == '0') {
        return '无须评审'
      } else {
        return '会议评审'
      }
    },
    getRowKeys(row) {
      return row.subContractId;
    },
    confirmChoose() {
      this.$emit('choose', this.chooseList)
    },
    clearChoose() {
      this.$refs.chooseRef.clearSelection();
    }
  },
}
</script>

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