<template>
    <div>
        <div id='prescription-print' class="prescription-print">
            <div v-if=" this.$store.getters.xt_user.org_id == 9504 || this.$store.getters.xt_user.org_id == 10028 || this.$store.getters.xt_user.org_id == 10138 || this.$store.getters.xt_user.org_id == 10278">
                <div class="printTitle">{{orgname}}&nbsp;&nbsp;医药费收据及收费项目清单</div>
                <div class="infoMain">
                    <div class="infoP">医院(药店)编号：{{org_code}}</div>
                    <div class="infoP">名称：{{orgname}}</div>
                    <div class="infoP">医生工号：{{doctor_code}}</div>
                    <div class="infoP">门诊流水号：{{result.transBody.akc190}}</div>
                    <div class="infoP">科别：{{全科}}</div>
                    <div class="infoP">处方单据号：</div>
                    <div class="infoP">姓名：{{patient_name}}</div>
                    <div class="infoP">医疗账号：</div>
                    <div class="infoP">医疗类别：普通</div>
                </div>
                <div class="chargeBox">
                    <div style="display:flex;justify-content: space-between;border-bottom:1px solid #000;">
                        <div class="chargeUl" style="width:20%;">
                            <p style="width:50%;border-right:1px solid #000;">费用类型</p>
                            <p style="width:50%;border-right:1px solid #000;">金额</p>
                        </div>
                        <div class="chargeUl" style="width:80%;">
                            <p style="width:40%;border-right:1px solid #000;">明细名称</p>
                            <p style="width:15%;border-right:1px solid #000;">规格</p>
                            <p style="width:15%;border-right:1px solid #000;">数量</p>
                            <p style="width:15%;border-right:1px solid #000;">单价</p>
                            <p style="width:15%;">金额</p>
                        </div>
                    </div>
                    <div style="display:flex;justify-content: space-between;">
                        <div style="width:20%;">
                            <div class="chargeUl" v-for="(item,index) in result.transBody.outputlist2" :key="index">
                                <p style="width:50%;">{{getItemName(item.aka111)}}</p>
                                <p style="width:50%;">{{item.bka058}}</p>
                            </div>
                            <div class="chargeUl" style="border-top:1px solid #000;">
                                <p style="width:50%;">费用合计</p>
                                <p style="width:50%;">{{result.transBody.akc264}}</p>
                            </div>
                            <div class="chargeUl" style="border-top:1px solid #000;">
                                <p style="width:50%;">记账支付</p>
                                <p style="width:50%;">{{result.transBody.akb068}}</p>
                            </div>
                            <div class="chargeUl" style="border-top:1px solid #000;">
                                <p style="width:50%;">个人账号</p>
                                <p style="width:50%;">{{result.transBody.akc264}}</p>
                            </div>
                            <div class="chargeUl" style="border-top:1px solid #000;border-bottom:1px solid #000;">
                                <p style="width:50%;">现金支付</p>
                                <p style="width:50%;">{{result.transBody.akb067}}</p>
                            </div>
                        </div>
                        <div style="width:80%;display:flex;height:300px;">

                            <div style="border-left:1px solid #000;border-right:1px solid #000;width:40%;text-align:center;">
                                <p v-for="(item,i) in name_arr" :key="i" class="chargeP">
                                    {{item}}</p>
                            </div>
                            <div style="border-right:1px solid #000;width:15%;text-align:center;">
                                <p v-for="(item,y) in spec_arr" :key="y" class="chargeP">
                                    {{item}}</p>
                            </div>
                            <div style="border-right:1px solid #000;width:15%;text-align:center;">
                                <p v-for="(item,z) in count_arr" :key="z" class="chargeP">
                                    {{item}}次</p>
                            </div>
                            <div style="border-right:1px solid #000;width:15%;text-align:center;">
                                <p v-for="(item,f) in price_arr" :key="f" class="chargeP">{{item}}</p>
                            </div>
                            <div style="width:15%;text-align:center;">
                                <p v-for="(item,d) in total_arr" :key="d" class="chargeP">{{item}}</p>
                            </div>
                        </div>
                    </div>

                </div>
                <div class="moneyBox">
                    <p>实收金：{{result.transBody.akc264}}</p>
                    <p>记账前金额：{{0.00}}</p>
                    <p>扣款金额：{{0.00}}</p>
                    <p>记账后金额：{{0.00}}</p>
                    <p>找赎金：{{0.00}}</p>
                </div>
                <div class="actionBar">
                    <div>收费员：{{doctor_name}}</div>
                    <div>日期：{{this.$route.query.record_date}}</div>
                </div>
            </div>

            <div v-else>
                <div class="printTitle">{{orgname}}&nbsp;&nbsp;医药费收据及收费项目清单</div>
                <div class="infoMain">
                    <div class="infoP">医院(药店)编号：</div>
                    <div class="infoP">名称：{{orgname}}</div>
                    <div class="infoP">医生工号：</div>
                    <div class="infoP">门诊流水号：</div>
                    <div class="infoP">科别：{{list.p_info.departments?list.p_info.departments:''}}</div>
                    <div class="infoP">处方单据号：</div>
                    <div class="infoP">姓名：{{patient.name}}</div>
                    <div class="infoP">医疗账号：</div>
                    <div class="infoP">医疗类别：普通</div>
                </div>
                <div class="chargeBox">
                    <div style="display:flex;justify-content: space-between;border-bottom:1px solid #000;">
                        <div class="chargeUl" style="width:20%;">
                            <p style="width:50%;border-right:1px solid #000;">费用类型</p>
                            <p style="width:50%;border-right:1px solid #000;">金额</p>
                        </div>
                        <div class="chargeUl" style="width:80%;">
                            <p style="width:40%;border-right:1px solid #000;">明细名称</p>
                            <p style="width:15%;border-right:1px solid #000;">规格</p>
                            <p style="width:15%;border-right:1px solid #000;">数量</p>
                            <p style="width:15%;border-right:1px solid #000;">单价</p>
                            <p style="width:15%;">金额</p>
                        </div>
                    </div>
                    <div style="display:flex;justify-content: space-between;">
                        <div style="width:20%;">
                            <div class="chargeUl" v-for="(item,index) in 1" :key="index">
                                <p style="width:50%;">材料费</p>
                                <p style="width:50%;"></p>
                            </div>
                            <div class="chargeUl" style="border-top:1px solid #000;">
                                <p style="width:50%;">费用合计</p>
                                <p style="width:50%;">
                                    {{list.order_info.medfee_sumamt?list.order_info.medfee_sumamt:''}}</p>
                            </div>
                            <div class="chargeUl" style="border-top:1px solid #000;">
                                <p style="width:50%;">记账支付</p>
                                <p style="width:50%;"></p>
                            </div>
                            <div class="chargeUl" style="border-top:1px solid #000;">
                                <p style="width:50%;">个人账号</p>
                                <p style="width:50%;"></p>
                            </div>
                            <div class="chargeUl" style="border-top:1px solid #000;border-bottom:1px solid #000;">
                                <p style="width:50%;">现金支付</p>
                                <p style="width:50%;">{{list.order_info.psn_cash_pay}}</p>
                            </div>
                        </div>
                        <div style="width:80%;display:flex;height:300px;">

                            <div style="border-left:1px solid #000;border-right:1px solid #000;width:40%;text-align:center;">
                                <p v-for="(item,i) in prescription[0].advices" :key="i" class="chargeP">
                                    {{item.advice_name}}</p>
                            </div>
                            <div style="border-right:1px solid #000;width:15%;text-align:center;">
                                <p v-for="(item,y) in prescription[0].advices" :key="y" class="chargeP">
                                    {{item.advice_desc}}</p>
                            </div>
                            <div style="border-right:1px solid #000;width:15%;text-align:center;">
                                <p v-for="(item,z) in prescription[0].advices" :key="z" class="chargeP">
                                    {{item.single_dose}}个</p>
                            </div>
                            <div style="border-right:1px solid #000;width:15%;text-align:center;">
                                <p v-for="(item,f) in prescription[0].advices" :key="f" class="chargeP">
                                    {{item.price}}</p>
                            </div>
                            <div style="width:15%;text-align:center;">
                                <p v-for="(item,d) in prescription[0].advices" :key="d" class="chargeP">
                                    {{item.single_dose *
                                    item.price}}</p>
                            </div>
                        </div>
                    </div>

                </div>
                <div class="moneyBox">
                    <p>实收金：{{list.order_info.medfee_sumamt?list.order_info.medfee_sumamt:''}}</p>
                    <p>记账前金额：{{list.order_info.preselfpay_amt?list.order_info.preselfpay_amt:''}}</p>
                    <p>扣款金额：</p>
                    <p>记账后金额：</p>
                    <p>找赎金：</p>
                </div>
                <div class="actionBar">
                    <div>收费员：{{}}</div>
                    <div>日期：{{this.$route.query.record_date}}</div>
                </div>
            </div>
        </div>
    </div>

</template>
<script>
  import axios from 'axios'
  import { getChargePrint } from '@/api/project/project'

  export default {
    data() {
      return {
        list: {},
        prescription: [],
        patient: {},
        orgname: '',

        result: {},
        org_code: '',
        patient_name: '',
        doctor_code: '',
        doctor_name: '',

        name_arr: [],
        spec_arr: [],
        count_arr: [],
        price_arr: [],
        total_arr: []

      }
    },
    props: {
      paramsObj: Object
    },
    methods: {
      getItemName(number) {
        switch (number) {
          case '01':
            return '床位费';
            break;
          case '02':
            return '西药费';

            break;
          case '03':
            return '中药费';

            break;
          case '04':
            return '中成药费';

            break;
          case '05':
            return '中草药费';

            break;
          case '06':
            return '检查费';

            break;
          case '07':
            return '治疗费';

            break;
          case '08':
            return '放射费';

            break;
          case '09':
            return '手术费';

            break;
          case '10':
            return '化验费';

            break;
          case '11':
            return '输血费';

            break;
          case '12':
            return '输氧费';

            break;
          case '13':
            return '其它费';

            break;
          case '14':
            return '麻醉费';

            break;
          case '15':
            return '材料费';

            break;
          case '16':
            return '特殊检查费';

            break;
          case '17':
            return '特殊治疗费';

            break;
          case '18':
            return '诊疗费(诊查费)';

            break;
          case '19':
            return '护理费';

            break;
          case '20':
            return '诊金';

            break;
          case '21':
            return '检查费（CT）';

            break;
          case '22':
            return '检查费（MRT）';

            break;
          case '23':
            return '检查费（其他）';

            break;
          case '24':
            return '特需服务费';

            break;
          case '25':
            return '杂费';

            break;
          case '26':
            return '挂号费';
            break

        }

      },
      getChargePrint(record_date, patient_id, prescription_id) {
        var params = {
          record_date: record_date,
          patient_id: patient_id,
          prescription_id: prescription_id
        };
        console.log('params', params);
        getChargePrint(params).then(response => {
          if (response.data.state == 1) {
            var list = response.data.data.list;
            console.log('list9999999999', list);
            this.list = list;
            var prescription = response.data.data.prescription;
            console.log('prescription', prescription);
            this.prescription = prescription;
            var patient = response.data.data.patient;
            console.log('patient', patient);
            this.patient = patient;
            var histpatient = response.data.data.hisPatient;
            console.log('hispatient', histpatient)
          }
        })
      }
    },
    created() {

      if (this.$store.getters.xt_user.org_id == 9504 || this.$store.getters.xt_user.org_id == 10028 || this.$store.getters.xt_user.org_id == 10138) {
        this.orgname = xtuser.org.org_name;
        var form = {
          'order_id': this.paramsObj.order_id,
          'patient_id': this.paramsObj.patient_id,
          'record_time': this.paramsObj.record_date,
          'admin_user_id': this.$store.getters.xt_user.user.id
        };
        var that = this;
        axios.get('http://127.0.0.1:9532/sz/api/settle/query', {
          params: form
        })
          .then(function(response) {
            if (response.data.state == 0) {
              that.$message.error(response.data.msg);
              return false
            } else {
              if (response.data.data.failed_code == -10) {
                // that.$message.error(response.data.data.msg)
                that.$confirm(response.data.data.msg, '医保错误信息', {
                  confirmButtonText: '确 定',
                  type: 'warning'
                }).then(() => {

                }).catch(() => {
                })
              } else {
                that.result = response.data.data.result;

                that.org_code = response.data.data.org_code;
                that.patient_name = response.data.data.patient_name;
                that.doctor_code = response.data.data.doctor_code;
                that.doctor_name = response.data.data.doctor_name;
                that.name_arr = [];
                that.spec_arr = [];
                that.count_arr = [];
                that.price_arr = [];
                that.total_arr = [];
                for (let i = 0; i < that.result.transBody.outputlist1.length; i++) {
                  that.name_arr.push(that.result.transBody.outputlist1[i].ake006);
                  that.spec_arr.push(that.result.transBody.outputlist1[i].aka074);
                  that.count_arr.push(that.result.transBody.outputlist1[i].akc226);
                  that.price_arr.push(that.result.transBody.outputlist1[i].akc225);
                  that.total_arr.push(that.result.transBody.outputlist1[i].akc264)
                }

              }

            }
          })
          .catch(function(error) {

          })

      } else {
        var record_date = this.paramsObj.record_date;
        console.log('record_date', record_date);
        var patient_id = this.paramsObj.patient_id;
        console.log('patient_id', patient_id);
        var prescription_id = this.paramsObj.prescription_id;
        this.getChargePrint(record_date, patient_id, prescription_id);
        var xtuser = this.$store.getters.xt_user;
        this.orgname = xtuser.org.org_name

      }

    },
    watch: {
      paramsObj: {//深度监听，可监听到对象、数组的变化
        handler(val, oldVal) {
          this.paramsObj = val;
          this.patient_id = this.paramsObj.patient_id;
          var record_date = this.paramsObj.record;
          this.record_date = record_date;
          var prescription_id = this.paramsObj.prescription_id;
          this.prescription_id = prescription_id

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


<style lang="scss" scoped>
    .prescription-print {
        -webkit-box-shadow: 0 1px 4px rgba(0, 0, 0, 0.27), 0 0 60px rgba(0, 0, 0, 0.06) inset;
        -moz-box-shadow: 0 1px 4px rgba(0, 0, 0, 0.27), 0 0 40px rgba(0, 0, 0, 0.06) inset;
        box-shadow: 0 1px 4px rgba(0, 0, 0, 0.27), 0 0 40px rgba(0, 0, 0, 0.06) inset;
        margin-bottom: 20px;
        padding: 20px 10px;
    }

    .printTitle {
        font-size: 22px;
        text-align: center;
        font-weight: bold;
    }

    .infoMain {
        display: flex;
        flex-wrap: wrap;
        padding: 0 10px;
        margin-top: 10px;
    }

    .infoMain .infoP {
        width: 33%;
        line-height: 24px;
    }

    .chargeBox {
        border: 1px solid #000;
    }

    .chargeUl {
        display: flex;
        justify-content: space-between;
        text-align: center;
    }

    .chargeUl p {
        height: 40px;
        line-height: 40px;
    }

    .chargeP {
        height: 40px;
        line-height: 40px;
    }

    .moneyBox {
        display: flex;
        justify-content: space-between;
        padding: 0 10px;
        background: #eee;
        height: 40px;
        align-items: center;
        border: 1px solid #000;
        border-top: none
    }

    .actionBar {
        display: flex;
        justify-content: space-between;
        line-height: 24px;
        padding: 0 10px;
    }

    .actionBar div {
        width: 150px;
    }
</style>
