Newer
Older
gdtMimiProgram / pages / index / index.vue
//首页
<template>
  <view class="index">
    <TabBar></TabBar>
    <view class="menu">
    	<button
    	  v-for="item in menu"
    	  :key="item.id"
    	  class="menu-item"
    	  @click="handleClick(item.id)"
    	  >{{ item.name }}
			</button>
    </view>
		<!-- 获取手机号popup组件 -->
		<GetPhonePopup :popShow="popShow" @closePop="closePop"/>
  </view>
</template>

<script>
import { mapMutations } from "vuex";
import TabBar from "@/components/tabBar/tabBar.vue";
import { getLogin, getUserProfile } from "@/utils/auth.js";
import { verifyPhone } from "@/api/index.js";
import { getLocationParams } from "@/common/utils.js";
import GetPhonePopup from "@/components/base/getphonePopup.vue";
import { subscription } from "@/utils/common.js"
export default {
  components: {
    TabBar, GetPhonePopup
  },
  data() {
    return {
      currentPagePath: "",
      menu: [
        {
          id: "submit",
          name: "访客信息提交",
        },
        {
          id: "check",
          name: "物联设备状态查看",
        },
      ],
      phone: "",
      popShow: false, //控制授权手机号弹出框
      active: "", //点击的是哪个按钮
    };
  },
  mounted() {
    this.phone = uni.getStorageSync("registerPhone");
    getLogin();
  },
  onShow() {
    let pages = getCurrentPages();
    const curPage = pages[pages.length - 1];
    this.currentPagePath = curPage.route;
    uni.setStorageSync("currentPagePath", this.currentPagePath);
  },
  methods: {
    // ...mapMutations(['setNavRect'])
    async handleClick(id) {
			
			// subscription();
      this.active = id;
      const sessionId = uni.getStorageSync("sessionId");
      //如果this.phone为空,先弹出获取手机号,得到手机号之后验证此人是都注册过
      if (!sessionId) {
        await getLogin();
      }
      if (this.phone) {
        this.checkphone();
      } else {
				//弹获取手机号
        this.popShow = true;
      }
    },
		//通过手机号检查是否存在这个用户
    async checkphone() {
      const res = await verifyPhone(this.phone);
      if (res === "用户未注册") {
        wx.reLaunch({
          url: "/pages/register/register",
        });
      } else {
				uni.setStorageSync("registerPhone", this.phone);
        await getUserProfile();
				
				if (uni.getStorageSync("userInfo")) {
				  const userInfo = JSON.parse(uni.getStorageSync("userInfo"));
				  if (userInfo.salt === "物业人员") {
				    subscription();
				  } 
				}
				
        if (this.active === "submit") {
          wx.navigateTo({
            url: `/pages/information/information?id=${this.active}`,
          });
        }
      }
    },
		
		closePop() {
			this.popShow = false;
		}
  },
};
</script>

<style lang="scss" scoped>
.index {
  padding-top: 40rpx;
  .menu{
	display: flex;
	justify-content: space-around;  
  }
  .menu-item {
    width: 320rpx;
    height: 320rpx;
    text-align: center;
    line-height: 320rpx;
    border-radius: 10rpx;
    color: #000;
    background-color: #eee;
    border: 1px solid gray;
  }
}
</style>
<style lang="scss">
.index {
  .u-popup__content {
    padding: 30rpx 40rpx;
		padding-bottom: 0;
  }
}
</style>