index.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. <template>
  2. <view v-if="isShowPage">
  3. <view class="top-fixed" :style="'height: ' + systems.barHeight + 'rpx;'">
  4. <view :class="'bgcolor' + (isTop == 1 ? ' opacity' : '')" :style="'height:' + systems.barHeight + 'rpx'"></view>
  5. <view class="top-fixed-c ddflex" :style="'height: ' + systems.navigationHeight + 'rpx;margin-top:' + systems.ktxStatusHeight + 'rpx;'">
  6. <navigator open-type="navigateBack" class="back"><image src="../static/images/back.png"></image></navigator>
  7. <view class="top-title ddflex fflex">领取会员卡</view>
  8. </view>
  9. </view>
  10. <image src="../static/images/vip_top.png" class="vip-top"></image>
  11. <view class="top">
  12. <view class="vip">
  13. <image src="../static/images/vip_bg.png" class="vip-bg"></image>
  14. <view class="vipc">
  15. <view class="userinfo ddflex">
  16. <image :src="userInfo.avatar ? userInfo.avatar : '/static/pages/images/userimg.png'" mode="aspectFill"></image>
  17. <view class="fflex">
  18. <view>{{ userInfo.nickName }}</view>
  19. <text>{{ userInfo.mobile ? userInfo.mobile : '' }}</text>
  20. </view>
  21. </view>
  22. <view class="vip-info">
  23. <view class="ddflex">
  24. <text v-if="vip.money > 0">¥</text>
  25. <view>{{ vip.money > 0 ? vip.money : '免费领取' }}</view>
  26. </view>
  27. <text>有效期 {{ vip.day }}天</text>
  28. </view>
  29. </view>
  30. </view>
  31. <view class="quanyi">
  32. <view class="tits ddflex"><text>会员权益</text></view>
  33. <view class="qy-con">
  34. <block v-if="vip.editorContent"><mp-html :content="vip.editorContent" @imgtap="choose" /></block>
  35. <block v-else>无</block>
  36. </view>
  37. </view>
  38. </view>
  39. <view style="height: 160rpx;"></view>
  40. <view class="bot">
  41. <view v-if="userVipInfo.levelGrade == vip.level && userVipInfo.levelGrade != 0 && !userVipInfo.end" class="btn">会员卡已领取</view>
  42. <!-- v-else -->
  43. <view v-else class="btn" @click="getVipRe()">{{ vip.money > 0 ? '支付' + vip.money + '元领取会员' : '免费领取会员卡' }}</view>
  44. </view>
  45. <update-userinfo
  46. :update-info="isUpdateInfo"
  47. :update-mobile="isUpdateMobile"
  48. v-if="isShowUpdate"
  49. @closeUpdate="closeUpdate"
  50. @updateInfo="updateInfo"
  51. @updateMobile="updateMobile"
  52. ></update-userinfo>
  53. </view>
  54. </template>
  55. <script>
  56. //index.js
  57. //获取应用实例
  58. const app = getApp();
  59. const req = require('../../utils/request.js');
  60. const route = require('../../utils/route');
  61. import mpHtml from '../../components/mp-html/components/mp-html/mp-html';
  62. export default {
  63. components: {
  64. mpHtml
  65. },
  66. data() {
  67. return {
  68. isShowPage: false,
  69. picUrlss: req.public.picUrls,
  70. about: {},
  71. isTop: 0,
  72. userinfo: '',
  73. systems: {},
  74. // vipList: [],
  75. vip: {},
  76. userInfo: {},
  77. userVipInfo: {}, //用户会员等级对象
  78. isShowUpdate: false, //是否显示更新信息弹窗
  79. isUpdateInfo: false, //更新用户信息
  80. isUpdateMobile: false //绑定手机号
  81. };
  82. },
  83. onLoad: async function(options) {
  84. this.getVip();
  85. },
  86. async onShow() {
  87. this.about = req.getStorage('about');
  88. this.userInfo = req.getStorage('userInfo');
  89. this.getuserVip();
  90. },
  91. methods: {
  92. getVip() {
  93. req.getRequest('/api/levelStrategy/userLevelList', {}, data => {
  94. this.vip = data[0];
  95. this.getVipMoneyT(this.vip.level);
  96. });
  97. },
  98. getVipMoneyT(index) {
  99. let from = {
  100. level: index
  101. };
  102. req.getRequest('/api/levelStrategy/list', from, data => {
  103. if (data && data.length > 0) {
  104. this.vip.money = data[0].price;
  105. this.vip.day = data[0].day;
  106. this.vip.levelId = data[0].id;
  107. this.isShowPage = true;
  108. this.$forceUpdate();
  109. console.log('this.vip数据>>>>', this.vip);
  110. }
  111. });
  112. },
  113. getVipRe() {
  114. if (this.vip.money > 0) {
  115. this.buy();
  116. } else {
  117. this.userInfo = req.getStorage('userInfo');
  118. if (!this.userInfo.mobile) {
  119. this.isShowUpdate = true;
  120. this.isUpdateMobile = true;
  121. return;
  122. }
  123. this.freeOpenVip();
  124. }
  125. },
  126. freeOpenVip() {
  127. req.postRequest('/api/levelStrategy/freeOfCharge', { strategyId: this.vip.levelId }, data => {
  128. this.getuserVip();
  129. uni.showModal({
  130. title: '提示',
  131. content: '会员卡领取成功',
  132. confirmText: '确定',
  133. showCancel: false,
  134. success(res) {
  135. }
  136. });
  137. });
  138. },
  139. //购买
  140. buy() {
  141. let that = this;
  142. if (this.userVipInfo.levelGrade > this.vip.level && !this.userVipInfo.end) {
  143. return req.msg('您不能开通低于现在等级会员');
  144. }
  145. route.vip(
  146. {
  147. strategyId: this.vip.levelId,
  148. scene: req.getStorage('scene')
  149. },
  150. data => {
  151. route.vipPay(data.id, data.status, this.price, res => {
  152. if (res) {
  153. app.globalData.navigateTo('product/pay/pay?isSuccess=true&vip=true');
  154. }
  155. });
  156. }
  157. );
  158. },
  159. getuserVip() {
  160. req.getRequest('/api/user/levelDetails', {}, data => {
  161. let expireTime = Array;
  162. if (data.expireTime) {
  163. expireTime = data.expireTime.split(' ');
  164. data.expireTime = data.expireTime.replace(/-/g, '/');
  165. }
  166. let nowTime = new Date().getTime();
  167. let endTime = new Date(data.expireTime).getTime();
  168. let times = parseInt((endTime - nowTime) / 1000);
  169. this.setData({
  170. userVipInfo: data,
  171. ['userVipInfo.expireTime']: expireTime[0]
  172. });
  173. if (times <= 0) {
  174. this.setData({
  175. ['userVipInfo.end']: true
  176. });
  177. } else {
  178. this.setData({
  179. ['userVipInfo.end']: false
  180. });
  181. }
  182. console.log('userVipInfo>>>>', this.userVipInfo);
  183. });
  184. },
  185. choose() {}
  186. },
  187. mounted() {
  188. const systemInfo = uni.getSystemInfoSync();
  189. // px转换到rpx的比例
  190. let pxToRpxScale = 750 / systemInfo.windowWidth;
  191. let systems = {
  192. ktxStatusHeight: systemInfo.statusBarHeight * pxToRpxScale, // 状态栏的高度
  193. navigationHeight: 44 * pxToRpxScale // 导航栏的高度
  194. };
  195. systems.barHeight = systems.ktxStatusHeight + systems.navigationHeight;
  196. this.systems = systems;
  197. },
  198. onPageScroll: function(e) {
  199. const systemInfo = uni.getSystemInfoSync();
  200. let height = systemInfo.statusBarHeight + 44;
  201. if (e.scrollTop > height) {
  202. this.isTop = 1;
  203. } else {
  204. this.isTop = 0;
  205. }
  206. }
  207. };
  208. </script>
  209. <style>
  210. @import './index.css';
  211. </style>