Newer
Older
gdtMimiProgram / pages / index / index.vue
dutingting on 24 Nov 2022 3 KB 权限问题处理
//首页
<template>
  <view class="index">
    <TabBar></TabBar>
    <view class="menu">
    	<view
    	  v-for="item in menu"
    	  :key="item.id"
    	  class="menu-item"
    	  @click="handleClick(item.id)"
    	  >{{ item.name }}</view
    	>
    </view>
    <u-popup
      customStyle="poppo"
      :show="show"
      :round="10"
      mode="center"
      @close="show = false"
    >
      <u--input
        v-model="inputValue"
        placeholder="填写手机号码"
        border="surround"
      ></u--input>
      <button @click="confirmPhone">确认</button>
    </u-popup>
  </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";
export default {
  components: {
    TabBar,
  },
  data() {
    return {
      currentPagePath: "",
      menu: [
        {
          id: "submit",
          name: "访客信息提交",
        },
        {
          id: "check",
          name: "物联设备状态查看",
        },
      ],
      phone: "",
      show: false,
      active: "", //点击的是哪个按钮
      inputValue: "",
    };
  },
  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) {
      this.active = id;
      const sessionId = uni.getStorageSync("sessionId");
      //如果this.phone为空,先弹出获取手机号,得到手机号之后验证此人是都注册过
      if (!sessionId) {
        await getLogin();
      }
      if (this.phone) {
        this.checkphone();
      } else {
        //如果没有电话就弹出填写电话的框
        this.show = true;
      }
    },
    confirmPhone() {
      this.phone = this.inputValue;
			this.show = false;
      this.checkphone();
    },
    async checkphone() {
      const res = await verifyPhone(this.phone);
      if (res === "用户未注册") {
        wx.reLaunch({
          url: "/pages/register/register",
        });
      } else {
				uni.setStorageSync("registerPhone", this.phone);
        getUserProfile();
        if (this.active === "submit") {
          wx.navigateTo({
            url: `/pages/information/information?id=${this.active}`,
          });
        }
      }
    },
  },
};
</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;
  }
}
.poppo {
  padding: 30rpx;
}
</style>
<style lang="scss">
.index {
  .u-popup__content {
    padding: 20rpx 40rpx;
  }
}
</style>