<template>
  <view>
    <view class="control-title">控制面板</view>
    <pilotLamp ref="pilotLamp" />
    <view style="height: 20px" />
    <mpattern ref="阀门工作状态" />
    <tabs :control="control" />
    <division ref="division" />
  </view>
</template>

<script>
import mpattern from "./modules/mpattern";
import tabs from "./modules/tabs";
import pilotLamp from "./modules/pilotLamp";
import division from "./modules/division";
export default {
  name: "prodnum-MT01",
  components: { mpattern, tabs, pilotLamp, division },
  props: {
    control: Object,
  },
  watch: {
    control: function (newVal) {
      if (newVal) {
        console.log("MT01", newVal);
        try {
          this.$refs.pilotLamp.list = [
            {
              name: "就地",
              value: getBoole("S002", 0),
            },
            {
              name: "远程",
              value: getBoole("S002")
            },
            {
              name: "开到位",
              value: getBoole("S004"),
            },
            {
              name: "关到位",
              value: getBoole("S003"),
            },
            {
              name: "过扭故障",
              value: getBoole("A001"),
              warn: true,
            },
            {
              name: "失压警告",
              value: getBoole("A003"),
              warn: true,
            },
            {
              name: "失压报警",
              value: getBoole("A004"),
              warn: true,
            },
            {
              name: "电量低报警",
              value: getBoole("A002"),
              warn: true,
            },
          ];
          function getBoole(name, expect = 1) {
            try {
              return newVal.paramvalues[name] == expect;
            } catch (error) {
              console.error("getBoole取值出错项", name);
              return false;
            }
          }
        } catch (error) {
          console.error("MT01指示灯", error);
        }
        try {
          this.$refs.阀门工作状态.ctrlModel = this.__proto__.getControlItem(
            ["阀门工作状态"],
            newVal,
            { 阀门工作状态: "radio" }
          )[0];
          switch (this.$refs.阀门工作状态.ctrlModel.showValue) {
            case "手动控制":
              this.$refs.阀门工作状态.list = [
                this.__proto__.getControlItem(["手动开度设置"], newVal)[0],
              ];
              break;
            case "自动调节":
              this.$refs.阀门工作状态.list = [
                this.__proto__.getControlItem(["手动压力设置"], newVal)[0],
              ];
              break;
            default:
              this.$refs.阀门工作状态.list = [];
              break;
          }
          console.log(
            "this.$refs.阀门工作状态.list",
            this.$refs.阀门工作状态.list
          );
        } catch (error) {
          console.error("MT01阀门工作状态", error);
        }
        try {
          let division = this.$refs.division;
          division && division.loadData(newVal);
        } catch (error) {
          console.error("MT01分时控制", error);
        }
      }
    },
  },
  data() {
    return {};
  },
};
</script>

<style></style>