<template>
  <div id="index" ref="appRef">
    <div class="bg">
      <dv-loading v-if="loading">Loading...</dv-loading>
      <div v-else class="host-body">
        <div class="d-flex jc-center">
          <dv-decoration-10 class="dv-dec-10" />
          <div class="d-flex jc-center">
            <dv-decoration-8 class="dv-dec-8" :color="decorationColor" />
            <div class="title">
              <span class="title-text">UAS-MES可视化平台</span>
              <dv-decoration-6
                class="dv-dec-6"
                :reverse="true"
                :color="['#50e3c2', '#67a1e5']"
              />
            </div>
            <dv-decoration-8
              class="dv-dec-8"
              :reverse="true"
              :color="decorationColor"
            />
          </div>
          <dv-decoration-10 class="dv-dec-10-s" />
        </div>

        <!-- 第二行 -->
        <div class="d-flex jc-between px-2">
          <div class="d-flex aside-width">
            <div class="react-left ml-4 react-l-s bg-color-blue">
              <span class="react-left"></span>
              <span class="text fw-b" style="font-size:24px;">次元之造智能工厂</span>
            </div>
            <div class="react-left ml-3">
              <span class="text">生产实况分析</span>
            </div>
          </div>
          <div class="d-flex aside-width">
            <div class="react-right bg-color-r mr-3">
              <span class="text" @click="fullScreen" ref="fullScreen">全屏</span>
              <span class="text" @click="exitFullScreen" ref="exitFullScreen"  style="display: none">退出全屏</span>
            </div>
            <div class="react-right mr-4 react-l-s" style="width: 900px">
              <span class="react-after"></span>

             <!-- <el-dropdown class="dropdown">
                <span class="el-dropdown-link" ref="echarType">
                   {{linecode.LI_CODE}} <i class="el-icon-arrow-down el-icon&#45;&#45;right"></i>&nbsp;&nbsp;&nbsp;&nbsp;
                </span>
                <el-dropdown-menu slot="dropdown">
                  <el-dropdown-item class="dropdownitem"
                                    v-for="item in linedata"
                                    :key="item.LI_CODE"
                  >{{item.LI_CODE}}</el-dropdown-item>
                 </el-dropdown-menu>
              </el-dropdown>*/-->

              <el-dropdown class="dropdown">
                <span class="el-dropdown-link" ref="echarType">
                  产线看板<i class="el-icon-arrow-down el-icon--right"></i>&nbsp;&nbsp;&nbsp;&nbsp;
                </span>
                  <el-dropdown-menu slot="dropdown">
                    <el-dropdown-item class="dropdownitem"><router-link to="shop">车间看板</router-link></el-dropdown-item>
                    <el-dropdown-item class="dropdownitem"><router-link to="quality">品质看板</router-link></el-dropdown-item>
                    <el-dropdown-item class="dropdownitem"><router-link to="device">设备看板</router-link></el-dropdown-item>
                  </el-dropdown-menu>
              </el-dropdown>

             <el-select v-model="linecode" class="dropdown" @change ="handleBlur" style="width: 150px">
                <el-option
                        v-for="item in linedata"
                        :key="item.LI_CODE"
                        :label="item.LI_CODE"
                        :value="item.LI_CODE"
                   ></el-option>
              </el-select>

              <span class="text">&nbsp;&nbsp;&nbsp;&nbsp;</span>
              <span class="text">{{ dateYear }} {{ dateWeek }} {{ dateDay }}</span>
            </div>
          </div>
        </div>

        <div class="body-box">
          <!-- 上面 -->
          <div class="content-box">
            <div>
              <dv-border-box-12>
                <up1 />
              </dv-border-box-12>
            </div>
            <div>
              <dv-border-box-12 >
                <up2 />
              </dv-border-box-12>
            </div>
            <div>
              <dv-border-box-12>
                <up3 />
              </dv-border-box-12>
            </div>
          </div>
          <!-- 下面 -->
          <div class="bottom-box">
              <dv-border-box-12>
                <bottom1 />
              </dv-border-box-12>
            <dv-border-box-12>
              <bottom2 />
            </dv-border-box-12>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import drawMixin from "../../utils/drawMixin";
import { formatTime } from '../../utils/index.js'
import up1 from './up1'
import up2 from './up2'
import up3 from './up3'
import bottom1 from './bottom1'
import bottom2 from './bottom2'
import { mapState } from "vuex"

export default {
  mixins: [ drawMixin ],
  computed: {
    ...mapState('user', ['user'])
  },
  data() {
    return {
      timing: null,
      loading: true,
      dateDay: null,
      dateYear: null,
      dateWeek: null,
      weekday: ['周日', '周一', '周二', '周三', '周四', '周五', '周六'],
      decorationColor: ['#568aea', '#000000'],
      linecode:null,
      linedata:[]
    }
  },
  components: {
    up1,
    up2,
    up3,
    bottom1,
    bottom2
  },
  created() {
    this.getLines();
  },
  mounted() {
    this.timeFn()
    this.cancelLoading()
  },
  beforeDestroy () {
    clearInterval(this.timing)
    clearInterval(this.intervalId)
  },
  methods: {
    timeFn() {
      this.timing = setInterval(() => {
        this.dateDay = formatTime(new Date(), 'HH: mm: ss')
        this.dateYear = formatTime(new Date(), 'yyyy-MM-dd')
        this.dateWeek = this.weekday[new Date().getDay()]
      }, 1000)
    },
    cancelLoading() {
      setTimeout(() => {
        this.loading = false
      }, 5000)
    },
    handleBlur (val){
      sessionStorage.setItem('li_code',val);
      this.$cookie.set("SMT_LI_CODE", val, {
        expires: 30,
      });
      location.reload();
    },
    getLines (){
      this.$http.get("kanban/getLinesByWorkCenter.action").then(
              (res)=>{
                if(res.data.linedata) {
                  const data = res.data.linedata;
                  if(this.$cookie.get("SMT_LI_CODE") && data.some(item => item.LI_CODE === this.$cookie.get("SMT_LI_CODE")) ){
                    sessionStorage.setItem('li_code', this.$cookie.get("SMT_LI_CODE"));
                  }else {
                    sessionStorage.setItem('li_code', data[0].LI_CODE);
                    this.$cookie.set("SMT_LI_CODE", data[0].LI_CODE, {
                      expires: 30,
                    });
                  }
                  this.linedata = data;
                }else{
                  sessionStorage.setItem('li_code','');
                }
                this.linecode = sessionStorage.getItem("li_code");
              },(result)=>{
                console.error(result)
              });
    }
  }
}
</script>

<style lang="scss" scoped>
@import '../../assets/scss/indexprodline.scss';
.dropdown{
  font-size: 18px;
  color: #568aea;
  transform: skewX(45deg);
  ::v-deep .el-select-dropdown {
    /* // 若不将下拉框的背景颜色设置为：transparent，那么做不出来半透明的效果；
    // 因为其最终的显示为：下拉框有一个背景颜色且下拉框的字体有一个背景颜色，重叠后的效果展示； */
    border: 1px solid #0f1325;
    background: #04308D !important;
  }

  ::v-deep .el-input__inner {
    background-color: #0f1325;
    color: #fff;
    border: 1px solid #0f1325;
  }

  .el-select-dropdown__item {
    color: #fff;
    background-color: #0f1325;
  }
  ::v-deep .el-select-dropdown {
    background-color: transparent;
    border: 1px solid #0f1325;
  }
  ::v-deep.el-select-dropdown__list {
    padding: 0;
  }
  ::v-deep.el-popper[x-placement^="bottom"] {
    margin-top: 0px;
  }
  ::v-deep.el-popper .popper__arrow,
  ::v-deep.el-popper .popper__arrow::after {
    display: none;
  }
  .el-select-dropdown__item:hover {
    background-color: rgba(0, 225, 219, 0.690196078431373);
  }
}

</style>
