<!-- 学生端工作台 -->
<template>
  <view class="user-workbench">
    <!-- <img class="top-big-img" src="@/images/Version2.2/ing_bg_banner.png"> -->
    <img class="top-big-img" :src="homepageBanner">
    <view class="min-icon-button-box">
      <view @click="goPage('casuallyPat')">
        <img src="@/images/Version2.2/icon_sy_ssp.png">
        <view>随手拍</view>
      </view>
      <view @click="saoCode">
        <img src="@/images/Version2.2/btn_wd_jfdh.png">
        <view>积分兑换</view>
      </view>
      <view @click="goPage('safeAccess')">
        <img src="@/images/Version2.2/icon_sy_zrsq.png">
        <view>准入申请</view>
      </view>
      <view @click="goPage('safetyInspect')">
        <img src="@/images/Version2.2/icon_sy_aqjc.png">
        <view>安全检查</view>
      </view>
      <!-- <view @click="goNull">
        <img src="@/images/Version2.2/icon_sy_aqxx.png">
        <view>安全学习</view>
      </view> -->
      <view @click="goPage('photoInspection')">
        <img src="@/images/icon_dzt_pzjc.png">
        <view>拍照检查</view>
      </view>
      <view @click="goPage('gas')">
        <img src="@/images/Version3.0/icon_sy_qpgl.png">
        <view>气瓶管理</view>
      </view>
      <view @click="goPage('none')">
        <img src="@/images/Version3.0/icon_sy_hxp.png">
        <view>化学品管理</view>
      </view>
      <view @click="goPage('none')">
        <img src="@/images/Version3.0/icon_sy_tzsb.png">
        <view>特种设备</view>
      </view>
    </view>
    <!-- 分级管控 -->
    <view class="grading">
      <img class="grading_l" src="@/images/icon_sy_fjgk.png"/>
      <view class="grading_c">分级管控</view>
      <view class="grading_r" @click="goPage('grading')">{{gradingCount>0?gradingCount+'项工作待完成':''}}<img src="@/images/icon_wdwg_gd.png"/></view>
    </view>
    <view class="big-icon-button-box">
      <view class="left-box">
        <img class="left-top-img" @click="goNull" src="@/images/Version2.2/img_bg_cjcx.png">
        <img class="left-bottom-img" @click="goPage('meViolation')" src="@/images/Version2.2/img_bg_wgjl.png">
      </view>
      <img class="right-img" @click="goNull" src="@/images/Version2.2/img_bg_jfmx.png">
    </view>
    <view class="bottom-max-box">
      <view class="bottom-title">
        <img src="@/images/Version2.2/icon_sy_wdzs.png">
        <view>我的证书</view>
      </view>
      <view class="bottom-big-box">
        <view class="bottom-for-box" v-for="(item,index) in dataList" :key="index">
          <view class="bottom-top-box">{{item.certTitle}}</view>
          <view class="bottom-bottom-box">
            <view class="bottom-right-box">{{item.createTime}}获得</view>
            <view class="bottom-right-box">到期时间:{{item.expirationTime}}</view>
          </view>
        </view>
        <view class="null-view" v-if="!dataList[0]">暂无数据</view>
      </view>
    </view>
    <tab-bar></tab-bar>
  </view>
</template>

<script>
import { myViolationCount,queryMyCert,outSubjectPhoto,gradingControl} from '@/api/index.js'
import { tabBar } from '@/component/tabBar.vue'
export default {
  components: {
    tabBar
  },
  data() {
    return {
      hintType:false,
      dataList:[],
      violationData:{},
      gradingCount:0,
      homepageBanner:uni.getStorageSync('homepageBanner'),
    }
  },
  created() {

  },
  mounted(){
    console.log("user-workbench")
    this.myViolationCount();
    this.getGrading();

    this.queryMyCert();
  },
  methods: {
    //获取分级管控未完成总数
    async getGrading(){
      let obj = {

      }
      const {data} = await gradingControl(obj)
      if(data.code==200){
        this.gradingCount=data.count;
      }

    },
    //暂无提示
    goNull(){
      uni.showToast({
        title: '暂未开放',
        mask:true,
        icon:"none",
        duration: 2000
      });
    },

    //调用摄像头
    saoCode(){
      uni.scanCode({
        onlyFromCamera: true,
        success: function (res) {
          uni.navigateTo({
            url: '/pages_student/mine/codeSuccess?q='+encodeURIComponent(JSON.stringify(res.result))
          });
        }
      });
    },
    // 查询违规记录列表 （用户端）
    async myViolationCount(){
      let self = this;
      let {data} = await myViolationCount()
      if(data.code == 200){
        this.violationData = data.data;
      }
    },
    // 查询证书列表 （用户端）
    async queryMyCert(){
      let self = this;
      let {data} = await queryMyCert({})
      if(data.code == 200){
        let list = [];
        for(let i=0;i<data.rows.length;i++){
          let timeOne = (new Date(data.rows[i].createTime)).getTime();
          let timeTwo = (new Date(data.rows[i].expirationTime)).getTime();
          data.rows[i].createTime = self.formatDate(timeOne);
          data.rows[i].expirationTime = self.formatDate(timeTwo);
        }
        this.dataList = data.rows;
      }
    },
    formatDate(date) {
      let newDate = new Date(date);
      let YY = newDate.getFullYear() + '-';
      let MM = (newDate.getMonth() + 1 < 10 ? '0' + (newDate.getMonth() + 1) : newDate.getMonth() + 1) + '-';
      let DD = (newDate.getDate() < 10 ? '0' + (newDate.getDate()) : newDate.getDate());
      return YY + MM + DD;
    },
    //页面跳转
    goPage(type){
      if(type == 'meViolation'){//我的违规
        uni.navigateTo({
          url: '/pages_student/workbench/meViolation',
        });
      }else if(type == 'photoInspection'){//拍照检查
        this.outSubjectPhoto();
      }else if(type == 'resultInquiry'){//成绩查询
        uni.navigateTo({
          url: '/pages_student/workbench/resultInquiry',
        });
      }else if(type == 'casuallyPat'){//随手拍
        uni.navigateTo({
          url: '/pages/casuallyPat',//随手拍
        });
      }else if(type == 'safeAccess'){//安全准入
        uni.navigateTo({
          url: '/pages_student/workbench/safeAccess/safeAccess',
        });
      }else if(type == 'examList'){//在线考试
        uni.navigateTo({
          url: '/pages_student/workbench/exam/examList',
        });
      }else if(type == 'grading'){
        uni.navigateTo({
          url: '/pages/gradingControl/gradingControl',//分级管控
        });
      }else if(type == 'safetyInspect'){//安全检查

        uni.navigateTo({
          url: '/pages_manage/workbench/securityCheck/safetyInspect',//安全检查
        });
      }else if(type == 'gas'){//气瓶管理
        uni.navigateTo({
          url: '/pages_student/gasManage/gasManage',
        });
      }else if(type == 'none'){
		  uni.showToast({
		    title: '暂未开放',
		    icon:"none",
		    mask:true,
		    duration: 2000
		  });
	  }
    },
    //获取拍照检查配置
    async outSubjectPhoto(){
      const {data} = await outSubjectPhoto();
      if(data.code == 200){
        if(data.data == null){
          //需要检查(重新填写)
          let obj = {
            sub:"实验室照片",
            subUrl:"",
            garbage:"垃圾桶清理后照片",
            garbageUrl:"",
            dangerous:"使用危险设备照片(选填)",
            dangerousUrl:"",
            sourceRisk:"危险源设备使用登记本照片(选填)",
            sourceRiskUrl:"",
          };
          uni.navigateTo({
            url: '/pages_student/workbench/photoInspection?newData='+encodeURIComponent(JSON.stringify(obj)),
          });
        }else if(data.data == false){
          //不需要检查
          uni.showToast({
            title: '暂无检查数据',
            icon:"none",
            mask:true,
            duration: 2000
          });
        }else{
          //需要检查(修改内容)
          let obj = {
            id:data.data.id,
            sub:"实验室照片",
            subUrl:data.data.subUrl,
            garbage:"垃圾桶清理后照片",
            garbageUrl:data.data.garbageUrl,
            dangerous:"使用危险设备照片(选填)",
            dangerousUrl:data.data.dangerousUrl,
            sourceRisk:"危险源设备使用登记本照片(选填)",
            sourceRiskUrl:data.data.sourceRiskUrl,
          };
          uni.navigateTo({
            url: '/pages_student/workbench/photoInspection?newData='+encodeURIComponent(JSON.stringify(obj)),
          });
        }
      }
    },
  }
}
</script>

<style lang="stylus" scoped>
.user-workbench{
  height:100%;
  flex:1;
  .top-big-img{
    height:342rpx;
    width:750rpx;
    background :#ffffff;
  }
  .min-icon-button-box{
    display flex;
    justify-content: flex-start;
    flex-wrap: wrap;
    width:710rpx;
    margin:20rpx;
    background :#ffffff;
    border-radius:20rpx;
    padding-bottom: 20rpx;
    view{
      width: 176rpx;
      img{
        height:75rpx;
        width:75rpx;
        margin:30rpx auto 10rpx;
      }
      view{
        text-align center
        font-size:24rpx;
      }
    }
  }
  /* 分级管控 */
  .grading{
    width :712rpx;
    height :80rpx;
    background: #FFFFFF;
    border-radius: 20rpx;
    margin-left:20rpx;
    margin-bottom :20rpx;
    display:flex;
    justify-content :flex-start;
    align-items :center;
    .grading_l{
      width :34rpx;
      height :34rpx;
      margin-left:16rpx;
    }
    .grading_c{
      font-size: 28rpx;
      font-family: PingFang SC;
      font-weight: 500;
      color: #333333;
      margin-left:16rpx;
    }
    .grading_r{
      width :504rpx;
      height :80rpx;
      font-size: 26rpx;
      font-family: PingFang SC;
      font-weight: 500;
      color: #EE3A3A;
      display :flex;
      justify-content :flex-end;
      align-items: center;
      >img{
        width: 20rpx;
        height: 20rpx;
        margin-left :20rpx;
        margin-top :8rpx;
      }
    }
  }

  .big-icon-button-box{
    width:710rpx;
    height:354rpx;
    margin:0 20rpx 20rpx;
    background :#ffffff;
    border-radius:20rpx;
    display flex
    .left-box{
      width:310rpx;
      height:310rpx;
      margin:22rpx 10rpx 22rpx 15rpx;
      .left-top-img{
        width:310rpx;
        height:150rpx;
        margin-bottom:14rpx;
      }
      .left-bottom-img{
        width:310rpx;
        height:150rpx;
      }
    }
    .right-img{
      width:362rpx;
      height:310rpx;
      margin:22rpx 13rpx 22rpx 0;
    }
  }
  .top-max-box{
    height:119rpx;
    background #fff
    overflow hidden
    .top-big-box{
      height:60rpx;
      width:649rpx;
      background: #F5F5F5;
      border-radius: 30px;
      margin:30rpx auto;
      padding:0 30rpx;
    }
    .top-big-one-type{
      color:#F95F5F;
      line-height:60rpx;
      font-size: 26rpx;
    }
    .top-big-two-type{
      line-height:60rpx;
      font-size: 26rpx;
      display flex
      .left-view{
        flex:1;
        display flex
        color:#333;
        .left-min-view{
          color:#e45656;
        }
      }
      .left-button-view{
        color:#0183fa;
      }
    }
  }
  .button-max-box{
    /*height:446rpx;*/
    background #fff
    margin-bottom:20rpx;
    .button-title{
      line-height:100rpx;
      border-bottom:1rpx solid #E0E0E0;
      padding-left:20rpx;
    }
    .button-max-box{
      /*height:345rpx;*/
      .button-min-box{
        width:250rpx;
        height:172rpx;
        display inline-block
        img{
          width:80rpx;
          height:80rpx;
          margin:34rpx auto 0;
        }
        view{
          line-height:50rpx;
          text-align center;
          font-size:28rpx;
          color: #333;
        }
      }
    }
  }
  .bottom-max-box{
    flex:1;
    background #fff
    margin:0 20rpx 100rpx;
    border-radius:20rpx;
    display flex
    flex-direction column
    overflow-y hidden
    .bottom-title{
      display flex
      border-bottom:1rpx solid #E0E0E0;
      img{
        width:34rpx;
        height:34rpx;
        margin:35rpx 16rpx 0 10rpx;
      }
      view{
        line-height:100rpx;
      }
    }
    .bottom-big-box{
      flex:1;
      overflow-y scroll
      .bottom-for-box:nth-child(1){
        border:none;
      }
      .bottom-for-box{
        height:154rpx;
        margin:0 20rpx;
        border-top:1rpx solid #E0E0E0;
        overflow hidden
        .bottom-top-box{
          font-size:28rpx;
          line-height:28rpx;
          color:#333;
          display:block;
          overflow:hidden;
          text-overflow:ellipsis;
          white-space:nowrap;
          margin:36rpx 0 30rpx;
        }
        .bottom-bottom-box{
          display flex
          view{
            flex:1;
            line-height:48rpx;
            font-size: 28rpx;
            color: #999999;
            display:block;
            overflow:hidden;
            text-overflow:ellipsis;
            white-space:nowrap;
          }
          view:nth-child(2){
            text-align right
          }

        }
      }
      .null-view{
        text-align center;
        color:#999;
        line-height:80rpx;
        font-size:28rpx;
      }
    }
  }
}
</style>
