<template>
    <view>
        <!-- pages/diagnosticEntry/prescription/prescription.wxml -->

        <view class="diagnostic-wrapper">
            <van-toast id="van-toast" />
            <van-dialog id="van-dialog" />
            <view class="topTitle">
                <view class="topTitle__amount">
                    <text class="topTitle__label">共计：</text>
                    <text class="money">¥{{ totalAmount }}</text>
                    <text class="topTitle__sub">西药 <text class="money">¥{{ wesMedAmount }}</text></text>
                    <text class="topTitle__sub">草药 <text class="money">¥{{ herbsAmount }}</text></text>
                </view>
                <button v-if="patientData.changeDataFlag != 'N'" class="addtext" @tap="addChange">
                    + 添加医嘱
                </button>
            </view>
            <view class="vTabs">
                <van-tabs :active="active" @change="onChange" color="#1687ff" title-active-color="#1687ff">
                    <van-tab :title="'西药（' + (wnum + wList.length) + '）'">
                        <view class="row">
                            <view class="col clearn">
                                <view class="col-12">
                                    <view class="divider" v-if="wList.length !== 0">
                                        <view class="divider-text">待确认</view>
                                    </view>
                                    <view class="box" v-for="(item, index) in wList" :key="index">
                                        <view class="boxTitle">
                                            <view class="boxTitle__main">
                                                <van-tag round type="warning" class="mr20">{{ item.selectIndex1.descripts }}</van-tag>
                                                <text>序号 {{ item.xh }}</text>
                                                <text v-if="!(!item.selectIndex9.xh || item.selectIndex9.xh === '')">(关联序号{{ item.selectIndex9.xh }})</text>
                                            </view>
                                            <text class="status-tag status-tag--pending">未确认</text>
                                        </view>

                                        <view class="boxcontent">
                                            <view>
                                                <text style="font-weight: bold">{{ item.searchSelect.medDesc }}</text>
                                                <text class="boxTime ml20">{{ item.guge }}</text>
                                                <text class="floatR money">¥ {{ m1.numberToFix(item.searchSelect.medPrice * item.stepper2) }}</text>
                                            </view>
                                            <view class="boxTime">
                                                <text class="boxTime mr20">
                                                    {{ item.dose != '' ? '每次' : '' }}{{ item.dose }}{{ item.selectIndex4.doseUnitDesc }} {{ item.dose != '' ? ',' : '' }}
                                                    {{ item.selectIndex2.descripts }} {{ item.selectIndex2.descripts != '' ? ',' : '' }} {{ item.selectIndex3.descripts }}
                                                    {{ item.selectIndex3.descripts != '' ? ',' : '' }} {{ item.stepper }}{{ item.ordDurationDesc }}
                                                    {{ item.ordDurationDesc != '' ? ',' : '' }} 共{{ item.stepper2 }}{{ item.selectIndex5.unitDesc }}
                                                </text>
                                                <view
                                                    class="redIcon"
                                                    v-if="
                                                        !(
                                                            item.selectIndex2.descripts &&
                                                            item.selectIndex2.descripts != '' &&
                                                            item.selectIndex3.descripts &&
                                                            item.selectIndex3.descripts != ''
                                                        )
                                                    "
                                                >
                                                    <van-icon name="warning" color="red" />
                                                </view>
                                            </view>
                                        </view>
                                        <view class="boxBtm">
                                            <button class="remove" @tap="tapRemove" :data-index="index">删除</button>
                                            <!-- <button class="btn">药品说明书</button> -->
                                            <button class="edit btn" @tap="tapEdit" :data-index="index">编辑</button>
                                        </view>
                                    </view>
                                    <view class="divider" v-if="wListDefault.length !== 0">
                                        <view class="divider-text">已确认</view>
                                    </view>
                                    <view v-for="(item, index) in wListDefault" :key="index">
                                        <view class="box boxBorder">
                                            <view class="boxTitle">
                                                <text class="boxTitle__main">处方号 {{ item.prescNo }} | {{ item.reason }}</text>
                                                <text class="status-tag status-tag--done">{{ item.prescState }}</text>
                                            </view>
                                            <view class="medData" v-for="(cell, index1) in item.medData" :key="index1">
                                                <view v-if="(cell.diagnoseStr || cell.diagnoseCode)">
                                                    诊断：{{ cell.diagnoseStr }} {{ cell.diagnoseCode ? '(' + cell.diagnoseCode + ')' : '' }}
                                                </view>
                                                <view class="boxcontent">
                                                    <view>
                                                        <text style="font-weight: bold">{{ cell.medItem }}</text>
                                                        <text class="ml20">{{ cell.spec }}</text>
                                                        <text class="floatR money">¥ {{ cell.medPrice }}</text>
                                                    </view>
                                                </view>

                                                <view>
                                                    <view class="boxTime">
                                                        <text class="mr20">
                                                            {{ cell.doseUnit != '' ? '每次' : '' }}{{ !cell.doseUnit ? '' : cell.dose }}{{ cell.doseUnit }} {{ cell.doseUnit != '' ? ',' : '' }}
                                                            {{ cell.frequence }} {{ cell.frequence != '' ? ',' : '' }} {{ cell.usage }} {{ cell.usage != '' ? ',' : '' }}
                                                            {{ cell.durQty }}{{ cell.duration }} {{ cell.duration != '' ? ',' : '' }} 共{{ cell.qty }}{{ cell.qtyUom }}
                                                        </text>
                                                    </view>
                                                </view>

                                                <view class="boxBtm" >
                                                    <button
                                                        v-if="cell.medID != '122165' && patientData.changeDataFlag != 'N' && canDeleteDefault(item)"
                                                        class="remove"
                                                        :data-index="index"
                                                        :data-item="item"
                                                        :data-cell="cell"
                                                        @tap="tapRemoveDefau1"
                                                    >
                                                        删除
                                                    </button>
                                                    <!-- <button class="btn">药品说明书</button> -->
                                                    <button class="btn" @tap="tapDetail" :data-item="item" :data-cell="cell">查看详情</button>
                                                </view>
                                            </view>
                                            <view class="boxTime" v-if="item.medData.length !== 1">用法：{{ item.medData[0].frequence }};{{ item.medData[0].usage }}</view>
                                        </view>
                                    </view>
                                </view>
                            </view>
                        </view>
                        <view class="empty" v-if="active === 0 && wnum + wList.length == 0">
                            <cover-image class="empty__img" :src="imgDomain + '/images/icon/doctor/none.png'"></cover-image>
                            <view class="empty__text">暂无医嘱</view>
                        </view>
                    </van-tab>
                    <van-tab :title="'草药（' + (gnum + gList.length) + '）'">
                        <view class="row">
                            <view class="col clearn">
                                <view class="col-12">
                                    <view class="divider" v-if="gList.length !== 0">
                                        <view class="divider-text">待确认</view>
                                    </view>
                                    <view class="box" v-for="(item, index) in gList" :key="index">
                                        <view class="boxTitle">
                                            <text class="boxTitle__main">序号 {{ item.xh }} | {{ item.selectData1.descripts }}</text>
                                            <text class="status-tag status-tag--pending">未确认</text>
                                        </view>

                                        <view v-for="(cell, index1) in item.gList" :key="index1">
                                            <view class="editText">
                                                <van-tag
                                                    class="mr20"
                                                    :color="
                                                        cell.comPrinciple.descripts === '君'
                                                            ? '#FFA33C'
                                                            : cell.comPrinciple.descripts === '臣'
                                                            ? '#36D2D2'
                                                            : cell.comPrinciple.descripts === '佐'
                                                            ? '#FA5AB4'
                                                            : '#AB72F9'
                                                    "
                                                >
                                                    {{ cell.comPrinciple.descripts }}药
                                                </van-tag>
                                                <text>{{ cell.searchSelect.medDesc }}</text>
                                                <text class="nodata">【{{ cell.jl }}{{ cell.typeList.unitDesc }}】</text>
                                                <text class="nodata" v-if="!(cell.decoctMethod.descripts == '' || !cell.decoctMethod.descripts)">
                                                    【{{ cell.decoctMethod.descripts }}】
                                                </text>
                                                <view class="floatR">
                                                    <view class="boxBtm editT">
                                                        <text class="nodata">¥ {{ cell.searchSelect.medPrice * cell.jl }}</text>
                                                    </view>
                                                </view>
                                            </view>
                                        </view>

                                        <view class="textRight fontS25 mt20">
                                            <text class="nodata">¥ {{ money }} X {{ item.stepper }} 付;</text>
                                            <text>总金额：¥ {{ sumMoney }}</text>
                                        </view>

                                        <view>
                                            <text class="nodata fontS25">
                                                用法：{{ item.stepper }}付;{{ item.herbalForm.descripts }};{{ item.frequence.descripts }};每次{{ item.sum }}ml;{{
                                                    item.usage.descripts
                                                }};{{ item.cookType.descripts }};{{ item.usageExplain.descripts }}
                                            </text>
                                        </view>

                                        <view class="boxBtm">
                                            <button class="remove" @tap="tapRemove2" :data-index="index">删除</button>
                                            <button class="btn edit" @tap="tapEdit" :data-index="index">编辑</button>
                                        </view>
                                    </view>
                                    <view class="divider" v-if="gListDefault.length !== 0">
                                        <view class="divider-text">已确认</view>
                                    </view>
                                    <view v-for="(item, index) in gListDefault" :key="index">
                                        <view class="box">
                                            <view class="boxTitle">
                                                <text class="boxTitle__main">处方号 {{ item.prescNo }} | {{ item.reason }}</text>
                                                <text class="status-tag status-tag--done">{{ item.prescState }}</text>
                                            </view>
                                          
                                            <view v-for="(cell, index1) in item.medData" :key="index1">
                                                <view v-if="index1 == 0 && (cell.diagnoseStr || cell.diagnoseCode)">
                                                    诊断：{{ cell.diagnoseStr }} {{ cell.diagnoseCode ? '(' + cell.diagnoseCode + ')' : '' }}
                                                </view>
                                                <view class="editText">
                                                    <van-tag
                                                        class="mr20"
                                                        :color="
                                                            cell.comPrinciple === '君'
                                                                ? '#FFA33C'
                                                                : cell.comPrinciple === '臣'
                                                                ? '#36D2D2'
                                                                : cell.comPrinciple === '佐'
                                                                ? '#FA5AB4'
                                                                : '#AB72F9'
                                                        "
                                                    >
                                                        {{ cell.comPrinciple }}药
                                                    </van-tag>
                                                    <text>{{ cell.medItem }}</text>
                                                    <text class="nodata">【{{ cell.eachPair }}{{ cell.doseUnit }}】</text>
                                                    <text class="nodata" v-if="!(cell.decoctMethod == '' || !cell.decoctMethod)">【{{ cell.decoctMethod }}】</text>
                                                    <view class="floatR">
                                                        <view class="boxBtm editT">
                                                            <text class="nodata">¥ {{ cell.medPrice }}</text>
                                                            <view class="editBtn" @tap="tapDetail" :data-item="item" :data-cell="cell">查看详情</view>
                                                        </view>
                                                    </view>
                                                </view>
                                            </view>
                                            <view class="textRight fontS25 mt20">
                                                <text class="nodata">¥ {{ item.unitPrice }} X {{ item.medData[0].durQty }} 付;</text>
                                                <text>总金额：¥ {{ item.prescPrice }}</text>
                                            </view>
                                            <view>
                                                <text class="nodata fontS25">
                                                    用法：{{ item.medData[0].durQty }}付;{{ item.medData[0].herbalForm }};{{ item.medData[0].freqDesc }};每次{{
                                                        item.medData[0].dose
                                                    }}ml;{{ item.medData[0].usage }};{{ item.medData[0].cookType }};{{ item.medData[0].usageExplain }}
                                                </text>
                                            </view>
                                            <view class="boxBtm">
                                                <button v-if="patientData.changeDataFlag != 'N' && canDeleteDefault(item)" class="remove" :data-index="index" :data-item="item" @tap="tapRemoveDefau2">
                                                    删除
                                                </button>
                                            </view>
                                        </view>
                                    </view>
                                </view>
                            </view>
                        </view>
                        <view class="empty" v-if="active === 1 && gnum + gList.length == 0">
                            <cover-image class="empty__img" :src="imgDomain + '/images/icon/doctor/none.png'"></cover-image>
                            <view class="empty__text">暂无医嘱</view>
                        </view>
                    </van-tab>

                    <van-tab :title="'检查（' + (jnum + jList.length) + '）'">
                        <view class="row">
                            <view class="col clearn">
                                <view class="col-12">
                                    <view class="divider" v-if="jList.length !== 0">
                                        <view class="divider-text">待确认</view>
                                    </view>
                                    <view class="box" v-for="(item, index) in jList" :key="index">
                                        <view class="boxTitle">
                                            <text class="boxTitle__main">序号 {{ index + 1 }} | {{ item.admReasonList[item.admReasonIndex].descripts }}</text>
                                            <text class="status-tag status-tag--pending">未确认</text>
                                        </view>

                                        <view class="boxcontent jc-flex">
                                            <view class="jc-left">
                                                <label style="margin-right: 10rpx">{{ item.ordDesc }}</label>
                                                <label v-for="(partCheckedItem, bodyIndex) in item.partCheckedList" :key="bodyIndex">
                                                    {{ partCheckedItem.descripts }} {{ partCheckedItem.descriptsSelectStr }}
                                                </label>
                                            </view>
                                            <view class="money jc-right">¥ {{ item.ordersObJ.ordPrice }}</view>
                                        </view>

                                        <view>
                                            <view class="boxTime">
                                                <text class="boxTime mr20">检查目的：{{ item.templateValue }}</text>
                                            </view>
                                        </view>

                                        <view class="boxBtm">
                                            <button class="remove" @tap="tapRemove3" :data-index="index">删除</button>
                                            <button class="edit btn" @tap="tapEdit" :data-index="index">编辑</button>
                                        </view>
                                    </view>
                                    <view class="divider" v-if="jListDefault.length !== 0">
                                        <view class="divider-text">已确认</view>
                                    </view>
                                    <view v-for="(item, index) in jListDefault" :key="index">
                                        <view class="box boxBorder">
                                            <view class="boxTitle">
                                                <text class="boxTitle__main">检查号 {{ item.prescNo }} | {{ item.reason }}</text>
                                                <text class="status-tag status-tag--done">{{ item.prescState }}</text>
                                            </view>
                                            <view class="medData" v-for="(cell, index1) in item.medData" :key="index1">
                                                <view v-if="(cell.diagnoseStr || cell.diagnoseCode)">
                                                    诊断：{{ cell.diagnoseStr }} {{ cell.diagnoseCode ? '(' + cell.diagnoseCode + ')' : '' }}
                                                </view>
                                                <view class="boxcontent">
                                                    <view>
                                                        <text style="font-weight: bold">
                                                            {{ cell.medItem }}
                                                        </text>
                                                        <text class="ml20">{{ cell.spec }}</text>
                                                        <text class="floatR money">×{{ cell.qty || '' }}{{ cell.qtyUom || '' }} ¥ {{ cell.medPrice }}</text>
                                                    </view>
                                                </view>

                                                <view>
                                                    <view class="boxTime">
                                                        <text class="mr20">检查目的：{{ cell.appPurpose }}</text>
                                                    </view>
                                                </view>

                                                <view class="boxBtm">
                                                    <button
                                                        v-if="patientData.changeDataFlag != 'N' && canDeleteDefault(item)"
                                                        class="remove"
                                                        :data-index="index"
                                                        :data-item="item"
                                                        :data-cell="cell"
                                                        @tap="tapRemoveDefau1"
                                                    >
                                                        删除
                                                    </button>
                                                    <button class="btn" @tap="tapDetail" :data-item="item" :data-cell="cell">查看详情</button>
                                                </view>
                                            </view>
                                            <!-- <view class="boxTime" hidden="{{item.medData.length===1}}">用法：{{item.medData[0].frequence}};{{item.medData[0].usage}}</view> -->
                                        </view>
                                    </view>
                                </view>
                            </view>
                        </view>
                        <view class="empty" v-if="active === 2 && jnum + jList.length == 0">
                            <cover-image class="empty__img" :src="imgDomain + '/images/icon/doctor/none.png'"></cover-image>
                            <view class="empty__text">暂无医嘱</view>
                        </view>
                    </van-tab>

                    <van-tab :title="'检验（' + (ynum + yList.length) + '）'">
                        <view class="row">
                            <view class="col clearn">
                                <view class="col-12">
                                    <view class="divider" v-if="yList.length !== 0">
                                        <view class="divider-text">待确认</view>
                                    </view>
                                    <view class="box" v-for="(item, index) in yList" :key="index">
                                        <view class="boxTitle">
                                            <text class="boxTitle__main">序号 {{ index + 1 }} | {{ item.admReasonList[item.admReasonIndex].descripts }}</text>
                                            <text class="status-tag status-tag--pending">未确认</text>
                                        </view>

                                        <view class="boxcontent">
                                            <view>
                                                <text style="font-weight: bold">{{ item.ordDesc }}</text>
                                                <text class="floatR money">¥ {{ item.ordersObJ.ordPrice }}</text>
                                            </view>
                                        </view>

                                        <view class="boxBtm">
                                            <button class="remove" @tap="tapRemove4" :data-index="index">删除</button>
                                            <button class="edit btn" @tap="tapEdit" :data-index="index">编辑</button>
                                        </view>
                                    </view>
                                    <view class="divider" v-if="yListDefault.length !== 0">
                                        <view class="divider-text">已确认</view>
                                    </view>
                                    <view v-for="(item, index) in yListDefault" :key="index">
                                        <view class="box boxBorder">
                                            <view class="boxTitle">
                                                <text class="boxTitle__main">检查号 {{ item.prescNo }} | {{ item.reason }}</text>
                                                <text class="status-tag status-tag--done">{{ item.prescState }}</text>
                                            </view>
                                            <view class="medData" v-for="(cell, index1) in item.medData" :key="index1">
                                                <view v-if="(cell.diagnoseStr || cell.diagnoseCode)">
                                                    诊断：{{ cell.diagnoseStr }} {{ cell.diagnoseCode ? '(' + cell.diagnoseCode + ')' : '' }}
                                                </view>
                                                <view class="boxcontent">
                                                    <view>
                                                        <text style="font-weight: bold">{{ cell.medItem }}</text>
                                                        <text class="ml20">{{ cell.spec }}</text>
                                                        <text class="floatR money">×{{ cell.qty || '' }}{{ cell.qtyUom || '' }} ¥ {{ cell.medPrice }}</text>
                                                    </view>
                                                </view>

                                                <view class="boxBtm">
                                                    <button
                                                        v-if="patientData.changeDataFlag != 'N' && canDeleteDefault(item)"
                                                        class="remove"
                                                        :data-index="index"
                                                        :data-item="item"
                                                        :data-cell="cell"
                                                        @tap="tapRemoveDefau1"
                                                    >
                                                        删除
                                                    </button>
                                                    <button class="btn" @tap="tapDetail" :data-item="item" :data-cell="cell">查看详情</button>
                                                </view>
                                            </view>
                                        </view>
                                    </view>
                                </view>
                            </view>
                        </view>
                        <view class="empty" v-if="active === 3 && ynum + yList.length == 0">
                            <cover-image class="empty__img" :src="imgDomain + '/images/icon/doctor/none.png'"></cover-image>
                            <view class="empty__text">暂无医嘱</view>
                        </view>
                    </van-tab>
                </van-tabs>
            </view>
            <view style="width: 100%; height: 120rpx;"></view>
        </view>
        <button :disabled="saveLoaing" class="diagnostibutton" @tap="sureChange" v-if="!(wList.length === 0 && gList.length === 0 && jList.length === 0 && yList.length === 0)">确认医嘱</button>
    </view>
</template>
<script module="m1" lang="wxs">
var numberToFix = function(value) {
	return value.toFixed(2)
}
module.exports = {
	numberToFix: numberToFix
}
</script>
<script>
// pages/diagnosticEntry/prescription/prescription.js
import { $http } from '../../../../../config/https';
import { httpconfig } from '../../../../../config/httpconfig';
import Util from '../../../../../utils/util.js';
import commonUtil from '../../../../../utils/common.js';
import Toast from '../../../../../utils/toast';
import Dialog from '../../../../../utils/dialog';
import Cache from '../../../../../utils/cache.js';
import messageUtil from '../../../../../utils/message.js';
export default {
    data() {
        return {
            saveLoaing: false,
            imgDomain: httpconfig.imgDomain,
            wnum: 0,

            // 西药数量
            gnum: 0,

            // 草药数量
            jnum: 0,

            //检查数量
            ynum: 0,

            //检验数据
            active: 0,

            // tab切换
            wList: [],

            // 西药数据
            wListDefault: [],

            // 西药已查询出来的数据数据
            gList: [],

            // 草药数据
            gListDefault: [],

            //草药数据已查询出来的数据数据
            jList: [],

            //检查数据
            jListDefault: [],

            // 检查已查询出来的数据数据
            yList: [],

            //检验数据
            yListDefault: [],

            // 检验已查询出来的数据数据
            wesMedAmount: '0',

            //  西药金额
            herbsAmount: '0',

            //  草药金额
            totalAmount: '0',

            //  总金额
            sumMoney: '0',

            //  总金额
            money: '0',

            //  单价总金额
            patientData: {
                changeDataFlag: ''
            },

            sendMessageFlag: 'Y',
            oldTemporary: false,

            // 是否存在主诊断（无主诊断时禁用"添加医嘱"按钮）
            hasMainDiag: false,

            cell: {
                medItem: '',
                spec: '',
                medPrice: '',
                doseUnit: '',
                dose: '',
                frequence: '',
                usage: '',
                durQty: '',
                duration: '',
                qty: '',
                qtyUom: '',

                comPrinciple: {
                    descripts: ''
                },

                searchSelect: {
                    medDesc: '',
                    medPrice: 0
                },

                jl: '',

                typeList: {
                    unitDesc: ''
                },

                decoctMethod: {
                    descripts: ''
                },

                eachPair: '',
                appPurpose: ''
            },

            bodyIndex: 0,

            partCheckedItem: {
                descripts: '',
                descriptsSelectStr: ''
            },

            callDataClone: {},
            callData2Clone: {}
        };
    },
    /**
     * 可以使用全局样式
     */
    options: {
        addGlobalClass: true
    },
    /**
     * 组件的属性列表
     */
    props: {
        callData: {
            type: Object,
            //类型
            default: () => ({}) //默认值
        },

        callData2: {
            type: Object,
            //类型
            default: () => ({}) //默认值
        }
    },
    destroyed: function () {
        // 在组件实例被从页面节点树移除时执行
        this.addTemporary(); // 保存临时数据
    },
    mounted() {
        // 处理小程序 attached 生命周期
        this.attached();
        // 处理小程序 ready 生命周期
        this.$nextTick(() => this.ready());
    },
    /**
     * 组件的方法列表
     */
    methods: {
        ready: function (options) {
            // 在组件在视图层布局完成后执行
            this.arrList(0); // 查询数据
            this.temporaryWList(); // 查询临时数据 西药
            this.temporaryGList(); // 查询临时数据 草药
            this.temporaryJList('JC').then((data) => {
                this.setData({
                    jList: data
                });
            }); // 查询临时数据 检查
            this.temporaryJList('JY').then((data) => {
                this.setData({
                    yList: data
                });
            }); // 查询临时数据 检验
            this.queryMainDiag(); // 查询是否存在主诊断
            let that = this;
            commonUtil.canChangeFlag('', (res) => {
                that.setData({
                    patientData: Cache.get('patientData')
                });
            });
            this.getToPatientMessageFlag();
        },

        // 查询诊断列表，判断是否存在主诊断（mainDiagID == 'Y'）
        queryMainDiag: function () {
            let patientData = Cache.get('patientData');
            if (!patientData) {
                return;
            }
            let { admID, patID } = patientData;
            $http.post('urlDeault', this, {
                code: '03050033',
                data: {
                    params: [
                        {
                            admID: admID || '',
                            patID: patID || '',
                            historyFlag: 'N',
                            historyType: 'O',
                            syFlag: 'Y'
                        }
                    ]
                },
                success: function (res) {
                    let errorCode = res.errorCode;
                    if (errorCode === '0') {
                        let diagList = (res.result && res.result.diagList) || [];
                        let hasMainDiag = diagList.some((item) => item.mainDiagID == 'Y');
                        this.setData({
                            hasMainDiag: hasMainDiag
                        });
                    }
                }
            });
        },

        // 已确认项目是否允许删除：
        // 药品处方（prescNo 以 OPN 开头）显示待支付、已支付或审核通过后不可删除；
        // 非药品处方已支付后不可删除。
        canDeleteDefault: function (item) {
            if (!item) {
                return true;
            }
            const prescNo = String(item.prescNo || '').trim();
            const prescState = String(item.prescState || '').trim();
            const isMedicinePrescription = prescNo.startsWith('OPN');

            return isMedicinePrescription ? !['处方审核通过', '待支付', '已支付'].includes(prescState) : prescState !== '已支付';
        },

        attached: function () {},

        handlePageShow() {
            let { callDataClone: callData, callData2Clone: callData2 } = this;
            this.setData({
                oldTemporary: false
            });
            // 刷新主诊断状态（用户可能在诊断tab增删了诊断）
            this.queryMainDiag();
            // 检验检查直接提交后端后，刷新已确认数据
            try {
                if (Cache.get('inspectionExamineSaved')) {
                    Cache.remove('inspectionExamineSaved');
                    this.arrList(2); // 重新查询已确认数据
                }
            } catch (e) {}
            // 添加序号 西药
            if (Array.isArray(callData)) {
                // 判断是数组
                callData.map((item, i) => {
                    this.wListPush(item, 'N');
                });
            } else {
                this.wListPush(callData, 'N');
            }

            // 添加序号 草药
            if (Array.isArray(callData2)) {
                // 判断是数组
                let obj;
                obj = this.otherGdata(callData2); // 转换数据
                console.log(obj);
                // 二次判断
                if (!obj.recLoc.id) {
                    return false;
                }
                this.gListPush(obj, 'N');
            } else {
                console.log(callData2);
                this.gListPush(callData2, 'N');
            }
            if (this.active === 2) {
                console.log('组件被展示了');
                this.temporaryJList('JC').then((data) => {
                    this.setData({
                        jList: data
                    });
                });
            }
            if (this.active === 3) {
                this.temporaryJList('JY').then((data) => {
                    this.setData({
                        yList: data
                    });
                });
            }
        },

        // 保存临时数据
        addTemporary: function () {
            if (this.oldTemporary) {
                return;
            }
            let patientData = Cache.get('patientData');
            let userData = Cache.get('userData');
            let { admID } = patientData;
            let { userID, locID, hospID, userName } = userData;
            let { wList, gList, active } = this;
            let orders = [];
            let medType = '';
            if (active === 0) {
                medType = 'WM';
                // 西药
                wList.map((item, i) => {
                    orders.push({
                        ordSeqNo: item.xh || '',
                        //序号
                        ordLinkSeqNo: item.selectIndex9 && item.selectIndex9.xh === '请选择' ? '' : (item.selectIndex9 && item.selectIndex9.xh) || '',
                        //关联序号
                        ordDate: '',
                        //开医嘱日期
                        ordTime: '',
                        //开医嘱时间
                        ordStartDate: '',
                        //医嘱开始日期
                        ordStartTime: '',
                        //医嘱开始时间
                        ordEndDate: '',
                        //医嘱结束日期
                        ordEndTime: '',
                        //医嘱结束时间
                        ordPriorityID: item.ordPriorityID || '',
                        //医嘱优先级
                        ordAdmReasonID: item.selectIndex1.id || '',
                        //结算类型
                        medID: item.medID || '',
                        //医嘱项id
                        ordFirstDayNum: '',
                        //首日次数
                        ordUsageID: item.selectIndex3.id || '',
                        //药品用法
                        ordFreqID: item.selectIndex2.id || '',
                        //频次
                        ordDose: item.dose || '',
                        //剂量
                        ordDoseUnitID: item.selectIndex4.doseUnitID || '',
                        //剂量单位
                        ordQty: item.stepper2 || '',
                        //数量
                        ordQtyUomID: item.selectIndex5.unitID || '',
                        //数量单位
                        ordDurQty: item.stepper || '',
                        //疗程数量
                        ordDurationID: item.ordDurationID || '',
                        //疗程单位
                        ordInfuseSpeed: '',
                        //滴速
                        ordSpeedUnitID: '',
                        //滴速单位
                        ordStage: '',
                        //医嘱阶段
                        ordRecLocID: item.selectIndex8.recLocID || '',
                        //接收科室
                        ordOPer: '',
                        //手术id
                        ordEMFlag: '',
                        //加急标志
                        ordPriorityExtID: '',
                        //二级医嘱优先级
                        ordNote: item.note || '',
                        //备注
                        orderResourceCode: '' //医嘱来源代码
                    });
                });
            } else {
                medType = 'CM';
                orders = gList;
            }
            if (orders.length < 1) {
                //return;
            }
            $http.post('urlDeault', this, {
                code: '03050176',
                data: {
                    params: [
                        {
                            admID: admID || '',
                            //就诊id
                            locID: locID || '',
                            //开单科室
                            docID: userID || '',
                            //开单医生
                            userID: userID || '',
                            //用户
                            hospID: hospID || '',
                            //登录医院id
                            orders: orders,
                            medType: medType
                        }
                    ]
                },
                success: function (res) {
                    let errorCode = res.errorCode;
                    if (errorCode === '0') {
                        if (orders.length > 0) {
                            messageUtil.handleSendMessage('P', '您有还未确认的医嘱', 'user' + userID, userName);
                        }
                    }
                }
            });
        },

        // 保存检查/检验临时数据
        saveJYTempData: function (medType) {
            let patientData = Cache.get('patientData');
            let userData = Cache.get('userData');
            let { userID, locID, hospID, userName } = userData;
            let { admID, admNo } = patientData;
            let paramsArr = medType === 'JC' ? this.jList : this.yList;
            let data = {
                params: [
                    {
                        medType: medType,
                        admID: admID || '',
                        hospID: hospID,
                        userID: userID,
                        locID: locID || '',
                        //开单科室
                        docID: userID,
                        paramsArr: paramsArr
                    }
                ]
            };
            console.log('data=', data);
            $http.post('urlDeault', this, {
                code: '03050176',
                data: data,
                success: function (res) {
                    if (res.errorCode == '0') {
                        // wx.navigateBack({
                        //   delta: this.data.handle ==="add"? 2:1,
                        // })
                    }
                },
                fail: function (err) {}
            });
        },

        // 查询保存临时数据 西药
        temporaryWList: function () {
            let patientData = Cache.get('patientData');
            let userData = Cache.get('userData');
            let { admID } = patientData;
            let { userID, locID, hospID, groupID } = userData;
            $http.post('urlDeault', this, {
                code: '03050177',
                data: {
                    params: [
                        {
                            admID: admID || '',
                            //就诊id
                            locID: locID || '',
                            //开单科室
                            userID: userID || '',
                            //用户
                            hospID: hospID || '',
                            //登录医院id
                            groupID: groupID || '',
                            medType: 'WM'
                        }
                    ]
                },
                success: function (res) {
                    let errorCode = res.errorCode;
                    let result = res.result;
                    if (errorCode === '0') {
                        this.setData({
                            oldTemporary: true
                        });
                        result.map((item, i) => {
                            item.defaultData.otherFlag = 1;
                            this.wListPush(item.defaultData, 'N');
                        });
                    }
                }
            });
        },

        // 查询保存临时数据 草药
        temporaryGList: function () {
            let patientData = Cache.get('patientData');
            let userData = Cache.get('userData');
            let { admID } = patientData;
            let { userID, locID, hospID, groupID } = userData;
            $http.post('urlDeault', this, {
                code: '03050228',
                data: {
                    params: [
                        {
                            admID: admID || '',
                            //就诊id
                            locID: locID || '',
                            //开单科室
                            userID: userID || '',
                            //用户
                            hospID: hospID || '',
                            //登录医院id
                            groupID: groupID || ''
                        }
                    ]
                },
                success: function (res) {
                    let errorCode = res.errorCode;
                    let result = res.result;
                    if (errorCode === '0') {
                        if (result[0]) {
                            this.setData({
                                oldTemporary: true
                            });
                            this.gListPush(result[0].orders[0], 'N');
                        }
                    }
                }
            });
        },

        //查询保存临时数据 检查
        temporaryJList: function (medType) {
            return new Promise((resolve, reject) => {
                let patientData = Cache.get('patientData');
                let userData = Cache.get('userData');
                let { admID } = patientData;
                let { userID, locID, hospID, groupID } = userData;
                let data = {
                    params: [
                        {
                            admID: admID || '',
                            //就诊id
                            locID: locID || '',
                            //开单科室
                            userID: userID || '',
                            //用户
                            hospID: hospID || '',
                            //登录医院id
                            groupID: groupID || '',
                            medType: medType
                        }
                    ]
                };
                $http.post('urlDeault', this, {
                    code: '03050228',
                    data: data,
                    success: function (res) {
                        if (res.errorCode == '0') {
                            if (res.result[0]) {
                                this.setData(
                                    {
                                        oldTemporary: true
                                    },
                                    () => {
                                        resolve(res.result[0].paramsArr);
                                    }
                                );
                            }
                        } else {
                            reject();
                        }
                    },
                    fail: function (err) {
                        reject();
                    }
                });
            });
        },

        // push 西药
        wListPush: function (obj, flag) {
            // 添加西药 草药数据
            let { wList, wListDefault, wnum } = this;
            if (JSON.stringify(obj) != '{}') {
                if (obj.otherFlag && obj.otherFlag === 1) {
                    obj = this.otherWdata(obj); // 转换数据
                }

                if (obj.xh && obj.xh != '') {
                    wList.map((item, i) => {
                        if (item.xh === obj.xh) {
                            wList[i] = obj;
                        }
                    });

                    // wList[wnum + wList.length - parseFloat(obj.xh)] = obj
                } else {
                    if (wList.length + wListDefault.length === 0) {
                        obj.xh = 1;
                    } else {
                        if (wList.length === 0) {
                            obj.xh = 1;
                        } else {
                            console.log(wList);
                            obj.xh = wList[0].xh + 1;
                        }
                    }
                    // obj.xh = 1 + wList.length + wListDefault.length
                    wList.unshift(obj);
                }
                this.setData({
                    active: 0
                });
            }
            this.setData(
                {
                    wList,
                    callDataClone: {}
                },
                () => {
                    if (this.wList.length > 0) {
                        if (flag != 'N') {
                            this.addTemporary(); // 保存临时数据
                            this.setData({
                                oldTemporary: false
                            });
                        } else {
                        }
                    }
                }
            );
        },

        // push 草药
        gListPush: function (obj, flag) {
            // 添加西药 草药数据
            let { gList, gListDefault } = this;
            // 添加序号 草药
            if (JSON.stringify(obj) != '{}' && obj) {
                gList = [];
                obj.xh = 1 + gList.length + gListDefault.length;
                gList.unshift(obj);
                console.log(gList);
                this.setData({
                    active: 1
                });
            }
            this.setData(
                {
                    gList,
                    callData2Clone: {}
                },
                () => {
                    if (this.gList.length > 0) {
                        if (flag != 'N') {
                            this.addTemporary(); // 保存临时数据
                        }
                    }
                    // 计算金额
                    let { gList } = this;
                    console.log(gList);
                    let money = 0;
                    let sumMoney = 0;
                    if (!gList[0]) {
                        return;
                    }
                    gList[0].gList.map((item, i) => {
                        money += parseFloat(item.searchSelect.medPrice * item.jl);
                    });
                    money = money.toFixed(2);
                    sumMoney = parseFloat(money * parseFloat(gList[0].stepper)).toFixed(2);
                    this.setData({
                        money,
                        sumMoney // 新增总金额
                    });
                }
            );
        },

        // 点击删除 西药
        tapRemove: function (event) {
            let { currentTarget } = event;
            let { wList } = this;
            let dataset = currentTarget.dataset;
            wList.map((item, i) => {
                if (item.selectIndex9.xh === wList[dataset.index].xh) {
                    item.selectIndex9 = {};
                }
            });
            wList.splice(dataset.index, 1);
            this.setData(
                {
                    wList,
                    oldTemporary: false
                },
                () => {
                    this.addTemporary(); // 保存临时数据
                }
            );
        },

        // 点击删除 草药
        tapRemove2: function (event) {
            let { currentTarget } = event;
            let { gList } = this;
            let dataset = currentTarget.dataset;
            gList.splice(dataset.index, 1);
            this.setData(
                {
                    gList,
                    oldTemporary: false
                },
                () => {
                    this.addTemporary(); // 保存临时数据
                }
            );
        },

        // 删除检查
        tapRemove3: function (e) {
            let { index } = e.currentTarget.dataset;
            let { jList } = this;
            jList.splice(index, 1);
            this.setData(
                {
                    jList
                },
                () => {
                    this.saveJYTempData('JC');
                }
            );
        },

        tapRemove4: function (e) {
            let { index } = e.currentTarget.dataset;
            let { yList } = this;
            yList.splice(index, 1);
            this.setData(
                {
                    yList
                },
                () => {
                    this.saveJYTempData('JY');
                }
            );
        },

        // 西药接口删除
        tapRemoveDefau1: function (event) {
            let msg = '确认删除这条西药数据？';
            if (this.active === 2) {
                msg = '确认删除这条检查数据？';
            } else if (this.active === 3) {
                msg = '确认删除这条检验数据？';
            }
            Dialog.confirm({
                title: '提示',
                message: msg,
                context: this
            })
                .then(() => {
                    // on confirm
                    let { currentTarget } = event;
                    let dataset = currentTarget.dataset;
                    let { cell } = dataset;
                    $http.post('urlDeault', this, {
                        code: '03050038',
                        data: {
                            params: [
                                {
                                    ordID: [cell.ordID] || '' //医嘱id
                                }
                            ]
                        },

                        success: function (res) {
                            let errorCode = res.errorCode;
                            if (errorCode === '0') {
                                Toast({
                                    type: 'success',
                                    message: '成功',
                                    context: this
                                });
                                this.arrList(2); // 数据查询
                            }
                        }
                    });
                })
                .catch(() => {
                    // on cancel
                });
        },

        // 草接口删除
        tapRemoveDefau2: function (event) {
            Dialog.confirm({
                title: '提示',
                message: '确认删除这条草药数据？',
                context: this
            })
                .then(() => {
                    // on confirm
                    let { currentTarget } = event;
                    let dataset = currentTarget.dataset;
                    let { item } = dataset;
                    let userData = Cache.get('userData');
                    let { userID, locID, hospID } = userData;
                    $http.post('urlDeault', this, {
                        code: '03050084',
                        data: {
                            params: [
                                {
                                    ordPrescNo: item.prescNo || '',
                                    userID: userID || '',
                                    locID: locID || '',
                                    hospID: hospID || ''
                                }
                            ]
                        },
                        success: function (res) {
                            let errorCode = res.errorCode;
                            if (errorCode === '0') {
                                Toast({
                                    type: 'success',
                                    message: '成功',
                                    context: this
                                });
                                this.arrList(2); // 数据查询
                            }
                        }
                    });
                })
                .catch(() => {
                    // on cancel
                });
        },

        // 查看详情
        tapDetail: function (event) {
            // let { prescNo, ordID } = this.data
            let { currentTarget } = event;
            let dataset = currentTarget.dataset;
            let { item, cell } = dataset;
            uni.navigateTo({
                //目的页面地址
                url: '/pages/entryWrite/page/Entry/prescription/prescDetail/prescDetail?ordID=' + cell.ordID + '&prescNo=' + item.prescNo + '&type=' + this.active,
                // 添加按钮名称,
                success: function (res) {}
            });
        },

        // 点击编辑
        tapEdit: function (event) {
            let { currentTarget } = event;
            let { active, gList, wList } = this;
            let dataset = currentTarget.dataset;
            let { index } = dataset;
            let editData = {};
            if (active === 2) {
                //检查编辑
                let urlAddress =
                    '/pages/entryWrite/page/Entry/prescription/addExamine/completeExamine/completeExamine?handle=edit&index=' + index + '&listArr=' + JSON.stringify(this.jList); // 添加按钮名称
                uni.navigateTo({
                    //目的页面地址
                    url: urlAddress,
                    success: function (res) {}
                });
            } else if (active === 3) {
                //检验编辑
                let urlAddress =
                    '/pages/entryWrite/page/Entry/prescription/addInspection/completeInspection/completeInspection?handle=edit&index=' +
                    index +
                    '&listArr=' +
                    JSON.stringify(this.yList); // 添加按钮名称
                uni.navigateTo({
                    //目的页面地址
                    url: urlAddress,
                    success: function (res) {}
                });
            } else {
                if (active === 0) {
                    // 西药编辑
                    editData = wList[index] || {};
                }
                if (active === 1) {
                    // 中药编辑
                    editData = gList[index] || {};
                }
                uni.navigateTo({
                    //目的页面地址
                    url:
                        '/pages/entryWrite/page/Entry/prescription/addPrescription/addPrescription?wList=' +
                        JSON.stringify(wList) +
                        '&active=' +
                        active +
                        '&editData=' +
                        JSON.stringify(editData),
                    // 添加按钮名称,
                    success: function (res) {}
                });
            }
        },

        // 点击添加
        addChange: function (event) {
            // 无主诊断时禁止添加医嘱
            if (!this.hasMainDiag) {
                Toast({
                    type: 'fail',
                    message: '请先添加主诊断后再添加医嘱',
                    context: this
                });
                return false;
            }
            let { active, gList, wList, jList, yList } = this;
            console.log('active===', active);
            if (active === 1 && gList.length > 0) {
                Toast({
                    type: 'fail',
                    message: '草药只能有一条未确认处方',
                    context: this
                });
                return false;
            }
            let urlAddress = '/pages/entryWrite/page/Entry/prescription/addPrescription/addPrescription?wList=' + JSON.stringify(wList) + '&active=' + active; // 添加按钮名称
            if (active === 2 || active === 3) {
                // 检查/检验统一进入 addPrescription 的检验检查类别
                urlAddress = '/pages/entryWrite/page/Entry/prescription/addPrescription/addPrescription?wList=' + JSON.stringify(wList) + '&active=2';
            }
            uni.navigateTo({
                url: urlAddress
            });
        },

        // 查询数据
        arrList: function (code) {
            let patientData = Cache.get('patientData');
            let { admID, admNo } = patientData;
            $http.post('urlDeault', this, {
                code: '03100056',
                data: {
                    params: [
                        {
                            admID: admID || '',
                            //就诊ID
                            admNo: admNo || '' //就诊号
                        }
                    ]
                },

                success: function (res) {
                    let errorCode = res.errorCode;
                    if (errorCode === '0') {
                        let totalAmount = res.result.totalAmount || 0;
                        if (totalAmount != this.totalAmount && totalAmount != 0 && code == 1) {
                            //费用不同时给患者发送消息提醒缴费
                            if (this.sendMessageFlag != 'Y') {
                                messageUtil.handleSendMessage('D', '您有新的待支付订单');
                            }
                        }
                        this.setData({
                            wListDefault: res.result.wesMed || [],
                            // 西药数据
                            gListDefault: res.result.herbs || [],
                            // 草药数据
                            jListDefault: res.result.pacsOrder || [],
                            //检查数据
                            yListDefault: res.result.lisOrder || [],
                            //检验数据
                            wesMedAmount: res.result.wesMedAmount || '0',
                            //  西药金额
                            herbsAmount: res.result.herbsAmount || '0',
                            //  草药金额
                            totalAmount: res.result.totalAmount || '0',
                            //  总金额
                            wnum: res.result.wesMed.length || 0,
                            // 西药数量
                            gnum: res.result.herbs.length || 0,
                            // 草药数量
                            jnum: res.result.pacsOrder.length || 0,
                            //检查数量
                            ynum: res.result.lisOrder.length || 0
                        });
                    }
                }
            });
        },

        // 确认处方
        onChange(event) {
            this.setData({
                active: event.detail.name || 0
            });
        },

        // 确认处方
        sureChange: Util.debounce(function () {
            let { active } = this;
            if (active === 0) {
                this.setData({ 
                    saveLoaing: true,
                }, () => {
                    this.sureChange1();
                });
                
            }
        }),

        // 西药
        sureChange1:function () {
            let patientData = Cache.get('patientData');
            let userData = Cache.get('userData');
            let { admID } = patientData;
            let { userID, locID, hospID } = userData;
            let { wList } = this;
            let orders = [];
            wList.map((item, i) => {
                orders.push({
                    ordSeqNo: item.xh || '',
                    //序号
                    ordLinkSeqNo: item.selectIndex9 && item.selectIndex9.xh === '请选择' ? '' : (item.selectIndex9 && item.selectIndex9.xh) || '',
                    //关联序号
                    ordDate: '',
                    //开医嘱日期
                    ordTime: '',
                    //开医嘱时间
                    ordStartDate: '',
                    //医嘱开始日期
                    ordStartTime: '',
                    //医嘱开始时间
                    ordEndDate: '',
                    //医嘱结束日期
                    ordEndTime: '',
                    //医嘱结束时间
                    ordPriorityID: item.ordPriorityID || '',
                    //医嘱优先级
                    ordAdmReasonID: item.selectIndex1.id || '',
                    //结算类型
                    medID: item.medID || '',
                    //医嘱项id
                    ordFirstDayNum: '',
                    //首日次数
                    ordUsageID: item.selectIndex3.id || '',
                    //药品用法
                    ordFreqID: item.selectIndex2.id || '',
                    //频次
                    ordDose: item.dose || '',
                    //剂量
                    ordDoseUnitID: item.selectIndex4.doseUnitID || '',
                    //剂量单位
                    ordQty: item.stepper2 || '',
                    //数量
                    ordQtyUomID: item.selectIndex5.unitID || '',
                    //数量单位
                    ordDurQty: item.stepper || '',
                    //疗程数量
                    ordDurationID: item.ordDurationID || '',
                    //疗程单位
                    ordInfuseSpeed: '',
                    //滴速
                    ordSpeedUnitID: '',
                    //滴速单位
                    ordStage: '',
                    //医嘱阶段
                    ordRecLocID: item.selectIndex8.recLocID || '',
                    //接收科室
                    ordOPer: '',
                    //手术id
                    ordEMFlag: '',
                    //加急标志
                    ordPriorityExtID: '',
                    //二级医嘱优先级
                    ordNote: item.note || '',
                    //备注
                    orderResourceCode: '', //医嘱来源代码
                    // 诊断信息（03100050 通过 extvalue 传递）
                    extvalue: [
                        {
                            code: 'Diag',
                            refDescripts: item.diagCode || '',
                            value: item.diagID || ''
                        }
                    ]
                });
            });

            $http.post('urlDeault', this, {
                code: '03100050',
                data: {
                    params: [
                        {
                            admID: admID || '',
                            //就诊id
                            locID: locID || '',
                            //开单科室
                            docID: userID || '',
                            //开单医生
                            userID: userID || '',
                            //用户
                            hospID: hospID || '',
                            //登录医院id
                            orders: orders
                        }
                    ]
                },
                fail: () => {
                    this.setData({ 
                      saveLoaing: false,
                    });
                },
                success: (res)=> {
                    let errorCode = res.errorCode;
                    if (errorCode == '0') {
                        this.setData({
                                wList: [], // 草药数据
                                saveLoaing: false,
                            },() => {
                                Toast({
                                    type: 'success',
                                    message: '成功',
                                    context: this
                                });
                                this.arrList(1); // 数据查询
                            }
                        );
                    }
                }
            });
        },
        // 接受其他传来的data 西药
        otherWdata: function (data) {
            let durationList = [
                {
                    id: '1',
                    code: '1',
                    descripts: '天',
                    enDescripts: '',
                    descriptsSPCode: 'T',
                    factor: 1,
                    CMFlag: 'N'
                },
                {
                    id: '2',
                    code: '2',
                    descripts: '周',
                    enDescripts: '',
                    descriptsSPCode: 'Z',
                    factor: 7,
                    CMFlag: 'N'
                },
                {
                    id: '3',
                    code: '3',
                    descripts: '月',
                    enDescripts: '',
                    descriptsSPCode: 'Y',
                    factor: 30,
                    CMFlag: 'N'
                }
            ];
            console.log(data);
            let obj = {
                selectIndex1:
                    {
                        id: data.ordAdmReasonID
                    } || {},
                selectIndex2:
                    {
                        id: data.ordFreqID,
                        descripts: data.ordFreqDesc || data.ordFrequenceDesc
                    } || {},
                selectIndex3:
                    {
                        id: data.ordUsageID,
                        descripts: data.ordUsageDesc
                    } || {},
                selectIndex4:
                    {
                        doseUnitID: data.ordDoseUnitID,
                        doseUnitDesc: data.ordDoseUnitDesc
                    } || {},
                selectIndex5:
                    {
                        unitID: data.ordQtyUomID,
                        unitDesc: data.ordQtyUomDesc
                    } || {},
                selectIndex6:
                    {
                        id: data.ordSpecID
                    } || {},
                selectIndex7:
                    {
                        id: data.ordSkinTestUsageID
                    } || {},
                selectIndex8:
                    {
                        recLocID: data.ordRecLocID
                    } || {},
                selectIndex9: {},
                medID: data.medID,
                //医嘱项id
                ordSetID: data.ordSetID,
                //医嘱套id
                stepper: data.ordDurQty,
                // 疗程值
                stepper2: data.ordQty,
                // 项目数量值
                timeSelect: this.picakIndex('id', data.ordDurationID, durationList),
                // 时间选中
                searchSelect:
                    {
                        medID: data.medID,
                        medDesc: data.ordMedItemDesc || data.ordDesc,
                        medPrice: data.ordPrice
                    } || '',
                //   选中的医嘱名称
                ordDurationDesc: data.ordDurationDesc,
                ordDurationID: data.ordDurationID,
                arrayTime: data.arrayTime || [],
                //   时间
                dose: data.ordDose,
                //   剂量
                note: data.ordNote,
                //   备注
                switch1Checked: '',
                //   皮试
                ordPriorityID: data.ordPriorityID,
                //   医嘱优先级
                xh: '',
                guge: data.spec // 规格
            };

            return obj;
        },

        // 接受其他传来的data 草药
        otherGdata: function (data) {
            console.log(data);
            let gList = [];
            data.map((item) => {
                gList.push({
                    searchSelect: {
                        medID: item.medID || '',
                        medDesc: item.ordDesc || ''
                    },
                    decoctMethod:
                        {
                            id: item.note
                        } || {},
                    //备注
                    comPrinciple:
                        {
                            id: item.comPrincipleID
                        } || {},
                    //用药类型
                    typeList:
                        {
                            id: item.ordDoseUnitID
                        } || {},
                    //剂量单位
                    jl: item.ordDose || '' // 单次剂量
                });
            });

            let obj = {
                gList: gList,
                // 草药组
                selectData1:
                    {
                        id: data.admReasonID
                    } || {},
                //结算类型加载数据
                frequence:
                    {
                        id: data.freqID
                    } || {},
                //频次
                herbalForm:
                    {
                        id: data.herbalFormID
                    } || {},
                //剂型
                usage:
                    {
                        id: data.usageID
                    } || {},
                //用法
                cookType:
                    {
                        id: data.cookTypeID
                    } || {},
                //煎药方式
                usageExplain:
                    {
                        id: data.usageExplainID
                    } || {},
                //服用要求
                recLoc:
                    {
                        id: data.recLocID
                    } || {},
                //科室
                stepper: data.durQty,
                // 用药值
                sum: data.doseQty // 每次数量
            };

            return obj;
        },

        // 获取索引值picker
        picakIndex: function (name, id, arr) {
            let index = '';
            if (!arr) {
                return false;
            }
            arr.map((item, i) => {
                if (item[name] == id) {
                    index = i;
                }
            });
            return parseFloat(index);
        },

        // 获取是否发消息给患者
        getToPatientMessageFlag: function () {
            $http.post('urlDeault', this, {
                code: '03100129',
                data: {},
                success: function (res) {
                    let errorCode = res.errorCode;
                    let result = res.result;
                    if (errorCode === '0') {
                        this.setData({
                            sendMessageFlag: result
                        });
                    }
                }
            });
        }
    },
    created: function () {},
    watch: {
        callData: {
            handler: function (newVal, oldVal) {
                this.callDataClone = newVal;
            },

            immediate: true,
            deep: true
        },

        callData2: {
            handler: function (newVal, oldVal) {
                this.callData2Clone = newVal;
            },

            immediate: true,
            deep: true
        }
    }
};
</script>
<style>
/* @import '../diagnostic/diagnostic.css'; */

.topTitle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 80rpx;
    font-size: 24rpx;
    color: #4b5563;
    background: #fff;
    padding: 12rpx 20rpx;
    box-sizing: border-box;
    margin: 0 0 8rpx;
    border-radius: 6rpx;
    box-shadow: none;
}

.topTitle__amount {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    line-height: 36rpx;
    gap: 4rpx 14rpx;
}

.topTitle__label {
    color: #1f2937;
    font-weight: 500;
    font-size: 26rpx;
}

.topTitle__sub {
    color: #9ca3af;
    font-size: 22rpx;
}

.money {
    color: #1687ff;
    font-weight: 600;
    margin: 0 2rpx;
    font-size: 26rpx;
}

.topNumber {
    display: flex;
    flex-grow: 1;
    justify-content: center;
}

.topNumber label {
    color: #1687ff;
}

.topRight {
    display: flex;
    align-items: center;
}

.addtext {
    display: inline-block;
    flex-shrink: 0;
    height: 56rpx;
    min-width: 140rpx;
    width: auto;
    color: #fff;
    background-color: #1890ff;
    line-height: 56rpx;
    font-size: 26rpx;
    text-align: center;
    box-sizing: border-box;
    margin-left: 16rpx;
    border-radius: 999rpx;
    padding: 0 24rpx;
    font-weight: normal;
}

.addtext:after {
    border: initial;
}

.medData {
    border-bottom: 1rpx solid #f0f2f5;
    color: #4b5563;
}

.none {
    width: 320rpx;
    margin: 0 auto;
    margin-top: 80rpx;
}

.van-tab--active {
    color: #1687ff;
}

.editText {
    font-size: 24rpx;
    line-height: 46rpx;
    overflow: hidden;
    padding: 10rpx 0;
}

.editBtn {
    border: 1rpx solid #e5e7eb;
    width: auto !important;
    height: 36rpx !important;
    line-height: 36rpx !important;
    display: inline-block;
    border-radius: 4rpx;
    padding: 0 12rpx;
    margin-left: 16rpx;
    font-size: 22rpx;
    color: #1687ff;
    background: #fff;
}

.editT {
    padding: 0 !important;
    margin: 0 !important;
    border: 0 !important;
    display: inline-block !important;
}

.boxBtm1 {
    float: right;
    text-align: right;
    width: 50%;
    box-sizing: border-box;
    padding-top: 0;
    margin-right: 16rpx;
}

.boxBtm1 button {
    margin-left: 0;
    width: 140rpx;
    display: inline-block;
    font-size: 24rpx;
    border-radius: 4rpx !important;
    font-weight: normal;
    padding: 0 !important;
    height: 44rpx !important;
    line-height: 44rpx !important;
}

.divider {
    width: auto;
    margin: 6rpx 0;
    padding: 0 8rpx;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: center;
}

.divider-text {
    color: #9ca3af;
    font-size: 22rpx;
    font-weight: 400;
    letter-spacing: 0.5rpx;
    line-height: 40rpx;
    padding: 0 4rpx;
    position: relative;
}

.divider-text::before,
.divider-text::after {
    content: '';
    display: inline-block;
    width: 48rpx;
    height: 1rpx;
    background: #e5e7eb;
    vertical-align: middle;
    margin: 0 14rpx;
}

.lin30 {
    line-height: 30rpx;
}

.boxTime {
    color: #9ca3af;
    font-size: 22rpx;
    line-height: 36rpx;
}

.remove {
    color: #f5222d;
    border: 1rpx solid #f5222d !important;
    background: #fff;
    min-width: 120rpx;
    height: 56rpx !important;
    line-height: 56rpx !important;
    border-radius: 999rpx !important;
    font-size: 26rpx !important;
    padding: 0 24rpx !important;
    margin: 0 !important;
    font-weight: normal;
}

.remove:after {
    border: initial;
}

.btn {
    background: #1890ff;
    color: #fff;
    border: 1rpx solid #1890ff !important;
    min-width: 120rpx;
    height: 56rpx !important;
    line-height: 56rpx !important;
    border-radius: 999rpx !important;
    font-size: 26rpx !important;
    padding: 0 24rpx !important;
    margin: 0 !important;
    font-weight: normal;
}

.btn:after {
    border: initial;
}

.boxcontent {
    height: auto;
    line-height: 48rpx;
    padding: 6rpx 0 0;
}

.boxBtm {
    border-top: 0;
    padding: 12rpx 0 0;
    text-align: right;
}

.boxTitle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: #1f2937;
    font-weight: 500;
    line-height: 36rpx;
    padding-bottom: 8rpx;
    border-bottom: 1rpx solid #f0f2f5;
    gap: 8rpx;
}

.boxTitle__main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4rpx 8rpx;
    color: #1f2937;
    font-weight: 500;
    line-height: 32rpx;
    font-size: 24rpx;
    word-break: break-all;
}

.status-tag {
    flex-shrink: 0;
    display: inline-block;
    font-size: 20rpx;
    line-height: 28rpx;
    padding: 0 10rpx;
    border-radius: 4rpx;
    font-weight: 500;
}

.status-tag--pending {
    color: #d97706;
    background: #fef3c7;
}

.status-tag--done {
    color: #1687ff;
    background: #e0edff;
}

.boxBorder {
    border-left: 0;
    background: #fafbfc;
}

.vTabs {
    /* 确认医嘱按钮已 fixed 定位，这里只需确保内容不被遮挡 */
    background: #f4f6f8;
}

.redIcon {
    display: inline-block;
    vertical-align: middle;
}
.jc-flex {
    display: flex;
    flex-direction: row;
}
.jc-left {
    flex: 1;
}
.jc-right {
    padding-left: 10rpx;
}

.diagnostic-wrapper {
    background: #f4f6f8;
}

.box {
    background: #fff;
    margin: 0 0 8rpx;
    padding: 16rpx 20rpx;
    border-radius: 6rpx;
    box-shadow: none;
    box-sizing: border-box;
    overflow: hidden;
}

.boxBtm {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    flex-wrap: wrap;
    gap: 12rpx;
    border-top: 0;
    padding: 12rpx 0 0;
    margin-top: 0;
    width: 100%;
}

.boxBtm button {
    margin: 0 !important;
    height: 56rpx !important;
    line-height: 56rpx !important;
    border-radius: 999rpx !important;
    font-size: 26rpx !important;
    padding: 0 24rpx !important;
    font-weight: normal;
}

.boxBtm button:after {
    border: initial;
}

.row {
    margin: 0;
}
.ros:last-child{
    padding-bottom: 100rpx;
}
/* 空状态 */
.empty {
    background: #fff;
    margin: 12rpx 0;
    padding: 80rpx 0;
    border-radius: 6rpx;
    text-align: center;
    box-shadow: none;
}

.empty__img {
    width: 200rpx;
    height: 200rpx;
    margin: 0 auto 12rpx;
    display: block;
    opacity: 0.6;
}

.empty__text {
    color: #9ca3af;
    font-size: 24rpx;
    text-align: center;
}

/* 确认医嘱按钮：与诊断录入页面按钮风格一致（药丸型 + 简洁悬浮） */
.diagnostibutton {
    position: fixed;
    left: 20rpx;
    right: 20rpx;
    bottom: 24rpx;
    height: 84rpx;
    line-height: 84rpx;
    background: #1890ff;
    color: #fff;
    font-size: 30rpx;
    font-weight: 500;
    text-align: center;
    border-radius: 999rpx;
    padding: 0;
    margin: 0;
    z-index: 10;
}

.diagnostibutton:after {
    border: initial;
}
</style>
