<template>
  <div>
    <div class="app-container home">
      <div id="cesiumContainer">
        <div class="center-title-box">
          <div class="control-state">
            <!-- 简化class绑定语法 -->
            <p :class="{ active: intelligentControl.value == 0 }">
              <span class="icon-img"></span>
              <span>{{ intelligentControl.name }}</span>
            </p>
          </div>
          <!-- 优化为数据驱动循环 -->
          <div
            class="title-box"
            v-for="(item, index) in sumpData"
            :key="index"
            :class="['top', 'center', 'bottom'][index]"
          >
            <p class="title">
              液体高度:{{ item | sumpFilter("heghtThreshold") }}m
            </p>
            <p class="name">{{ item | sumpFilter("sumpName") }}</p>
          </div>
        </div>
        <div
          class="water-pump"
          v-for="(item, i) in pumpList"
          :key="item.pumpId || `pump_${i}`"
          :class="`pst${Number(item.locationNum) - 3}`"
        >
          <div class="H36">
            <div
              class="button on"
              :class="item.status == 1 ? 'active' : ''"
              @click="openWaterPump(item, 1)"
            >
              开启
            </div>
            <div
              class="button off"
              :class="item.status == 0 ? 'active' : ''"
              @click="closeWaterPump(item, 0)"
            >
              关闭
            </div>
          </div>
          <div class="H164">
            <div
              class="phd-left"
              v-show="[5, 6, 1, 2].includes(Number(item.locationNum) - 3)"
            ></div>
            <div class="phd-right">
              <div class="phd-top"></div>
              <div
                class=""
                :class="
                  [5, 6, 1, 2].includes(Number(item.locationNum) - 3)
                    ? 'water-pump-img-left'
                    : 'water-pump-img-right'
                "
              >
                <div
                  class="tip-box"
                  :class="
                    [5, 6, 1, 2].includes(Number(item.locationNum) - 3)
                      ? 'dw'
                      : 'dwr'
                  "
                >
                  <p>点击电流：{{ item.motorCurrent }}A</p>
                  <p>电机轴承温度：{{ item.motorBearingTemp }}℃</p>
                  <p>水泵轴承温度：{{ item.pumpBearingTemp }}℃</p>
                  <p>水泵流量：{{ item.pumpFlow }}</p>
                  <p>排水管路压力：{{ item.drainagePressure }}</p>
                </div>
              </div>
              <p>{{ item.pumpName }}</p>
            </div>
            <div
              class="phd-left"
              v-show="[7, 3, 4].includes(Number(item.locationNum) - 3)"
            ></div>
          </div>
        </div>
      </div>
    </div>
    <div class="up-window" v-show="upWindowShow">
      <div class="up-window-box">
        <p><span></span>开启/关闭水泵</p>
        <i class="el-icon-close close-button" @click="upWindowShow = false"></i>
        <div class="W400">
          <span>请输入密码</span>
          <el-input placeholder="" v-model="password" show-password></el-input>
        </div>
        <div>
          <div class="button close" @click="upWindowShow = false">取消</div>
          <div class="button" @click="submitPumpPassword()">确认</div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { getDraData, updatePumpSwitch } from "@/api/tyler/psxt.js";
export default {
  name: "psxt",
  data() {
    return {
      password: "",
      upWindowShow: false,
      pumpId: "",
      intelligentControl: {},
      pumpList: [
        {
          pumpId: 1,
          pumpName: "5#水泵",
          pumpStatus: 1,
        },
      ],
      sumpData: [],
      pumpList: [],
      pumpStatus: 0, //水泵状态
    };
  },
  created() {
    this.initPumpList();
  },
  methods: {
    initPumpList() {
      getDraData().then((res) => {
        //水池数据
        if (res.code == 200) {
          this.sumpData = res.data[0].value;
          this.pumpList = res.data[1].value;
          this.intelligentControl = res.data[2];
        } else {
          this.$modal.msgError(res.message);
        }
      });
    },
    // 水泵开启按钮
    openWaterPump(item, status) {
      this.upWindowShow = true;
      // this.submitPumpPassword(pumpId, this.password, 0);
      this.pumpId = item.pumpId;
      this.pumpStatus = status;
    },
    // 水泵关闭按钮
    closeWaterPump(item, status) {
      this.upWindowShow = true;
      this.pumpId = item.pumpId;
      this.pumpStatus = status;

      this.password = "";
    },
    //提交水泵密码
    submitPumpPassword() {
      let pumpId = this.pumpId;
      let password = this.password;
      if (!password) {
        return this.$modal.msgError("请输入密码");
      }
      updatePumpSwitch({ pumpId, password, status: this.pumpStatus }).then(
        (res) => {
          if (res.code === 200) {
            this.upWindowShow = false;
            this.password = "";
            this.$modal.msgSuccess(res.msg);
            this.initPumpList();
          } else {
            this.$modal.msgError(res.msg);
          }
        }
      );
    },
  },
  filters: {
    // 水池显示数据过滤
    sumpFilter(item, key) {
      // 优化过滤逻辑
      return item?.[key] || "--";
    },
  },
};
</script>

<style scoped lang="scss">
.home {
  width: 100%;
  height: 100%;
  background: url("~@/assets/images/screen/psxt/bg.png") no-repeat center;
  display: flex;
  justify-content: center;
  padding-top: 155px;
  #cesiumContainer {
    width: 1800px;
    height: 745px;
    background: url("~@/assets/images/screen/psxt/gd.png") no-repeat center;
    background-size: 1800px 745px;
    position: relative;
    .center-title-box {
      width: 200px;
      height: 100%;
      margin: auto;
      position: relative;
      .control-state {
        width: 260px;
        height: 44px;
        background: url("~@/assets/images/screen/psxt/bg1.png") no-repeat center;
        background-size: 100% 100%;
        position: absolute;
        top: 33px;
        left: 342px;
        p {
          font-weight: 400;
          font-size: 20px;
          color: #ffd929;
          line-height: 44px;
          margin: 0px;
          text-align: center;
          .icon-img {
            background: url("~@/assets/images/screen/psxt/icon1.png") no-repeat
              center;
            width: 20px;
            height: 20px;
            display: inline-block;
            margin-bottom: -4px;
            margin-right: 10px;
          }
          &.active {
            color: #e1e1e1;
            .icon-img {
              background: url("~@/assets/images/screen/psxt/icon3.png")
                no-repeat center;
            }
          }
        }
      }
      .title-box {
        text-align: center;
        .title {
          font-family: Source Han Sans SC;
          font-weight: 400;
          font-size: 18px;
          color: #11e0ff;
        }
        .name {
          font-weight: 400;
          font-size: 20px;
          color: #ffffff;
        }
      }
      .top {
        margin-top: -35px;
      }
      .center {
        margin-top: 273px;
      }
      .bottom {
        margin-top: 270px;
      }
    }
    .water-pump {
      position: absolute;
      width: 172px;
      height: 200px;
      // background: #ffffff;
      .H36 {
        height: 36px;
        .button {
          width: 86px;
          height: 36px;
          float: left;
          line-height: 36px;
          text-align: center;
          font-weight: bold;
          font-size: 18px;
          color: #96aeba;
          line-height: 32px;
          text-shadow: 0px 1px 4px rgba(5, 38, 68, 0.73);
          border: 2px solid #d8efff;
          border-radius: 2px;
          background: RGBA(0, 26, 49, 1);
          cursor: pointer;
        }
        .on {
          &.active {
            background: url("~@/assets/images/screen/psxt/button.png") no-repeat
              center;
            color: #ffffff;
          }
        }
        .off {
          border-left: none;
          &.active {
            background: url("~@/assets/images/screen/psxt/button2.png")
              no-repeat center;
            color: #ffffff;
          }
        }
      }
      .H164 {
        height: calc(100% - 36px);
        .phd-left {
          width: 50px;
          height: calc(100% - 36px);
          float: left;
        }
        .phd-right {
          width: 122px;
          height: calc(100% - 36px);
          float: left;
          .phd-top {
            height: 40px;
          }
          .water-pump-img-left {
            width: 122px;
            height: 70px;
            background: url("~@/assets/images/screen/psxt/item.png") no-repeat
              center;
            position: relative;
            .tip-box {
              width: 182px;
              height: 136px;
              background: #0a1e36;
              border: 2px solid #00deff;
              padding: 7px 13px 15px 10px;
              opacity: 0.8;
              p {
                font-size: 17px;
                color: #11e0ff;
                line-height: 22px;
                margin-bottom: -2px;
                text-align: left;
                font-weight: 400;
              }
              &.dw {
                position: absolute;
                top: -26px;
                left: 131px;
              }
            }
          }
          .water-pump-img-right {
            width: 122px;
            height: 70px;
            background: url("~@/assets/images/screen/psxt/item1.png") no-repeat
              center;
          }
          p {
            font-weight: 400;
            font-size: 20px;
            color: #ffffff;
            line-height: 30px;
            text-align: center;
            margin-top: 3px;
          }
          .tip-box {
            width: 182px;
            height: 136px;
            background: #0a1e36;
            border: 2px solid #00deff;
            padding: 7px 13px 15px 10px;
            opacity: 0.8;
            p {
              font-size: 17px;
              color: #11e0ff;
              line-height: 22px;
              margin-bottom: -2px;
              text-align: left;
              font-weight: 400;
            }
            &.dwr {
              position: absolute;
              top: 48px;
              left: -189px;
            }
          }
        }
      }
      &.pst5 {
        top: 139px;
        left: 143px;
      }
      &.pst6 {
        top: 139px;
        left: 582px;
      }
      &.pst7 {
        top: 139px;
        left: 1408px;
      }
      &.pst1 {
        top: 480px;
        left: 0px;
      }
      &.pst2 {
        top: 480px;
        left: 440px;
      }
      &.pst3 {
        top: 480px;
        left: 1188px;
      }
      &.pst4 {
        top: 480px;
        left: 1630px;
      }
    }
  }
}
.up-window {
  width: 100%;
  height: 100%;
  background: RGBA(4, 21, 42, 0.6);
  position: absolute;
  z-index: 9999;
  top: 0;
  left: 0;
  .up-window-box {
    width: 588px;
    height: 350px;
    background: linear-gradient(0deg, #062451 0%, #09162d 100%);
    box-shadow: 0px 15px 11px 2px rgba(0, 20, 39, 0.31);
    border: 2px solid #11b9ff;
    opacity: 1;
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    padding: 20px 37px 37px 27px;
    color: #ffffff;
    p {
      width: 500px;
      height: 37px;
      margin: 0px;
      background: url("~@/assets/images/screen/psxt/title.png") no-repeat center;
      background-size: 100%;
      font-weight: 500;
      font-size: 22px;
      color: #ffffff;
      height: 37px;
      background-position-y: 9px;
      span {
        width: 27px;
        display: inline-block;
      }
    }
    .close-button {
      font-size: 30px;
      position: absolute;
      top: 16px;
      right: 16px;
      cursor: pointer;
      &:hover {
        -webkit-transform: rotate(360deg);
        transform: rotate(360deg);
        -webkit-transition: -webkit-transform 1s linear;
        transition: transform 1s linear;
      }
    }
    .W400 {
      width: 400px;
      margin: auto;
      ::v-deep .el-input__inner {
        border-radius: 0px !important;
        height: 52px;
      }
      span {
        font-weight: 400;
        font-size: 21px;
        color: #ffffff;
        margin-top: 60px;
        display: inline-block;
        margin-bottom: 15px;
      }
    }
    .button {
      width: 110px;
      height: 42px;
      background: #11b9ff;
      border-radius: 4px;
      font-weight: 400;
      font-size: 20px;
      color: #ffffff;
      text-align: center;
      line-height: 42px;
      float: left;
      margin-left: 100px;
      margin-top: 55px;
      cursor: pointer;
      &:hover {
        background: #66d2ff;
      }
      &.close {
        background: none;
        color: #fff;
        &:hover {
          color: #66d2ff;
        }
      }
    }
  }
}
</style>
