<template>
  <div class="app-container">
    <div>
      <div class="tab-header webtop">
        <div>选择合同页面</div>
        <div>
          <el-button type="info" size="small" @click="handleReturn()">关闭</el-button>
        </div>
      </div>
      <div class="main-content">
        <div class="searchcon">
          <el-button size="small" class="searchbtn" @click="clicksearchShow">{{ searchxianshitit }}</el-button>
          <div v-show="isSearchShow" class="search">
            <el-form ref="listQueryform" :inline="true" :model="listQuery" label-width="120px" class="tab-header">
              <el-form-item label="贷款合同编号" class="searchlist">
                <el-input v-model="listQuery.params.loanContractNo" placeholder="" clearable />
              </el-form-item>
              <el-form-item label="客户名称" class="searchlist">
                <el-input v-model="listQuery.params.customerName" placeholder="" clearable/>
              </el-form-item>
              <el-form-item label="贷款人" class="searchlist">
                <el-input v-model="listQuery.params.loanName" placeholder="" clearable/>
              </el-form-item>
            </el-form>
            <div class="btn" style="text-align: center;">
              <el-button type="primary" icon="el-icon-search" @click="handleFilter" size="small">查询</el-button>
              <el-button type="primary" icon="el-icon-refresh" @click="handleReset" size="small">重置</el-button>
            </div>
          </div>
        </div>
        <div class="listtop">
          <div class="tit">贷款合同列表</div>
        </div>
        <div class="">
          <el-table :key="tableKey" ref="multipleTable" v-loading="listLoading" :data="list" border style="width: 100%">
            <el-table-column width="60" label="序号" type="index" :index="indexMethod" align="center" />
            <el-table-column width="80" label="操作" align="center">
              <template slot-scope="scope">
                <el-button type="primary" size="small" @click="toSelect(scope.row)">选择</el-button>
              </template>
            </el-table-column>
            <el-table-column prop="loanContractNo" label="贷款合同编号" align="center" />
            <el-table-column prop="customerName" label="客户名称" align="center" />
            <el-table-column prop="loanName" label="贷款人" align="center" />
            <el-table-column prop="bankName" label="资方" align="center" />
            <el-table-column prop="bankContractNo" label="资方合同编号" align="center" />
          </el-table>
        </div>
        <div class="pages">
          <div class="tit"/>
          <!-- 翻页 -->
          <Pagination v-show="list.length > 0" :total="listQuery.total" :page.sync="listQuery.current" :limit.sync="listQuery.size" class="pagination" @pagination="getList"/>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import Pagination from '@/components/pagination'
import req from '@/api/caseaction/caseaction'

export default {
  name: 'SelectContract',
  components: {
    Pagination
  },
  data() {
    return {
      isSearchShow: false,
      searchxianshitit: '隐藏查询条件',
      tableKey: 0,
      list: [],
      listLoading: false,
      listQuery: {
        current: 1,
        size: 5,
        params: {
          userSid: '',
          orgPath: '',
          loanContractNo: '',
          customerName: '',
          loanName: ''
        },
        total: 0
      }
    }
  },
  methods: {
    // 搜索条件效果
    clicksearchShow() {
      this.isSearchShow = !this.isSearchShow
      if (this.isSearchShow) {
        this.searchxianshitit = '隐藏查询条件'
      } else {
        this.searchxianshitit = '显示查询条件'
      }
    },
    indexMethod(index) {
      var pagestart = (this.listQuery.current - 1) * this.listQuery.size
      var pageindex = index + 1 + pagestart
      return pageindex
    },
    // 返回
    handleReturn() {
      this.$emit('doback')
    },
    // 查询列表信息
    getList() {
      this.listLoading = true
      req.getListPage(this.listQuery).then((response) => {
        this.listLoading = false
        if (response.success) {
          this.listQuery.total = response.data.total
          this.list = response.data.records
        }
      })
    },
    // 查询按钮
    handleFilter() {
      this.listQuery.current = 1
      this.getList()
    },
    // 重置按钮
    handleReset() {
      this.listQuery.current = 1
      this.listQuery.size = 5
      this.listQuery.total = 0
      this.listQuery.params.loanContractNo = ''
      this.listQuery.params.customerName = ''
      this.listQuery.params.loanName = ''
      this.getList()
    },
    showData(orgPath) {
      this.listQuery.params.orgPath = orgPath
      this.listQuery.current = 1
      this.listQuery.size = 5
      this.listQuery.total = 0
      this.getList()
    },
    toSelect(row) {
      this.$emit('backData', row.loanContractSid)
    }
  }
}
</script>
<style scoped>
</style>
