<template>
  <div class="main-contain outpatientChargesManagement">
    <div class="position">
      <bread-crumb :crumbs='crumbs'></bread-crumb>
    </div>
    <div class="app-container" style="display:flex;flex: 1;padding: 10px 20px 0px 20px;">
      <div class="mainLeft">

        <el-date-picker
            v-model="record_date"
            prefix-icon="el-icon-date"
            @change="changeTimeTwo"
            :editable="false"
            style="width: 100%;"
            type="date"
            :picker-options="pickerOptions"
            placeholder="选择开始时间"
            align="right"
            format="yyyy-MM-dd"
            value-format="yyyy-MM-dd">
        </el-date-picker>

        <div class="mainCell">
          <el-radio-group v-model="schedule_type" @change="changeScheduleType">
            <el-radio :label="1">上午</el-radio>
            <el-radio :label="2">下午</el-radio>
            <el-radio :label="3">晚上</el-radio>
            <el-radio :label="0">全部</el-radio>
          </el-radio-group>
        </div>

        <div class="mainCell">
          <el-radio-group v-model="radio" @change="changeRadio">
            <el-radio :label=1>未上传<span
                style="color: red;margin-bottom:10px;display: inline-block;">{{ un_upload_num }}</span>人
            </el-radio>
            <el-radio :label=2>已上传<span
                style="color: red;margin-bottom:10px;display: inline-block;">{{ upload_num }}</span>人
            </el-radio>

          </el-radio-group>
        </div>
        <div class="mainCell" style="margin-bottom:10px;">
          <el-input size="small" v-model.trim="search_input"
                    class="filter-item"/>
          <el-button size="small" style="margin-left:10px;" class="filter-item" type="primary"
                     @click="searchAction">
            搜索
          </el-button>
        </div>
        <div>
          <el-table :data="patientTableData" :height="tableHeight" border
                    style="width: 100%;"
                    :row-style="{ color: '#303133' }"
                    :header-cell-style="{backgroundColor: 'rgb(245, 247, 250)',color: '#606266'}"
                    highlight-current-row ref="tab"
                    @current-change="handleCurrentChange">
            <el-table-column align="center" prop="name" label="姓名" wdith='89'>
              <template slot-scope="scope">{{ scope.$index + 1 }}.{{ scope.row.name }}</template>
            </el-table-column>
            <el-table-column align="center" prop="name" label="就诊号" width="110">
              <template slot-scope="scope">{{ scope.row ? scope.row.number : '' }}
              </template>
            </el-table-column>
          </el-table>

        </div>
      </div>

      <div class="mainRight">

        <div class="mainCell fixedCell" style="margin-bottom:10px;">

          <div v-if="activeName == 'first'">

            <el-button
                v-if="(this.radio == 1 && this.hisPatientInfo.balance_accounts_type != 2 && this.hisPatientInfo.id > 0 && this.hisPatientInfo.in_hospital_status == 1 && this.hisPatientInfo.out_hospital_status == 0 )"
                size="small"
                @click="open(1)"
                type="primary">上传费用明细
            </el-button>


            <el-button
                v-if="(this.radio == 1 && this.hisPatientInfo.balance_accounts_type == 2 && this.hisPatientInfo.id > 0 && this.hisPatientInfo.in_hospital_status == 1 && this.hisPatientInfo.out_hospital_status == 0 )"
                size="small"
                @click="open(1)"
                type="primary">上传费用明细
            </el-button>


            <el-button
                v-if="( this.radio == 2 &&this.hisPatientInfo.balance_accounts_type != 2  && this.hisPatientInfo.id > 0 && this.hisPatientInfo.in_hospital_status == 1 && this.hisPatientInfo.out_hospital_status == 0)"
                size="small" @click="open(2)" type="primary"
            >撤销明细
            </el-button>



            <el-button
                v-if="( this.radio == 2 &&this.hisPatientInfo.balance_accounts_type == 2  && this.hisPatientInfo.id > 0 && this.hisPatientInfo.in_hospital_status == 1 && this.hisPatientInfo.out_hospital_status == 0)"
                size="small" @click="open(2)" type="primary"
            >撤销明细
            </el-button>


          </div>
          <div v-if="activeName == 'second'">

            <el-button
                v-if="( this.hisPatientInfo.balance_accounts_type != 2 && this.hisPatientInfo.id > 0 && this.hisPatientInfo.in_hospital_status == 1 && this.hisPatientInfo.out_hospital_status == 0 )"
                size="small"
                @click="open(1)"
                type="primary">上传费用明细
            </el-button>


            <el-button
                v-if="( this.hisPatientInfo.balance_accounts_type != 2  && this.hisPatientInfo.id > 0 && this.hisPatientInfo.in_hospital_status == 1 && this.hisPatientInfo.out_hospital_status == 0)"

                size="small" @click="open(2)" type="primary"
            >撤销明细
            </el-button>

          </div>

        </div>

        <div class="mainCenter" v-loading="loading">
          <el-tabs class="settlementTabs" v-model="activeName" @tab-click="handleClick">
            <el-tab-pane label="日结" name="first">
              <div style="display:flex;height:100%;">
                <div class="centerLeft">
                  <div class="tabsBox">
                    <!--<el-button type="text" class="addTab" @click="addCharges" icon="el-icon-circle-plus">附加收费</el-button>-->
                    <el-tabs class="preTabs" v-model="editableTabsValue" type="border-card"
                             @tab-click="tabclickEvent">
                      <el-tab-pane
                          v-for="(item, index) in prescriptions"
                          :key="index"
                          :label="item.name"
                          :name="item.name"
                      >
                      </el-tab-pane>

                      <!--<div class="RP">-->
                      <!--Rp-->
                      <!--<el-date-picker-->
                      <!--v-model="record_date"-->
                      <!--type="date"-->
                      <!--:clearable="false"-->
                      <!--@change="changeDate"-->
                      <!--format="yyyy-MM-dd"-->
                      <!--value-format="yyyy-MM-dd"-->
                      <!--placeholder="选择日期">-->
                      <!--</el-date-picker>-->
                      <!--</div>-->
                      <!--<charge-prescription-table ref="prescription_tables"-->
                      <!--:prescription="curPrescriptions"></charge-prescription-table>-->
                      <!--<charge-prescription-table ref="prescription_tables" :prescription="curPrescriptions"></charge-prescription-table>-->
                      <charge-prescription-table ref="prescription_tables"
                                                 :manufacturers="manufacturers"
                                                 :prescription="curPrescriptions"></charge-prescription-table>

                    </el-tabs>

                  </div>
                  <div class="costBox">
                    <span>当前处方总费用：<span style="color:red;">{{ total }}元</span></span>
                    <span v-if="this.radio == 2&&this.hisPatientInfo.balance_accounts_type != 2">处方总价：<span style="color:red;">{{
                        all_total + '元' + ' = 全自费总金额:' + fulamt_ownpay_amt + '元+' + '超限价总金额:' + overlmt_amt + '元+' + '先行自付金额:' + preselfpay_amt + '元+' + '符合正常范围总金额:' + inscp_scp_amt + '元'
                      }}</span></span>
                    <span v-if="this.radio == 2&&this.hisPatientInfo.balance_accounts_type == 2">处方总价：<span style="color:red;">{{
                        all_total + '元' + ' = 全自费总金额:' + all_total + '元+' + '超限价总金额:' + overlmt_amt + '元+' + '先行自付金额:' + preselfpay_amt + '元+' + '符合正常范围总金额:' + inscp_scp_amt + '元'
                      }}</span></span>
                    <span v-if="this.radio == 1">处方总价：<span style="color:red;">{{ all_total }}元</span></span>

                    <!--                    <span v-if="this.curPrescriptions.order_status  == 1">待结算</span>-->
                    <!--                    <span v-if="this.curPrescriptions.order_status  == 2">已结算</span>-->
                    <!--                    <span v-if="this.curPrescriptions.order_status  == 3">已退费</span>-->
                  </div>
                </div>
                <!--                <div class="centerRight">-->
                <!--                  <p class="centerRightTitle">人员信息</p>-->
                <!--                  <div style="display:flex;justify-content: space-between;line-height:30px;">-->
                <!--                    <span style="font-size:14px;">人员编码:{{ patientInfo.dialysis_no }}</span>-->
                <!--                    <span style="font-size:14px;">日期:{{ record_date }}</span>-->
                <!--                  </div>-->
                <!--                  <ul class="basicUl">-->
                <!--                    <li style="width:50%;">姓名：{{ patientInfo.name }}</li>-->
                <!--                    <li style="width:50%;">性别：{{ patientInfo.gender == 1 ? '男' : '女' }}</li>-->
                <!--                    <li style="width:50%;">年龄：{{ patientInfo.age }}</li>-->
                <!--                    <li style="width:50%;">电话：{{ patientInfo.phone }}</li>-->

                <!--                    &lt;!&ndash;<span>过敏病史:</span>&ndash;&gt;-->
                <!--                    &lt;!&ndash;<el-autocomplete&ndash;&gt;-->
                <!--                    &lt;!&ndash;style="width:100%;"&ndash;&gt;-->
                <!--                    &lt;!&ndash;class="inline-input"&ndash;&gt;-->
                <!--                    &lt;!&ndash;v-model="sick_history"&ndash;&gt;-->
                <!--                    &lt;!&ndash;:fetch-suggestions="querySearch2"&ndash;&gt;-->
                <!--                    &lt;!&ndash;placeholder="请输入内容"&ndash;&gt;-->
                <!--                    &lt;!&ndash;&gt;</el-autocomplete>&ndash;&gt;-->
                <!--                    &lt;!&ndash;<li style="width:100%;">地址：{{patientInfo.home_address}}</li>&ndash;&gt;-->
                <!--                    &lt;!&ndash;<li style="width:100%;">过敏史及其他病史：{{info.sick_history}}</li>&ndash;&gt;-->
                <!--                  </ul>-->
                <!--                  <p class="centerRightTitle" style="padding-top: 10px;">诊断信息</p>-->
                <!--                  <div style="display:flex;justify-content: space-between;line-height:30px;">-->
                <!--                    <span style="font-size:14px;">住院编号:{{ hisPatientInfo.number }}</span>-->
                <!--                  </div>-->
                <!--                  <ul class="basicUl">-->
                <!--                    <li style="width:50%;">医生：{{ info.doctor }}</li>-->
                <!--                    <li style="width:50%;">科室：{{ info.departments }}</li>-->
                <!--                    <li style="width:100%;">总费用：{{ getTotal() }}</li>-->

                <!--                    <li style="width:100%;">判断结果：{{ info.diagnosis }}</li>-->
                <!--                    <li style="width:100%;">是否有传染病：</li>-->
                <!--                    <li style="width:100%;">血压：</li>-->
                <!--                  </ul>-->
                <!--                </div>-->
              </div>
            </el-tab-pane>
            <el-tab-pane label="月结" name="second">
              <div style="display:flex;height:100%;">
                <div class="centerLeft">
                  <div class="tabsBox">
                    <!-- <el-button type="text" class="addTab" @click="addCharges" icon="el-icon-circle-plus">附加收费</el-button> -->
                    <el-tabs class="preTabs" v-model="editableTabsValue" type="border-card"
                             @tab-click="tabclickEventTwo">

                      <el-tab-pane
                          v-for="(item, index) in month_prescriptions"
                          :key="index"
                          :label="item.name"
                          :name="item.name">
                      </el-tab-pane>

                      <div class="RP">
                        Rp
                        <el-date-picker
                            v-model="other_start_time"
                            prefix-icon="el-icon-date"
                            @change="changeTime"
                            :editable="false"
                            style="width: 150px;"
                            type="date"
                            placeholder="选择开始时间"
                            align="right"
                            format="yyyy-MM-dd"
                            value-format="yyyy-MM-dd">
                        </el-date-picker>
                        <span class>-</span>
                        <el-date-picker
                            v-model="other_end_time"
                            prefix-icon="el-icon-date"
                            @change="changeEndTime"
                            :editable="false"
                            style="width: 150px;"
                            type="date"
                            placeholder="选择结束时间"
                            align="right"
                            format="yyyy-MM-dd"
                            value-format="yyyy-MM-dd">
                        </el-date-picker>
                        <el-select v-model="month_is_upload" @change="changeMonthData"
                                   placeholder="请选择">
                          <el-option
                              v-for="item in upload_options"
                              :key="item.value"
                              :label="item.label"
                              :value="item.value">
                          </el-option>
                        </el-select>
                      </div>

                      <!--<prescription-table :preTableData='preTableData'></prescription-table>-->
                      <!--<month-prescription-table ref="prescription_tables"-->
                      <!--:activeType="activeType"  :prescription="curMonthPrescriptions"></month-prescription-table>-->
                      <charge-month-prescription-table
                          :prescription="curMonthPrescriptions"></charge-month-prescription-table>

                    </el-tabs>

                  </div>
                  <div class="costBox">
                    <span>当前处方总费用：<span style="color:red;">{{ month_total }}元</span></span>
                    <span>处方总价：<span style="color:red;">{{ all_month_total }}元</span></span>

                    <!--<span>{{ state }}</span>-->
                  </div>
                </div>
                <!--                <div class="centerRight">-->
                <!--                  <p class="centerRightTitle">人员信息</p>-->
                <!--                  <div style="display:flex;justify-content: space-between;line-height:30px;">-->
                <!--                    <span style="font-size:14px;">人员编码:{{ patientInfo.dialysis_no }}</span>-->
                <!--                    <span style="font-size:14px;">日期:{{ record_date }}</span>-->
                <!--                  </div>-->

                <!--                  <ul class="basicUl">-->
                <!--                    <li style="width:50%;">姓名：{{ patientInfo.name }}</li>-->
                <!--                    <li style="width:50%;">性别：{{ patientInfo.gender == 1 ? '男' : '女' }}</li>-->
                <!--                    <li style="width:50%;">年龄：{{ patientInfo.age }}</li>-->
                <!--                    <li style="width:50%;">电话：{{ patientInfo.phone }}</li>-->
                <!--                    <li style="width:100%;">过敏史及其他病史：{{ info.sick_history }}</li>-->

                <!--                  </ul>-->
                <!--                  <p class="centerRightTitle" style="padding-top: 10px;">诊断信息</p>-->
                <!--                  <div style="display:flex;justify-content: space-between;line-height:30px;">-->
                <!--                    <span style="font-size:14px;">门诊编号:{{ hisPatientInfo.number }}</span>-->
                <!--                  </div>-->
                <!--                  <ul class="basicUl">-->
                <!--                    <li style="width:50%;">医生：{{ info.doctor }}</li>-->
                <!--                    <li style="width:50%;">科室：{{ getDepartment(info.departments) }}</li>-->
                <!--                    <li style="width:100%;" v-if="activeName == 'first'">总费用：{{ getTotal() }}</li>-->
                <!--                    <li style="width:100%;" v-if="activeName == 'second'">总费用：{{ getTotalTwo() }}-->
                <!--                    </li>-->

                <!--                    <li style="width:100%;">判断结果：{{ info.diagnosis }}</li>-->
                <!--                    &lt;!&ndash;<li style="width:100%;">是否有传染病：</li>&ndash;&gt;-->
                <!--                    &lt;!&ndash;<li style="width:100%;">血压：</li>&ndash;&gt;-->
                <!--                  </ul>-->
                <!--                </div>-->
              </div>
            </el-tab-pane>
          </el-tabs>
        </div>
      </div>
    </div>

  </div>

</template>


<script>
import axios from 'axios'

import BreadCrumb from '@/xt_pages/components/bread-crumb'
import noCharge from './components/noCharge'
import charged from './components/charged'
import medicalInsuranceRefund from './components/medicalInsuranceRefund'
import additionalCharges from './components/additionalCharges'
import { getHisHospitalDetailInfo, getHisHospitalDetailList, getMonthHisHospitalDetailInfo } from '@/api/his/his'
import { upLoadChargeInfo,refundDetail } from '@/api/his/his_hospital'

import { uParseTime } from '@/utils/tools'

import RegisterDialog from './components/registerDialog'
import treatPrint from './treatPrint'
import statementPrint from './statementPrint'
import ChargeDialog from './components/chargeDialog'
import MonthPrescriptionTable from './components/monthPrescriptionTable'
import ChargeMonthPrescriptionTable from './components/chargeMonthPrescriptionTable'
import NewStatementPrintTwo from './newStatementPrintTwo'
import RegisterDialog9504 from './components/registerDialog9504'
import ChargePrescriptionTable from './components/ChargePrescriptionTable'
import invoicePrint from './invoicePrint'
import SettlePrescriptionTable from './components/settlePrescriptionTable'

const moment = require('moment')
export default {
  components: {
    SettlePrescriptionTable,
    ChargePrescriptionTable,
    RegisterDialog9504,
    NewStatementPrintTwo,
    ChargeMonthPrescriptionTable,
    MonthPrescriptionTable,
    ChargeDialog,
    RegisterDialog,
    BreadCrumb,
    noCharge,
    charged,
    medicalInsuranceRefund,
    additionalCharges,
    treatPrint,
    statementPrint,
    invoicePrint

  },
  data() {
    return {
      register: [
        { value: 11, label: '普通门诊' },
        // { value: 12, label: '门诊挂号' },
        // { value: 13, label: '急诊' },
        { value: 14, label: '门诊慢性病' }
        // { value: 15, label: '门诊统筹' },
        // { value: 16, label: '门诊慢性病' },
        // { value: 21, label: '普通住院' }

      ],
      upload_options: [
        { value: 0, label: '全部' },
        { value: 2, label: '已上传' },
        { value: 1, label: '未上传' }

      ],
      loading: false,
      dise_loading: false,
      month_is_upload: 0,
      sick_history: '',
      p_type: '',
      sick_type: '',
      diagnosis: '',
      isShowUpload: 1,
      isShowWithdrawUpload: 1,
      schedule_type: 0,
      month_p_type: '',
      month_sick_type: '',
      month_diagnosis: '',
      key: '',
      other_start_time: moment(new Date()).subtract(30, 'days').format('YYYY-MM-DD'),
      other_end_time: moment(new Date()).add('year', 0).format('YYYY-MM-DD'),
      curMonthPrescriptions: null,
      curSettlePrescriptions: null,

      month_total: 0,
      crumbs: [
        { path: false, name: '住院工作站' },
        { path: false, name: '住院收费管理' }
      ],
      current_index: 0,
      un_upload_num: '',
      upload_num: '',
      tableHeight: '',
      fullHeight: document.documentElement.clientHeight,
      activeName: 'first',
      info: {},
      curPrescriptions: {},
      prescriptions: [],
      month_prescriptions: [],
      settle_prescriptions: [],

      settle_total: 0,
      all_total: 0,
      all_month_total: 0,
      record_date: '',
      tableData: [],
      editableTabsValue: '处方1',

      editSettletableTabsValue: '处方1',

      loadingone: false,
      editableTabs: [{
        title: '处方1',
        name: '1'
      }],
      tabIndex: 1,
      hisPatientInfo: {},
      loadingtwo: false,
      patientTableData: [{
        name: '杨美英',
        mdtrt_id: '1709946'
      }],
      patientInfo: { id: 0 },
      doctor: {},
      total: 0,
      state: '未收费',
      radio: 1,
      radioStatus: 1,
      search_input: '',
      start_time: moment().locale('zh-cn').format('YYYY-MM-DD'),
      patient_id: 0,
      prescription_id: 0,
      all_table_data: [],
      manufacturers: [],
      hisPatientDatas: [],
      order: {},
      addtions_charge: [],
      treatVisible: false,
      orderObj: {},
      paramsObj: {},
      newOrderObj: {},
      statementVisible: false,
      newStatementVisible: false,
      chargePatientTableData: [],
      sick: [],
      diagnoses: [],

      department: [],
      invoiceVisible: false,
      invoiceParams: {},
      fulamt_ownpay_amt: '',
      overlmt_amt: '',
      preselfpay_amt: '',
      inscp_scp_amt: ''
    }
  },
  created() {
    let tableHeight = document.body.clientHeight - 243
    this.tableHeight = tableHeight
    var nowDate = new Date()
    var nowYear = nowDate.getFullYear()
    var nowMonth = nowDate.getMonth() + 1
    var nowDay = nowDate.getDate()
    this.record_date =
        nowYear +
        '-' +
        (nowMonth < 10 ? '0' + nowMonth : nowMonth) +
        '-' +
        (nowDay < 10 ? '0' + nowDay : nowDay)

    // this.getInitData()
    //获取患者信息
    this.getPatientList()
  },
  methods: {
    changeScheduleType() {

      this.getPatientList()

    },
    getMonthData() {
      this.loading = true

      let params = {
        'id': this.hisPatientInfo.id,
        'patient_id': this.hisPatientInfo.patient_id,
        'start_time': this.other_start_time,
        'end_time': this.other_end_time,
        'is_upload': this.month_is_upload
      }
      getMonthHisHospitalDetailInfo(params).then(response => {
        if (response.data.state == 0) {
          this.loading = false
          this.$message.error(response.data.msg)
          return false
        } else {
          this.month_prescriptions = []
          this.curMonthPrescriptions = {}
          this.loading = false
          this.hisPatientInfo = response.data.data.his_info
          this.setMonthPrescription(response.data.data.month_prescriptions)
          this.month_total = this.getMonthTotalOne()
          this.all_month_total = this.getTotalTwo()
        }
      })

    },
    changeMonthData() {
      this.getMonthData()

    },
    getTimes(time) {
      return uParseTime(time, '{y}-{m}-{d}')
    },
    changeTimeTwo() {
      this.getPatientList()
    },

    changeTime(val) {
      this.getPatientInformation(this.hisPatientInfo.id, this.hisPatientInfo.patient_id)
    }, changeEndTime(val) {
      this.getPatientInformation(this.hisPatientInfo.id, this.hisPatientInfo.patient_id)

    },

    handleClick() {
      // this.getPatientList()
      if (this.activeName == 'first') {
        // this.patientTableData = this.all_table_data
        this.getDayPatientList()

      } else if (this.activeName == 'second') {
        this.getMonthPatientList()
        // this.getPatientList()

        // if (this.patientTableData.length > 0) {
        //   this.$refs.tab.setCurrentRow(this.patientTableData[0])
        //   this.getPatientInformation(this.patientTableData[0].id, this.patientTableData[0].order.number)
        // }

      } else {

        console.log(this.settle_prescriptions)
      }

    },
    searchAction() {

      if (this.search_input.length == 0) {
        switch (this.radio) {
          case 1:
            this.patientTableData = this.all_table_data

            break
          case 2:

            this.patientTableData = this.all_table_data

            break
        }

      } else {
        switch (this.radio) {
          case 1:
            let arr3 = []
            for (let i = 0; i < this.all_table_data.length; i++) {
              if (this.all_table_data[i].name.indexOf(this.search_input) != -1) {
                arr3 = arr3.concat(this.all_table_data[i])
              }
            }
            this.patientTableData = arr3
            break
          case 2:
            let arr2 = []
            for (let i = 0; i < this.all_table_data.length; i++) {
              if (this.all_table_data[i].name.indexOf(this.search_input) != -1) {
                arr2 = arr2.concat(this.all_table_data[i])
              }
            }
            this.patientTableData = arr2

            break

        }
      }

    },
    tabclickEventTwo(val) {
      for (let i = 0; i < this.month_prescriptions.length; i++) {
        if (this.month_prescriptions[i].name == val.name) {

          this.curMonthPrescriptions = {}
          var temp = this.deepClone(this.month_prescriptions[i])
          this.curMonthPrescriptions = temp
        }
      }
      this.prescription_id = this.month_prescriptions.id
      this.month_total = 0
      this.month_total = this.getMonthTotalOne()

    },
    tabclickEventThree(val) {
      for (let i = 0; i < this.settle_prescriptions.length; i++) {
        if (this.settle_prescriptions[i].name == val.name) {

          this.curSettlePrescriptions = {}
          var temp = this.deepClone(this.settle_prescriptions[i])
          this.curSettlePrescriptions = temp
        }
      }
      this.prescription_id = this.settle_prescriptions.id
      this.settle_total = 0
      this.settle_total = this.getSettleTotalOne()

    },
    tabclickEvent(val) {
      console.log('val', val.name)
      for (let i = 0; i < this.prescriptions.length; i++) {
        if (this.prescriptions[i].name == val.name) {

          this.curPrescriptions = {}
          var temp = this.deepClone(this.prescriptions[i])
          this.curPrescriptions = temp
        }
      }
      console.log('9999', this.curPrescriptions)
      this.prescription_id = this.curPrescriptions.id
      this.total = 0
      this.total = this.getTotalOne()

    },
    deepClone(source) {
      if (!source && typeof source !== 'object') {
        throw new Error('error arguments', 'shallowClone')
      }
      const targetObj = source.constructor === Array ? [] : {}
      Object.keys(source).forEach((keys) => {
        if (source[keys] && typeof source[keys] === 'object') {
          targetObj[keys] = this.deepClone(source[keys])
        } else {
          targetObj[keys] = source[keys]
        }
      })
      return targetObj
    },
    getTotalOne() {
      var total = 0
      if (this.curPrescriptions.type == 1) {
        if (this.curPrescriptions.advices != null) {
          for (let a = 0; a < this.curPrescriptions.advices.length; a++) {
            total = parseFloat(total) + parseFloat(this.curPrescriptions.advices[a].retail_price * this.curPrescriptions.advices[a].prescribing_number)

          }
        }
      } else {
        if (this.curPrescriptions.project != null) {
          for (let b = 0; b < this.curPrescriptions.project.length; b++) {
            total = parseFloat(total) + parseFloat(this.curPrescriptions.project[b].price * this.curPrescriptions.project[b].total)

          }
        }
      }
      return total.toFixed(2)
    },
    getMonthTotalOne() {
      var total = 0
      if (this.curMonthPrescriptions.type == 1) {
        if (this.curMonthPrescriptions.advices != null) {
          for (let a = 0; a < this.curMonthPrescriptions.advices.length; a++) {
            total = parseFloat(total) + parseFloat(this.curMonthPrescriptions.advices[a].retail_price * this.curMonthPrescriptions.advices[a].prescribing_number)

          }
        }
      } else {
        if (this.curMonthPrescriptions.project != null) {
          for (let b = 0; b < this.curMonthPrescriptions.project.length; b++) {
            total = parseFloat(total) + parseFloat(this.curMonthPrescriptions.project[b].price * this.curMonthPrescriptions.project[b].total)

          }
        }
      }

      return total.toFixed(2)

    },
    getTotal() {
      var total = 0
      for (let i = 0; i < this.prescriptions.length; i++) {
        if (this.prescriptions[i].advices != null) {
          for (let a = 0; a < this.prescriptions[i].advices.length; a++) {
            total = parseFloat(total) + parseFloat(this.prescriptions[i].advices[a].retail_price * this.prescriptions[i].advices[a].prescribing_number)
          }
        }
        if (this.prescriptions[i].project != null) {
          for (let b = 0; b < this.prescriptions[i].project.length; b++) {

            total = parseFloat(total) + parseFloat(this.prescriptions[i].project[b].price * this.prescriptions[i].project[b].total)
          }
        }

      }
      return total.toFixed(2)

    },
    getTotalTwo() {
      var total = 0
      for (let i = 0; i < this.month_prescriptions.length; i++) {
        if (this.month_prescriptions[i].advices != null) {
          for (let a = 0; a < this.month_prescriptions[i].advices.length; a++) {
            total = parseFloat(total) + parseFloat(this.month_prescriptions[i].advices[a].retail_price * this.month_prescriptions[i].advices[a].prescribing_number)
          }
        }
        if (this.month_prescriptions[i].project != null) {
          for (let a = 0; a < this.month_prescriptions[i].project.length; a++) {

            total = parseFloat(total) + parseFloat(this.month_prescriptions[i].project[a].price * this.month_prescriptions[i].project[a].total)
          }
        }

      }
      return total.toFixed(2)

    },
    moreState(tab, event) {
      if (tab == 'more') {
        return false
      }
    }, formatJson(filterVal, jsonData) {
      return jsonData.map(v => filterVal.map(j => v[j]))
    },
    open(index) {
      if (index == 2) {
        let settle_accounts_type = ''
        if (this.activeName == 'first') {
          settle_accounts_type = 1
          var that = this
          this.$confirm('是否撤销明细', '撤销明细', {
            confirmButtonText: '确 定',
            cancelButtonText: '取 消',
            type: 'warning'
          }).then(() => {
            if (that.hisPatientInfo.balance_accounts_type != 2){
              let params = {
                'settle_accounts_type': settle_accounts_type,
                'patient_id': that.hisPatientInfo.patient_id,
                'his_patient_id': that.hisPatientInfo.id,
                'record_time': that.record_date,
                'admin_user_id': that.$store.getters.xt_user.user.id
              }
              axios.get('http://127.0.0.1:9532/zh/api/refunddetail', {
                params: params
              })
                  .then(function(response) {
                    if (response.data.state == 0) {
                      that.$message.error(response.data.msg)
                      that.loadingtwo = false
                      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.$message.success('撤销明细成功')
                        that.radio = 1
                        that.getPatientList()
                      }

                    }
                  })
                  .catch(function(error) {
                  })


            }else{
              let params = {
                'settle_accounts_type': settle_accounts_type,
                'patient_id': that.hisPatientInfo.patient_id,
                'his_patient_id': that.hisPatientInfo.id,
                'record_time': that.record_date,
                'admin_user_id': that.$store.getters.xt_user.user.id
              }
              refundDetail(params).then(response => {
                if (response.data.state == 0) {
                  this.loading = false
                  this.$message.error(response.data.msg)
                  return false
                } else {
                  that.$message.success('撤销明细成功')
                  that.radio = 1
                  that.getPatientList()
                }
              })

            }
          }).catch(() => {
          })
        } else {
          settle_accounts_type = 2
          var that = this
          this.$confirm('该操作会撤销此次入院后所有处方明细，是否继续操作？', '撤销明细', {
            confirmButtonText: '确 定',
            cancelButtonText: '取 消',
            type: 'warning'
          }).then(() => {

            let params = {
              'settle_accounts_type': settle_accounts_type,
              'patient_id': that.hisPatientInfo.patient_id,
              'his_patient_id': that.hisPatientInfo.id,
              'record_time': that.record_date,
              'order_id': that.order.id,
              'admin_user_id': that.$store.getters.xt_user.user.id
            }
            axios.get('http://127.0.0.1:9532/zh/api/refunddetail', {
              params: params
            })
                .then(function(response) {
                  if (response.data.state == 0) {
                    that.$message.error(response.data.msg)
                    that.loadingtwo = false
                    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.$message.success('撤销明细成功')
                      that.radio = 1
                      that.getPatientList()
                    }

                  }
                })
                .catch(function(error) {
                })

          }).catch(() => {
          })

        }

      } else if (index == 1) {
        var that = this
        let params = {
          'in_hospital_id': that.hisPatientInfo.id,
          'id': that.hisPatientInfo.patient_id,
          'admin_user_id': that.$store.getters.xt_user.user.id,
          'record_time': that.record_date

        }
        if (this.activeName == 'first') {
          params['settle_accounts_type'] = 1

        } else {
          params['start_time'] = that.other_start_time
          params['end_time'] = that.other_end_time
          params['settle_accounts_type'] = 2

        }
        if (this.hisPatientInfo.balance_accounts_type != 2) {
          axios.get('http://127.0.0.1:9532/zh/api/uploadinfo/get', {
            params: params
          })
              .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.$message.success('上传明细成功')
                    that.radio = 2
                    that.changePatientInfo()
                  }

                }
              })
              .catch(function(error) {
              })
        } else if (this.hisPatientInfo.balance_accounts_type == 2) {
          var that = this
          let params = {
            'in_hospital_id': that.hisPatientInfo.id,
            'id': that.hisPatientInfo.patient_id,
            'admin_user_id': that.$store.getters.xt_user.user.id,
            'record_time': that.record_date

          }
          if (this.activeName == 'first') {
            params['settle_accounts_type'] = 1

          } else {
            params['start_time'] = that.other_start_time
            params['end_time'] = that.other_end_time
            params['settle_accounts_type'] = 2

          }
          upLoadChargeInfo(params).then(response => {
            if (response.data.state == 0) {
              this.loading = false
              this.$message.error(response.data.msg)
              return false
            } else {
              that.$message.success('上传明细成功')
              that.radio = 2
              that.changePatientInfo()
            }
          })
        }
      }
    }, changePatientInfo() {
      let params = {
        'record_date': this.record_date,
        'sch_type': this.schedule_type
      }
      getHisHospitalDetailList(params).then(response => {
        if (response.data.state == 0) {
          this.$message.error(response.data.msg)
          return false
        } else {
          if (response.data.data.list == null) {
            response.data.data.list = []
          }
          if (response.data.data.list_two == null) {
            response.data.data.list_two = []
          }
          this.hisPatientInfo = {}
          this.curPrescriptions = {}
          this.curMonthPrescriptions = {}
          this.month_prescriptions = []
          this.prescriptions = []

          this.patientTableData = []
          this.upload_num = response.data.data.upload_num
          this.un_upload_num = response.data.data.un_upload_num
          switch (this.radio) {
            case 1:
              this.all_table_data = response.data.data.list
              this.patientTableData = response.data.data.list
              if (this.hisPatientInfo.id > 0) {
                for (let i = 0; i < this.patientTableData.length; i++) {
                  if (this.hisPatientInfo.patient_id == this.patientTableData[i].patient_id) {
                    this.current_index = i
                    this.$refs.tab.setCurrentRow(this.patientTableData[i])
                    this.getPatientInformation(this.patientTableData[i].id, this.patientTableData[i].patient_id)

                  }
                }
              } else {
                this.$refs.tab.setCurrentRow(this.patientTableData[0])
                this.getPatientInformation(this.patientTableData[0].id, this.patientTableData[0].patient_id)
              }
              break
            case 2:
              this.all_table_data = response.data.data.list_two
              this.patientTableData = response.data.data.list_two

              if (this.hisPatientInfo.id > 0) {
                for (let i = 0; i < this.patientTableData.length; i++) {
                  if (this.hisPatientInfo.patient_id == this.patientTableData[i].patient_id) {
                    this.current_index = i
                    this.$refs.tab.setCurrentRow(this.patientTableData[i])
                    this.getPatientInformation(this.patientTableData[i].id, this.patientTableData[i].patient_id)

                  }
                }
              } else {
                this.$refs.tab.setCurrentRow(this.patientTableData[0])
                this.getPatientInformation(this.patientTableData[0].id, this.patientTableData[0].patient_id)
              }
              break

          }
        }
      })

    },
    changeRadio(id) {
      // this.hisPatientInfo = null
      this.getPatientList()
    },
    formatDecimal(num, decimal) {
      num = num.toString()
      let index = num.indexOf('.')
      if (index !== -1) {
        num = num.substring(0, decimal + index + 1)
      } else {
        num = num.substring(0)
      }
      return parseFloat(num).toFixed(decimal)
    },
    //患者列表
    getPatientList() {
      let params = {
        'record_date': this.record_date,
        'sch_type': this.schedule_type
      }
      getHisHospitalDetailList(params).then(response => {
        if (response.data.state == 0) {
          this.$message.error(response.data.msg)
          return false
        } else {
          if (response.data.data.list == null) {
            response.data.data.list = []
          }
          if (response.data.data.list_two == null) {
            response.data.data.list_two = []
          }
          this.hisPatientInfo = {}
          this.curPrescriptions = {}
          this.curMonthPrescriptions = {}
          this.month_prescriptions = []
          this.prescriptions = []

          this.patientTableData = []
          this.upload_num = response.data.data.upload_num
          this.un_upload_num = response.data.data.un_upload_num
          switch (this.radio) {
            case 1:
              this.all_table_data = response.data.data.list
              this.patientTableData = response.data.data.list
              if (this.hisPatientInfo.id > 0) {
                for (let i = 0; i < this.patientTableData.length; i++) {
                  if (this.hisPatientInfo.patient_id == this.patientTableData[i].patient_id) {
                    this.current_index = i
                    this.$refs.tab.setCurrentRow(this.patientTableData[i])
                    this.getPatientInformation(this.patientTableData[i].id, this.patientTableData[i].patient_id)

                  }
                }
              } else {
                this.$refs.tab.setCurrentRow(this.patientTableData[0])
                this.getPatientInformation(this.patientTableData[0].id, this.patientTableData[0].patient_id)
              }
              break
            case 2:
              this.all_table_data = response.data.data.list_two
              this.patientTableData = response.data.data.list_two
              if (this.hisPatientInfo.id > 0) {
                for (let i = 0; i < this.patientTableData.length; i++) {
                  if (this.hisPatientInfo.patient_id == this.patientTableData[i].patient_id) {
                    this.current_index = i
                    this.$refs.tab.setCurrentRow(this.patientTableData[i])
                    this.getPatientInformation(this.patientTableData[i].id, this.patientTableData[i].patient_id)

                  }
                }
              } else {
                this.$refs.tab.setCurrentRow(this.patientTableData[0])
                this.getPatientInformation(this.patientTableData[0].id, this.patientTableData[0].patient_id)
              }
              break
          }
        }
      })
    },
    setMonthPrescription(month_prescriptions) {
      this.month_prescriptions = []

      let drug_month_prescriptions = {
        advices: []
      }
      let drug_ids = []
      let project_month_prescriptions = {
        project: []

      }
      let project_ids = []

      let addition_month_prescriptions = {
        addition: []

      }
      let additions_ids = []

      for (let i = 0; i < month_prescriptions.length; i++) {
        if (month_prescriptions[i].type == 1) { //药品
          for (let a = 0; a < month_prescriptions[i].advices.length; a++) {
            let obj = {
              id: month_prescriptions[i].advices[a].drug_id,
              price: month_prescriptions[i].advices[a].price

            }
            drug_ids.push(obj)
            // drug_ids.push(month_prescriptions[i].advices[a].drug_id)

            drug_month_prescriptions.advices.push(month_prescriptions[i].advices[a])
          }

        } else if (month_prescriptions[i].type == 2) { //项目
          for (let a = 0; a < month_prescriptions[i].project.length; a++) {
            let obj = {
              id: month_prescriptions[i].project[a].project_id,
              price: month_prescriptions[i].project[a].price

            }
            project_ids.push(obj)
            project_month_prescriptions.project.push(month_prescriptions[i].project[a])
          }
        }

      }

      drug_ids = this.unique_two(drug_ids)
      project_ids = this.unique_two(project_ids)
      additions_ids = this.unique_two(additions_ids)

      let drugs = []
      let projects = []
      let additions = []

      for (let i = 0; i < drug_ids.length; i++) {
        let obj = {}
        let count = 0
        for (let a = 0; a < drug_month_prescriptions.advices.length; a++) {
          if (drug_ids[i].price == drug_month_prescriptions.advices[a].price && drug_ids[i].id == drug_month_prescriptions.advices[a].drug_id) {

            obj['drug_name'] = drug_month_prescriptions.advices[a].advice_name
            obj['single_dose'] = drug_month_prescriptions.advices[a].single_dose
            obj['delivery_way'] = drug_month_prescriptions.advices[a].delivery_way
            obj['execution_frequency'] = drug_month_prescriptions.advices[a].execution_frequency
            obj['day'] = drug_month_prescriptions.advices[a].day
            // obj['prescribing_number'] =  obj['prescribing_number']  + drug_month_prescriptions.advices[a].prescribing_number
            obj['prescribing_number_unit'] = drug_month_prescriptions.advices[a].prescribing_number_unit
            obj['medical_insurance_number'] = drug_month_prescriptions.advices[a].drug.medical_insurance_number
            obj['id'] = drug_month_prescriptions.advices[a].drug_id
            // obj['retail_price'] = obj['retail_price'] +  drug_month_prescriptions.advices[a].drug.retail_price
            obj['retail_price'] = parseFloat(drug_month_prescriptions.advices[a].price)
            count = count + drug_month_prescriptions.advices[a].prescribing_number

          }
        }
        obj['prescribing_number'] = count
        drugs.push(obj)
      }

      for (let i = 0; i < project_ids.length; i++) {
        let obj = {}
        let count = 0
        for (let a = 0; a < project_month_prescriptions.project.length; a++) {
          if (project_ids[i].price == project_month_prescriptions.project[a].price && project_ids[i].id == project_month_prescriptions.project[a].project_id) {

            if (project_month_prescriptions.project[a].type == 2) {
              obj['statistical_classification'] = ''
              obj['medical_code'] = project_month_prescriptions.project[a].project.medical_code
              obj['project_name'] = project_month_prescriptions.project[a].project.project_name
              obj['type'] = 2

            } else if (project_month_prescriptions.project[a].type == 3) {
              obj['statistical_classification'] = ''
              obj['medical_code'] = project_month_prescriptions.project[a].good_info.medical_insurance_number
              obj['project_name'] = project_month_prescriptions.project[a].good_info.good_name
              obj['type'] = 3

            }

            // obj['project_name'] = project_month_prescriptions.project[a].project.project_name;
            // obj['statistical_classification'] = project_month_prescriptions.project[a].project.statistical_classification;
            obj['single_dose'] = project_month_prescriptions.project[a].single_dose
            obj['delivery_way'] = project_month_prescriptions.project[a].delivery_way
            obj['execution_frequency'] = project_month_prescriptions.project[a].execution_frequency
            obj['number_days'] = project_month_prescriptions.project[a].day
            // obj['medical_code'] = project_month_prescriptions.project[a].project.medical_code;
            obj['unit'] = project_month_prescriptions.project[a].unit
            obj['project_id'] = project_month_prescriptions.project[a].project_id
            count = count + parseFloat(project_month_prescriptions.project[a].count)
            // price = price + project_month_prescriptions.project[a].price
            obj['price'] = parseFloat(project_month_prescriptions.project[a].price)

          }
        }
        obj['total'] = count
        projects.push(obj)
      }

      let p1 = {
        name: '处方' + 1,
        advices: drugs,
        project: [],
        type: 1,
        addition: additions
      }
      let p2 = {
        name: '处方' + 2,
        type: 2,
        project: projects,
        advices: [],
        addition: []
      }

      this.month_prescriptions.push(p1)
      this.month_prescriptions.push(p2)

      this.curMonthPrescriptions = this.month_prescriptions[0]

    },

    unique_two(array) {
      // res用来存储结果
      var res = []
      for (var i = 0, arrayLen = array.length; i < arrayLen; i++) {
        for (var j = 0, resLen = res.length; j < resLen; j++) {
          if (array[i].id === res[j].id && array[i].price === res[j].price) {
            break
          }
        }
        // 如果array[i]是唯一的，那么执行完循环，j等于resLen
        if (j === resLen) {
          res.push(array[i])
        }
      }
      return res
    },

    unique(arr) {
      const res = new Map()
      return arr.filter((arr) => !res.has(arr.id_card_no) && res.set(arr.id_card_no, 1))
    },
    handleCurrentChange(val) {
      this.getPatientInformation(val.id, val.patient_id)
    },
    //获取患者的基本信息
    getPatientInformation(id, patient_id) {
      let params = {
        'id': id,
        'record_date': this.record_date,
        'patient_id': patient_id,
        'start_time': this.other_start_time,
        'end_time': this.other_end_time,
        'is_upload': this.radio
      }
      this.loading = true
      getHisHospitalDetailInfo(params).then(response => {
        if (response.data.state == 0) {
          this.loading = false
          this.$message.error(response.data.msg)
          return false
        } else {
          this.prescriptions = []
          this.month_prescriptions = []
          this.curPrescriptions = {}
          this.curMonthPrescriptions = {}
          this.loading = false
          this.hisPatientInfo = response.data.data.his_info
          this.setMonthPrescription(response.data.data.month_prescriptions)
          for (let i = 0; i < response.data.data.prescription.length; i++) {
            var prescription = response.data.data.prescription[i]
            let tempAdvice = []
            let tempProject = []
            let tempAddition = []
            for (let b = 0; b < prescription.advices.length; b++) {
              let spec = prescription.advices[b].drug.dose + prescription.advices[b].drug.dose_unit + '*' + prescription.advices[b].drug.min_number + prescription.advices[b].drug.min_unit + '/' + prescription.advices[b].drug.max_unit

              let obj = {
                advice_id: prescription.advices[b].id,
                drug_name: prescription.advices[b].advice_name,
                single_dose: prescription.advices[b].single_dose,
                delivery_way: prescription.advices[b].delivery_way,
                execution_frequency: prescription.advices[b].execution_frequency,
                retail_price: prescription.advices[b].price.toString(),
                remark: prescription.advices[b].remark,
                day: prescription.advices[b].day,
                prescribing_number: prescription.advices[b].prescribing_number.toString(),
                single_dose_unit: prescription.advices[b].single_dose_unit,
                prescribing_number_unit: prescription.advices[b].prescribing_number_unit,
                medical_insurance_number: prescription.advices[b].med_list_codg,

                spec: spec,
                code: prescription.advices[b].drug.medical_insurance_number,
                det_item_fee_sumamt: prescription.advices[b].order_info.det_item_fee_sumamt,
                name_id: prescription.advices[b].drug.manufacturer,
                fulamt_ownpay_amt: prescription.advices[b].order_info.fulamt_ownpay_amt,
                overlmt_amt: prescription.advices[b].order_info.overlmt_amt,
                preselfpay_amt: prescription.advices[b].order_info.preselfpay_amt,
                inscp_scp_amt: prescription.advices[b].order_info.inscp_scp_amt,
                execution_state: prescription.advices[b].execution_state

              }
              tempAdvice.push(obj)
            }

            for (let b = 0; b < prescription.project.length; b++) {
              let obj = {
                id: prescription.project[b].id,
                project_id: prescription.project[b].project.id,
                // project_name: prescription.project[b].project.project_name,
                // statistical_classification: prescription.project[b].project.statistical_classification,
                single_dose: prescription.project[b].single_dose,
                delivery_way: prescription.project[b].delivery_way,
                execution_frequency: prescription.project[b].execution_frequency,
                number_days: prescription.project[b].day,
                total: prescription.project[b].count.toString(),
                price: prescription.project[b].price,
                remark: prescription.project[b].remark,
                // medical_code: prescription.project[b].project.medical_code,
                unit: prescription.project[b].project.unit,
                type: prescription.project[b].type,
                det_item_fee_sumamt: prescription.project[b].order_info.det_item_fee_sumamt,
                fulamt_ownpay_amt: prescription.project[b].order_info.fulamt_ownpay_amt,
                overlmt_amt: prescription.project[b].order_info.overlmt_amt,
                preselfpay_amt: prescription.project[b].order_info.preselfpay_amt,
                inscp_scp_amt: prescription.project[b].order_info.inscp_scp_amt,
                execution_state: prescription.project[b].execution_state

              }

              if (prescription.project[b].type == 2) {
                obj['statistical_classification'] = prescription.project[b].team.project_team
                obj['medical_code'] = prescription.project[b].project.medical_code
                obj['project_name'] = prescription.project[b].project.project_name
                obj['spec'] = ''
                obj['name_id'] = 0

              } else if (prescription.project[b].type == 3) {
                obj['statistical_classification'] = prescription.project[b].team.project_team
                obj['medical_code'] = prescription.project[b].good_info.medical_insurance_number
                obj['project_name'] = prescription.project[b].good_info.good_name
                obj['spec'] = prescription.project[b].good_info.specification_name
                obj['name_id'] = prescription.project[b].good_info.manufacturer

              }

              tempProject.push(obj)
            }

            let index = i + 1
            let obj = {
              id: prescription.id,
              name: '处方' + index,
              advices: tempAdvice,
              project: tempProject,
              addition: tempAddition,
              order_status: prescription.order_status,
              type: prescription.type
            }
            this.prescriptions.push(obj)

            for (let i = 0; i < this.prescriptions.length; i++) {
              if (this.prescriptions[i].order_status != 4) {
                this.isShowUpload = 2
              }

            }

          }
          if (this.prescriptions.length > 0) {
            this.curPrescriptions = this.prescriptions[0]
          } else {
            this.curPrescriptions = {}
          }
          if (this.month_prescriptions.length > 0) {
            this.curMonthPrescriptions = this.month_prescriptions[0]
          } else {
            this.curMonthPrescriptions = {}
          }
          this.total = 0
          this.total = this.getTotalOne()
          this.month_total = this.getMonthTotalOne()
          this.all_total = this.getTotal()
          this.all_month_total = this.getTotalTwo()
          this.fulamt_ownpay_amt = this.getFulamtOwnpayAmtTotal()
          this.overlmt_amt = this.getOverlmtAmtTotal()
          this.preselfpay_amt = this.getPreselfpayAmtTotal()
          this.inscp_scp_amt = this.getInscpScpAmtTotal()

        }
      })
    }, getFulamtOwnpayAmtTotal() {
      var total = 0
      for (let i = 0; i < this.prescriptions.length; i++) {
        if (this.prescriptions[i].advices != null) {
          for (let a = 0; a < this.prescriptions[i].advices.length; a++) {
            total = parseFloat(total) + parseFloat(this.prescriptions[i].advices[a].fulamt_ownpay_amt)
          }
        }
        if (this.prescriptions[i].project != null) {
          for (let b = 0; b < this.prescriptions[i].project.length; b++) {

            total = parseFloat(total) + parseFloat(this.prescriptions[i].project[b].fulamt_ownpay_amt)
          }
        }

      }
      return total.toFixed(2)

    }, getOverlmtAmtTotal() {
      var total = 0
      for (let i = 0; i < this.prescriptions.length; i++) {
        if (this.prescriptions[i].advices != null) {
          for (let a = 0; a < this.prescriptions[i].advices.length; a++) {
            total = parseFloat(total) + parseFloat(this.prescriptions[i].advices[a].overlmt_amt)
          }
        }
        if (this.prescriptions[i].project != null) {
          for (let b = 0; b < this.prescriptions[i].project.length; b++) {

            total = parseFloat(total) + parseFloat(this.prescriptions[i].project[b].overlmt_amt)
          }
        }

      }
      return total.toFixed(2)

    }, getPreselfpayAmtTotal() {
      var total = 0
      for (let i = 0; i < this.prescriptions.length; i++) {
        if (this.prescriptions[i].advices != null) {
          for (let a = 0; a < this.prescriptions[i].advices.length; a++) {
            total = parseFloat(total) + parseFloat(this.prescriptions[i].advices[a].preselfpay_amt)
          }
        }
        if (this.prescriptions[i].project != null) {
          for (let b = 0; b < this.prescriptions[i].project.length; b++) {

            total = parseFloat(total) + parseFloat(this.prescriptions[i].project[b].preselfpay_amt)
          }
        }

      }
      return total.toFixed(2)

    }, getInscpScpAmtTotal() {
      var total = 0
      for (let i = 0; i < this.prescriptions.length; i++) {
        if (this.prescriptions[i].advices != null) {
          for (let a = 0; a < this.prescriptions[i].advices.length; a++) {
            total = parseFloat(total) + parseFloat(this.prescriptions[i].advices[a].inscp_scp_amt)
          }
        }
        if (this.prescriptions[i].project != null) {
          for (let b = 0; b < this.prescriptions[i].project.length; b++) {

            total = parseFloat(total) + parseFloat(this.prescriptions[i].project[b].inscp_scp_amt)
          }
        }

      }
      return total.toFixed(2)

    },
    sz_open(index) {
      switch (index) {
        case 1:
          this.$refs.register9504.show()
          break
        case 2:
          var that = this
          if (this.activeName == 'first') {
            this.settle_accounts_type = 1

          } else {
            this.settle_accounts_type = 2
            this.start_time = this.other_start_time
            this.end_time = this.other_end_time
            this.settle_accounts_type = 2

          }
          let params = {
            'patient_id': this.patientInfo.id,
            'record_time': this.record_date,
            'settle_accounts_type': this.settle_accounts_type,
            'admin_user_id': this.$store.getters.xt_user.user.id
          }
          axios.get('http://127.0.0.1:9532/sz/api/upload/get', {
            params: params,
            headers: {
              'Permission': 5
            }
          })
              .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.changeRadioAndPatient(1)
                    that.$message({ message: '预结算成功', type: 'success' })
                  }

                }
              })
              .catch(function(error) {
              })
          break
        case 3:
          if (this.activeName == 'first') {
            this.$refs.charge.show(this.getTotal())
          } else {
            this.$refs.charge.show(this.getTotalTwo())
          }
          break
        case 4:
          break
        case 5:
          var that = this
          this.$confirm('是否退费', '退费', {
            confirmButtonText: '确 定',
            cancelButtonText: '取 消',
            type: 'warning'
          }).then(() => {
            axios.get('http://127.0.0.1:9532/sz/api/refund/get', {
              params: {
                order_id: this.order.id,
                record_time: this.record_date,
                admin_user_id: this.$store.getters.xt_user.user.id,
                patient_id: this.patientInfo.id
              }
            })
                .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.changeRadioAndPatient(1)
                      that.$message({ message: '退费成功', type: 'success' })
                    }
                  }
                })
                .catch(function(error) {
                })
          }).catch(() => {
          })
          break
        case 6:
          var that = this
          axios.get('http://127.0.0.1:9532/sz/api/settle/query', {
            params: {
              order_id: this.order.id,
              record_time: this.record_date,
              admin_user_id: this.$store.getters.xt_user.user.id,
              patient_id: this.patientInfo.id
            }
          })
              .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.$message({ message: '查询成功', type: 'success' })
                  }
                }
              })
              .catch(function(error) {
              })
          break
        case 7:
          var that = this
          axios.get('http://127.0.0.1:9532/sz/api/detail/cancel', {
            params: {
              order_id: this.order.id,
              record_time: this.record_date,
              admin_user_id: this.$store.getters.xt_user.user.id,
              patient_id: this.patientInfo.id

            }
          })
              .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.$message({ message: '明细撤销成功', type: 'success' })

                  }
                }
              })
              .catch(function(error) {
              })

          break
        case 10:
          this.newStatementVisible = true
          let obj = {
            record_time: this.record_date,
            patient_id: this.patient_id,
            prescription_id: this.prescription_id,
            order_id: this.order.id,
            admin_user_id: this.$store.getters.xt_user.user.id

          }
          this.newOrderObj = obj
          // this.$refs.print.getInfo(this.order.id)
          break
        case 11:
          var that = this
          this.$confirm('是否退号', '退号', {
            confirmButtonText: '确 定',
            cancelButtonText: '取 消',
            type: 'warning'
          }).then(() => {
            axios.get('http://127.0.0.1:9532/sz/api/refundnumber/get', {
              params: {
                order_id: this.order.id,
                record_time: this.record_date,
                admin_user_id: this.$store.getters.xt_user.user.id,
                patient_id: this.hisPatientInfo.patient_id
              }
            })
                .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.changeRadioAndPatient(1)
                      that.$message({ message: '退号成功', type: 'success' })
                    }
                  }
                })
                .catch(function(error) {
                })
          }).catch(() => {
          })
          break

      }

    }
  },
  mounted() {
    const that = this
    window.onresize = () => {
      return (() => {
        window.fullHeight = document.documentElement.clientHeight
        that.fullHeight = window.fullHeight
      })()
    }
  },
  watch: {
    fullHeight(val) {
      if (!this.timer) {
        this.fullHeight = val
        let tableHeight = val - 243
        this.tableHeight = tableHeight
        this.timer = true
        let that = this
        setTimeout(function() {
          that.timer = false
        }, 400)
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.app-container {
  height: 100%;
}

.outpatientChargesManagement {
  height: 100%;
  display: flex;
  flex-direction: column;

.mainLeft {
  width: 200px;
  height: 100%;
  display: flex;
  flex-direction: column;
  padding-top: 20px;

.el-radio {
  margin-right: 5px;
}

}
.mainCell {
  height: 36px;
  display: flex;
  align-items: center;
}

.fixedCell {
  position: fixed;
  z-index: 99;
  right: 42px;
  background: #fff;
  display: flex;
  justify-content: space-between;
}

.mainRight {
  margin-left: 10px;
  flex: 1;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow-y: auto;

.cellSpan {
  min-width: 80px;
  display: inline-block;
  margin-right: 10px;
}

}
.tabsBox {
  position: relative;
  height: 90%;
  overflow-y: auto;
  margin-bottom: 60px;

.el-tabs__item {
  padding: 0 10px;
}

}
.addTab {
  position: absolute;
  right: 6px;
  top: 3px;
  z-index: 20;
}

.mainCenter {
  display: flex;
  flex: 1;
  height: 100%;
}

.costBox {
  width: 100%;
  height: 60px;
  background: #fff;
  position: absolute;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.centerLeft {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
}

.preTabs {
  height: 100%;
  display: flex;
  flex-direction: column;

.el-tab-pane {
  height: auto !important;
}

}

.settlementTabs {
  flex: 1;

.el-tab-pane {
  height: 100%;
}

.el-tabs__content {
  height: 100%;
}

}
.centerRight {
  width: 300px;
  margin-left: 10px;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.RP {
  color: #409EFF;
  font-size: 20px;
  margin-bottom: 5px;
}

.centerRightTitle {
  color: #409EFF;
}

.basicUl {
  border-top: 1px solid #e5e5e5;
  border-left: 1px solid #e5e5e5;
  display: flex;
  flex-wrap: wrap;

li {
  border-bottom: 1px solid #e5e5e5;
  border-right: 1px solid #e5e5e5;
  width: 100%;
  min-height: 38px;
  /* line-height: 38px;
  text-indent: 5px; */
  font-size: 14px;
  display: flex;
  align-items: center;
  padding: 5px;
  box-sizing: border-box;
}

}
}
</style>

<style lang="scss">
#tab-more {

.el-icon-close {
  display: none;
}

}
.settlementTabs {

.el-tabs__content {
  height: 90%;
}

}
.preTabs {

.el-tabs__content {
  flex: 1;
  overflow-y: auto;
  padding: 5px 0 5px 5px;
}

}
.centerDialog {

.el-dialog__body {
  max-height: calc(100vh - 100px) !important;
  padding: 0 20px;
}

}
</style>

