
<template>
  <div id='invoice-print'>
    <div v-for='(i,index) in pageArr.length' :key="index" style="width: 80%;margin: 0 auto;">
      <div style="text-align: center;width: 100%;font-size: 20px; font-weight: bolder;">盐城响水燕舞血液透析中心收据</div>
      <div style="display: flex; margin: 15px 0 5px 0;">
        <div style="flex: 1;">业务流水号:{{ list.order_number }}</div>
        <div style="flex: 1;">医疗机构类型:</div>
        <div style="flex: 1;">医院国家编码：H32092103007</div>
       
      </div>
      <div style="display: flex;">
        <div style="flex:1;">医生：{{ doctor_info.user_name }}</div>
        <div style="flex: 1;">医生编码：{{ doctor_info.doctor_number }}</div>
        <div style="flex: 1;">No.{{list.order.fa_piao_number}}</div>
      </div>
      <div style="display: flex;border: 1px solid black;padding: 5px 0;">
        <div style="flex: 1;">姓名：{{ paramsObj.name }}</div>
        <div style="flex: 1;">性别：</div>
        <div style="flex: 1;">医保类型：</div>
        <div style="flex: 1;">社会保障号码：</div>

      </div>
      <div style="display: flex;border: 1px solid black;text-align: center;border-top:none;">
        <div style="flex: 1;display: flex;">
          <div style="flex: 1;border-right: 1px solid black;padding: 5px 0;">项目</div>
          <div style="flex: 1; padding: 5px 0;">金额</div>
        </div>
        <div style="flex: 2;display: flex;border-left: 1px solid black;">
          <div style="flex: 1; padding: 5px 0;">项目/规格</div>
          <div style="flex: 1;border-left: 1px solid black; padding: 5px 0;">数量</div>
          <div style="flex: 1;border-left: 1px solid black; padding: 5px 0;">金额</div>
        </div>
        <div style="flex: 2;display: flex;border-left: 1px solid black;">
          <div style="flex: 1; padding: 5px 0;">项目/规格</div>
          <div style="flex: 1;border-left: 1px solid black; padding: 5px 0;">数量</div>
          <div style="flex: 1;border-left: 1px solid black; padding: 5px 0;">金额</div>
        </div>
      </div>

      <div style="display: flex;border: 1px solid black;border-top:none;min-height: 200px;">
        <div style="flex: 1;" >
          <div v-if="list.westernMedicineCostTotal">西药 &nbsp;&nbsp;{{ list.westernMedicineCostTotal }}</div>
          <div v-if="list.treatCostTotal">治疗费 &nbsp;&nbsp;{{ list.treatCostTotal }}</div>
          <div v-if="list.bedCostTotal">床位费 &nbsp;&nbsp;{{ list.bedCostTotal }}</div>
          <div v-if="list.chineseTraditionalMedicineCostTotal">中成药 &nbsp;&nbsp;{{ list.chineseTraditionalMedicineCostTotal }}</div>
          <div v-if="list.laboratoryCostTotal">化验费 &nbsp;&nbsp;{{ list.laboratoryCostTotal }}</div>
          <div v-if="list.operationCostTotal">手术费 &nbsp;&nbsp;{{ list.operationCostTotal }}</div>
          <div v-if="list.otherCostTotal">其他费 &nbsp;&nbsp;{{ list.otherCostTotal }}</div>
          <div v-if="list.materialCostTotal">材料费 &nbsp;&nbsp;{{ list.materialCostTotal }}</div>
        </div>
        <div style="flex: 2;border-left: 1px solid black;">
          <div v-for="item in list.order_info.slice(index * 10,(index * 10) + pageArr[index])" style="">
            <span style="display:inline-block;width:56%;">
                <span v-if="item.advice.id == 0">
                    <span v-if="item.project.type == 2">{{ item.project.project.project_name }}</span>
                    <span v-if="item.project.type == 3">{{ item.project.good_info.good_name }}</span>
                </span>
                <span v-else>{{ item.advice.advice_name }}</span>
            </span>
            <span style="display:inline-block;width:50px;">
                <span v-if="item.advice.id == 0">
                    <span v-if="item.project.type == 2">{{ item.project.count }}{{ item.project.unit }}</span>
                    <span v-if="item.project.type == 3">{{ item.project.count }}{{ item.project.unit }}</span>
                </span>
                <span v-else>{{ item.advice.prescribing_number }}{{ item.advice.prescribing_number_unit }}</span>
            </span>
            <span>
                <span v-if="item.advice.id == 0">
                    <span v-if="item.project.type == 2">{{ (item.project.count * item.pric).toFixed(2) }}</span>
                    <span v-if="item.project.type == 3">{{ (item.project.count * item.pric).toFixed(2) }}</span>
                </span>
                <span v-else>{{ (item.advice.prescribing_number * item.pric).toFixed(2) }}</span>
            </span>
          </div>
        </div>
        <div style="flex: 2;border-left: 1px solid black;">
          
        </div>
      </div>
      <div style="display: flex;border:1px solid black;border-top: none;">
        <div style="flex: 2; padding: 5px 0;">
          <span style="font-weight: bolder;">合计(大写):</span>
          <span>{{ zhongwen }}</span>
        </div>
        <div style="flex: 1;border-left: 1px solid black; padding: 5px 0;">￥：{{ list.medfee_sumamt }}</div>
      </div>
      <div style="border:1px solid black;border-top: none;height: 80px;">
        <div style="padding: 5px 0; position: relative;">
          <div v-if="index == pageArr.length - 1">
            <div style="display:flex;">
              <div style="flex: 1;">医疗总费用：{{ list.order.medfee_sumamt }}</div>
              <div style="flex: 1;">基金支付总额：{{ list.order.fund_pay_sumamt }}</div>
              <div style="flex: 1;">统筹支出：{{ list.order.hifp_pay }}</div>
              <div style="flex: 1;">大病支出：{{list.order.hifmi_pay}}</div>

            </div>
            <div style="display:flex;">
              <div style="flex: 1;">个人账户支付：{{ list.order.acct_pay }}</div>
              <div style="flex: 1;">现金支出：{{ list.order.psn_cash_pay }}</div>
              <div style="flex: 1;">本次账户：0</div>
              <div style="flex: 1;">上次账户：0</div>
            </div>
            <div style="display:flex;">
              <div style="flex: 1;">账户余额：{{ list.order.balc }}</div>
              <div style="flex: 1;">其他支出：{{ list.order.oth_pay }}</div>
              <div style="flex: 1;">大病补充保险支出：0</div>
              <div style="flex: 1;">民政支出：0</div>
            </div>
            <div style="display:flex;">
              <div style="flex: 1;">医疗救助基金支出：{{ list.order.maf_pay }}</div>
              <div style="flex: 1;">企业补充医疗保险基金支出：{{ list.order.hifes_pay }}</div>
            </div>

          </div>
          <!-- <span style="position: absolute;left: 80%;top: 70%;">(手写无效)</span> -->
        </div>
      </div>
      <div style="display: flex;">
        <div style="flex: 1;">收款单位（章）：{{ org_name }}</div>
        <div style="flex: 1;">收费员：{{ paramsObj.chargeName }}</div>
        <div style="flex: 1;">
          <span>{{  paramsObj.setl_time ? paramsObj.setl_time.split(' ')[0].slice(0,4) : getTime(list.date, '{y}-{m}-{d}').slice(0,4) }}</span>
          年
          <span>{{ paramsObj.setl_time ? parseInt(paramsObj.setl_time.split(' ')[0].slice(5,7)) : getTime(list.date, '{y}-{m}-{d}').slice(5,7) }}</span>
          月
          <span>{{ paramsObj.setl_time ? parseInt(paramsObj.setl_time.split(' ')[0].slice(8,11)) : getTime(list.date, '{y}-{m}-{d}').slice(8,11) }}</span>
          日
          </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getInvoice } from '@/api/project/project'
import { uParseTime } from '@/utils/tools'
export default {
    props:{
        paramsObj:Object
    },
    data(){
        return{
            list:{},
            printDate:'',
            zhongwen:'',
            totalPrice:0.0,
            org_id:'',
            org_name:'',
            page:1,
            pageArr:[],
            doctor_info:{},
        }
    },
    created(){
        console.log('paramsObj',this.paramsObj)
        let params = {
            order_id: this.paramsObj.order_id,
            patient_id: this.paramsObj.patient_id,
        }
        this.getInvoice(params)
        // var data = new Date();
        // var month =data.getMonth() < 9 ? "0" + (data.getMonth() + 1) : data.getMonth() + 1;
        // var date = data.getDate() <= 9 ? "0" + data.getDate() : data.getDate();
        // this.printDate = data.getFullYear() + "-" + month + "-" + date;
        // this.smalltoBIG(982732.21)
        this.org_id = this.$store.getters.xt_user.org_id
        this.org_name = this.$store.getters.xt_user.org.org_name
    },
    methods:{
        getInvoice(params){
            getInvoice(params).then((res) => {
                console.log('res',res)
                this.list = res.data.data
                this.totalPrice = this.list.westernMedicineCostTotal + this.list.checkCostTotal + this.list.treatCostTotal + this.list.bedCostTotal + this.list.chineseTraditionalMedicineCostTotal +
                                    this.list.laboratoryCostTotal + this.list.operationCostTotal + this.list.otherCostTotal + this.list.materialCostTotal
                this.smalltoBIG(this.list.medfee_sumamt)
                var data = new Date(res.data.data.date * 1000);
                var month =data.getMonth() < 9 ? "0" + (data.getMonth() + 1) : data.getMonth() + 1;
                var date = data.getDate() <= 9 ? "0" + data.getDate() : data.getDate();
                this.printDate = data.getFullYear() + "-" + month + "-" + date;
                this.pageArr = []
                this.getPage()
                this.doctor_info = res.data.data.doctor_info
                console.log('pageArr',this.pageArr)
            })
        },
        smalltoBIG(n) {
            // let fraction = ['角', '分'];
            // let digit = ['零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖'];
            // let unit = [['元.', '万,', '亿,'], ["元",'拾', '佰', '仟']];
            // let head = price < 0 ? '欠' : '';
            // price = Math.abs(price);
            // let upper = '';
            // for (let i = 0; i < fraction.length; i++) {
            // upper += (digit[Math.floor(price * 10 * Math.pow(10, i)) % 10] + fraction[i]).replace(/零./, '');
            // }
            // upper = upper || '整';
            // price = Math.floor(price);
            // for (let i = 0; i < unit[0].length && price > 0; i++) {
            // let p = '';
            // for (let j = 0; j < unit[1].length && price > 0; j++) {
            //     p = digit[price % 10] + unit[1][j] + p;
            //     price = Math.floor(price / 10);
            // }
            // upper = p.replace(/(零.)*零$/, '').replace(/^$/, '零') + unit[0][i] + upper;
            // }
            // this.zhongwen = head + upper.replace(/(零.)*零圆/, '圆').replace(/(零.)+/g, '零').replace(/^整$/, '零圆整')
            // console.log('6666',head + upper.replace(/(零.)*零圆/, '圆').replace(/(零.)+/g, '零').replace(/^整$/, '零圆整'))
            if (!/^(0|[1-9]\d*)(\.\d+)?$/.test(n)){
                return "数据非法";  //判断数据是否大于0
            }

            var unit = "仟佰拾亿仟佰拾万仟佰拾元角分", str = "";
            n += "00";

            var indexpoint = n.indexOf('.');  // 如果是小数，截取小数点前面的位数

            if (indexpoint >= 0){

                n = n.substring(0, indexpoint) + n.substr(indexpoint+1, 2);   // 若为小数，截取需要使用的unit单位
            }

            unit = unit.substr(unit.length - n.length);  // 若为整数，截取需要使用的unit单位
            for (var i=0; i < n.length; i++){
                str += "零壹贰叁肆伍陆柒捌玖".charAt(n.charAt(i)) + unit.charAt(i);  //遍历转化为大写的数字
            }
            console.log("str",str)
            if(str == '零元零角零分'){
                this.zhongwen = '零'
            }else{
                this.zhongwen =  str.replace(/零(仟|佰|拾|角)/g, "零").replace(/(零)+/g, "零").replace(/零(万|亿|元)/g, "$1").replace(/(亿)万|壹(拾)/g, "$1$2").replace(/^元零?|零分/g, "").replace(/元$/g, "元整");
            }

            console.log(this.zhongwen)
        },
        getTime(value, temp) {
            if (value == 0) {
                return ''
            }
            if (value != undefined) {
                return uParseTime(value, temp)
            }
            return ''
        },
        getPage(){
        if(this.list.order_info.length <= 10){
            this.page = 1
            this.pageArr.push(this.list.order_info.length)
        }else if(this.list.order_info.length > 10){
            this.page = parseInt(this.list.order_info.length / 10)
            let num = this.list.order_info.length % 10
            for (var i=0;i<this.page;i++){
                this.pageArr.push(10)
            }
            if(num != 0){
                this.pageArr.push(num)
            }
        }
      }

    },
    watch:{
        paramsObj:{//深度监听，可监听到对象、数组的变化
            handler(val, oldVal){
                let params = {
                    order_id: val.order_id,
                    patient_id: val.patient_id,
                }
                this.getInvoice(params)

            },
            deep:true
        }
    }
}
</script>
