<template>
  <div class="testdiv">
    <div class="top_title">
      <span>{{ title }}</span>
      <img :src="imgLogo" class="logo" @click="back()" />
      <div class="times_bg">{{ nowTime }}</div>
      <div class="setting" @click="openSet()">
        <img src="../../../static/images/setting.svg" />
      </div>
    </div>
    <div class="middle_bottom">
      <div class="formBox">
        <div class="formMain">
          <ul class="table_title_bg andonHead">
            <li>序号</li>
            <li>工位</li>
            <li>班次</li>
            <li>产品名称</li>
            <li>理论产出(件)</li>
            <li>实际产出(件)</li>
            <li>产出效率</li>
          </ul>
          <vue-seamless-scroll :data="odArr" :class-option="oet" class="tblSd">
            <ul class="tableDetail">
              <li v-if="!odArr.length"></li>
              <li class="andonBody" v-for="(v, i) in odArr" :key="i" v-else>
                <div>{{ i + 1 }}</div>
                <div>{{ v.deviceNo }}</div>
                <div>{{ v.schdule }}</div>
                <div>{{ v.productName }}</div>
                <div>{{ v.theoryOut }}</div>
                <div>{{ v.factOut }}</div>
                <div>{{ v.outRate }}%</div>
              </li>
            </ul>
          </vue-seamless-scroll>
        </div>
      </div>
    </div>
    <!-- 弹出框 -->
    <Modal :styles="setting" v-model="setModal" footer-hide>
      <p slot="header">
        <span>请选择要跳转的组合</span>
      </p>
      <div class="modal_body" style="max-height: 160px; overflow-y: auto">
        <List size="small">
          <ListItem v-for="(v, i) in combList" :key="i">
            <span class="setItem" @click="play(v.id)">{{ v.title }}</span>
          </ListItem>
        </List>
      </div>
    </Modal>
  </div>
</template>

<script>
import vueSeamlessScroll from "vue-seamless-scroll";
import moment from "moment";
import { mapState } from "vuex";
import { setInterval, clearInterval } from "timers";

export default {
  inject: ["reload"],
  components: {
    vueSeamlessScroll,
  },
  computed: {
    ...mapState(["user"]),
    oet: function () {
      return {
        step: 5,
        hoverStop: true,
        singleHeight: 80,
      };
    },
    combId() {
      return this.$route.query.combId;
    },
    title() {
      return this.$route.query.title;
    },
    setting() {
      return {
        position: "fixed",
        top: "50px",
        right: "50px",
        width: "250px",
      };
    },
  },
  data() {
    return {
      combList: [],
      setModal: false,
      imgLogo: require("../../../static/images/siger.png"),
      nowTime: moment(new Date().getTime()).format("YYYY-MM-DD"),
      odArr: [],
      timer: 0,
      timeArr: 0,
    };
  },
  created() {
    if (this.user.logo) {
      this.imgLogo = this.user.logo;
    }
  },
  mounted() {
    if (this.timer) {
      clearInterval(this.timer);
    } else {
      this.initdata();
      this.timer = setInterval(() => {
        this.initdata();
      }, 1000 * 60 * 5);
    }
    if (this.timeArr) {
      clearInterval(this.timeArr);
    } else {
      this.timeArr = setInterval(() => {
        this.reload();
      }, 1000 * 60 * 30);
    }
  },
  methods: {
    openSet() {
      const _this = this;
      _this.axios
        .request({
          url: "/dashboard/DashboardConfig/GetCombList",
          method: "get",
        })
        .then((res) => {
          let result = res.data;
          if (result.ret == 1) {
            _this.combList = result.data_comb;
            _this.setModal = true;
          }
        });
    },
    // 页面播放
    play(combId) {
      const _this = this;
      let params = {
        id: combId,
        projectid: _this.user.projectId,
      };
      _this.axios
        .request({
          url: "/dashboard/DashboardShow/getallcombpages",
          params,
          method: "get",
        })
        .then((res) => {
          let result = res.data;
          if (result.ret == 1) {
            _this.$router.replace({ name: "8000063", query: { combId } });
            _this.reload();
          }
        });
    },
    back() {
      this.$router.go(-1);
    },
    initdata() {
      let _this = this;
      let query = _this.$route.query;
      let params = {
        patial_code: query.patial_code,
        page_id: query.pageId,
        projectid: _this.user.projectId,
      };
      this.axios
        .request({
          url: "/dashboard/DashboardShow/getalldata",
          params,
          method: "get",
        })
        .then((res) => {
          let result = res.data;
          if (result.ret == 1) {
            let data = result.data;
            let odArr = [];
            let orderItem;
            if (data && Array.isArray(data) && data.length) {
              data.forEach(function (ele, i) {
                orderItem = {};
                let productName = !ele.productName ? "NA" : ele.productName;
                orderItem.deviceNo = ele.machineName;
                orderItem.schdule = ele.shift;
                orderItem.productName = productName;
                orderItem.theoryOut = ele.theoreticalOutput;
                orderItem.factOut = ele.actualOutput;
                orderItem.outRate = ele.efficiency;
                odArr.push(orderItem);
              });
            }
            _this.odArr = odArr;
          }
        });
    },
  },
  beforeDestroy() {
    clearInterval(this.timer);
    clearInterval(this.timeArr);
  },
  beforeRouteEnter(to, from, next) {
    if (from.path == "/") {
      next((vm) => {
        vm.$router.replace({ name: "8000063", query: { combId: vm.combId } });
      });
      return false;
    }
    next();
  },
};
</script>

<style lang="less" scoped>
.testdiv {
  width: 100%;
  max-width: 1920px;
  height: 100%;
  background-image: url("../../../static/images/u0.png");
  background-size: 100% 100%;
  padding: 11px;
  box-sizing: border-box;
  overflow-y: auto;
}

.top_title {
  width: 100%;
  height: 106px;
  background: url("../../../static/images/u2.png") center center no-repeat;
  background-size: 81.25% 100%;
  padding: 0 25px 0 40px;
  box-sizing: border-box;
  display: inline-block;
  text-align: center;
  font-size: 59px;
  color: #fff;
  font-weight: bold;
  line-height: 100px;
  position: relative;
  font-style: italic;

  .logo {
    width: 200px;
    height: 60px;
    float: left;
    margin-top: 27px;
    cursor: pointer;
  }

  .times_bg {
    width: 200px;
    height: 40px;
    font-size: 24px;
    text-align: center;
    line-height: 40px;
    color: #fff;
    float: right;
    background: url("../../../static/images/u4.png") center center no-repeat;
    background-size: 100% 40px;
    margin-top: 34px;
  }
}

.middle_bottom {
  margin-top: 10px;

  .formBox {
    .formMain {
      box-sizing: border-box;
      width: 100%;
      height: 940px;
      background: url("../../../static/images/u_11.png") center center no-repeat;
      background-size: 100% 100%;

      .table_title_bg {
        width: 100%;
        height: 120px;

        li {
          height: 100%;
          line-height: 120px;
          font-size: 25px;
          color: #fff;
          font-weight: normal;
          text-align: center;
          display: inline-block;
        }

        li:first-child {
          width: 14%;
        }

        li:nth-child(2) {
          width: 14%;
        }

        li:nth-child(3) {
          width: 14%;
        }

        li:nth-child(4) {
          width: 14%;
        }

        li:nth-child(5),
        li:nth-child(6),
        li:nth-child(7) {
          width: 14%;
        }
      }

      .tblSd {
        width: 100%;
        height: 815px;
        overflow-y: hidden;

        .tableDetail {
          li {
            width: 100%;
            text-align: center;
            color: #fff;
            overflow: hidden;
            height: 80px;
            display: flex;
            align-items: center;

            div {
              width: 30%;
              float: left;
              font-size: 25px;
            }

            div:first-child {
              width: 14%;
            }

            div:nth-child(2) {
              width: 14%;
            }

            div:nth-child(3) {
              width: 14%;
            }

            div:nth-child(4) {
              width: 14%;
            }

            div:nth-child(5),
            div:nth-child(6),
            div:nth-child(7) {
              width: 14%;
            }
          }
        }
      }
    }
  }
}
::-webkit-scrollbar {
  /*隐藏滚轮*/
  display: none;
}
.setting {
  display: inline-block;
  position: fixed;
  right: 20px;
  top: -20px;
  img {
    width: 40px;
    cursor: pointer;
  }
}
.setItem {
  font-size: 14px;
  cursor: pointer;
}
.setItem:hover {
  color: #2d8cf0;
  font-weight: bold;
}
</style>
