<template>
  <!-- 发货打印 -->
  <div>
    <div id="sendGood-print" style="height:500px;overflow:auto;" v-if="financeBookList&&financeBookList.length">
      <div
        v-for="(fcItem,index) in financeBookList"
        class="sendGood-print-box"
        :key="index+'-fcitem'"
        style="width:564pt;margin:0 auto;">
        <table
          ref="printBox"
          cellspacing="0"
          cellpadding="0"
          style="border-collapse: collapse;width: 564pt;font-size:14px;line-height: normal;">
          <tr>
            <td>
              <div class="print-box" style="width: 564pt;margin-left:1.5pt;">
                <div style="text-align:center;margin:5pt 0;font-size:20px;font-weight: bold;">收款通知单</div>
                <div>
                  <div>
                    <table border="1" style="width: 564pt;border-collapse: collapse;text-align: center;">
                      <tr>
                        <th style="width: 36pt;background:#f6f6f6;">日期</th>
                        <th style="background:#f6f6f6;width: 82pt;">客户名称</th>
                        <th style="background:#f6f6f6;width: 82pt;">营业执照<br>名称</th>
                        <th style="width: 53pt;background:#f6f6f6;">订单金额</th>
                        <th style="width: 53pt;background:#f6f6f6;">收款金额</th>
                        <th style="width: 53pt;background:#f6f6f6;">使用授信</th>
                        <th style="width: 53pt;background:#f6f6f6;">授信还款</th>
                        <th style="width: 53pt;background:#f6f6f6;">汇入银行</th>
                        <th style="width: 37pt;background:#f6f6f6;">足额<br>打款</th>
                        <th style="width: 64pt;background:#f6f6f6;">说明</th>
                      </tr>
                      <tr v-for="item in fcItem.subList" :key="item.bookDetailSn">
                        <td style="padding:3pt 1pt;width: 34pt;">{{ item.receiptDate.split('-')[0] }}<br>{{ item.receiptDate.split('-')[1]+'/'+item.receiptDate.split('-')[2] }}</td>
                        <td style="padding:3pt 1pt;width: 80pt;word-break:break-all;">
                          {{ item.payerName }}
                          <div>
                            {{ item.dealerEntity ? item.dealerEntity.kdMidCustomerFnumber : '' }}
                          </div>
                        </td>
                        <td style="padding:3pt 1pt;width: 80pt;word-break:break-all;">
                          {{ item.payerAccountInfo }}
                        </td>
                        <td style="padding:3pt 1pt;width: 51pt;text-align:center;">
                          {{ item.orderAmount?item.orderAmount.toFixed(2):'0.00' }}
                        </td>
                        <td style="padding:3pt 1pt;width: 51pt;text-align:center;">
                          {{ item.receiptAmount?item.receiptAmount.toFixed(2):'0.00' }}
                        </td>
                        <td style="padding:3pt 1pt;width: 51pt;text-align:center;">
                          {{ getTotal(item.detailItemUseList||[]) }}
                        </td>
                        <td style="padding:3pt 1pt;width: 51pt;text-align:center;">
                          {{ item.payCreditAmount?item.payCreditAmount.toFixed(2):'0.00' }}
                        </td>
                        <td style="padding:3pt 1pt;width: 51pt;">
                          {{ item.bankAccount }}<br>
                          {{ item.bankName }}
                        </td>
                        <td style="padding:3pt 1pt;width: 35pt;">{{ item.fullPaymentFlagDictValue }}</td>
                        <td style="padding:3pt 1pt;width: 62pt;word-break:break-all;">{{ item.explainInfo }}</td>
                      </tr>
                    </table>
                    <div style="padding:5pt 0;border-bottom: 1px solid #999;overflow:hidden;">
                      <div style="width:49%;display:flex;float:left;">使用授信明细：<div>{{ fcItem.detail||'暂无' }}</div></div>
                      <div style="width:49%;display:flex;float:right;">授信还款明细：<div>{{ fcItem.payDetail||'暂无' }}</div></div>
                    </div>
                    <div style="padding:5pt 0;border-bottom: 1px solid #999;overflow:hidden;" v-if="!hideBookReson">
                      收款事由：{{ fcItem.subList[0]['bookReason']||'暂无' }}
                    </div>
                    <div style="padding:5pt 0;">
                      审批人员：{{ fcItem.audit||'暂无' }}
                    </div>
                  </div>
                </div>
              </div>
            </td>
          </tr>
        </table>
      </div>
    </div>
    <div class="btn-box" style="display:flex;align-item:center;justify-content: center;" v-if="financeBookList&&financeBookList.length">
      <a-button @click="handleCommonCancel">取消</a-button>
      <a-button :loading="spinning" type="primary" @click="handleCommonOk">立即打印</a-button>
    </div>
  </div>
</template>

<script>
import { jGPlPrint, groupLessThan } from '@/libs/JGPrint.js'
import moment from 'moment'
export default {
  data () {
    return {
      spinning: false,
      detail: null,
      financeBookList: [],
      printNums: [],
      hideBookReson: false
    }
  },
  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.getElementsByClassName('sendGood-print-box')
      const result = groupLessThan(html, false)
      this.$store.state.app.curActionPermission = 'B_SkPrint'
      // html, type, callback, printLogParams
      this.spinning = true
      jGPlPrint(result, 'print', function (res) {
        if (res) {
          _this.handleCommonCancel()
        }
        _this.$emit('printOk', res)
        _this.spinning = false
      }, this.printNums, '收款单')
    },
    getData (data, list, hideBookReson) {
      console.log(data, list)
      this.hideBookReson = hideBookReson
      this.financeBookList = data
      list.map(item => {
        this.printNums.push({
          billType: 'FINANCE_BOOK_DETAIL',
          billSn: item.bookDetailSn,
          billNo: item.bookNo,
          printType: '收款打印'
        })
      })
    },
    handleCommonCancel () {
      this.$emit('cancel')
      this.clearData()
    },
    clearData () {
      this.detail = null
      this.financeBookList = []
      this.printNums = []
      this.$store.state.app.curActionPermission = ''
    }
  }
}
</script>

<style>
</style>
