<template>
  <style id="printPaymentApprovalStyle">
   #printPaymentApproval td {
      height: 60px;
      text-align: center;
    }

   #printPaymentApproval table {
      margin: auto;
      width: 100%;
      border-collapse: collapse;
      border: 1px solid black;
    }
   #printPaymentApproval h1,
   #printPaymentApproval h2,
   #printPaymentApproval h3,
   #printPaymentApproval h4,
   #printPaymentApproval h5,
   #printPaymentApproval h6 {
      text-align: center;
    }

   #printPaymentApproval  .orgs {
      border-bottom: 2px solid;
      padding: 5px;
    }

   #printPaymentApproval  .date {
      float: left;
      padding-left: 10px;
    }

   #printPaymentApproval  .status {
      float: right;
      padding-right: 10px;
    }

   #printPaymentApproval  .seal {
      position: absolute;
      right: 100px;
      top: 120px;
      width: 150px;
      height: 150px;
      /*opacity: 0.5;*/
      z-index: -1;
    }
  </style>
  <div style="margin-bottom: 20px" class="form-group select-overspread">
    <label class="control-label-justify control-label col-sm-10">打印付款审批单</label>
    <div class="col-sm-2">
      <button class="button_search button_spacing" type="button" style="width: max-content;position: absolute"
              @click="openModal()">打印预览
      </button>
    </div>
  </div>
  <modal v-if="showModal" :show.sync="showModal" title="打印预览" v-ref:modal large backdrop="false">
    <header slot="modal-header" class="modal-header">
      <button type="button" class="close" @click="colseModal()"><span>&times;</span></button>
      <h4 class="modal-title">打印预览</h4>
    </header>
    <article slot="modal-body" class="modal-body">
      <div id="printPaymentApproval">
        <h4>
          榆 林 榆 川 天 然 气 有 限 责 任 公 司
        </h4>
        <h2>
        付 款 审 批 单
        </h2>
        <table style="border: 0px solid black;">
          <tr>
            <td style="height: 30px;">{{ new Date().Format('yyyy年MM月dd日') }}</td>
          </tr>
        </table>
        <table border="1" width="100%">
          <tr>
            <td style="width: 17%">收款单位名称：</td>
            <td colspan="2" style="border: none">
              {{ selectdata.f_paper_name }}
            </td>
            <td style="width: 17%">付 款 方 式：</td>
            <td colspan="2" style="border: none">
              {{ selectdata.f_payment_method }}
            </td>
          </tr>
          <tr>
            <td style="width: 17%">开 户 银 行：</td>
            <td colspan="2" style="width: 33%">{{ selectdata.f_bank }}</td>
            <td style="width: 17%">账&emsp;&emsp;号：</td>
            <td colspan="2" style="width: 33%">{{ selectdata.f_paper_account }}</td>
          </tr>
          <tr>
            <td>付 款 事 由：</td>
            <td colspan="5" style="text-align:left">
              {{ selectdata.f_pay_remark }}
            </td>
          </tr>
          <tr>
            <td>付款金额(元、大写):</td>
            <td colspan="2">{{ selectdata.f_amount_words }}</td>
            <td>付款金额(元、小写):</td>
            <td colspan="2">{{ selectdata.f_due_money }}</td>
          </tr>
          <tr>
            <td style="width: 17%">备&emsp;&emsp;注：</td>
            <td colspan="2" style="width: 33%">{{ selectdata.f_payment_remarks }}</td>
            <td style="width: 17%">附件张数：</td>
            <td colspan="2" style="width: 33%">{{ selectdata.f_attachment_count }}</td>
          </tr>
        </table>
        <table style="border: 0px solid black;">
          <tr>
            <td>财务部门负责人：</td>
            <td>&emsp;&emsp;</td>
            <td>部门负责人：</td>
            <td>&emsp;&emsp;</td>
            <td>经办人：</td>
            <td>&emsp;&emsp;</td>
          </tr>
          <tr>
            <td>单位负责人：</td>
            <td>&emsp;&emsp;</td>
            <td>财务主管：</td>
            <td>&emsp;&emsp;</td>
            <td>分管领导：</td>
            <td>&emsp;&emsp;</td>
          </tr>
        </table>
      </div>
    </article>
    <footer slot="modal-footer" class="modal-footer">
      <button type="button" class="btn btn-primary" @click="print()">打印</button>
    </footer>
  </modal>

  <apply-print-element v-show="false" v-ref:print id='printPayentApproval' styleid='printPaymentApprovalStyle'
                 top='20' left='30' width='100%' height='100%'>
  </apply-print-element>
</template>

<script>
import {isEmpty} from '../../../../Util'
import {HttpResetClass} from "vue-client";

Date.prototype.Format = function (fmt) {
  var o = {
    'M+': this.getMonth() + 1, // 月份
    'd+': this.getDate(), // 日
    'H+': this.getHours(), // 小时
    'm+': this.getMinutes(), // 分
    's+': this.getSeconds(), // 秒
    'q+': Math.floor((this.getMonth() + 3) / 3), // 季度
    'S': this.getMilliseconds() // 毫秒
  }
  if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length))
  for (var k in o)
    if (new RegExp('(' + k + ')').test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (('00' + o[k]).substr(('' + o[k]).length)))
  return fmt
}
export default {
  title: '打印付款审批单',
  props: ['selectdata'],
  data () {
    return {
      showModal: false,
      device: null
    }
  },
  ready () {
  },
  methods: {
    openModal () {
      if (this.selectdata.f_due_money >= 0 && this.selectdata.f_due_money) {
        this.smalltoBIG(this.selectdata.f_due_money)
      } else {
        this.selectdata.f_amount_words = ''
      }
      this.showModal = true
    },
    colseModal () {
      this.showModal = false
    },
    print () {
      this.showInput = false
      setTimeout(() => {
        this.$refs.print.PrintTable()
      }, 10)
    },
    // 金额转大写
    smalltoBIG (n) {
      let fraction = ['角', '分']
      let digit = ['零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖']
      let unit = [['元', '万', '亿'], ['', '拾', '佰', '仟']]
      let head = n < 0 ? '欠' : ''
      n = Math.abs(n)

      let s = ''

      for (var i = 0; i < fraction.length; i++) {
        s += (digit[Math.floor(n * 10 * Math.pow(10, i)) % 10] + fraction[i]).replace(/零./, '')
      }
      s = s || '整'
      n = Math.floor(n)

      for (var i = 0; i < unit[0].length && n > 0; i++) {
        let p = ''
        for (var j = 0; j < unit[1].length && n > 0; j++) {
          p = digit[n % 10] + unit[1][j] + p
          n = Math.floor(n / 10)
        }
        s = p.replace(/(零.)*零$/, '').replace(/^$/, '零') + unit[0][i] + s
      }
      let result = head + s.replace(/(零.)*零元/, '元').replace(/(零.)+/g, '零').replace(/^整$/, '零元整')
      console.log('当前大写', result)
      this.selectdata.f_amount_words = result
    }
  },
  computed: {
    orgs () {
      return this.$login.f.f_fengongsi
    },
    src () {
    }
  }
}
</script>

<style scoped>

</style>
