memberPage.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. // 服务列表
  2. var serviceList = [
  3. {
  4. name: '优惠商品',
  5. subTitle: '超级会员专享',
  6. pcIcon:'/img/member/pc-cm-svip-icon1.png',
  7. h5Icon:'/img/member/h5-cm-svip-icon1.png'
  8. },
  9. {
  10. name: '专属优惠券',
  11. subTitle: '每季度可领',
  12. pcIcon:'/img/member/pc-cm-svip-icon2.png',
  13. h5Icon:'/img/member/h5-cm-svip-icon2.png'
  14. },
  15. {
  16. name: '免运费',
  17. subTitle: '下单全包邮',
  18. pcIcon:'/img/member/pc-cm-svip-icon8.png',
  19. h5Icon:'/img/member/h5-cm-svip-icon8.png'
  20. },
  21. {
  22. name: '采美豆翻倍',
  23. subTitle: '下单返采美豆',
  24. pcIcon:'/img/member/pc-cm-svip-icon3.png',
  25. h5Icon:'/img/member/h5-cm-svip-icon3.png'
  26. },
  27. {
  28. name: '专属客服',
  29. subTitle: '一对一',
  30. pcIcon:'/img/member/pc-cm-svip-icon4.png',
  31. h5Icon:'/img/member/h5-cm-svip-icon4.png'
  32. },
  33. {
  34. name: '专属销售顾问',
  35. subTitle: '一对一',
  36. pcIcon:'/img/member/pc-cm-svip-icon5.png',
  37. h5Icon:'/img/member/h5-cm-svip-icon5.png'
  38. },
  39. {
  40. name: '新品试用',
  41. subTitle: '新品可优先试用',
  42. pcIcon:'/img/member/pc-cm-svip-icon6.png',
  43. h5Icon:'/img/member/h5-cm-svip-icon6.png'
  44. },
  45. {
  46. name: '售后服务',
  47. subTitle: '会员加速',
  48. pcIcon:'/img/member/pc-cm-svip-icon7.png',
  49. h5Icon:'/img/member/h5-cm-svip-icon7.png'
  50. }
  51. ];
  52. var memberPage = new Vue({
  53. el: '#memberPage',
  54. mixins: [cmSysVitaMixins],
  55. data: {
  56. serviceList: serviceList, // 服务列表
  57. serviceList2: [
  58. {
  59. name: '分期付',
  60. subTitle: '热门商品分期付',
  61. pcIcon:'/img/member/pc-cm-svip-icon8.png',
  62. h5Icon:'/img/member/h5-cm-svip-icon8.png'
  63. }
  64. ], // 服务列表
  65. comboInfo: [], // svip套餐信息
  66. showMask: false, // 遮罩层
  67. showRenewPopup: false, // 续费弹窗
  68. showConfirmPopup: false, // 支付确认弹窗
  69. showBottomBtns: false,
  70. // 优惠券列表
  71. couponList: [],
  72. comboCurrent: 0, // 当前选择的套餐
  73. vipInfo: {}, // 用户svip信息
  74. currentIndex: 0,
  75. productList: [],
  76. listQuery: {
  77. userId: GLOBAL_USER_ID,
  78. source: 1,
  79. pageNum: 1,
  80. pageSize: 6
  81. },
  82. payType: 1, // 1:RMB支付 2:采美豆抵扣
  83. payBtnType: 1, // 1: 支付/抵扣按钮1, 2: 支付/抵扣按钮2 3:续费
  84. },
  85. computed: {
  86. svipTips: function () {
  87. var vipFlag = this.vipInfo.vipFlag;
  88. var endTime = moment(this.vipInfo.endTime).format('yyyy.MM.DD');
  89. if (vipFlag === 1) {
  90. return '<span>已开通采美超级会员</span><span class="time">有效期至' + endTime + '</span>'
  91. } else if (vipFlag === -1) {
  92. return '<span class="error">采美·超级会员已过期</span><span class="time">有效期至' + endTime + '</span>';
  93. } else {
  94. return '<span>采美·超级会员</span><span>享专属特权</span>'
  95. }
  96. },
  97. },
  98. mounted: function () {
  99. this.fetchSuperPackage();
  100. this.initCenter();
  101. this.getSvipProductList();
  102. this.setBottomBtnsVisiable();
  103. },
  104. methods: {
  105. // 是否显示vip标签价格
  106. showVipPriceTag: function(product){
  107. return (product.priceFlag !== 1 && product.svipProductFlag === 1 && ((GLOBAL_USER_IDENTITY === 4 && GLOBAL_VIP_FLAG === 1) || GLOBAL_USER_IDENTITY === 2));
  108. },
  109. // 初始化会员中心
  110. initCenter: function () {
  111. var _self = this;
  112. UserApi.GetSuperCenterInfo({userId: GLOBAL_USER_ID, source: 1}, function (res) {
  113. if (res.code === 0) {
  114. _self.vipInfo = res.data.vip;
  115. window.localStorage.setItem('vipInfo', JSON.stringify(_self.vipInfo));
  116. _self.couponList = _self.initCouponInfo(res.data.coupon.splice(0, 4));
  117. } else {
  118. CAIMEI.Alert(response.msg, '确定', false);
  119. _self.isRequset = false;
  120. }
  121. })
  122. },
  123. //选择套餐
  124. chooseCombo: function (index) {
  125. this.currentIndex = index
  126. },
  127. //支付会员
  128. payAction: function (type, payBtnType) {
  129. this.payBtnType = payBtnType;
  130. // RMB支付
  131. switch (type) {
  132. case 1: // RMB支付
  133. this.payByRMB();
  134. break;
  135. case 2: // 采美豆支付
  136. this.payByBeans();
  137. break;
  138. default:
  139. return;
  140. }
  141. },
  142. // RMB支付
  143. payByRMB: function (packageId) {
  144. console.log('RMB支付');
  145. var currentCombo = this.comboInfo[this.currentIndex];
  146. var _self = this;
  147. UserApi.RegisterSuperPay({userId: GLOBAL_USER_ID, packageId: currentCombo.id}, function (response) {
  148. if (response.code === 0) {
  149. console.log(response);
  150. //本地保存一下选中的会员套餐信息
  151. window.localStorage.setItem('comboInfo', JSON.stringify(currentCombo));
  152. window.open('/pay/caimei-hlbpay.html?pageType=2&vipRecordId=' + response.data);
  153. _self.showRenewPopup = false;
  154. _self.showMask = false;
  155. // this.showConfirmPopup = true;
  156. } else {
  157. CAIMEI.dialog(response.data, false);
  158. }
  159. });
  160. },
  161. // 采美豆支付
  162. payByBeans: function (packageId) {
  163. var _self = this;
  164. var currentPackage = _self.comboInfo[this.currentIndex];
  165. var popupParams = {
  166. content: '确认使用' + (currentPackage.price * currentPackage.proportion) + '采美豆开通' + (currentPackage.duration) + '个月会员?',
  167. confitmBtnText: '确认开通',
  168. cancelBtnText: '取消',
  169. closeIcon:true
  170. };
  171. CAIMEI.Popup(popupParams, function () {
  172. console.log('采美豆支付');
  173. var params = {
  174. userId: GLOBAL_USER_ID,
  175. packageId: currentPackage.id
  176. };
  177. UserApi.RegisterSuperByBeans(params, function (res) {
  178. if (res.code) {
  179. CAIMEI.dialog(res.msg, false);
  180. _self._czcPushHandle(true);
  181. } else {
  182. CAIMEI.dialog('开通会员成功', true, function () {
  183. var userInfo = JSON.parse(localStorage.getItem('userInfo'));
  184. userInfo.vipFlag = 1;
  185. window.localStorage.setItem('userInfo', JSON.stringify(userInfo));
  186. window.location.reload();
  187. })
  188. }
  189. _self.handleCloseRenewPopup()
  190. })
  191. },function(){
  192. _self._czcPushHandle(false);
  193. });
  194. },
  195. // 本页面友盟统计 flag 确认/取消
  196. _czcPushHandle: function (flag = true) {
  197. var arg1 = ''; // 事件类别
  198. var arg2 = '超级会员'; // 分类
  199. var arg3 = ''; // 说明
  200. var eventName = '';
  201. // 配置参数
  202. if(this.payBtnType === 1){
  203. arg1 = '开通超级会员';
  204. arg3 = '采美豆抵扣1';
  205. eventName = 'RegisterSuperPayOne';
  206. }else if(this.payBtnType === 2){
  207. arg1 = '开通超级会员';
  208. arg3 = '采美豆抵扣2';
  209. eventName = 'RegisterSuperPayTwo';
  210. }else{
  211. arg1 = '续费超级会员';
  212. arg3 = '采美豆抵扣';
  213. eventName = 'RenewSuperPay';
  214. }
  215. // 确认 or 取消
  216. if(flag){
  217. eventName += 'Confirm';
  218. arg3 += '-确认抵扣'
  219. }else{
  220. eventName += 'Cancel';
  221. arg3 += '-取消'
  222. }
  223. var pushParamsList = ['_trackEvent', arg1, arg2, arg3, '', 'Um_Event_' + eventName];
  224. _czc.push(pushParamsList);
  225. // console.log(pushParamsList); for debugger
  226. },
  227. fetchSuperPackage: function () {
  228. var _self = this;
  229. UserApi.FetchSuperPackage({}, function (response) {
  230. if (response.code === 0) {
  231. _self.comboInfo = response.data;
  232. }
  233. })
  234. },
  235. // 初始化优惠券信息
  236. initCouponInfo: function (couponList) {
  237. var typeText = {
  238. 0: '活动券',
  239. 1: '品类券',
  240. 2: '用户专享券',
  241. 3: '店铺券',
  242. 4: '新用户券'
  243. };
  244. return couponList.map(function (item, index) {
  245. item.typeText = typeText[item.couponType];
  246. return item;
  247. })
  248. },
  249. // 点击去使用跳转路由处理
  250. toUseCoupon: function (coupon) {
  251. var resultUrl = '';
  252. switch (coupon.couponType) {
  253. case 0:// 活动券跳转到商城首页 / 或者活动页(看是否指定了商品)
  254. if (coupon.productType === 1) {
  255. resultUrl = '/index.html';
  256. } else {
  257. resultUrl = '/product/product-coupon.html?couponId=' + coupon.couponId;
  258. }
  259. break;
  260. case 1:// 品类券:跳转到产品 / 仪器页
  261. if (coupon.categoryType === 1) {
  262. resultUrl = '/product/type-287.html';
  263. } else {
  264. resultUrl = '/product/type-286.html';
  265. }
  266. break;
  267. case 2:// 专享券:跳转到商城首页
  268. resultUrl = '/index.html';
  269. break;
  270. case 3:// 店铺券:跳转到店铺首页
  271. resultUrl = '/supplier-' + coupon.shopId + '.html';
  272. debugger
  273. break;
  274. case 4:// 新用户券:跳转到商城首页
  275. resultUrl = '/index.html';
  276. break;
  277. }
  278. window.open(resultUrl, '_blank');
  279. },
  280. // 领取专属优惠券
  281. receiveCoupon: function (id) {
  282. var _self = this;
  283. if(_self.vipInfo.vipFlag !== 1){
  284. return CAIMEI.dialog('您还未开通超级会员,不能领取', false);
  285. }
  286. ProductApi.ReceiveCoupon({
  287. userId: GLOBAL_USER_ID,
  288. couponId: id,
  289. source: 1
  290. }, function (response) {
  291. if (!response.code) {
  292. _self.couponList = _self.couponList.map(function (item, i) {
  293. if (item.couponId === id) {
  294. item.getFlag = 1
  295. }
  296. return item;
  297. });
  298. CAIMEI.dialog(response.data, false);
  299. }
  300. })
  301. },
  302. // 续费弹窗
  303. handleShowRenewPopup: function () {
  304. if(this.comboInfo.length === 0){
  305. return CAIMEI.dialog('暂无可选套餐~', false);
  306. }
  307. this.fetchSuperPackage();
  308. this.currentIndex = 0;
  309. this.showMask = true;
  310. this.showRenewPopup = true;
  311. },
  312. // 关闭续费弹窗
  313. handleCloseRenewPopup: function () {
  314. this.showMask = false;
  315. this.showRenewPopup = false;
  316. },
  317. // 获取页面优惠商品
  318. getSvipProductList: function () {
  319. var _self = this;
  320. ProductApi.GetSvipProductList(this.listQuery, function (res) {
  321. if (res.code) return;
  322. var resultData = res.data;
  323. if (isPC) {
  324. _self.productList = resultData.svipProductPage.results.splice(0, 5);
  325. } else {
  326. _self.productList = resultData.svipProductPage.results.splice(0, 6);
  327. }
  328. setTimeout(function () {
  329. $("img[data-original]").lazyload();
  330. });
  331. })
  332. },
  333. makePrice: function (product) {
  334. if (!product) return;
  335. // 普通商品
  336. var priceFlag = parseInt(product.priceFlag); //商品可见度 0公开价格 1不公开价格 2仅对会员机构公开
  337. var userIdentity = parseInt(product.userIdentity); //用户身份 0、个人 1、协销 2、资质机构 3、供应商 4,个人机构
  338. var shopID = parseInt(product.shopID); // 所属供应商id
  339. var originalPrice = parseFloat(product.originalPrice).toFixed(2); //商品原价
  340. var price = parseFloat(product.price).toFixed(2); // 商品价格
  341. var priceGrade = parseInt(product.priceGrade); // 价格等级
  342. // 二手商品价格标识 2 :价格详聊
  343. var detailTalkFlag = parseInt(detailTalkFlag);
  344. // 标签
  345. var promotions = product.promotions; // 促销标签内容
  346. var svipProductFlag = product.svipProductFlag; // SVIP标识 1 是 2 不是
  347. var isSvip = true;
  348. if (product.productCategory === '1') {
  349. // 登录后查看
  350. if (!GLOBAL_USER_ID) {
  351. return '¥登录后查看'
  352. }
  353. if (priceFlag === 1) {
  354. return '¥价格未公开'
  355. }
  356. if ((priceFlag === 2 && GLOBAL_USER_IDENTITY === 4) && GLOBAL_VIP_FLAG !== 1) {
  357. return '¥会员可见'
  358. }
  359. if ((priceFlag === 3 && GLOBAL_USER_IDENTITY === 2 && GLOBAL_CLUB_TYPE!=1) || (priceFlag === 3 && GLOBAL_USER_IDENTITY === 4)) {
  360. return '¥仅医美机构可见'
  361. }
  362. // 价格可见
  363. if ((priceFlag === 0 && userIdentity !== 3) || (GLOBAL_USER_IDENTITY === 2) || (userIdentity === 3 && GLOBAL_SHOP_ID === shopID) || GLOBAL_VIP_FLAG === 1) {
  364. if (promotions || (svipProductFlag === 1 && GLOBAL_VIP_FLAG === 1)) {
  365. return '<del>¥' + originalPrice + '</del>'
  366. }
  367. return '¥' + price;
  368. }
  369. return '<span>¥</span><span class=\"p-icon i' + priceGrade + '\"></span>'
  370. } else {
  371. // 二手商品
  372. if (detailTalkFlag === 2) {
  373. return '¥价格详聊'
  374. }
  375. return '¥' + price;
  376. }
  377. },
  378. setBottomBtnsVisiable: function () {
  379. var _self = this;
  380. setTimeout(function () {
  381. if (isPC && _self.comboInfo.length > 0 && _self.vipInfo.vipFlag !== 1) {
  382. $(window).scroll(function () {
  383. var vipPackage = document.querySelector('#vipPackage').getBoundingClientRect();
  384. var memberPage = document.querySelector('#memberPage').getBoundingClientRect();
  385. var clientHeight = $(window).height();
  386. if(vipPackage.bottom < 185 ){
  387. _self.showBottomBtns = true;
  388. }
  389. if (clientHeight - memberPage.bottom > 104) {
  390. _self.showBottomBtns = true;
  391. $('#pay-amount-bottom').addClass('absolute');
  392. } else {
  393. $('#pay-amount-bottom').removeClass('absolute');
  394. if (vipPackage.bottom > 185) {
  395. _self.showBottomBtns = false;
  396. }
  397. }
  398. })
  399. }
  400. },200)
  401. }
  402. }
  403. });