<template>
  <view style="background-color: #F6F6F6;height: 100%;">
    <image src="../../image/home.jpg" style="width: 100%;height: 130px;"></image>
    <view style="display: block; padding-left: 30px; padding-top: 12px;">
      <text>欢迎你，{{ displayUsername }}！</text>
    </view>
    <view style="display: block;" v-if="isUser">
      <view style="display: flex;text-align: center;margin-top: 20px;">
        <view style="width: 25%;">
          <image src="../../image/icon/code.png" style="width: 40px;height: 40px;" @tap='goCode'></image>
          <view>进出码</view>
        </view>
        <view style="width: 25%;">
          <image src="../../image/icon/feedback.png" style="width: 40px;height: 40px;" bindtap='goFeedback'></image>
          <view>反馈查看</view>
        </view>
        <view style="width: 25%;">
          <image src="../../image/icon/apply.png" style="width: 40px;height: 40px;" bindtap='goApply'></image>
          <view>申请记录</view>
        </view>
      </view>
      <view style="display: flex;text-align: center;margin-top: 20px;">
        <view style="width: 25%;">
          <image src="../../image/icon/yq.png" style="width: 40px;height: 40px;" data-web="xgPage" bindtap='goWebPage'>
          </image>
          <view>疫情追踪</view>
        </view>
        <view style="width: 25%;">
          <image src="../../image/icon/report.png" style="width: 40px;height: 40px;" bindtap='goReport'></image>
          <view>今日日报</view>
        </view>
        <view style="width: 25%;">
          <image src="../../image/icon/updPwd.png" style="width: 40px;height: 40px;" bindtap='goUpdPwd'></image>
          <view>密码修改</view>
        </view>
        <view style="width: 25%;">
          <image src="../../image/icon/fk.png" style="width: 40px;height: 40px;" bindtap='goKf'></image>
          <view>提交反馈</view>
        </view>
      </view>
    </view>
    <view style="display: block;" v-if="isAdmin">
      <view style="display: flex;text-align: center;margin-top: 20px;">
        <view style="width: 25%;">
          <image src="../../image/icon/danger.png" style="width: 40px;height: 40px;" bindtap='goCode'></image>
          <view>不健康人员</view>
        </view>
        <view style="width: 25%;">
          <image src="../../image/icon/feedback.png" style="width: 40px;height: 40px;" bindtap='goFeedbackReplay'>
          </image>
          <view>反馈回复</view>
        </view>
        <view style="width: 25%;">
          <image src="../../image/icon/apply.png" style="width: 40px;height: 40px;" bindtap='goApplyReplay'></image>
          <view>申请审批</view>
        </view>
      </view>
      <view style="display: flex;text-align: center;margin-top: 20px;">
        <view style="width: 25%;">
          <image src="../../image/icon/gg.png" style="width: 40px;height: 40px;" data-web="xgPage" bindtap='goNotice'>
          </image>
          <view>公告发布</view>
        </view>
        <view style="width: 25%;">
          <image src="../../image/icon/visitor.png" style="width: 40px;height: 40px;" bindtap="goVisitor"></image>
          <view>访客审批</view>
        </view>
        <view style="width: 25%;">
          <image src="../../image/icon/count.png" style="width: 40px;height: 40px;" bindtap='goCount'></image>
          <view>分配账号</view>
        </view>
        <view style="width: 25%;">
          <image src="../../image/icon/_report.png" style="width: 40px;height: 40px;" bindtap='toRedList'></image>
          <view>今日未填</view>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
import Taro from '@tarojs/taro'
import { eventCenter, getCurrentInstance } from '@tarojs/taro'

import './index.css'

export default {
  setup() {
  },
  data() {
    return {
      userInfo: null,
      displayUsername: "",
      isUser: false,
      isAdmin: false,
    }
  },
  mounted() {
    eventCenter.once(getCurrentInstance().router.onShow, () => {
      console.log('onShow')
      this.userInfo = Taro.getStorageSync("userInfo");
      this.displayUsername = this.userInfo?.username ?? "请登录";
      if (!this.userInfo) {
        console.log("用户未登录")
        Taro.redirectTo({
          url: '/pages/index/login'
        })
      } else {
        this.isUser = this.userInfo.userType == "user";
        this.isAdmin = this.userInfo.userType == "admin";
      }
    })
  },
  methods: {
    goCode() {
      // Taro.navigateTo({
      //   url: '/pages/residents/code'
      // })
      Taro.switchTab({
        url: '/pages/residents/code'
      })
    }
  }
}
</script>
