<template>
  <van-popup v-model:show="visible" position="right" :style="{ width: '60%', height: '100%' }">
    <div class="manager_container">
      <div class="manager_dbox">
        <div @click="navigateAndClose('My')">
          <img src="/img/my_u1.png" alt="">
          <span>个人管理中心</span>
          <van-icon class="r" name="arrow"></van-icon>
        </div>
        <!-- v-if="c" -->
        <div @click="navigateAndClose(`Merchant?id=${PermissionsData.id}`)" v-show="PermissionsData.isshop">
          <img src="/img/my_u2.png" alt="">
          <span>商家管理中心</span>
          <van-icon class="r" name="arrow"></van-icon>
        </div>

        <div @click="navigateAndClose('Operations')" v-if="PermissionsData.iscenter">
          <img src="/img/my_u3.png" alt="">
          <span>运营管理中心</span>
          <van-icon class="r" name="arrow"></van-icon>
        </div>
      </div>

      <div class="manager_dbox">
        <div @click="navigateAndClose('Home')">
          <img src="/img/my_u4.png" alt="">
          <span>首页</span>
          <van-icon class="r" name="arrow"></van-icon>
        </div>

        <div @click="navigateAndClose('Gift')">
          <img src="/img/my_u5.png" alt="">
          <span>礼包</span>
          <van-icon class="r" name="arrow"></van-icon>
        </div>

        <div @click="navigateAndClose('Mall')">
          <img src="/img/my_u6.png" alt="">
          <span>商城</span>
          <van-icon class="r" name="arrow"></van-icon>
        </div>
      </div>

      <button @click="loginout">
        退出登录
      </button>
    </div>
  </van-popup>
</template>

<script>
export default {
  name: 'ManagerPopup',
  props: {
    modelValue: {
      type: Boolean,
      default: false
    }
  },
  emits: ['update:modelValue'],
  data() {
    return {
      showInfo: false,
      saving: false,
      tempData: {},
      PermissionsData: {},
    }
  },
  mounted() {
    this.getPermissions()
  },
  computed: {
    visible: {
      get() {
        return this.modelValue
      },
      set(val) {
        this.$emit('update:modelValue', val)
      }
    }
  },
  methods: {
    navigateAndClose(route) {
      this.visible = false
      this.$nextTick(() => {
        this.$navigate(route)
      })
    },
    getPermissions() {
      if (!this.$isLogin()) {
        // this.$showFailToast('登录状态异常，请重新登录')
        // location.replace('#/Login')
        return
      }
      this.$get('/v1/client/DUsersClient').then(res => {
        this.PermissionsData = {
          id: res.data.id,
          isshop: res.data.isshop,
          iscenter: res.data.col2,
        }
        // console.log(this.PermissionsData);

      }).catch(() => { })
    },
    loginout() {
      this.$showConfirmDialog({
        title: "确认退出？",
      }).then(() => {
        this.$ls.remove('member_token');
        location.replace('#/Login');
        setTimeout(() => {
          location.reload();
        }, 100);
      }).catch(() => { });
    },
    open() {
      this.visible = true
    },
    close() {
      this.visible = false
    },
    goInfo() {
      this.visible = false
      this.loadUserInfo()
      this.showInfo = true
    },
  }
}
</script>