<template>
    <view>
        <view class="control-title">控制面板</view>
        <pilotLamp ref="pilotLamp" />
        <view style="height: 20px;" />
        <mpattern ref="控制方式" />
        <tabs :control="control" />
        <division ref="division" />
    </view>
</template>

<script>
import mpattern from "./modules/mpattern"
import tabs from "./modules/tabs"
import pilotLamp from "./modules/pilotLamp"
import division from "./modules/division"
export default {
    name: 'prodnum-MT03',
    components: { mpattern, tabs, pilotLamp, division },
    props: {
        control: Object
    },
    watch: {
        control: function (newVal) {
            if (newVal) {
                console.log('MT03', newVal)
                try {
                    this.$refs.pilotLamp.list = [{
                        name: "就地",
                        value: getBoole('执行器就地_远程信号', 0)
                    }, {
                        name: "远程",
                        value: getBoole('执行器就地_远程信号')
                    }, {
                        name: "开到位",
                        value: getBoole('开到位')
                    }, {
                        name: "关到位",
                        value: getBoole('关到位')
                    }, {
                        name: "故障位",
                        value: getBoole('故障')
                    }, {
                        name: "失压警告",
                        value: getBoole('失压警告')
                    }, {
                        name: "失压报警",
                        value: getBoole('失压报警')
                    }, {
                        name: "超流量警告",
                        value: getBoole('超流量警告')
                    }, {
                        name: "超流量报警",
                        value: getBoole('超流量报警')
                    }, {
                        name: "强制关断",
                        value: getBoole('强制关断')
                    }, {
                        name: "阀门故障",
                        value: getBoole('阀门故障')
                    }, {
                        name: "PLC电量低报警",
                        value: getBoole('PLC电量低报警')
                    }]
                    function getBoole(name, expect = 1) {
                        try {
                            return newVal.paramvalues[name] == expect
                        } catch (error) {
                            console.error("getBoole取值出错项", name)
                            return false
                        }
                    }
                    console.log(this.$refs.pilotLamp.list)
                } catch (error) {
                    console.error("MT03指示灯", error)
                }
                try {
                    this.$refs.控制方式.ctrlModel = this.__proto__.getControlItem(['控制方式'], newVal, { Ctrl: "radio" })[0];
                    if (this.$refs.控制方式.ctrlModel.showValue == '自动调节') {
                        let arr = [this.__proto__.getControlItem(['自动控制'], newVal, { '自动控制': "switch" })[0]];
                        if (arr[0].params.lastvalue == 0) arr.push(this.__proto__.getControlItem(['手动流量设置'], newVal)[0])
                        this.$refs.控制方式.list = arr;
                    } else {
                        this.$refs.控制方式.list = [this.__proto__.getControlItem(['手动开度设置'], newVal)[0]]
                    }
                    console.log(this.$refs.控制方式.list)
                } catch (error) {
                    console.error("MT03控制方式", error)
                }
                try {
                    let division = this.$refs.division;
                    division && division.loadData(newVal, true)
                } catch (error) {
                    console.error("MT03分时控制", error)
                }
            } else {

            }
        }
    },
    data() {
        return {

        }
    },
}
</script>

<style></style>