memberPage.js 13 KB

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