<template>
    <view class="grass-push-page">
        <!-- pages/entryWrite/page/Entry/prescription/addPrescription/customDiagnostics/grass/grassPush/grassPush.wxml -->
        <nav-bar :navbarData="navbarData"></nav-bar>
        <view class="diagnosticEntry" :style="'margin-top: ' + (height * 2 + 10) + 'rpx; height: calc(100vh - ' + (height * 2 + 10) + 'rpx)'">
            <view class="boxTitle fontS30 topTitle">
                <text class="floatR addToList" @tap="addChange">{{ addText }}</text>
            </view>
            <mp-cells ext-class="my-cells">
                <mp-cell class="diag-form__cell" hover @tap.native="tapSelect">
                    <view class="diag-form__line">
                        <view class="diag-form__label diag-form__label--required">
                            草药名称
                            <view class="redIcon" v-if="!(verification === 'N' || (searchSelect && searchSelect.medDesc && searchSelect.medDesc !== ''))">
                                <van-icon name="warning" color="red" />
                            </view>
                        </view>
                        <view class="diag-form__picker">{{ (searchSelect && searchSelect.medDesc) || '请选择' }}</view>
                    </view>
                </mp-cell>
                <mp-cell class="diag-form__cell" hover>
                    <view class="diag-form__line">
                        <view class="diag-form__label diag-form__label--required">
                            单次剂量
                            <view class="redIcon" v-if="!(verification === 'N' || (jl && jl !== ''))">
                                <van-icon name="warning" color="red" />
                            </view>
                        </view>
                        <view class="diag-form__input-wrap">
                            <input class="diag-form__input" :focus="doseFocus" placeholder="请输入单次剂量" :value="jl" @input="bindnoteChange" type="digit" />
                        </view>
                    </view>
                </mp-cell>
                <picker @change="bindPickerChange2" :value="typeList1" :range="typeList" range-key="unitDesc">
                    <mp-cell class="diag-form__cell" hover>
                        <view class="diag-form__line">
                            <view class="diag-form__label diag-form__label--required">
                                剂量单位
                                <view
                                    class="redIcon"
                                    v-if="!(verification === 'N' || (typeList && typeList.length && typeList[typeList1] && typeList[typeList1].unitDesc && typeList[typeList1].unitDesc !== '' && typeList[typeList1].unitDesc !== '请选择'))"
                                >
                                    <van-icon name="warning" color="red" />
                                </view>
                            </view>
                            <view class="diag-form__picker">{{ (typeList && typeList.length && typeList[typeList1] && typeList[typeList1].unitDesc) || '请选择' }}</view>
                        </view>
                    </mp-cell>
                </picker>
                <picker @change="bindPickerChange1" :value="comPrinciple1" :range="comPrinciple" range-key="descripts">
                    <mp-cell class="diag-form__cell" hover>
                        <view class="diag-form__line">
                            <view class="diag-form__label">用药类型</view>
                            <view class="diag-form__picker">{{ (comPrinciple && comPrinciple.length && comPrinciple[comPrinciple1] && comPrinciple[comPrinciple1].descripts) || '请选择' }}</view>
                        </view>
                    </mp-cell>
                </picker>
                <picker @change="bindPickerChange3" :value="decoctMethod1" :range="decoctMethod" range-key="descripts">
                    <mp-cell class="diag-form__cell" hover>
                        <view class="diag-form__line">
                            <view class="diag-form__label">备注</view>
                            <view class="diag-form__picker">{{ (decoctMethod && decoctMethod.length && decoctMethod[decoctMethod1] && decoctMethod[decoctMethod1].descripts) || '请选择' }}</view>
                        </view>
                    </mp-cell>
                </picker>
            </mp-cells>
            <view class="box medList" v-if="selectIndex === ''">
                <view class="boxTitle fontS30 borderB2">
                    <text>已添加草药</text>
                </view>
                <view class="medData" v-for="(item, index) in gList" :key="index">
                    <view class="medInfo">
                        <view class="medDesc">
                            <text>{{ (item.searchSelect && item.searchSelect.medDesc) || '' }}</text>
                        </view>
                        <view class="medDetail">
                            <text class="detailInfo">剂量：{{ item.jl || '-' }} {{ (item.typeList && item.typeList.unitDesc) || '' }}</text>
                            <text class="detailInfo">用药类型：{{ (item.comPrinciple && item.comPrinciple.descripts) || '-' }}</text>
                            <text class="detailInfo">备注：{{ (item.decoctMethod && item.decoctMethod.descripts) || '-' }}</text>
                        </view>
                    </view>
                    <view class="medActions">
                        <view class="medAction medAction--edit" @tap="tapEdit" :data-index="index">
                            编辑
                        </view>
                        <view class="medAction medAction--del" @tap="tapRemove" :data-index="index">
                            删除
                        </view>
                    </view>
                </view>
                <view class="textCenter empty" v-if="gList.length <= 0">暂无添加草药</view>
            </view>
            <view class="col textCenter bottombtn" v-if="selectIndex === ''">
                <button class="saveTo" @tap="addbtn" :disabled="isLoading">{{ isLoading ? '保存中' : '保存' }}</button>
            </view>
        </view>
        <van-dialog id="van-dialog" />
        <van-toast id="van-toast" />
    </view>
</template>

<script>
import Cache from '../../../../../../../../../utils/cache';
import navBar from '@/pages/components/navbar/index';
// pages/entryWrite/page/Entry/prescription/addPrescription/customDiagnostics/grass/grassPush/grassPush.js
import { $http } from '../../../../../../../../../config/https';
import Toast from '../../../../../../../../../utils/toast';
import Dialog from '../../../../../../../../../utils/dialog';
import util from '../../../../../../../../../utils/util';
const app = getApp();
export default {
    components: {
        navBar
    },
    data() {
        return {
            medID: '',

            //   医嘱项id
            recLocID: '',

            //   执行科室id
            herbalFormID: '',

            //   剂型
            searchSelect: {
                medDesc: ''
            },

            //   选中的医嘱名称
            decoctMethod1: '',

            //备注
            decoctMethod: [],

            //备注
            comPrinciple1: '',

            //用药类型
            comPrinciple: [],

            //用药类型
            typeList1: '',

            //剂量单位
            typeList: [],

            //剂量单位
            jl: '',

            // 单次剂量
            gList: [],

            // 已添加草药
            selectIndex: '',

            // 当前编辑
            doseFocus: false,

            verification: 'N',

            // 验证
            editVis: 'N',

            // 编辑标识
            navbarData: {
                isGoBack: true,
                background: '',
                title: '添加草药',
                //导航栏 中间的标题
                bottom: false
            },

            height: app.globalData.height,
            addText: '添加到列表',
            isLoading: false,
            unitDesc: '',
            descripts: ''
        };
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        // 接收gList
        this.optionsUrl(options);
        this.searchSelectFun(); //获取选中的select数据
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {
        // 清除Storage
        // wx.removeStorageSync('searchSelect');
        this.selectData2(); // 其他下拉加载数据
        this.selectData3(); // 其他下拉加载数据
        console.log('onReady');
    },
    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        // 从草药选择页返回时，选择页已将选中数据写入 Storage('searchSelect')
        // grassPush 是 page，选择页通过 prevPage.searchSelect 回传，但 data.searchSelect 是对象不是方法，
        // 故这里改为从 Storage 取值（读后即删，避免重复触发）
        try {
            let searchSelectData = Cache.get('searchSelect');
            if (searchSelectData && searchSelectData.medID) {
                Cache.remove('searchSelect');
                this.searchSelectFun(searchSelectData);
            }
        } catch (e) {}
    },
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {},
    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {},
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {},
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {},
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {},
    methods: {
        // 获取选中的select数据
        searchSelectFun: function (selectData) {
            console.log(selectData);
            let searchSelect = selectData;
            if (searchSelect) {
                this.setData(
                    {
                        searchSelect,
                        medID: searchSelect.medID,
                        doseFocus: true
                    },
                    () => {
                        this.selectData2(); // 其他下拉加载数据
                        this.selectData3(); // 其他下拉加载数据
                    }
                );
            }
        },

        // 医嘱名称跳转select
        tapSelect: function (e) {
            let { herbalFormID } = this;
            uni.navigateTo({
                //目的页面地址
                url: '/pages/components/searchSelect/searchSelect?code=03050019&type=Y&herbalFormID=' + herbalFormID,
                success: function (res) {}
            });
        },

        // 其他下拉加载数据
        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(
                            {
                                decoctMethod: res.result.decoctMethod || [],
                                //备注
                                comPrinciple: res.result.comPrinciple || [] //配伍规则
                                // 默认值
                                // jl: res.result.defaultDoseQty || '', // 单次剂量
                            },
                            () => {
                                let { decoctMethod, comPrinciple } = this;
                                decoctMethod.unshift({
                                    descripts: '请选择'
                                });
                                comPrinciple.unshift({
                                    descripts: '请选择'
                                });
                                // 备注/用药类型不设默认值（非必填）
                                let decoctMethod1 = '';
                                let comPrinciple1 = '';
                                this.setData({
                                    decoctMethod,
                                    comPrinciple,
                                    decoctMethod1,
                                    comPrinciple1
                                });
                            }
                        );
                    }
                }
            });
        },

        // 获取医嘱项信息(草药)
        selectData3: function (e) {
            let userData = Cache.get('userData');
            let patientData = Cache.get('patientData');
            let { hospID, locID, userID, groupID } = userData;
            let { admID } = patientData;
            let { medID, recLocID } = this;
            $http.post('urlDeault', this, {
                code: '03050076',
                data: {
                    params: [
                        {
                            recLocID: recLocID || '',
                            groupID: groupID || '',
                            userID: userID || '',
                            locID: locID || '',
                            admID: admID || '',
                            hospID: hospID || '',
                            orders: [
                                {
                                    medID: medID || '',
                                    ordSetID: ''
                                }
                            ]
                        }
                    ]
                },
                success: function (res) {
                    let errorCode = res.errorCode;
                    let errorList = res.errorList[0];
                    let { selectIndex, gList, decoctMethod } = this;
                    if (errorCode === '0') {
                        if (errorList) {
                            if (errorList.errorMessage.indexOf('诊断') > -1) {
                                Dialog.confirm({
                                    title: '提示',
                                    confirmButtonText: '录入诊断',
                                    message: errorList.errorMessage
                                })
                                    .then(() => {
                                        // 历史诊疗
                                        uni.navigateTo({
                                            //目的页面地址
                                            url: '/pages/entryWrite/page/Entry/Entry?select=1&addText=添加诊断' // 历史诊疗,
                                        });
                                    })
                                    .catch(() => {
                                        // on cancel
                                    });
                            } else {
                                Dialog.alert({
                                    title: '提示',
                                    message: errorList.errorMessage,
                                    context: this
                                });
                            }
                            this.setData({
                                searchSelect: {} //   选中的医嘱名称
                            });

                            return false;
                        }
                        if (res.data[0]) {
                            // 修复：原代码 `let { searchSelectFun: searchSelect } = this` 取的是方法对象，
                            // 新增模式下 setData 会把方法对象赋给 data.searchSelect，覆盖选择页回传的正确值，
                            // 导致草药名称无法回显。改为新增模式直接使用 this.searchSelect。
                            let typeList1 =
                                selectIndex !== ''
                                    ? this.picakIndex('unitID', gList[selectIndex].typeList.unitID, res.data[0].qtyUnitList)
                                    : this.picakIndex('unitID', res.data[0].ordDoseUnitID, res.data[0].qtyUnitList);
                            // comPrinciple1 = selectIndex !== '' ? this.picakIndex('id', gList[selectIndex].comPrinciple.id, comPrinciple) : this.picakIndex('id', res.data[0].comPrincipleID, comPrinciple)
                            // 非必填项（备注）不设默认值，新增模式保持"请选择"
                            let decoctMethod1 = selectIndex !== '' ? this.picakIndex('id', gList[selectIndex].decoctMethod.id, decoctMethod) : '';
                            let searchSelect = selectIndex !== '' ? gList[selectIndex].searchSelect : this.searchSelect;
                            let jl = selectIndex !== '' ? gList[selectIndex].jl : this.jl;
                            this.setData({
                                typeList: (res.data[0] && res.data[0].qtyUnitList) || [],
                                //剂量单位
                                typeList1,
                                // comPrinciple1,
                                decoctMethod1,
                                searchSelect,
                                jl
                            });
                        }
                    }
                }
            });
        },

        // 剂量单位
        bindPickerChange1: function (e) {
            this.setData({
                comPrinciple1: e.detail.value
            });
        },

        // 用药类型
        bindPickerChange2: function (e) {
            this.setData({
                typeList1: e.detail.value
            });
        },

        // 备注
        bindPickerChange3: function (e) {
            this.setData({
                decoctMethod1: e.detail.value
            });
        },

        // 单次剂量
        bindnoteChange: function (e) {
            this.setData({
                jl: e.detail.value
            });
        },

        // 添加列表
        addChange: function (e) {
            let { gList, searchSelect, decoctMethod1, decoctMethod, comPrinciple1, comPrinciple, typeList, typeList1, jl, selectIndex } = this;
            let requireData = [
                {
                    message: '请先选择草药',
                    value: searchSelect
                },
                {
                    message: '剂量不能为空',
                    value: jl
                },
                {
                    message: '剂量单位不能为空',
                    value: typeList[typeList1] && typeList[typeList1].unitDesc === '请选择' ? {} : typeList[typeList1]
                }
            ];
            util.formRequire(requireData, (data) => {
                if (data && data.length > 0) {
                    this.setData({
                        verification: 'Y'
                    });
                    Toast({
                        type: 'fail',
                        message: data[0].message,
                        context: this
                    });
                } else {
                    if (selectIndex === '') {
                        var fitArr = gList.filter((item, i) => {
                            return item.searchSelect.medID === searchSelect.medID;
                        });
                        if (fitArr.length > 0) {
                            Toast({
                                type: 'fail',
                                message: '已添加该草药',
                                context: this
                            });
                            return;
                        }
                        console.log(decoctMethod[decoctMethod1]);
                        gList.unshift({
                            searchSelect: searchSelect,
                            decoctMethod: decoctMethod[decoctMethod1] && decoctMethod[decoctMethod1].descripts !== '请选择' ? decoctMethod[decoctMethod1] : {},
                            //备注
                            comPrinciple: comPrinciple[comPrinciple1] && comPrinciple[comPrinciple1].descripts !== '请选择' ? comPrinciple[comPrinciple1] : {},
                            //用药类型
                            typeList: typeList[typeList1] && typeList[typeList1].unitDesc !== '请选择' ? typeList[typeList1] : {},
                            //剂量单位
                            qtyUnitList: typeList || [],
                            //完整剂量单位列表，供保存接口使用
                            jl: jl || '' // 单次剂量
                        });
                    } else {
                        gList[selectIndex].searchSelect = searchSelect;
                        gList[selectIndex].decoctMethod = decoctMethod[decoctMethod1] && decoctMethod[decoctMethod1].descripts !== '请选择' ? decoctMethod[decoctMethod1] : {}; //备注
                        gList[selectIndex].comPrinciple = comPrinciple[comPrinciple1] && comPrinciple[comPrinciple1].descripts !== '请选择' ? comPrinciple[comPrinciple1] : {};
                        gList[selectIndex].typeList = typeList[typeList1] && typeList[typeList1].unitDesc !== '请选择' ? typeList[typeList1] : {};
                        gList[selectIndex].qtyUnitList = typeList || [];
                        gList[selectIndex].jl = jl;
                    }
                    let { navbarData } = this;
                    navbarData.title = '保存草药';
                    this.setData(
                        {
                            navbarData,
                            addText: '添加到列表',
                            gList,
                            selectIndex: '',
                            medID: '',
                            //   医嘱项id
                            searchSelect: {},
                            //   选中的医嘱名称
                            decoctMethod1: '',
                            //备注
                            comPrinciple1: '',
                            //用药类型
                            typeList1: '',
                            //剂量单位
                            typeList: [],
                            //剂量单位
                            jl: '' // 单次剂量
                        },
                        () => {
                            let { editVis } = this;
                            if (editVis === 'Y') {
                                this.addbtn(); // 保存
                            }
                        }
                    );
                }
            });
        },

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

        // 保存
        addbtn: function (event) {
            this.setData({
                isLoading: true
            });
            let { gList } = this;
            if (gList.length == 0) {
                this.setData({
                    isLoading: false
                });
                Toast({
                    type: 'fail',
                    message: '未添加草药',
                    context: this
                });
                return false;
            }
            this.setData({
                medID: '',
                //   医嘱项id
                recLocID: '',
                //   执行科室id
                searchSelect: {},
                //   选中的医嘱名称
                decoctMethod1: '',
                //备注
                comPrinciple1: '',
                //用药类型
                typeList1: '',
                //剂量单位
                typeList: [],
                //剂量单位
                jl: '' // 单次剂量
            });

            let pages = getCurrentPages();
            //上一个页面实例对象
            let prevPage = pages[pages.length - 2];
            //关键在这里
            // 修复：grassPush 由 grass 组件 navigateTo 打开，prevPage 是祖父 page（addPrescription），
            // 原代码 prevPage.callData(gList) 调用的方法在 page 上不存在，导致保存无反应。
            // 改为调用祖父 page 的 setGListPush，由它转发给 customDiagnostics → grass 组件回填 gList。
            let target = prevPage && (prevPage.$vm || prevPage);
            if (target && typeof target.setGListPush === 'function') {
                target.setGListPush(gList);
            } else if (target && typeof target.callData === 'function') {
                // 兼容老链路
                target.callData(gList);
            }
            this.setData({
                isLoading: false
            });
            uni.navigateBack({
                delta: 1
            });
        },

        // 接收 url传参
        optionsUrl: function (options) {
            let gList = JSON.parse(options.gList); //解析得到对象
            let recLocID = JSON.parse(options.recLocID); //科室ID
            let herbalFormID = JSON.parse(options.herbalFormID); //剂型
            let e = JSON.parse(options.e); //编辑
            let { index } = e.currentTarget.dataset;
            console.log(index);
            if (index || index === 0) {
                // 编辑进来

                let { navbarData, addText } = this;
                navbarData.title = '编辑草药';
                this.setData({
                    navbarData,
                    editVis: 'Y',
                    addText: '保存'
                });
            }
            this.setData(
                {
                    gList,
                    recLocID,
                    herbalFormID
                },
                () => {
                    this.tapEdit(e);
                }
            );
        },

        // 获取索引值picker
        picakIndex: function (name, id, arr) {
            // 兜底：arr 为空/未找到匹配项/ id 为空时默认返回 0（第一项）
            if (!arr || !arr.length) {
                return 0;
            }
            if (id === '' || id === null || id === undefined) {
                return 0;
            }
            for (let i = 0; i < arr.length; i++) {
                if (arr[i] && arr[i][name] == id) {
                    return parseInt(i, 10);
                }
            }
            return 0;
        },

        // 编辑
        tapEdit: function (e) {
            let { gList } = this;
            let selectIndex = e.currentTarget.dataset.index;
            console.log(e);
            if (!gList[selectIndex]) {
                return false;
            }
            this.setData(
                {
                    medID: gList[selectIndex].searchSelect.medID,
                    selectIndex
                },
                () => {
                    let { navbarData } = this;
                    navbarData.title = '编辑草药';
                    this.setData({
                        navbarData,
                        addText: '保存'
                    });
                    this.selectData3();
                }
            );
            // console.log(gList[selectIndex])
        }
    }
};
</script>
<style>
/* @import '../../../../../diagnostic/addDiagnostic/customDiagnostics/customDiagnostics.css'; */
/* @import '../../../../../diagnostic/diagnostic.css'; */

page {
    height: 100%;
}

.topTitle {
    height: 80rpx;
    line-height: 80rpx;
    padding: 0;
}

.addtext {
    color: #fff;
    padding: 5rpx 10rpx;
    background: #1890ff;
    border-radius: 8rpx;
}

.addToList {
    color: #fff;
    padding: 0 10rpx;
    background: #1890ff;
    height: 100%;
    line-height: 80rpx;
    min-width: 200rpx;
    text-align: center;
}

.detailInfo {
    padding: 6rpx 16rpx 6rpx 0;
    color: #909399;
    font-size: 24rpx;
    line-height: 1.4;
    display: block;
}

.medList {
    height: calc(100% - 80rpx - 456rpx - 100rpx);
    margin: 10rpx 0;
    overflow: auto;
    box-sizing: border-box;
}

.empty {
    height: 300rpx;
    line-height: 300rpx;
}

.medData {
    border-bottom: 1rpx solid #eee;
    display: flex;
    align-items: center;
    padding: 16rpx 20rpx;
    background: #fff;
}

.medInfo {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.medDesc {
    padding: 0;
    margin-right: 20rpx;
    height: 56rpx;
    line-height: 56rpx;
    font-size: 30rpx;
    color: #1f2937;
    font-weight: 500;
}

.medDetail {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
}

.medActions {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    margin-left: 10rpx;
    overflow: visible;
    color: #1890ff;
}

.medAction {
    width: 80rpx;
    height: 80rpx;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: visible;
    line-height: 1;
}

.medAction--edit {
    margin-right: 8rpx;
}

.bottombtn {
    height: 100rpx;
    font-size: 30rpx;
    color: #fff;
    padding: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
}

.saveTo {
    flex: 1;
    align-items: center;
    justify-content: center;
    display: flex;
    background-color: #1890ff;
    color: #fff;
    border-radius: 0 !important;
}

.redIcon {
    display: inline-block;
    vertical-align: middle;
}

/* 表单一行布局：标题与内容横向排列不换行 */
.my-cells .weui-cell__ft:after {
    display: none;
}

.my-cells .weui-cell__bd {
    width: 100%;
}

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

.diag-form__line {
    width: 100%;
    min-height: 66rpx;
    box-sizing: border-box;
    padding-right:8rpx;
    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;
}
/* 页面布局：与处方录入页保持一致的卡片间距与底部操作区。 */
page {
    background: #f4f7fb;
}

.grass-push-page {
    height: 100%;
    background: #f4f7fb;
}

.grass-push-page .diagnosticEntry {
    width: 100%;
    min-height: 0;
    padding: 16rpx 24rpx 136rpx;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    background: #f4f7fb;
}

.grass-push-page .topTitle {
    height: 72rpx;
    min-height: 72rpx;
    margin: 0 0 12rpx;
    padding: 0;
    border: 0;
    display: flex;
    align-items: center;
    justify-content: flex-end;
}

.grass-push-page .addToList {
    float: none;
    min-width: 176rpx;
    height: 64rpx;
    padding: 0 24rpx;
    box-sizing: border-box;
    line-height: 64rpx;
    border-radius: 12rpx;
    background: #1687ff;
    font-size: 26rpx;
    font-weight: 500;
    box-shadow: 0 6rpx 14rpx rgba(22, 135, 255, 0.2);
}

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

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

.grass-push-page .my-cells .weui-cell__bd {
    min-width: 0;
}

.grass-push-page .medList {
    flex: 1;
    min-height: 0;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    border-radius: 14rpx;
    background: #fff;
    box-shadow: 0 6rpx 18rpx rgba(15, 23, 42, 0.04);
}

.grass-push-page .medList .boxTitle {
    min-height: 76rpx;
    padding: 0 24rpx;
    flex: 0 0 auto;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    border-bottom: 1rpx solid #eef1f5;
    color: #1f2937;
    font-size: 28rpx;
    font-weight: 600;
    background: #fff;
}

.grass-push-page .empty {
    flex: 1;
    min-height: 220rpx;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #97a1b1;
    font-size: 26rpx;
}

.grass-push-page .medData {
    padding: 20rpx 24rpx;
    border-bottom-color: #eef1f5;
}

.grass-push-page .medDesc {
    height: 48rpx;
    margin-right: 12rpx;
    line-height: 48rpx;
    font-weight: 600;
}

.grass-push-page .detailInfo {
    padding: 4rpx 16rpx 4rpx 0;
    color: #9099a8;
    line-height: 1.45;
}

.grass-push-page .medActions {
    margin-left: 16rpx;
}

.grass-push-page .medAction {
    width: 76rpx;
    height: 52rpx;
    box-sizing: border-box;
    line-height: 52rpx;
    border-radius: 8rpx;
    font-size: 24rpx;
}

.grass-push-page .medAction--edit {
    margin-right: 10rpx;
    color: #1687ff;
    background: #edf6ff;
}

.grass-push-page .medAction--del {
    color: #f05252;
    background: #fff1f0;
}

.grass-push-page .bottombtn {
    height: 88rpx;
    padding: 0;
    bottom: calc(20rpx + env(safe-area-inset-bottom));
    left: 24rpx;
    right: 24rpx;
    z-index: 10;
}

.grass-push-page .saveTo {
    background-color: #1687ff;
    border-radius: 12rpx !important;
    font-size: 30rpx;
    font-weight: 500;
    box-shadow: 0 8rpx 18rpx rgba(22, 135, 255, 0.22);
}
</style>
