<template>
  <view class="page-css">
    <u-navbar :is-back="false" title="工作台">
      <view slot="right" @click="goPage('/pages/notice/index')">
        <u-badge size="mini" type="error" :count="messageCount" v-if="messageCount>0"></u-badge>
        <u-icon name="chat" size="60" color="#3a62d7" :is-center="true" style="padding-right: 20rpx;">
        </u-icon>
      </view>
    </u-navbar>
    <view class="">
      <view class="banner-swiper" v-if="swiperList.length > 0">
        <view class="logo-txt">科研医疗建筑运维平台</view>
        <image :src="swiperList[0]" style="padding-right:12rpx;height:444rpx;width:100%"></image>
      </view>
      <view class="work-title">工作台</view>
      <view class="workbench">
        <view v-for="(item, index) in workList" :key="index" class="workbench-slider">
          <view class="workbench-item" @click="goPage(item.pagePath)">
            <view class="workbench-item-icon">
              <image :src="item.img" mode="aspectFit" />
            </view>
            <u-badge class="badge" type="error" :count="item.num" :offset="[0, 0]"></u-badge>
          </view>
          <view class="workbench-name">{{ item.name }}</view>
        </view>
      </view>
      
      <view>
        <swiperSlider></swiperSlider>
      </view>
      <view>
        <swiperRepair></swiperRepair>
      </view>
      <!--  -->
      <view>
        <alarm></alarm>
      </view>
      <view class="work-title">维修统计</view>
      <view class="statistics">
        <eacharts></eacharts>
      </view>
      <view class="work-title">故障现象分类</view>
      <view class="statistics">
        <eachartsPie :echartData="pieInfo.fault"></eachartsPie>
      </view>
      <view class="work-title">设备分类</view>
      <view class="statistics">
        <eachartsNightpie :echartData="pieInfo.device"></eachartsNightpie>
      </view>
    </view>
    <betone-tabbar ref="tabbarRef" />
    <betone-loading ref="BetLoading"></betone-loading>
  </view>
</template>
<script>
import swiperSlider from "./components/swiper.vue";
import alarm from "./components/alarm.vue";
import eacharts from "./components/eacharts.vue";
import eachartsPie from "./components/eacharts_pie.vue";
import eachartsNightpie from "./components/eacharts_nightpie.vue";
// swiperRepair
import swiperRepair from "./components/swiperRepair.vue";
export default {
  components: {
    swiperSlider,
    alarm,
    eacharts,
    eachartsPie,
    eachartsNightpie,
    swiperRepair
  },
  data() {
    return {
      swiperList: [],
      workList: [],
      pieInfo: {},//饼图数据
      messageCount:0,//消息通知数量
    };
  },
  onShow() {
    this.$nextTick(() => {
      // this.pieStat()
      this.$refs.tabbarRef.getPermission();
      //  this.BetLoading.show();
      //   setTimeout(() => {
      //    this.BetLoading.hide();
      //   }, 1000);
    });
    //工作台
    this.pieStat()
    this.getUserInfo()
    this.getoverview()
    this.getMesseageTotal()
  },
  methods: {
    // 工作台 列表  overview
    getoverview() {
      this.$u.api.overview().then(res => {
        if (res.code == 200) {
          let data_ = res.data
          data_.forEach(item => {
            if (item.name.indexOf('巡检') > 0) {
              item.pagePath = '/pages/inspection/plan'
              item.img = require("@/static/images/home/lab_xj.png")
            }
            if (item.name.indexOf('记录') > 0) {
              item.pagePath = '/pages/submission/records?type=submission'
              item.img = require("@/static/images/home/bs_jl.png")
            }
            if (item.name.indexOf('报警') > 0) {
              item.pagePath = ''
              item.img = require("@/static/images/home/alarm.png")
            }
          });
          data_.push({
            name: "其他",
            img: require("@/static/images/home/full.png"),
            num: 0,
            pagePath: ''
          })
          this.workList = data_
        }


      })
    },
    getUserInfo() {
      this.$u.api.getUserInfo().then(res => {
        if (res.code == 200) {
          if (res.data?.backGroundPic != undefined) {
            this.swiperList.push(res.data.backGroundPic)
          } else {
            this.swiperList.push(require("@/static/images/home/lab.png"))
          }
        }
      }).catch(err => {
        this.swiperList.push(require("@/static/images/home/lab.png"))
      })
    },
    goPage(item) {
      if (item == '') {
        uni.showToast({ title: "功能正在完善中，敬请期待！", icon: "none" });
      } else {
        uni.navigateTo({
          url: item,
        });
      }

    },
    scanCode() {
      uni.scanCode({
        success: (res) => {
          console.log('扫码结果：' + res.result);
          // 扫码成功后的操作，例如：
          // this.handleScanResult(res.result);
        },
        fail: (err) => {
          console.error('扫码失败：' + err);
        }
      });
    },
     // 饼图数据
     pieStat() {
      this.$u.api.pieStat().then(res => {
        if (res.code == 200) {
          this.pieInfo = res.data
        }
      })
    },
    // 获取消息总数
    getMesseageTotal(){
      this.$u.api.getMesseageTotal().then(res=>{
          console.log(res.data)
          this.messageCount = res.data
      })
    }
  },
};
</script>
<style lang="scss" scoped>
.page-css {
  width: 100%;
  // min-height: 100%;
  padding: 0;
  background: rgba(239, 239, 239, 1);
  padding-top: var(--status-bar-height);

  .banner-swiper {
    margin-bottom: 64rpx;
    position: relative;

    .logo-txt {
      color: rgba(255, 255, 255, 1);
      font-size: 36rpx;
      position: absolute;
      top: 40rpx;
      left: 20rpx;
      z-index: 10;
    }

    .logo-scan {
      position: absolute;
      right: 20rpx;
      top: 40rpx;
      z-index: 10;
      color: rgba(255, 255, 255, 1);
    }
  }

  .work-title {
    color: rgba(16, 16, 16, 1);
    font-size: 32rpx;
    padding: 0 0 32rpx 36rpx;
  }

  .workbench {
    height: 210rpx;
    position: relative;
    display: flex;
    justify-content: space-around;
    margin: 0 40rpx 32rpx;

    .workbench-item {
      width: 150rpx;
      height: 150rpx;
      background-color: rgba(58, 98, 215, 0.57);
      border-radius: 8rpx;
      position: relative;

      .workbench-item-icon {
        width: 64rpx;
        height: 64rpx;
        position: absolute;
        left: 0;
        top: 0;
        bottom: 0;
        right: 0;
        margin: auto;

        image {
          width: 100%;
          height: 100%;
        }
      }
    }

    .workbench-name {
      width: 100%;
      text-align: center;
      font-size: 28rpx;
      color: rgba(16, 16, 16, 1);
      margin-top: 16rpx;
    }

    .badge {
      // background-color: blue;
      // color: white;
    }
  }

  .statistics_pie {
    width: 100%;
  }
}
</style>