<template>
  <div id="index">
    <admin-frame :useTop="false" :usePage="false" :useNav="false">
      <template v-slot:info>
        <van-col span="24" class="one">
          <van-col span="4" class="left">
            <van-image :src="icon"></van-image>
          </van-col>
          <van-col span="20" class="right">
            <van-col span="24" class="info">{{ userInfo.phone }}</van-col>
            <van-col span="24" class="info">联系电话：{{ userInfo.name }}</van-col>
          </van-col>
        </van-col>
        <van-col span="24" class="two">
          <van-cell title="基本信息" @click="to('basic')" is-link />
          <van-cell title="机构用户" @click="to('mechanism')" is-link v-if="userInfo.role == '1'" />
          <van-cell title="平台用户" @click="to('users')" is-link v-if="userInfo.role == '1' || userInfo.role == '2'" />
          <van-cell title="代理机构" @click="to('agentmech')" is-link v-if="userInfo.role == '1'" />
          <van-cell title="咨询师" @click="to('answertea')" is-link v-if="userInfo.role == '1'" />
          <van-cell title="专利运营" @click="toPatent('patent')" is-link />
          <van-cell title="修改密码" @click="to('password')" is-link v-if="userInfo.role == '1' || userInfo.role == '2' || userInfo.role == '3'" />
          <van-cell title="退出登录" @click="logout" is-link />
        </van-col>
      </template>
    </admin-frame>
  </div>
</template>

<script>
import adminFrame from '@frame/src/components/mobile-frame/mobile-main.vue';
import { mapState, createNamespacedHelpers } from 'vuex';
export default {
  name: 'index',
  props: {},
  components: {
    adminFrame,
  },
  data: function () {
    return {
      icon: require('@a/icon.jpg'),
      userInfo: {},
    };
  },
  async created() {
    if (this.user) this.$set(this, `userInfo`, this.user);
  },
  methods: {
    // 退出登录
    logout() {
      let token = localStorage.removeItem('token');
      let openid = sessionStorage.removeItem('openid');
      if (token == undefined && openid == undefined) {
        this.$toast({ type: 'fail', message: '退出登录成功' });
        this.$router.push({ path: '/login', query: { path: '/account/index', type: '1' } });
      }
    },
    to(type) {
      this.$router.push({ path: `/account/${type}/index` });
    },
    // 专利运营
    toPatent(type) {
      this.$router.push({ path: `/${type}/index` });
    },
  },
  computed: {
    ...mapState(['user']),
  },
  metaInfo() {
    return { title: this.$route.meta.title };
  },
  watch: {
    test: {
      deep: true,
      immediate: true,
      handler(val) {},
    },
  },
};
</script>

<style lang="less" scoped>
.one {
  background-color: #fff;
  margin: 0 0 10px 0;
  padding: 0 10px;
  .left {
    text-align: center;
    padding: 20px 0;
  }
  .right {
    padding: 20px 10px;
    .info {
      margin: 5px 0;
    }
  }
}
</style>
