<template>
  <!-- 发货打印 -->
  <div>
    <a-spin :spinning="spinning" tip="Loading..." style="height: 60vh;overflow: auto;width: 100%;padding:20px 40px;">
      <div id="sendGood-print" v-if="financeBookList&&financeBookList.length">
        <table
          v-for="(fcItem,index) in financeBookList"
          :key="index+'-fcitem'"
          ref="printBox"
          cellspacing="0"
          cellpadding="0"
          style="border-collapse: collapse;width: 562pt;margin:0 auto;font-size:14px;">
          <tr>
            <td>
              <div class="print-box" style="width: 562pt;margin:0 auto;">
                <h1 style="text-align:center;margin:0.2cm 0">收款通知单</h1>
                <div>
                  <div>
                    <table border="1" style="width: 562pt;border-collapse: collapse;text-align: center;">
                      <tr>
                        <th style="line-height: 20pt;width: 50pt;background:#f6f6f6;">日期</th>
                        <th style="line-height: 20pt;width: 82pt;background:#f6f6f6;">客户名称</th>
                        <th style="line-height: 20pt;width: 60pt;background:#f6f6f6;">订单金额</th>
                        <th style="line-height: 20pt;width: 60pt;background:#f6f6f6;">收款金额</th>
                        <th style="line-height: 20pt;width: 60pt;background:#f6f6f6;">使用授信</th>
                        <th style="line-height: 20pt;width: 60pt;background:#f6f6f6;">余款抵扣</th>
                        <th style="line-height: 20pt;width: 60pt;background:#f6f6f6;">汇入银行</th>
                        <th style="line-height: 20pt;width: 60pt;background:#f6f6f6;">足额打款</th>
                        <th style="line-height: 20pt;width: 70pt;background:#f6f6f6;">说明</th>
                      </tr>
                      <tr v-for="item in fcItem.subList" :key="item.bookDetailSn">
                        <td style="padding:3pt;width: 44pt;">{{ moment(item.receiptDate).format('M月D日') }}</td>
                        <td style="padding:3pt;width: 76pt;text-align:left;">
                          {{ item.payerName }}
                          <div>
                            {{ item.dealerEntity ? item.dealerEntity.kdMidCustomerFnumber : '' }}
                          </div>
                        </td>
                        <td style="padding:3pt;width: 54pt;text-align:center;">
                          {{ item.orderAmount?item.orderAmount.toFixed(2):'0.00' }}
                        </td>
                        <td style="padding:3pt;width: 54pt;text-align:center;">
                          {{ item.receiptAmount?item.receiptAmount.toFixed(2):'0.00' }}
                        </td>
                        <td style="padding:3pt;width: 54pt;text-align:center;">
                          {{ getTotal(item.detailItemUseList||[]) }}
                        </td>
                        <td style="padding:3pt;width: 54pt;text-align:center;">
                          {{ item.balanceAmount?item.balanceAmount.toFixed(2):'0.00' }}
                        </td>
                        <td style="padding:3pt;width: 54pt;">
                          {{ item.bankAccount }}<br>
                          {{ item.bankName }}
                        </td>
                        <td style="padding:3pt;width: 54pt;">{{ item.fullPaymentFlagDictValue }}</td>
                        <td style="padding:3pt;width: 84pt;word-break:break-all;">{{ item.remarks }}</td>
                      </tr>
                    </table>
                    <div style="line-height: 30pt;border-bottom: 1px solid #666;">使用授信明细：{{ fcItem.detail }}</div>
                    <div style="line-height: 30pt;">审批人员：</div>
                  </div>
                </div>
              </div>
            </td>
          </tr>
        </table>
      </div>
    </a-spin>
    <div class="btn-box" style="display:flex;align-item:center;justify-content: center;">
      <a-button @click="handleCommonCancel">取消</a-button>
      <a-button :loading="spinning" type="primary" @click="handleCommonOk">立即打印</a-button>
    </div>
  </div>
</template>

<script>
import { jGPrint } from '@/libs/JGPrint.js'
import moment from 'moment'
export default {
  data () {
    return {
      spinning: false,
      detail: null,
      financeBookList: []
    }
  },
  methods: {
    moment,
    getTotal (data) {
      let ret = 0
      data.map(item => {
        ret = ret + item.itemAmount
        delete item.id
      })
      return ret.toFixed(2)
    },
    handleCommonOk () {
      const _this = this
      const html = document.getElementById('sendGood-print').innerHTML
      _this.spinning = true
      // html, type, callback, printLogParams
      jGPrint(html, 'print', function (res) {
        _this.spinning = false
        _this.handleCommonCancel()
        _this.$emit('printOk')
      })
    },
    getData (data, flag) {
      console.log(data)
      this.financeBookList = data
    },
    handleCommonCancel () {
      this.$emit('cancel')
      this.detail = null
      this.financeBookList = []
    },
    clearData () {
      this.detail = null
      this.financeBookList = []
    }
  }
}
</script>

<style>
</style>
