<template>
  <view class="page-raw">
    <view class="header">
      <view class="left">
        <u-icon class="icon" color="white" name="arrow-left" @click="uni.navigateBack({})" />
      </view>
      <view>
        <u-avatar :src="src" size="large"></u-avatar>
        <view>{{ sessiondata.loginName }}</view>
        <view>{{ sessiondata.roles[0].roleName }}: {{ sessiondata.nickName }}</view>
        <!-- <view>仓库管理员 ID:0000001</view> -->
      </view>
    </view>
    <view class="container">
      <view class="title">
        <view>
          <view>7</view>
          <view class="title-list">待收货</view>
        </view>
        <view class="shuxian"></view>
        <view>
          <view>20</view>
          <view class="title-list">待入库</view>
        </view>
        <view class="shuxian"></view>
        <view>
          <view>11</view>
          <view class="title-list">待出库</view>
        </view>
        <view class="shuxian"></view>
        <view>
          <view>3</view>
          <view class="title-list">待盘点</view>
        </view>
      </view>
    </view>
    <view class="astyle astyleversion">
      <view> 版本 </view>
      <view> Version:{{ version }} </view>
      <!-- <u-button
        @click.native="
          uni.navigateTo({
            url: `/pages/lanju/mes/ProductionQtyInsp/index`,
          })
        "
      >
        <u-icon size="80" name="/static/icons/icon-02.png"></u-icon>
        <text class="name">生产质检 </text>
      </u-button> -->
    </view>
    <view class="astyle">
      <view @click="session.logout()"> 退出登录 </view>
    </view>
  </view>
</template>

<script lang="ts">
import { Component } from 'vue-property-decorator';
import { BasePage } from '@/components/base/page';
import dayjs from 'dayjs';
import model from './model';
import { session } from '@/store/modules/session';
import { auth } from '@/store/modules/auth';

@Component
export default class RawHome extends BasePage {
  model = model;
  src: 'http://pic2.sc.chinaz.com/Files/pic/pic9/202002/hpic2119_s.jpg';
  today = dayjs().format('YYYY-MM-DD dddd');
  version = '';
  checkversion: any = {};
  sessiondata: any = '';
  onLoad() {
    // this.model.getMenuList();
    uni.setStorageSync('version', this.version);
    this.sessiondata = session;
    this.version = auth.getVersion;
  }
  // compareVersion(version1: any, version2: any) {
  //   //如果version1 大 会返回1  &&&  如果version2 大 会返回 -1
  //   const newVersion1 = `${version1}`.split('.').length < 3 ? `${version1}`.concat('.0') : `${version1}`;
  //   const newVersion2 = `${version2}`.split('.').length < 3 ? `${version2}`.concat('.0') : `${version2}`;
  //   //计算版本号大小,转化大小
  //   function toNum(a) {
  //     const c = a.toString().split('.');
  //     const num_place = ['', '0', '00', '000', '0000'],
  //       r = num_place.reverse();
  //     for (let i = 0; i < c.length; i++) {
  //       const len = c[i].length;
  //       c[i] = r[len] + c[i];
  //     }
  //     return c.join('');
  //   }
  //   //检测版本号是否需要更新
  //   function checkPlugin(a: any, b: any) {
  //     const numA = toNum(a);
  //     const numB = toNum(b);
  //     return numA > numB ? 1 : numA < numB ? -1 : 0;
  //   }
  //   return checkPlugin(newVersion1, newVersion2);
  // }
  // async checkupdate() {
  //   try {
  //     await this.model.checkupdate();
  //     const queryversion = this.model.checkversion.version;
  //     //const queryversion = this.checkversion.Version.match(/\d+\.\d+\.\d+/)[0];
  //     let versionNumber = this.compareVersion(this.version, queryversion); //this.version, queryversion
  //     if (versionNumber == -1) {
  //       // 版本更新提示
  //       uni.showModal({
  //         content: '新版本为：' + this.model.checkversion.version + ',' + '是否更新？',
  //         success: (res) => {
  //           if (res.confirm) {
  //             //确定执行下载
  //             let downloadApkUrl = this.model.checkversion.fileAddress;
  //             uni.showLoading({
  //               title: '下载中',
  //             });
  //             ////////////////uni下载方法,
  //             uni.downloadFile({
  //               url: downloadApkUrl,
  //               success: (downloadResult) => {
  //                 uni.hideLoading();
  //                 if (downloadResult.statusCode == 200) {
  //                   //安装更新
  //                   plus.runtime.install(downloadResult.tempFilePath as any, { force: true }, function () {
  //                     //uni.showToast('更新成功，重启');
  //                     plus.runtime.restart();
  //                   });
  //                 }
  //               },
  //             });
  //           } else if (res.cancel) {
  //             console.log();
  //           }
  //         },
  //       });
  //       return;
  //     } else {
  //       uni.showToast({
  //         title: '无更新内容',
  //         icon: 'none',
  //       });
  //     }
  //   } catch (e) {
  //     console.log('error', e);
  //   }
  // }
}
</script>

<style lang="scss" scoped>
.page-raw {
  background-color: #f4f7fc;
  min-height: 100%;

  .header {
    // background-color: #d9001b;
    background-image: url(../../static/images/me.jpeg);
    background-size: 100% 100%;
    background-repeat: no-repeat;
    height: 600rpx;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    .left {
      position: absolute;
      left: 10rpx;
      top: 10rpx;
    }

    //padding: 60rpx 30rpx 40rpx;
    //color: #fff;
    //box-shadow: 0 1rpx 5rpx #6b90ef;
    .welcome {
      display: flex;
      justify-content: space-between;

      .name {
        font-size: 44rpx;
        font-weight: 500;
        margin-left: 62rpx;
      }
      .logout {
        border: 2rpx solid;
        width: 100rpx;
        border-radius: 8rpx;
        text-align: center;
      }
    }
    .date {
      margin-top: 30rpx;
      font-size: 28rpx;
      font-weight: 400;
      opacity: 0.7;
    }
  }

  .container {
    margin-top: -86rpx;
    .title {
      display: flex;
      background-color: #ffffff;
      height: 100px;
      flex-direction: row;
      justify-content: space-around;
      margin: auto;
      margin: auto;
      text-align: center;
      padding: 54rpx;
      .shuxian {
        height: 36rpx;
        border: 1rpx solid #797979;
        margin-top: 10rpx;
      }
      .title-list {
        color: #797979;
      }
    }
    .u-row {
    }
    .u-col {
      margin-bottom: 30rpx;
    }
    .u-btn {
      height: 160rpx;
      padding: 0 30rpx;
      border: 1px solid #f0f5fc;
      color: #42465a;
      font-size: 30rpx;
      font-weight: 400;
      &:after {
        border-color: #f0f5fc;
        border-radius: 4rpx;
      }
      .name {
        flex: 1;
        margin-left: 32rpx;
        text-align: left;
      }
    }
  }
  .astyle {
    background-color: #ffffff;
    padding: 32rpx;
    margin-top: 4rpx;
    text-align: center;
    border: 1rpx solid #f2f2f2;
    border-radius: 8rpx;
  }
}
.astyleversion {
  display: flex;
  justify-content: space-between;
}
</style>
