<template>
    <!-- pages/Entry/prescription/addPrescription/customDiagnostics/customDiagnostics.wxml -->
    <view class="diagnostic-wrapper" disabled>
        <view v-if="active == 0">
            <western ref="western" id="western" :wListData="wListData" :editData="editData" @addInfo="addInfo($event, { tagId: 'western' })" />
        </view>
        <view v-if="active == 1">
            <grass ref="grass" :gListcallData="gListcallData" :gListData="gListData" :editData="editData" @addInfo="addInfo" />
        </view>
    </view>
</template>

<script>
import grass from './grass/grass';
import western from './western/western';
// pages/Entry/prescription/addPrescription/customDiagnostics/customDiagnostics.js
export default {
    components: {
        grass,
        western
    },
    data() {
        return {};
    },
    /**
     * 可以使用全局样式
     */
    options: {
        addGlobalClass: true
    },
    /**
     * 组件的属性列表
     */
    props: {
        wListData: {
            type: Array,
            //类型
            default: () => [] //默认值
        },

        gListData: {
            type: Array,
            //类型
            default: () => [] //默认值
        },

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

        active: {
            type: Number,
            //类型
            default: 0 //默认值
        },

        editData: {
            type: Object,
            //类型
            default: () => ({}) //默认值
        }
    },
    mounted() {
        // 处理小程序 attached 生命周期
        this.attached();
        // 处理小程序 ready 生命周期
        this.$nextTick(() => this.ready());
    },
    destroyed: function () {
        // 在组件实例被从页面节点树移除时执行
    },
    /**
     * 组件的方法列表
     */
    methods: {
        ready: function (options) {
            console.log(this.gListData);
        },

        attached: function () {},

        // 获取子组件参数
        // 西药 草药
        addInfo(e, _dataset) {
            /* ---处理dataset begin--- */
            this.handleDataset(e, _dataset);
            /* ---处理dataset end--- */
            this.$emit('addInfo', {
                detail: e.detail
            }); //通过triggerEvent将参数传给父组件
        },

        searchSelect: function (selectData) {
            // H5 + Vue3 下 zpSelectComponent 通过 vnode.data.attrs.id 查找子组件不稳定,
            // 优先使用 Vue $refs 进行子组件调用,且 western 内部方法为 searchSelectFun。
            let child = (this.$refs && this.$refs.western) || null;
            if (!child && typeof this.zpSelectComponent === 'function') {
                try {
                    child = this.zpSelectComponent('#western');
                } catch (e) {
                    child = null;
                }
            }
            if (child && typeof child.searchSelectFun === 'function') {
                child.searchSelectFun(selectData);
            } else if (child && typeof child.searchSelect === 'function') {
                child.searchSelect(selectData);
            }
        }
    },
    created: function () {}
};
</script>
<style>
/* @import '../../../diagnostic/addDiagnostic/customDiagnostics/customDiagnostics.css'; */

.overlay {
    position: fixed;
    top: 328rpx;
    left: 0;
    z-index: 1;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
}
</style>
