member.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517
  1. <template>
  2. <view>
  3. <!-- 顶部导航 -->
  4. <fa-navbar title="我的VIP会员"></fa-navbar>
  5. <view class="u-p-30">
  6. <view class="center u-p-30" :style="[{ background: theme.bgColor }]">
  7. <view class="u-flex">
  8. <view class="u-m-r-15"><u-avatar size="90" :src="vuex_user.avatar"></u-avatar></view>
  9. <view class="u-flex u-flex-column u-row-between u-col-top u-flex-1">
  10. <view class="u-flex">
  11. <view class="nickname">{{ vuex_user.nickname }}</view>
  12. <view class="u-m-l-10" v-if="vipInfo.level">
  13. <u-tag :text="vipInfo.name" mode="dark" size="mini" type="success" />
  14. </view>
  15. </view>
  16. <view class="u-m-t-10 u-font-22 u-flex u-row-between" style="width: 100%;">
  17. <view class="">VIP等级: {{ vipInfo.level || 0 }}</view>
  18. <view class="remainseconds" v-if="vipInfo.remainseconds && vipInfo.remainseconds < 86400">
  19. <u-count-down font-size="22" separator-color="#ffffff" :timestamp="vipInfo.remainseconds || 0"></u-count-down>
  20. </view>
  21. </view>
  22. </view>
  23. </view>
  24. <view class="u-flex u-row-between u-m-t-15">
  25. <view class="">{{ vipInfo.expiredate | expireRender }}</view>
  26. <view class="">
  27. <u-button size="mini" shape="circle" hover-class="none" v-if="vipInfo.level" @click="goBuy(1)">续费会员</u-button>
  28. <u-button size="mini" shape="circle" hover-class="none" v-else @click="goBuy(0)">购买会员</u-button>
  29. </view>
  30. </view>
  31. </view>
  32. </view>
  33. <block v-if="isVipList(1)">
  34. <view class="u-p-30 bg-title">选择购买会员</view>
  35. <view class="u-border-bottom u-p-t-20 u-p-b-20">
  36. <!-- #ifndef MP-BAIDU -->
  37. <u-tabs :list="vipList" :active-color="theme.bgColor" :bar-width="tabwidth" :is-scroll="isVipList(4)" :current="current" @change="change"></u-tabs>
  38. <!-- #endif -->
  39. <!-- #ifdef MP-BAIDU -->
  40. <fa-u-tabs :list="vipList" :active-color="theme.bgColor" :bar-width="tabwidth" :is-scroll="isVipList(4)" :current="current" @change="change"></fa-u-tabs>
  41. <!-- #endif -->
  42. </view>
  43. </block>
  44. <view class="u-flex u-row-between u-p-30 bg-title">
  45. <view class="">选择开通时长</view>
  46. <view class="">
  47. <u-icon name="info-circle"></u-icon>
  48. <text class="u-m-l-10">价格说明</text>
  49. </view>
  50. </view>
  51. <view class="u-p-l-30 u-p-r-30 u-p-t-30">
  52. <view class="list u-flex u-flex-wrap">
  53. <view class="item u-text-center" :style="[itemStyle(index)]" v-for="(item, index) in pricedata" :key="index" @click="selectVip(item, index)">
  54. <view class="">{{ item.title }}</view>
  55. <view class="u-p-t-15 u-p-b-15 price">
  56. <text class="u-font-20">¥</text>
  57. <text class="u-font-40 u-text-weight">{{ item.price }}</text>
  58. </view>
  59. <view class="u-font-20 u-tips-color u-line-2">{{ item.subtext }}</view>
  60. </view>
  61. </view>
  62. </view>
  63. <view class="u-p-30 bg-title">获得权益</view>
  64. <view class="">
  65. <view class="interests u-p-30 u-flex u-flex-wrap">
  66. <view class="item u-text-center" v-for="(item, index) in rightdata" :key="index">
  67. <view class="u-flex u-row-center"><u-image width="80rpx" height="80rpx" :src="item.image" shape="circle"></u-image></view>
  68. <view class="u-font-30 u-text-weight u-m-t-10 u-m-b-10">{{ item.text }}</view>
  69. <view class="u-font-20 u-tips-color u-line-3">{{ item.intro }}</view>
  70. </view>
  71. </view>
  72. </view>
  73. <view class="u-p-30 bg-title">支付方式</view>
  74. <view class="">
  75. <u-radio-group v-model="paytype" style="width: 100%;">
  76. <u-cell-item
  77. v-for="(item, index) in payList"
  78. :icon="item == 'wechat' ? 'weixin-circle-fill' : 'zhifubao-circle-fill'"
  79. :key="index"
  80. :icon-style="{ color: item == 'wechat' ? '#40BA49' : '#00AAEE' }"
  81. :arrow="false"
  82. :title="item == 'wechat' ? '微信支付' : '支付宝支付'"
  83. @click="selectPayType(item)"
  84. >
  85. <u-radio :active-color="theme.bgColor" slot="right-icon" :name="item"></u-radio>
  86. </u-cell-item>
  87. </u-radio-group>
  88. </view>
  89. <u-gap height="180" bg-color="#f3f4f6"></u-gap>
  90. <view class="vip-footer u-p-30 u-border-top">
  91. <u-button
  92. shape="circle"
  93. type="primary"
  94. hover-class="none"
  95. :custom-style="{ backgroundColor: isDisabled ? '#ccc' : theme.bgColor, color: theme.color }"
  96. @click="goBuy(0)"
  97. >
  98. {{ nowLevel }}
  99. </u-button>
  100. </view>
  101. </view>
  102. </template>
  103. <script>
  104. export default {
  105. onLoad(e) {
  106. this.vip = e.vip || 0;
  107. if (this.vuex_token) {
  108. this.getUserIndex();
  109. }
  110. this.getVipIndex();
  111. },
  112. computed: {
  113. itemStyle() {
  114. return index => {
  115. let style = {
  116. height:'250rpx'
  117. };
  118. if (index == this.selectIndex[this.current]) {
  119. style.border = '1px solid ' + this.theme.bgColor;
  120. style.backgroundColor = this.lightColor;
  121. }
  122. return style;
  123. };
  124. },
  125. isVipList() {
  126. return index => {
  127. return this.vipList.length > index;
  128. };
  129. },
  130. nowLevel() {
  131. if (this.isDisabled) {
  132. return '不可操作';
  133. }
  134. if (!this.vipInfo.level) {
  135. return '立即购买';
  136. }
  137. if (this.vipList.length > 0 && this.vipInfo.level == this.vipList[this.current].level) {
  138. return '我要续费';
  139. }
  140. return '我要升级';
  141. },
  142. isDisabled() {
  143. if (this.vipInfo.level && this.vipList[this.current].level < this.vipInfo.level) {
  144. return true;
  145. }
  146. return false;
  147. },
  148. payList() {
  149. // #ifdef MP-WEIXIN
  150. if (this.paytypelist.indexOf('wechat') != -1) {
  151. return ['wechat'];
  152. }
  153. // #endif
  154. // #ifdef APP-PLUS
  155. return this.paytypelist;
  156. // #endif
  157. // #ifdef H5
  158. if (this.$util.isWeiXinBrowser()) {
  159. if (this.paytypelist.indexOf('wechat') != -1) {
  160. return ['wechat'];
  161. }
  162. } else {
  163. return this.paytypelist;
  164. }
  165. // #endif
  166. return [];
  167. }
  168. },
  169. filters: {
  170. expireRender(value) {
  171. if (!value) {
  172. return '请先购买会员吧!';
  173. }
  174. let obj1 = new Date(value);
  175. let obj2 = new Date();
  176. let time1 = obj1.getFullYear() + '-' + (obj1.getMonth() + 1) + '-' + obj1.getDate();
  177. let time2 = obj2.getFullYear() + '-' + (obj2.getMonth() + 1) + '-' + obj2.getDate();
  178. if (time1 == time2) {
  179. return '今天过期,尽快续费哦!';
  180. }
  181. if (obj1 - obj2 < 0) {
  182. return '会员已过期,请续费哦!';
  183. }
  184. return time1 + ' 后过期';
  185. }
  186. },
  187. data() {
  188. return {
  189. vip: 0,
  190. tabwidth: 120,
  191. vipList: [],
  192. pricedata: [],
  193. rightdata: [],
  194. vipInfo: {},
  195. current: 0,
  196. selectIndex: [],
  197. paytype: 'wechat',
  198. paytypelist: []
  199. };
  200. },
  201. methods: {
  202. getUserIndex: async function() {
  203. let res = await this.$api.getUserIndex();
  204. if (!res.code) {
  205. this.$u.toast(res.msg);
  206. return;
  207. }
  208. this.$u.vuex('vuex_user', res.data.userInfo || {});
  209. },
  210. change(index) {
  211. this.tabwidth = this.$util.strlen(this.vipList[index].name) * 30;
  212. this.current = index;
  213. this.setPriceData();
  214. },
  215. getIsDefault(value){
  216. return [true,1,'1','yes','true'].indexOf(value) != -1;
  217. },
  218. getVipIndex() {
  219. this.$api.getVipIndex().then(res => {
  220. if (res.code) {
  221. this.paytypelist = res.data.config.paytypelist;
  222. this.paytype = res.data.config.defaultpaytype;
  223. //有vip等级传来,自动到VIP
  224. res.data.vipList.some((item, index) => {
  225. if (item.level == this.vip) {
  226. this.current = index;
  227. return true;
  228. }
  229. });
  230. this.vipList = res.data.vipList || [];
  231. this.vipInfo = res.data.vipInfo || {};
  232. this.setPriceData();
  233. }
  234. });
  235. },
  236. //渲染数据
  237. setPriceData() {
  238. this.vipList.length > this.current && (this.pricedata = this.vipList[this.current].pricedata) && (this.rightdata = this.vipList[this.current].rightdata);
  239. if(typeof this.selectIndex[this.current] == 'undefined'){
  240. let defaultIndex = 0;
  241. //渲染默认的index
  242. this.pricedata.some((item, index) => {
  243. if (this.getIsDefault(item.default)) {
  244. defaultIndex = index;
  245. return true;
  246. }
  247. });
  248. this.$set(this.selectIndex, this.current, defaultIndex);
  249. }
  250. },
  251. //选择
  252. selectVip(item, index) {
  253. this.$set(this.selectIndex, this.current, index);
  254. },
  255. selectPayType(e) {
  256. this.paytype = e;
  257. },
  258. // #ifndef H5
  259. goBuy(type) {
  260. if (!type && this.isDisabled) {
  261. // this.$u.toast('')
  262. return;
  263. }
  264. // #ifdef MP-BAIDU
  265. this.$u.toast('未支持百度小程序支付!')
  266. return;
  267. // #endif
  268. let data = {
  269. paytype: this.paytype,
  270. level: this.vipList[this.current].level,
  271. days: this.pricedata[this.selectIndex[this.current]].days
  272. };
  273. //续费
  274. if (type == 1) {
  275. this.vipList.some((item, index) => {
  276. if (item.level == this.vipInfo.level) {
  277. data.level = item.level;
  278. //如果选择过,用选择的,没有用默认的天数
  279. if (typeof this.selectIndex[index] != 'undefined') {
  280. data.days = item.pricedata[this.selectIndex[index]].days;
  281. } else {
  282. item.pricedata.some(res => {
  283. if (this.getIsDefault(res.default)) {
  284. data.days = res.days;
  285. return true;
  286. }
  287. });
  288. }
  289. return true;
  290. }
  291. });
  292. }
  293. // #ifdef APP-PLUS
  294. data.appid = plus.runtime.appid;
  295. data.method = 'app';
  296. // #endif
  297. // #ifdef MP-WEIXIN
  298. data.method = 'miniapp';
  299. // #endif
  300. this.$api.goVipSubmit(data).then(res => {
  301. if (!res.code) {
  302. this.$u.toast(res.msg);
  303. return;
  304. }
  305. if (res.data == 'bind') {
  306. // #ifdef MP-WEIXIN
  307. this.$Router.push('/pages/login/wxlogin');
  308. // #endif
  309. return;
  310. }
  311. // #ifdef MP-WEIXIN
  312. uni.requestPayment({
  313. provider: 'wxpay',
  314. timeStamp: res.data.timeStamp,
  315. nonceStr: res.data.nonceStr,
  316. package: res.data.package,
  317. signType: res.data.signType,
  318. paySign: res.data.paySign,
  319. success: res => {
  320. this.$u.toast('支付成功!');
  321. this.getUserIndex();
  322. this.getVipIndex();
  323. },
  324. fail: err => {
  325. this.$u.toast('fail:' + JSON.stringify(err));
  326. }
  327. });
  328. // #endif
  329. // #ifdef APP-PLUS
  330. uni.requestPayment({
  331. provider: this.paytype == 'alipay' ? 'alipay' : 'wxpay',
  332. orderInfo: res.data, //微信、支付宝订单数据
  333. success: res => {
  334. this.$u.toast('支付成功!');
  335. this.getUserIndex();
  336. this.getVipIndex();
  337. },
  338. fail: function(err) {
  339. console.log('fail:' + JSON.stringify(err));
  340. }
  341. });
  342. // #endif
  343. });
  344. },
  345. // #endif
  346. // #ifdef H5
  347. goBuy(type) {
  348. if (!type && this.isDisabled) {
  349. // this.$u.toast('')
  350. return;
  351. }
  352. console.log(this.vipList[this.current]);
  353. let data = {
  354. paytype: this.paytype,
  355. level: this.vipList[this.current].level,
  356. days: this.pricedata[this.selectIndex[this.current]].days,
  357. method: 'wap'
  358. };
  359. //续费
  360. if (type == 1) {
  361. this.vipList.some((item, index) => {
  362. if (item.level == this.vipInfo.level) {
  363. data.level = item.level;
  364. //如果选择过,用选择的,没有用默认的天数
  365. if (typeof this.selectIndex[index] != 'undefined') {
  366. data.days = item.pricedata[this.selectIndex[index]].days;
  367. } else {
  368. item.pricedata.some(res => {
  369. if (this.getIsDefault(res.default)) {
  370. data.days = res.days;
  371. return true;
  372. }
  373. });
  374. }
  375. return true;
  376. }
  377. });
  378. }
  379. //在微信环境,且为微信支付
  380. if (this.isWeixin && this.paytype == 'wechat') {
  381. data.method = 'mp';
  382. this.$api.goVipSubmit(data).then(res => {
  383. if (!res || !res.code) {
  384. this.$u.toast(res.msg || '支付错误');
  385. return;
  386. }
  387. if (res.data == 'bind') {
  388. this.goAuth();
  389. return;
  390. }
  391. window.WeixinJSBridge.invoke(
  392. 'getBrandWCPayRequest',
  393. {
  394. appId: res.data.appId, // 公众号名称,由商户传入
  395. timeStamp: res.data.timeStamp, // 时间戳,自1970年以来的秒数
  396. nonceStr: res.data.nonceStr, // 随机串
  397. package: res.data.package,
  398. signType: res.data.signType, // 微信签名方式:
  399. paySign: res.data.paySign // 微信签名
  400. },
  401. res => {
  402. if (res.err_msg === 'get_brand_wcpay_request:ok') {
  403. this.$u.toast('支付成功!');
  404. this.getUserIndex();
  405. this.getVipIndex();
  406. } else if (res.err_msg === 'get_brand_wcpay_request:cancel') {
  407. this.$u.toast('取消支付');
  408. } else {
  409. this.$u.toast('支付失败');
  410. }
  411. }
  412. );
  413. });
  414. } else {
  415. //非微信环境的wap 支付方法,会返回orderid,再模拟表单提交
  416. data.returnurl = window.location.href;
  417. this.$api.goVipSubmit(data).then(res => {
  418. if (!res || !res.code) {
  419. this.$u.toast(res.msg || '支付错误!');
  420. return;
  421. }
  422. //URL地址
  423. if (res.data.toString().match(/^((?:[a-z]+:)?\/\/)(.*)/i)) {
  424. location.href = res.data;
  425. return;
  426. }
  427. //Form表单
  428. document.getElementsByTagName('body')[0].innerHTML = res.data;
  429. let form = document.querySelector('form');
  430. if (form && form.length > 0) {
  431. form.submit();
  432. return;
  433. }
  434. //Meta跳转
  435. let meta = document.querySelector('meta[http-equiv="refresh"]');
  436. if (meta && meta.length > 0) {
  437. setTimeout(function() {
  438. location.href = meta.content.split(/;/)[1];
  439. }, 300);
  440. return;
  441. }
  442. });
  443. }
  444. }
  445. // #endif
  446. }
  447. };
  448. </script>
  449. <style lang="scss" scoped>
  450. .center {
  451. border-radius: 20rpx;
  452. color: #ffffff;
  453. box-shadow: 0 0 16rpx 4rpx rgba(55, 68, 134, 0.3);
  454. .nickname {
  455. font-weight: bold;
  456. }
  457. }
  458. .u-flex-column {
  459. flex-direction: column;
  460. height: 100%;
  461. }
  462. .bg-title {
  463. background-color: #f3f4f6;
  464. }
  465. .list {
  466. .item {
  467. border: 1px solid #cccccc;
  468. width: calc((100vw - 120rpx) / 3);
  469. padding: 40rpx 30rpx;
  470. margin-bottom: 30rpx;
  471. border-radius: 10rpx;
  472. &:nth-child(3n-1) {
  473. margin-left: 30rpx;
  474. margin-right: 30rpx;
  475. }
  476. .price {
  477. color: #fc4c57;
  478. }
  479. }
  480. }
  481. .interests {
  482. .item {
  483. width: calc((100vw - 120rpx) / 3);
  484. margin-bottom: 30rpx;
  485. height: 250rpx;
  486. &:nth-child(3n-1) {
  487. margin-left: 30rpx;
  488. margin-right: 30rpx;
  489. }
  490. }
  491. }
  492. .vip-footer {
  493. position: fixed;
  494. left: 0;
  495. bottom: 0;
  496. width: 100%;
  497. background-color: #ffffff;
  498. z-index: 999;
  499. }
  500. </style>