<template>
  <view class="control">
    <view class="update-line">
      <view class="label" :style="{ color: fColor }">
        {{ ctrlModel.funcname }}
      </view>
      <view class="content" :style="{ color: fColor }">
        <block v-if="ctrlModel.inputType == 'switch'">
          {{ switchRes(ctrlModel) }}
        </block>
        <block v-else>
          {{ ctrlModel.showValue || "暂未设置" }}
        </block>
        <view
          class="control-updata-but"
          hover-class="navigator-hover"
          @click="onClick(ctrlModel)"
          >{{ ctrlModel.isfeedback ? "待更新" : "更新" }}</view
        >
      </view>
    </view>

    <view class="update-line" v-for="item in list" :key="item.paramName">
      <view class="label" :style="{ color: fColor }">
        {{ item.funcname }}
      </view>
      <view class="content" :style="{ color: fColor }">
        <block v-if="item.inputType == 'switch'">
          {{ switchRes(item) }}
        </block>
        <block v-else>
          {{ item.paramValue || item.params.lastvalue || "暂未设置" }}
        </block>
        <view
          class="control-updata-but"
          hover-class="navigator-hover"
          @click="onClick(item)"
          >{{ item.isfeedback ? "待更新" : "更新" }}</view
        >
      </view>
    </view>

    <My_input ref="MyInput" />
  </view>
</template>

<script>
export default {
  name: "mpattern",
  props: {
    fColor: {
      type: String,
      value: "#FFF",
    },
  },
  data() {
    return {
      ctrlModel: {},
      list: [],
    };
  },
  computed: {
    switchRes: function () {
      return (item) => {
        try {
          if (item.showValue) return item.showValue;
          let value = item.paramValue || item.params.lastvalue,
            res = item.params.options.find((v) => v.value == value);
          return res ? res.label : "暂未设置";
        } catch (error) {}
      };
    },
  },
  methods: {
    onClick(item) {
      this.$refs.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>