<template>
  <div class="app-container">
    <!-- 搜索 -->
    <div class="filter-container">
      <el-form :inline="true" :model="searchForm">
        <el-form-item label="客户单位" >
          <el-input v-model="searchForm.client_company" placeholder="请输入客户单位" />
        </el-form-item>
        <!-- <el-form-item label="联系人" >
          <el-input v-model="searchForm.client_man" placeholder="请输入联系人" />
        </el-form-item>
        <el-form-item label="联系人电话" >
          <el-input v-model="searchForm.client_phone" placeholder="请输入联系人电话" />
        </el-form-item> -->
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" @click="fetchData">搜索</el-button>
          <router-link to="/basicInfo/cliCreate"><el-button class="ml-10" type="primary" icon="el-icon-edit">新增</el-button></router-link>
        </el-form-item>
      </el-form>
    </div>
    <!-- 表格 -->
    <el-table v-loading="listLoading" :data="firmList" border fit  highlight-current-row style="width: 100%;">
      <!-- <el-table-column label="ID" prop="client_id" align="center" width="80"></el-table-column> -->
      <el-table-column label="客户编号" prop="client_num" align="center"></el-table-column>
      <el-table-column label="客户名称" prop="client_name" align="center"></el-table-column>
      <el-table-column label="客户单位" prop="client_company" align="center"></el-table-column>
      <!-- <el-table-column label="联系人" prop="client_man" align="center"></el-table-column>
      <el-table-column label="联系电话" prop="client_phone" align="center"></el-table-column>
      <el-table-column label="联系地址" prop="client_address" align="center"></el-table-column> -->
      <el-table-column label="工地数" prop="site_count" align="center"></el-table-column>
      <el-table-column label="对接负责人" prop="accept_man" align="center"></el-table-column>
      <el-table-column label="对接财务人" prop="accept_finance" align="center"></el-table-column>
      <el-table-column label="操作" align="center" width="220">
        <template slot-scope="scope">
          <router-link :to="'/basicInfo/cliEdit/'+scope.row.client_id">
            <el-button class="ml-10" type="primary" size="mini">编辑</el-button>
          </router-link>
          <el-button class="ml-10" size="mini" type="danger" @click="handleDelete(scope.row.client_id)"> 删除 </el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 翻页 -->
    <pagination v-show="total>0" 
      :total="total" 
      :page.sync="searchForm.page" 
      :page_len.sync="searchForm.page_len"
      :limit.sync="searchForm.limit" 
      @pagination="fetchData" />
  </div>
</template>

<script>
import { listClient, deleteClient } from '@/api/base/index'

export default {
  data() {
    return {
      firmList: [],  // 列表
      total: 0,  // 总页数
      listLoading: true,
      // 搜索相关数据
      searchForm: {
        page: 1,
        page_len: 10
      },
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    // 获取企业列表
    fetchData(obj={}) {
      if(obj.page) {
        this.searchForm.page = obj.page
        this.searchForm.page_len = obj.page_len
      }
      this.listLoading = true
      this.$http(listClient(this.searchForm), (res) => {
        this.firmList = res.data.result
        this.total = res.data.data_sum
        this.listLoading = false
      })
    },
    // 删除
    handleDelete(id) {
      this.$confirm('删除', `确认删除吗`, () => {
        this.$http(deleteClient(id), res => {
          if(res.code == 0) {
            this.$message.success(res.message)
            this.fetchData()
          }
        })
      })
    },
  }
}
</script>

<style lang='scss' scoped>
  .img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
  }
</style>
