<template>
  <div class="app-container">
    <!-- 搜索 -->
    <div class="filter-container">
      <el-form :inline="true" :model="searchForm">
        <!-- <el-form-item label="发票号" >
          <el-input v-model="searchForm.input_num" placeholder="请输入发票号" />
        </el-form-item> -->
        <el-form-item label="供应商名称" >
          <el-input v-model="searchForm.supplier_name" placeholder="请输入供应商名称" />
        </el-form-item>
        <template>
          <div style="display:inline-block;">
            <span class="g66 f700 font-14">开票时间</span>
            <el-date-picker
              v-model="searchForm.start_time"
              :picker-options="pickerOptionsStart"
              type="datetime"
              placeholder="请选择开始时间"
              value-format="yyyy-MM-dd HH:mm:ss"
              @change="changeEnd"/>
            <span>~</span>
            <el-date-picker
              v-model="searchForm.end_time"
              :picker-options="pickerOptionsEnd"
              type="datetime"
              placeholder="请选择结束时间"
              value-format="yyyy-MM-dd HH:mm:ss"
              @change="changeStart"/>
          </div>
        </template>
        <el-form-item>
          <el-button class="ml-10" type="primary" icon="el-icon-search" @click="fetchData">搜索</el-button>
          <router-link to="/financialManagement/supplier/create">
            <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="input_id" align="center" width="80"></el-table-column>
      <!-- <el-table-column label="发票号" prop="input_num" align="center"></el-table-column> -->
      <el-table-column label="供应商名称" prop="supplier_name" align="center"></el-table-column>
      <el-table-column label="开票时间" prop="ticket_time" align="center"></el-table-column>
      <el-table-column label="开票金额" prop="input_fee" align="center"></el-table-column>
      <el-table-column label="开票差额" prop="diff_fee" align="center"></el-table-column>
      <!-- <el-table-column label="联系人" prop="supplier_man" align="center"></el-table-column>
      <el-table-column label="联系电话" prop="supplier_phone" align="center"></el-table-column> -->
      <!-- <el-table-column label="税额" prop="input_tax" align="center"></el-table-column>
      <el-table-column label="含税金额" prop="tax_fee" align="center"></el-table-column> -->
      <el-table-column label="操作员" prop="operate_man" align="center"></el-table-column>
      <el-table-column label="操作" align="center" width="160">
        <template slot-scope="scope">
          <router-link :to="'/financialManagement/supplier/ticketEdit/'+scope.row.order_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"
      :limit.sync="searchForm.limit" 
      @pagination="fetchData" />
    <!-- <div class="font-14 mb-10">商品信息：</div>
    <el-table v-loading="msgListLoading" :data="msgList" border style="width: 80%;">
      <el-table-column label="类型" prop="product_type" align="center">
        <template slot-scope="scope">{{getProductType(scope.row.product_type)}}</template>
      </el-table-column>
      <el-table-column label="品种" prop="variety_num" align="center"></el-table-column>
      <el-table-column label="数量(吨)" prop="product_ton" align="center"></el-table-column>
      <el-table-column label="单价" prop="product_fee" align="center"></el-table-column>
    </el-table> -->
  </div>
</template>

<script>
import { listInput, listProduct } from '@/api/order/index'

export default {
  data() {
    return {
      firmList: [],  // 列表
      msgList: [], // 商品信息
      total: 0,  // 总页数
      listLoading: true,
      msgListLoading: false,
      // 搜索相关数据
      searchForm: {
        page: 1,
        page_len: 10
      },
      // 限制开始时间
      pickerOptionsStart: {},  
      pickerOptionsEnd: {},
    }
  },
  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(listInput(this.searchForm), (res) => {
        this.firmList = res.data.result
        this.total = res.data.data_sum
        this.listLoading = false
      })
    },
    cellClick(row,column,event,cell) {
      this.msgListLoading = true
      this.$http(listProduct(row.input_id), (res) => {
        this.msgList = res.data
        this.msgListLoading = false
      })
    },
    // 配送产品
    getProductType(value) {
      return value=="type-00"?"散装":(value=="type-01"?"袋装":"")
    },
    // 结束时间限制开始时间
    changeStart() {
      let self = this
      if (!this.searchForm.end_time) {
        this.pickerOptionsStart = {
          disabledDate: {}
        }
        return
      }
      this.pickerOptionsStart = Object.assign({}, self.pickerOptionsStart, {
        disabledDate(time) {
          return time.getTime() > new Date(self.searchForm.end_time).getTime()
        }
      })
    },
    // 开始时间控制结束时间
    changeEnd() {
      let self = this
      if (!this.searchForm.start_time) {
        this.pickerOptionsEnd = {
          disabledDate: {}
        }
        return
      }
      this.pickerOptionsEnd = Object.assign({}, self.pickerOptionsEnd, {
        disabledDate(time) {
          return time.getTime() < new Date(self.searchForm.start_time).getTime()
        }
      })
    },
  }
}
</script>

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