<template>
  <view>
    <view style="height: 20px" />
    <Identity ref="Identity" />
    <basics ref="basics" />
    <pilotLamp ref="pilotLamp" itemW="21%" />
    <view class="control-title">设备参数</view>
    <preview ref="preview" />
    <control-panel ref="mpattern" />
  </view>
</template>

<script>
import controlPanel from "../prodnum-YK01/modules/controlPanel.vue";
import preview from "../prodnum-YK01/modules/preview.vue";
import pilotLamp from "../prodnum-MT03/modules/pilotLamp.vue";
import basics from "./modules/basics.vue";
import Identity from "./modules/Identity.vue";

export default {
  name: "prodnum-FW01",
  components: { controlPanel, pilotLamp, preview, Identity, basics },
  props: {
    control: Object,
  },
  watch: {
    control: function (newVal) {
      this.$refs.Identity.ctrlModel = this.__proto__.getControlItem(
        ["身份验证"],
        newVal
      )[0];
      this.$refs.Identity.bluetoothcode = newVal.bluetoothcode;
      if (newVal) {
        try {
          this.$refs.preview.list = [
            newVal.params["U002"],
            newVal.params["U003"],
          ];
        } catch (error) {
          console.error("FW01设备状态", error);
        }

        try {
          this.$refs.mpattern.itemList = this.__proto__.getControlItem(
            ["上传时间间隔", "开度变更提醒值", "阀门圈数", "当前阀门开度"],
            newVal
          );
        } catch (error) {
          console.error("FW01控制面板", error);
        }
        try {
          this.$refs.pilotLamp.list = [
            {
              name: "开度变动提醒",
              value: getBoole("A005"),
            },
            {
              name: "低电量提醒",
              value: getBoole("A002"),
            },
          ];

          if (getBoole("A005")) {
            this.$refs.basics.ctrlModel = this.__proto__.getControlItem(
              ["开度提醒复位"],
              newVal
            )[0];
            console.log("ctrlModel", this.$refs.basics.ctrlModel);
          }
          function getBoole(name, expect = 1) {
            try {
              return newVal.paramvalues[name] == expect;
            } catch (error) {
              console.log("getBoole取值出错项", name);
              return false;
            }
          }
        } catch (error) {
          console.error("FW01指示灯", error);
        }
        try {
          this.$Http.openNetwork(newVal.params.U004.lastvalue);
        } catch (error) {
          setTimeout(this.$Http.openNetwork(newVal.params.U004.lastvalue), 100);
          console.error("06信号强度", error);
        }
      } else {
      }
    },
  },
};
</script>
<style lang="scss" scoped>
/deep/.pilotLamp .item {
  width: 21% !important;
}
</style>