<!-- 付款账单 -->
<template>
  <div class="container">
    <my-table :data="data" :columns="columns" :table-filter="tableFilter" :table-page="params" @event-handle="eventHandle" @on-change="changePage"></my-table>
    <bill-modal v-model="show" :data="formData"></bill-modal>
  </div>
</template>

<script>
import { GetPaymentBill } from '@/api/applyPurchase'
import MyTable from '_c/my-table/my-table'
import BillModal from './bill-modal'
import { exportExcel } from '@/libs/util'
export default {
  name: 'material_bill',
  components: {
    MyTable,
    BillModal
  },
  data () {
    return {
      formData: {},
      show: false,
      data: [{}],
      columns: [
        {
          title: '序号',
          type: 'index',
          width: 60,
          align: 'center'
        },
        {
          title: '账单时间',
          key: 'billTime',
          minWidth: 150
        },
        {
          title: '付款期限',
          key: 'payLimitTime',
          minWidth: 150
        },
        {
          title: '明细数量',
          key: 'detailNum',
          minWidth: 150
        },
        {
          title: '累计应付',
          key: 'totalAmount',
          minWidth: 150
        },
        {
          title: '查看详情',
          key: 'purchaseBillNo',
          minWidth: 100,
          fixed: 'right',
          align: 'center',
          render: (h, params) => {
            let _this = this
            return h('a', {
              on: {
                click () {
                  _this.formData = { ...params.row }
                  _this.show = true
                }
              }
            }, '查看详情')
          }
        }
      ],
      tableFilter: [
        {
          name: 'Input',
          value: 'keyword',
          placeholder: '请输入关键字'
        },
        {
          name: 'Button',
          type: 'primary',
          text: '查询',
          e: 'search'
        },
        {
          name: 'Button',
          type: 'primary',
          text: '导出Excel',
          e: 'export'
        }
      ],
      params: {
        pageIndex: 1,
        pageSize: 20,
        total: 0
      }
    }
  },
  methods: {
    cfm (type, formData) {
      if (type === 'add') {
        FacPriceAdd({
          ...formData,
          materialCode: formData.code
        }).then(res => {
          if (res.code === 0) {
            this.$Message.info(res.msg)
            this.getList()
          }
        })
      } else if (type === 'edit') {
        FacPriceChange({
          ...formData,
          factoryPriceId: formData.id
        }).then(res => {
          if (res.code === 0) {
            this.$Message.info(res.msg)
            this.getList()
          }
        })
      }
    },
    // 检索条件事件处理
    eventHandle (option) {
      switch (option._evnet) {
        case 'search':
          this.params.pageIndex = 1
          this.params.keyWord = option.key
          this.getList()
          break
        case 'add':
          this.formType = 'add'
          this.show = true
          break
        case 'back':
          this.$router.go(-1)
          break
        case 'export':
          GetPaymentBill({
            ...this.params,
            pageIndex: 1,
            pageSize: 99999
          }).then(res => {
            if (res.code === 0) {
              let data = res.result.list
              if (data.length < 1) return this.$Message.error('数据为空！')
              exportExcel(this.columns, data, '合同账单')
            }
          })
          break
      }
    },
    changePage (pageIndex) {
      this.params.pageIndex = pageIndex
      this.getList()
    },
    getList () {
      GetPaymentBill(this.params).then(res => {
        if (res.code === 0) {
          this.data = res.result.list
          this.params.total = res.result.totalCount
        }
      })
    }
  },
  mounted () {
    this.getList()
  }
}
</script>

<style lang="less" scoped>
.container {
  height: 100%;
}
</style>
