<template>
  <view>
    <template v-if="!userInfo || !userInfo.realName">
      <view class="top d-flex a-center px3 main-color-bg" @tap="login">
        <view class="img">
          <image src="/static/images/user_pic.png" mode=""></image>
        </view>
        <view class="ml-3 f-size-36 text-color-white">登录 / 注册</view>
      </view>
    </template>

    <template v-else>
      <view class="top d-flex a-center px3 main-color-bg">
        <view class="img">
          <image :src="myAvatar" @error="myDefaultAvatar" mode=""></image>
        </view>
        <view class="ml-3 f-size-36 text-color-white">{{
          userInfo.realName
        }}</view>
      </view>
    </template>

    <view class="divider"></view>
    <view class="often px3 bg-color-white">
      <view class="f-size-32 f-weight-bold py2 border-bottom">常用功能</view>
      <view class="d-flex f-wrap my2 py3">
        <!-- <view class="col4 mb-2" @tap="handleCode">
          <view class="d-flex f-column a-center j-center">
            <view class="iconfont icon-saoma main-color-text"></view>
            <image src="../../static/images/code.png" mode=""></image>
            <text class="f-size-26 text-color-6 mt-2">设备扫码</text>
          </view>
        </view> -->
        <!--                <navigator class="col4 mb-2" url="../check/check">
                    <view class="d-flex f-column a-center j-center">
                        <view class="iconfont icon-weixiu z-bl"></view>
                        <text
                            class="f-size-26 text-color-6 mt-2"
                        >点检管理</text
                        >
                    </view>
                </navigator>
                <navigator class="col4 mb-2" url="../inspection/inspection">
                    <view class="d-flex f-column a-center j-center">
                        <view class="iconfont icon-xunjianguanli z-bl"></view>
                        <text
                            class="f-size-26 text-color-6 mt-2"
                        >巡检填报</text
                        >
                    </view>
                </navigator>-->
        <navigator class="col4 mb-2" url="../maintain/maintain">
          <view class="d-flex f-column a-center j-center">
            <view class="iconfont icon-tubiaozhizuomoban-135 z-bl"></view>
            <text class="f-size-26 text-color-6 mt-2">保养管理</text>
          </view>
        </navigator>
        <!--                <navigator class="col4 mb-2" url="../running/running">
                    <view class="d-flex f-column a-center j-center">
                        &lt;!&ndash; <image src="../../static/images/code.png" mode=""></image> &ndash;&gt;
                        <view
                            class="iconfont icon-icon-GIS_yunhangguanli main-color-text"
                        ></view>
                        <text
                            class="f-size-26 text-color-6 mt-2"
                        >运行填报</text
                        >
                    </view>
                </navigator>-->
        <navigator class="col4 mb-2" url="../repair/repair">
          <view class="d-flex f-column a-center j-center">
            <!-- <image src="../../static/images/code.png" mode=""></image> -->
            <view class="iconfont icon-baoxiu main-color-text" style="color: #0f6fb9"></view>
            <text class="f-size-26 text-color-6 mt-2 ">设备报修</text>
          </view>
        </navigator>
        <!--                <navigator class="col4 mb-2" url="../receive/receive">
                    <view class="d-flex f-column a-center j-center">
                        &lt;!&ndash; <image src="../../static/images/code.png" mode=""></image> &ndash;&gt;
                        <view
                            class="iconfont icon-houqinwuzi main-color-text"
                        ></view>
                        <text
                            class="f-size-26 text-color-6 mt-2"
                        >备品备件</text
                        >
                    </view>
                </navigator>-->
        <navigator class="col4 mb-2" url="../equipment/equipment">
          <view class="d-flex f-column a-center j-center">
            <!-- <image src="../../static/images/shebei.png" mode=""></image> -->
            <view class="iconfont icon-shebei z-bl"></view>
            <text class="f-size-26 text-color-6 mt-2">设备台账</text>
          </view>
        </navigator>
        <!--                <view class="col4 mb-2" @tap="handleCodeIn">
                    <view class="d-flex f-column a-center j-center">
                        <view
                            class="iconfont icon-houqinwuzi main-color-text"
                            style="color: #fda621"
                        ></view>
                        <text class="f-size-26 text-color-6 mt-2">入库</text>
                    </view>
                </view>
                <view class="col4 mb-2" @tap="handleCodeOut">
                    <view class="d-flex f-column a-center j-center">
                        <view
                            class="iconfont icon-houqinwuzi main-color-text"
                            style="color: #fda621"
                        ></view>
                        <text class="f-size-26 text-color-6 mt-2">出库</text>
                    </view>
                </view>-->
        <!--<navigator class="col4 mb-2" url="/pages/repair/repair-edit">
          <view class="d-flex f-column a-center j-center">
            <view class="iconfont icon-baoxiu"></view>
            <text class="f-size-26 text-color-6 mt-2">报修验收</text>
          </view>
        </navigator>-->
      </view>
    </view>
    <view class="often px3 bg-color-white">
      <view class="f-size-32 f-weight-bold py2 border-bottom">仓库功能</view>
      <view class="d-flex f-wrap my2 py3">

        <navigator class="col4 mb-2" url="../in-store/list">
          <view class="d-flex f-column a-center j-center">
            <view class="iconfont icon-ruku main-color-text" style="color: #f1650c"></view>
            <text class="f-size-26 text-color-6 mt-2 main-color-text">入库</text>
          </view>
        </navigator>
        <navigator class="col4 mb-2" url="../out-store/list">
          <view class="d-flex f-column a-center j-center">
            <view class="iconfont icon-chuku main-color-text" style="color: #fda621"></view>
            <text class="f-size-26 text-color-6 mt-2">出库</text>
          </view>
        </navigator>
        <view class="col4 mb-2" @tap="handleSpareStore">
          <view class="d-flex f-column a-center j-center">
            <view class="iconfont icon-shebei main-color-text" style="color: #f1650c"></view>
            <text class="f-size-26 text-color-6 mt-2 main-color-text">库存信息</text>
          </view>
        </view>
        <!-- <view class="col4 mb-2" @tap="handleSpareQrCode">
                    <view class="d-flex f-column a-center j-center">
                        <view
                            class="iconfont icon-saoma main-color-text"
                            style="color: #f1650c"
                        ></view>
                        <text
                            class="f-size-26 text-color-6 mt-2 main-color-text"
                        >备件扫码</text
                        >
                    </view>
                </view> -->
      </view>
    </view>
    <u-tabbar :list="tabbar" :mid-button="true" active-color="#0082ff"></u-tabbar>
  </view>
</template>

<script>
export default {
  data() {
    return {
      userInfo: {
        realName: null,
        avatar: null
      },
      gatherTask: {
        maintainTask: 0,
        lubricationTask: 0,
        oilTask: 0,
        repairTask: 0
      },
      myAvatar: '',
      tabbar: [
        {
          iconPath: '/static/tabars/home.png',
          pagePath: '/pages/home/home',
          selectedIconPath: '/static/tabars/home_s.png',
          text: '首页'
        },
        {
          iconPath: '/static/tabars/order.png',
          pagePath: '/pages/operate/operate',
          selectedIconPath: '/static/tabars/order_s.png',
          text: '功能'
        },
        {
          iconPath: '/static/tabars/publish.png',
          pagePath: '/pages/middle/middle',
          selectedIconPath: '/static/tabars/publish.png',
          text: '报修',
          midButton: true
        },
        {
          iconPath: '/static/tabars/tiding.png',
          pagePath: '/pages/tidings/tidings',
          selectedIconPath: '/static/tabars/tiding_s.png',
          text: '消息'
        },
        {
          iconPath: '/static/tabars/mine.png',
          pagePath: '/pages/my/my',
          selectedIconPath: '/static/tabars/mine_s.png',
          text: '我的'
        }
      ]
    }
  },
  onLoad() { },

  onShow() {
    this.userInfo = this.$BaseTool.UserUtil.getUserInfo()
    if (!this.userInfo || !this.userInfo.username) {
      uni.showModal({
        content: '登录后方可查看内容',
        showCancel: true,
        success: result => {
          uni.reLaunch({ url: '/pages/login/login' })
        }
      })
      return
    }
    this.myAvatar = this.$BaseTool.UserUtil.getFileUrl(this.userInfo.avatar)
    this.$Http.getGatherTask().then(res => {
      this.gatherTask = res.data
    })
  },
  methods: {
    myDefaultAvatar() {
      this.myAvatar = '/static/images/user_pic.png'
    },
    getSetting() {
      uni.navigateTo({
        url: '../setting/setting'
      })
    },

    // 维修任务
    handleService() {
      uni.navigateTo({
        url: '../service/service'
      })
    },
    // 加油任务
    handleOiling() {
      uni.navigateTo({
        url: '../oiling/oiling'
      })
    },
    // 保养任务
    handleMaintain() {
      uni.navigateTo({
        url: '../maintain/maintain'
      })
    },
    // 润滑任务
    handleLubrication(e) {
      uni.navigateTo({
        url: '../lubrication/lubrication'
      })
    },
    handleSpareStore() {
      uni.navigateTo({
        url: '../spare/spare-store'
      })
    },
    // 设备扫码
    handleCode() {
      // #ifdef H5
      uni.showToast({
        title: '暂不支持该功能',
        icon: 'none'
      })
      // #endif
      // #ifndef H5
      uni.scanCode({
        success(e) {
          console.log(e.result)
          if (e.result) {
            const sbId = e.result.split('=')[1]
            if (sbId != null) {
              uni.navigateTo({
                url: '/pages/equipment-detail/equipment-detail?detailId=' + sbId
              })
            } else {
              uni.showToast('非本系统二维码，无法识别')
            }
          }
        }
      })
      // #endif
    },
    // 备件扫码
    handleSpareQrCode() {
      // #ifdef H5
      uni.showToast({
        title: '暂不支持该功能',
        icon: 'none'
      })
      /*uni.navigateTo({
                url:'/pages/spare/spare-detail?detailId=607fd4b643dc4e04acc0a6fe'
            });*/
      // #endif
      // #ifndef H5
      uni.scanCode({
        success(e) {
          console.log(e.result)
          if (e.result) {
            uni.navigateTo({
              url: '/pages/spare/spare-detail?detailId=' + e.result
            })
          }
        }
      })
      // #endif
    },
    // 登录
    login() {
      uni.navigateTo({
        url: '../login/login'
      })
    }
  }
}
</script>

<style lang="less">
page {
  background-color: #f4f4f4;
}

.often {
  image {
    width: unit(50, rpx);
    height: unit(50, rpx);
  }

  .iconfont {
    font-size: unit(50, rpx);
  }
}

.top {
  height: unit(200, rpx);

  .img {
    width: unit(128, rpx);
    height: unit(128, rpx);
    border-radius: 50%;

    image {
      width: unit(128, rpx);
      height: unit(128, rpx);
      border-radius: 50%;
      background-color: #999;
      // border: 5rpx solid #fff;
    }
  }
}
</style>
