<template>
  <div class="my">
    <van-nav-bar title="我的" class="van-nav-bar-my-fixed" fixed />
    <!-- right-text="登出"
       -->
    <div class="mine-resume">
      <div class="mine-resume-main">
        <ul class="clear">
          <li v-if="userData === null">
            <p class="title"><span>登录</span></p>
          </li>
          <li v-else>
            <p class="title">
              <span>您好,{{ userData.nickname }}</span>
            </p>
            <p>
              <span
                >有效期：{{ userData.starttime }}~{{
                  userData.expiretime
                }}</span
              >
            </p>
          </li>
          <li>
            <img :src="header" alt="" />
          </li>
        </ul>
      </div>

      <div class="cell-list">
        <van-cell
          is-link
          v-for="(item, index) in cellList"
          :key="item.n + index"
          @click="goto(item.r)"
        >
          <template #title>
            <img class="cell-my-img" :src="item.i" alt="" />
            <span class="custom-title">{{ item.n }}</span>
          </template>
        </van-cell>
        <!-- <van-cell is-link to="order">
          <template #title>
            <img class="cell-my-img" :src="order" alt="" />
            <span class="custom-title">我的订单</span>
          </template>
        </van-cell>
        <van-cell is-link to="aboutUs">
          <template #title>
            <img class="cell-my-img" :src="we" alt="" />
            <span class="custom-title">联系我们</span>
          </template>
        </van-cell> -->
      </div>
      <div class="my-btn-main">
        <van-button
          class="my-button"
          block
          type="info"
          @click.native="logout()"
        >
          退出登录
        </van-button>
      </div>
    </div>
  </div>
</template>

<script>
import asyncRequest from "@/apis/my/index";
import resToken from "@/mixins/resToken";
export default {
  mixins: [resToken],
  data() {
    return {
      header: require("@/assets/images/my/header.png"),
      userData: null,
      ad: require("@/assets/images/my/ad.png"),
      order: require("@/assets/images/my/order.png"),
      we: require("@/assets/images/my/we.png"),
      loading: false,
      cellList: [],
    };
  },
  async created() {
    this.cellList = [
      {
        r: "/address",
        i: this.ad,
        n: "我的地址",
      },
      {
        r: "/order",
        i: this.order,
        n: "我的订单",
      },
      {
        r: "/aboutUs",
        i: this.we,
        n: "联系我们",
      },
    ];
    // await this.getUserInfor();
  },
  mounted() {
    this.getStock();
  },
  methods: {
    goto(url) {
      window.vm.$router.push({
        path: url,
      });
    },

    async getStock() {
      if (!this.loading) {
        let res = await asyncRequest.detail({});
        if (res && res.code == 0) {
          this.userData = res.data;
        } else if (res && res.code >= 100 && res.code <= 104) {
          await this.logout();
        } else {
          this.show_title(res.msg);
        }
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.my {
  background: #ffffff;
  position: relative;
  width: 100%;
  height: 100%;
  .mine-resume {
    padding-top: 46px;
    position: relative;
    box-sizing: border-box;
    width: 100%;

    .mine-resume-main {
      background: #fbfbfb;
      padding: 0 0 10px 0;
      ul {
        padding: 16px;
        background: #ffffff;

        li {
          float: left;
          &:first-child {
            width: calc(100% - 60px);
            p {
              padding: 0 16px 0 0;
              margin: 0;
              color: #1a1a1a;
              font-size: 12px;
              line-height: 16px;
              color: #999999;
              &.title {
                color: #1a1a1a;
                font-weight: bolder;
                font-size: 16px;
                height: 30px;
                line-height: 21px;
                padding: 0 16px 0 0;
              }
            }
          }
          &:last-child {
            width: 60px;
            text-align: center;
            img {
              display: inline-block;
              width: 60px;
            }
          }
        }
      }
    }
    .cell-list {
      .cell-my-img {
        display: inline-block;
        width: 16px;
        height: 18px;
        vertical-align: middle;
        margin: 0 6px 4px 0;
      }
    }
    .my-btn-main {
      width: 100%;
      margin: 18vh 0 0 0;
      padding: 0 16px;
      box-sizing: border-box;
      .my-button {
        box-sizing: border-box;
        display: inline-block;
        border-radius: 20px;
        background: #dbdbdb;
        border: 0;
      }
    }
  }
}
</style>
