<template>
  <div class="main-contain outpatientChargesManagement">
    <div class="position">
      <bread-crumb :crumbs="crumbs"></bread-crumb>
    </div>
    <div class="app-container">
      <div style=" display: flex; justify-content: space-between;  margin-bottom: 10px;">
        <div class="content_top" style="margin-right: 10px;">
          <div style="width: 60%;">
            <el-input  style="width: 60%"
              v-model="keywords" @input="searchAction"
              @keyup.enter.native="searchAction"
              class="filter-item" placeholder="请输入患者姓名"
            />
            <el-button  class="filter-item" type="primary" @click="searchAction">
              搜索
            </el-button>
          </div>

          <div>
            <el-select  v-model="sort_type"
              placeholder="请选择"
              style="width: 100%;"
              @change="changeSortType"
            >
              <el-option
                v-for="(item, index) in sort_types"
                :key="index"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </div>

          <div style="margin: 0 5px;">
            <el-select v-model="sch_type" placeholder="请选择班次" @change="handleSchType" style="width: 100%;">
              <el-option label="全部" value="0"></el-option>
              <el-option label="上午" value="1"></el-option>
              <el-option label="下午" value="2"></el-option>
              <el-option label="晚上" value="3"></el-option>
            </el-select>
          </div>

          <div>
            <el-select v-model="zoneVal" placeholder="请选择分区" style="width: 100%;" @change="handleZoneChange">
              <el-option
                v-for="item in zone_options"
                :key="item.id"
                :label="item.text"
                :value="item.id">
              </el-option>
            </el-select>
          </div>
        </div>
        <div class="content_button"  style="">
          <el-button
            size="small" type="primary" @click="query">查询
          </el-button>
          <el-button
            v-if="$store.getters.xt_user.org_id == 10138 || $store.getters.xt_user.org_id == 10278 ||
                $store.getters.xt_user.org_id == 10610 || $store.getters.xt_user.org_id == 0"
            size="small" type="primary" @click="batch_print_settlte">批量打印结算单
          </el-button>
          <el-button size="small" type="primary" @click="export_detail"
          >报表下载
          </el-button>
          <el-button v-if="$store.getters.xt_user.org_id == 10106 " size="small"
                     type="primary" @click="export_detail_ten">报表下载2
          </el-button>
          <el-button v-if="$store.getters.xt_user.org_id == 10318" size="small"
                     type="primary" @click="export_detail_ten_two">报表下载3
          </el-button>


        </div>
      </div>

      <div style=" display: flex; justify-content: space-between;  margin-bottom: 10px;">
        <div class="content_top" style="margin-right: 10px;">
          <div style="">
            <el-date-picker size="small" v-model="start_time" prefix-icon="el-icon-date"
              @change="handleStartTimeChange":editable="false" :clearable="false"
              style="width: 45%;"
              type="date"
              placeholder="选择开始日期"
              format="yyyy-MM-dd"
              value-format="yyyy-MM-dd"
              align="right"
            ></el-date-picker>
            <span style="text-align: center;">-</span>
            <el-date-picker
              size="small"
              v-model="end_time"
              prefix-icon="el-icon-date"
              @change="handleEndTimeChange"
              :editable="false"
              :clearable="false"
              style="width: 45%;"
              type="date"
              placeholder="选择结束日期"
              format="yyyy-MM-dd"
              value-format="yyyy-MM-dd"
              align="right"
            ></el-date-picker>
          </div>
          <div>
            <el-select  v-model="staff" placeholder="请选择缴费人员"
                   style="width:100%;" >
              <el-option
                v-for="item,index in admins"
                :key="index"
                :label="item.user_name"
                :value="item.user_name">
              </el-option>
            </el-select>
          </div>
          <div style="margin-left: 5px;">
            <el-select v-model="medTypeVal" @change="handleMedChange"
              placeholder="请选择医疗类别" style="width: 100%;"
            >
              <el-option
                v-for="item in med_options"
                :key="item.id"
                :label="item.text"
                :value="item.id">
              </el-option>
            </el-select>
          </div>


        </div>
        <div class="content_button">
          <el-button size="small" type="primary" @click="export_detail_three" v-if="$store.getters.xt_user.org_id == 10265 || $store.getters.xt_user.org_id == 0">报表下载12</el-button>
          <el-button size="small" type="primary" @click="accounts_click()">门诊结账</el-button>
          <el-button size="small" type="primary" @click="export_detail_six">诊疗下载</el-button>
          <el-button size="small" type="primary" @click="export_detail_ten_five">导出就诊凭证类型人员</el-button>
        </div>
      </div>

      <div style=" display: flex; justify-content: space-between;  margin-bottom: 10px;">
        <div class="content_top">
          <el-date-picker size="small"
            v-model="pay_time"
            prefix-icon="el-icon-date"
            :editable="false"
            :clearable="false"
            style="width:250px; "
            type="datetime"
            placeholder="选择缴费日期"
            format="yyyy-MM-dd HH:mm:ss"
            value-format="yyyy-MM-dd HH:mm:ss"
            align="right"
          ></el-date-picker>
        </div>
        <div class="content_top"></div>
      </div>

      <el-table
        :data="tableData"
        border
        style="width: 100%"
        :row-style="{ color: '#303133' }"
        @selection-change="handleSelectionChange"
        :header-cell-style="{
          backgroundColor: 'rgb(245, 247, 250)',
          color: '#606266',
        }"
        highlight-current-row
        height="calc(100vh - 300px)"
      >
        <el-table-column align="center" type="selection" width="50"></el-table-column>
        <el-table-column
          prop="date"
          label="序号"
          width="40"
          align="center"
          type="index"
        >
        </el-table-column>
        <el-table-column align="center" width="80" prop="name" label="就诊号">
          <template slot-scope="scope">{{ scope.row.mdtrt_id }}</template>
        </el-table-column>
        <el-table-column align="center" width="80" prop="name" label="患者名字">
          <template slot-scope="scope">{{ scope.row.patient.name }}</template>
        </el-table-column>

        <el-table-column align="center" width="60" prop="name" label="患者性别">
          <template slot-scope="scope">{{ scope.row.patient.gender == 1 ? '男':'女' }}</template>
        </el-table-column>

        <el-table-column align="center" width="60" prop="name" label="患者年龄">
          <template slot-scope="scope">{{getAge(scope.row.patient.id_card_no)}}</template>
        </el-table-column>
        <el-table-column align="center" width="90" prop="name" label="患者类型">
          <template slot-scope="scope">
            {{ getpatient(scope.row.patient.patient_type) }}
          </template>
        </el-table-column>

        <el-table-column align="center" width="80" prop="name" label="应收金额">
          <template slot-scope="scope">{{
              scope.row.medfee_sumamt.toFixed(2)
            }}
          </template>
        </el-table-column>
        <el-table-column align="center" width="80" prop="name" label="实收金额">
          <template slot-scope="scope">{{
              scope.row.medfee_sumamt.toFixed(2)
            }}
          </template>
        </el-table-column>
        <el-table-column align="center" width="80" prop="name" label="折扣金额">
          <template slot-scope="scope">{{
              scope.row.discount_price.toFixed(2)
            }}
          </template>
        </el-table-column>

        <el-table-column align="center" width="80" prop="name" label="优惠金额">
          <template slot-scope="scope">{{
              scope.row.preferential_price.toFixed(2)
            }}
          </template>
        </el-table-column>

        <el-table-column align="center" width="70" prop="name" label="科室">
          <template slot-scope="scope">{{
              scope.row.department_name
            }}
          </template>
        </el-table-column>
        <el-table-column align="center" width="90" prop="name" label="医疗类型">
          <template slot-scope="scope">
            <div>{{ getMedType(scope.row.med_type) }}</div>
          </template>
        </el-table-column>

        <el-table-column align="center" width="60" prop="name" label="收费类型">
          <template slot-scope="scope">
            <div v-if="scope.row.is_medicine_insurance == 1">
              医保
            </div>
            <div v-if="scope.row.is_medicine_insurance != 1">
              自费
            </div>
          </template>
        </el-table-column>

        <el-table-column align="center" width="60" prop="name" label="险种类型">
          <template slot-scope="scope">
            <div v-if="scope.row.insutype == '390'">
              城乡居民
            </div>
            <div v-if="scope.row.insutype == '310'">
              职工
            </div>
          </template>
        </el-table-column>


        <el-table-column align="center" width="90" prop="name" label="就诊凭证类型">
          <template slot-scope="scope">
            <div v-if="scope.row.mdtrt_cert_type =='01'">
              医保电子凭证
            </div>
            <div v-if="scope.row.mdtrt_cert_type =='02'">
              居民身份证
            </div>

            <div v-if="scope.row.mdtrt_cert_type =='03'">
              社会保障卡
            </div>
          </template>
        </el-table-column>

        <el-table-column align="center" width="100" prop="name" label="收费日期">
          <template slot-scope="scope">
            {{
              scope.row.setl_time
                ? scope.row.setl_time
                : getTimes(scope.row.settle_accounts_date)
            }}
          </template>
        </el-table-column>
        <el-table-column align="center" width="65" prop="name" label="收费员">
          <template slot-scope="scope">{{
              getName(scope.row.creator)
            }}
          </template>
        </el-table-column>
        <el-table-column align="center" width="65" prop="name" label="状态">
          <template slot-scope="scope">
            <div v-if="scope.row.order_status == 1">待结算</div>
            <div v-if="scope.row.order_status == 2">已结算</div>
            <div v-if="scope.row.order_status == 3">已退费</div>
          </template>
        </el-table-column>
        <el-table-column align="center" width="" prop="name" label="操作">
          <template slot-scope="scope">
            <el-button class="butt_1" size="mini" type="primary" @click="toDetail(scope.row)"
            >详情
            </el-button
            >
            <el-button class="butt_2" size="mini" type="primary" @click="toPrint(scope.row)">
              结算单
            </el-button>
            <el-button v-if="$store.getters.xt_user.org_id == 10191" class="butt_2" size="mini" type="primary"
                       @click="tolistPrint(scope.row)">
              结算清单
            </el-button>
            <el-button
              class="butt_2"
              size="mini"
              type="primary"
              @click="uploadInfo(scope.row)"
              v-if="scope.row.order_status == 2 && scope.row.result.id == 0"
            >
              上传结算清单

            </el-button>

            <el-button
              class="butt_2"
              size="mini"
              type="primary"
              @click="confirmUploadInfo(scope.row)"
              v-if="$store.getters.xt_user.org_id == 10265 || $store.getters.xt_user.org_id == 10191"
            >
              确认结算清单
            </el-button>

            <el-button
              class="butt_2"
              size="mini"
              type="primary"
              @click="cancelUploadTwo(scope.row)"
              v-if="$store.getters.xt_user.org_id == 10265"
            >
              取消结算清单
            </el-button>

            <el-button
              class="butt_2"
              size="mini"
              type="primary"
              @click="queryData(scope.row)"
              v-if="$store.getters.xt_user.org_id == 10265"
            >
              查询结算清单
            </el-button>

            <el-button
              class="butt_2"
              size="mini"
              type="primary"
              @click="cancelUpload(scope.row)"
              v-if="$store.getters.xt_user.org_id != 10265 && scope.row.order_status == 2 && scope.row.result.id > 0"
            >
              撤销结算清单
            </el-button>

            <el-button
              class="butt_2"
              size="mini"
              type="primary"
              @click="cancelUploadThree(scope.row)"
            >
              更改结算清单状态为未提交
            </el-button>
            <el-button
              class="butt_2"
              size="mini"
              type="primary"
              v-if="
                scope.row.order_status == 2 &&
                $store.getters.xt_user.org_id == 10106
              "
              @click="settlementPrint(scope.row)"
            >结算单
            </el-button>
            <el-button class="butt_2" size="mini" type="primary" @click="toRefund(scope.row)">
              退费
            </el-button>
            <el-button
              class="butt_2"
              size="mini"
              type="primary"
              @click="invoicePrint(scope.row)"
            >打印发票
            </el-button>
            <el-button
              class="butt_2"
              size="mini"
              type="primary"
              @click="open(scope.row)"
            >打印清单
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :page-sizes="[10, 50, 100]"
        :page-size="10"
        :current-page.sync="page"
        background
        style="margin-top: 20px; float: right"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </div>

    <el-dialog
      class="centerDialog"
      width="1200px"
      title="打印"
      :visible.sync="statementVisible"
    >
      <!--<statementPrint ref="print" :paramsObj='orderObj'></statementPrint>-->
      <new-statement-print
        ref="print"
        :paramsObj="orderObj"
      ></new-statement-print>
    </el-dialog>

    <!-- 批量打印 -->
    <el-dialog
      class="centerDialog"
      width="1200px"
      title="打印"
      :visible.sync="batchStatementVisible"
    >
      <!--      <batchStatementPrint-->
      <!--        ref="batchPrint"-->
      <!--        :paramsObj="batchOrderObj"-->
      <!--      ></batchStatementPrint>-->
      <batch-statement-print
        ref="batchPrint"
        :paramsObj="batchOrderObj"
      ></batch-statement-print>
    </el-dialog>

    <el-dialog
      class="centerDialog"
      width="1200px"
      title="打印"
      :visible.sync="statementListVisible"
    >
      <!--<statementPrint ref="print" :paramsObj='orderObj'></statementPrint>-->
      <statement-list-print ref="printlist" :paramsObj='orderObj'></statement-list-print>
    </el-dialog>
    <!-- 打印结算清单 -->
    <el-dialog
      class="centerDialog"
      width="900px"
      title="打印"
      :visible.sync="listVisible"
    >
      <listPrint ref="checklists" :paramsObj='paramsObj' :key="jgFileTimer"></listPrint>
    </el-dialog>

    <el-dialog
      class="centerDialog"
      width="900px"
      title="打印"
      :visible.sync="allListVisible"
    >
      <allListPrint :paramsObj="paramsObj"></allListPrint>
    </el-dialog>

    <!--<el-dialog-->
    <!--class="centerDialog"-->
    <!--width="1200px"-->
    <!--title="打印"-->
    <!--:visible.sync="statementVisible9504">-->
    <!--&lt;!&ndash;<statementPrint ref="print" :paramsObj='orderObj'></statementPrint>&ndash;&gt;-->
    <!--&lt;!&ndash;<new-statement-print ref="print" :paramsObj='orderObj9504'></new-statement-print>&ndash;&gt;-->
    <!--<new-statement-print-two ref="print" :paramsObj='orderObj9504'></new-statement-print-two>-->
    <!--</el-dialog>-->

    <el-dialog
      class="centerDialog"
      width="1200px"
      title="打印"
      :visible.sync="invoiceVisible"
    >
      <invoice-print ref="print" :invoiceParams="invoiceParams"></invoice-print>
    </el-dialog>
    <el-dialog
      class="centerDialog"
      width="1200px"
      title="打印"
      :visible.sync="settlementVisible"
    >
      <settlement-print
        ref="print"
        :paramsObj="settlementObj"
      ></settlement-print>
    </el-dialog>

    <el-dialog
      class="centerDialog"
      width="1200px"
      title="打印"
      :visible.sync="settlementVisible"
    >
      <settlement-print
        ref="print"
        :paramsObj="settlementObj"
      ></settlement-print>
    </el-dialog>
    <!-- 门诊结账 -->
    <el-dialog
      class="centerDialog"
      width="70%"
      title="打印"
      :visible.sync="accounts_click_vi"
    >
      <div>
        <div id="accounts_print">
          <div style="text-align: center;font-size: 18px;margin-bottom:20px ;">门诊结账</div>
          <div style="margin: auto;">
            <div style="margin-bottom: 20px;">
              <table class="table" border="1" style="border-collapse: collapse;text-align: center;width: 100%;">
                <tr>
                  <td>起始日期:</td>
                  <td>{{start_time}}</td>
                  <td>终止日期:</td>
                  <td>{{end_time}}</td>
                  <td>缴款日期:</td>
                  <td>{{pay_time}}</td>
                </tr>
                <tr>
                  <td>起始单号:</td>
                  <td v-if="tableData2&&tableData2.length > 0">{{tableData2[0].number}}</td>
                  <td v-else></td>
                  <td>终止单号:</td>
                  <td v-if="tableData2&&tableData2.length > 0">{{tableData2[tableData2.length-1].number}}</td>
                  <td v-else></td>
                  <td>缴款人员:</td>
                  <td>{{staff}}</td>
                </tr>
                <tr>
                  <td>收费张数:</td>
                  <td v-if="tableData2">{{tableData2.length}}</td>
                  <td v-else></td>

                  <td>作废张数:</td>
                  <td>0</td>
                  <td>退费张数:</td>
                  <td>0</td>
                </tr>
                <tr>
                  <td>收费金额:</td>
                  <td>{{getTotal()}}</td>
                  <td>作废金额:</td>
                  <td>0</td>
                  <td>退费金额:</td>
                  <td>0</td>
                </tr>
                <tr>
                  <td>合计张数:</td>
                  <td v-if="tableData2">{{tableData2.length}}</td>
                  <td v-else></td>
                  <td>合计金额:</td>
                  <td colspan="3">{{getTotal()}}</td>
                </tr>
              </table>
            </div>
            <div style="margin-bottom: 20px;">
              <table class="table" border="1" style="border-collapse: collapse;text-align: center;width: 50%;">
                <tr>
                  <td>医保</td>
                  <td>微信</td>
                  <td>现金</td>
                  <td>门诊预存</td>
                  <td>合计</td>
                </tr>
                <tr>
                  <td>{{getYibao()}}</td>
                  <td>0</td>
                  <td>{{getPsnCash()}}</td>
                  <td>0</td>
                  <td>{{getTotal()}}</td>
                </tr>
              </table>
            </div>
            <div>
              <table class="table" border="1" style="border-collapse: collapse;text-align: center;width: 100%;">
                <tr>
                  <td>单号</td>
                  <td>卡号</td>
                  <td>姓名</td>
                  <td>年龄</td>
                  <td>性别</td>
                  <td>收费金额</td>
                  <td>收费时间</td>
                  <td>类型</td>
                </tr>
                <tr v-for="item in tableData2">
                  <td>{{item.number}}</td>
                  <td>{{item.certno}}</td>
                  <td>{{item.psn_name}}</td>
                  <td>{{item.patient.age}}</td>
                  <td v-if="item.gend == 1">男</td>
                  <td v-if="item.gend != 1">女</td>
                  <td>{{item.medfee_sumamt}}</td>
                  <td>{{item.setl_time}}</td>
                  <td></td>
                </tr>
              </table>
            </div>
          </div>

        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="accounts_click_vi = false">取 消</el-button>
        <el-button type="primary" @click="accounts_sum">确 定</el-button>
      </span>
    </el-dialog>

    <el-dialog title="修改发票号码" :visible.sync="dialogfapiaoVisible">
      <el-input v-model="fapiao_number" type="text"></el-input>
      <div slot="footer" class="dialog-footer">
        <el-button @click="camcleModifyFaPiaoCode">取 消</el-button>
        <el-button type="primary" @click="modifyFaPiaoCode">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>


<script>
import BreadCrumb from '@/xt_pages/components/bread-crumb'
import { getDoctorList, getExportConsumeDetailList, getHisOrderList, Refund } from '@/api/his/his'
import { ModifyFapiaoCode } from '@/api/his/his_tools'

// import NewStatementPrint from './newStatementPrint'
import { adminMainView} from "@/api/role/admin";
import NewStatementPrint from './statementPrint.vue'
import listPrint from './listPrint'
import allListPrint from './allListPrint'
import NewStatementPrintTwo from './newStatementPrintTwo'
import { fetchAllAdminUsers } from '@/api/doctor'
import axios from 'axios'
import invoicePrint from './invoicePrint'
import settlementPrint from './settlementPrint'
import { jsGetAge, uParseTime } from '@/utils/tools'
import {
  exportOrderInfo,
  getAllOrders,
  getHisDataFive,
  getHisDataSix,
  getHisDataThree,
  getHisDataTwo,
  handleOne,
  getHisOrderListtwo,
  modifyFapiaoCodetwo
} from '../../api/his/his'

import { handleData10106, handleData10138Two, handleData10318 } from '../../api/his/his_export'
import StatementListPrint from './statementListPrint'
import { getDialysisRecordInitData } from '@/api/dialysis_record'
import BatchStatementPrint from './batchStatementPrint'
import { exportMdtrtCertType } from '../../api/his/his_tools'

const moment = require('moment')
export default {
  name: 'OutpatientChargesSummary',
  components: {
    BatchStatementPrint,
    StatementListPrint,
    NewStatementPrintTwo,
    NewStatementPrint,
    BreadCrumb,
    listPrint,
    allListPrint,
    invoicePrint,
    settlementPrint,
  },
  data() {
    return {
      staff:"",
      admins:[],
      orderObj: {},
      batchOrderObj: {},
      fapiao_number:"",
      med_options: [
        { id: 0, text: '全部' },
        { id: 11, text: '普通门诊' },
        { id: 14, text: '门诊特殊病' }
      ],
      zone_options: [
        { id: 0, text: '全部分区' }
      ],
      statementListVisible: false,
      statementVisible: false,
      batchStatementVisible: false,
      statementVisible9504: false,
      orderObj9504: {},
      crumbs: [
        { path: false, name: '门诊收费' },
        { path: false, name: '项目消费明细汇总' }
      ],
      tableData: [],
      tableData2:[],
      selecting_schs: [],
      dialogfapiaoVisible:false,
      targeOrderId:0,
      targeObj:{},
      limit: 10,
      page: 1,
      keywords: '',
      sch_type: '0',//班次
      zoneVal: 0,//分区
      medTypeVal: 0,
      start_time: moment(new Date()).add('year', 0).format('YYYY-MM-DD'),
      end_time: moment(new Date()).add('year', 0).format('YYYY-MM-DD'),
      pay_time:"",
      total: '',
      doctors: [],
      sort_type: 1,
      sort_types: [
        { value: 1, label: '处方时间' },
        { value: 2, label: '结算时间' }
      ],
      admin_user_id: '',
      listVisible: false,
      allListVisible: false,
      adminUserOptions: [],
      invoiceVisible: false,
      paramsObj: {id:''},
      invoiceParams: {},
      settlementVisible: false,
      settlementObj: {},
      accounts_click_vi:false,
      org_id:'',
      patienttypeArr:[{value:1,label:'血透患者'},{value:2,label:'慢病患者'},{value:3,label:'会员患者'},
                        {value:4,label:'腹透患者'},{value:5,label:'CKD患者'},{value:6,label:'其他患者'}
      ],
      jgFileTimer:''
    }
  },

  //判断列表页是否刷新
  beforeRouteEnter(to, from, next) {
    console.log(from, 'beforeRouteEnter')
    if (from.path == '/outpatientCharges/summaryDetail') {
      next((vm) => {
        vm.page = vm.$store.getters.pagedata.list.page
        vm.limit = vm.$store.getters.pagedata.list.limit
        vm.keywords = vm.$store.getters.pagedata.list.keywords
        vm.start_time = vm.$store.getters.pagedata.list.start_time
        vm.end_time = vm.$store.getters.pagedata.list.end_time
        vm.admin_user_id = vm.$store.getters.pagedata.list.admin_user_id
        vm.p_type = 2
        vm.sort_type = vm.$store.getters.pagedata.list.sort_type
        setTimeout(() => {
          vm.getHisOrderList()
        }, 300)

      })
    } else {
      next()
    }
  },

  beforeRouteLeave(to, from, next) {
    if (to.path == '/outpatientCharges/summaryDetail') {
      console.log(to.path, '路由跳转判断')
      this.setStorage()
      next()
    } else {
      next()
    }
  },

  created() {
    this.getInitData()
    this.fetchAllAdminUsers()
    this.getDoctorList()
    this.getHisOrderList()
    this.getAllstaff()
    this.org_id == this.$store.getters.xt_user.org.id
  },

  methods: {
    // 患者类型
    getpatient(id){
      const options = this.patienttypeArr
      if(id !=0&&id!=''){
        for(let i in options){
          if(id == options[i].value){
            return options[i].label
          }
        }
      }else{
        return ''
      }
    },
    query(){
      this.getHisOrderList()
    },
    getAge(UUserCard) {
      if (UUserCard != null && UUserCard != '') {
        //获取年龄
        var myDate = new Date();
        var month = myDate.getMonth() + 1;
        var day = myDate.getDate();
        var age = myDate.getFullYear() - UUserCard.substring(6, 10) - 1;
        if (UUserCard.substring(10, 12) < month || UUserCard.substring(10, 12) == month && UUserCard.substring(12, 14) <= day) {
          age++;
        }
        return age;
      }
    },
    accounts_click(){
      let params = {
        start_time: this.start_time,
        end_time: this.end_time,
      }
      getHisOrderListtwo(params).then((response) => {
        if (response.data.state == 0) {
          this.$message.error(response.data.msg)
          return false
        } else {
          this.accounts_click_vi=  true
          this.tableData2 =  response.data.data.order2

        }
      })

    },
    getPsnCash(){
      let result = 0
      if(this.tableData2 != null) {
        for (let i = 0; i < this.tableData2.length; i++) {
          result = result + this.tableData2[i].psn_cash_pay
        }
      }
        return result.toFixed(2)
    },
    getYibao(){
      let result = 0
      if(this.tableData2 != null) {

        for (let i = 0; i < this.tableData2.length; i++) {
          result = result + this.tableData2[i].fund_pay_sumamt
        }
      }
      return result.toFixed(2)
    },
    getTotal(){
     let result = 0
      if(this.tableData2 != null) {

        for (let i = 0; i < this.tableData2.length; i++) {
          result = result + this.tableData2[i].medfee_sumamt
        }
      }
      return result.toFixed(2)
    },
    getAllstaff(){
      adminMainView()
        .then(rs => {

          var resp = rs.data;
          if (resp.state === 1) {
            var adminData = resp.data.admins
            this.admins.push(...adminData);
          } else {
            this.$message.error(resp.msg);
          }
        })
        .catch(err => {
          this.$message.error(err);
        });


    },
    // 门诊结账
    accounts_sum(){
      const style = '@media print {#accounts_print{font-size:15px} .table tr td{padding:5px 0;}}'
      printJS({
        printable: "accounts_print",
        type: "html",
        style: style,
        scanStyles: false
      });

    },
    handleSelectionChange(val) {
      this.selecting_schs = val
    },
    handleSchType(val) {
      this.sch_type = val
      // this.getHisOrderList()
    }, handleMedChange() {
      // this.getHisOrderList()
    },
    handleZoneChange(val) {
      this.zoneVal = val
      // this.getHisOrderList()

    },
    getInitData: function() {
      getDialysisRecordInitData().then((rs) => {
        var resp = rs.data
        if (resp.state == 1) {
          var zones = resp.data.zones
          var zone_options = [{ id: 0, text: '全部' }]
          for (let z_i = 0; z_i < zones.length; z_i++) {
            const zone = zones[z_i]
            zone_options.push({ id: zone.id, text: zone.name })
          }
          this.zone_options = zone_options

        } else {
          this.$message.error(resp.msg)
        }
      })
    },

    setStorage() {
      this.$store.commit('SET_PAGEDATA', {
        page: this.page,
        limit: this.limit,
        keywords: this.keywords,
        start_time: this.start_time,
        end_time: this.end_time,
        type: this.admin_user_id || '',
        p_type: 2,
        sort_type: this.sort_type
      })
    },

    getMedType(med_type) {
      var med_type = parseInt(med_type)
      switch (med_type) {
        case 11:
          return '普通门诊'
          break
        case 12:
          return '门诊挂号'
          break
        case 13:
          return '急诊'
          break
        case 14:
          return '门诊特殊病'
          break
        case 15:
          return '门诊统筹'
          break
        case 16:
          return '门诊慢性病'
          break
        case 21:
          return '普通住院'
          break
        case 140104:
          return '城乡门诊特殊病(140104)'
          break
        case 992102:
          return '单病种(992102)'
          break
      }
    },
    cancelUploadTwo(row) {
      if (this.$store.getters.xt_user.org_id == 10265) {
        var that = this
        axios
          .get('http://127.0.0.1:9532/api/4102', {
            params: {
              order_id: row.id,
              admin_user_id: this.$store.getters.xt_user.user.id,
              stas_type: 0
            }
          })
          .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('撤销成功')
                row.result.id = 0
              }
            }
          })
          .catch(function(error) {
          })
      }
    },
    cancelUpload(row) {
      var that = this
      axios
        .get('http://127.0.0.1:9532/zh/api/clearsettle', {
          params: {
            order_id: row.id,
            admin_user_id: this.$store.getters.xt_user.user.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.success('撤销成功')
              row.result.id = 0
            }
          }
        })
        .catch(function(error) {
        })

    },
    uploadInfo(row) {
      var that = this
      axios
        .get('http://127.0.0.1:9532/api/settlelist/get', {
          params: {
            order_id: row.id,
            admin_user_id: this.$store.getters.xt_user.user.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.success('上传成功')
              row.result.id = response.data.data.result.id
            }
          }
        })
        .catch(function(error) {
        })
    }, export_detail_zzzz() {
      handleTeamData({}).then((response) => {
        if (response.data.state == 0) {
          this.$message.error(response.data.msg)
          return false
        } else {
          let list = []
          for (let i = 0; i < response.data.data.ps.length; i++) {
            let order = response.data.data.ps[i]
            let obj = {
              id: order.team_id,
              name: order.pn,
              sub_id: order.project.id,
              sub_name: order.project.project_name
            }
            list.push(obj)
          }

          var tarList = []
          for (let i = 0; i < list.length; i++) {
            let obj = {
              '大项id': list[i].id,
              '大项名称': list[i].name,
              '子项id': list[i].sub_id,
              '子项名称': list[i].sub_name
            }
            tarList.push(obj)
          }

          import('@/vendor/Export2Excel').then((excel) => {
            const tHeader = [
              '大项id',
              '大项名称',
              '子项id',
              '子项名称'
            ]
            const filterVal = [
              '大项id',
              '大项名称',
              '子项id',
              '子项名称'
            ]
            const data = this.formatJson(filterVal, tarList)
            excel.export_json_to_excel({
              header: tHeader,
              data,
              filename: '消费明细'
            })
          })
        }
      })

    },
    queryData(row) {
      var that = this
      axios
        .get('http://127.0.0.1:9532/api/4103', {
          params: {
            order_id: row.id,
            admin_user_id: this.$store.getters.xt_user.user.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
                .$confirm(response.data.data.msg, '医保错误信息', {
                  confirmButtonText: '确 定',
                  type: 'warning'
                })
                .then(() => {
                })
                .catch(() => {
                })
            } else {
              that
                .$confirm(response.data.data.msg, '医保信息', {
                  confirmButtonText: '确 定'
                })
                .then(() => {
                })
                .catch(() => {
                })
            }
          }
        })
        .catch(function(error) {
        })

    }, cancelUploadThree(row) {
      var that = this
      // if(this.$store.getters.xt_user.org_id == 10191){
      axios
        .get('http://127.0.0.1:9532/api/comfirm/upload', {
          params: {
            order_id: row.id,
            admin_user_id: this.$store.getters.xt_user.user.id,
            stas_type: 0
          }
        })
        .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
                .$confirm(response.data.data.msg, '医保错误信息', {
                  confirmButtonText: '确 定',
                  type: 'warning'
                })
                .then(() => {
                })
                .catch(() => {
                })
            } else {
              that.$message.success('确认成功')
              row.result.id = response.data.data.result.id
            }
          }
        })
        .catch(function(error) {
        })
      // }
    },
    confirmUploadInfo(row) {
      var that = this
      if (this.$store.getters.xt_user.org_id == 10191) {
        axios
          .get('http://127.0.0.1:9532/api/comfirm/upload', {
            params: {
              order_id: row.id,
              admin_user_id: this.$store.getters.xt_user.user.id,
              stas_type: 1
            }
          })
          .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
                  .$confirm(response.data.data.msg, '医保错误信息', {
                    confirmButtonText: '确 定',
                    type: 'warning'
                  })
                  .then(() => {
                  })
                  .catch(() => {
                  })
              } else {
                that.$message.success('确认成功')
                row.result.id = response.data.data.result.id
              }
            }
          })
          .catch(function(error) {
          })
      } else {
        axios
          .get('http://127.0.0.1:9532/api/4102', {
            params: {
              order_id: row.id,
              admin_user_id: this.$store.getters.xt_user.user.id,
              stas_type: 1
            }
          })
          .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
                  .$confirm(response.data.data.msg, '医保错误信息', {
                    confirmButtonText: '确 定',
                    type: 'warning'
                  })
                  .then(() => {
                  })
                  .catch(() => {
                  })
              } else {
                that.$message.success('确认成功')
                row.result.id = response.data.data.result.id
              }
            }
          })
          .catch(function(error) {
          })

      }

    },

    fetchAllAdminUsers() {
      fetchAllAdminUsers().then((response) => {
        if (response.data.state == 1) {
          this.adminUserOptions = response.data.data.users
        }
      })
    },
    getName(admin_user_id) {
      for (let i = 0; i < this.adminUserOptions.length; i++) {
        if (this.adminUserOptions[i].id == admin_user_id) {
          return this.adminUserOptions[i].name
        }
      }
    },
    toRefund(row) {
      if (row.his_patient.balance_accounts_type == 2) {
        this.$confirm('是否退费', '退费', {
          confirmButtonText: '确 定',
          cancelButtonText: '取 消',
          type: 'warning'
        })
          .then(() => {
            let params = {
              order_id: row.id,
              patient_id: row.patient_id,
              record_time: this.getTimes(row.settle_accounts_date)
            }
            Refund(params).then((response) => {
              if (response.data.state == 0) {
                this.$message.error(response.data.msg)
                return false
              } else {
                this.$message({ message: '退费成功', type: 'success' })
                this.getHisOrderList()
              }
            })
          })
          .catch(() => {
          })
      } else {
        var that = this
        this.$confirm('是否退费', '退费', {
          confirmButtonText: '确 定',
          cancelButtonText: '取 消',
          type: 'warning'
        })
          .then(() => {
            let params = {
              order_id: row.id,
              patient_id: row.patient_id,
              record_time: that.getTimes(row.settle_accounts_date),
              admin_user_id: that.$store.getters.xt_user.user.id
            }
            axios
              .get('http://127.0.0.1:9532/api/refund/post', {
                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({
                      message: '退费成功',
                      type: 'success',
                      duration: 5000
                    })
                    that.getHisOrderList()
                  }
                }
              })
              .catch(function(error) {
              })
          })
          .catch(() => {
          })
      }
    }, tolistPrint(row) {
      // if (this.$store.getters.xt_user.org_id == 9504 || this.$store.getters.xt_user.org_id == 10028 || this.$store.getters.xt_user.org_id == 10138) {
      //   if (row.mdtrt_id.indexOf('H') > -1) {
      //     this.statementVisible9504 = true
      //     let obj = {
      //       order_id: row.id,
      //       patient_id: row.patient_id,
      //       record_time: this.getTimes(row.settle_accounts_date),
      //       admin_user_id: this.$store.getters.xt_user.user.id
      //     }
      //     this.orderObj9504 = obj
      //   } else {
      //
      //     this.statementVisible9504 = true
      //     let obj = {
      //       order_id: row.id,
      //       patient_id: row.patient_id,
      //       record_time: this.getTimes(row.settle_accounts_date),
      //       admin_user_id: this.$store.getters.xt_user.user.id,
      //       balance_accounts_type: 2
      //     }
      //     this.orderObj9504 = obj
      //   }
      //
      // } else {
      this.statementListVisible = true
      let obj = {
        order_id: row.id,
        settle_type: row.settle_type,
        start_time: row.settle_start_time,
        end_time: row.settle_end_time,
        balance_accounts_type: row.his_patient.balance_accounts_type
      }
      this.orderObj = obj
    },

    toPrint(row) {
      // if (this.$store.getters.xt_user.org_id == 9504 || this.$store.getters.xt_user.org_id == 10028 || this.$store.getters.xt_user.org_id == 10138) {
      //   if (row.mdtrt_id.indexOf('H') > -1) {
      //     this.statementVisible9504 = true
      //     let obj = {
      //       order_id: row.id,
      //       patient_id: row.patient_id,
      //       record_time: this.getTimes(row.settle_accounts_date),
      //       admin_user_id: this.$store.getters.xt_user.user.id
      //     }
      //     this.orderObj9504 = obj
      //   } else {
      //
      //     this.statementVisible9504 = true
      //     let obj = {
      //       order_id: row.id,
      //       patient_id: row.patient_id,
      //       record_time: this.getTimes(row.settle_accounts_date),
      //       admin_user_id: this.$store.getters.xt_user.user.id,
      //       balance_accounts_type: 2
      //     }
      //     this.orderObj9504 = obj
      //   }
      //
      // } else {
      var balance_accounts_type = row.his_patient.balance_accounts_type
      if (row.is_medicine_insurance == 1){
        balance_accounts_type = 1
      }else{
        balance_accounts_type = 2

      }

      this.statementVisible = true
      let obj = {
        order_id: row.id,
        settle_type: row.settle_type,
        start_time: row.settle_start_time,
        end_time: row.settle_end_time,
        balance_accounts_type:balance_accounts_type
      }
      this.orderObj = obj
    },
    settlementPrint(row) {
      this.settlementVisible = true
      let obj = {
        order_id: row.id
      }
      this.settlementObj = obj
    },
    export_detail_two() {
      let params = {}
      getHisDataTwo(params).then((response) => {
        if (response.data.state == 0) {
          this.$message.error(response.data.msg)
          return false
        } else {
          let list = []
          console.log(response.data.data.order)
          for (let i = 0; i < response.data.data.order.length; i++) {
            let order = response.data.data.order[i]
            for (let b = 0; b < order.info.length; b++) {
              let obj = {
                index: b + 1,
                org_name: '肇庆三鹤血液透析中心',
                name: order.psn_name,
                id_card_no: order.certno,
                level: '未定级',
                psn_type: order.psn_type,
                date: '202年3月',
                start_time: order.his.in_hosptial_time,
                end_time: order.his.out_hosptial_time,
                total: order.info[b].det_item_fee_sumamt,
                fund_total: order.info[b].inscp_scp_amt,
                patient_id: order.info[b].patient_id,
                dialysis_time: this.getTimes(order.info[b].upload_date)

              }
              // if (order.info[b].advice_id > 0 && order.info[b].project_id == 0) {
              //   obj["dialysis_time"] = this.getTimes(order.info[b].advice_date)
              // } else if (order.info[b].advice_id == 0 && order.info[b].project_id > 0) {
              //   obj["dialysis_time"] = this.getTimes(order.info[b].record_date)
              // }
              if (order.psn_type == '11') {
                obj['psn_type'] = '职工在职'
              } else if (order.psn_type == '12') {
                obj['psn_type'] = '职工退休'
              } else if (order.psn_type == '13') {
                obj['psn_type'] = '离休'
              } else if (order.psn_type == '14') {
                obj['psn_type'] = '居民医保'
              } else if (order.psn_type == '15') {
                obj['psn_type'] = '居民医保'
              } else if (order.psn_type == '16') {
                obj['psn_type'] = '居民医保'
              }

              list.push(obj)
            }
          }
          console.log(list)

          var new_list = this.unique_two(list)

          for (let i = 0; i < new_list.length; i++) {
            let total = 0
            let fund_total = 0
            for (let b = 0; b < list.length; b++) {
              if (new_list[i].patient_id == list[b].patient_id && new_list[i].dialysis_time == list[b].dialysis_time) {
                total = total + list[b].total
                fund_total = fund_total + list[b].fund_total
              }
            }
            new_list[i].total = total.toFixed(2)
            new_list[i].fund_total = fund_total.toFixed(2)

          }

          console.log(new_list)

          var tarList = []
          for (let i = 0; i < new_list.length; i++) {
            let obj = {
              '序号': i + 1,
              '医疗机构名称': new_list[i].org_name,
              '姓名': new_list[i].name,
              '身份证号': new_list[i].id_card_no,
              '医院等级': new_list[i].level,
              '参保类型': new_list[i].psn_type,
              '费用所属期': new_list[i].date,
              '开始就医时间': new_list[i].start_time,
              '结束就医时间': new_list[i].end_time,
              '透析日期': new_list[i].dialysis_time,
              '本次透析医疗总金额': new_list[i].total,
              '本次透析医保结算费用金额': new_list[i].fund_total

            }
            tarList.push(obj)

          }

          import('@/vendor/Export2Excel').then((excel) => {
            const tHeader = [
              '序号',
              '医疗机构名称',
              '姓名',
              '身份证号',
              '医院等级',
              '参保类型',
              '费用所属期',
              '开始就医时间',
              '结束就医时间',
              '透析日期',
              '本次透析医疗总金额',
              '本次透析医保结算费用金额'

            ]
            const filterVal = [
              '序号',
              '医疗机构名称',
              '姓名',
              '身份证号',
              '医院等级',
              '参保类型',
              '费用所属期',
              '开始就医时间',
              '结束就医时间',
              '透析日期',
              '本次透析医疗总金额',
              '本次透析医保结算费用金额'

            ]
            const data = this.formatJson(filterVal, tarList)
            excel.export_json_to_excel({
              header: tHeader,
              data,
              filename: '消费明细'
            })
          })
        }
      })
    }, getItemTypeName(order_infos, id, type) {
      console.log(type)

      var name = ''
      for (let i = 0; i < order_infos.length; i++) {
        if (type == 1) {
          if (order_infos[i].advice_id == id) {

            name = this.getItemName(order_infos[i].med_chrgitm_type)
          }
        } else {
          if (order_infos[i].project_id == id) {

            name = this.getItemName(order_infos[i].med_chrgitm_type)
          }
        }

      }
      return name
    }, getItemName(med_chrgitm_type) {
      switch (med_chrgitm_type) {
        case '01':
          return '床位费'
          break
        case '02':
          return '诊察费'

          break
        case '03':
          return '检查费'

          break
        case '04':
          return '化验费'
          break
        case '05':
          return '治疗费'

          break
        case '06':
          return '手术费'

          break
        case '07':
          return '护理费'

          break
        case '08':
          return '材料费'

          break
        case '09':
          return '西药费'

          break
        case '10':
          return '中药饮片费'

          break
        case '11':
          return '中成药费'

          break
        case '12':
          return '一般诊疗费'

          break
        case '13':
          return '挂号费'
          break
        case '14':
          return '其他费'
          break
        case '0':
          return '其他费'
          break

      }

    },

    export_detail_three() {
      let params = {
        start_time: this.start_time,
        end_time: this.end_time,
        org_id: 10265,
      }
      getHisDataThree(params).then((response) => {
        if (response.data.state == 0) {
          this.$message.error(response.data.msg)
          return false
        } else {
          let list = []
          console.log(response.data.data.order)
          for (let i = 0; i < response.data.data.order.length; i++) {
            let order = response.data.data.order[i]
            let data = this.setMonthPrescription(order.info)
            console.log(data)
            for (let b = 0; b < data.length; b++) {
              let obj = {
                name: order.patient.name,
                id_card_no: order.patient.id_card_no,
                year:  order.setl_time.split(' ')[0].split('-')[0],
                month: order.setl_time.split(' ')[0].split('-')[1],
                ddd: this.getTimes(order.settle_accounts_date),
                code: data[b].code,
                pric: data[b].total,
                item_name: data[b].name,
                unit: data[b].unit,
                count: data[b].count,
                item_type_name: this.getItemTypeName(order.info, data[b].id, data[b].type),
                pric_two: data[b].pric

              }
              if (order.insutype == '310') {
                obj['insutype'] = '职工'
              } else if (order.insutype == '390') {
                obj['insutype'] = '城乡'
              }
              list.push(obj)
            }

          }

          var tarList = []
          for (let i = 0; i < list.length; i++) {
            if (list[i].pric > 0) {
              let obj = {
                '姓名': list[i].name,
                '身份证号': list[i].id_card_no,
                '医保类型': list[i].insutype,
                '年': list[i].year,
                '月': list[i].month,
                '时间': list[i].ddd,
                '药品编码': list[i].code,
                '费用类型': list[i].item_type_name,
                '名称': list[i].item_name,
                '单位': list[i].unit,
                '数量': list[i].count,
                '金额': list[i].pric,
              }
              tarList.push(obj)
            }
          }

          import('@/vendor/Export2Excel').then((excel) => {
            const tHeader = [
              '姓名',
              '身份证号',
              '医保类型',
              '年',
              '月',
              '时间',
              '药品编码',
              '费用类型',
              '名称',
              '单位',
              '数量',
              '金额',

            ]
            const filterVal = [
              '姓名',
              '身份证号',
              '医保类型',
              '年',
              '月',
              '时间',
              '药品编码',
              '费用类型',
              '名称',
              '单位',
              '数量',
              '金额',

            ]
            const data = this.formatJson(filterVal, tarList)
            excel.export_json_to_excel({
              header: tHeader,
              data,
              filename: '消费明细'
            })
          })
        }
      })
    },
    export_detail_four() {
      let params = {}
      getHisDataFive(params).then((response) => {
        if (response.data.state == 0) {
          this.$message.error(response.data.msg)
          return false
        } else {
          let list = []
          for (let i = 0; i < response.data.data.order.length; i++) {
            let order = response.data.data.order[i]
            // console.log(data)
            for (let b = 0; b < order.info.length; b++) {
              let obj = {
                org_name: '生命之源血液透析中心',
                name: order.patient.name,
                id_card_no: order.patient.id_card_no,
                jiuyi_date: this.getTimes(order.settle_accounts_date),
                dianhua: order.patient.phone,
                pric: order.info[b].pric,
                cnt: order.info[b].cnt,
                det_item_fee_sumamt: order.info[b].det_item_fee_sumamt,
                zhenduan: '慢性肾衰竭',
                shifouyibao: '是',
                doctor: '高华',
                jiesuanfangshi: '医保',
                jizhangshijian: order.setl_time,
                feiyongheji: order.medfee_sumamt,
                jizhangjine: order.fund_pay_sumamt,
                xianjinheji: order.psn_cash_pay

              }
              if (order.is_medicine_insurance == 1) {
                obj.jiesuanfangshi = '是'

              } else {

                obj.jiesuanfangshi = '否'

              }

              if (order.info[b].advice_id > 0 && order.info[b].project_id == 0) {
                obj['yibaomulucode'] = order.info[b].advices.drug.medical_insurance_number
                obj['yibaomuluname'] = order.info[b].advices.drug.drug_name
                obj['neibumulucode'] = order.info[b].advices.drug.id
                obj['neibumuluname'] = order.info[b].advices.drug.drug_name
              }
              if (order.info[b].advice_id == 0 && order.info[b].project_id > 0) {
                if (order.info[b].project.type == 2) {
                  obj['yibaomulucode'] = order.info[b].project.project.medical_code
                  obj['yibaomuluname'] = order.info[b].project.project.project_name
                  obj['neibumulucode'] = order.info[b].project.project.id
                  obj['neibumuluname'] = order.info[b].project.project.project_name

                } else {
                  obj['yibaomulucode'] = order.info[b].project.good_info.medical_insurance_number
                  obj['yibaomuluname'] = order.info[b].project.good_info.good_name
                  obj['neibumulucode'] = order.info[b].project.good_info.id
                  obj['neibumuluname'] = order.info[b].project.good_info.good_name
                }
              }
              var thisLen = order.patient.id_card_no.length
              var birth = ''
              if (thisLen == 15) {
                birth = '19' + order.patient.id_card_no.substr(6, 6)
              } else {
                birth = order.patient.id_card_no.substr(6, 8)
              }
              var births =
                birth.substr(0, 4) +
                '-' +
                birth.substr(4, 2) +
                '-' +
                birth.substr(6, 2)
              obj['age'] = jsGetAge(births, '-')

              if (order.patient.gender == 1) {
                obj['gender'] = '男'
              } else {
                obj['gender'] = '女'
              }

              list.push(obj)
            }

          }

          var tarList = []
          for (let i = 0; i < list.length; i++) {
            if (list[i].pric > 0) {
              let obj = {
                '机构编码': list[i].org_name,
                '就诊人姓名': list[i].name,
                '性别': list[i].gender,
                '年龄': list[i].age,
                '身份证号码': list[i].id_card_no,
                '就医日期': list[i].jiuyi_date,
                '电话': list[i].dianhua,
                '医保目录编码': list[i].yibaomulucode,
                '医保目录名称': list[i].yibaomuluname,
                '机构内部编码': list[i].neibumulucode,
                '机构内部名称': list[i].neibumuluname,
                '就诊项目明细': list[i].yibaomuluname,
                '单价': list[i].pric,
                '数量': list[i].cnt,
                '金额': list[i].det_item_fee_sumamt,
                '费用合计': list[i].feiyongheji,
                '记账金额': list[i].jizhangjine,
                '现金合计': list[i].xianjinheji,
                '结算方式': list[i].jiesuanfangshi,
                '接诊医生': list[i].doctor,
                '诊断': list[i].zhenduan,
                '记账时间': list[i].jizhangshijian,
                '是否医保': list[i].shifouyibao

              }
              tarList.push(obj)
            }
          }

          import('@/vendor/Export2Excel').then((excel) => {
            const tHeader = [
              '机构编码',
              '就诊人姓名',
              '性别',
              '年龄',
              '身份证号码',
              '就医日期',
              '电话',
              '医保目录编码',
              '医保目录名称',
              '机构内部编码',
              '机构内部名称',
              '就诊项目明细',
              '单价',
              '数量',
              '金额',
              '费用合计',
              '记账金额',
              '现金合计',
              '结算方式',
              '接诊医生',
              '诊断',
              '记账时间',
              '是否医保'

            ]
            const filterVal = [
              '机构编码',
              '就诊人姓名',
              '性别',
              '年龄',
              '身份证号码',
              '就医日期',
              '电话',
              '医保目录编码',
              '医保目录名称',
              '机构内部编码',
              '机构内部名称',
              '就诊项目明细',
              '单价',
              '数量',
              '金额',
              '费用合计',
              '记账金额',
              '现金合计',
              '结算方式',
              '接诊医生',
              '诊断',
              '记账时间',
              '是否医保'

            ]
            const data = this.formatJson(filterVal, tarList)
            excel.export_json_to_excel({
              header: tHeader,
              data,
              filename: '消费明细'
            })
          })
        }
      })

    },
    export_detail_five() {
      let params = {}
      getHisDataFive(params).then((response) => {
        if (response.data.state == 0) {
          this.$message.error(response.data.msg)
          return false
        } else {
          let list = []
          for (let i = 0; i < response.data.data.order.length; i++) {
            let order = response.data.data.order[i]
            // console.log(data)
            for (let b = 0; b < order.info.length; b++) {
              if (order.info[b].project.project.cost_classify == 3) {
                let obj = {
                  p_name: order.psn_name,
                  code: order.info[b].project.project.id,
                  name: order.info[b].project.project.project_name,
                  unit: order.info[b].project.project.unit,
                  jiage: order.info[b].det_item_fee_sumamt,
                  name_yibao: order.info[b].project.project.project_name,
                  guoma: order.info[b].project.project.medical_code,
                  zifu: order.info[b].selfpay_prop,
                  cnt: order.info[b].cnt,
                  pric: order.info[b].pric,
                  gerenzifu: order.info[b].fulamt_ownpay_amt + order.info[b].preselfpay_amt,
                  baoxiaojine: order.info[b].inscp_scp_amt

                }
                if (order.info[b].chrgitm_lv == '01') {
                  obj['yibao_dengji'] = '甲'
                } else if (order.info[b].chrgitm_lv == '02') {
                  obj['yibao_dengji'] = '乙'
                } else {
                  obj['yibao_dengji'] = '丙'
                }
                list.push(obj)
              }
            }

          }
          console.log(list)

          var tarList = []
          for (let i = 0; i < list.length; i++) {
            let obj = {
              '姓名': list[i].p_name,
              '医保目录编码': list[i].guoma,
              '名称': list[i].name,
              '单位': list[i].unit,
              '价格': list[i].jiage,
              '医保等级': list[i].yibao_dengji,
              '自付比例': list[i].zifu,
              '数量': list[i].cnt,
              '金额': list[i].pric,
              '个人自付': list[i].gerenzifu,
              '报销金额': list[i].baoxiaojine

            }
            tarList.push(obj)
          }

          import('@/vendor/Export2Excel').then((excel) => {
            const tHeader = [
              '姓名',
              '医保目录编码',
              '名称',
              '单位',
              '价格',
              '医保等级',
              '自付比例',
              '数量',
              '金额',
              '个人自付',
              '报销金额'

            ]
            const filterVal = [
              '姓名',
              '医保目录编码',
              '名称',
              '单位',
              '价格',
              '医保等级',
              '自付比例',
              '数量',
              '金额',
              '个人自付',
              '报销金额'
            ]
            const data = this.formatJson(filterVal, tarList)
            excel.export_json_to_excel({
              header: tHeader,
              data,
              filename: '消费明细'
            })
          })
        }
      })

    },
    export_detail_six() {
      let params = {}
      getHisDataSix(params).then((response) => {
        if (response.data.state == 0) {
          this.$message.error(response.data.msg)
          return false
        } else {
          let list = []
          let new_list = []
          for (let i = 0; i < response.data.data.order.length; i++) {
            let order = response.data.data.order[i]
            for (let b = 0; b < order.info.length; b++) {
              new_list.push(order.info[b])
            }
          }

          var infos = this.setMonthPrescriptiontwo(new_list)
          for (let b = 0; b < infos.length; b++) {
            list.push(infos[b])
          }

          var tarList = []
          for (let i = 0; i < list.length; i++) {
            let obj = {
              '周期': '2024年第二季度',
              '类别': '门诊',
              '医保目录编码': list[i].code,
              '医保目录名称': list[i].name,
              '本机构目录编码': list[i].code,
              '本机构目录名称': list[i].name,
              '使用例数': list[i].count,
              '价格': list[i].price

            }
            tarList.push(obj)
          }

          import('@/vendor/Export2Excel').then((excel) => {
            const tHeader = [
              '周期',
              '类别',
              '医保目录编码',
              '医保目录名称',
              '本机构目录编码',
              '本机构目录名称',
              '使用例数',
              '价格'
            ]
            const filterVal = [
              '周期',
              '类别',
              '医保目录编码',
              '医保目录名称',
              '本机构目录编码',
              '本机构目录名称',
              '使用例数',
              '价格'
            ]
            const data = this.formatJson(filterVal, tarList)
            excel.export_json_to_excel({
              header: tHeader,
              data,
              filename: '消费明细'
            })
          })
        }
      })

    }, export_detail_ten_five() {
      let params = {
        start_time: this.start_time,
        end_time: this.end_time
      }

      exportMdtrtCertType(params).then((response) => {
        if (response.data.state == 0) {
          this.$message.error(response.data.msg)
          return false
        } else {
          let new_list = response.data.data.list
          var tarList = []
          for (let i = 0; i < new_list.length; i++) {
            let obj = {
              '姓名': new_list[i].psn_name
            }
            if (new_list[i].mdtrt_cert_type == '01') {
              obj['就诊凭证类型'] = '医保电子凭证'

            } else if (new_list[i].mdtrt_cert_type == '02') {

              obj['就诊凭证类型'] = '身份证'

            } else if (new_list[i].mdtrt_cert_type == '03') {

              obj['就诊凭证类型'] = '社会保障卡'

            }
            tarList.push(obj)
          }

          import('@/vendor/Export2Excel').then((excel) => {
            const tHeader = [
              '姓名',
              '就诊凭证类型',

            ]
            const filterVal = [
              '姓名',
              '就诊凭证类型',
            ]
            const data = this.formatJson(filterVal, tarList)
            excel.export_json_to_excel({
              header: tHeader,
              data,
              filename: '名单'
            })
          })
        }
      })

    }, export_detail_ten_four() {
      let params = {
        start_time: '2022-01-01',
        end_time: '2022-04-30'
      }
      handleOne(params).then((response) => {
        if (response.data.state == 0) {
          this.$message.error(response.data.msg)
          return false
        } else {
          let new_orders = []

          let new_orders_3663 = []
          let new_orders_4059 = []
          let new_orders_4039 = []

          for (let i = 0; i < response.data.data.order.length; i++) {
            let order = response.data.data.order[i]
            for (let b = 0; b < order.info.length; b++) {
              order.info[b]['new_order'] = order
              order.info[b]['new_date'] = this.getTime(order.info[b].pre_time, '{y}-{m}')
              new_orders.push(order.info[b])
            }
          }

          let new_list_four = []
          for (let i = 0; i < new_orders.length; i++) {
            let order = new_orders[i]
            new_list_four.push(order.p_info)
          }

          const obj111 = {}
          new_list_four = new_list_four.reduce((cur, next) => {
            obj111[next.id] ? '' : obj111[next.id] = true && cur.push(next)
            return cur
          }, []) // 设置cur默认类型为数组，并且初始值为空的数组

          let new_list_six = []
          for (let i = 0; i < new_list_four.length; i++) {
            let order = new_list_four[i]
            let obj = {
              p_id: order.id,
              patient_id: order.patient_id,
              cur_date: this.getTime(order.record_date, '{y}-{m}'),
              list: []
            }
            for (let b = 0; b < new_orders.length; b++) {
              if (order.id == new_orders[b].p_info.id) {
                obj.list.push(new_orders[b])
              }
            }
            new_list_six.push(obj)
          }

          console.log(new_list_six)

          for (let i = 0; i < new_list_six.length; i++) {
            let order = new_list_six[i]
            let islvguo = false
            for (let b = 0; b < order.list.length; b++) {
              for (let c = 0; c < order.list[b].project.length; c++) {
                if (order.list[b].project[c].project.id == 78 && order.list[b].project[c].project.id != 79 && order.list[b].project[c].project.id != 1074) {
                  islvguo = true
                }
              }
            }
            if (islvguo) {
              new_orders_3663.push(order)
            }
          }
          console.log(new_orders_3663)

          for (let i = 0; i < new_list_six.length; i++) {
            let order = new_list_six[i]
            let islvguo = false
            for (let b = 0; b < order.list.length; b++) {
              for (let c = 0; c < order.list[b].project.length; c++) {
                if (order.list[b].project[c].project.id == 1074 && order.list[b].project[c].project.id != 78 && order.list[b].project[c].project.id != 79) {
                  islvguo = true
                }
              }
            }
            if (islvguo) {
              new_orders_4059.push(order)
            }
          }

          console.log(new_orders_4059)

          for (let i = 0; i < new_list_six.length; i++) {
            let order = new_list_six[i]
            let islvguo = false
            for (let b = 0; b < order.list.length; b++) {
              for (let c = 0; c < order.list[b].project.length; c++) {
                if (order.list[b].project[c].project.id == 79 && order.list[b].project[c].project.id != 78 && order.list[b].project[c].project.id != 1074) {
                  islvguo = true
                }
              }
            }
            if (islvguo) {
              new_orders_4039.push(order)
            }
          }

          console.log(new_orders_4039)

          var months_3663 = []
          for (let i = 0; i < new_orders_3663.length; i++) {
            months_3663.push(new_orders_3663[i].cur_date)
          }
          const obj = {}
          months_3663 = months_3663.reduce((cur, next) => {
            obj[next] ? '' : obj[next] = true && cur.push(next)
            return cur
          }, []) // 设置cur默认类型为数组，并且初始值为空的数组

          var months_4039 = []
          for (let i = 0; i < new_orders_4039.length; i++) {
            months_4039.push(new_orders_4039[i].cur_date)
          }
          const obj2 = {}
          months_4039 = months_4039.reduce((cur, next) => {
            obj2[next] ? '' : obj2[next] = true && cur.push(next)
            return cur
          }, []) // 设置cur默认类型为数组，并且初始值为空的数组

          var months_4059 = []

          for (let i = 0; i < new_orders_4059.length; i++) {

            months_4059.push(new_orders_4059[i].cur_date)

          }
          const obj3 = {}
          months_4059 = months_4059.reduce((cur, next) => {
            obj3[next] ? '' : obj3[next] = true && cur.push(next)
            return cur
          }, [])
          // 设置cur默认类型为数组，并且初始值为空的数组
          let new_list = []
          for (let i = 0; i < months_3663.length; i++) {
            let obj = {
              cus_date: months_3663[i],
              info: []
            }
            for (let b = 0; b < new_orders_3663.length; b++) {
              if (months_3663[i] == new_orders_3663[b].cur_date) {
                obj.info.push(new_orders_3663[b])
              }
            }
            new_list.push(obj)
          }

          let new_list_two = []
          for (let i = 0; i < months_4039.length; i++) {
            let obj = {
              cus_date: months_4039[i],
              info: []
            }
            for (let b = 0; b < new_orders_4039.length; b++) {
              if (months_4039[i] == new_orders_4039[b].cur_date) {
                obj.info.push(new_orders_4039[b])
              }
            }
            new_list_two.push(obj)
          }

          let new_list_three = []
          for (let i = 0; i < months_4059.length; i++) {
            let obj = {
              cus_date: months_4059[i],
              info: []
            }
            for (let b = 0; b < new_orders_4059.length; b++) {
              if (months_4059[i] == new_orders_4059[b].cur_date) {
                obj.info.push(new_orders_4059[b])
              }
            }
            new_list_three.push(obj)
          }

          console.log(new_list)
          console.log(new_list_two)
          console.log(new_list_three)

          var list_one = []
          var list_two = []
          var list_three = []

          for (let b = 0; b < new_list.length; b++) {
            let obj = {
              cur_date: new_list[b].cus_date,
              order_info: [],
              info_length: new_list[b].info.length

            }
            for (let c = 0; c < new_list[b].info.length; c++) {
              for (let d = 0; d < new_list[b].info[c].list.length; d++) {
                if (new_list[b].info[c].list[d].advices.length > 0 && new_list[b].info[c].list[d].project.length == 0) {
                  for (let e = 0; e < new_list[b].info[c].list[d].advices.length; e++) {
                    obj.order_info.push(new_list[b].info[c].list[d].advices[e].order_info)
                  }

                }
                if (new_list[b].info[c].list[d].advices.length == 0 && new_list[b].info[c].list[d].project.length > 0) {
                  for (let e = 0; e < new_list[b].info[c].list[d].project.length; e++) {
                    obj.order_info.push(new_list[b].info[c].list[d].project[e].order_info)

                  }
                }
              }
            }
            list_one.push(obj)

          }

          for (let b = 0; b < new_list_two.length; b++) {
            let obj = {
              cur_date: new_list_two[b].cus_date,
              order_info: [],
              info_length: new_list_two[b].info.length

            }
            for (let c = 0; c < new_list_two[b].info.length; c++) {
              for (let d = 0; d < new_list_two[b].info[c].list.length; d++) {
                if (new_list_two[b].info[c].list[d].advices.length > 0 && new_list_two[b].info[c].list[d].project.length == 0) {
                  for (let e = 0; e < new_list_two[b].info[c].list[d].advices.length; e++) {
                    obj.order_info.push(new_list_two[b].info[c].list[d].advices[e].order_info)
                  }

                }
                if (new_list_two[b].info[c].list[d].advices.length == 0 && new_list_two[b].info[c].list[d].project.length > 0) {
                  for (let e = 0; e < new_list_two[b].info[c].list[d].project.length; e++) {
                    obj.order_info.push(new_list_two[b].info[c].list[d].project[e].order_info)
                  }
                }
              }
            }
            list_two.push(obj)

          }

          for (let b = 0; b < new_list_three.length; b++) {
            let obj = {
              cur_date: new_list_three[b].cus_date,
              order_info: [],
              info_length: new_list_three[b].info.length
            }
            for (let c = 0; c < new_list_three[b].info.length; c++) {
              for (let d = 0; d < new_list_three[b].info[c].list.length; d++) {
                if (new_list_three[b].info[c].list[d].advices.length > 0 && new_list_three[b].info[c].list[d].project.length == 0) {
                  for (let e = 0; e < new_list_three[b].info[c].list[d].advices.length; e++) {
                    obj.order_info.push(new_list_three[b].info[c].list[d].advices[e].order_info)
                  }

                }
                if (new_list_three[b].info[c].list[d].advices.length == 0 && new_list_three[b].info[c].list[d].project.length > 0) {
                  for (let e = 0; e < new_list_three[b].info[c].list[d].project.length; e++) {
                    obj.order_info.push(new_list_three[b].info[c].list[d].project[e].order_info)
                  }
                }
              }
            }
            list_three.push(obj)

          }

          console.log(list_one)
          console.log(list_two)
          console.log(list_three)

          // list_one = []
          // list_one = list_two

          // list_one = []
          // list_one = list_three

          var tarList = []
          for (let i = 0; i < list_one.length; i++) {
            let obj = {
              '年月': list_one[i].cur_date,
              '总人数': this.getTotalOneOne(list_one[i].order_info),
              '总人次': list_one[i].info_length,
              '总费用': this.getTotalOne(list_one[i].order_info),
              '总治疗费': this.getTotalTwo(list_one[i].order_info),
              '总材料费': this.getTotalThree(list_one[i].order_info),
              '总检查检验费': this.getTotalFour(list_one[i].order_info),
              '总药品费': this.getTotalFive(list_one[i].order_info),
              '人均费用': this.getTotalOne(list_one[i].order_info) / this.getTotalOneOne(list_one[i].order_info),
              '次均费用': this.getTotalOne(list_one[i].order_info) / list_one[i].info_length,
              '次均治疗费': this.getTotalTwo(list_one[i].order_info) / list_one[i].info_length,
              '次均材料费': this.getTotalThree(list_one[i].order_info) / list_one[i].info_length,
              '次均检查检验费': this.getTotalFour(list_one[i].order_info) / list_one[i].info_length,
              '次均药品费': this.getTotalFive(list_one[i].order_info) / list_one[i].info_length
            }
            tarList.push(obj)
          }
        }

        import('@/vendor/Export2Excel').then((excel) => {
          const tHeader = [
            '年月',
            '总人数',
            '总人次',
            '总费用',
            '总治疗费',
            '总材料费',
            '总检查检验费',
            '总药品费',
            '人均费用',
            '次均费用',
            '次均治疗费',
            '次均材料费',
            '次均检查检验费',
            '次均药品费'
          ]
          const filterVal = [
            '年月',
            '总人数',
            '总人次',
            '总费用',
            '总治疗费',
            '总材料费',
            '总检查检验费',
            '总药品费',
            '人均费用',
            '次均费用',
            '次均治疗费',
            '次均材料费',
            '次均检查检验费',
            '次均药品费'
          ]
          const data = this.formatJson(filterVal, tarList)
          excel.export_json_to_excel({
            header: tHeader,
            data,
            filename: '消费明细'
          })
        })

      })

    }, getTotalOneOne(order_info) {
      var patient_ids = []
      for (var i = 0; i < order_info.length; i++) {
        patient_ids.push(order_info[i].patient_id)
      }
      const obj2 = {}
      patient_ids = patient_ids.reduce((cur, next) => {
        obj2[next] ? '' : obj2[next] = true && cur.push(next)
        return cur
      }, []) // 设置cur默认类型为数组，并且初始值为空的数组
      return patient_ids.length

    }, getTotalOneTwo(order_info) {
      let total = 0
      for (var i = 0; i < order_info.length; i++) {
        total = total + order_info[i].det_item_fee_sumamt
      }
      return total.toFixed(2)
    }, getTotalOne(order_info) {
      let total = 0
      for (var i = 0; i < order_info.length; i++) {
        total = total + order_info[i].det_item_fee_sumamt
      }
      return total.toFixed(2)

    }, getTotalTwo(order_info) {
      let total = 0
      for (var i = 0; i < order_info.length; i++) {
        if (order_info[i].med_chrgitm_type == '05') {
          total = total + order_info[i].det_item_fee_sumamt
        }
      }
      return total.toFixed(2)

    }, getTotalThree(order_info) {
      let total = 0
      for (var i = 0; i < order_info.length; i++) {
        if (order_info[i].med_chrgitm_type == '08') {
          total = total + order_info[i].det_item_fee_sumamt
        }
      }
      return total.toFixed(2)

    }, getTotalFour(order_info) {
      let total = 0
      for (var i = 0; i < order_info.length; i++) {
        if (order_info[i].med_chrgitm_type == '03' || order_info[i].med_chrgitm_type == '04') {
          total = total + order_info[i].det_item_fee_sumamt
        }
      }
      return total.toFixed(2)

    }, getTotalFive(order_info) {
      let total = 0
      for (var i = 0; i < order_info.length; i++) {
        if (order_info[i].med_chrgitm_type == '09' || order_info[i].med_chrgitm_type == '10' || order_info[i].med_chrgitm_type == '11') {
          total = total + order_info[i].det_item_fee_sumamt
        }
      }
      return total.toFixed(2)

    }, getTotalSix(order_info) {

    }, getTotalSeven(order_info) {

    }, getTotalEigth(order_info) {

    }, getTotalNine(order_info) {

    }, getTotalTen(order_info) {

    }, getTotalTenOne(order_info) {

    },

    export_detail_seven() {
      let params = {}
      handleData10106(params).then((response) => {
        if (response.data.state == 0) {
          this.$message.error(response.data.msg)
          return false
        } else {
          let new_orders = []
          for (let i = 0; i < response.data.data.order.length; i++) {
            let order = response.data.data.order[i]
            let islvguo = false
            for (let b = 0; b < order.info.length; b++) {
              if (order.info[b].project.project.id == 372) {
                islvguo = true
              }

            }
            if (islvguo) {
              new_orders.push(order)
            }
          }
          console.log(new_orders.length)

          let list = []
          for (let i = 0; i < new_orders.length; i++) {
            let order = response.data.data.order[i]
            let obj = {
              md: order.mdtrt_id,
              name: order.patient.name,
              kaichu: this.getTimes(order.settle_start_time),
              xianzhong: '',
              yingshou: order.medfee_sumamt,
              yibaotongchou: order.hifp_pay,
              dabingjijin: order.hifmi_pay,
              yiliaojiuzhu: order.maf_pay,
              gongwujijin: order.cvlserv_pay,
              gerenzhifu: order.psn_part_amt,
              zongjine: order.medfee_sumamt,
              setl_time: order.setl_time,
              jiesuanleixing: '医保',
              xueyetouxilvguo: 480,
              lvhuana: 3,
              zhihuanguan: 40,
              good_name: ''
            }
            if (order.insutype == '390') {

              obj.xianzhong = '城乡'
            } else {

              obj.xianzhong = '职工'

            }

            for (let b = 0; b < order.info.length; b++) {
              if (order.info[b].advice_id == 0 && order.info[b].project_id > 0) {
                if (order.info[b].project.type == 2) {
                  if (order.info[b].project.project.id == 254 || order.info[b].project.project.id == 253 || order.info[b].project.project.id == 250 || order.info[b].project.project.id == 249) {
                    obj.good_name = this.GetGoodName(order.info[b].project.project.id)
                  }
                } else if (order.info[b].project.type == 3) {
                  if (order.info[b].project.project.id == 1478 || order.info[b].project.project.id == 1479 || order.info[b].project.project.id == 1482 || order.info[b].project.project.id == 1483 || order.info[b].project.project.id == 2577 || order.info[b].project.project.id == 2578 || order.info[b].project.project.id == 2058 || order.info[b].project.project.id == 2059) {
                    obj.good_name = this.GetGoodName(order.info[b].project.good_info.id)
                  }
                }
              }
            }
            list.push(obj)
          }

          var tarList = []
          for (let i = 0; i < list.length; i++) {
            if (list[i].good_name.length > 0) {
              let obj = {
                '序号': i + 1,
                '就诊号': list[i].md,
                '患者姓名': list[i].name,
                '开处时间': list[i].kaichu,
                '项目(透析器)': list[i].good_name,
                '血液透析滤过': list[i].xueyetouxilvguo,
                '0.9%氯化钠注射液': list[i].lvhuana,
                '置换液管': list[i].zhihuanguan,
                '险种类型': list[i].xianzhong,
                '应收金额': list[i].yingshou,
                '医保统筹金额': list[i].yibaotongchou,
                '大病基金金额': list[i].dabingjijin,
                '医疗救助金额': list[i].yiliaojiuzhu,
                '公务员基金': list[i].gongwujijin,
                '个人支付基金': list[i].gerenzhifu,
                '总金额': list[i].zongjine,
                '收费时间': list[i].setl_time,
                '结算类型': list[i].jiesuanleixing,
                '收费状态': '已收费'
              }
              tarList.push(obj)
            }
          }

          import('@/vendor/Export2Excel').then((excel) => {
            const tHeader = [
              '序号',
              '就诊号',
              '患者姓名',
              '开处时间',
              '项目(透析器)',
              '血液透析滤过',
              '0.9%氯化钠注射液',
              '置换液管',
              '险种类型',
              '应收金额',
              '医保统筹金额',
              '大病基金金额',
              '医疗救助金额',
              '公务员基金',
              '个人支付基金',
              '总金额',
              '收费时间',
              '结算类型',
              '收费状态'
            ]
            const filterVal = [
              '序号',
              '就诊号',
              '患者姓名',
              '开处时间',
              '项目(透析器)',
              '血液透析滤过',
              '0.9%氯化钠注射液',
              '置换液管',
              '险种类型',
              '应收金额',
              '医保统筹金额',
              '大病基金金额',
              '医疗救助金额',
              '公务员基金',
              '个人支付基金',
              '总金额',
              '收费时间',
              '结算类型',
              '收费状态'
            ]
            const data = this.formatJson(filterVal, tarList)
            excel.export_json_to_excel({
              header: tHeader,
              data,
              filename: '消费明细'
            })
          })

        }
      })

    },
    export_detail_tenone() {
      let params = {
        start_time: this.start_time,
        end_time: this.end_time
      }
      handleData10138Two(params).then((response) => {
        if (response.data.state == 0) {
          this.$message.error(response.data.msg)
          return false
        } else {
          var list = []
          var orders = response.data.data.info
          for (let i = 0; i < orders.length; i++) {
            for (let b = 0; b < orders[i].order.length; b++) {
              for (let c = 0; c < orders[i].order[b].infos.length; c++) {
                let name = orders[i].name
                let date = this.getTimes(orders[i].order[b].settle_accounts_date)
                let code = orders[i].order[b].number
                let cnt = orders[i].order[b].infos[c].cnt
                let pric = orders[i].order[b].infos[c].pric
                let det_item_fee_sumamt = orders[i].order[b].infos[c].det_item_fee_sumamt

                let item_name = ''
                let unit = ''
                let spec = ''

                if (orders[i].order[b].infos[c].advice_id > 0) {
                  item_name = orders[i].order[b].infos[c].advices.drug.drug_name
                  unit = orders[i].order[b].infos[c].advices.prescribing_number_unit
                  spec = (orders[i].order[b].infos[c].advices.drug.dose + orders[i].order[b].infos[c].advices.drug.dose_unit) + '*' + orders[i].order[b].infos[c].advices.drug.min_number + orders[i].order[b].infos[c].advices.drug.min_unit + '/' + orders[i].order[b].infos[c].advices.drug.max_unit
                }
                if (orders[i].order[b].infos[c].project_id > 0 && orders[i].order[b].infos[c].project.type == 2) {
                  item_name = orders[i].order[b].infos[c].project.project.project_name
                  unit = orders[i].order[b].infos[c].project.project.unit
                  spec = orders[i].order[b].infos[c].project.project.project_name
                }
                if (orders[i].order[b].infos[c].project_id > 0 && orders[i].order[b].infos[c].project.type == 3) {
                  item_name = orders[i].order[b].infos[c].project.good_info.good_name
                  unit = orders[i].order[b].infos[c].project.good_info.packing_unit
                  spec = orders[i].order[b].infos[c].project.good_info.specification_name
                }

                let obj = {
                  '姓名': name,
                  '处方日期': date,
                  '费用编码': code,
                  '项目名称': item_name,
                  '规格': spec,
                  '数量': cnt,
                  '单位': unit,
                  '金额': det_item_fee_sumamt,
                  '单价': pric
                }
                list.push(obj)
              }
            }
          }

          import('@/vendor/Export2Excel').then((excel) => {
            const tHeader = [
              '姓名',
              '处方日期',
              '费用编码',
              '项目名称',
              '规格',
              '数量',
              '单位',
              '单价',
              '金额'
            ]
            const filterVal = [
              '姓名',
              '处方日期',
              '费用编码',
              '项目名称',
              '规格',
              '数量',
              '单位',
              '单价',
              '金额'
            ]
            const data = this.formatJson(filterVal, list)
            excel.export_json_to_excel({
              header: tHeader,
              data,
              filename: '消费明细'
            })
          })

        }
      })
    },
    getType(med_chrgitm_type) {
      switch (med_chrgitm_type) {
        case '01':
          return '床位费'
          break
        case '1':
          return '床位费'
          break
        case '02':
          return '诊察费'

          break
        case '2':
          return '诊察费'
          break
        case '03':
          return '检查费'

          break
        case '3':
          return '检查费'

          break
        case '04':
          return '化验费'
          break
        case '4':
          return '化验费'
          break
        case '05':
          return '治疗费'

          break
        case '5':
          return '治疗费'

          break
        case '06':
          return '手术费'

          break
        case '6':
          return '手术费'

          break
        case '07':
          return '护理费'

          break
        case '7':
          return '护理费'

          break
        case '08':
          return '材料费'

          break
        case '8':
          return '材料费'

          break
        case '09':
          return '西药费'

          break
        case '9':
          return '西药费'

          break
        case '10':
          return '中药饮片费'

          break
        case '11':
          return '中成药费'

          break
        case '12':
          return '一般诊疗费'

          break
        case '13':
          return '挂号费'
          break
        case '14':
          return '其他费'
          break
        case '0':
          return '其他费'
          break
      }

    },

    export_detail_ten() {
      let params = {
        start_time: this.start_time,
        end_time: this.end_time
      }
      handleData10106(params).then((response) => {
        if (response.data.state == 0) {
          this.$message.error(response.data.msg)
          return false
        } else {
          let list = []
          for (let i = 0; i < response.data.data.order.length; i++) {
            let order = response.data.data.order[i]
            let med_chrgitm_types = []
            for (let b = 0; b < order.info.length; b++) {
              med_chrgitm_types.push(order.info[b].med_chrgitm_type)
              const obj = {}
              med_chrgitm_types = med_chrgitm_types.reduce((cur, next) => {
                obj[next] ? '' : obj[next] = true && cur.push(next)
                return cur
              }, []) // 设置cur默认类型为数组，并且初始值为空的数组
            }

            for (let i = 0; i < med_chrgitm_types.length; i++) {
              let price = 0
              let obj = {

                number: '440722196501072316',
                name: order.patient.name,
                idNo: '',
                med_chrgitm_name: this.getType(med_chrgitm_types[i]),
                price: '',
                remark: ''
              }
              if (i == 0) {
                obj.remark = '就诊日期:' + this.getTimes(order.settle_accounts_date) + ' 医保报销: ' + order.fund_pay_sumamt + ' 现金:' + order.psn_cash_pay
                obj.idNo = order.patient.id_card_no
              } else {
                obj.remark = ''
                obj.idNo = ''
              }
              for (let b = 0; b < order.info.length; b++) {
                if (med_chrgitm_types[i] == order.info[b].med_chrgitm_type) {

                  price = price + order.info[b].det_item_fee_sumamt
                }
              }
              obj.price = price
              list.push(obj)
            }
          }
          let list_two = []
          const obj = {}
          for (let i = 0; i < list.length; i++) {
            console.log(list[i])
            list_two.push(list[i].name)
          }

          list_two = list_two.reduce((cur, next) => {
            obj[next] ? '' : obj[next] = true && cur.push(next)
            return cur
          }, []) // 设置cur默认类型为数组，并且初始值为空的数组

          for (let i = 0; i < list_two.length; i++) {
            for (let b = 0; b < list.length; b++) {
              if (list_two[i] == list[b].name) {
                list[b]['index'] = i + 1
              }
            }
          }

          var tarList = []
          for (let i = 0; i < list.length; i++) {
            let obj = {
              '订单序号': list[i].index,
              '订单号码': '',
              '购方名称': list[i].name,
              '购方纳税人识别号': list[i].idNo,
              '开户行及账号': '',
              '地址电话': '',
              '税收编码': '3070202000000000000',
              '商品名称': list[i].med_chrgitm_name,
              '规格型号': '',
              '计量单位': '',
              '数量': '',
              '单价': '',
              '金额': list[i].price,
              '税率': '0%',
              '优惠政策': '普通零税率',
              '税额': '0',
              '备注': list[i].remark,
              '电子邮箱': ''

            }
            tarList.push(obj)
          }

          import('@/vendor/Export2Excel').then((excel) => {
            const tHeader = [
              '订单序号',
              '订单号码',
              '购方名称',
              '购方纳税人识别号',
              '开户行及账号',
              '地址电话',
              '税收编码',
              '商品名称',
              '规格型号',
              '计量单位',
              '数量',
              '单价',
              '金额',
              '税率',
              '优惠政策',
              '税额',
              '备注',
              '电子邮箱'
            ]
            const filterVal = [
              '订单序号',
              '订单号码',
              '购方名称',
              '购方纳税人识别号',
              '开户行及账号',
              '地址电话',
              '税收编码',
              '商品名称',
              '规格型号',
              '计量单位',
              '数量',
              '单价',
              '金额',
              '税率',
              '优惠政策',
              '税额',
              '备注',
              '电子邮箱'
            ]
            const data = this.formatJson(filterVal, tarList)
            excel.export_json_to_excel({
              header: tHeader,
              data,
              filename: '消费明细'
            })
          })

        }
      })

    },
    export_detail_ten_two() {
      let params = {
        start_time: this.start_time,
        end_time: this.end_time
      }
      handleData10318(params).then((response) => {
        if (response.data.state == 0) {
          this.$message.error(response.data.msg)
          return false
        } else {
          let list = []
          for (let i = 0; i < response.data.data.order.length; i++) {
            let order = response.data.data.order[i]

            let obj = {
              姓名: order.patient.name,
              身份证: order.patient.id_card_no,
              西药费: 0,
              化验费: 0,
              检查费: 0,
              治疗费: 0,
              材料费: 0,
              中成药费: 0,
              护理费: 0,
              备注: '就诊日期:' + this.getTimes(order.settle_accounts_date) + ' 医保报销: ' + order.fund_pay_sumamt + ' 现金:' + order.psn_cash_pay
            }
            let xiyaoPrice = 0
            let huaYanPrice = 0
            let jianChaPrice = 0
            let zhiLiaoPrice = 0
            let cailiaoPrice = 0
            let zhongchengyaoPrice = 0
            let huliPrice = 0

            for (let b = 0; b < order.info.length; b++) {
              if (order.info[b].med_chrgitm_type == '09') {
                xiyaoPrice = xiyaoPrice + order.info[b].det_item_fee_sumamt
              }
              if (order.info[b].med_chrgitm_type == '04') {
                huaYanPrice = huaYanPrice + order.info[b].det_item_fee_sumamt
              }
              if (order.info[b].med_chrgitm_type == '03') {
                jianChaPrice = jianChaPrice + order.info[b].det_item_fee_sumamt
              }
              if (order.info[b].med_chrgitm_type == '05') {
                zhiLiaoPrice = zhiLiaoPrice + order.info[b].det_item_fee_sumamt
              }
              if (order.info[b].med_chrgitm_type == '08') {
                cailiaoPrice = cailiaoPrice + order.info[b].det_item_fee_sumamt
              }
              if (order.info[b].med_chrgitm_type == '11') {
                zhongchengyaoPrice = zhongchengyaoPrice + order.info[b].det_item_fee_sumamt
              }

              if (order.info[b].med_chrgitm_type == '07') {
                huliPrice = huliPrice + order.info[b].det_item_fee_sumamt
              }
            }
            obj.西药费 = xiyaoPrice
            obj.化验费 = huaYanPrice
            obj.检查费 = jianChaPrice
            obj.治疗费 = zhiLiaoPrice
            obj.材料费 = cailiaoPrice
            obj.中成药费 = zhongchengyaoPrice
            obj.护理费 = huliPrice

            list.push(obj)
          }

          import('@/vendor/Export2Excel').then((excel) => {
            const tHeader = [
              '姓名',
              '身份证',
              '西药费',
              '化验费',
              '检查费',
              '治疗费',
              '材料费',
              '中成药费',
              '护理费',

              '备注'
            ]
            const filterVal = [
              '姓名',
              '身份证',
              '西药费',
              '化验费',
              '检查费',
              '治疗费',
              '材料费',
              '中成药费',
              '护理费',
              '备注'
            ]
            const data = this.formatJson(filterVal, list)
            excel.export_json_to_excel({
              header: tHeader,
              data,
              filename: '消费明细'
            })
          })

        }
      })

    },
    export_detail_ten_three() {
      exportOrderInfo().then((response) => {
        if (response.data.state == 0) {
          this.$message.error(response.data.msg)
          return false
        } else {
          let list = []
          for (let b = 0; b < response.data.data.info.length; b++) {
            let item_name = ''
            let item_code = ''
            let price = ''
            let unit = ''
            let spec = ''
            let cnt = ''

            if (
              response.data.data.info[b].advices.id == 0 &&
              response.data.data.info[b].project.id > 0
            ) {

              if (response.data.data.info[b].project.type == 2) {
                item_name = response.data.data.info[b].project.project.project_name
                item_code = response.data.data.info[b].project.project.medical_code
                price = response.data.data.info[b].det_item_fee_sumamt
                unit = response.data.data.info[b].project.project.unit
                cnt = response.data.data.info[b].cnt

              } else {

                item_name = response.data.data.info[b].project.good_info.good_name
                item_code = response.data.data.info[b].project.good_info.medical_insurance_number
                price = response.data.data.info[b].det_item_fee_sumamt
                unit = response.data.data.info[b].project.good_info.packing_unit
                cnt = response.data.data.info[b].cnt

              }

            } else if (
              response.data.data.info[b].advices.id > 0 &&
              response.data.data.info[b].project.id == 0
            ) {
              item_name = response.data.data.info[b].advices.advice_name
              item_code =
                response.data.data.info[b].advices.drug.medical_insurance_number
              price = response.data.data.info[b].det_item_fee_sumamt
              unit = response.data.data.info[b].advices.prescribing_number_unit
              spec = response.data.data.info[b].advices.drug.dose + response.data.data.info[b].advices.drug.dose_unit + '*' + response.data.data.info[b].advices.drug.min_number + response.data.data.info[b].advices.drug.min_unit + '/' + response.data.data.info[b].advices.drug.max_unit
              cnt = response.data.data.info[b].cnt

            }
            let obj = {
              名称: item_name,
              总价: price,
              数量: cnt,
              规格: spec

            }

            list.push(obj)
          }
          import('@/vendor/Export2Excel').then((excel) => {
            const tHeader = [
              '名称',
              '总价',
              '数量',
              '规格'

            ]
            const filterVal = [
              '名称',
              '总价',
              '数量',
              '规格'

            ]
            const data = this.formatJson(filterVal, list)
            excel.export_json_to_excel({
              header: tHeader,
              data,
              filename: '消费明细'
            })
          })
        }
      })

    },
    GetGoodName(id) {
      switch (id) {
        case 254:
          return '空心纤维透析器REXEED-18UC(旭化成)'
          break
        case 253:
          return '空心纤维透析器REXEED-15UC(旭化成)'
          break
        case 250:
          return '聚砜膜透析滤过器-XevontaHI18(贝朗)'
          break
        case 249:
          return '聚砜膜透析滤过器-XevontaHI15(贝朗)'
          break
        case 1478:
          return '聚砜膜透析滤过器-XevontaHI15(贝朗)'
          break
        case 1479:
          return '聚砜膜透析滤过器-XevontaHI18(贝朗)'
          break
        case 1482:
          return '空心纤维透析器REXEED-15UC(旭化成)'
          break
        case 1483:
          return 'REXEED-18UC(旭化成)'
          break
        case 2577:
          return '空心纤维透析器(FB-15U)(尼普洛)'
          break
        case 2578:
          return '空心纤维透析器(FB-17U)(尼普洛)'
          break
        case 2058:
          return '中空纤维透析器CTA-1500'
          break
        case 2059:
          return '中空纤维透析器CTA-2000'
          break

          break

      }

    },

    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].patient_id === res[j].patient_id && array[i].dialysis_time === res[j].dialysis_time) {
            break
          }
        }
        // 如果array[i]是唯一的，那么执行完循环，j等于resLen
        if (j === resLen) {
          res.push(array[i])
        }
      }
      return res
    },
    batch_print_settlte() {
      if (this.selecting_schs.length === 0) {
        this.$message.error('请至少选择一条需要打印的内容')
        return false
      } else {
        var sch_ids = []
        for (let index = 0; index < this.selecting_schs.length; index++) {
          sch_ids.push(this.selecting_schs[index].id)
        }
        this.batchStatementVisible = true
        let params = {
          order_ids: sch_ids.join(','),
          admin_user_id: this.$store.getters.xt_user.user.id
        }
        this.batchOrderObj = params
      }
    },
    export_detail() {
      let params = {
        start_time: this.start_time,
        end_time: this.end_time,
        p_type: 2,
        sort_type:this.sort_type
      }
      getExportConsumeDetailList(params).then((response) => {
        if (response.data.state == 0) {
          this.$message.error(response.data.msg)
          return false
        } else {
          let list = []
          let list2 = []
          for (let i = 0; i < response.data.data.order.length; i++) {
            let order = response.data.data.order[i]
            let number = ''
            let name = ''
            let department = ''
            let doctor_name = ''
            let balance_accounts = ''
            let order_status = ''
            let charge_name = ''
            let  gender = ""
            let  age = 0


            let insutypeName = ''

            if(order.patient.gender == 1){
              gender = "男"
            }else{
              gender = "女"
            }

            age = this.getAge(order.patient.id_card_no)

            let time = ''
            if (
              order.his_patient != null &&
              order.his_patient.number.length > 0
            ) {
              number = order.his_patient.number
            }

            if (order.his_patient != null) {
              if (order.his_patient.balance_accounts_type == 2) {
                balance_accounts = '自费'
              }

              if (order.his_patient.balance_accounts_type == 1) {
                balance_accounts = '医保'
              }
            }

            if (order.patient != null && order.patient.name.length > 0) {
              name = order.patient.name
            }

            if (
              order.p_info != null &&
              order.p_info.department != null &&
              order.p_info.department.name.length > 0
            ) {
              department = order.p_info.department.name
            }

            if (order.p_info != null && order.p_info.doctor.length > 0) {
              doctor_name = order.p_info.doctor
            }

            if (order.creator != null) {
              charge_name = this.getName(order.creator)
            }
            if (order.insutype == '390') {
              insutypeName = '城乡居民基本医疗保险'
            } else if (order.insutype == '310') {
              insutypeName = '职工基本医疗保险'
            }

            if (order.order_status == 1) {
              order_status = '待结算'
            }

            if (order.order_status == 2) {
              order_status = '已结算'
            }

            if (order.order_status == 3) {
              order_status = '已退费'
            }

            if (order.settle_type == 2) {
              time = this.getTimes(order.settle_start_time)
            } else {
              time = this.getTimes(order.settle_accounts_date)
            }
            // var hifmi_pay = 0.0
            // if (order.setl_detail && order.setl_detail.length > 0) {
            //   var jsonObj = JSON.parse(order.setl_detail)
            //
            //   console.log(jsonObj)
            //   if (jsonObj != null) {
            //     for (let i = 0; i < jsonObj.length; i++) {
            //       if (order.insutype == '310') {
            //         if (jsonObj[i].fund_pay_type == '310300') {
            //           hifmi_pay = jsonObj[i].fund_payamt
            //         }
            //       } else if (order.insutype == '390') {
            //         if (order.fund_pay_type == '390200') {
            //           hifmi_pay = jsonObj[i].fund_payamt
            //         }
            //       }
            //     }
            //   }
            // }

            // var hifmi_pay = 0.0

            // console.log(order.setl_detail)
            // if (order.setl_detail && order.setl_detail.length > 0) {
            //   var jsonObj = JSON.parse(order.setl_detail)
            //   if (jsonObj != null) {
            //     for (let i = 0; i < jsonObj.length; i++) {
            //       if (order.insutype == '310') {
            //         if (jsonObj[i].fund_pay_type == '310300') {
            //           hifmi_pay = jsonObj[i].fund_payamt
            //         }
            //       }
            //       if (order.insutype == '390') {
            //         if (jsonObj[i].fund_pay_type == '390200') {
            //           hifmi_pay = jsonObj[i].fund_payamt
            //         }
            //       }
            //     }
            //   }
            // }

            let insuplc_admdvs_name = ''
            if (order.his_patient.insuplc_admdvs == '440703') {
              insuplc_admdvs_name = '蓬江区'

            } else if (order.his_patient.insuplc_admdvs == '440704') {

              insuplc_admdvs_name = '江海区'

            } else if (order.his_patient.insuplc_admdvs == '440705') {

              insuplc_admdvs_name = '新会区'

            } else if (order.his_patient.insuplc_admdvs == '440781') {

              insuplc_admdvs_name = '台山市'

            } else if (order.his_patient.insuplc_admdvs == '440783') {
              insuplc_admdvs_name = '开平市'

            } else if (order.his_patient.insuplc_admdvs == '440784') {
              insuplc_admdvs_name = '鹤山市'

            } else if (order.his_patient.insuplc_admdvs == '440785') {
              insuplc_admdvs_name = '恩平市'

            } else if (order.his_patient.insuplc_admdvs == '440799') {
              insuplc_admdvs_name = '市直'
            }

            let obj = {
              就诊号: order.mdtrt_id,
              患者姓名: name,
              患者性别: gender,
              患者年龄: age,
              开处时间: time,
              险种类型: insutypeName,
              参保所属医保区划: order.his_patient.insuplc_admdvs,
              参保号: order.his_patient.id_card_no,
              属地名称: insuplc_admdvs_name,
              应收金额: order.medfee_sumamt,
              实收金额: order.medfee_sumamt,
              医保统筹金额: order.hifp_pay,
              大额基金金额: order.hifob_pay,
              大病基金金额: order.hifmi_pay,
              补充保险基金金额: order.hifes_pay,
              医疗救助基金金额: order.maf_pay,
              公务员基金: order.cvlserv_pay,
              个人支付基金: order.psn_cash_pay,
              个人账户支付金额: order.acct_pay,
              科室: department,
              医生姓名: doctor_name,
              收费类别: balance_accounts,
              收费者姓名: charge_name,
              总金额: order.medfee_sumamt,
              现金支付: '',
              账户支付: '',
              支付宝支付: '',
              微信支付: '',
              其他支付: '',
              收费时间: order.setl_time,
              收费状态: order_status,
              退费日期: ''
            }
            let obj2 = {
              就诊号: order.mdtrt_id,
              患者姓名: name,
              患者性别: gender,
              患者年龄: age,
              开处时间: time,
              险种类型: insutypeName,
              参保所属医保区划: order.his_patient.insuplc_admdvs,
              参保号: order.his_patient.id_card_no,
              应收金额: order.medfee_sumamt,
              实收金额: order.medfee_sumamt,
              医保统筹金额: order.hifp_pay,
              大额基金金额: order.hifob_pay,
              大病基金金额: order.hifmi_pay,
              补充保险基金金额: order.hifes_pay,
              医疗救助基金金额: order.maf_pay,
              公务员基金: order.cvlserv_pay,
              个人支付基金: order.psn_cash_pay,
              个人账户支付金额: order.acct_pay,
              医生姓名: doctor_name,
              收费类别: balance_accounts,
              总金额: order.medfee_sumamt,
              现金支付: '',
              账户支付: '',
              支付宝支付: '',
              微信支付: '',
              其他支付: '',
              收费时间: order.setl_time,
              收费状态: order_status
            }
            list.push(obj)
            list2.push(obj2)
          }
          if(this.org_id != 10697 && this.org_id != 0){
            import('@/vendor/Export2Excel').then((excel) => {
              const tHeader = [
              '就诊号',
              '患者姓名',
              "患者性别",
              "患者年龄",
              '开处时间',
              '险种类型',
              '参保所属医保区划',
              '参保号',
              '属地名称',
              '应收金额',
              '实收金额',
              '医保统筹金额',
              '大额基金金额',
              '大病基金金额',
              '补充保险基金金额',
              '医疗救助基金金额',
              '公务员基金',
              '个人支付基金',
              '个人账户支付金额',
              '科室',
              '医生姓名',
              '收费类别',
              '收费者姓名',
              '总金额',
              '现金支付',
              '账户支付',
              '支付宝支付',
              '微信支付',
              '其他支付',
              '收费时间',
              '收费状态',
              '退费日期'
              ]
              const filterVal = [
                '就诊号',
                '患者姓名',
                "患者性别",
                "患者年龄",
                '开处时间',
                '险种类型',
                '参保所属医保区划',
                '参保号',
                '属地名称',
                '应收金额',
                '实收金额',
                '医保统筹金额',
                '大额基金金额',
                '大病基金金额',
                '补充保险基金金额',
                '医疗救助基金金额',
                '公务员基金',
                '个人支付基金',
                '个人账户支付金额',
                '科室',
                '医生姓名',
                '收费类别',
                '收费者姓名',
                '总金额',
                '现金支付',
                '账户支付',
                '支付宝支付',
                '微信支付',
                '其他支付',
                '收费时间',
                '收费状态',
                '退费日期'
              ]
              const data = this.formatJson(filterVal, list)
              excel.export_json_to_excel({
                header: tHeader,
                data,
                filename: '消费明细'
              })
            })
          }else{
            import('@/vendor/Export2Excel').then((excel) => {
              console.log('222222南昌');
              const tHeader2 = [
              '就诊号',
              '患者姓名',
              "患者性别",
              "患者年龄",
              '开处时间',
                '险种类型',
                '参保所属医保区划',
              '参保号',
              '应收金额',
              '实收金额',
              '医保统筹金额',
              '大额基金金额',
              '大病基金金额',
              '补充保险基金金额',
              '医疗救助基金金额',
              '公务员基金',
              '个人支付基金',
              '个人账户支付金额',
              '医生姓名',
              '收费类别',
              '总金额',
              '现金支付',
              '账户支付',
              '支付宝支付',
              '微信支付',
              '其他支付',
              '收费时间',
              '收费状态'
              ]
              const filterVal2 = [
                '就诊号',
                '患者姓名',
                "患者性别",
                "患者年龄",
                '开处时间',
                '险种类型',
                '参保所属医保区划',
                '参保号',
                '应收金额',
                '实收金额',
                '医保统筹金额',
                '大额基金金额',
                '大病基金金额',
                '补充保险基金金额',
                '医疗救助基金金额',
                '公务员基金',
                '个人支付基金',
                '个人账户支付金额',
                '医生姓名',
                '收费类别',
                '总金额',
                '现金支付',
                '账户支付',
                '支付宝支付',
                '微信支付',
                '其他支付',
                '收费时间',
                '收费状态'
              ]
              const data = this.formatJson(filterVal2, list2)
              excel.export_json_to_excel({
                header: tHeader2,
                data,
                filename: '消费明细'
              })
            })
          }
        }
      })
    },
    formatJson(filterVal, jsonData) {
      return jsonData.map((v) => filterVal.map((j) => v[j]))
    },
    changeSortType() {
      this.page = 1
      this.keywords = ''
      // this.getHisOrderList()
    },
    changeDoctor() {
      this.page = 1
      this.keywords = ''
      // this.getHisOrderList()
    },
    handleSizeChange(limit) {
      this.limit = limit
      this.getHisOrderList()
    },
    handleCurrentChange(page) {
      this.page = page
      this.getHisOrderList()
    },
    handleStartTimeChange() {
      this.page = 1
      this.keywords = ''
      this.getHisOrderList()
    },
    handleEndTimeChange() {
      this.page = 1
      this.keywords = ''
      this.getHisOrderList()
    },
    setMonthPrescription(month_prescriptions) {
      console.log(month_prescriptions)
      let tableData = []
      let drug_month_prescriptions = {
        advices: []
      }
      let drug_ids = []
      let project_month_prescriptions = {
        project: []

      }
      let project_ids = []

      let to = 0
      for (let i = 0; i < month_prescriptions.length; i++) {
        to = to + month_prescriptions[i].det_item_fee_sumamt
      }
      console.log(to)

      // let addition_month_prescriptions = {
      //   addition: []
      //
      // }
      // let additions_ids = []
      for (let i = 0; i < month_prescriptions.length; i++) {
        if (month_prescriptions[i].advice_id > 0 && month_prescriptions[i].project_id == 0) { //药品
          let obj = {
            id: month_prescriptions[i].advices.drug_id,
            price: month_prescriptions[i].pric
          }
          drug_ids.push(obj)
          drug_month_prescriptions.advices.push(month_prescriptions[i])

        } else if (month_prescriptions[i].advice_id == 0 && month_prescriptions[i].project_id > 0) { //项目
          let obj = {
            id: month_prescriptions[i].project.project_id,
            price: month_prescriptions[i].pric
          }

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

      }
      console.log(drug_ids)
      console.log(project_ids)

      drug_ids = this.unique(drug_ids)
      project_ids = this.unique(project_ids)
      console.log(drug_ids)
      console.log(project_ids)

      // additions_ids= this.unique(additions_ids)

      for (let i = 0; i < drug_ids.length; i++) {
        let obj = {}
        let count = 0
        let total = 0

        for (let a = 0; a < drug_month_prescriptions.advices.length; a++) {
          console.log(drug_month_prescriptions.advices[a].id)
          console.log(drug_month_prescriptions.advices[a].det_item_fee_sumamt)
          console.log((parseFloat(drug_month_prescriptions.advices[a].pric) * parseFloat(drug_month_prescriptions.advices[a].cnt)).toFixed(2))

          if (drug_ids[i].price == drug_month_prescriptions.advices[a].pric && drug_ids[i].id == drug_month_prescriptions.advices[a].advices.drug_id) {
            obj['name'] = drug_month_prescriptions.advices[a].advices.advice_name
            obj['code'] = drug_month_prescriptions.advices[a].advices.id
            obj['unit'] = drug_month_prescriptions.advices[a].advices.drug.min_unit
            obj['price'] = parseFloat(drug_month_prescriptions.advices[a].pric)
            obj['id'] = drug_month_prescriptions.advices[a].advices.id
            obj['type'] = 1

            count = count + drug_month_prescriptions.advices[a].cnt
            total = total + drug_month_prescriptions.advices[a].det_item_fee_sumamt
          }
        }

        obj['count'] = count
        obj['total'] = total

        tableData.push(obj)
      }

      for (let i = 0; i < project_ids.length; i++) {
        let obj = {}
        let count = 0
        let total = 0

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

            if (project_month_prescriptions.project[a].project.type == 2) {
              obj['name'] = project_month_prescriptions.project[a].project.project.project_name
              obj['code'] = project_month_prescriptions.project[a].project.id
              obj['unit'] = project_month_prescriptions.project[a].project.project.unit
              obj['type'] = 2
              obj['id'] = project_month_prescriptions.project[a].project.id

            } else if (project_month_prescriptions.project[a].project.type == 3) {
              obj['name'] = project_month_prescriptions.project[a].project.good_info.good_name
              obj['code'] = project_month_prescriptions.project[a].project.id
              obj['unit'] = project_month_prescriptions.project[a].project.good_info.packing_unit
              obj['type'] = 3
              obj['id'] = project_month_prescriptions.project[a].project.id

            }
            count = count + parseFloat(project_month_prescriptions.project[a].cnt)
            total = total + project_month_prescriptions.project[a].det_item_fee_sumamt

            obj['price'] = parseFloat(project_month_prescriptions.project[a].pric)
            obj['type'] = 2

          }
        }

        obj['count'] = count
        obj['total'] = total

        tableData.push(obj)

      }
      return tableData
    },
    setMonthPrescriptiontwo(month_prescriptions) {
      let tableData = []

      let project_month_prescriptions = {
        project: []

      }
      let project_ids = []

      for (let i = 0; i < month_prescriptions.length; i++) {
        if (month_prescriptions[i].type == 2) { //项目
          for (let a = 0; a < month_prescriptions[i].project.length; a++) {
            if (month_prescriptions[i].project[a].type == 2) {
              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])
            }
          }
        }
      }

      project_ids = this.unique(project_ids)
      console.log(project_ids)

      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['name'] = project_month_prescriptions.project[a].project.project_name
              obj['code'] = project_month_prescriptions.project[a].project.medical_code
              count = count + parseFloat(project_month_prescriptions.project[a].count)
              obj['price'] = parseFloat(project_month_prescriptions.project[a].price)
            }
          }
        }
        obj['count'] = count
        tableData.push(obj)

      }
      return tableData
    },

    Action() {
      getAllOrders().then((response) => {
        if (response.data.state == 0) {
          this.$message.error(response.data.msg)
          return false
        } else {
          let list = []
          for (let i = 0; i < response.data.data.order.length; i++) {
            let order = response.data.data.order[i]
            for (let b = 0; b < order.info.length; b++) {
              let item_name = ''
              let item_code = ''
              let price = ''
              let unit = ''
              let spec = ''
              let time = ''
              let cnt = ''

              if (
                order.info[b].advices.id == 0 &&
                order.info[b].project.id > 0
              ) {

                if (order.info[b].project.type == 2) {
                  item_name = order.info[b].project.project.project_name
                  item_code = order.info[b].project.project.medical_code
                  price = order.info[b].pric
                  unit = order.info[b].project.project.unit
                  cnt = order.info[b].cnt
                  time = order.setl_time

                } else {

                  item_name = order.info[b].project.good_info.good_name
                  item_code = order.info[b].project.good_info.medical_insurance_number
                  price = order.info[b].pric
                  unit = order.info[b].project.good_info.packing_unit
                  cnt = order.info[b].cnt
                  time = order.setl_time

                }

              } else if (
                order.info[b].advices.id > 0 &&
                order.info[b].project.id == 0
              ) {
                item_name = order.info[b].advices.advice_name
                item_code =
                  order.info[b].advices.drug.medical_insurance_number
                price = order.info[b].pric
                unit = order.info[b].advices.prescribing_number_unit
                spec = order.info[b].advices.drug.dose + order.info[b].advices.drug.dose_unit + '*' + order.info[b].advices.drug.min_number + order.info[b].advices.drug.min_unit + '/' + order.info[b].advices.drug.max_unit
                cnt = order.info[b].cnt
                time = order.setl_time

              }
              let obj = {
                项目编码: item_code,
                项目名称: item_name,
                规格: spec,
                厂家: '',
                单位: unit,
                数量: cnt,
                时间: time
              }

              list.push(obj)
            }
          }
          import('@/vendor/Export2Excel').then((excel) => {
            const tHeader = [
              '项目编码',
              '项目名称',
              '规格',
              '厂家',
              '单位',
              '数量',
              '时间'
            ]
            const filterVal = [
              '项目编码',
              '项目名称',
              '规格',
              '厂家',
              '单位',
              '数量',
              '时间'
            ]
            const data = this.formatJson(filterVal, list)
            excel.export_json_to_excel({
              header: tHeader,
              data,
              filename: '消费明细'
            })
          })
        }
      })
    },
    searchAction() {
      this.page = 1
      // const tableData = this.tableData
      // if (this.keywords.length == 0) {
      //   this.getHisOrderList()
      // } else {
      //   console.log('6666666',tableData);
      //   let arr = []
      //   for (let i = 0; i < tableData.length; i++) {

      //     if (tableData[i].patient.name.indexOf(this.keywords) != -1 ||
      //       tableData[i].patient.first_letter.indexOf(this.keywords) != -1) {
      //       arr = arr.concat(tableData[i])
      //     }
      //   }
      //   this.tableData = arr
      // }
      this.getHisOrderList()
    },
    getTimes(time) {
      return uParseTime(time, '{y}-{m}-{d}')
    },

    toDetail(row) {
      this.$router.push(
        '/outpatientCharges/summaryDetail?patient_id=' +
        row.patient.id +
        '&number=' +
        row.number +
        '&id=' +
        row.id
      )
    },
    getTime(value, temp) {
      if (value != undefined) {
        return uParseTime(value, temp)
      }
      return ''
    },
    getHisOrderList() {
      let params = {
        page: this.page,
        limit: this.limit,
        keywords: this.keywords,
        start_time: this.start_time,
        end_time: this.end_time,
        type: this.admin_user_id,
        p_type: 2,
        sort_type: this.sort_type,
        sch_type: this.sch_type,
        zone_type: this.zoneVal,
        med_type: this.medTypeVal
      }
      getHisOrderList(params).then((response) => {
        if (response.data.state == 0) {
          this.$message.error(response.data.msg)
          return false
        } else {
          console.log('8888888',response.data.data);
          this.tableData = response.data.data.order
          this.tableData2 =  response.data.data.order2
          this.total = response.data.data.total
        }
      })
    },
    getDoctorList() {
      getDoctorList().then((response) => {
        if (response.data.state == 0) {
          this.$message.error(response.data.msg)
          return false
        } else {
          this.doctors = response.data.data.doctors
        }
      })
    },
    open(row) {
      this.paramsObj.id =''
      console.log('row',(row.id).toString());
      const id = (row.id).toString()
      this.paramsObj.id = id
      this.jgFileTimer = new Date().getTime()
      console.log('this.paramsObj.id',this.paramsObj.id);
      this.listVisible = true

    }, unique(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
    },camcleModifyFaPiaoCode(){
      this.dialogfapiaoVisible = false
      this.invoiceVisible = true
      var obj = this.targeObj
      let paramsObj = {
        order_id: obj.id,
        patient_id: obj.patient_id,
        number: obj.mdtrt_id,
        name: obj.patient.name,
        age: obj.age,
        gend: obj.patient.gender,
        setl_time: obj.setl_time,
        chargeName: this.getName(obj.creator)
      }
      this.dialogfapiaoVisible = false
      this.invoiceParams = paramsObj
      this.invoiceVisible = true
    },modifyFaPiaoCode(){
      let params = {
          id:this.targeOrderId,
          fapiao_number: this.fapiao_number
      }
      modifyFapiaoCodetwo(params).then((response) => {
        if (response.data.state == 0) {
          this.$message.error(response.data.msg)
          return false
        } else {
          var obj = this.targeObj
          let paramsObj = {
            order_id: obj.id,
            patient_id: obj.patient_id,
            number: obj.mdtrt_id,
            name: obj.patient.name,
            age: obj.age,
            gend: obj.patient.gender,
            setl_time: obj.setl_time,
            chargeName: this.getName(obj.creator)
          }
          this.dialogfapiaoVisible = false
          this.invoiceParams = paramsObj
          this.invoiceVisible = true
          this.getHisOrderList()
        }
      })

    },

    invoicePrint(obj) {
      if(this.$store.getters.xt_user.org_id == 10480 || this.$store.getters.xt_user.org_id == 0){
        this.fapiao_number  = obj.fa_piao_number
        this.dialogfapiaoVisible = true
        this.targeOrderId = obj.id
        this.targeObj = obj
      }else{
        let paramsObj = {
          order_id: obj.id,
          patient_id: obj.patient_id,
          number: obj.mdtrt_id,
          name: obj.patient.name,
          age: obj.age,
          gend: obj.patient.gender,
          setl_time: obj.setl_time,
          chargeName: this.getName(obj.creator)
        }
        this.dialogfapiaoVisible = false
        this.invoiceParams = paramsObj
        this.invoiceVisible = true


      }


    }
  },

}
</script>
<style lang="scss">
  .table{
    tr td{
      padding:5px 0;
    }
  }
  .content_top{
    flex: 1;
    display: flex;
    // justify-content: space-between;
  }
  .content_button{
    flex: 1;
    display: flex;
    text-align: right;
    justify-content: flex-end;
    //justify-content:space-around;
  }
  .butt_1{
    margin-left:10px;
  }
  .butt_2{
    margin-top: 3px;
  }
</style>
