<template>
  <scroll-view scroll-y class="content">
    <div class="user">
      <van-cell @click="getUserProfile" center :value="userInfo.nickName ? userInfo.nickName : '新用户'">
        <view slot="title">
          <image class="user-headImg" v-if="userInfo.headImage" :src="userInfo.headImage"></image>
          <image class="user-headImg" v-else :src="unLoginHead"></image>
        </view>
      </van-cell>
      <van-cell title-class="uni-app-fontsize-paragraph" title="电子资料" is-link @click="goPath('/pages/extraWeb/index?src=https://nbjk-h5.zzxcx.net/pdfImages')"
        center>
        <template #icon>
          <m-icon type="fkbz" class="cell-icon" />
        </template>
      </van-cell>
      <!-- <van-cell title="我要提现" value="" is-link center @click="goCashOut">
        </van-cell> -->
      <!-- <van-cell title="我的下级" value="" is-link center @click="goMyBranch">
				<template #icon>
					<m-icon type="hyyxq" class="cell-icon" />
				</template>
			</van-cell> -->
      <!-- <van-cell
          title="我的推广积分"
          value=""
          is-link
          center
          @click="goMyIntegral"
        >
        </van-cell> -->
      <!-- #ifdef MP-WEIXIN -->
      <!-- <van-cell
        title="会员有效期"
        :value="expireTime ? expireTime : '开通会员'"
        is-link
        center
        url="/otherPages/buyVip/index"
      >
      </van-cell> -->

      <!-- #endif -->
      <!-- #ifdef MP-TOUTIAO -->
      <van-cell v-if="!isVip" title="会员有效期" :value="'开通会员'" is-link center url="/otherPages/buyVip/index">
      </van-cell>
      <van-cell v-if="isVip" title="会员有效期" :value="'已开通'" is-link center>
      </van-cell>
      <van-cell title="资料下载" is-link @click="goVipPath('/otherPages/pdfList/index')" center>
        <template #icon>
          <m-icon type="fkbz" class="cell-icon" />
        </template>
      </van-cell>

      <!-- #endif -->
      <!-- #ifdef MP-WEIXIN -->
<!-- 
      <van-cell title-class="uni-app-fontsize-paragraph" title="反馈帮助" is-link center url="/pages/extraWeb/index?src=https://support.qq.com/product/359609">
        <template #icon>
          <m-icon type="fkbz" class="cell-icon" />
        </template>
      </van-cell> -->

      <!-- #endif -->
    </div>
    <view class="wxad">
      <ad ad-type="video" :ad-intervals="100" unit-id="adunit-8eb44bbd7e3147d4"></ad>
    </view>
   
    <!-- <view class="ad-box serviceBox">
			<ad unit-id="adunit-d8c1548cc9663765"></ad>
		</view> -->
  </scroll-view>
</template>

<script>
import api from "@/api/index";
import unLoginHead from "@/assets/img/unLoginHead.png";
export default {
  computed: {
    unLoginHead() {
      return unLoginHead;
    },
    userInfo() {
      return this.$store.state.user.userInfo;
    },
    expireTime() {
      return this.$store.state.user.userInfo.expireTime &&
        this.$store.getters.isVip
        ? this.$store.state.user.userInfo.expireTime.split(" ")[0]
        : null;
    },
    isVip() {
      return this.$store.getters.isVip;
    },
  },
  mounted() {
    this.$store.dispatch("GetInfo");

  },
  methods: {
    goPath(url) {

      uni.navigateTo({
          url,
        });
    },
    goVipPath(url) {
      if (this.isVip) {
        uni.navigateTo({
          url,
        });
      } else {
        uni.showToast({
          title: "vip才能使用",
          icon: 'none'
        });
      }
    },
    getUserProfile(e) {
      let that = this;
      uni.getUserProfile({
        desc: "业务需要",
        success(res) {
          console.log(res);
          api.user
            .userInfoUserInfo({
              headImage: res.userInfo.avatarUrl,
              nickName: res.userInfo.nickName,
            })
            .then((res) => {
              that.$store.dispatch("GetInfo");
            });
        },
      });

      // let updateRes = await this.$api.user.updateUserInfo({
      //   headImage: userInfo.userInfo.avatarUrl,
      //   nickName: userInfo.userInfo.nickName,
      // });
      // if (updateRes.code == 200) {

      //   this.$store.state.user.userInfo.headImage = userInfo.userInfo.avatarUrl;
      //   this.$store.state.user.userInfo.nickName = userInfo.userInfo.nickName;
      // }
    },
  },
};
</script>

<style lang="scss" scoped>
.user {
  background-color: #f2f3f5;
 
  /* height: 100vh; */
  .group {
    margin: 10px 0;
  }

  .user-avatar {
    width: 46px;
    height: 46px;
    margin-right: 10px;
  }
}

.user-headImg {
  width: 90rpx;
  height: 90rpx;
  border-radius: 50%;
}

.cell-icon {
  margin-right: 5px;
}
</style>
