<template>
    <div class="app-container">
        <el-card style="background-color: #5298f8; width: 99%; margin: 0 auto">
            <div class="boxmain">
                <div class="btslist" style="width: 150px">
                    <el-button @click="cardtype('1')" style="color: #3d7ff5; width: 97px; font-size: 17px; font-weight: 600" round>读卡</el-button>
                </div>
                <div class="" style="width: 170px; line-height: 38px; color: white">
                    <span class="ksmzjzzzbs">姓名:</span>
                    <span style="margin-left: 10px"> {{ out_patient.patient.id }}</span>
                </div>
                <div class="" style="width: 170px; line-height: 38px; color: white">
                    <span class="ksmzjzzzbs">挂号类型:</span>
                    <span style="margin-left: 10px"> {{ out_patient.patient.p_xm }}</span>
                </div>
                <div style="width: 200px; line-height: 38px; color: white">
                    <span class="ksmzjzzzbs">价格:</span>
                    <span style="margin-left: 10px">{{ out_patient.patient.id }}</span>
                </div>
            </div>
        </el-card>
        <div class="medadmin">
            <div class="medbox">
                <span>结算流程相关注意事项</span>
            </div>
            <div class="bottombox">
                <div style="margin-bottom: 12px" v-for="item in arrite" :key="item">
                    <div class="bottombox_text"><span>1.显示标题</span></div>
                    <div class="bottombox_text2"><span>显示内容显示内容显示内容显示内容显示内容显示内容显示内容显示内容显示内容显示内容显示内容显示内容显示内容显示内容显示内容</span></div>
                </div>
            </div>
        </div>
        <div></div>
        <el-dialog title="标题" :visible.sync="sprice_show" width="660px" top="20vh !important" class="tanchaung">
            <div slot="title" class="dialog-title">
                <div style="display: flex">
                    <div>
                        <span>姓名：</span>
                        <span>{{ patientInfo.xm }}</span>
                    </div>
                    <div style="margin-left: 20px">
                        <span>号别：</span>
                        <span>{{ out_patient == null ? '' : out_patient.yyxmmc }}</span>
                    </div>
                </div>
            </div>

            <div class="tabin">
                <el-form ref="form" :model="form">
                    <div style="display: flex; justify-content: space-between">
                        <el-form-item label="用户ID" label-width="100px">
                            <el-input v-model="price_data.patient_id" readonly></el-input>
                        </el-form-item>
                        <el-form-item label="病人负担" label-width="100px">
                            <el-input v-model="price_data.brfdje" readonly></el-input>
                        </el-form-item>
                    </div>
                    <div style="display: flex; justify-content: space-between">
                        <el-form-item label="总金额" label-width="100px">
                            <el-input v-model="price_data.zje" readonly></el-input>
                        </el-form-item>
                        <el-form-item label="医保负担" label-width="100px">
                            <el-input v-model="price_data.ybfdje" readonly></el-input>
                        </el-form-item>
                    </div>
                    <div style="display: flex; justify-content: space-between">
                        <el-form-item label="个账支付" label-width="100px">
                            <el-input v-model="price_data.grzhzf" readonly></el-input>
                        </el-form-item>
                        <el-form-item label="医保账户支付" label-width="100px">
                            <el-input v-model="price_data.shortfall" readonly></el-input>
                        </el-form-item>
                    </div>
                    <div style="display: flex; justify-content: space-between">
                        <el-form-item label="就诊卡余额" label-width="100px">
                            <el-input v-model="price_data.balance" readonly></el-input>
                        </el-form-item>
                        <el-form-item label="其他医疗补助" label-width="100px">
                            <el-input v-model="price_data.other_expense" readonly></el-input>
                        </el-form-item>
                        <!-- <el-form-item label="应收合计" label-width="100px">
                            <el-input v-model="price_data" readonly></el-input>
                        </el-form-item> -->
                    </div>
                </el-form>
            </div>
            <span slot="footer" class="dialog-footer">
                <el-button @click="sprice_show = false">取 消</el-button>
                <el-button type="primary" @click="sure_ghf">确 定</el-button>
            </span>
        </el-dialog>
        <!-- <el-dialog title="选择就诊介质" :visible.sync="jiezhishow" width="489px" :close-on-click-modal="false">
            <img :src="logo" style="display: block; margin: -50px auto 0px" alt="logo" />
            <el-form :model="yibaoinfo" :inline="true" @submit.native.prevent v-loading="jiezhiLoading" element-loading-text="结算中...">
                <div style="text-align: center">
                    <el-input v-model="pingzhengma" type="text" placeholder="请输入患者卡号" @keyup.enter.native="cardjiesuan" ref="input" style="width: 300px"></el-input>
                </div>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="jiezhishow = false">取 消</el-button>
                <el-button type="primary" @click="cardjiesuan" :disabled="jiezhiLoading">确 定</el-button>
            </div>
        </el-dialog> -->
        <el-dialog title="选择卡类型" :visible.sync="yibaoshow" width="489px" :close-on-click-modal="false">
            <img :src="logo" style="display: block; margin: 0 auto; width: 420px" alt="logo" />
            <el-form :model="yibaoinfo" :inline="true" @submit.native.prevent>
                <div style="text-align: center; color: red"><span>地方医保患者请刷社会保障卡或电子医保凭证</span></div>
                <div style="text-align: center">
                    <el-form-item label="卡类型">
                        <el-radio-group v-model="yibaoinfo.cardtype" style="line-height: 37px">
                            <el-radio label="02">身份证</el-radio>
                            <el-radio label="03">社会保障卡</el-radio>
                            <!-- <el-radio label="04">山东省电子健康卡</el-radio> -->
                            <!-- <el-radio label="00">就诊卡</el-radio> -->
                            <el-radio label="01">电子医保凭证</el-radio>
                        </el-radio-group>
                    </el-form-item>
                </div>

                <div style="text-align: center">
                    <el-input
                        v-if="yibaoinfo.cardtype == '02'"
                        v-model="shenfenzheng"
                        type="text"
                        placeholder="请输入患者身份证"
                        @keyup.enter.native="getmzxx('1')"
                        ref="input"
                        style="width: 300px"
                    ></el-input>
                </div>
                <div style="text-align: center">
                    <el-input
                        v-if="yibaoinfo.cardtype == '01'"
                        v-model="adminpingzhengma"
                        type="text"
                        placeholder="请输入患者卡号"
                        @keyup.enter.native="queren"
                        ref="input"
                        style="width: 300px"
                    ></el-input>
                </div>
                <div style="text-align: center">
                    <el-input v-if="yibaoinfo.cardtype == '00'" v-model="jiuzhencard" type="text" placeholder="请输入患者卡号" @keyup.enter.native="queren" ref="input" style="width: 300px"></el-input>
                </div>
                <div style="text-align: center">
                    <el-input v-if="yibaoinfo.cardtype == '04'" v-model="sdsdzjkk" type="text" placeholder="请输入患者卡号" @keyup.enter.native="queren" ref="input" style="width: 300px"></el-input>
                </div>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="yibaoshow = false">取 消</el-button>
                <el-button type="primary" @click="queren">确 定</el-button>
            </div>
        </el-dialog>
        <el-dialog title="选择就诊介质" :visible.sync="jiezhishow" width="489px" :close-on-click-modal="false">
            <img :src="logo" style="display: block; margin: -50px auto 0px" alt="logo" />
            <el-form :model="yibaoinfo" :inline="true" @submit.native.prevent v-loading="jiezhiLoading" element-loading-text="结算中...">
                <div style="text-align: center">
                    <el-form-item label="介质类型">
                        <el-radio-group v-model="jiezhi">
                            <el-radio label="A">医保电子凭证</el-radio>
                            <el-radio label="B" v-if="miev != 1">社保卡</el-radio>
                        </el-radio-group>
                    </el-form-item>
                </div>
                <div style="text-align: center">
                    <el-input v-if="jiezhi == 'A'" v-model="pingzhengma" type="text" placeholder="请输入患者卡号" @keyup.enter.native="cardjiesuan" ref="input" style="width: 300px"></el-input>
                </div>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <!-- <el-button @click="jiezhishow = false">取 消</el-button> -->
                <el-button type="primary" @click="cardjiesuan" :disabled="jiezhiLoading">确 定</el-button>
            </div>
        </el-dialog>
        <Readcards :isOpenCarded="carddialogFormVisible" @getyibaoinfo="getyibaoinfo" @closeReadcard="closeReadcard" />

        <el-dialog width="50%" title="付款方式" :visible.sync="uploadfeeshow" :close-on-click-modal="false">
            <el-form :model="feelist" :inline="true" @submit.native.prevent>
                <div>
                    <div style="text-align: center">
                        <div>
                            <el-radio v-model="feelist.channel" label="1">微信付款</el-radio>
                            <el-radio v-model="feelist.channel" label="2">支付宝付款</el-radio>
                        </div>
                        <div style="text-align: center; margin-top: 10px">
                            <el-input
                                v-if="feelist.channel == '1'"
                                v-model="fee.weixin"
                                type="text"
                                placeholder="请刷微信付款码"
                                @keyup.enter.native="feesure(1)"
                                ref="inputWX"
                                style="width: 300px"
                            ></el-input>
                            <el-input
                                v-if="feelist.channel == '2'"
                                v-model="fee.zhifubao"
                                type="text"
                                placeholder="请刷支付宝付款码"
                                @keyup.enter.native="feesure(2)"
                                ref="inputZFB"
                                style="width: 300px"
                            ></el-input>
                        </div>
                    </div>
                </div>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="feesure(feelist.channel)">确 定</el-button>
            </div>
        </el-dialog>
    </div>
</template>
<script>
import Readcards from '@/components/Readcards'
import { mzxxs, jsxx, registration_pre, registration, hiscard, pdxx, mzxx } from '@/api/mz'
import { get_serial_number, editProp, zfbl, freemoney } from '@/api/jiesuan'
export default {
    components: {
        Readcards,
    },
    name: 'Outpatient',
    data() {
        return {
            jiezhi: 'A',
            jiezhishow: false,
            price_data: {},
            out_patient: {
                yyxmmc: '',
            },
            patientInfo: {
                channel: '',
            },
            adminpingzhengma: '',
            shenfenzheng: '',
            yibaoshow: false,
            patientform: '',
            sprice_show: false,
            arrite: [1, 2, 3, 4, 5, 6, 7, 8],
            man_name: '0',
            jiezhiLoading: false,
            resorderID: '',
            src: require('@/assets/images/1.png'),
            patientCard: {},
            pingzhengma: '',
            yibaoinfo: {
                sfzhm: '',
                idcard: '',
                cardtype: '02',
                cardno: '',
                channel: 'local',
            },
            tempsrc: require('@/assets/images/暂无记录.png'),
            logo: require('@/assets/logo/CardReader.gif'),
            carddialogFormVisible: false,
            tableData: {
                cost: [],
                costs: [],
                patient: { p_xm: '', id: '' },
            },
            type: '1',
            form: {
                brxm: '',
            },
            miev: '', // 1 卡介质仅有电子医保凭证 0 显示全介质
            uploadfeeshow: false, //充值显示
            feelist: {
                channel: '1', //
            },
            fee: {
                weixin: '',
                zhifubao: '',
            },
        }
    },
    mounted() {
        this.socketInit()
    },
    created() {
        this.getParam()
        if (!window.WebSocket) {
            alert('该版本浏览器不支持WebSocket')
        } else {
            console.log('支持websocket')
        }
    },
    methods: {
        //获取传参
        getParam() {
            this.out_patient = {}
            var urlParams = new URLSearchParams(window.location.search)
            var encodedObject = urlParams.get('a')
            var decodedObject = JSON.parse(decodeURIComponent(encodedObject))
            console.log(decodedObject, 'ppppppppppppppppppppp')
            this.out_patient = decodedObject
            console.log(this.out_patient)
        },
        //首次进页面第一次刷卡返回的信息
        getyibaoinfo(e, x) {
            console.log('=================--------------')
            //第一次读二维码不需要from_web
            if (x) {
                this.card_typeinfor = x
                let param = {
                    channel: 'local',
                    p_ewm: x.value,
                    p_dzpzywm: '301',
                    card_type: '01',
                }
                mzxxs(param)
                    .then(response => {
                        this.ybewmsfid = response.data.sfzhm
                        let xxx = {
                            card_no: response.data.sfzhm,
                            card_type: 'ID_CARD',
                        }
                        hiscard(xxx)
                            .then(response => {
                                this.carddialogFormVisible = false
                                this.dialogFormVisible = false
                                this.patientInfo = response.data
                                this.form.brxm = response.data.name
                                this.getpdxx(this.patientInfo)
                            })
                            .finally(() => {
                                this.carddialogFormVisible = false
                                this.dialogFormVisible = false
                                this.loading = false
                            })
                    })
                    .finally(res => {
                        this.carddialogFormVisible = false
                        this.dialogFormVisible = false
                    })
            } else {
                this.carddialogFormVisible = false
                this.getmzxxs(e)
            }
        },
        //首次获取患者基本信息
        getmzxxs(e) {
            this.card_typeinfor = e
            this.param = {
                name: e.xm,
                idcard: e.sfzhm,
                card_no: e.physicalCard,
                card_type: e.physicalCardType,
            }
            hiscard(this.param)
                .then(response => {
                    this.patientInfo = response.data
                    this.form.brxm = response.data.name
                    this.getpdxx(this.patientInfo)
                })
                .finally(() => {
                    this.loading = false
                })
        },
        getpdxx(e) {
            this.loading = true
            pdxx({
                id: e.med_id,
            })
                .then(response => {
                    this.tableData.patient.p_xm = response.data.name
                    this.tableData.patient.id = response.data.patientId
                    this.tableData.patient.idCard = response.data.idCard
                    this.patientCard = response.data
                    this.ybewmsfid = response.data.idCard
                    this.getWaiting()

                    // this.tableData = response.data
                })
                .finally(() => {
                    this.loading = false
                })
        },
        cardtype(type) {
            this.yibaoshow = true
            this.yibaoinfo.cardtype = type
            // this.carddialogFormVisible = true
        },
        //微信支付宝充值接口
        feesure(e) {
            var payment_type
            if (e == '1') {
                payment_type = 'WX_BAR'
            }
            if (e == '2') {
                payment_type = 'ALI_BAR'
            }
            this.$message({
                message: '充值成功',
                type: 'success',
            })
            this.uploadfeeshow = false
            this.price_data.shortfall = 0

            freemoney({
                payment_type: payment_type,
                amount: this.price_data.shortfall,
                auth_code: this.fee.weixin,
                his_patient_id: this.out_patient.patient.id,
                patient_type: 'mz',
                settlement_no: '1', //随便传
            })
                .then(response => {
                    this.$message({
                        message: response.message,
                        type: 'success',
                    })
                })
                .finally(() => {})
        },
        sure_ghf() {
            // price_data
            // this.jiezhishow = true
            // return false
            var that = this
            if (this.price_data.shortfall > 0) {
                // 弹窗提示 去补交金额
                this.$message('金额不足，请补交')
                setTimeout(function () {
                    that.uploadfeeshow = true
                }, 2000)
            } else {
                if (this.yibaoinfo.cardtype == '01') {
                    //01电子医保凭证
                    this.miev = 1
                    this.jiezhiLoading = false
                    this.jiezhishow = true
                } else {
                    if (this.price_data.grzhzf > 0 && this.out_patient.channel == 'local') {
                        this.miev = 0
                        this.jiezhiLoading = false
                        this.jiezhishow = true
                    } else {
                        var cache_uuid = this.patientInfo.cache_uuid
                        this.settleFun(cache_uuid)
                    }
                }
            }

            // if (this.out_patient.channel=='local' && this.price_data.shortfall == 0 && this.price_data.grzhzf>0) { //东营市本地并且待补交=0并且个账>0
            //     this.jiezhishow = true
            // } else if(this.price_data.shortfall>0){
            //     // 弹窗提示 去补交金额
            //     this.$message('金额不足，请补交');
            // } else{
            //     this.settleFun()
            // }
        },
        //预结算
        settlePre(cache_uuid) {
            let param = {
                patient_id: this.out_patient.patient_id,
                yyxmbm: this.out_patient.yyxmbm,
                yyxmmc: this.out_patient.yyxmmc,
                ksbm: this.out_patient.ksbm,
                zje: this.out_patient.zje,
                zfbl: this.out_patient.zfbl,
                name: this.patientInfo.xm,
                yb_cache_uuid: cache_uuid,
            }
            console.log(param)
            // return false
            registration_pre(param).then(response => {
                this.sprice_show = true
                // console.log(response)
                this.price_data = response.data
                console.log('66666666666666registration_pre')
                console.log(this.price_data)
            })
        },
        //结算
        settleFun(cache_uuid, t) {
            if (t) {
                var x = {
                    yyxmbm: this.out_patient.yyxmbm,
                    yyxmmc: this.out_patient.yyxmmc,
                    zje: this.out_patient.zje,
                    patient_id: this.out_patient.patient_id,
                    patient_name: this.patientInfo.xm,
                    pre_flag: this.price_data.pre_flag,
                    ksbm: this.out_patient.ksbm,
                    zfbl: this.out_patient.zfbl,
                    yb_cache_uuid: cache_uuid,
                    mis_data: {
                        trade_no: t.TradeRef,
                        order_no: this.resorderID,
                        bank_no: t.BankNo,
                        time: t.TradeDate,
                        amount: t.Amount,
                    },
                }
            } else {
                var x = {
                    yyxmbm: this.out_patient.yyxmbm,
                    yyxmmc: this.out_patient.yyxmmc,
                    zje: this.out_patient.zje,
                    patient_id: this.out_patient.patient_id,
                    patient_name: this.patientInfo.xm,
                    pre_flag: this.price_data.pre_flag,
                    ksbm: this.out_patient.ksbm,
                    zfbl: this.out_patient.zfbl,
                    yb_cache_uuid: cache_uuid,
                }
            }
            //测试注销
            // if (this.out_patient.notify_url) {
            //     x.notify_url = this.out_patient.notify_url //传值
            // }
            // return false
            registration(x)
                .then(response => {
                    this.jiezhiLoading = false
                    this.$message.success('结算成功')
                    this.dialogVisible = false
                    this.loadingapplyList = false
                    this.jiezhishow = false
                    this.sprice_show = false
                    setTimeout(function () {
                        window.close()
                    }, 3000)
                    // this.tuiconst = 0
                })
                .catch(() => {
                    if (this.resorderID != '') {
                        this.YBKerror(t)
                    }
                })
                .finally(() => {
                    this.jiezhiLoading = false
                    this.loadingapplyList = false
                    this.jiezhishow = false
                    this.dialogVisible = false
                    // this.tuiconst = 0
                })
        },
        YBKerror(e) {
            console.log(e, 'kooooooooooooooo')
            const _this = this
            let x =
                'Trans&15|00|' +
                e.Amount +
                '|' +
                e.BankNo +
                '|' +
                e.TradeRef +
                '||' +
                e.TradeDate +
                '|{"patientInfo":{"patientId":"' +
                _this.out_patient.patient_id +
                '","patientName":"' +
                _this.patientInfo.xm +
                '","cardNo":"' +
                _this.patientInfo.grbh +
                '","accountType":"01","visitId":"","ywlx":"SUCCESS","transType":"social","cardType":"01","source":"窗口门诊挂号费医保卡结算失败自动退费","operatorId":"' +
                localStorage.getItem('userbh') +
                '","operatorName":"' +
                localStorage.getItem('usernames') +
                '","orderId":"' +
                _this.resorderID +
                '","id_card_no":"' +
                _this.patientInfo.grbh +
                '"}}'
            var wsImpl = window.WebSocket || window.MozWebSocket
            _this.ws = new wsImpl('ws://127.0.0.1:50000/')
            _this.ws.onopen = function () {
                _this.ws.send(x)
            }
            _this.ws.onmessage = _this.YBKerrormessage
            _this.ws.onclose = function () {}
            this.uploadfeeshow = false
        },
        YBKerrormessage(evt) {
            this.adminloading = false
            //退款结果
            const ret = JSON.parse(evt.data)
            if (ret && ret.TrandeCode == '00') {
                this.$alert('自动退款成功！正常情况2-3天到账，提醒患者及时查看！', '', {
                    confirmButtonText: '确定',
                    callback: action => {
                        this.$message({
                            message: ret.TrandeMsg,
                            type: 'success',
                        })
                    },
                })
                return false
            } else {
                this.$message({
                    message: ret.TrandeMsg,
                    type: 'error',
                })
                //关闭弹窗

                return false
            }
        },
        // mis
        misfun() {
            get_serial_number({
                type: 'MIS',
            })
                .then(response => {
                    const _this = this
                    var input = _this.price_data.grzhzf * 1
                    let x =
                        'Trans&07|01|' +
                        +input +
                        '|||||{"patientInfo":{"patientId":"' +
                        _this.out_patient.patient_id +
                        '","patientName":"' +
                        _this.patientInfo.xm +
                        '","cardNo":"' +
                        _this.patientInfo.grbh +
                        '","accountType":"01","visitId":"","ywlx":"SUCCESS","transType":"social","cardType":"01","source":"窗口门诊医保卡消费","operatorId":"' +
                        localStorage.getItem('userbh') +
                        '","operatorName":"' +
                        localStorage.getItem('usernames') +
                        '","orderId":"' +
                        response.data.value +
                        '","id_card_no":"' +
                        _this.patientInfo.grbh +
                        '"}}'
                    this.resorderID = response.data.value

                    var wsImpl = window.WebSocket || window.MozWebSocket
                    _this.ws = new wsImpl('ws://127.0.0.1:50000/')
                    _this.ws.onopen = function () {
                        _this.ws.send(x)
                    }
                    _this.ws.onmessage = this.YBKsetOnmessageMessage
                    _this.ws.onclose = function () {}
                })
                .finally(() => {
                    this.uploadfeeshow = false
                    this.fullscreenLoading = false
                })
        },
        //读卡器方法
        socketInit() {
            this.wj = new WebSocket('ws://127.0.0.1:9000/')
            this.wj.onopen = function () {}
            this.wj.onmessage = this.onmessagecard
            this.wj.onclose = function () {}
        },
        //刷卡界面关闭
        closeReadcard() {
            this.carddialogFormVisible = false
        },
        //结算按钮预结算按钮
        queren() {
            this.jiezhiLoading = false
            if (this.yibaoinfo.cardtype == '02') {
                // TODO: 输入框
                // FIXME: 要修改的东西ASDASDAS
                //读身份证
                if (this.shenfenzheng != '') {
                    this.getmzxx('1')
                } else {
                    this.wj.send('{ "MethodName": "OpenDevice" }')
                    this.wj.send('{ "MethodName": "ReadIDCard"}')
                }
                //没卡就手写传卡号
            } else if (this.yibaoinfo.cardtype == '03') {
                //读医保卡
                this.wj.send('{ "MethodName": "OpenDevice" }')
                this.wj.send('{ "MethodName": "ReadSSSECard" }')
                // TODO:
                // FIXME: 要修改的东西ASDASDAS
                //电子医保凭证
            } else if (this.yibaoinfo.cardtype == '01') {
                this.getmzxx('3')
            } else if (this.yibaoinfo.cardtype == '00') {
                //就诊卡
                this.getmzxx('4')
            } else if (this.yibaoinfo.cardtype == '04') {
                //就健康卡
                this.getmzxx('5')
            }
            this.carddialogFormVisible = false
        },

        //刷卡回调方法
        onmessagecard(evt) {
            let res = JSON.parse(evt.data)
            // 赋值调接口
            if (res.MethodName == 'ReadIDCard' && res.RespCode == 0) {
                // 身份证读取
                this.yibaoinfo.cardno = res.RespData.CardId
                this.getmzxx('1')
                this.closedevice()
            } else if (res.MethodName == 'ReadSSSECard' && res.RespCode == 0) {
                // 社保卡读取
                if (this.yibaoinfo.channel == 'offsite') {
                    this.yibaoinfo.cardno = res.RespData.sfzh
                } else {
                    this.yibaoinfo.idcard = res.RespData.CardNo
                }
                this.yibaoinfo.xm = res.RespData.xm
                this.yibaoinfo.p_sbm = res.RespData.ksbm
                this.yibaoinfo.sfzhm = res.RespData.sfzh
                this.getmzxx('2')
                this.closedevice()
            } else {
                return false
            }
        },
        //刷卡后获取患者信息
        getmzxx(e) {
            if (e == '1' || e == '2') {
                if (e == '1') {
                    if (this.shenfenzheng != '') {
                        this.yibaoinfo.cardno = this.shenfenzheng
                    }
                    this.param = {
                        grbh: this.yibaoinfo.cardno,
                        p_xzbz: this.typelistno == '4' ? 'D' : 'C',
                        yltclb: '0',
                        channel: this.out_patient.channel,
                        card_type: this.yibaoinfo.cardtype,
                        from_web: '1',
                    }
                    mzxx(this.param)
                        .then(response => {
                            this.yibaoshow = false
                            this.patientInfo = response.data
                            this.form.sfzh = response.data.grbh
                            this.form.dwmc = response.data.cbjgmc
                            this.form.ybkh = response.data.ybbh
                            this.form.brxm = response.data.xm
                            this.form.brxb = response.data.xb == '2' ? '女' : '男'

                            var cache_uuid = this.patientInfo.cache_uuid
                            this.settlePre(cache_uuid)
                        })
                        .catch(e => {
                            this.loading = false
                        })
                }
                if (e == '2' && this.yibaoinfo.channel == 'offsite') {
                    // if (this.shenfenzheng != '') {
                    //     this.yibaoinfo.cardno = this.yibaoka
                    // }
                    this.param = {
                        grbh: this.yibaoinfo.cardno,
                        p_xzbz: this.typelistno == '4' ? 'D' : 'C',
                        yltclb: '0',
                        channel: this.patientInfo.channel,
                        card_type: '02',
                        from_web: '1',
                    }
                    mzxx(this.param)
                        .then(response => {
                            this.yibaoshow = false
                            this.patientInfo = response.data
                            this.form.sfzh = response.data.grbh
                            this.form.dwmc = response.data.cbjgmc
                            this.form.ybkh = response.data.ybbh
                            this.form.brxm = response.data.xm
                            this.form.brxb = response.data.xb == '2' ? '女' : '男'

                            var cache_uuid = this.patientInfo.cache_uuid
                            this.settlePre(cache_uuid)
                        })
                        .catch(e => {
                            this.loading = false
                        })
                }
            }
            if (e == '2' || e == '3') {
                //不是跨省异地的身份证
                if (e == '2' && this.yibaoinfo.channel != 'offsite') {
                    // if (this.shenfenzheng != '') {
                    //     this.yibaoinfo.idcard = this.yibaoka
                    // }
                    this.param = {
                        p_xm: this.yibaoinfo.xm,
                        p_sbm: this.yibaoinfo.p_sbm,
                        p_gfbb: '03',
                        p_shbzhm: this.yibaoinfo.sfzhm,
                        p_kh: this.yibaoinfo.idcard,
                        channel: this.out_patient.channel,
                        p_dzpzywm: '301',
                        card_type: this.yibaoinfo.cardtype,
                        from_web: '1',
                    }
                }
                //第二次读医保二维码
                if (e == '3') {
                    this.param = {
                        p_ewm: this.adminpingzhengma,
                        p_dzpzywm: '301',
                        channel: this.out_patient.channel,
                        card_type: '01',
                        from_web: '1',
                    }
                }
                mzxxs(this.param)
                    .then(response => {
                        this.yibaoshow = false
                        this.patientInfo = response.data
                        this.form.sfzh = response.data.grbh
                        this.form.dwmc = response.data.cbjgmc
                        this.form.ybkh = response.data.ybbh
                        this.form.brxm = response.data.xm
                        this.form.brxb = response.data.xb == '2' ? '女' : '男'

                        var cache_uuid = this.patientInfo.cache_uuid
                        this.settlePre(cache_uuid)
                    })
                    .catch(e => {
                        this.loading = false
                    })
            }
            if (e == '4' || e == '5') {
                //就诊卡
                if (e == '4') {
                    this.param = {
                        card_no: this.jiuzhencard,
                        card_type: 'HOSPITAL_CARD',
                    }
                }
                //电子健康卡
                if (e == '5') {
                    this.param = {
                        card_no: this.jiuzhencard.toString().substring(0, 64),
                        card_type: 'ELECTRONIC_HEALTH_CARD',
                    }
                }

                hiscard(this.param)
                    .then(response => {
                        this.param = {
                            grbh: response.data.idCard,
                            p_xzbz: this.typelistno == '4' ? 'D' : 'C',
                            yltclb: '0',
                            channel: this.patientInfo.channel,
                            card_type: this.yibaoinfo.cardtype,
                            from_web: '1',
                        }
                        mzxx(this.param)
                            .then(response => {
                                this.yibaoshow = false
                                this.patientInfo = response.data
                                this.form.sfzh = response.data.grbh
                                this.form.brxm = response.data.xm
                                this.form.brxb = response.data.xb == '2' ? '女' : '男'
                                this.form.dwmc = response.data.cbjgmc
                                this.form.ybkh = response.data.ybbh
                                // this.jiesuanadmin(this.patientInfo.cache_uuid)
                                var cache_uuid = this.patientInfo.cache_uuid
                                this.settlePre(cache_uuid)
                            })
                            .finally(() => {
                                this.loading = false
                            })
                    })
                    .finally(() => {
                        this.loading = false
                    })
            }
        },
        //电子医保凭证方法
        cardjiesuan() {
            this.jiezhiLoading = true
            var that = this
            console.log(this.jiezhi)
            //第三次刷电子医保凭证,通过电子医保凭证获取cache_uuid,走结算
            if (this.jiezhi == 'A') {
                let param = {
                    p_ewm: this.pingzhengma,
                    card_type: '01',
                    channel: this.out_patient.channel,
                    from_web: '1',
                }
                mzxxs(param)
                    .then(response => {
                        var cache_uuid = response.data.cache_uuid
                        this.settleFun(cache_uuid)
                    })
                    .catch(e => {
                        this.jiezhiLoading = false
                        this.loading = false
                    })
            } else if (this.jiezhi == 'B') {
                // setTimeout(function () {
                //     that.jiezhiLoading = false
                // }, 5000)
                this.misfun()
            }
        },
        //医保卡返回方法
        YBKsetOnmessageMessage(evt) {
            const ret = JSON.parse(evt.data)
            if (ret && ret.TrandeCode == '00') {
                this.$message({
                    message: ret.TrandeMsg,
                    type: 'success',
                })
                this.ckh = ret.TradeRef
                this.misdataYB = ret
                console.log(this.patientInfo, ret, '1111111111111111')
                this.settleFun(this.patientInfo.cache_uuid, ret)
                this.fullscreenLoading = false
            } else {
                this.$message({
                    message: ret.TrandeMsg,
                    type: 'error',
                })
                this.fullscreenLoading = false
            }
            this.jiezhiLoading = false
            this.jiezhishow = false
            this.sprice_show = false
        },

        // 关闭设备
        closedevice() {
            this.wj.send('{ "MethodName": "CloseDevice" }')
        },

        round(num, decimals) {
            const factor = Math.pow(10, decimals)
            return Math.round(num * factor) / factor
        },
    },
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.tanchaung {
    ::v-deep .el-dialog__body {
        padding: 12px !important;
        background: #f2f2f2;
        border-radius: 0px 0px 0px 0px;
        opacity: 1;
    }
}
.bottombox_text2 {
    font-size: 14px;
    font-family: PingFang SC-Regular, PingFang SC;
    font-weight: 400;
    color: #333333;
    margin-top: 10px;
}
.bottombox_text {
    font-size: 16px;
    font-family: PingFang SC-Semibold, PingFang SC;
    font-weight: 600;
    color: #333333;
}
.bottombox {
    background-color: white;
    padding: 10px;
    height: calc(100vh - 213px);
    overflow-y: auto;
    border-radius: 0px 0px 0px 0px;
    opacity: 1;
}
.medadmin {
    padding: 5px;
}
.tabin {
    padding: 12px;
    background: #ffffff;
    border-radius: 3px 3px 3px 3px;
    opacity: 1;
    ::v-deep.el-form-item {
        margin-bottom: 5px;
    }
}
.medbox {
    font-size: 18px;
    font-family: PingFang SC-Semibold, PingFang SC;
    font-weight: 600;
    color: #333333;
    padding: 12px;
    height: 49px;
    background: #e3f2ff;
    border-radius: 0px 0px 0px 0px;
    opacity: 1;
    border: 1px solid #e0e0e0;
}

::v-deep .el-dialog__body {
    padding: 0px 20px !important;
}

.selectinput {
    ::v-deep.el-input--medium .el-input__inner {
        height: 30px;
        margin-top: 5px;
        line-height: 30px;
        width: 150px;
    }
}
.tablast {
    padding: 12px;
    height: 202px;
    background: #f2f2f2;
    border-radius: 0px 0px 0px 0px;
    opacity: 1;
}
.boxmain {
    display: flex;
    justify-content: flex-start;
}
.app-container {
    background: #f3f3f3;
}

.maxbox {
    background-color: white;
    padding: 12px;
}

.jstitle {
    display: flex;
    justify-content: space-between;
    height: 30px;
}
.jstitle ::v-deep .el-form-item {
    border: 1px #bdbdbd solid;
}
</style>
