<template>
  <div class="app-container">
    <!-- 搜索 -->
    <div class="filter-container">
      <el-form :inline="true" :model="searchForm">
        <el-form-item label="中转站名称" >
          <el-input v-model="searchForm.transit_name" placeholder="请输入中转站名称" />
        </el-form-item>
        <el-form-item label="车牌号" >
          <el-input v-model="searchForm.driver_account" placeholder="请输入车牌号" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" @click="fetchData">搜索</el-button>
          <router-link to="/basicInfo/transferCreate"><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="中转站名称" prop="transit_name" align="center"></el-table-column>
      <el-table-column label="车牌号" prop="driver_account" align="center"></el-table-column>
      <el-table-column label="负责人名称" prop="transit_man" align="center"></el-table-column>
      <el-table-column label="负责人电话" prop="transit_phone" align="center"></el-table-column>
      <el-table-column label="中转站地址" prop="transit_addr" align="center"></el-table-column>
      <el-table-column label="操作" align="center" width="220">
        <template slot-scope="scope">
          <router-link :to="'/basicInfo/transferEdit/'+scope.row.transit_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.transit_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 { listTransfer, deleteTransfer } 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(listTransfer(this.searchForm), (res) => {
        this.firmList = res.data.result
        this.total = res.data.data_sum
        this.listLoading = false
      })
    },
    // 删除
    handleDelete(id) {
      this.$confirm('删除', `确认删除吗`, () => {
        this.$http(deleteTransfer(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>
