<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-if="preview" hover-class="navigator-hover" @click="onClick(preview.tar)">
            <view class="box">
                <view class="label">{{ preview.now.paramname || '' }}</view>
                <view class="content">
                    <view class="value">{{ preview.now.lastvalue || '--' }}</view>
                </view>
            </view>
            <view class="box">
                <view class="label">{{ preview.tar.funcname }}</view>
                <view class="content">
                    <view class="value">{{ preview.tar.params.lastvalue || '--' }}</view>
                    <view class="unit">{{ preview.tar.params.unit || '' }}</view>
                </view>
            </view>
            <view class="dot" v-if="preview.tar.isfeedback" />
        </view>

        <My_input ref="MyInput" />

    </view>
</template>

<script>
let model = null;
export default {
    name: "mpattern",
    data() {
        return {
            ctrlModel: {},
            preview: null
        }
    },
    methods: {
        onClick(item) {
            if (!model) model = this.$refs.MyInput;
            model.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>