<template>
    <view class="control">
        <view class="control-title">
            控制模式
        </view>
        <view class="update-line">
            <view class="label">
                {{ ctrlModel.funcname }}
            </view>
            <view class="content">
                {{ ctrlModel.showValue }}
                <view class="control-updata-but" hover-class="navigator-hover" @click="onClick(ctrlModel)">{{
                    ctrlModel.isfeedback ? '待更新' : '更新' }}</view>
            </view>
        </view>
        <view class="row" v-for="item in list" :key="item.now.paramname" :style="{ 'opacity': item.current ? 1 : .8 }"
            hover-class="navigator-hover" @click="onClick(item.tar)">
            <view class="box">
                <view class="label">{{ item.now.paramname || '' }}</view>
                <view class="content">
                    <view class="value">{{ item.now.lastvalue || '--' }}</view>
                </view>
            </view>
            <view class="box">
                <view class="label">{{ item.tar.funcname }}</view>
                <view class="content">
                    <view class="value">{{ item.tar.params.lastvalue || '--' }}</view>
                    <view class="unit">{{ item.tar.params.unit || '' }}</view>
                </view>
            </view>
            <view class="dot" v-if="item.tar.isfeedback" />
        </view>
        <My_input ref="MyInput" />
    </view>
</template>

<script>
export default {
    name: "mpattern",
    data() {
        return {
            ctrlModel: {},
            list: []
        }
    },
    methods: {
        onClick(item) {
            let MyInput = this.$refs.MyInput;
            console.log(item)
            if (item.paramName == 'ConMode') {
                MyInput.checkBeforeSending = (w_functionid, params) => {
                    let tar = this.list[params.ConMode - 1].tar;
                    let lastvalue = tar.params.lastvalue - 0;
                    if (lastvalue == 0) {
                        uni.showModal({
                            title: '提示',
                            content: `"${tar.funcname}"值为"0",不可修改为"${this.ctrlModel.params.options.find(v => v.value == params.ConMode).label}"模式`,
                            showCancel: false,
                        })
                    } else {
                        MyInput.checkBeforeSending = null;
                        MyInput.submit(w_functionid, params)
                    }
                }
            }
            MyInput.openInput(item)
        }
    }
}
</script>

<style lang="scss" scoped>
.row {

    position: relative;
    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;
            }
        }
    }

    .dot {
        position: absolute;
        right: 2px;
        top: 2px;
        width: 10px;
        height: 10px;
        background: #D9001B;
        border-radius: 50%;
    }
}
</style>