<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-select v-model="searchForm.draft_type" placeholder="请选择" clearable>
            <el-option label="全部" value=""></el-option>
            <el-option label="纸票" value="type-00"></el-option>
            <el-option label="电票" value="type-01"></el-option>
            <el-option label="商票" value="type-02"></el-option>
            <el-option label="现金" value="type-03"></el-option>
          </el-select>
        </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 type="primary" icon="el-icon-search" @click="fetchData">搜索</el-button>
        </el-form-item>
      </el-form>
    </div>
    <!-- 表格 -->
    <div class="mb-10 f700">
      <span>金额合计：{{fee_sum}}</span>
    </div>
    <el-table v-loading="listLoading" :data="firmList" border fit highlight-current-row style="width: 100%;">
      <el-table-column label="ID" prop="order_id" align="center" width="80"></el-table-column>
      <el-table-column label="入账时间" prop="input_time" align="center"></el-table-column>
      <el-table-column label="供应商名称" prop="supplier_name" align="center"></el-table-column>
      <el-table-column label="转账明细" prop="draft_detail" align="center"></el-table-column>
      <el-table-column label="票号" prop="draft_num" align="center"></el-table-column>
      <el-table-column label="票据类型" prop="draft_type" align="center">
        <template slot-scope="scope">
          {{getDraftType(scope.row.draft_type)}}
        </template>
      </el-table-column>
      <el-table-column label="金额" prop="order_fee" align="center"></el-table-column>
      <el-table-column label="出票日" prop="output_date" align="center"></el-table-column>
      <el-table-column label="到期日" prop="expire_date" align="center"></el-table-column>
      <el-table-column label="备注" prop="draft_note" 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/draftEdit/'+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>
</template>

<script>
import { listDraft } from '@/api/order/index'

export default {
  data() {
    return {
      firmList: [],  // 列表
      total: 0,  // 总数
      fee_sum: 0, // 金额合计
      listLoading: true,
      // 搜索相关数据
      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(listDraft(this.searchForm), (res) => {
        this.firmList = res.data.result
        this.total = res.data.data_sum
        this.fee_sum = res.data.fee_sum
        this.listLoading = false
      })
    },
    // 配送产品
    getDraftType(value) {
      let obj = {
        "type-00": "纸票",
        "type-01": "电票",
        "type-02": "商票",
        "type-03": "现金"
      }
      return obj[value]
    },
    // 结束时间限制开始时间
    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>
  
</style>