vip_renew.js 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844
  1. var renew = {
  2. oldRules: Calculation.PriceRule.old,
  3. newRules: Calculation.PriceRule.new,
  4. requestRules: {},
  5. price: '', // 单位分
  6. timeSelect: [1, 2], // 续费周期(默认选中1个月)
  7. timeCheckOk: true,
  8. buyInfo: { // 购买的信息
  9. startTime: 0,
  10. endTime: 0,
  11. area: {},
  12. industry: [],
  13. buyset: {
  14. areacount: 0,
  15. newcitys: [],
  16. buyerclasscount: 0,
  17. upgrade: 0
  18. },
  19. isTrial: false,
  20. renewList: []
  21. },
  22. isMaxTime: false,
  23. init: function () {
  24. this.initEvents()
  25. this.recoverState()
  26. this.getPrice()
  27. this.getBuySetInfo()
  28. this.setTimePickerSelected(this.timeSelect)
  29. },
  30. setAreaAndIndustry: function () {
  31. var buySet = this.buyInfo.buyset
  32. var result = {
  33. area: '',
  34. industry: ''
  35. }
  36. // 区域
  37. if (buySet.areacount === -1) {
  38. result.area = '全国'
  39. } else {
  40. var strArr = []
  41. if (buySet.upgrade == 1) {
  42. if (buySet.areacount) {
  43. strArr.push(buySet.areacount + '')
  44. }
  45. } else {
  46. if (buySet.areacount) {
  47. strArr.push(buySet.areacount + '个省')
  48. }
  49. if (buySet.newcitys && buySet.newcitys.length !== 0) {
  50. var count = 0
  51. buySet.newcitys.forEach(function (item) {
  52. count += item
  53. })
  54. strArr.push(count + '个市(分布在' + buySet.newcitys.length + '个省内')
  55. }
  56. }
  57. result.area = strArr.join('、')
  58. }
  59. // 行业
  60. if (buySet.buyerclasscount === -1) {
  61. result.industry = '全部行业'
  62. } else {
  63. result.industry = buySet.buyerclasscount + '个行业'
  64. }
  65. $('.area .item-r').text(result.area)
  66. $('.industry .item-r').text(result.industry)
  67. return result
  68. },
  69. initEvents: function () {
  70. this.initClickEvents()
  71. this.initPickerEvents()
  72. },
  73. getBuySetInfo: function () {
  74. var _this = this
  75. $.ajax({
  76. url: '/subscribepay/vipsubscribe/getSubBuyMsg',
  77. type: 'POST',
  78. success: function (r) {
  79. if (r.success && r.data) {
  80. Object.assign(_this.buyInfo, r.data)
  81. _this.setAreaAndIndustry()
  82. _this.checkShowDueTip()
  83. // 初始化默认续费周期
  84. _this.calcDuration(true)
  85. // 初始化价格计算类
  86. Calculation.Init(
  87. _this.buyInfo.isTrial,
  88. new Buyset(
  89. _this.buyInfo.buyset.areacount,
  90. _this.buyInfo.buyset.newcitys,
  91. _this.buyInfo.buyset.buyerclasscount,
  92. _this.buyInfo.buyset.upgrade || 0
  93. )
  94. )
  95. // 新超级订阅续费
  96. if (r.data.buyset.upgrade == 1) {
  97. $("[data-new-vip]").show()
  98. $("[data-old-vip]").hide()
  99. if (_this.buyInfo.buyset.areacount == -1) {
  100. goodsSize.props.areaCount = 16
  101. } else {
  102. goodsSize.props.areaCount = _this.buyInfo.buyset.areacount
  103. }
  104. }
  105. goodsCoupon.$refs.goodsCoupon.couponList = [] // 防止频繁切换商品规格时 能点击到上和规格可用的优惠券
  106. // 初始化默认金额
  107. _this.setPrice(_this.calcPrice())
  108. }
  109. }
  110. })
  111. },
  112. getPrice: function () {
  113. var _this = this
  114. $.ajax({
  115. url: '/subscribepay/vipsubscribe/getPrice',
  116. type: 'POST',
  117. success: function (r) {
  118. if (r) {
  119. _this.requestRules = r
  120. // 将价格列表传至商品规格组件
  121. goodsSize.props.priceInfo = r.new
  122. }
  123. }
  124. })
  125. },
  126. // 计算价格
  127. calcPrice: function (timeSelect) {
  128. return Calculation.GetTotal(undefined, timeSelect ? timeSelect : this.timeSelect)
  129. },
  130. // 获取当前选择的商品有无满赠活动
  131. getGiftList: function(callback) {
  132. var size = JSON.parse(sessionStorage.getItem('vip-cur-select-size')) || {}
  133. console.log(size)
  134. if (!size || Object.keys(size).length == 0) {
  135. size.period = '1年'
  136. }
  137. var pId;
  138. var _this = this
  139. switch (size.period) {
  140. case '1月':
  141. pId = 1012
  142. break;
  143. case '1季':
  144. pId = 1013
  145. break;
  146. case '1年':
  147. pId = 1014
  148. break;
  149. }
  150. goodsSize.props.giftCycle = null // 下次请求前将满赠周期清掉 请求成功后再赋值
  151. // 先查有没有满赠
  152. $.ajax({
  153. type:'POST',
  154. url:'/jyCoupon/giveInfo',
  155. data:{
  156. useProduct: pId,
  157. useProductType: 0 // 商品类型 0普通的 1线上课程(除线上课程以外的都是0)
  158. },
  159. success:function(res) {
  160. if(res.data && res.data.length > 0) {
  161. res.data.forEach(function(item) {
  162. // 处理展示文字(天、月、年)
  163. if(item.timeType == 1) {
  164. item.time = item.time + '天'
  165. } else if (item.timeType == 2 && item.time < 12) {
  166. item.time = item.time + '个月'
  167. } else if (item.timeType == 2 && item.time == 12) {
  168. item.time = '1年'
  169. }
  170. // 将赠品信息传递给商品订单提交子组件
  171. goodsOrder.giftName = item.name // 满赠商品名称
  172. goodsOrder.giftId = item.discountId // 满赠id
  173. goodsSize.props.defaultSize.time = item.time
  174. goodsSize.props.giftCycle = item.time
  175. })
  176. } else {
  177. // 没有满赠活动再执行其他回调(优惠券)
  178. callback && callback()
  179. }
  180. },
  181. error:function(err) {
  182. console.log(err)
  183. }
  184. })
  185. },
  186. // 设置价格
  187. setPrice: function (price) {
  188. this.price = parseInt(price)
  189. var size = JSON.parse(sessionStorage.getItem('vip-cur-select-size'))
  190. // console.log(renew.buyInfo.buyset)
  191. var count = renew.buyInfo.buyset.areacount == -1 ? 16 : renew.buyInfo.buyset.areacount
  192. if (this.buyInfo.buyset.upgrade == 1) {
  193. // 新规则初始化价格
  194. if (size) {
  195. // 初始化上次选择的商品规格
  196. goodsOrder.updatePrice(size.price / 100)
  197. // 查有无满赠活动 有满赠不再请求优惠券接口
  198. renew.getGiftList(function(){
  199. goodsCoupon.updatePrice(size.price / 100, size.pId)
  200. })
  201. // 校验本次选择的周期是否达到3年的最大限制
  202. renew.checkOver3Years(goodsSize.getTimeSelect(size.period))
  203. } else {
  204. // 初始化默认一年*省份数量或全国价格
  205. sessionStorage.removeItem('$select-coupon')
  206. if (count >= 16) {
  207. goodsOrder.updatePrice(599900 / 100)
  208. renew.getGiftList(function(){
  209. // 一年对应的pId 是1014
  210. goodsCoupon.updatePrice(599900 / 100, 1014)
  211. })
  212. } else {
  213. goodsOrder.updatePrice(38000*count / 100)
  214. renew.getGiftList(function(){
  215. goodsCoupon.updatePrice(38000*count / 100, 1014)
  216. })
  217. }
  218. // 校验本次选择的周期是否达到3年的最大限制
  219. renew.checkOver3Years(goodsSize.getTimeSelect('1年'))
  220. }
  221. } else {
  222. // 旧规则初始化订单价格
  223. goodsOrder.updatePrice(this.price / 100)
  224. // 旧规则初始化自动领券 旧规则无满赠活动可直接领券 旧规则使用默认的pId 101
  225. goodsCoupon.updatePrice(this.price / 100)
  226. }
  227. },
  228. // 根据选中结果得到续费了多长时间的字符串
  229. getDuration: function (timeSelect) {
  230. var durationStr = ''
  231. if (timeSelect[1] === 1) {
  232. // 年
  233. durationStr = timeSelect[0] + '年'
  234. } else if (timeSelect[1] === 2) {
  235. // 月
  236. durationStr = timeSelect[0] + '个月'
  237. }
  238. return durationStr
  239. },
  240. // 计算续费后的日期区间
  241. calcDuration: function (needSet) {
  242. // 根据
  243. var endTime = this.buyInfo.endTime
  244. if (!endTime) {
  245. $('.select_cycle .duration').hide()
  246. return
  247. }
  248. var durationStamp = getVipEndDate(this.timeSelect[1], this.timeSelect[0], endTime) - endTime // 续费时间段时间戳
  249. var durationStr = this.getDuration(this.timeSelect) // 续费时间段字符串
  250. var buyEndTimeString = new Date(endTime * 1000).pattern('yyyy年MM月dd日') // svip到期时间
  251. var renewEndTimeString = new Date((endTime + durationStamp) * 1000).pattern('yyyy年MM月dd日') //续费后到期时间
  252. if (needSet) {
  253. $('.select_cycle .month').text(durationStr)
  254. $('.select_cycle .duration').text(buyEndTimeString + ' - ' + renewEndTimeString)
  255. } else {
  256. return {
  257. duration: durationStr, // 续费时间段字符串
  258. buyEndTimeString: buyEndTimeString, // svip到期时间
  259. renewEndTimeString: renewEndTimeString, //续费后到期时间
  260. }
  261. }
  262. },
  263. // 月份转年份(超过1年才会转)
  264. monthToYear: function (num) {
  265. var year = Math.floor(num / 12)
  266. var month = num % 12
  267. var str = ''
  268. if (year) {
  269. str += (year + '年')
  270. }
  271. if (month) {
  272. str += (month + '个月')
  273. }
  274. return {
  275. str: str,
  276. year: year,
  277. month: month
  278. }
  279. },
  280. checkOver3Years: function (timeSelect) {
  281. // 根据
  282. var endTime = this.buyInfo.endTime
  283. if (!endTime) {
  284. return
  285. }
  286. var maxEndMonth = 36 // 最大续费36个月
  287. var durationStamp = getVipEndDate(timeSelect[1], timeSelect[0], endTime) - endTime // 续费时间段时间戳
  288. // 最长订阅周期不可超过3年 ------------
  289. var nowStamp = Math.floor(Date.now() / 1000)
  290. // 已购买的套餐剩余月数
  291. var lastMonthStamp = endTime - nowStamp
  292. var lastMonth = Math.round(lastMonthStamp / (60 * 60 * 24 * 30))
  293. // 续费后套餐剩余月数(需要加上原剩余月数lastMonth)
  294. var renewMonthTotalStamp = lastMonthStamp + durationStamp
  295. var renewMonthTotal = Math.round(renewMonthTotalStamp / (60 * 60 * 24 * 30))
  296. if (renewMonthTotal > maxEndMonth) {
  297. var showTipText = '<div style="white-space: nowrap;">最长订阅周期不可超过3年</div>剩余周期:' + this.monthToYear(lastMonth).str
  298. weui.toast(showTipText, {
  299. duration: 3000,
  300. className: 'jy-toast',
  301. })
  302. renew.isMaxTime = true
  303. // 确认按钮置灰
  304. $('#enter_period').prop('disabled', true)
  305. } else {
  306. renew.isMaxTime = false
  307. $('#enter_period').prop('disabled', false)
  308. }
  309. renew.flushSubmit()
  310. },
  311. // 是否展示即将到期
  312. checkShowDueTip () {
  313. var endTime = this.buyInfo.endTime * 1000
  314. var timeSub = endTime - Date.now()
  315. if (timeSub > 0 && timeSub < 60 * 60 * 24 * 1000 * 3) {
  316. $('.vip-header').show()
  317. }
  318. },
  319. setTimePickerSelected: function (timeSelect) {
  320. if (timeSelect[1] == 1) {
  321. // 年
  322. var cButton = $('.year_number.j-button-select[data-id=' + timeSelect[0] + ']')
  323. if (cButton) {
  324. cButton.trigger('click')
  325. } else {
  326. $('input[value=year]').trigger('click')
  327. }
  328. } else if (timeSelect[1] == 2) {
  329. // 月
  330. $('input[value=month]').trigger('click')
  331. $('#number_box_month .month_number').text(timeSelect[0] - 1)
  332. $('#number_box_month button.add').trigger('click')
  333. }
  334. },
  335. getTimePickerSelected: function () {
  336. var timeSelectPicker = $('#time_cycle')
  337. var $checkInput = timeSelectPicker.find('input[name=time]:checked')
  338. if (!$checkInput) return
  339. // year/month(按年或者按月购买)
  340. var checkedType = $checkInput.val()
  341. // timeSelectedArr[0] 代表选择的内容
  342. // timeSelectedArr[1] 代表选择的类型 1年份 2月份
  343. var timeSelectedArr = []
  344. if (checkedType === 'month') {
  345. timeSelectedArr = [$('#number_box_month .month_number').text() - 0, 2]
  346. } else if (checkedType === 'year') {
  347. timeSelectedArr = [$('#number_box_year .year_number.active').attr('data-id') - 0, 1]
  348. }
  349. return timeSelectedArr
  350. },
  351. onTimePickerChange: function () {
  352. var timeSelect = this.getTimePickerSelected()
  353. var price = this.calcPrice(timeSelect)
  354. $('.computed_price').text(formatMoney(price / 100))
  355. this.checkOver3Years(timeSelect)
  356. },
  357. // 恢复数据
  358. recoverState: function () {
  359. var vipSubSelectTime = sessionStorage.getItem('vipSubSelectTime')
  360. if (vipSubSelectTime) {
  361. this.timeSelect = JSON.parse(vipSubSelectTime)
  362. }
  363. this.flushSubmit()
  364. },
  365. // 保存数据
  366. saveState: function () {
  367. sessionStorage.setItem('vipSubSelectTime', JSON.stringify(this.timeSelect))
  368. },
  369. // 是否可提交
  370. flushSubmit: function () {
  371. if (this.timeCheckOk && sessionStorage.getItem("vipSub_read") === "true" && !this.isMaxTime) {
  372. $('.vip-footer.renew .confirm').prop('disabled', false)
  373. goodsOrder.checkboxStatus = true
  374. goodsOrder.$refs.couponRef.submitStatus = false
  375. } else {
  376. $('.vip-footer.renew .confirm').prop('disabled', true)
  377. goodsOrder.$refs.couponRef.submitStatus = true
  378. }
  379. },
  380. initClickEvents: function () {
  381. var _this = this
  382. /*------ 关闭弹窗事件 点击取消或遮罩层 -----*/
  383. $('.weui-mask').click(hideDialog);
  384. $('.cancel').click(hideDialog);
  385. // 确认订阅周期
  386. $('#enter_period').on('click', function () {
  387. $('.weui-mask').trigger('click')
  388. _this.timeSelect = _this.getTimePickerSelected()
  389. _this.calcDuration(true)
  390. // 选择完周期后清除上次选择的优惠券
  391. sessionStorage.removeItem('vip-cur-select-coupon')
  392. _this.setPrice(_this.calcPrice())
  393. _this.saveState()
  394. })
  395. $('.vip-footer.renew .confirm').on('click', function () {
  396. $('.vip-footer.renew .confirm').prop('disabled', true)
  397. var upgrade = renew.buyInfo.buyset.upgrade
  398. var size = JSON.parse(JSON.stringify(goodsSize.props.defaultSize))
  399. var sizeTime = ''
  400. var pId;
  401. if (size && size.period) {
  402. switch (size.period) {
  403. case '1月':
  404. pId = 1012
  405. break;
  406. case '1季':
  407. pId = 1013
  408. break;
  409. case '1年':
  410. pId = 1014
  411. break;
  412. }
  413. if(size.period.indexOf('月') > -1 && size.period.indexOf('个月') == -1) {
  414. size.period = size.period.replace('月', '个月')
  415. }
  416. sizeTime = size.period
  417. } else {
  418. sizeTime = '1年'
  419. pId = 1014
  420. }
  421. console.log(upgrade,sizeTime, '新or老')
  422. //支付请求
  423. var data = {
  424. userLotteryId :goodsCoupon.curSelectCoupon.userLotteryId,
  425. lotteryId : goodsCoupon.curSelectCoupon.lotteryId,
  426. time : upgrade == 0 ? _this.getDuration(_this.timeSelect).trim() : sizeTime,
  427. orderType: 5,
  428. disWord :GetQueryString('disWord'),
  429. price: goodsOrder.initPrice*10000/100,
  430. useProduct: pId, // 商品类型
  431. discountId: goodsOrder.giftId, // 满赠id
  432. }
  433. $.ajax({
  434. // url: '/subscribepay/vipsubscribe/createOrder',
  435. url: '/subscribepay/vipsubscribe/renew',
  436. type: 'POST',
  437. data: data,
  438. success: function (r) {
  439. if (r.success) {
  440. clearSessionStorage()
  441. try {
  442. history.replaceState({}, '', '/front/vipsubscribe/toOrderDetailPage?orderCode=' + r.data.code);
  443. window.location.href = "/weixin/pay/checkout_subvip?t=1&orderCode=" + r.data.code;
  444. } catch (e) {
  445. showToast(e)
  446. }
  447. } else {
  448. showToast(r.errMsg || '请求失败')
  449. }
  450. },
  451. complete: function () {
  452. $('.vip-footer.renew .confirm').prop('disabled', false)
  453. }
  454. })
  455. })
  456. },
  457. initPickerEvents: function () {
  458. var _this = this
  459. /* ----- 订阅周期弹窗弹出事件 -------*/
  460. // 选择订阅周期
  461. $('.select_cycle a').click(function (e) {
  462. _this.onTimePickerChange()
  463. $('#time_cycle').show(200);
  464. });
  465. // 对订阅时间选择的input绑定点击事件
  466. $('#time_cycle input:radio[name="time"]').on('click', function (e) {
  467. // 解除确认按钮的锁定
  468. if ($(e.target).hasClass('monthly') !== $('#number_box_month').hasClass('active')) {
  469. $('#time_cycle .form-btn button').removeAttr('disabled');
  470. }
  471. if ($(e.target).hasClass('monthly')) {
  472. // 按月订阅
  473. $('#number_box_month').addClass('active');
  474. $('#number_box_year span').removeClass('active');
  475. } else {
  476. // 按年订阅
  477. $('#number_box_month').removeClass('active');
  478. }
  479. });
  480. /* --------控制月份number_box的事件 点击加减号触发的事件------- */
  481. $('#number_box_month').on('click', 'button', function (e) {
  482. // 点击加减号让input radio选中
  483. $('#monthly').prop('checked', true);
  484. $('#yearly').prop('checked', false);
  485. $('.number_box span').removeClass('active');
  486. $('#number_box_month').addClass('active');
  487. var $number = $('#number_box_month span.month_number');
  488. var $monthlyInput = $('#monthly');
  489. // 未整理的data数组,里面的值都是字符串
  490. var preData = e.delegateTarget.dataset;
  491. var currentNum = parseInt($number.text());
  492. var data = {};
  493. // 把字符串转换成数字
  494. for (var i in preData) {
  495. data[i] = preData[i] - 0
  496. }
  497. if (!$monthlyInput.prop('checked')) {
  498. return
  499. }
  500. // 判断是点击的是+ 还是-
  501. if ($(e.target).hasClass('add') || $(e.currentTarget).hasClass('add')) {
  502. if (currentNum == 11) { //12个月自动跳转1年
  503. $("#number_box_year .year_number:eq(0)").trigger("click");
  504. return
  505. }
  506. // 点的+
  507. currentNum = currentNum >= data.numboxMax ? data.numboxMax : (currentNum + data.numboxStep);
  508. } else {
  509. // 点的-
  510. currentNum = currentNum <= data.numboxMin ? data.numboxMin : (currentNum - data.numboxStep);
  511. }
  512. $number.text(currentNum);
  513. _this.onTimePickerChange()
  514. var firstButton = $('#number_box_month button:first');
  515. var lastButton = $('#number_box_month button:last');
  516. // 如果为操作后的结果为1,则锁定减号按钮
  517. if (currentNum === data.numboxMin) {
  518. firstButton.attr('disabled', true)
  519. } else {
  520. firstButton.removeAttr('disabled')
  521. }
  522. // 如果为操作后的结果为12,则锁定加号按钮
  523. if (currentNum === data.numboxMax) {
  524. lastButton.attr('disabled', true)
  525. } else {
  526. lastButton.removeAttr('disabled')
  527. }
  528. });
  529. /* -------- 控制年份number_box的事件 点击1年 2年 3年触发的事件------- */
  530. $('#number_box_year').on('click', 'span', function (e) {
  531. $('#number_box_month').removeClass('active');
  532. var id = e.target.dataset.id;
  533. $(this).addClass('active').siblings().removeClass('active');
  534. $('#yearly').prop('checked', true);
  535. $("#monthly").prop('checked', false);
  536. _this.onTimePickerChange()
  537. });
  538. /* -------- 选择按月订阅 radio触发的事件------- */
  539. $('#monthly').on('change', function (e) {
  540. var isChecked = $(this).is(':checked');
  541. var val = $('.month_number').text();
  542. if (!isChecked) {
  543. $('#number_box_month button').attr('disabled', true)
  544. }
  545. _this.onTimePickerChange()
  546. });
  547. /* -------- 选择按年订阅 radio触发的事件------- */
  548. $('#yearly').on('change', function (e) {
  549. var isChecked = $(this).is(':checked');
  550. // 按年订阅默认选择1年
  551. var val = 1;
  552. if (isChecked) {
  553. $('#number_box_year span:eq(0)').addClass('active').siblings().removeClass('active')
  554. }
  555. _this.onTimePickerChange()
  556. });
  557. // 计价标准
  558. $('.billing-list-btn').on('click', function () {
  559. pickerShow('.billing-list-container', true)
  560. })
  561. // 计算标准隐藏
  562. $('.billing-list-container .dialog_hd__close').on('click', function () {
  563. pickerShow('.billing-list-container', false)
  564. })
  565. $('.checkbox').on('click', function () {
  566. $(this).toggleClass('checked')
  567. var state = $(this).hasClass('checked')
  568. sessionStorage.setItem("vipSub_read", state)
  569. renew.flushSubmit()
  570. });
  571. }
  572. }
  573. $(function () {
  574. renew.init()
  575. })
  576. //获取url中"?"符后的字符串并正则匹配
  577. function GetQueryString(name) {
  578. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
  579. var r = window.location.search.substr(1).match(reg);
  580. var context = "";
  581. if (r != null)
  582. context = r[2];
  583. reg = null;
  584. r = null;
  585. return context == null || context == "" || context == "undefined" ? "" : context;
  586. }
  587. // 隐藏dialog选择框
  588. function hideDialog() {
  589. $('#pay_way').hide(200);
  590. $('#time_cycle').hide(200);
  591. $('.discount-details').hide()
  592. $('.discount-button .icon-arrow').removeClass('up')
  593. }
  594. function clearSessionStorage() {
  595. sessionStorage.removeItem("vipSubSelectTime");
  596. sessionStorage.removeItem("vipSub_read");
  597. sessionStorage.removeItem("historypushDataCache");
  598. sessionStorage.removeItem("endTime");
  599. sessionStorage.To_introducePage = 2;
  600. //订阅首页
  601. sessionStorage.removeItem("sub_vip_state");
  602. sessionStorage.removeItem("vip_index_read");
  603. sessionStorage.removeItem("vip_change_time");
  604. sessionStorage.removeItem("pay_read_cache")
  605. sessionStorage.removeItem("liveActiveCode_renew");
  606. sessionStorage.removeItem("liveActiveCode_new");
  607. // 清除商品规格当前选择
  608. sessionStorage.removeItem("vip-cur-select-size")
  609. sessionStorage.removeItem("$select-coupon") // 原订单提交组件上记录的缓存
  610. // 商品介绍页上记录的当前选择的优惠券
  611. sessionStorage.removeItem('vip-cur-select-coupon')
  612. }
  613. function showToast(text) {
  614. weui.toast(text, {
  615. duration: 3000,
  616. className: 'jy-toast',
  617. })
  618. }
  619. function pickerShow(selector, f) {
  620. if (f) {
  621. // 添加进场动画,并显示
  622. $(selector).find('.weui-mask').removeClass('weui-animate-fade-out').addClass('weui-animate-fade-in')
  623. $(selector).find('.weui-picker').removeClass('weui-animate-slide-down').addClass('weui-animate-slide-up')
  624. $(selector).show(300);
  625. } else {
  626. // 添加离场动画,并隐藏
  627. $(selector).find('.weui-mask').removeClass('weui-animate-fade-in').addClass('weui-animate-fade-out')
  628. $(selector).find('.weui-picker').removeClass('weui-animate-slide-up').addClass('weui-animate-slide-down')
  629. $(selector).hide(300);
  630. }
  631. }
  632. /* vue 代码 start */
  633. // vip商品规格组件
  634. var goodsSize = new Vue({
  635. el:'#goods-size-vue',
  636. data: function() {
  637. return {
  638. props: {
  639. defaultSize: {},
  640. areaCount: 1,
  641. priceInfo: {},
  642. giftCycle: null // 满赠周期
  643. }
  644. }
  645. },
  646. created () {},
  647. mounted () {
  648. this.getSizeStorage()
  649. },
  650. methods: {
  651. // 父组件传省份数量至子组件
  652. getAreaCount: function() {
  653. var areaStorage = JSON.parse(sessionStorage.getItem('vipSubSelectArea'))
  654. console.log(renew.buyInfo.buyset.areacount)
  655. if (areaStorage) {
  656. var count = 0
  657. for (var key in areaStorage) {
  658. if (key.indexOf('全国') > -1) {
  659. count = 16
  660. } else {
  661. count++
  662. }
  663. }
  664. this.props.areaCount = count
  665. }
  666. },
  667. getSizeStorage: function() {
  668. // 恢复商品规格选择
  669. var size = JSON.parse(sessionStorage.getItem('vip-cur-select-size'))
  670. // console.log(size, '恢复的商品规格')
  671. if (size) {
  672. this.$refs.goodsSize.goodsActive = size.index
  673. this.props.defaultSize = size
  674. this.$nextTick(function(){
  675. goodsOrder.updatePrice(size.price/100)
  676. })
  677. } else {
  678. // 默认选择1年
  679. this.$refs.goodsSize.goodsActive = 2
  680. }
  681. },
  682. getGoodSize: function(data) {
  683. // console.log(data, '父组件接收子组件传来的商品规格')
  684. renew.checkOver3Years(this.getTimeSelect(data.period))
  685. sessionStorage.removeItem('$select-coupon')
  686. this.props.defaultSize = data
  687. goodsCoupon.$refs.goodsCoupon.couponList = [] // 防止频繁切换商品规格时 能点击到上和规格可用的优惠券
  688. goodsOrder.updatePrice(data.price/100)
  689. // 查询有无满赠,无满赠执行回调查优惠券
  690. renew.getGiftList(function(){
  691. goodsCoupon.updatePrice(data.price/100, data.pId)
  692. })
  693. },
  694. getTimeSelect: function(data) {
  695. var time;
  696. switch (data) {
  697. case '1月':
  698. time = [1,2]
  699. break;
  700. case '1季':
  701. time = [3,2]
  702. break;
  703. case '1年':
  704. time = [1,1]
  705. break;
  706. }
  707. return time
  708. }
  709. }
  710. })
  711. // vip优惠券
  712. var goodsCoupon = new Vue({
  713. el:'#goods-coupon-vue',
  714. data: function() {
  715. return {
  716. curSelectCoupon: {}
  717. }
  718. },
  719. mounted () {},
  720. methods: {
  721. updatePrice: function(data, pId){
  722. this.$refs.goodsCoupon.getCoupon(data, pId)
  723. },
  724. updateCoupon: function(data) {
  725. console.log(data, '更新优惠券选择')
  726. this.curSelectCoupon = data
  727. var curSize = JSON.parse(sessionStorage.getItem('vip-cur-select-size'))
  728. // 更新优惠券选择同时更新订单组件的价格及优惠金额
  729. if (curSize) {
  730. goodsOrder.updatePrice(curSize.price/100)
  731. } else {
  732. goodsOrder.updatePrice(goodsOrder.initPrice)
  733. }
  734. }
  735. }
  736. })
  737. // 订单提交组件
  738. var goodsOrder = new Vue({
  739. el: '#goods-order-vue',
  740. data: function () {
  741. return {
  742. type: 'vip',
  743. initPrice: 0, // 原价
  744. realPrice: 0, // 实付价
  745. checkboxStatus: false, // checkbox状态
  746. submitStatus: true, // 提交按钮状态
  747. links: [
  748. {
  749. text: '《剑鱼标讯线上购买与服务条款》',
  750. url: '/front/staticPage/wx-serviceterms.html',
  751. event: this.readEvent
  752. }
  753. ],
  754. buttons: {
  755. submit: this.submitOrder
  756. },
  757. hideCoupon: true,
  758. giftName: '', // 赠品名称
  759. giftId: '' // 赠品id
  760. }
  761. },
  762. mounted () {
  763. this.init()
  764. this.$emit('mounted')
  765. },
  766. methods: {
  767. payOrderTemplateMounted: function () {
  768. $('#submitButton').attr('data-cl-event', 'c_wx_order_buttonclick')
  769. },
  770. // 更新价格相关
  771. updatePrice: function (before) {
  772. var curCoupon = JSON.parse(sessionStorage.getItem('vip-cur-select-coupon'))
  773. // 处理优惠金额 主要作用为展示优惠明细弹框立得优惠金额
  774. if (curCoupon) {
  775. if(curCoupon.lotteryAttribute == '折扣券') {
  776. // disCount为折扣率 优惠金额 = 原价*优惠了多少比例(100 - disCount)
  777. this.$refs.couponRef.coupon.value = Number(before*((100 - curCoupon.disCount*10)/100)).toFixed(2)
  778. } else if (curCoupon.lotteryAttribute == '满减券') {
  779. this.$refs.couponRef.coupon.value = curCoupon.reduce
  780. }
  781. } else {
  782. this.$refs.couponRef.coupon.value = 0
  783. }
  784. this.initPrice = before;
  785. },
  786. // 初始化及回显相关
  787. init: function () {},
  788. // 勾选阅读协议
  789. updateS: function(data) {
  790. data.callback(this.checkSubmitStatus(data.check))
  791. },
  792. // 校验checkbox
  793. checkSubmitStatus: function (checkStatus) {
  794. sessionStorage.setItem("vipSub_read", checkStatus)
  795. renew.flushSubmit()
  796. return renew.timeCheckOk && sessionStorage.getItem("vipSub_read") === "true" && !renew.isMaxTime
  797. },
  798. saveEvent: function () {
  799. renew.saveState()
  800. sessionStorage.setItem("pay_read_cache", "0");
  801. },
  802. // 阅读协议点击事件
  803. readEvent: function () {
  804. renew.saveState()
  805. toRead()
  806. },
  807. // 订单提交事件
  808. submitOrder: function () {
  809. this.$refs.couponRef.submitStatus = true
  810. $('.vip-footer.renew .confirm').trigger('click')
  811. this.$refs.couponRef.submitStatus = false
  812. }
  813. }
  814. })
  815. /* vue 代码 end */