vip.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  1. <template>
  2. <view>
  3. <view class="huiyuan" v-if="TabList.length > 0">
  4. <swiper class="swiper" next-margin="15rpx" @change="swiperChange">
  5. <swiper-item :class="'li li' + index" v-for="(item, index) in TabList" :key="index">
  6. <image :src="item.pic ? item.pic : '../static/mine/images/vip_bg' + index + '.png'" class="vipbg"></image>
  7. <view class="userinfo">
  8. <view class="infos dflex">
  9. <image :src="userinfo.avatar ? userinfo.avatar : '../../static/pages/images/userimg.png'" mode="aspectFill" class="user-img"></image>
  10. <view class="flex">
  11. <view class="username">{{ userinfo.nickName }}</view>
  12. <image :src="item.icon ? item.icon : '../static/mine/images/level' + index + '.png'" mode="heightFix" class="level-img"></image>
  13. </view>
  14. </view>
  15. <view class="times" v-if="userinfo.level == item.id && userinfo.level != 0 && !userinfo.end">
  16. <view class="expire">
  17. <view class="v-price" v-if="vip.money > 0">
  18. <text>¥</text>
  19. {{ vip.money }}
  20. </view>
  21. <view class="v-price" v-else>免费领取</view>
  22. <view class="ddflex">
  23. {{ userinfo.expireTime }}到期
  24. <image :src="'../static/mine/images/rico' + index + '.png'"></image>
  25. </view>
  26. </view>
  27. <view class="vipid">NO.{{ userinfo.level }}</view>
  28. </view>
  29. <block v-else>
  30. <view class="v-times">
  31. <view class="v-price" v-if="vip.money > 0">
  32. <text>¥</text>
  33. {{ vip.money }}
  34. </view>
  35. <view class="v-price" v-else>免费领取</view>
  36. <view class="invi">有效期:{{ vip.day }}天</view>
  37. </view>
  38. </block>
  39. <view class="obtn" @tap="openVip(item,index)" :data-index="index">
  40. <block v-if="vip.money > 0">{{ userinfo.level == item.id && userinfo.level != 0 && !userinfo.end ? '立即续费' : '立即开通' }}</block>
  41. <block v-else>{{ userinfo.level == item.id && userinfo.level != 0 && !userinfo.end ? '已领取' : '立即领取' }}</block>
  42. </view>
  43. </view>
  44. </swiper-item>
  45. </swiper>
  46. <view class="dots dflex">
  47. <block v-for="(item, index) in TabList" :key="index"><view :class="['dot', index == swiperCurrent ? 'active' : '']"></view></block>
  48. </view>
  49. </view>
  50. <view class="quanyi">
  51. <view class="quanyi-tit dflex">会员权益</view>
  52. <view class="ziyou">
  53. <block v-if="nodes[idx]"><!-- <mp-html :content="nodes[idx]" @imgtap="choose" /> --><rich-text :nodes="nodes[idx]"></rich-text></block>
  54. <block v-else>无</block>
  55. </view>
  56. </view>
  57. <block v-if="couponCount>0">
  58. <view class="cai-tit">
  59. 会员优惠券
  60. </view>
  61. <view class="quan">
  62. <scroll-view scroll-x="true" :class="'quans' + (couponCount == 1 ? ' quans1':'')">
  63. <view class="li" v-for="(item, index) in couponList" :key="index" @click="recieveCoupon(index)">
  64. <view class="q-info ddflex">
  65. <view class="fflex">
  66. <view class="q-title tover">{{item.couponType === 3 ? '通用券' : item.couponType === 1 ? '满减券' : item.couponType === 4 ? '免除券':'代金券'}}-{{item.couponTitle}}</view>
  67. <view class="q-time ddflex"><view>{{timeFormat(item.couponStart)}}</view><text>至</text><view>{{timeFormat(item.couponEnd)}}</view></view>
  68. </view>
  69. <view class="info-r">
  70. <view class="q-money"><text>¥</text>{{item.couponAmount}}</view>
  71. <view class="q-man">{{item.couponBrief}}</view>
  72. </view>
  73. </view>
  74. <view class="li-bot ddflex">
  75. <view class="check ddflex fflex" @click.stop="checks(item,index)">查看详情
  76. <image src="../static/mine/images/bico.png"></image>
  77. </view>
  78. <view class="yong ddflex">{{item.userCount >= item.userReceive&&item.userCount!=0&&item.userReceive!=-1 ? '已领取' : '领取'}}</view>
  79. </view>
  80. <view class="q-infos" v-if="item.isShow">
  81. <view>1.使用时间:{{timeFormat(item.couponStart)}}至{{timeFormat(item.couponEnd)}}</view>
  82. <view v-if="item.couponBrief">2.使用范围:{{item.couponBrief}}</view>
  83. <view v-if="item.useActionsList && item.useActionsList.length > 0" class="i-pro">{{item.couponBrief?'3':'2'}}.指定产品:
  84. <text v-for="(it,idx) in item.useActionsList" :key="idx" @click="toDetail(it)">{{it.name}}</text>
  85. </view>
  86. </view>
  87. </view>
  88. </scroll-view>
  89. </view>
  90. </block>
  91. <view class="cai">
  92. <view class="cai-tit">
  93. 会员专区
  94. <text>专属折扣享不停</text>
  95. </view>
  96. <view class="tabcon pdlr20 dflex">
  97. <block v-for="(item, index) in likeList" :key="index">
  98. <view class="li">
  99. <view class="jsdimgs" @tap="toDetail" :data-id="item.id">
  100. <image :src="item.pic + '?x-oss-process=style/w375'" mode="aspectFit" class="jsdpro"></image>
  101. <image src="/static/pages/images/jishida.png" v-if="item.isTimely === 1" class="jsdimg"></image>
  102. </view>
  103. <view class="jsdinfo">
  104. <view class="proname" @tap="toDetail" :data-id="item.id">{{ item.title }}</view>
  105. <view class="xiaol dflex">
  106. <block v-if="item.isOtc != 5 && about.is_open_shop == 1 && (isDistriUser == 2 || ascription)">
  107. <view class="zhuan dflex" v-if="item.commission > 0">
  108. <block>
  109. <text>赚</text>
  110. <view class="dflex">¥{{ item.commission }}</view>
  111. </block>
  112. </view>
  113. </block>
  114. <view class="yishou">{{ item.sellStock }}件已售</view>
  115. </view>
  116. <view class="operate dflex">
  117. <view class="price proprice">
  118. <text>{{ show_membership_price == 1 && item.actualPrice < item.salePrice ? item.actualPrice : item.salePrice }}</text>
  119. <text class="vip" v-if="show_membership_price == 1 && item.membersPrice < item.salePrice">
  120. <text class="sale">VIP</text>
  121. <text class="members">{{ item.membersPrice }}</text>
  122. </text>
  123. <text class="del" v-else>¥{{ item.marketPrice }}</text>
  124. </view>
  125. <view class="add-cart">
  126. <view class="nums dflex" v-if="item.count > 0">
  127. <image src="/static/pages/images/jian.png"></image>
  128. <view class="num">{{ item.count }}</view>
  129. <image src="/static/pages/images/jia1.png"></image>
  130. </view>
  131. <image
  132. src="/static/pages/images/jia.png"
  133. @tap="addShopCart"
  134. :data-id="item.id"
  135. :data-skuid="item.skuId"
  136. :data-index="index"
  137. :data-state="item.state"
  138. v-else
  139. ></image>
  140. </view>
  141. </view>
  142. </view>
  143. </view>
  144. </block>
  145. </view>
  146. </view>
  147. <!-- 开通会员弹窗 -->
  148. <view class="mask" @tap="eliminate" v-if="show"></view>
  149. <view class="purchaseVip" v-if="show">
  150. <view class="timg dflex">
  151. <image :src="userinfo.avatar" mode="aspectFit"></image>
  152. <text>{{ userinfo.nickName }}</text>
  153. </view>
  154. <view class="cont">
  155. <view class="tab">
  156. <scroll-view class="scroll-box" scroll-x style="height:100rpx">
  157. <view
  158. v-for="(item, index) in TabList"
  159. :key="index"
  160. :class="'li ' + (item.active ? 'active' : '')"
  161. :style="
  162. TabList.length == 4
  163. ? 'width:25%'
  164. : TabList.length == 3
  165. ? 'width:33%'
  166. : TabList.length == 2
  167. ? 'width:50%'
  168. : TabList.length == 1
  169. ? 'width:100%'
  170. : 'width:20%'
  171. "
  172. :data-index="index"
  173. :data-level="item.level"
  174. @tap="switchTab"
  175. v-if="item.price != 0"
  176. >
  177. {{ item.title }}
  178. </view>
  179. </scroll-view>
  180. </view>
  181. <view class="jiage dflex">
  182. <scroll-view class="scroll-box" scroll-x style="height:400rpx">
  183. <view
  184. v-for="(item, index) in money"
  185. :key="index"
  186. class="li"
  187. @tap="selectOpen"
  188. :data-index="index"
  189. :data-id="item.id"
  190. :data-price="item.price"
  191. :data-day="item.day"
  192. >
  193. <view :class="'month ' + (item.active ? 'act' : '')">{{ item.day }}天</view>
  194. <view :class="'money ' + (item.active ? 'actbor' : '')">
  195. <text class="txt">¥</text>
  196. {{ item.price }}
  197. </view>
  198. </view>
  199. </scroll-view>
  200. </view>
  201. <view class="title">开通{{ day }}天会员,享尊贵特权</view>
  202. <view class="confirm mbglinear" @tap="buy">立即支付{{ price }}元</view>
  203. </view>
  204. </view>
  205. <view class="placeholder-view" :style="'height:' + (bottomBlankHeight + 115) + 'rpx'"></view>
  206. </view>
  207. </template>
  208. <script>
  209. const app = getApp();
  210. const req = require('../../utils/request.js');
  211. const route = require('../../utils/route');
  212. const utils = require('../../utils/util.js');
  213. import mpHtml from '../../components/mp-html/components/mp-html/mp-html';
  214. export default {
  215. components: {
  216. mpHtml
  217. },
  218. data() {
  219. return {
  220. swiperCurrent: 0,
  221. page: 1,
  222. likeList: [],
  223. isLikeLoad: true,
  224. TabList: [],
  225. show: false,
  226. index: 0,
  227. idx: 0,
  228. bottomBlankHeight: app.globalData.isIPhoneX ? 68 : 0,
  229. bottomId: '',
  230. searchTitle: '',
  231. show_membership_price: 0,
  232. money: [],
  233. level: '',
  234. imgs: '',
  235. vipList: '',
  236. nodes: '',
  237. imags: '',
  238. userinfo: '',
  239. price: 0,
  240. day: 0,
  241. id: '',
  242. freshen: true,
  243. vip: {
  244. money: 0,
  245. day: 0
  246. }, //默认的会员价格
  247. about: {},
  248. isDistriUser: 0, // 判断用户是否是分销员 2为分销员
  249. ascription: false ,//是否开启小店
  250. couponList: [],//会员优惠券
  251. couponCount: 0
  252. };
  253. },
  254. components: {},
  255. props: {},
  256. onLoad(options) {
  257. this.getConfig();
  258. this.getMy();
  259. this.getLikeList();
  260. if (options.searchTitle) {
  261. this.setData({
  262. searchTitle: options.searchTitle
  263. });
  264. }
  265. },
  266. onShow() {
  267. if (this.freshen) {
  268. this.getuserVip();
  269. if (req.getStorage('userInfo')) {
  270. this.getVip();
  271. }
  272. }
  273. },
  274. methods: {
  275. timeFormat(time){
  276. if(time.indexOf('00:00:00')>-1){
  277. let newTime = /\d{4}-\d{1,2}-\d{1,2}/g.exec(time);
  278. return newTime[0].split('-').join('.');
  279. }else{
  280. return time.substring(0,16).replace(/\-/g, '.');
  281. }
  282. },
  283. loadCoupon(id) {
  284. let that = this;
  285. req.getRequest('/api/userLevel/coupon', {id: id}, data => {
  286. data.map(it=>{
  287. it.isShow = false;
  288. return it;
  289. })
  290. that.couponList = data;
  291. that.couponCount = data.length;
  292. });
  293. },
  294. recieveCoupon(index) {
  295. let _ts = this;
  296. if(_ts.userinfo.level !== _ts.TabList[_ts.idx].id){
  297. // '该优惠券仅限' + _ts.TabList[_ts.idx].title + '领取,
  298. req.msgConfirmText('请先升级成为' + _ts.TabList[_ts.idx].title,'升级',suc=>{
  299. _ts.openVip(_ts.idx);
  300. })
  301. return false;
  302. }
  303. const coupon = _ts.couponList[index];
  304. if (coupon.userReceive > -1 && coupon.userCount >= coupon.userReceive) {
  305. return req.msg('超出优惠券领取限制,无法领取');
  306. }
  307. req.postRequest('/api/coupon/receive', {
  308. id: coupon.id
  309. }, res => {
  310. coupon.userCount++
  311. req.msg('领取成功', () => {});
  312. });
  313. },
  314. checks(item,index){
  315. let pageList = this.couponList;
  316. if(pageList[index].isShow){
  317. pageList[index].isShow = false;
  318. }else{
  319. pageList.map(it=>{
  320. it.isShow = false;
  321. return it;
  322. });
  323. pageList[index].isShow = true;
  324. }
  325. },
  326. swiperChange(e) {
  327. let source = e.detail.source
  328. if (source == 'autoplay' || source == 'touch') {
  329. this.swiperCurrent = e.detail.current;
  330. this.idx = e.detail.current;
  331. this.vip.money = '';
  332. this.vip.day = '';
  333. this.getVipMoneyT(this.TabList[this.idx].level);
  334. this.loadCoupon(this.TabList[this.idx].id)
  335. }
  336. },
  337. choose() {
  338. this.setData({
  339. freshen: false
  340. });
  341. },
  342. getMy() {
  343. let that = this;
  344. req.getRequest('/api/user/my', {}, data => {
  345. that.isDistriUser = data.isDistriUser;
  346. if (data && data.listShopBase && data.listShopBase != null && data.listShopBase.length > 0) {
  347. if (data.listShopBase[0].merchant_id == that.merchant.id && that.merchant.type != 5) {
  348. that.ascription = true;
  349. }
  350. }
  351. });
  352. },
  353. getConfig() {
  354. var _this = this;
  355. return new Promise((resolve, reject) => {
  356. req.getRequest('/api/config', {}, function(res) {
  357. _this.about = res;
  358. if (res && res.show_membership_price == 1) {
  359. _this.setData({
  360. show_membership_price: 1
  361. });
  362. }
  363. resolve();
  364. });
  365. });
  366. },
  367. showVipd(e) {
  368. let index = e.currentTarget.dataset.index;
  369. let d = {};
  370. let def = this.TabList.findIndex(it => it.active);
  371. d['TabList[' + def + '].active'] = false;
  372. d['TabList[' + index + '].active'] = true;
  373. d['pageList'] = [];
  374. this.setData(d);
  375. this.setData({
  376. idx: index,
  377. bottomId: 'bottomView' + index
  378. });
  379. },
  380. addShopCart(e) {
  381. let state = e.currentTarget.dataset.state;
  382. let skuId = e.currentTarget.dataset.skuid;
  383. let id = e.currentTarget.dataset.id;
  384. let defaultMerchant = req.getStorage('defaultMerchant');
  385. // console.log(skuId, id);
  386. let params = {
  387. skuId: skuId,
  388. quantity: 1,
  389. productId: id,
  390. merchantId: defaultMerchant.id
  391. }; // if(state!=1){
  392. // return req.msg('您来晚了,商品已经下架')
  393. // }
  394. if (this.merchant) {
  395. params.merchantId = this.merchant.id;
  396. }
  397. req.postRequest('/api/purchase/cart', params, res => {
  398. req.msg('加入购物车成功');
  399. });
  400. },
  401. getLikeList() {
  402. //Recommend
  403. if (!this.isLikeLoad) return false;
  404. this.isLikeLoad = false;
  405. let that = this;
  406. req.getRequest(
  407. '/api/product/list',
  408. {
  409. page: that.page,
  410. limit: 10,
  411. attr: 'sell_well'
  412. },
  413. res => {
  414. if (res && res.length >= 10) that.isLikeLoad = true;
  415. if (that.page > 1) res = that.likeList.concat(res);
  416. res = res.map(it => {
  417. if (it.deliverWay && JSON.parse(it.deliverWay).indexOf(3) != -1) it.isJs = true;
  418. return it;
  419. });
  420. that.setData({
  421. likeList: res
  422. });
  423. }
  424. );
  425. },
  426. toDetail(e) {
  427. let id = e.currentTarget.dataset.id;
  428. app.globalData.openPage('product/detail/detail?id=' + id);
  429. },
  430. jumpUrl(url) {
  431. uni.navigateTo({
  432. url: url
  433. });
  434. },
  435. openVip(item,idx) {
  436. // if (this.vip.money <= 0) {
  437. // if (this.userinfo.level == this.item.id && this.userinfo.level != 0 && !this.userinfo.end) {
  438. // } else {
  439. //未领取
  440. // this.jumpUrl('/topic/card/index');
  441. this.freshen = false;
  442. this.jumpUrl('/open/index/index?levelId='+item.id);
  443. // }
  444. return;
  445. // }
  446. this.setData({
  447. money: []
  448. });
  449. let index = e.currentTarget.dataset.index;
  450. let def = this.TabList.findIndex(it => it.active);
  451. let d = {};
  452. d['TabList[' + def + '].active'] = false;
  453. d['TabList[' + index + '].active'] = true;
  454. d['pageList'] = [];
  455. this.setData(d);
  456. this.getVipMoney(this.TabList[index].level);
  457. this.setData({
  458. show: true,
  459. level: this.TabList[index].level
  460. });
  461. console.log('会员等级>>>>>>>',this.TabList);
  462. },
  463. eliminate() {
  464. this.setData({
  465. show: false
  466. });
  467. },
  468. switchTab(event) {
  469. this.setData({
  470. money: []
  471. });
  472. let index = event.currentTarget.dataset.index;
  473. let level = event.currentTarget.dataset.level;
  474. let def = this.TabList.findIndex(it => it.active);
  475. let d = {};
  476. d['TabList[' + def + '].active'] = false;
  477. d['TabList[' + index + '].active'] = true;
  478. d['pageList'] = [];
  479. this.setData({
  480. index: index,
  481. level: level
  482. });
  483. this.setData(d);
  484. this.getVipMoney(level);
  485. },
  486. getVip() {
  487. req.getRequest('/api/levelStrategy/userLevelList', {}, data => {
  488. let that = this;
  489. let arr = [];
  490. let node = [];
  491. data.forEach(it => {
  492. var nodes = it.editorContent;
  493. node.push(nodes);
  494. return it;
  495. });
  496. this.nodes = node;
  497. arr.forEach(it => {});
  498. this.setData({
  499. vipList: data,
  500. TabList: data,
  501. ['TabList[' + 0 + '].active']: true,
  502. imags: arr
  503. });
  504. this.getVipMoneyT(this.TabList[0].level);
  505. this.loadCoupon(this.TabList[0].id)
  506. this.getVipListOrg();
  507. });
  508. },
  509. getVipListOrg() {
  510. if (this.TabList && this.userinfo) {
  511. for (var i = 0; i < this.TabList.length; i++) {
  512. var item = this.TabList[i];
  513. if (this.userinfo.level == item.id) {
  514. this.TabList = this.TabList.slice(i, this.TabList.length);
  515. this.getVipMoneyT(this.TabList[0].level);
  516. this.loadCoupon(this.TabList[0].id)
  517. let node = [];
  518. this.TabList.forEach(it => {
  519. var nodes = it.editorContent;
  520. node.push(nodes);
  521. return it;
  522. });
  523. this.nodes = node;
  524. return;
  525. }
  526. }
  527. }
  528. },
  529. getuserVip() {
  530. req.getRequest('/api/user/levelDetails', {}, data => {
  531. let expireTime = Array;
  532. if (data.expireTime) {
  533. expireTime = data.expireTime.split(' ');
  534. data.expireTime = data.expireTime.replace(/-/g, '/');
  535. }
  536. let nowTime = new Date().getTime();
  537. let endTime = new Date(data.expireTime).getTime();
  538. let times = parseInt((endTime - nowTime) / 1000);
  539. this.setData({
  540. userinfo: data,
  541. ['userinfo.expireTime']: expireTime[0]
  542. });
  543. if (times <= 0) {
  544. this.setData({
  545. ['userinfo.end']: true
  546. });
  547. } else {
  548. this.setData({
  549. ['userinfo.end']: false
  550. });
  551. }
  552. this.getVipListOrg();
  553. });
  554. },
  555. /**
  556. * 获取每个会员的销售价格
  557. * @param {Object} index
  558. */
  559. getVipMoney(index) {
  560. this.setData({
  561. price: 0,
  562. day: 0,
  563. id: ''
  564. });
  565. let from = {
  566. level: index
  567. };
  568. req.getRequest('/api/levelStrategy/list', from, data => {
  569. if (data && data.length > 0) {
  570. this.setData({
  571. money: data,
  572. ['money[' + 0 + '].active']: true,
  573. price: data[0].price,
  574. day: data[0].day,
  575. id: data[0].id
  576. });
  577. //设置等级的价格
  578. this.TabList[index-1].price = data[0].price;
  579. }
  580. });
  581. },
  582. getVipMoneyT(index) {
  583. let from = {
  584. level: index
  585. };
  586. return new Promise((resolve, reject) => {
  587. req.getRequest('/api/levelStrategy/list', from, data => {
  588. if (data && data.length > 0) {
  589. this.vip.money = data[0].price;
  590. this.vip.day = data[0].day;
  591. }
  592. this.TabList[index-1].price = data[0].price;
  593. });
  594. resolve();
  595. });
  596. },
  597. // 选择开通时长
  598. selectOpen(event) {
  599. let index = event.currentTarget.dataset.index;
  600. let id = event.currentTarget.dataset.id;
  601. let price = event.currentTarget.dataset.price;
  602. let day = event.currentTarget.dataset.day;
  603. let def = this.money.findIndex(it => it.active);
  604. let d = {};
  605. d['money[' + def + '].active'] = false;
  606. d['money[' + index + '].active'] = true;
  607. d['pageList'] = [];
  608. this.setData(d);
  609. this.setData({
  610. price: price,
  611. day: day,
  612. id: id
  613. });
  614. },
  615. //购买
  616. buy() {
  617. let that = this;
  618. if (!this.id || this.id == undefined || this.id == null) return req.msg('请选择开通类型');
  619. if (this.userinfo.levelGrade > this.level && !this.userinfo.end) return req.msg('您不能购买低于现在等级会员');
  620. that.setData({
  621. show: false
  622. });
  623. route.vip(
  624. {
  625. strategyId: this.id,
  626. scene: req.getStorage('scene')
  627. },
  628. data => {
  629. route.vipPay(data.id, data.status, this.price, res => {
  630. if (res) {
  631. app.globalData.navigateTo('product/pay/pay?isSuccess=true&vip=true');
  632. }
  633. });
  634. }
  635. );
  636. }
  637. }
  638. };
  639. </script>
  640. <style>
  641. @import './vip.css';
  642. </style>