<template>
  <div class="light-matrix">
    <div class="panel">
      <div class="dot left top"></div>
      <div class="dot left bottom"></div>
      <div class="dot right top"></div>
      <div class="dot right bottom"></div>
      <Row>
        <Col :span="3">
          <div class="panel-item-gf">
            <div class="panel-item-gf-left">
              <span class="svg-icon svg-icon-write svg-icon-md">
                <SvgIcon :svgid="panelData.first.icon"></SvgIcon>
              </span>
            </div>
            <div class="panel-item-gf-right">
              <div class="panel-item-gf-up">{{ panelData.first.text }}</div>
              <div class="panel-item-gf-down">{{ sourceMap[panelData.first.key] || "---" }}</div>
            </div>
          </div>
        </Col>
        <Col :span="3" v-for="(data, index) of panelData.datas" :key="index">
          <div class="panel-item" :class="data.color">
            <div class="panel-item-left">
              <div class="panel-item-li">
                <span>{{ data.name }}</span>
                <span class="svg-icon svg-icon-sm" :class="'svg-icon-' + data.color">
                  <SvgIcon :svgid="data.nameIcon"></SvgIcon>
                </span>
              </div>
              <div class="panel-item-li">
                <span v-if="data.calcStr && sourceMap">{{ calcGfStr(data.calcStr) || "---" }}</span>
                <span v-else>{{ sourceMap[data.key] || "---" }}</span>
                <span class="svg-icon svg-icon-sm" :class="'svg-icon-' + data.color">
                  <SvgIcon :svgid="data.numIcon"></SvgIcon>
                </span>
              </div>
            </div>
            <div class="panel-item-right">
              <div class="panel-item-ri">
                <span>{{ data.text1 }}</span>
                <span>{{ sourceMap[data.key1] || "---" }}</span>
              </div>
              <div class="panel-item-ri">
                <span>{{ data.text2 }}</span>
                <span>{{ sourceMap[data.key2] || "---" }}</span>
              </div>
            </div>
          </div>
        </Col>
      </Row>
    </div>
    <el-scrollbar>
      <div class="panel-box">
        <div v-for="(pItem, pIndex) in sourceMap.fjmap" :key="pIndex">
          <div class="panel-title">
            <div class="panel-title-name">
              <i class="svg-icon svg-icon-sm svg-icon-green">
                <SvgIcon :svgid="'svg-wind-site'"></SvgIcon>
              </i>
              <span>{{ sourceMap.fczbmap[pItem[pIndex].wpId].name }}</span>
              <div class="sub-title-item" v-for="(data, index) of tables[0].subTitleDatas" :key="index">
                <span class="sub-title">{{ data.text }}</span>
                <span class="sub-count" :class="data.color">{{ sourceMap.fczbmap[pItem[pIndex].wpId][data.key] }}</span>
              </div>
            </div>
          </div>
          <div class="panel-body">
            <div class="card" v-for="(cItem, cIndex) in pItem" :key="cIndex" :class="cItem.color" @click="goDetails(cItem)">
              <div class="card-panel">
                <div class="card-left">
                  <div class="tag">{{ cItem.wtnum }}</div>
                  <div class="icon">
                    <span class="svg-icon svg-icon-sm" :class="cItem.color == 'black' ? 'svg-icon-black' : cItem.color == 'gray' ? 'svg-icon-gray' : 'svg-icon-write'">
                      <SvgIcon :svgid="mapping[cItem.color]"></SvgIcon>
                    </span>
                  </div>
                </div>
                <div class="card-right">
                  <div class="num">
                    <i class="svg-icon svg-icon-sm" :class="cItem.color != 'red' ? 'svg-icon-' + cItem.color : 'svg-icon-white'">
                      <SvgIcon svgid="svg-W"></SvgIcon>
                    </i>
                    <span>{{ cItem.gl }}</span>
                  </div>
                  <div class="num">
                    <i class="svg-icon svg-icon-sm" :class="cItem.color != 'red' ? 'svg-icon-' + cItem.color : 'svg-icon-white'">
                      <SvgIcon svgid="svg-R"></SvgIcon>
                    </i>
                    <span>{{ cItem.fdjzs.toFixed(2) }}</span>
                  </div>
                  <div class="num">
                    <i class="svg-icon svg-icon-sm" :class="cItem.color != 'red' ? 'svg-icon-' + cItem.color : 'svg-icon-white'">
                      <SvgIcon svgid="svg-P"></SvgIcon>
                    </i>
                    <span>{{ cItem.fs }}</span>
                  </div>
                </div>
              </div>
            </div>
            <!-- 站位用 保证卡片布局最后一行不会有问题 -->
            <i class="blank" v-for="i in pItem.length" :key="i"></i>
          </div>
        </div>
      </div>
    </el-scrollbar>
  </div>
</template>

<script>
import Row from "@/components/coms/grid/row.vue";
import Col from "@/components/coms/grid/col.vue";
import SvgIcon from "@com/coms/icon/svg-icon.vue";
import util from "@/helper/util.js";

import store from "@store/index.js";

export default {
  // 名称
  name: "LightMatrix3",
  // 使用组件
  components: {
    Row,
    Col,
    SvgIcon,
  },

  // 数据
  data() {
    return {
      timmer: null, // 遮罩开关
      sourceMap: {}, // 核心数据
      mapping: {
        green: "svg-standby",
        blue: "svg-normal-power",
        pink: "svg-limit-power",
        red: "svg-gz-downtime",
        orange: "svg-jx-downtime",
        gray: "svg-offline",
        black: "svg-intranet-involvement",
      },
      panelData: {
        first: {
          icon: "svg-photovoltaic",
          text: "接入风场",
          key: "fcjrnum",
        },
        datas: [
          {
            color: "green",
            name: "待机",
            nameIcon: "svg-standby",
            calcStr: ["fcdjnum", "fcsdtjnum"],
            numIcon: "svg-manual",
            text1: "待风",
            key1: "fcdjnum",
            text2: "手动停机",
            key2: "fcsdtjnum",
          },
          {
            color: "blue",
            name: "运行",
            nameIcon: "svg-normal-power",
            calcStr: ["fczcfdnum", "fcqxjclnum"],
            numIcon: "svg-drop-output",
            text1: "正常发电",
            key1: "fczcfdnum",
            text2: "降出力运行",
            key2: "fcqxjclnum",
          },
          {
            color: "pink",
            name: "限电",
            nameIcon: "svg-limit-power",
            calcStr: ["fcxdjclnum", "fcxdtjnum"],
            numIcon: "svg-downtime",
            text1: "限电降出力",
            key1: "fcxdjclnum",
            text2: "停机",
            key2: "fcxdtjnum",
          },
          {
            color: "red",
            name: "故障",
            nameIcon: "svg-gz-downtime",
            calcStr: ["fcgztjnum", "fccnsltjnum"],
            numIcon: "svg-field-involved",
            text1: "故障停机",
            key1: "fcgztjnum",
            text2: "场内受累",
            key2: "fccnsltjnum",
          },
          {
            color: "orange",
            name: "检休",
            nameIcon: "svg-jx-downtime",
            calcStr: ["fcjxtjnum", "fccnsljxnum"],
            numIcon: "svg-field-involved",
            text1: "检修停机",
            key1: "fcjxtjnum",
            text2: "产内受累",
            key2: "fccnsljxnum",
          },
          {
            color: "write",
            name: "受累",
            calcStr: ["fcdwslnum", "fchjslnum"],
            nameIcon: "svg-intranet-involvement",
            numIcon: "svg-environment",
            text1: "电网",
            key1: "fcdwslnum",
            text2: "环境",
            key2: "fchjslnum",
          },
          {
            color: "gray",
            name: "离线",
            nameIcon: "svg-offline",
            key: "fclxnum",
            numIcon: "svg-unknown",
            text1: "离线",
            key1: "fclxnum",
            text2: "未知",
            key2: "fcwznum",
          },
        ],
      },
      tables: [
        {
          col: 15,
          subTitleDatas: [
            {
              text: "接入台数",
              color: "write",
              key: "jrts",
            },
            {
              text: "待机台数",
              color: "green",
              key: "djts",
            },
            {
              text: "并网台数",
              color: "blue",
              key: "yxts",
            },
            {
              text: "限电台数",
              color: "pink",
              key: "xdts",
            },
            {
              text: "故障台数",
              color: "red",
              key: "gzts",
            },
            {
              text: "检修台数",
              color: "orange",
              key: "whts",
            },
            {
              text: "受累台数",
              color: "write",
              key: "slts",
            },
            {
              text: "离线台数",
              color: "gray",
              key: "lxts",
            },
            {
              text: "风速",
              color: "gray",
              key: "ssfs",
            },
            {
              text: "预测功率",
              color: "gray",
              key: "ycgl",
            },
            {
              text: "保证功率",
              color: "gray",
              key: "bzgl",
            },
            {
              text: "应发功率",
              color: "gray",
              key: "yfgl",
            },
            {
              text: "实际功率",
              color: "gray",
              key: "sjgl",
            },
            {
              text: "AGC指令",
              color: "gray",
              key: "agcygsd",
            },
            {
              text: "出线功率",
              color: "gray",
              key: "agccxyg",
            },
          ],
          datas: [
            {
              tag: "A-11",
              num1: 1234.56,
              num2: 1234.56,
              num3: 1234.56,
              color: "blue",
            },
          ],
        },
      ],
    };
  },

  // 函数
  methods: {
    // 根据风机状态码返回对应 class
    getColor(fjzt) {
      switch (fjzt) {
        case 0: // 待机
          return "green";
        case 1: // 手动停机
          return "green";
        case 2: // 正常发电
          return "blue";
        case 3: // 缺陷降出力
          return "blue";
        case 4: // 限电降出力
          return "purple";
        case 5: // 限电停机
          return "purple";
        case 6: // 故障停机
          return "red";
        case 7: // 场内受累停机
          return "red";
        case 8: // 检修停机
          return "orange";
        case 9: // 离线
          return "orange";
        case 10: // 电网受累
          return "gray";
        case 11: // 环境受累
          return "gray";
        case 12: // 离线
          return "black";
      }
    },

    calcGfStr(calcStr) {
      return parseInt(this.sourceMap[calcStr[0]]) + parseInt(this.sourceMap[calcStr[1]]) + "";
    },

    // 请求服务
    requestData(showLoading) {
      let that = this;
      that.API.requestData({
        showLoading,
        method: "POST",
        subUrl: "matrix/matrixDetialPush",
        success(res) {
          if (res.data) {
            let sourceMap = res.data;
            for (let key in sourceMap) {
              if (key !== "fczbmap" && key !== "fjmap") {
                sourceMap[key] += "";
              } else if (key === "fjmap") {
                sourceMap[key].forEach((pItem) => {
                  pItem.forEach((cItem) => {
                    cItem.color = that.getColor(cItem.fjzt);
                    cItem.isShow = true;
                  });
                });
              }
            }
            that.sourceMap = sourceMap;
          } else {
            that.sourceMap = {};
          }
        },
      });
    },
  },

  created() {
    let that = this;
    that.$nextTick(() => {
      that.requestData(false);
      that.timmer = setInterval(() => {
        that.requestData(false);
      }, that.$store.state.websocketTimeSec);
    });
  },

  mounted() {},

  unmounted() {
    clearInterval(this.timmer);
    this.timmer = null;
  },
};
</script>

<style lang="less" scoped>
@panelHeight: 6.481vh;
@titleHeight: 3.704vh;

.light-matrix {
  width: calc(100% - 1.111vh);
  height: calc(100vh - 7.222vh);
  display: flex;
  flex-direction: column;

  .panel {
    width: 100%;
    border: 0.093vh solid @darkgray;
    position: relative;
    padding: 1.111vh 2.222vh;
    background-color: fade(@darkgray, 20%);

    .dot {
      width: 0.185vh;
      height: 0.185vh;
      border-radius: 50%;
      background-color: @write;
      position: absolute;

      &.left {
        left: 0.37vh;
      }

      &.right {
        right: 0.37vh;
      }

      &.top {
        top: 0.37vh;
      }

      &.bottom {
        bottom: 0.37vh;
      }
    }

    .panel-item-gf {
      width: 100%;
      background-color: fade(@darkgray, 20%);
      display: flex;
      height: @panelHeight;

      .panel-item-gf-left {
        width: @panelHeight;
        height: @panelHeight;
        background-color: fade(@darkgray, 40%);
        display: flex;
        align-items: center;
        justify-content: center;

        i {
          font-size: 2.778vh;
          color: @write;
        }
      }

      .panel-item-gf-right {
        flex-grow: 1;
        color: @write;
        text-align: right;

        .panel-item-gf-up {
          height: @panelHeight / 2;
          border-bottom: 0.093vh solid fade(@darkgray, 40%);
          line-height: @panelHeight / 2;
          padding-right: 1.111vh;
          font-size: @fontsize;
        }

        .panel-item-gf-down {
          height: @panelHeight / 2;
          line-height: @panelHeight / 2;
          padding-right: 1.111vh;
          font-weight: 600;
          font-size: @fontsize;
        }
      }
    }

    .panel-item {
      width: 100%;
      height: @panelHeight;
      display: flex;
      font-size: @fontsize-s;

      .panel-item-left {
        width: @panelHeight;
        height: @panelHeight;

        .panel-item-li {
          width: 100%;
          height: @panelHeight / 2;
          line-height: @panelHeight / 2;
          padding: 0 1.111vh;
          display: flex;
          align-items: center;
          font-size: @fontsize-s;

          .svg-icon {
            margin-left: auto;
          }
        }
      }

      .panel-item-right {
        flex-grow: 1;
        height: @panelHeight;

        .panel-item-ri {
          height: @panelHeight / 2;
          line-height: @panelHeight / 2;
          padding: 0 1.111vh;

          &:first-child {
            border-bottom: 0.093vh solid;
          }

          span {
            &:first-child {
              float: left;
            }

            &:last-child {
              float: right;
              color: @write;
            }
          }
        }
      }

      &.green {
        background-color: fade(@green, 15%);
        color: @green;

        .panel-item-left {
          background-color: fade(@green, 15%);
        }

        .panel-item-right {
          .panel-item-ri {
            &:first-child {
              border-color: @green;
            }
          }
        }
      }

      &.blue {
        background-color: fade(@darkBlue, 15%);
        color: @darkBlue;

        .panel-item-left {
          background-color: fade(@darkBlue, 15%);
        }

        .panel-item-right {
          .panel-item-ri {
            &:first-child {
              border-color: @darkBlue;
            }
          }
        }
      }

      &.pink {
        background-color: fade(@pink, 15%);
        color: @pink;

        .panel-item-left {
          background-color: fade(@pink, 15%);
        }

        .panel-item-right {
          .panel-item-ri {
            &:first-child {
              border-color: @pink;
            }
          }
        }
      }

      &.red {
        background-color: fade(@red, 15%);
        color: @red;

        .panel-item-left {
          background-color: fade(@red, 15%);
        }

        .panel-item-right {
          .panel-item-ri {
            &:first-child {
              border-color: @red;
            }
          }
        }
      }

      &.orange {
        background-color: fade(@orange, 15%);
        color: @orange;

        .panel-item-left {
          background-color: fade(@orange, 15%);
        }

        .panel-item-right {
          .panel-item-ri {
            &:first-child {
              border-color: @orange;
            }
          }
        }
      }

      &.gray {
        background-color: fade(@darkgray, 15%);
        color: @gray;

        .panel-item-left {
          background-color: fade(@darkgray, 15%);
        }

        .panel-item-right {
          .panel-item-ri {
            &:first-child {
              border-color: @darkgray;
            }
          }
        }
      }

      &.write {
        background-color: fade(@write, 15%);
        color: @write;

        .panel-item-left {
          background-color: fade(@write, 15%);
        }

        .panel-item-right {
          .panel-item-ri {
            &:first-child {
              border-color: @write;
            }
          }
        }
      }
    }
  }

  .panel-box {
    margin-top: 1.481vh;
    flex-grow: 1;

    .panel-title {
      width: 100%;
      height: @titleHeight;
      line-height: @titleHeight;
      background-color: fade(@darkgray, 40%);

      .panel-title-name {
        font-size: @fontsize-s;
        color: @green;
        display: flex;
        align-items: center;
        padding: 0 16px;

        i {
          margin-right: 0.7407vh;
        }

        .sub-title-item {
          display: flex;
          flex: 1;

          .sub-title {
            flex: 0 0 auto;
            color: @gray;
            font-size: 12px;
            margin: 0 0.556vh 0 1.481vh;
            padding-top: 1px;
            width: 50px;
          }

          .sub-count {
            flex: 1 0 auto;
            font-size: 14px;
            font-family: "Bicubik";
            font-weight: 500;

            &.write {
              color: @write;
            }

            &.green {
              color: @green;
            }

            &.blue {
              color: @darkBlue;
            }

            &.pink {
              color: @pink;
            }

            &.red {
              color: @red;
            }

            &.orange {
              color: @orange;
            }

            &.gray {
              color: @gray;
            }
          }
        }
      }
    }

    .panel-body {
      background-color: fade(@darkgray, 20%);
      padding: 0.741vh;
      margin-bottom: 1.481vh;
      width: 100%;
      display: flex;
      flex-direction: row;
      flex-wrap: wrap;
      justify-content: space-between;

      .blank {
        margin-right: 4px;
        flex: 1 0 105px;
      }

      .card {
        margin-right: 4px;
        margin-top: 4px;
        flex: 1 0 105px;
      }

      .card {
        border: 1px solid;

        .card-panel {
          display: flex;
          flex-grow: row;

          .card-left {
            width: 40px;
            border-right: 0.093vh dotted;
            display: flex;
            flex-direction: column;

            .tag {
              color: @write;
              font-size: 12px;
              width: 100%;
              text-align: center;
              line-height: 1.5;
            }

            .icon {
              flex-grow: 1;
              display: flex;
              align-items: center;
              justify-content: center;

              i {
                font-size: 14px;
              }
            }
          }

          .card-right {
            margin-top: 2px;

            .num {
              width: 72px;
              font-size: 12px;
              text-align: left;
              padding-right: 0.278vh;
              display: flex;
              align-items: center;
              justify-content: space-around;

              i {
                margin: 0 2px 0 4px;
              }
              span {
                flex: 1;
              }
            }
          }
        }

        .card-percent {
          height: 0.926vh;
          padding: 0.093vh 0.185vh;
          position: relative;
          border-top: 1px solid;
          background-color: transparent;

          .percent {
            height: 0.648vh;
            background-color: @green;
            position: absolute;
            left: 0.185vh;
            top: 0.093vh;
          }
        }

        &.blue {
          border-color: @darkBlue;
          background-color: fade(@darkBlue, 15%);

          .card-panel {
            .card-left {
              border-color: @darkBlue;

              .tag {
                background-color: fade(@darkBlue, 30);
              }

              .icon {
                svg {
                  use {
                    fill: @write;
                  }
                }
              }
            }

            .card-right {
              .num {
                color: @darkBlue;
              }
            }
          }

          .card-percent {
            border-color: @darkBlue;
          }
        }

        &.pink {
          border-color: @pink;
          background-color: fade(@pink, 15%);

          .card-panel {
            .card-left {
              border-color: @pink;

              .tag {
                background-color: fade(@pink, 30);
              }

              .icon {
                svg {
                  use {
                    fill: @write;
                  }
                }
              }
            }

            .card-right {
              .num {
                color: @pink;
              }
            }
          }

          .card-percent {
            border-color: @pink;
          }
        }

        &.orange {
          border-color: @orange;
          background-color: fade(@orange, 15%);

          .card-panel {
            .card-left {
              border-color: @orange;

              .tag {
                background-color: fade(@orange, 30);
              }

              .icon {
                use {
                  fill: @write;
                }
              }
            }

            .card-right {
              .num {
                color: @orange;
              }
            }
          }

          .card-percent {
            border-color: @orange;
          }
        }

        &.green {
          border-color: @green;
          background-color: fade(@green, 15%);

          .card-panel {
            .card-left {
              border-color: @green;

              .tag {
                background-color: fade(@green, 30);
              }

              .icon {
                use {
                  fill: @write;
                }
              }
            }

            .card-right {
              .num {
                color: @green;
              }
            }
          }

          .card-percent {
            border-color: @green;
          }
        }

        &.gray {
          border-color: @darkgray;
          background-color: fade(@darkgray, 15%);

          .card-panel {
            .card-left {
              border-color: @darkgray;

              .tag {
                background-color: fade(@darkgray, 30%);
              }

              .icon {
                use {
                  fill: @black;
                }
              }
            }

            .card-right {
              .num {
                color: @gray;
              }
            }
          }

          .card-percent {
            border-color: @darkgray;
          }
        }

        &.red {
          border-color: @red;

          .card-panel {
            background-color: @red;

            .card-left {
              border-color: @darkRed;

              .tag {
                background-color: fade(@darkRed, 50%);
              }

              .icon {
                use {
                  fill: @write;
                }
              }
            }

            .card-right {
              .num {
                color: @write;
              }
            }
          }

          .card-percent {
            border-color: @red;
          }
        }

        &.black {
          border-color: @write;

          .card-panel {
            background-color: @write;

            .card-left {
              border-color: @black;

              .tag {
                background-color: fade(@darkgray, 80%);
              }

              .icon {
                .svg-icon {
                  svg {
                    use {
                      fill: @black;
                    }
                  }
                }
              }
            }

            .card-right {
              .num {
                color: @black;
              }
            }
          }
        }
      }
    }
  }
}
</style>
