<template>
  <div class="app-container">
    <!-- 搜索 -->
    <div class="filter-container">
      <el-form :inline="true" :model="searchForm">
        <el-form-item label="供应商名称" >
          <el-input v-model="searchForm.supplier_name" placeholder="请输入供应商名称" />
        </el-form-item>
        <el-form-item label="工地名称" >
          <el-input v-model="searchForm.site_name" placeholder="请输入工地名称" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" @click="fetchData">搜索</el-button>
          <router-link to="/distributionManagement/disCostCreate"><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="post_id" align="center" width="80"></el-table-column>
      <el-table-column label="供应商" prop="supplier_name" align="center"></el-table-column>
      <el-table-column label="中转站" prop="transit_name" align="center"></el-table-column>
      <el-table-column label="工地" prop="site_name" align="center"></el-table-column>
      <el-table-column label="运费单价(元)" prop="cash_fee" align="center"></el-table-column>
      <el-table-column label="开始时间" prop="start_time" align="center"></el-table-column>
      <el-table-column label="结束时间" prop="end_time" align="center"></el-table-column>
      <el-table-column label="备注" prop="post_note" align="center"></el-table-column>
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <router-link :to="'/distributionManagement/disCostEdit/'+scope.row.post_id">
            <el-button class="ml-10" type="primary" size="mini">编辑</el-button>
          </router-link>
        </template>
      </el-table-column>
    </el-table>
    <!-- 翻页 -->
    <pagination v-show="total>0" 
      :total="total" 
      :page.sync="searchForm.page" 
      :page_len.sync="searchForm.page_len"
      @pagination="fetchData" />
  </div>
</template>

<script>
import { listPostCash } from '@/api/order/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(listPostCash(this.searchForm), (res) => {
        this.firmList = res.data.result
        this.total = res.data.data_sum
        this.listLoading = false
      })
    },
  }
}
</script>

<style lang='scss' scoped>

</style>
