<template>
  <div id="container">
    <!--    banner模块-->
    <banner></banner>
    <!--    未登录 登录窗口模块-->
    <div class="login_card" v-if="!is_login">
      <!--      登录窗口-->
      <login_container v-if="status == 'login'"
                       @changeStatus="change_status"
                       @changeTitle="change_title"
      ></login_container>
      <!--      关于水母-->
      <scan_container v-if="status == 'scan'"></scan_container>
      <!--      注册窗口-->
      <regist_container v-if="status == 'regist'"
                        @changeStatus='change_status'
                        @change_login_status="change_login_status"
                        :title="regist_title"
      ></regist_container>

    </div>
    <!--    登陆后 的个人首页-->
    <div class="personal_card" v-if="is_login">
      <personal_container></personal_container>
      <device_container></device_container>
    </div>
    <div class="service">
      <div class="head">
        <div>
          <div class="line"></div>
          <div class="title">功能服务</div>
        </div>
      </div>
      <div class="content">
        <img src="https://img.shuimuai.com/chongzhizhongxin.png" @click="to_page('recharge')"></img>
        <img src="https://img.shuimuai.com/shebeiguanli.png" @click="to_page('user_center')"></img>
        <img src="https://img.shuimuai.com/chongzhizhongxin.png" @click="to_page('report')"></img>
        <img src="https://img.shuimuai.com/shebeiguanli.png" @click="to_page('agent/index')"></img>
      </div>
    </div>
    <van-toast id="van-toast"/>

  </div>
</template>

<script>
import banner from '@/components/banner'
import login_container from '@/components/index/login'
import scan_container from '@/components/index/scan'
import regist_container from '@/components/index/regist'
import personal_container from "@/components/index/personal";
import device_container from "@/components/device/device";
import Toast from '../../../static/vant/toast/toast';


export default {
  name: "index_container",
  components: {
    banner, login_container, scan_container, regist_container, personal_container, device_container
  },
  data() {
    return {
      // 三种状态 扫码scan 注册regist 登录login
      status: "login",
      is_login: false,
      regist_title: ""
    }
  },
  methods: {
    get_init_data() {
    },
    //切换到扫码
    change_status($status) {
      this.status = $status
    },
    //跳转充值中心
    to_recharge() {
      mpvue.navigateTo({
        url: "/pages/user_center/recharge/main"
      })
    },
    //修改登录状态
    change_login_status() {
      this.is_login = this.$store.getters.get_login_status
    },
    // 修改界面的文字
    change_title($status) {
      if ($status == 0) {
        this.regist_title = "注册"
      } else if ($status == 1) {
        this.regist_title = "登录"
      }
    },
    //跳转页面
    to_page($page) {
      if (!this.is_login){
        Toast.fail("请先登录")
        return false
      }
      mpvue.navigateTo({
        url: "/pages/" + $page + "/main"
      })
    }
  },
  mounted() {
  },
  onLoad($option) {
    //  判断存储是否登录
    let $token = wx.getStorageSync('token')
    if ($token) {
      this.$store.commit('set_token', $token);
      this.$store.commit('set_login', true);
      this.is_login = this.$store.getters.get_login_status
    }
  }
}
</script>

<style scoped>
@import "index.css";
</style>
