<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"
          placeholder="选择开始时间"
          align="right"
          format="yyyy-MM-dd"
          value-format="yyyy-MM-dd">
        </el-date-picker>


        <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;" v-if="this.radio == 1">
          <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 class="mainCell" style="margin-bottom:10px;" v-if="this.radio == 2">
          <el-input size="small" v-model.trim="search_input_two"
                    class="filter-item"/>
          <el-button size="small" style="margin-left:10px;" class="filter-item" type="primary"
                     @click="searchActiontwo">
            搜索
          </el-button>
        </div>
        <div>
          <el-table v-if="this.radio == 1" :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>


          <el-table v-if="this.radio == 2" :data="upload_list" :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="handleCurrentChangetwo">
            <el-table-column align="center" prop="name" label="姓名" wdith='89'>
              <template slot-scope="scope">{{ scope.$index + 1 }}.{{ scope.row.his_patient.name }}</template>
            </el-table-column>
          </el-table>


        </div>
      </div>

      <div class="mainRight">

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

          <div v-if="this.radio == 1&&this.activeName=='first'">
            <el-button
              size="small"
              v-loading="isloading"
              :disabled="isdisabled"
              @click="open(1,0)"
              type="primary">上传明细
            </el-button>
          </div>
          <div v-if="this.radio == 2">
            <el-button
              size="small"
              @click="open(2,0)"
              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="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="tabclickEvent">
                      <el-tab-pane
                        v-for="(item, index) in prescriptions"
                        :key="index"
                        :label="item.name"
                        :name="item.name"
                      >
                        <el-button type="primary"  v-loading="isloading"
                                     :disabled="isdisabled"  @click="open(1,item.id)">上传处方费用</el-button>


                      </el-tab-pane>

                      <charge-month-prescription-table v-if="this.radio == 1"
                                                       :prescription="curPrescriptions"></charge-month-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>

                  </div>
                </div>

              </div>
            </el-tab-pane>
            <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="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
                        <div v-if="radio == 2">
                          <span>处方日期：{{ getTimes(zuobiao_info.start_time) }}~{{
                              getTimes(zuobiao_info.end_time)
                            }}</span>
                        </div>
                        <div v-if="radio == 2">
                          <span>医嘱单id：{{ zuobiao_info.cbm01 }}</span>
                        </div>
                        <el-date-picker
                          v-if="radio == 1"
                          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 v-if="radio == 1" class>-</span>
                        <el-date-picker
                          v-if="radio == 1"
                          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="请选择" v-if="radio == 1">
                          <el-option
                            v-for="item in upload_options"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                          </el-option>
                        </el-select>
                        <label>
                          疾病类型：
                        </label>
                        <el-select filterable v-model="sick_type" placeholder="请选择疾病类型">
                          <el-option
                            v-for="(item,index) in sick"
                            :key="index"
                            :label="item.class_name"
                            :value="item.id">
                          </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 v-if="this.radio == 1"
                                                       :prescription="curMonthPrescriptions"></charge-month-prescription-table>

                      <settle-prescription-table v-if="this.radio == 2"
                                                 :prescription="curMonthPrescriptions"></settle-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>


                  </div>
                </div>

              </div>
            </el-tab-pane>
          </el-tabs>
        </div>
      </div>
    </div>

  </div>

</template>


<script>
import axios from 'axios'
import { getUploadZuoBiaoPatientInfo, getZuoBiaoPatientInfo, getZuoBiaoPatientList } from '@/api/his/his_zuobiao'
import { uParseTime } from '@/utils/tools'
import { getInitData } from '@/api/his/his'

import MonthPrescriptionTable from './componenttwo/ChargePrescriptionTable'
import ChargeMonthPrescriptionTable from './componenttwo/chargeMonthPrescriptionTable'
import { getZuoBiaoPatientMonthInfo } from '../../api/his/his_zuobiao'
import SettlePrescriptionTable from '../hospitalStation/components/settlePrescriptionTable.vue'

const moment = require('moment')
export default {
  components: {
    SettlePrescriptionTable,
    ChargeMonthPrescriptionTable,
    MonthPrescriptionTable
  },
  data() {
    return {
      isloading: false,
      isdisabled: false,
      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: 1,
      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,
      zuobiao_info: {},

      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: {},
      prescription_info: {},
      loadingtwo: false,
      upload_list: [],
      patientTableData: [{}],
      patientInfo: { id: 0 },
      doctor: {},
      total: 0,
      state: '未收费',
      radio: 1,
      radioStatus: 1,
      search_input: '',
      search_input_two: '',
      start_time: moment().locale('zh-cn').format('YYYY-MM-DD'),
      patient_id: 0,
      prescription_id: 0,
      all_table_data: [],
      all_upload_list: [],
      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.getInitData()
    this.getPatientList()
  },
  methods: {
    getInitData() {
      getInitData().then(response => {
        if (response.data.state == 0) {
          this.$message.error(response.data.msg)
          return false
        } else {
          this.sick = response.data.data.sick
        }
      })

    },
    changeScheduleType() {

      this.getPatientList()

    },
    getMonthData() {
      this.loading = true

      let params = {
        'id': this.hisPatientInfo.id,
        'start_time': this.other_start_time,
        'end_time': this.other_end_time,
        'is_upload': this.month_is_upload
      }
      getZuoBiaoPatientMonthInfo(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.patient
          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)
    }, changeEndTime(val) {
      this.getPatientInformation(this.hisPatientInfo.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

        }
      }

    },
    searchActiontwo() {
      if (this.search_input_two.length == 0) {
        this.upload_list = this.all_upload_list

      } else {
        let arr2 = []
        for (let i = 0; i < this.all_upload_list.length; i++) {
          if (this.all_upload_list[i].his_patient.name.indexOf(this.search_input_two) != -1) {
            arr2 = arr2.concat(this.all_upload_list[i])
          }
        }
        this.upload_list = arr2
      }
    },

    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,id) {
      if (index == 2) {
        var that = this
        let obj3 = {
          id: this.zuobiao_info.id,
          admin_user_id: this.$store.getters.xt_user.user.id
        }
        axios.get('http://127.0.0.1:9532' + '/nmg/coordinate/settleAccount/cancel', {
          params: obj3
        })
          .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.$confirm(response.data.data.msg, '医保错误信息', {
                  confirmButtonText: '确 定',
                  type: 'warning'
                }).then(() => {

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

              } else {
                that.radio = 1
                that.getPatientList()

                that.$message({ message: '撤销成功', type: 'success', duration: 5000 })
              }

            }
          })
          .catch(function(error) {

          })
      } else if (index == 1) {
        this.isloading = true
        this.isdisabled = true
        var that = this
        if (this.hisPatientInfo.id == 0) {
          this.$message.error('请选择需要记账的患者')
          return
        }
        if (this.sick_type == 0 || this.sick_type == '') {
          this.$message.error('请选择疾病类型')
          return
        }

        let obj = {
          patient_id: this.hisPatientInfo.id,
          diagnosis_time: this.record_date,
          record_date: this.record_date,
          admin_user_id: this.$store.getters.xt_user.user.id,
          org_id: this.$store.getters.xt_user.org_id,
          sick_type: this.sick_type,
          settle_type: this.activeName,
          p_id:id,
        }
        if (this.activeName == "first"){
          obj['settle_accounts_type'] = 2
        }else{
          obj['settle_accounts_type'] = 1
        }
        obj['start_time'] = this.other_start_time
        obj['end_time'] = this.other_end_time
        axios.get('http://127.0.0.1:9532' + '/nmg/coordinate/settleAccount', {
          params: obj
        })
          .then(function(response) {
            if (response.data.state == 0) {
              that.$message.error(response.data.msg)
              that.isloading = false
              that.isdisabled = false

              return false
            } else {
              that.isloading = false
              that.isdisabled = false
              if (response.data.data.failed_code == -10) {
                that.$confirm(response.data.data.msg, '医保错误信息', {
                  confirmButtonText: '确 定',
                  type: 'warning'
                }).then(() => {

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

              } else {
                that.isloading = false
                that.isdisabled = false
                that.radio = 2
                that.$message({ message: '上传成功', type: 'success', duration: 5000 })
                that.getPatientList()
              }
            }
          })
          .catch(function(error) {
          })
      }
    }, 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.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

              this.$refs.tab.setCurrentRow(this.patientTableData[0])
              this.getPatientInformation(this.patientTableData[0].id)

              break
            case 2:
              this.all_table_data = response.data.data.list_two
              this.patientTableData = response.data.data.list_two
              this.upload_list = response.data.data.upload_list
              this.all_upload_list = response.data.data.upload_list
              this.$refs.tab.setCurrentRow(this.upload_list[0])
              console.log(this.upload_list[0].id)
              this.getPatientInformationtwo(this.upload_list[0].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
      }
      getZuoBiaoPatientList(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.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 && this.hisPatientInfo.id > 0) {
                for (let i = 0; i < this.patientTableData.length; i++) {
                  if (this.hisPatientInfo.id == this.patientTableData[i].id) {
                    this.$refs.tab.setCurrentRow(this.patientTableData[i])
                  }
                }
              } else {
                this.$refs.tab.setCurrentRow(this.patientTableData[0])
                this.getPatientInformation(this.patientTableData[0].id)
              }
              break
            case 2:
              this.all_table_data = response.data.data.list_two
              this.patientTableData = response.data.data.list_two
              this.upload_list = response.data.data.upload_list
              this.all_upload_list = response.data.data.upload_list
              if (this.hisPatientInfo && this.hisPatientInfo.id > 0) {
                for (let i = 0; i < this.upload_list.length; i++) {
                  if (this.hisPatientInfo.id == this.upload_list[i].his_patient.id) {
                    this.$refs.tab.setCurrentRow(this.upload_list[i])
                    this.getPatientInformation(this.upload_list[0].his_patient.id)

                  }
                }
              } else {
                this.$refs.tab.setCurrentRow(this.upload_list[0])
                this.getPatientInformation(this.upload_list[0].his_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['project'] = project_month_prescriptions.project[a].project

              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['good_info'] = project_month_prescriptions.project[a].good_info

              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)
    },
    handleCurrentChangetwo(val) {
      this.getPatientInformationtwo(val.id)
    },
    //获取患者的基本信息
    getPatientInformationtwo(id) {
      console.log(id)
      let params = {
        'id': id
      }
      this.loading = true
      getUploadZuoBiaoPatientInfo(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.zuobiao_info = {}
          this.loading = false
          this.prescription_info = response.data.data.prescription_info
          this.sick_type = this.prescription_info.sick_type
          if (this.sick_type == 0) {
            this.sick_type = ''
          }
          console.log(this.sick_type)
          this.hisPatientInfo = response.data.data.patient
          this.zuobiao_info = response.data.data.zuobiao_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].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()

        }
      })
    },
    getPatientInformation(id) {
      let params = {
        'id': id,
        'record_date': this.record_date,
        'start_time': this.other_start_time,
        'end_time': this.other_end_time,
        'is_upload': this.radio
      }
      this.loading = true
      getZuoBiaoPatientInfo(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.patient
          this.prescription_info = response.data.data.prescription_info
          this.sick_type = this.prescription_info.sick_type
          if (this.sick_type == 0) {
            this.sick_type = ''
          }
          console.log(this.sick_type)
          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].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['project'] = prescription.project[b].project

                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
                obj['good_info'] = prescription.project[b].good_info

              }

              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.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;
  padding-top: 10px;
}

.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>

