<template>
    <view class="container">
        <!-- 控制模式 -->
        <mpattern ref="mpattern" />
        <!-- 基础控制 -->
        <basics ref="basics" />
        <!-- 分时开关 -->
        <division ref="division" />
    </view>
</template>

<script>
import mpattern from './modules/mpattern.vue'
import basics from './modules/basics.vue'
import division from './modules/division.vue'
export default {
    name: "prodnum-06",
    components: { mpattern, basics, division },
    props: {
        control: Object
    },
    watch: {
        control: function (newVal) {
            if (newVal) {
                try {
                    let nameList = ['Flow control', 'pressure control', 'Config', 'Sleep time', 'Pilot valve', 'Minimum', 'MOP']
                    this.$refs.basics.itemList = this.__proto__.getControlItem(nameList, newVal)
                    this.$refs.basics.preview = ['Batt4', 'Batt12', 'BatFlow'].map(v => {
                        return newVal.params[v]
                    })
                } catch (error) {
                    console.error("06基础控制", error)
                }
                try {
                    let division = this.$refs.division;
                    division && division.loadData(newVal.function, newVal.paramcmdvalues, newVal.params, newVal.isfeedback)
                    division.timeControl = this.__proto__.getControlItem(["TimeControl"], newVal)[0]
                } catch (error) {
                    console.error("06分时控制", error)
                }
                try {
                    let ctrlModel = this.__proto__.getControlItem(['Ctrl'], newVal, { Ctrl: "radio" })[0]
                    this.$refs.mpattern.ctrlModel = ctrlModel;
                    let lastvalue = ctrlModel.params.lastvalue - 0;
                    this.$refs.mpattern.list = [{
                        now: newVal.params['DownP'],
                        tar: this.__proto__.getControlItem(['Downstream'], newVal)[0],
                        current: lastvalue == 1
                    }, {
                        now: newVal.params['NowFlow'],
                        tar: this.__proto__.getControlItem(['Constantflow'], newVal)[0],
                        current: lastvalue == 2
                    }, {
                        now: newVal.params['MostBad'],
                        tar: this.__proto__.getControlItem(['unfavorable'], newVal)[0],
                        current: lastvalue == 3
                    }];
                } catch (error) {
                    console.error("06控制模式", error)
                }
                try {
                    this.$Http.openNetwork(newVal.params.RSSI.lastvalue)
                } catch (error) {
                    setTimeout(this.$Http.openNetwork(newVal.params.RSSI.lastvalue), 100)
                    console.error("06信号强度", error)
                };
            } else {

            }
        }
    }
}
</script>