<template>
    <div class="main-contain">
        <div class="position">
            <bread-crumb :crumbs='crumbs'></bread-crumb>
        </div>
        <!--<div v-if="this.$store.getters.xt_user.org_id == 9504 || this.$store.getters.xt_user.org_id == 10028 || this.$store.getters.xt_user.org_id == 10138"-->
             <!--class="app-container">-->
            <!--<div class="cell clearfix">-->
                <!--&lt;!&ndash; <el-input style="width: 180px;" v-model.trim="search_input" class="filter-item"/> &ndash;&gt;-->
                <!--<el-autocomplete-->
                        <!--style="margin:16px 5px"-->
                        <!--popper-class="my-autocomplete"-->
                        <!--v-model.trim="search_input"-->
                        <!--:fetch-suggestions="querySearchAsync"-->
                        <!--:trigger-on-focus="false"-->
                        <!--placeholder="病人名字或者透析号"-->
                        <!--@select="handleSelect"-->
                <!--&gt;-->
                    <!--<i class="el-icon-search el-input__icon" slot="suffix"> </i>-->
                    <!--<template slot-scope="{ item }">-->
                        <!--<div class="name">{{ item.name }}</div>-->
                    <!--</template>-->
                <!--</el-autocomplete>-->
                <!--<el-button style="margin-right:10px;" class="filter-item" type="primary" icon="el-icon-search"-->
                           <!--@click="searchAction">搜索-->
                <!--</el-button>-->
                <!--&lt;!&ndash; <el-date-picker-->
                <!--v-model="value1"-->
                <!--@change="changeTime"-->
                <!--style="margin-right:10px;"-->
                <!--type="daterange"-->
                <!--range-separator="-"-->
                <!--start-placeholder="开始日期"-->
                <!--end-placeholder="结束日期">-->
                <!--</el-date-picker> &ndash;&gt;-->
                <!--<el-date-picker type="datetime" format="yyyy-MM-dd" value-format="yyyy-MM-dd"-->
                                <!--placeholder="选择时间" v-model="start_time" style="width:200px"-->
                                <!--@change="changeStart"-->
                <!--&gt;-->
                <!--</el-date-picker>-->
                <!-- - -->
                <!--<el-date-picker type="datetime" format="yyyy-MM-dd" value-format="yyyy-MM-dd"-->
                                <!--placeholder="选择时间" v-model="end_time" style="width:200px"-->
                                <!--@change="changeEnd"-->
                <!--&gt;-->
                <!--</el-date-picker>-->
                <!--<label class="title"><span class="name">挂号类型</span> : </label>-->
                <!--<el-select v-model="register_type" placeholder="请选择" style="width:150px;" @change="changeRegister">-->
                    <!--<el-option-->
                            <!--v-for="item in register"-->
                            <!--:key="item.value"-->
                            <!--:label="item.label"-->
                            <!--:value="item.value">-->
                    <!--</el-option>-->
                <!--</el-select>-->
            <!--</div>-->
            <!--<el-table :data="tableData" border style="width: 100%;" :row-style="{ color: '#303133' }"-->
                      <!--:header-cell-style="{backgroundColor: 'rgb(245, 247, 250)',color: '#606266'}"-->
                      <!--highlight-current-row>-->
                <!--<el-table-column align="center" type="index" label="序号" width="60">-->
                <!--</el-table-column>-->
                <!--<el-table-column align="center" prop="name" label="时间" width="100">-->
                    <!--<template slot-scope="scope">{{getTime(scope.row.ctime,'{y}-{m}-{d} {h}:{i}:{s}')}}</template>-->
                <!--</el-table-column>-->
                <!--<el-table-column align="center" prop="dialysis_no" label="姓名" width="80">-->
                    <!--<template slot-scope="scope">{{scope.row.name }}</template>-->
                <!--</el-table-column>-->
                <!--<el-table-column align="center" prop="name" label="科室" width="80">-->
                    <!--<template slot-scope="scope">{{getDepartMent(scope.row.departments)}}</template>-->
                <!--</el-table-column>-->
                <!--<el-table-column align="center" prop="name" label="挂号类型" width="90">-->
                    <!--<template slot-scope="scope">-->
                        <!--<span v-if="scope.row.register_type == 1">普通</span>-->
                        <!--<span v-if="scope.row.register_type == 2">主治</span>-->
                        <!--<span v-if="scope.row.register_type == 3">主任</span>-->
                        <!--<span v-if="scope.row.register_type == 4">免收诊金</span>-->
                        <!--<span v-if="scope.row.register_type == 5">专家</span>-->
                    <!--</template>-->
                <!--</el-table-column>-->
                <!--<el-table-column align="center" prop="name" label="就诊号" width="80">-->
                    <!--<template slot-scope="scope">-->
                        <!--{{scope.row.number}}-->
                    <!--</template>-->
                <!--</el-table-column>-->
                <!--<el-table-column align="center" prop="name" label="证件号" width='180'>-->
                    <!--<template slot-scope="scope">{{ scope.row.id_card_no }}</template>-->
                <!--</el-table-column>-->
                <!--<el-table-column align="center" label="社保类型">-->
                    <!--<template slot-scope="scope">{{getMedicalTreatment(scope.row.social_type)}}</template>-->
                <!--</el-table-column>-->
                <!--<el-table-column align="center" prop="name" label="医生" width="80">-->
                    <!--<template slot-scope="scope">{{getDoctor(scope.row.doctor) }}</template>-->
                <!--</el-table-column>-->
                <!--<el-table-column align="center" prop="name" label="挂号费" width="70">-->
                    <!--<template slot-scope="scope">{{ scope.row.register_cost }}</template>-->
                <!--</el-table-column>-->
                <!--<el-table-column align="center" prop="name" label="诊疗费" width="70">-->
                    <!--<template slot-scope="scope">{{ scope.row.treatment_cost }}</template>-->
                <!--</el-table-column>-->
                <!--<el-table-column align="center" prop="name" label="工本费" width="70">-->
                    <!--<template slot-scope="scope">{{ scope.row.cost_of_production }}</template>-->
                <!--</el-table-column>-->
                <!--<el-table-column align="center" prop="name" label="结算类型" width="70">-->
                    <!--<template slot-scope="scope">{{getBanlance(scope.row.balance_accounts_type) }}</template>-->
                <!--</el-table-column>-->
                <!--<el-table-column align="center" prop="name" label="操作人" width="70">-->
                    <!--<template slot-scope="scope">{{creator}}</template>-->
                <!--</el-table-column>-->
                <!--<el-table-column align="center" prop="name" label="操作" width="180">-->
                    <!--<template slot-scope="scope">-->
                        <!--&lt;!&ndash;<el-button size="mini" type="primary" v-if=" scope.row.record_date < startUnix" :disabled="true">已过号</el-button>&ndash;&gt;-->
                        <!--<el-button size="mini" type="primary" v-if="scope.row.status == 1"-->
                                   <!--@click="toReturnSZPatient(scope.row)">退号-->
                        <!--</el-button>-->
                        <!--<el-button size="mini" type="primary" :disabled="true" v-if="scope.row.status == 0">已退号-->
                        <!--</el-button>-->

                        <!--&lt;!&ndash;<el-button size="mini" type="primary" v-if="scope.row.record_date == startUnix && scope.row.is_return == 2" :disabled="true">已退号</el-button>&ndash;&gt;-->
                        <!--&lt;!&ndash;<el-button size="mini" type="primary" v-if="scope.row.record_date == startUnix && scope.row.is_return == 3" :disabled="true">已就诊</el-button>&ndash;&gt;-->
                        <!--&lt;!&ndash;<el-button size="mini" type="primary" @click="open(scope.row)">详情</el-button>&ndash;&gt;-->
                    <!--</template>-->
                <!--</el-table-column>-->
            <!--</el-table>-->

            <!--<el-pagination-->
                    <!--@size-change="handleSizeChange"-->
                    <!--@current-change="handleCurrentChange"-->
                    <!--:page-sizes="[10, 50, 100]"-->
                    <!--:page-size="10"-->
                    <!--background-->
                    <!--style="margin-top:20px;float: right"-->
                    <!--layout="total, sizes, prev, pager, next, jumper"-->
                    <!--:total="total"-->
            <!--&gt;-->
            <!--</el-pagination>-->
            <!--<el-dialog-->
                    <!--title="挂号历史详情"-->
                    <!--:visible.sync="dialogVisible"-->
                    <!--width="1100px"-->
                    <!--:before-close="handleClose">-->
                <!--<div>-->
                    <!--<div class="formMain">-->
                        <!--<el-form class="basicForm" :model="form" ref="form" label-width="130px">-->
                            <!--<el-form-item label="患者姓名：" prop="name">-->
                                <!--<div>{{ form.name }}</div>-->
                            <!--</el-form-item>-->

                            <!--<el-form-item label="性别：" prop="gender">-->
                                <!--<div v-if="form.gender == 1">男</div>-->
                                <!--<div v-if="form.gender == 2">女</div>-->
                            <!--</el-form-item>-->

                            <!--<el-form-item label="年龄：" prop="age">-->
                                <!--<div>{{ form.age }}</div>-->
                            <!--</el-form-item>-->


                            <!--<el-form-item label="出生日期：" prop="birthday">-->
                                <!--<div>{{ getTime(form.birthday,'{y}-{m}-{d}') }}</div>-->
                            <!--</el-form-item>-->

                            <!--<el-form-item label="手机号码：" prop="phone">-->
                                <!--<div>{{ form.phone }}</div>-->
                            <!--</el-form-item>-->


                            <!--<el-form-item label="医疗类别：">-->
                                <!--<div>{{ getDictionaryDataConfig(form.medical_treatment_type) }}</div>-->
                            <!--</el-form-item>-->


                            <!--<el-form-item label="证件类型：">-->
                                <!--<div>{{ getCertificates(form.id_type) }}</div>-->
                            <!--</el-form-item>-->

                            <!--<el-form-item label="证件号码：" prop="idCard">-->
                                <!--{{ form.id_card_no }}-->
                            <!--</el-form-item>-->


                            <!--<el-form-item label="结算类型：">-->
                                <!--{{ getSettlement(form.balance_accounts_type) }}-->
                            <!--</el-form-item>-->


                            <!--<el-form-item label="社保类型：">-->
                                <!--<div>{{ getMedicalCare(form.social_type) }}</div>-->
                            <!--</el-form-item>-->
                            <!--<el-form-item class="specialFormItem" style="width:66.5%;" label="医保卡号：">-->
                                <!--<div>{{ form.medical_insurance_number }}</div>-->
                            <!--</el-form-item>-->
                            <!--<el-form-item label="挂号类型：" prop="register" :validate-event="is_Name">-->
                                <!--<div>{{ getRegister(form.register_type) }}</div>-->
                            <!--</el-form-item>-->
                            <!--<el-form-item label="医生：" prop="doctor" :validate-event="is_Name">-->
                                <!--<div>{{ getDoctor(form.doctor) }}</div>-->
                            <!--</el-form-item>-->
                            <!--<el-form-item label="科室：" prop="department" :validate-event="is_Name">-->
                                <!--<div>{{ getDepartMent(form.departments) }}</div>-->
                            <!--</el-form-item>-->
                            <!--&lt;!&ndash; <el-form-item label="是否需要工本费：">-->
                              <!--<div v-if="form.is_need_cost_of_production == 1">是</div>-->
                              <!--<div v-else>否</div>-->
                            <!--</el-form-item> &ndash;&gt;-->

                            <!--<el-form-item label="挂号费：">-->
                                <!--<div>{{ form.register_cost }}</div>-->
                            <!--</el-form-item>-->
                            <!--<el-form-item label="诊疗费：">-->
                                <!--<div>{{ form.treatment_cost }}</div>-->
                            <!--</el-form-item>-->
                            <!--<el-form-item label="工本费：">-->
                                <!--<div>{{ form.cost_of_production }}</div>-->
                            <!--</el-form-item>-->
                            <!--<el-form-item label="合计：">-->
                                <!--<div>{{ form.total }}</div>-->
                            <!--</el-form-item>-->
                            <!--<el-form-item>-->
                                <!--&lt;!&ndash; <el-input v-model="form.name"></el-input> &ndash;&gt;-->
                            <!--</el-form-item>-->
                        <!--</el-form>-->
                    <!--</div>-->
                <!--</div>-->
                <!--<span slot="footer" class="dialog-footer">-->
                <!--<el-button @click="dialogVisible = false">取 消</el-button>-->
                <!--<el-button type="primary" @click="dialogVisible = false">确 定</el-button>-->
              <!--</span>-->
            <!--</el-dialog>-->
        <!--</div>-->

        <div class="app-container">
            <div class="cell clearfix">
                <!-- <el-input style="width: 180px;" v-model.trim="search_input" class="filter-item"/> -->
                <el-autocomplete
                        style="margin:16px 5px"
                        popper-class="my-autocomplete"
                        v-model.trim="search_input"
                        :fetch-suggestions="querySearchAsync"
                        :trigger-on-focus="false"
                        placeholder="病人名字或者透析号"
                        @select="handleSelect"
                >
                    <i class="el-icon-search el-input__icon" slot="suffix"> </i>
                    <template slot-scope="{ item }">
                        <div class="name">{{ item.name }}</div>
                    </template>
                </el-autocomplete>
                <el-button style="margin-right:10px;" class="filter-item" type="primary" icon="el-icon-search"
                           @click="searchAction">搜索
                </el-button>
                <!-- <el-date-picker
                v-model="value1"
                @change="changeTime"
                style="margin-right:10px;"
                type="daterange"
                range-separator="-"
                start-placeholder="开始日期"
                end-placeholder="结束日期">
                </el-date-picker> -->
                <el-date-picker type="datetime" format="yyyy-MM-dd" value-format="yyyy-MM-dd"
                                placeholder="选择时间" v-model="start_time" style="width:200px"
                                @change="changeStart"
                >
                </el-date-picker>
                -
                <el-date-picker type="datetime" format="yyyy-MM-dd" value-format="yyyy-MM-dd"
                                placeholder="选择时间" v-model="end_time" style="width:200px"
                                @change="changeEnd"
                >
                </el-date-picker>
                <label class="title"><span class="name">挂号类型</span> : </label>
                <el-select v-model="register_type" placeholder="请选择" style="width:150px;" @change="changeRegister">
                    <el-option
                            v-for="item in register"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                    </el-option>
                </el-select>
            </div>
            <el-table :data="tableData" border style="width: 100%;" :row-style="{ color: '#303133' }"
                      :header-cell-style="{backgroundColor: 'rgb(245, 247, 250)',color: '#606266'}"
                      highlight-current-row>
                <el-table-column align="center" type="index" label="序号" width="60">
                </el-table-column>
                <el-table-column align="center" prop="name" label="时间" width="100">
                    <template slot-scope="scope">{{getTime(scope.row.ctime,'{y}-{m}-{d} {h}:{i}:{s}')}}</template>
                </el-table-column>
                <el-table-column align="center" prop="dialysis_no" label="姓名" width="80">
                    <template slot-scope="scope">{{scope.row.name }}</template>
                </el-table-column>
                <el-table-column align="center" prop="name" label="科室" width="80">
                    <template slot-scope="scope">{{getDepartMent(scope.row.departments)}}</template>
                </el-table-column>
                <el-table-column align="center" prop="name" label="挂号类型" width="90">
                    <template slot-scope="scope">
                        <span v-if="scope.row.register_type == 1">普通</span>
                        <span v-if="scope.row.register_type == 2">主治</span>
                        <span v-if="scope.row.register_type == 3">主任</span>
                        <span v-if="scope.row.register_type == 4">免收诊金</span>
                        <span v-if="scope.row.register_type == 5">专家</span>
                    </template>
                </el-table-column>
                <el-table-column align="center" prop="name" label="就诊号" width="80">
                    <template slot-scope="scope">
                        {{scope.row.number}}
                    </template>
                </el-table-column>
                <el-table-column align="center" prop="name" label="证件号" width='180'>
                    <template slot-scope="scope">{{ scope.row.id_card_no }}</template>
                </el-table-column>
                <el-table-column align="center" label="社保类型">
                    <template slot-scope="scope">{{getMedicalTreatment(scope.row.social_type)}}</template>
                </el-table-column>
                <el-table-column align="center" prop="name" label="医生" width="80">
                    <template slot-scope="scope">{{getDoctor(scope.row.doctor) }}</template>
                </el-table-column>
                <el-table-column align="center" prop="name" label="挂号费" width="70">
                    <template slot-scope="scope">{{ scope.row.register_cost }}</template>
                </el-table-column>
                <el-table-column align="center" prop="name" label="诊疗费" width="70">
                    <template slot-scope="scope">{{ scope.row.treatment_cost }}</template>
                </el-table-column>
                <el-table-column align="center" prop="name" label="工本费" width="70">
                    <template slot-scope="scope">{{ scope.row.cost_of_production }}</template>
                </el-table-column>
                <el-table-column align="center" prop="name" label="结算类型" width="70">
                    <template slot-scope="scope">{{getBanlance(scope.row.balance_accounts_type) }}</template>
                </el-table-column>
                <el-table-column align="center" prop="name" label="操作人" width="70">
                    <template slot-scope="scope">{{creator}}</template>
                </el-table-column>
                <el-table-column align="center" prop="name" label="操作" width="180">
                    <template slot-scope="scope">
                        <!--<el-button size="mini" type="primary" v-if=" scope.row.record_date < startUnix" :disabled="true">已过号</el-button>-->
                        <el-button size="mini" type="primary" v-if="scope.row.status == 1"
                                   @click="toReturnPatient(scope.row)">退号
                        </el-button>
                        <el-button size="mini" type="primary" v-if="scope.row.status == 0" :disabled="true">已退号
                        </el-button>
                        <!--<el-button size="mini" type="primary" v-if="scope.row.record_date == startUnix && scope.row.is_return == 2" :disabled="true">已退号</el-button>-->
                        <!--<el-button size="mini" type="primary" v-if="scope.row.record_date == startUnix && scope.row.is_return == 3" :disabled="true">已就诊</el-button>-->
                        <el-button 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"
                    background
                    style="margin-top:20px;float: right"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="total"
            >
            </el-pagination>
            <el-dialog
                    title="挂号历史详情"
                    :visible.sync="dialogVisible"
                    width="1100px"
                    :before-close="handleClose">
                <div>
                    <div class="formMain">
                        <el-form class="basicForm" :model="form" ref="form" label-width="130px">
                            <el-form-item label="患者姓名：" prop="name">
                                <div>{{ form.name }}</div>
                            </el-form-item>

                            <el-form-item label="性别：" prop="gender">
                                <div v-if="form.gender == 1">男</div>
                                <div v-if="form.gender == 2">女</div>
                            </el-form-item>

                            <el-form-item label="年龄：" prop="age">
                                <div>{{ form.age }}</div>
                            </el-form-item>


                            <el-form-item label="出生日期：" prop="birthday">
                                <div>{{ getTime(form.birthday,'{y}-{m}-{d}') }}</div>
                            </el-form-item>

                            <el-form-item label="手机号码：" prop="phone">
                                <div>{{ form.phone }}</div>
                            </el-form-item>


                            <el-form-item label="医疗类别：">
                                <div>{{ getDictionaryDataConfig(form.medical_treatment_type) }}</div>
                            </el-form-item>


                            <el-form-item label="证件类型：">
                                <div>{{ getCertificates(form.id_type) }}</div>
                            </el-form-item>

                            <el-form-item label="证件号码：" prop="idCard">
                                {{ form.id_card_no }}
                            </el-form-item>


                            <el-form-item label="结算类型：">
                                {{ getSettlement(form.balance_accounts_type) }}
                            </el-form-item>


                            <el-form-item label="社保类型：">
                                <div>{{ getMedicalCare(form.social_type) }}</div>
                            </el-form-item>
                            <el-form-item class="specialFormItem" style="width:66.5%;" label="医保卡号：">
                                <div>{{ form.medical_insurance_number }}</div>
                            </el-form-item>
                            <el-form-item label="挂号类型：" prop="register" :validate-event="is_Name">
                                <div>{{ getRegister(form.register_type) }}</div>
                            </el-form-item>
                            <el-form-item label="医生：" prop="doctor" :validate-event="is_Name">
                                <div>{{ getDoctor(form.doctor) }}</div>
                            </el-form-item>
                            <el-form-item label="科室：" prop="department" :validate-event="is_Name">
                                <div>{{ getDepartMent(form.departments) }}</div>
                            </el-form-item>
                            <!-- <el-form-item label="是否需要工本费：">
                              <div v-if="form.is_need_cost_of_production == 1">是</div>
                              <div v-else>否</div>
                            </el-form-item> -->

                            <el-form-item label="挂号费：">
                                <div>{{ form.register_cost }}</div>
                            </el-form-item>
                            <el-form-item label="诊疗费：">
                                <div>{{ form.treatment_cost }}</div>
                            </el-form-item>
                            <el-form-item label="工本费：">
                                <div>{{ form.cost_of_production }}</div>
                            </el-form-item>
                            <el-form-item label="合计：">
                                <div>{{ form.total }}</div>
                            </el-form-item>
                            <el-form-item>
                                <!-- <el-input v-model="form.name"></el-input> -->
                            </el-form-item>
                        </el-form>
                    </div>
                </div>
                <span slot="footer" class="dialog-footer">
                <el-button @click="dialogVisible = false">取 消</el-button>
                <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
              </span>
            </el-dialog>
        </div>
    </div>
</template>

<script>
  const moment = require('moment')
  import BreadCrumb from '@/xt_pages/components/bread-crumb'
  import { changePatient, getHisPatient, getHisPatientHistory } from '@/api/project/project'

  import { refundNumber} from '@/api/his/his'


  import { uParseTime } from '@/utils/tools'
  import { getDictionaryDataConfig } from '@/utils/data'
  import axios from 'axios'


  export default {
    components: {
      BreadCrumb
    },
    data() {
      return {
        crumbs: [
          { path: false, name: '门诊挂号' },
          { path: false, name: '挂号历史' }
        ],
        register_type: 0,
        search_input: '',
        value1: '',
        tableData: [],
        register: [
          { value: 0, label: '全部' },
          { value: 1, label: '普通' },
          { value: 2, label: '主治' },
          { value: 3, label: '主任' },
          { value: 4, label: '免收诊金' },
          { value: 5, label: '专家' }
        ],
        start_time: moment().format('YYYY-MM-DD'),
        end_time: moment().format('YYYY-MM-DD'),
        limit: 10,
        page: 1,
        total: 0,
        departMent: [],
        doctorList: [],
        medicalCare: [{
          id: 1,
          name: '职工基本医疗保险'
        }, {
          id: 2,
          name: '公务员医疗补助'
        }, {
          id: 3,
          name: '大额医疗费用补助'
        }, {
          id: 4,
          name: '离休人员医疗'
        }, {
          id: 5,
          name: '城乡居民基本医疗保险'
        }, {
          id: 6,
          name: '城乡居民大病医疗保险'
        },
          {
            id: 7,
            name: '生育保险'
          }],
        certificates: [{
          value: 1,
          label: '内地身份证'
        }, {
          value: 2,
          label: '社保卡'
        }, {
          value: 3,
          label: '护照'
        }, {
          value: 4,
          label: '军官证'
        }, {
          value: 5,
          label: '台胞证'
        }, {
          value: 6,
          label: '港澳地区身份证'
        }],
        settlement:
          [
            { value: 1, label: '医保' },
            { value: 2, label: '自费' },
            { value: 3, label: '公费' },
            { value: 4, label: '农保' },
            { value: 5, label: '会员' },
            { value: 6, label: '职工' },
            { value: 7, label: '合同' },
            {value: 8, label: '医保自费'},

          ],
        // medicalCare: [{
        //   value: 1,
        //   label: '职工基本医疗保险'
        //   }, {
        //   value: 2,
        //   label: "公务员医疗补助"
        //   },{
        //   value: 3,
        //   label: "大额医疗费用补助"
        //   },{
        //   value: 4,
        //   label: "离休人员医疗"
        //   },{
        //   value: 5,
        //   label: "城乡居民基本医疗保险"
        //   },{
        //   value: 6,
        //   label: "城乡居民大病医疗保险"
        //   },
        //   {
        //   value: 7,
        //   label: "生育保险"
        // }],
        newRegister: [{
          value: 1,
          label: '普通'
        }, {
          value: 2,
          label: '主治'
        }, {
          value: 3,
          label: '主任'
        }, {
          value: 4,
          label: '免收诊金'
        }, {
          value: 5,
          label: '专家'
        }],

        tablePatient: [],
        creator: '',
        startUnix: '',

        dialogVisible: false,
        form: {},
        is_Name: false
      }
    },
    created() {
      // let a = JSON.parse(localStorage.getItem("temp"))
      // let arr = []
      // a.map(item => {
      //     if(item.org_id == this.$store.getters.xt_user.org_id){
      //         item.create_time = moment(item.create_time * 1000).format('YYYY-MM-DD')
      //         arr.push(item)
      //     }

      // })
      // this.tableData = arr
      //获取所有挂号号的患者

      this.creator = this.$store.getters.xt_user.user.user_name
      var today = moment().startOf('day').format('YYYY-MM-DD')
      var todayUnix = Date.parse(today) / 1000
      this.startUnix = todayUnix - 28800

      this.getlist()
      this.getDictionaryDataConfig()
    },
    methods: {
      searchAction() {
        this.getlist()
      },
      // changeTime(val){
      //     let arr = JSON.parse(localStorage.getItem("temp"))
      //     arr.map(item => {
      //         item.create_time = moment(item.create_time * 1000).format('YYYY-MM-DD')
      //     })
      //     this.tableData = arr
      //     console.log(new Date(val[0]).getTime() / 1000)
      //     console.log(new Date(val[1]).getTime() / 1000)
      //     let arr1 = this.tableData
      //     let a = []
      //     arr1.map(item => {
      //      if(new Date(item.create_time).getTime() / 1000 > new Date(val[0]).getTime() / 1000 && new Date(item.create_time).getTime() / 1000 < new Date(val[1]).getTime() / 1000 && item.org_id == this.$store.getters.xt_user.org_id){
      //         a.push(item)
      //       }
      //     })
      //     this.tableData = a
      // },
      changeStart(val) {
        this.start_time = val
        this.getlist()
      },
      changeEnd(val) {
        this.end_time = val
        this.getlist()
      },
      changeRegister(val) {
        this.getlist()
      },
      handleSizeChange(val) {
        this.limit = val
        this.getlist()
      },
      handleCurrentChange(val) {
        this.page = val
        this.getlist()
      },
      getlist() {
        var params = {
          keyword: this.search_input,
          start_time: this.start_time,
          end_time: this.end_time,
          register_type: this.register_type,
          limit: this.limit,
          page: this.page
        }
        console.log('params', params)
        getHisPatientHistory(params).then(response => {
          if (response.data.state == 1) {
            var history = response.data.data.history

            console.log('history', history)
            this.tableData = history
            var total = response.data.data.total
            console.log('total', total)
            this.total = total
            var department = response.data.data.department
            console.log('department', department)
            this.departMent = department
            var doctor = response.data.data.doctor
            console.log('doctor', doctor)
            this.doctorList = doctor
          }
        })

      },
      getDepartMent(id) {
        var name = ''
        for (let i = 0; i < this.departMent.length; i++) {
          if (id == this.departMent[i].id) {
            name = this.departMent[i].name
          }
        }
        return name
      },
      getDoctor(id) {
        var user_name = ''
        for (let i = 0; i < this.doctorList.length; i++) {
          if (id == this.doctorList[i].admin_user_id) {
            user_name = this.doctorList[i].user_name
          }
        }
        return user_name
      },
      getMedicalTreatment(id) {
        var name = ''
        for (let i = 0; i < this.medicalCare.length; i++) {
          if (this.medicalCare[i].id == id) {
            name = this.medicalCare[i].name
          }
        }
        return name
      },
      getTime(value, temp) {
        if (value != undefined) {
          return uParseTime(value, temp)
        }
        return ''
      }, toReturnSZPatient(val) {
        if(val.balance_accounts_type == 2){
          this.$confirm('是否退号', '退号 ', {
            confirmButtonText: '确 定',
            cancelButtonText: '取 消',
            type: 'warning'
          }).then(() => {
            let params = {
              'id': val.id,
            };
            refundNumber(params).then(response => {
              if (response.data.state == 0) {
                this.$message.error(response.data.msg);
                this.loadingtwo = false;
                return false
              } else {
                this.getlist()
                this.$message({ message: '退号成功', type: 'success' });

              }
            })

          }).catch(() => {

          })

        }else{
          var that = this
          this.$confirm('是否退号', '退号', {
            confirmButtonText: '确 定',
            cancelButtonText: '取 消',
            type: 'warning'
          }).then(() => {
            axios.get('http://127.0.0.1:9532/sz/api/refundnumber/get', {
              params: {
                his_patient_id: val.id,
                record_time: this.getTime(val.record_date, '{y}-{m}-{d}'),
                admin_user_id: this.$store.getters.xt_user.user.id,
                patient_id: val.patient_id
              }
            })
              .then(function(response) {
                if (response.data.state == 0) {
                  that.$message.error(response.data.msg)
                  return false
                } else {
                  if (response.data.data.failed_code == -10) {
                    that.$confirm(response.data.data.msg, '医保错误信息', {
                      confirmButtonText: '确 定',
                      type: 'warning'
                    }).then(() => {

                    }).catch(() => {
                    })
                    // that.$message.error(response.data.data.msg)

                  } else {
                    that.getlist()
                    that.$message({ message: '退号成功', type: 'success' })
                  }
                }
              })
              .catch(function(error) {
              })
          }).catch(() => {
          })
        }
      },
      toReturnPatient(row) {
        var that = this
        this.$confirm('确认退号吗?', '退号', {
          confirmButtonText: '确 定',
          cancelButtonText: '取 消',
          type: 'warning'
        }).then(() => {
          //
          let params = {
            'id':row.id,
            'patient_id': row.patient_id,
            'record_time': that.getTimes(row.record_date),
            'admin_user_id': this.$store.getters.xt_user.user.id
          }
          axios.get('http://127.0.0.1:9532/api/refundnumber/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.getlist()
                }
              }
            })
            .catch(function(error) {
            })
          //
          // changePatient(id).then(response => {
          //   if (response.data.state == 1) {
          //     var msg = response.data.data.msg
          //     this.$message.success('退号成功')
          //     this.getlist()
          //   } else {
          //     this.$message.error('患者已就诊,退号失败')
          //   }
          // })
        })
          .catch(() => {
          })
      }, getTimes(time) {
        return uParseTime(time, '{y}-{m}-{d}')
      },

      querySearchAsync(keyword, cb) {
        let key = '';
        if (keyword != undefined) {
          key = keyword
        }
        let searchArray = []

        var params = {
          keyword: key
        }
        console.log('params', params)
        getHisPatient(params).then(response => {
          if (response.data.state == 1) {
            searchArray = response.data.data.patient
            console.log('searcharrya', searchArray)
            cb(searchArray)
          }
        })
        return searchArray
      },

      handleSelect(val) {
        this.search_input = val.name
        this.getlist()
      },
      handleClose(done) {
        done()
      },
      open(obj) {
        this.dialogVisible = true
        this.form = obj
        console.log(obj)
      },
      getDictionaryDataConfig(type) {
        let arr = getDictionaryDataConfig('system', 'social_type')
        let str = ''
        arr.map(item => {
          if (item.id == type) {
            str = item.name
          }
        })
        return str
      },
      getCertificates(type) {
        let arr = this.certificates
        let str = ''
        arr.map(item => {
          if (item.value == type) {
            str = item.label
          }
        })
        return str
      },
      getSettlement(type) {
        let arr = this.settlement
        let str = ''
        arr.map(item => {
          if (item.value == type) {
            str = item.label
          }
        })
        return str
      },
      getMedicalCare(type) {
        let arr = this.medicalCare
        let str = ''
        arr.map(item => {
          if (item.id == type) {
            str = item.name
          }
        })
        return str
      },
      getRegister(type) {
        let arr = this.newRegister
        let str = ''
        arr.map(item => {
          if (item.value == type) {
            str = item.label
          }
        })
        return str
      },
      getDepartMent(type) {
        let arr = this.departMent
        let str = ''
        arr.map(item => {
          if (item.id == type) {
            str = item.name
          }
        })
        return str
      },

      getBanlance(id) {
        var label = ''
        for (let i = 0; i < this.settlement.length; i++) {
          if (id == this.settlement[i].value) {
            label = this.settlement[i].label
          }
        }
        return label
      }
    }
  }
</script>

<style lang="scss" scoped>
    .basicForm {
        display: flex;
        flex-wrap: wrap;
        justify-content: space-between;

    .el-form-item {
        width: 33%;
    }

    }
</style>
