<template>
  <div class="my">
    <!-- <van-nav-bar title="我的" class="van-nav-bar-my-fixed" fixed /> -->
    <!-- right-text="登出"
       -->
    <div class="mine-resume">
      <div class="bgImg">
        <img src="@/assets/images/my/personal/bgImg.png" alt="" />
      </div>
      <div class="my-info">
        <img src="@/assets/images/my/personal/my-info.png" alt="" />
        <div class="mine-resume-main">
          <ul class="clear headerBox">
            <div class="headerImg">
              <img :src="header" alt="" />
              <div class="header-info">
                <p>欢迎您!</p>
                <span>尊敬的金卡用户</span>
              </div>
            </div>
            <div class="headerDesc">
              <li v-if="userData === null">
                <p class="title"><span>登录</span></p>
              </li>
              <li v-else class="usable">
                <span>有效期至{{ userData.expiretime }}</span>
              </li>
              <li class="header-username">
                <span>NO:{{ username }}</span>
              </li>
            </div>
          </ul>
        </div>
      </div>

      <div class="top">
        <!-- 我的页面下待收，待发、售后盒子 -->
        <p>我的订单</p>
        <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">
        <p class="common">常用功能</p>
        <div class="cell-list">
          <div
            class="box-detaile"
            is-link
            v-for="(item, index) in cellList"
            :key="item.name + index"
            @click="goto(item.anchor, item.name)"
          >
            <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 class="footer">
            <img src="@/assets/images/my/footer.png" />
          </div>
          <div style="height: 50px"></div>
        </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,
      active: require("@/assets/images/my/menu.png"),
      ad: require("@/assets/images/my/ad.png"), //地理定位
      order: require("@/assets/images/my/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: [],
      canStockBag: "",
      canStockBox: "",
      username: "",
    };
  },
  async created() {
    this.cellList = [
      {
        anchor: "/address",
        id: this.ad,
        name: "我的地址",
      },
      {
        anchor: "/order",
        id: this.order,
        name: "历史订单",
      },
      {
        anchor: "/referMenu",
        id: this.active,
        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: "/referMenu",
        id: this.saleAfter,
        name: "售后",
      },
    ];
  },

  mounted() {
    this.getStock();
  },
  methods: {
    goto(url, name) {
      window.vm.$router.push({
        path: url,
        query: {
          type: name,
        },
      });
    },

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

    showT(index) {
      console.log(index);
      if (index === 2) {
        // Dialog.alert({
        //   message: "敬请期待!",
        // }).then(async () => {});
        window.vm.$router.push({
          path: "/referMenu",
          query: {
            type: "售后",
          },
        });
      } 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%;
    height: 100vh;
    background: #e6e6dc;

    .mine-resume-main {
      // background:linear-gradient(0deg, rgba(255,255,255,.1) 0%, #fff 80%);;
      // background-color: #fff;
      padding: 0 0;
      // margin: -19vh 0 0 0;
      left: 10px;
      top: 20px;
      position: absolute;

      ul {
        background: transparent;
        li {
          float: left;
          &:first-child {
            width: calc(100% - 60px);
            p {
              width: 188px;
              padding: 0 16px 0 0;
              margin: 0;
              color: #daad70;

              // color: #1a1a1a;
              font-size: 12px;
              line-height: 16px;
              color: #999999;
              &.title {
                color: #daad70;

                // color: #1a1a1a;
                font-weight: bolder;
                font-size: 16px;
                height: 100px;
                line-height: 21px;
                padding: 0 16px 0 0;
              }
            }
          }
          &:last-child {
            // width: 60px;
            text-align: center;
            margin: 0 0 0 0;
          }
        }
      }
      .headerBox {
        width: 80vw;
        margin: 0px auto;
      }
      .headerImg {
        width: 47.5px;
        height: 47.5px;
        border-radius: 50%;
        // position: absolute;
        // left: 35px;
        // top: 20px;
        img {
          width: 100%;
          border-radius: 50%;
        }
        .header-info {
          width: 86px;
          height: 29.5px;
          float: left;
          margin: -43px 0 0 60px;
          // position: absolute;
          // left: 55px;
          // top: 7px;
          p {
            margin: 0;
            // width: 74px;
            height: 15px;
            font-size: 15px;
            font-family: Source Han Sans CN;
            font-weight: 500;
            color: #5c3501;
            line-height: 15px;
            opacity: 0.8;
          }
          span {
            color: #5c3501;
          }
        }
      }
      .headerDesc {
        width: 90vw;
        overflow: hidden;
        display: flex;
        height: 19px;
        margin: 0 0 0 -10px;
        .usable {
          // width: 188px;
          // height: 19px;
          margin: 0 5px 0 0;
          width: 52vw;
          font-size: 0.5rem;
          font-family: Source Han Sans CN;
          font-weight: 400;
          color: #5c3501;
          line-height: 10px;
          height: 13px;
          // position: absolute;
          overflow: hidden;
          left: 30px;
          top: 110px;
        }
        .header-username {
          margin: 0 0px 0 10px;

          font-size: 0.5rem;
          font-family: Source Han Sans CN;
          font-weight: 500;
          color: #5c3501;
          line-height: 10px;
          height: 10px;
          // position: absolute;
          left: 235px;
          top: 110px;
        }
      }
    }
    /**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%;
        }
      }
    }

    .my-btn-main {
      width: 321.5px;
      margin: 40px auto 0;
      box-sizing: border-box;
      // .my-button {
      //   box-sizing: border-box;
      //   display: inline-block;
      //   border-radius: 20px;
      //   background: #dbdbdb;
      //   border: 0;
      // }
      .footer {
        width: 321.5px;
        height: 95px;
        img {
          width: 100%;
        }
      }
    }
    //  <!-- 我的页面下待收，待发、售后盒子 -->
    .top {
      width: 100%;
      padding: 0 20px;
      box-sizing: border-box;
      background: #e6e6dc;
      margin: 0vh 0 0 0;
      // height:140px;
      p {
        width: 64.5px;
        height: 15px;
        font-size: 16px;
        font-family: Source Han Sans CN;
        font-weight: 400;
        color: #242424;
        line-height: 13px;
      }
      .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;
        }
      }
    }
    /**vip服务区域样式 */
    .cell-vip {
      // width: 331px;
      height: 81px;
      background: #fcfcf0;
      border-radius: 16px;
      padding: 10px 0px 20px 0;
      height: 50px;
      display: flex;
      margin: 0 0 0 0px;
      .cell-my-img {
        display: block;
        width: 45px;
        height: 45px;
      }
      .vip-title {
        display: inline-block;
        height: 10px;
        line-height: 20px;
        font-family: Source Han Sans CN;
        font-weight: 400;
        color: #8a8a8a;
      }
      .vip-item {
        height: 45px;
        display: inline-block;
        flex: 1;
        text-align: center;
        font-size: 12px;
        color: #4d4d4d;
        line-height: 6px;
        text-align: center;
        img {
          width: 45px;
          height: 45px;
          display: inline-block;
        }
        span {
          height: 16px;
          display: block;
        }
      }
    }
  }

  .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;
  }

  .bottom {
    width: 100vw;
    box-sizing: border-box;
    background: #e6e6dc;
    margin: 0 0 0 0;
    p {
      margin: 0;
    }
    /**地址栏收获样式 */
    .cell-list {
      padding: 0 20px;
      height: 81px;
      background: #fcfcf0;
      border-radius: 16px;
      padding: 10px 0px;
      height: 50px;
      display: -webkit-box;
      display: -ms-flexbox;
      display: flex;
      margin: 0 20px;
      .van-cell__title {
        width: 200px;
        position: relative;
        left: 0;
        top: 0;
        text-align: center;
        img {
          margin: 0 40px;
        }
      }
      .box-detaile {
        flex: 1;
        text-align: center;
        .detaile-box {
          width: 20vw;
          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;
          }
        }
      }
    }
  }

  //常用功能下的按钮

  // 改
  .bgImg {
    width: 100%;
    height: 246px;
    position: absolute;
    top: 0px;
    img {
      width: 100%;
    }
  }
  .my-info {
    width: 90vw;
    // float: left;
    position: relative;
    left: 0;
    top: 0;
    margin: 15vh auto 0;
    img {
      position: relative;

      width: 100%;
    }
  }
  @media screen and (min-width: 320px) {
    .mine-resume .mine-resume-main .headerDesc {
      margin-top: 27px;
    }
  }
  @media screen and (min-width: 375px) {
    .mine-resume .mine-resume-main .headerDesc {
      margin-top: 53px;
      margin: 53px 0 0 5px;
    }
  }
  @media screen and (min-width: 414px) {
    .mine-resume .mine-resume-main .headerDesc {
      margin-top: 53px;
      margin: 66px 0 0 5px;
    }
  }
}
</style>
