<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.expiretime }}</span>
            </p>
          </li>
          <li>
            <img :src="header" alt="" />
          </li>
        </ul>
      </div>
      <div class="top">
        <div class="vip-box clear">
          <img :src="vip_text" alt="" />
          <div class="open-btn" @click="showT(2)">
            立即开通
            <!-- <span></span> -->
          </div>
        </div>

        <!-- <ul class="vip-box">
          <li class="vip-bg">
            
          </li>
        </ul> -->

        <!-- 我的页面下待收，待发、售后盒子 -->

        <ul class="cell-vip">
          <li
            v-for="(item, index) in cellVip"
            :key="item.name + index"
            class="vip-item"
            @click="showT(index)"
          >
            <img class="cell-my-img" :src="item.id" alt="" />
            <span class="vip-title">{{ item.name }}</span>
          </li>
        </ul>
      </div>

      <div class="bottom">
        <h1 class="common">常用功能</h1>
        <div class="cell-list">
          <div
            class="box-detaile"
            is-link
            v-for="(item, index) in cellList"
            :key="item.name + index"
            @click="goto(item.anchor)"
          >
            <div class="detaile-box">
              <div class="cell-my-img">
                <img :src="item.id" alt="" />
              </div>
              <div class="custom-title">
                {{ item.name }}
              </div>
            </div>
          </div>
        </div>
        <div class="my-btn-main">
          <van-button
            class="my-button"
            block
            type="info"
            @click.native="logout()"
          >
            退出登录
          </van-button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import asyncRequest from "@/apis/my/index";
import resToken from "@/mixins/resToken";
import { Dialog } from "vant";
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"), //用户订单
      unshipped: require("@/assets/images/my/unshipped.png"), //待发货
      shipped: require("@/assets/images/my/shipped.png"), //待收货
      service: require("@/assets/images/my/service.png"), //客户服务
      vip_bg: require("@/assets/images/my/vip_bg.png"), //vip盒子背景图
      vip_text: require("@/assets/images/my/vip_text.png"), //vip
      saleAfter: require("@/assets/images/my/saleAfter.png"), //售后服务
      loading: false,
      cellList: [],
      cellVip: [],
    };
  },
  async created() {
    this.cellList = [
      {
        anchor: "/address",
        id: this.ad,
        name: "我的地址",
      },
      {
        anchor: "/order",
        id: this.order,
        name: "我的订单",
      },
      {
        anchor: "/aboutUs",
        id: this.service,
        name: "联系我们",
      },
    ];
    // await this.getUserInfor();
    this.cellVip = [
      {
        anchor: "/address",
        id: this.unshipped,
        name: "待发货",
      },
      {
        anchor: "/order",
        id: this.shipped,
        name: "待收货",
      },
      {
        anchor: "/aboutUs",
        id: this.saleAfter,
        name: "售后",
      },
    ];
  },
  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);
        }
      }
    },

    showT(index) {
      if (index === 2) {
        Dialog.alert({
          message: "敬请期待!",
        }).then(async () => {});
      } else {
        window.vm.$router.push({
          path: "/order",
          query: {
            type: index + 1 + "",
          },
        });
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.my {
  position: relative;
  width: 100%;
  height: 100%;
  .mine-resume {
    padding-top: 46px;
    position: relative;
    box-sizing: border-box;
    width: 100%;
    .mine-resume-main {
      // background:linear-gradient(0deg, rgba(255,255,255,.1) 0%, #fff 80%);;
      background-color: #fff;
      padding: 0  0;
      ul {
        padding: 16px;
        background: transparent;
        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;
            }
          }
        }
      }
    }
    /**vip开通框 */
    .vip-box {
      width: 100%;
      height: 50px;
      position: relative;
      .vip-bg {
        border-top-left-radius: 13px;
        border-top-right-radius: 13px;
        width: 80%;
        height: 49px;
        position: absolute;
        left: 50%;
        transform: translateX(-50%);
        background-color: #292f46;
        img {
          width: 44px;
          height: 19px;
          display: block;
          position: absolute;
          left: 26px;
          top: 18px;
        }
      }
      .vip-text {
        width: 100px;
        img {
          width: 100%;
        }
      }
    }
    /**vip服务区域样式 */
    .cell-vip {
      padding: 20px 0px;
      height: 50px;
      display: flex;
      .cell-my-img {
        display: block;
        width: 25px;
        height: 24px;
      }
      .vip-title {
        display: inline-block;
        padding-top: 10px;
        height: 20px;
        line-height: 20px;
      }
      .vip-item {
        height: 60px;
        display: inline-block;
        flex: 1;
        text-align: center;
        font-size: 12px;
        color: #4d4d4d;
        line-height: 6px;
        text-align: center;
        img {
          width: 30px;
          height: 28px;
          display: inline-block;
        }
        span {
          height: 28px;
          display: block;
        }
      }
    }
    .my-btn-main {
      width: 100%;
      box-sizing: border-box;
      .my-button {
        box-sizing: border-box;
        display: inline-block;
        border-radius: 20px;
        background: #dbdbdb;
        border: 0;
      }
    }
    /**地址栏收获样式 */
    .cell-list {
      display: flex;
      padding: 0 10px;
      background-color: #fff;
      .van-cell__title {
        width: 200px;
        position: relative;
        left: 0;
        top: 0;
        text-align: center;
        img {
          margin: 0 44px;
        }
      }
    }
    .my-btn-main {
      width: 100%;
      margin: 45px 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;
      }
    }
  }
}
.common {
  margin: 10px;
  width: 110px;
  height: 26px;
  font-size: 14px;
  font-weight: 600;
  color: #333333;
  line-height: 26px;
  position: relative;
  top: 0;
  left: 0;
  padding: 8px 0px 8px 15px;
}
.top {
  width: 100%;
  padding: 0 34.5px;
  box-sizing: border-box;
  background-color: #fff;
  // height:140px;
  .vip-box {
    height: 70px;
    background-color: #292f46;
    border-radius: 15px;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    padding: 13px 13px;
    box-sizing: border-box;
    img {
      display: inline-block;
      height: 23px;
    }
    .open-btn {
      background: linear-gradient(90deg, #dfa460 0%, #f0d0a1 100%);
      border-radius: 10px;
      float: right;
      color: #fff;
      line-height: 18px;
      padding: 3px 8px;
    }
  }
}
.bottom {
  width: 100%;
  position: relative;
  left: 0;
  box-sizing: border-box;
  background-color: #fff;
}

//常用功能下的按钮
.box-detaile {
  flex: 1;
  text-align: center;
  .detaile-box {
    width: 90px;
    margin: 0 auto;
    text-align: center;
    .cell-my-img {
      height: 25px;
      width: 100%;
      overflow: hidden;
      img {
        display: inline-block;
        height: 25px;
        width: auto;
        margin: 0 auto;
      }
    }
    .custom-title {
      margin-top: 8px;
    }
  }
}
</style>
