<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;">
          <tr>
            <td>
              <div class="print-box" style="width: 564pt;margin-left:1.5pt;">
                <div style="text-align:center;margin:5pt 0;font-size:22px;font-weight: bold;">收款通知单</div>
                <div>
                  <div>
                    <table border="1" style="width: 564pt;border-collapse: collapse;text-align: center;">
                      <tr>
                        <th style="width: 56pt;background:#f6f6f6;">日期</th>
                        <th style="width: 62pt;background:#f6f6f6;">客户名称</th>
                        <th style="width: 62pt;background:#f6f6f6;">营业执照名称</th>
                        <th style="width: 54pt;background:#f6f6f6;">订单金额</th>
                        <th style="width: 54pt;background:#f6f6f6;">收款金额</th>
                        <th style="width: 54pt;background:#f6f6f6;">使用授信</th>
                        <th style="width: 54pt;background:#f6f6f6;">余款抵扣</th>
                        <th style="width: 54pt;background:#f6f6f6;">汇入银行</th>
                        <th style="width: 54pt;background:#f6f6f6;">足额打款</th>
                        <th style="width: 60pt;background:#f6f6f6;">说明</th>
                      </tr>
                      <tr v-for="item in fcItem.subList" :key="item.bookDetailSn">
                        <td style="padding:3pt 1pt;width: 50pt;">{{ moment(item.receiptDate).format('YYYY/MM/DD') }}</td>
                        <td style="padding:3pt 1pt;width: 56pt;text-align:left;">
                          {{ item.payerName }}
                          <div>
                            {{ item.dealerEntity ? item.dealerEntity.kdMidCustomerFnumber : '' }}
                          </div>
                        </td>
                        <td style="padding:3pt 1pt;width: 56pt;text-align:left;word-break:break-all;">
                          {{ item.payerAccountInfo }}
                        </td>
                        <td style="padding:3pt 1pt;width: 48pt;text-align:center;">
                          {{ item.orderAmount?item.orderAmount.toFixed(2):'0.00' }}
                        </td>
                        <td style="padding:3pt 1pt;width: 48pt;text-align:center;">
                          {{ item.receiptAmount?item.receiptAmount.toFixed(2):'0.00' }}
                        </td>
                        <td style="padding:3pt 1pt;width: 48pt;text-align:center;">
                          {{ getTotal(item.detailItemUseList||[]) }}
                        </td>
                        <td style="padding:3pt 1pt;width: 48pt;text-align:center;">
                          {{ item.balanceAmount?item.balanceAmount.toFixed(2):'0.00' }}
                        </td>
                        <td style="padding:3pt 1pt;width: 48pt;">
                          {{ item.bankAccount }}<br>
                          {{ item.bankName }}
                        </td>
                        <td style="padding:3pt 1pt;width: 48pt;">{{ item.fullPaymentFlagDictValue }}</td>
                        <td style="padding:3pt 1pt;width: 54pt;word-break:break-all;">{{ item.explainInfo }}</td>
                      </tr>
                    </table>
                    <div style="padding:5pt 0;border-bottom: 1px solid #333;">使用授信明细：{{ fcItem.detail||'暂无。' }}</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: []
    }
  },
  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) {
      console.log(data, list)
      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>
