<template>
    <view class="control">
        <view class="control-title">
            分时控制
        </view>
        <view class="update-line">
            <view class="label">
                {{ timeControl.funcname }}
            </view>
            <view class="content">
                {{ timeControl.showValue }}
                <view class="control-updata-but" hover-class="navigator-hover" @click="onClick(timeControl)">更新</view>
            </view>
        </view>
        <view class="row" hover-class="navigator-hover" v-for="item in list" :key="item.key" @click="onClick(item)">
            <view class="box">
                <view class="label">第{{ item.index }}时段时间</view>
                <view class="content">
                    <view class="value">{{ item.params["T" + item.index + "_T"].lastvalue || '--' }}</view>
                </view>
            </view>
            <view class="box">
                <view class="label">第{{ item.index }}时段压力</view>
                <view class="content">
                    <view class="value">{{ item.params["T" + item.index + "_P"].lastvalue || '--' }}</view>
                    <view class="unit">{{ item.params["T" + item.index + "_P"].unit || '' }}</view>
                </view>
            </view>
        </view>
        <My_input ref="MyInput" />
    </view>
</template>

<script>
let model = null;
export default {
    name: "division",
    data() {
        return {
            list: [],
            timeControl: {}
        }
    },
    methods: {
        loadData(funs, values, paramsList) {
            model = this.$refs.MyInput;
            let reg = /^T\d{1,5}_P$/,
                count = 0,
                list = [];
            for (const key in values) {
                if (reg.test(key)) count++
            }
            for (let i = 1; i <= count; i++) {
                let obj = funs[`T${i}`];
                list.push(Object.assign(obj, {
                    key: `T${i}_`,
                    index: i,
                    inputType: "dayParting",
                    paramValue: {
                        time: values[`T${i}_T`],
                        value: values[`T${i}_P`]
                    },
                    params: {
                        [`T${i}_T`]: paramsList[`T${i}_T`],
                        [`T${i}_P`]: paramsList[`T${i}_P`],
                    }
                }))
            }
            console.log(paramsList)
            console.log(list)
            this.list = list;
            this.timeControl = this.__proto__.getControlItem(["TimeControl"], funs, values, paramsList)[0]
        },
        onClick(item) {
            if (!model) model = this.$refs.MyInput;
            model.openInput(item)
        }
    }
}
</script>

<style lang="scss" scoped>
.row {
    display: flex;
    padding: 4px 6px 0;
    height: 60px;
    box-sizing: border-box;
    background: #fff;
    border-radius: 4px;
    margin-bottom: 5px;

    .box {
        width: 49%;

        .content {
            display: flex;
            margin-top: 10px;
            align-items: flex-end;

            .value {
                width: 0;
                flex: 1;
                color: #333;
                font-size: 16px;
                flex-shrink: 0;
                font-weight: bold;
            }

            .unit {
                font-size: 10px;
                color: #666;
                flex-shrink: 0;
                max-width: 50px;
            }
        }



    }
}
</style>