<template>
    <view class="diag-form">
        <!-- pages/entryWrite/page/Entry/prescription/addPrescription/customDiagnostics/grass/grass.wxml -->
        <mp-cells ext-class="my-cells">
            <picker @change="bindPickerChange2" :value="herbalForm1" :range="herbalForm" range-key="descripts">
                <mp-cell class="diag-form__cell">
                    <view class="diag-form__line">
                        <view class="diag-form__label diag-form__label--required">
                            使用剂型
                            <view class="redIcon" v-if="!(verification === 'N' || (herbalForm && herbalForm[herbalForm1] && herbalForm[herbalForm1].descripts))">
                                <van-icon name="warning" color="red" />
                            </view>
                        </view>
                        <view class="diag-form__picker">{{ (herbalForm && herbalForm[herbalForm1] && herbalForm[herbalForm1].descripts) || '请选择' }}</view>
                    </view>
                </mp-cell>
            </picker>
            <mp-cell class="diag-form__cell">
                <view class="diag-form__line">
                    <view class="diag-form__label diag-form__label--required">
                        用药付数
                        <view class="redIcon" v-if="!(verification === 'N' || (stepper && stepper !== ''))">
                            <van-icon name="warning" color="red" />
                        </view>
                    </view>
                    <view class="diag-form__stepper-wrap diag-form__stepper-wrap--right">
                        <van-stepper :value="stepper" :min="minQty" :max="maxQty" @change="onChangeStepper" integer input-width="80px" button-size="28px" />
                    </view>
                </view>
            </mp-cell>
            <picker @change="bindPickerChange3" :value="frequence1" :range="frequence" range-key="descripts">
                <mp-cell class="diag-form__cell">
                    <view class="diag-form__line">
                        <view class="diag-form__label diag-form__label--required">
                            使用频次
                            <view class="redIcon" v-if="!(verification === 'N' || (frequence && frequence[frequence1] && frequence[frequence1].descripts))">
                                <van-icon name="warning" color="red" />
                            </view>
                        </view>
                        <view class="diag-form__picker">{{ (frequence && frequence[frequence1] && frequence[frequence1].descripts) || '请选择' }}</view>
                    </view>
                </mp-cell>
            </picker>
            <mp-cell class="diag-form__cell">
                <view class="diag-form__line">
                    <view class="diag-form__label diag-form__label--required">
                        每次数量
                        <view class="redIcon" v-if="!(verification === 'N' || (sum && sum !== ''))">
                            <van-icon name="warning" color="red" />
                        </view>
                    </view>
                    <view class="diag-form__input-wrap">
                        <input class="diag-form__input" placeholder="请输入每次数量" :value="sum" @input="binddoseChange" type="text" />
                    </view>
                </view>
            </mp-cell>
            <picker @change="bindPickerChange4" :value="usage1" :range="usage" range-key="descripts">
                <mp-cell class="diag-form__cell">
                    <view class="diag-form__line">
                        <view class="diag-form__label diag-form__label--required">
                            用药方法
                            <view class="redIcon" v-if="!(verification === 'N' || (usage && usage[usage1] && usage[usage1].descripts))">
                                <van-icon name="warning" color="red" />
                            </view>
                        </view>
                        <view class="diag-form__picker">{{ (usage && usage[usage1] && usage[usage1].descripts) || '请选择' }}</view>
                    </view>
                </mp-cell>
            </picker>
            <picker @change="bindPickerChange5" :value="cookType1" :range="cookType" range-key="descripts">
                <mp-cell class="diag-form__cell">
                    <view class="diag-form__line">
                        <view class="diag-form__label">
                            煎药方式
                            <view class="redIcon" v-if="!(verification === 'N' || (cookType && cookType[cookType1] && cookType[cookType1].descripts))">
                                <van-icon name="warning" color="red" />
                            </view>
                        </view>
                        <view class="diag-form__picker">{{ (cookType && cookType[cookType1] && cookType[cookType1].descripts) || '请选择' }}</view>
                    </view>
                </mp-cell>
            </picker>
            <picker @change="bindPickerChange6" :value="usageExplain1" :range="usageExplain" range-key="descripts">
                <mp-cell class="diag-form__cell">
                    <view class="diag-form__line">
                        <view class="diag-form__label diag-form__label--required">
                            服用要求
                            <view class="redIcon" v-if="!(verification === 'N' || (usageExplain && usageExplain[usageExplain1] && usageExplain[usageExplain1].descripts))">
                                <van-icon name="warning" color="red" />
                            </view>
                        </view>
                        <view class="diag-form__picker">{{ (usageExplain && usageExplain[usageExplain1] && usageExplain[usageExplain1].descripts) || '请选择' }}</view>
                    </view>
                </mp-cell>
            </picker>
            <picker @change="bindPickerChange7" :value="recLoc1" :range="recLoc" range-key="descripts">
                <mp-cell class="diag-form__cell">
                    <view class="diag-form__line">
                        <view class="diag-form__label diag-form__label--required">
                            执行科室
                            <view class="redIcon" v-if="!(verification === 'N' || (recLoc && recLoc[recLoc1] && recLoc[recLoc1].descripts))">
                                <van-icon name="warning" color="red" />
                            </view>
                        </view>
                        <view class="diag-form__picker">{{ (recLoc && recLoc[recLoc1] && recLoc[recLoc1].descripts) || '请选择' }}</view>
                    </view>
                </mp-cell>
            </picker>
            <picker @change="bindPickerChange1" :value="selectIndex1" :range="selectData1" range-key="descripts">
                <mp-cell class="diag-form__cell">
                    <view class="diag-form__line">
                        <view class="diag-form__label diag-form__label--required">
                            结算类型
                            <view class="redIcon" v-if="!(verification === 'N' || (selectData1 && selectData1[selectIndex1] && selectData1[selectIndex1].descripts))">
                                <van-icon name="warning" color="red" />
                            </view>
                        </view>
                        <view class="diag-form__picker">{{ (selectData1 && selectData1[selectIndex1] && selectData1[selectIndex1].descripts) || '请选择' }}</view>
                    </view>
                </mp-cell>
            </picker>
        </mp-cells>

        <view class="grass-detail">
            <view class="grass-detail__header">
                <text class="grass-detail__title required">用药明细</text>
                <text class="grass-detail__add" @tap="addChange">+ 添加草药</text>
            </view>
            <view class="grass-detail__item" v-for="(item, index) in gList" :key="index">
                <view class="grass-detail__row">
                    <van-tag type="primary">{{ item.comPrinciple.descripts }}</van-tag>
                    <text class="grass-detail__med">{{ item.searchSelect.medDesc }}</text>
                </view>
                <view class="grass-detail__meta">
                    <text class="grass-detail__meta-item">剂量：{{ item.jl }} {{ item.typeList.unitDesc }}</text>
                    <text class="grass-detail__meta-item">用药类型：{{ item.comPrinciple.descripts }}</text>
                    <text class="grass-detail__meta-item" v-if="item.decoctMethod && item.decoctMethod.descripts">备注：{{ item.decoctMethod.descripts }}</text>
                </view>
                <view class="grass-detail__actions">
                    <button class="grass-detail__btn grass-detail__btn--remove" @tap="tapRemove" :data-index="index">删除</button>
                    <button class="grass-detail__btn grass-detail__btn--edit" @tap="addChangeEdit" :data-index="index">编辑</button>
                </view>
            </view>
            <view class="grass-detail__empty" v-if="gList.length <= 0">暂无用药明细</view>
        </view>

        <view class="diag-form__actions diag-form__actions--bottom">
            <button class="diag-form__action diag-form__action--plain" @tap="clearnbtn">清空</button>
            <button class="diag-form__action diag-form__action--primary" @tap="addbtn" :disabled="isLoading">{{ isLoading ? '保存中' : '保存' }}</button>
        </view>
        <van-toast id="van-toast" />
        <van-dialog id="van-dialog" />
        <van-overlay :show="show">
            <view class="wrapper">
                <van-loading type="spinner" />
            </view>
        </van-overlay>
    </view>
</template>

<script>
import Cache from '../../../../../../../../utils/cache';
// pages/entryWrite/page/Entry/prescription/addPrescription/customDiagnostics/grass/grass.js
import { $http } from '../../../../../../../../config/https';
import util from '../../../../../../../../utils/util';
import Toast from '../../../../../../../../utils/toast';
import Dialog from '../../../../../../../../utils/dialog';
export default {
    components: {},
    data() {
        return {
            gList: [],

            // 草药list
            selectIndex1: '',

            selectData1: [],

            //结算类型加载数据
            frequence1: '',

            frequence: [],

            //频次
            herbalForm1: '',

            herbalForm: [],

            //剂型
            usage1: '',

            usage: [],

            //用法
            cookType1: '',

            cookType: [],

            //煎药方式
            usageExplain1: '',

            usageExplain: [],

            //服用要求
            recLoc1: '',

            recLoc: [],

            //科室
            stepper: '0',

            // 用药值
            sum: '',

            // 每次数量
            show: true,

            // 遮罩层
            show1: true,

            // 遮罩层条件一
            show2: true,

            // 遮罩层条件二
            verification: 'N',

            // 验证
            maxQty: '99999',

            // 最大值
            minQty: '0',

            // 最小值
            isLoading: false,

            descripts: '',
            gListcallDataClone: ''
        };
    },
    /**
     * 可以使用全局样式
     */
    options: {
        addGlobalClass: true
    },
    /**
     * 组件的属性列表
     */
    props: {
        gListData: {
            type: Array,
            //类型
            default: () => [] //默认值
        },

        gListcallData: {
            type: Object,
            //类型
            default: () => ({}) //默认值
        },

        editData: {
            type: Object,
            //类型
            default: () => ({}) //默认值
        }
    },
    mounted() {
        // 处理小程序 attached 生命周期
        this.attached();
        // 处理小程序 ready 生命周期
        this.$nextTick(() => this.ready());
    },
    destroyed: function () {
        // 在组件实例被从页面节点树移除时执行
        this.addInfo(); //组件值外传
    },
    /**
     * 组件的方法列表
     */
    methods: {
        handlePageShow() {
            // 添加草药数据
            let { gListData, gListcallDataClone: gListcallData } = this;
            console.log('erzi', gListcallData);
            this.setData({
                gList: gListData,
                gListcallDataClone: gListcallData
            });
        },

        ready: function (options) {
            // 添加草药数据
            let { gListData, gListcallDataClone: gListcallData } = this;
            console.log('erzi', gListcallData);
            this.setData({
                gList: gListData,
                gListcallDataClone: gListcallData
            });
            // 在组件在视图层布局完成后执行
            this.selectData1Fun(); // 结算类型加载数据
            this.selectData2(); // 其他下拉加载数据
        },

        attached: function () {
            // 在组件实例进入页面节点树时执行
            // 清除Storage
            Cache.remove('searchSelect');
        },

        callpress: function () {
            let { gListcallDataClone: gListcallData } = this;
            if (JSON.stringify(gListcallData) !== '{}') {
                this.setData(
                    {
                        herbalForm1: this.picakIndex('id', gListcallData.cmOrderSetHerbalFormID, this.herbalForm),
                        // 剂型
                        stepper: gListcallData.cmOrderSetDurQty,
                        //用药付数
                        frequence1: this.picakIndex('id', gListcallData.cmOrderSetFreqID, this.frequence),
                        //频次
                        sum: gListcallData.cmOrderSetDoseQty,
                        //数量
                        usage1: this.picakIndex('id', gListcallData.cmOrderSetUsageID, this.usage),
                        //用药方法
                        usageExplain1: this.picakIndex('id', gListcallData.cmOrderSetUsageExplainID, this.usageExplain),
                        //服用要求
                        recLoc1: this.picakIndex('id', gListcallData.cmOrderSetRecLocID, this.recLoc) //默认接收科室
                    },
                    () => {
                        this.setData({
                            gListcallDataClone: {}
                        });
                    }
                );
            }
        },

        // 组件值外传
        addInfo: function () {
            let obj = this.objadd(); //要传给父组件的参数
            obj.WGType = 'G';
            this.$emit('addInfo', {
                detail: obj
            }); //通过triggerEvent将参数传给父组件
        },

        // 回显数据
        editDataFun: function (editData) {
            if (JSON.stringify(editData) != '{}') {
                if (!editData.gList) {
                    //  不是草药回显
                    return false;
                }
                console.log(editData);
                this.setData(
                    {
                        herbalForm1: this.picakIndex('id', editData.herbalForm.id, this.herbalForm)
                    },
                    () => {
                        this.bindPickerChange2Http(); // 切换 默认值
                    }
                );

                this.setData({
                    gList: editData.gList || [],
                    // 草药list
                    selectIndex1: this.picakIndex('id', editData.selectData1.id, this.selectData1),
                    frequence1: this.picakIndex('id', editData.frequence.id, this.frequence),
                    usage1: this.picakIndex('id', editData.usage.id, this.usage),
                    cookType1: this.picakIndex('id', editData.cookType.id, this.cookType),
                    usageExplain1: this.picakIndex('id', editData.usageExplain.id, this.usageExplain),
                    recLoc1: this.picakIndex('id', editData.recLoc.id, this.recLoc),
                    stepper: editData.stepper || '0',
                    // 用药值
                    sum: editData.sum || '' // 每次数量
                });
            }
        },

        // 结算类型加载数据
        selectData1Fun: function (e) {
            let patientData = Cache.get('patientData');
            let userData = Cache.get('userData');
            let { hospID } = userData;
            let { patID, admID } = patientData;
            $http.post('urlDeault', this, {
                code: '03100048',
                data: {
                    params: [
                        {
                            admID: admID || '',
                            // admID
                            patID: patID || '',
                            //患者id
                            hospID: hospID || '' //医院id
                        }
                    ]
                },

                success: function (res) {
                    let errorCode = res.errorCode;
                    if (errorCode === '0') {
                        this.setData(
                            {
                                selectData1: res.result || [],
                                // 结算类型
                                show1: false // 遮罩层条件2
                            },
                            () => {
                                let { selectData1Fun: selectData1 } = this;
                                selectData1.map((item, i) => {
                                    if (item.defaultFlag === 'Y') {
                                        this.setData({
                                            selectIndex1: this.picakIndex('id', item.id, selectData1)
                                        });
                                    }
                                });
                                this.showFun(); // 遮罩层
                            }
                        );
                    }
                }
            });
        },

        // 其他下拉加载数据
        selectData2: function (e) {
            let userData = Cache.get('userData');
            let { hospID } = userData;
            $http.post('urlDeault', this, {
                code: '03100066',
                data: {
                    params: [
                        {
                            hospID: hospID || '',
                            //登录医院id
                            admType: 'O',
                            //就诊类型
                            comPrincipleFlag: '1',
                            //配伍原则
                            herbalFormFlag: '1',
                            //剂型
                            frequenceFlag: '1',
                            //频次
                            usageFlag: '1',
                            //用法
                            durationFlag: '1',
                            //疗程单位
                            usageExplainFlag: '1',
                            //服用要求
                            authRangeFlag: '1',
                            //使用级别
                            decoctMethodFlag: '1',
                            //备注
                            cookTypeFlag: '1' //
                        }
                    ]
                },

                success: function (res) {
                    let errorCode = res.errorCode;
                    if (errorCode === '0') {
                        this.setData(
                            {
                                herbalForm: res.result.herbalForm || [],
                                //剂型
                                usage: res.result.usage || [],
                                //用法
                                cookType: res.result.cookType || [],
                                //煎药方式
                                usageExplain: res.result.usageExplain || [],
                                //服用要求
                                recLoc: res.result.recLoc || [],
                                //科室
                                frequence: res.result.frequence || [],
                                //频次
                                // 默认值
                                usageExplain1: this.picakIndex('id', res.result.defaultUsageExplainID, res.result.cookType),
                                //默认服用要求
                                cookType1: this.picakIndex('id', res.result.defaultCookTypeID, res.result.usageExplain),
                                //默认煎药方式
                                stepper: res.result.defaultDurQty,
                                //默认疗程数
                                sum: res.result.defaultDoseQty,
                                //默认用量
                                frequence1: this.picakIndex('id', res.result.defaultFreqID, res.result.frequence),
                                //默认频次
                                herbalForm1: this.picakIndex('id', res.result.defaultHerbalFormID, res.result.herbalForm),
                                //默认剂型
                                usage1: this.picakIndex('id', res.result.defaultUsageExplainID, res.result.usage),
                                //默认用药方法

                                show2: false // 遮罩层条件2
                            },
                            () => {
                                let { editDataFun: editData, recLoc } = this;
                                recLoc.map((item, i) => {
                                    if (item.defaultFlag === 'Y') {
                                        this.setData({
                                            recLoc1: this.picakIndex('id', item.id, recLoc)
                                        });
                                    }
                                });
                                this.editDataFun(editData); // 回显数据
                                this.showFun(); // 遮罩层
                                let { gListcallDataClone: gListcallData } = this;
                                if (JSON.stringify(gListcallData) !== '{}') {
                                    this.callpress();
                                } else {
                                    this.bindPickerChange2Http(); // 切换 默认值
                                }
                            }
                        );
                    }
                }
            });
        },

        // 结算类型切换
        bindPickerChange1: function (e) {
            this.setData({
                selectIndex1: e.detail.value
            });
        },

        // 使用剂型切换
        bindPickerChange2: function (e) {
            Dialog.confirm({
                title: '提示',
                message: '剂型切换会导致用药明细清空，是否继续切换',
                context: this
            })
                .then(() => {
                    this.setData(
                        {
                            herbalForm1: e.detail.value,
                            gList: [] // 草药list
                        },
                        () => {
                            this.bindPickerChange2Http();
                        }
                    );
                })
                .catch(() => {
                    // on cancel
                });
        },

        // 使用剂型切换 http 重置 科室下拉款数据
        bindPickerChange2Http: function () {
            let { herbalForm1, herbalForm } = this;
            let herbalFormID = herbalForm[herbalForm1].id;
            $http.post('urlDeault', this, {
                code: '03050083',
                data: {
                    params: [
                        {
                            herbalFormID: herbalFormID,
                            admType: 'O',
                            //就诊类型
                            tisaneFlag: 'N' //代煎标识
                        }
                    ]
                },

                success: function (res) {
                    let errorCode = res.errorCode;
                    if (errorCode === '0') {
                        this.setData({
                            recLoc: res.data.CMRecLocList || [],
                            // 接收科室下拉框
                            frequence1: this.picakIndex('id', res.data.defaultFreqID, this.frequence),
                            // 默认频次id
                            usage1: this.picakIndex('id', res.data.defaultUsageID, this.usage),
                            // 默认用法id
                            usageExplain1: this.picakIndex('id', res.data.defaultUsageExplainID, this.usageExplain),
                            //默认服用要求
                            stepper: res.data.defaultDurQty,
                            // 默认付数
                            sum: res.data.defaultDoseQty,
                            //默认用量
                            recLoc1: this.picakIndex('id', res.data.defaultCMRecLocID, res.data.CMRecLocList),
                            //默认接收科室id
                            cookType: res.data.cookTypeList || [],
                            // 默认煎药方式List
                            cookType1: this.picakIndex('id', res.data.defaultCookTypeID, this.cookType) // 默认煎药方式List
                        });
                    }
                }
            });
        },

        // 使用频次
        bindPickerChange3: function (e) {
            this.setData({
                frequence1: e.detail.value
            });
        },

        // 用药方法
        bindPickerChange4: function (e) {
            this.setData({
                usage1: e.detail.value
            });
        },

        // 煎药方式
        bindPickerChange5: function (e) {
            this.setData(
                {
                    cookType1: e.detail.value
                },
                () => {
                    let { cookType, cookType1 } = this;
                    this.bindPickerChange5Http(cookType[cookType1].id);
                }
            );
        },

        // 煎药方式Http
        bindPickerChange5Http: function (id) {
            let userData = Cache.get('userData');
            let { hospID } = userData;
            $http.post('urlDeault', this, {
                code: '02030115',
                data: {
                    params: [
                        {
                            hospID: hospID,
                            cookTypeID: id
                        }
                    ]
                },
                success: function (res) {
                    let errorCode = res.errorCode;
                    if (errorCode === '0') {
                        let locaID = '';
                        res.result.map((item, i) => {
                            if (item.defaultFlag === 'Y') {
                                locaID = item.id;
                            }
                        });
                        this.setData(
                            {
                                recLoc: res.result,
                                recLoc1: this.picakIndex('id', locaID, res.result)
                            },
                            () => {
                                let { recLoc1, recLoc } = this;
                                this.setData(
                                    {
                                        maxQty: recLoc[recLoc1].maxQty && recLoc[recLoc1].maxQty != '' ? recLoc[recLoc1].maxQty : '99999',
                                        minQty: recLoc[recLoc1].minQty && recLoc[recLoc1].minQty != '' ? recLoc[recLoc1].minQty : '0'
                                    },
                                    () => {
                                        if (this.stepper > this.maxQty) {
                                            this.setData({
                                                stepper: this.maxQty
                                            });
                                        }
                                    }
                                );
                            }
                        );
                    }
                }
            });
        },

        // 服用要求
        bindPickerChange6: function (e) {
            this.setData({
                usageExplain1: e.detail.value
            });
        },

        // 执行科室
        bindPickerChange7: function (e) {
            this.setData(
                {
                    recLoc1: e.detail.value
                },
                () => {
                    let { recLoc1, recLoc } = this;
                    this.setData({
                        maxQty: recLoc[recLoc1].maxQty && recLoc[recLoc1].maxQty != '' ? recLoc[recLoc1].maxQty : '99999',
                        minQty: recLoc[recLoc1].minQty && recLoc[recLoc1].minQty != '' ? recLoc[recLoc1].minQty : '0'
                    });
                }
            );
        },

        //用药步进器
        onChangeStepper: function (e) {
            this.setData({
                stepper: e.detail
            });
        },

        // 每次数量变化
        binddoseChange: function (e) {
            this.setData({
                sum: e.detail.value
            });
        },

        // 点击编辑
        addChangeEdit: function (e) {
            console.log(1);
            this.addChange(e);
        },

        // 点击添加
        addChange: function (e) {
            console.log(e);
            let { gList, recLoc, recLoc1, herbalForm, herbalForm1 } = this;
            if (!recLoc[recLoc1]) {
                Toast({
                    type: 'fail',
                    message: '请选择科室',
                    context: this
                });
                return false;
            }
            let url =
                '/pages/entryWrite/page/Entry/prescription/addPrescription/customDiagnostics/grass/grassPush/grassPush?gList=' +
                JSON.stringify(gList) +
                '&recLocID=' +
                recLoc[recLoc1].id +
                '&herbalFormID=' +
                herbalForm[herbalForm1].id;
            if (e) {
                url = url + '&e=' + JSON.stringify(e);
            }
            uni.navigateTo({
                //目的页面地址
                url: url
            });
        },

        // 点击删除
        tapRemove: function (event) {
            let { currentTarget } = event;
            let { gList } = this;
            let dataset = currentTarget.dataset;
            gList.splice(dataset.index, 1);
            this.setData({
                gList: gList || [] // 已添加草药
            });
        },

        // 清空
        clearnbtn: function (event) {
            this.setData({
                selectIndex1: '',
                frequence1: '',
                herbalForm1: '',
                usage1: '',
                cookType1: '',
                usageExplain1: '',
                recLoc1: '',
                stepper: '0',
                // 用药值
                sum: '',
                // 每次数量
                verification: 'N' // 验证
            });
        },

        // 保存
        objadd: function (event) {
            let {
                gList,
                selectIndex1,
                selectData1Fun: selectData1,
                //结算类型加载数据
                frequence1,
                frequence,
                //频次
                herbalForm1,
                herbalForm,
                //剂型
                usage1,
                usage,
                //用法
                cookType1,
                cookType,
                //煎药方式
                usageExplain1,
                usageExplain,
                //服用要求
                recLoc1,
                recLoc,
                //科室
                stepper,
                // 用药值
                sum // 每次数量
            } = this;
            let obj = {
                gList: gList,
                // 草药组
                selectData1: selectData1[selectIndex1] || {},
                //结算类型加载数据
                frequence: frequence[frequence1] || {},
                //频次
                herbalForm: herbalForm[herbalForm1] || {},
                //剂型
                usage: usage[usage1] || {},
                //用法
                cookType: cookType[cookType1] || {},
                //煎药方式
                usageExplain: usageExplain[usageExplain1] || {},
                //服用要求
                recLoc: recLoc[recLoc1] || {},
                //科室
                stepper: stepper || '',
                // 用药值
                sum: sum || '' // 每次数量
            };

            return obj;
        },

        // 保存
        addbtn: function (event) {
            this.setData({
                isLoading: true
            });
            let { gList } = this;
            let obj = this.objadd();
            console.log(gList);
            console.log(obj);
            let requireData = [
                {
                    message: '没有需要保存的医嘱',
                    value: gList
                },
                {
                    message: '结算类型不能为空',
                    value: obj.selectData1
                },
                {
                    message: '频次不能为空',
                    value: obj.frequence
                },
                {
                    message: '剂型不能为空',
                    value: obj.herbalForm
                },
                {
                    message: '用法不能为空',
                    value: obj.usage
                },
                {
                    message: '服用要求不能为空',
                    value: obj.usageExplain
                },
                {
                    message: '科室不能为空',
                    value: obj.recLoc
                }
            ];
            util.formRequire(requireData, (data) => {
                if (data && data.length > 0) {
                    this.setData({
                        isLoading: false
                    });
                    this.setData({
                        verification: 'Y'
                    });
                    Toast({
                        type: 'fail',
                        message: data[0].message,
                        context: this
                    });
                } else {
                    this.setData({
                        isLoading: false
                    });
                    let pages = getCurrentPages();
                    //上一个页面实例对象
                    let prevPage = pages[pages.length - 2];
                    //关键在这里
                    prevPage.callData2(obj);
                    uni.navigateBack({
                        delta: 1
                    });
                }
            });
        },

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

        // 去掉遮罩层
        showFun: function () {
            let { show1, show2 } = this;
            if (!show1 && !show2) {
                this.setData({
                    show: false
                });
            }
        }
    },
    created: function () {},
    watch: {
        gListcallData: {
            handler: function (newVal, oldVal) {
                this.gListcallDataClone = newVal;
            },

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

.diag-form {
    margin: 0 4rpx 12rpx;
    padding-bottom: 120rpx;
}

.my-cells {
    display: block;
    margin: 0;
    border-radius: 14rpx;
    overflow: hidden;
    background: #fff;
    box-shadow: 0 6rpx 18rpx rgba(15, 23, 42, 0.04);
}

.diag-form .weui-cell {
    min-height: 88rpx;
    padding: 16rpx 24rpx;
    align-items: center;
    box-sizing: border-box;
}

.diag-form .weui-cell__bd {
    width: 100%;
    min-width: 0;
}

.diag-form .weui-cell__ft {
    display: none;
}

.diag-form .weui-cell__ft:after {
    display: none;
}

.diag-form__cell {
    font-size: 28rpx !important;
    color: #1f2937;
}

.diag-form__line {
    width: 100%;
    min-height: 56rpx;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.diag-form__label {
    flex: 0 0 40%;
    max-width: 40%;
    color: #1f2937;
    font-size: 28rpx;
    font-weight: 500;
    line-height: 42rpx;
    text-align: left;
    box-sizing: border-box;
    padding-right: 20rpx;
    display: flex;
    align-items: center;
}

.diag-form__label--required:before {
    content: "*";
    color: #f5222d;
    margin-right: 4rpx;
}

.diag-form__picker {
    flex: 0 0 60%;
    max-width: 60%;
    color: #3f4a5a;
    min-height: 42rpx;
    line-height: 42rpx;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: right;
}

.diag-form__input-wrap {
    flex: 0 0 60%;
    max-width: 60%;
    min-height: 56rpx;
    display: flex;
    align-items: center;
    justify-content: flex-end;
}

.diag-form__input {
    width: 100%;
    min-height: 56rpx;
    line-height: 56rpx;
    text-align: right;
    color: #3f4a5a;
    font-size: 28rpx;
}

.diag-form__stepper-wrap {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10rpx;
}

.diag-form__stepper-wrap--right {
    flex: 0 0 60%;
    max-width: 60%;
    justify-content: flex-end;
}

.diag-form__actions {
    width: 100%;
    min-height: 76rpx;
    display: flex;
    align-items: center;
    gap: 14rpx;
    box-sizing: border-box;
    padding: 16rpx 24rpx;
}

.diag-form__actions--bottom {
    margin: 14rpx 4rpx 0;
    background: #fff;
    border-radius: 14rpx;
    box-shadow: 0 6rpx 18rpx rgba(15, 23, 42, 0.04);
}

.diag-form__action {
    flex: 1;
    height: 72rpx;
    line-height: 72rpx;
    border-radius: 12rpx !important;
    font-size: 30rpx;
    padding: 0;
    margin: 0;
    font-weight: normal;
}

.diag-form__action--plain {
    border: 1px solid #d8dee8;
    background: #fff;
    color: #1f2937;
}

.diag-form__action--primary {
    background-color: #1890ff;
    color: #ffffff;
    border: 0;
}

.diag-form__action:after {
    border: 0;
}

.grass-detail {
    margin: 14rpx 4rpx 0;
    background: #fff;
    border-radius: 14rpx;
    padding: 18rpx 24rpx;
    box-shadow: 0 6rpx 18rpx rgba(15, 23, 42, 0.04);
}

.grass-detail__header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 14rpx;
    border-bottom: 1rpx solid #edf1f6;
}

.grass-detail__title {
    color: #1f2937;
    font-weight: 600;
    font-size: 28rpx;
}

.grass-detail__title.required:before {
    content: "*";
    color: #f5222d;
    margin-right: 4rpx;
}

.grass-detail__add {
    color: #fff;
    background: #1890ff;
    border-radius: 999rpx;
    padding: 6rpx 22rpx;
    font-size: 25rpx;
    line-height: 36rpx;
}

.grass-detail__item {
    padding: 14rpx 0;
    border-bottom: 1rpx solid #edf1f6;
}

.grass-detail__item:last-child {
    border-bottom: 0;
}

.grass-detail__row {
    display: flex;
    align-items: center;
    gap: 12rpx;
}

.grass-detail__med {
    color: #1f2937;
    font-weight: 500;
    font-size: 28rpx;
}

.grass-detail__meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6rpx 18rpx;
    margin-top: 10rpx;
    color: #7b8794;
    font-size: 25rpx;
    line-height: 38rpx;
}

.grass-detail__actions {
    display: flex;
    justify-content: flex-end;
    gap: 14rpx;
    margin-top: 12rpx;
}

.grass-detail__btn {
    height: 56rpx;
    line-height: 56rpx;
    border-radius: 999rpx;
    font-size: 25rpx;
    padding: 0 24rpx;
    margin: 0;
}

.grass-detail__btn:after {
    border: 0;
}

.grass-detail__btn--remove {
    color: #f5222d;
    background: #fff;
    border: 1rpx solid #f5222d;
}

.grass-detail__btn--edit {
    color: #1687ff;
    background: #fff;
    border: 1rpx solid #1687ff;
}

.grass-detail__empty {
    text-align: center;
    color: #8b98a8;
    padding: 40rpx 0;
    font-size: 26rpx;
}

.wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
}

.redIcon {
    display: inline-block;
    vertical-align: middle;
    margin-left: 6rpx;
}
</style>
