task-202207.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958
  1. function Point (x, y) {
  2. this.x = x
  3. this.y = y
  4. }
  5. function Map (w, h) {
  6. this.width = w
  7. this.height = h
  8. }
  9. // 画布中生成随机不重叠的坐标
  10. // 坐标点以左上角为中心
  11. function RandomCoordinate (conf) {
  12. conf = conf || {}
  13. this.el = conf.el || '' // 画布选择器或者dom
  14. this.pointSize = conf.pointSize || new Map(1, 1) // 坐标点半径(最大)
  15. this.total = conf.total || 1 // 生成多少个随机不重叠坐标
  16. this.pointCoordList = [] // 生成坐标点数组
  17. this.init = function () {
  18. if (!this.el) return console.warn('画布选择器必传')
  19. // 获取画布宽高
  20. this.map = this.getMapSize()
  21. this.getPointCoordLimits()
  22. this.create()
  23. }
  24. this.getMapSize = function () {
  25. this.$el = $(this.el)
  26. var w = this.$el.width()
  27. var h = this.$el.height()
  28. return new Map(w, h)
  29. }
  30. this.getPointCoordLimits = function () {
  31. var xMax = this.map.width - this.pointSize.width
  32. var yMax = this.map.height - this.pointSize.height
  33. if (xMax <= 0) {
  34. xMax = 1
  35. }
  36. if (yMax <= 0) {
  37. yMax = 1
  38. }
  39. this.coordLimits = new Point(xMax, yMax)
  40. }
  41. // this.check
  42. // 检查是否和已创建的有重叠
  43. this.checkListOverlap = function (p) {
  44. if (this.pointCoordList.length <= 0) return true
  45. var pass = true // pass,所有都不重叠
  46. for (var i = 0; i < this.pointCoordList.length; i++) {
  47. var overlap = this.checkOverlap(p, this.pointCoordList[i])
  48. if (overlap) {
  49. pass = false
  50. break
  51. }
  52. }
  53. return pass
  54. },
  55. // point为矩形左上的碰撞检测:碰撞返回true
  56. // 利用两圆相切,圆心距离小于2r表示两圆相交(r圆半径)。把矩形对角线看作圆的直径
  57. // 如果两个矩形左上角的点间距离大于矩形对角线长度,则认为两矩形无碰撞(无重叠)
  58. // 参考:https://segmentfault.com/a/1190000017463616
  59. this.checkOverlap = function (nPoint, oPoint) {
  60. // 两矩形左上角坐标距离(三角函数)
  61. // https://www.qttc.net/171-javascript-get-two-points-distance.html
  62. var dx = Math.abs(nPoint.x - oPoint.x)
  63. var dy = Math.abs(nPoint.y - oPoint.y)
  64. var distance = Math.sqrt(dx * dx + dy * dy)
  65. // 矩形对角线长度
  66. var w = this.pointSize.width
  67. var h = this.pointSize.height
  68. var diagonal = Math.sqrt(w * w + h * h)
  69. return distance <= diagonal
  70. }
  71. // 创建一个坐标
  72. this.createOne = function () {
  73. var createTimes = 0
  74. var createFailTimes = 0
  75. var maxCreateFailTime = 200
  76. var x,y
  77. while (createFailTimes < maxCreateFailTime) {
  78. createTimes++
  79. x = Math.floor(Math.random() * this.coordLimits.x)
  80. y = Math.floor(Math.random() * this.coordLimits.y)
  81. var point = new Point(x, y)
  82. var pass = this.checkListOverlap(point)
  83. if (pass) {
  84. this.pointCoordList.push(point)
  85. break
  86. } else {
  87. createFailTimes++
  88. }
  89. }
  90. if (createFailTimes >= maxCreateFailTime) {
  91. console.log('随机生成坐标%s次失败,停止随机生成', maxCreateFailTime)
  92. } else {
  93. console.log('随机生成坐标次数:%s,\n随机生成坐标失败次数:%s\n获得坐标:', createTimes, createFailTimes, JSON.stringify(point))
  94. }
  95. }
  96. this.create = function () {
  97. for (var i = 0; i < this.total; i++) {
  98. this.createOne()
  99. }
  100. this.pointCoordList = this.pointCoordList.sort(function (a, b) {
  101. return a.x - b.x
  102. })
  103. }
  104. this.init()
  105. }
  106. // 判断活动是否结束
  107. var initPageTime = new Date().getTime()
  108. var initActiveOverCheck = -1
  109. function activeOverCheck (endTime, callback) {
  110. if (initPageTime >= endTime) {
  111. return callback()
  112. }
  113. clearTimeout(initActiveOverCheck)
  114. var reloadTime = endTime - new Date().getTime()
  115. if (reloadTime <= (10 * 60 * 1000) ) {
  116. initActiveOverCheck = setTimeout(function () {
  117. callback && callback()
  118. }, reloadTime)
  119. }
  120. }
  121. // toast上限提示
  122. function toastFn (text, duration) {
  123. if (!duration) {
  124. duration = 1000
  125. }
  126. var _html = ""
  127. _html+='<div class="custom-toast"><div class="mask" style="background-color: transparent;"></div><div class="toast-container">'
  128. _html+='<span>' + text + '</span></div></div>'
  129. $('body').append(_html)
  130. setTimeout(function(){
  131. $(".custom-toast").fadeOut().remove();
  132. },duration)
  133. }
  134. // 展示弹窗
  135. function showDialogOfType (type) {
  136. $('#active-tip-modal').attr('data-modal-type', 'success').modal('show')
  137. $('#active-tip-modal').attr('data-modal-type', 'over').modal('show')
  138. $('#active-tip-modal').attr('data-modal-type', 'code').modal('show')
  139. var modal = $('#active-tip-modal')
  140. modal.attr('data-modal-type', type).modal('show')
  141. if (type === 'over') {
  142. modal.off('click')
  143. } else {
  144. modal.off('click').on('click', function () {
  145. modal.modal('hide')
  146. })
  147. }
  148. }
  149. // 固定事件
  150. $(function () {
  151. // 弹窗按钮事件
  152. $('#dialog-button--over').on('click', function () {
  153. window.open('/swordfish/frontPage/share/sess/index')
  154. })
  155. $('#dialog-button--success').on('click', function () {})
  156. })
  157. var task = new Vue({
  158. el: '#main-app',
  159. delimiters: ['${', '}'],
  160. data: {
  161. conf: {
  162. before: 0, // 单位: s
  163. clock: '10:00:00',
  164. end: 0, // 单位: s
  165. now: 0, // 单位: s
  166. start: 0 // 单位: s
  167. },
  168. activeState: '',
  169. lastTimestamp: 0, // 单位: ms
  170. yureConf: {
  171. total: 0,
  172. got: false
  173. },
  174. yureInfo: {
  175. timerId: null,
  176. tipText: '',
  177. buttonText: '点击免费领',
  178. buttonDisabled: false
  179. },
  180. couponList: [],
  181. progress: {
  182. min: 0,
  183. max: 1500,
  184. current: 0, // 当前剑鱼币
  185. pointImgMap: {
  186. unreceived: '/frontRouter/pc/activity/image/unreceived@2x.png',
  187. received: '/frontRouter/pc/activity/image/received@2x.png',
  188. wait: '/frontRouter/pc/activity/image/received@2x.png'
  189. },
  190. anchorList: [
  191. {
  192. id: '',
  193. className: 'first',
  194. rate: 0, // 进度,单位%,最大为100
  195. pointImg: '', // ''/unreceived/received
  196. anchorText: '0剑鱼币'
  197. },
  198. {
  199. id: '800',
  200. className: 'unreceived',
  201. rate: 80,
  202. pointImg: 'unreceived',
  203. anchorText: '800剑鱼币',
  204. tipText: '1个月超级订阅'
  205. },
  206. {
  207. id: '1500',
  208. className: 'unreceived',
  209. rate: 100,
  210. pointImg: 'unreceived',
  211. anchorText: '1500剑鱼币',
  212. tipText: '1个月超级订阅'
  213. }
  214. ],
  215. },
  216. // 任务球
  217. missionsList: [
  218. {
  219. id: 'buyvip',
  220. className: '',
  221. x: 190,
  222. y: 120,
  223. num: 800,
  224. unit: '剑鱼币',
  225. complete: false,
  226. hide: true,
  227. name: '购买超级订阅' // 任务描述
  228. },
  229. {
  230. id: 'invite',
  231. className: 'delay-100',
  232. x: 380,
  233. y: 0,
  234. num: 500,
  235. unit: '剑鱼币',
  236. complete: false,
  237. hide: true,
  238. name: '邀请领好礼'
  239. },
  240. {
  241. id: 'share',
  242. className: 'delay-300',
  243. x: 900,
  244. y: 80,
  245. num: 200,
  246. unit: '剑鱼币',
  247. complete: false,
  248. hide: true,
  249. name: '分享活动'
  250. }
  251. ],
  252. copyLinkText: location.href,
  253. rewardList: [],
  254. dialog: {
  255. myReward: false
  256. },
  257. rulesList: [
  258. {
  259. text: '活动时间:预热期:7.25-7.31 、活动期:8.1-8.14。'
  260. },
  261. {
  262. text: '预热福利:预热期内用户每天10点开始领取,每天限量500份,每天0点数量更新,每人仅限领取一次,数量有限,先到先得。'
  263. },
  264. {
  265. text: '福利一:官方补贴限时抢 购买超级订阅立减:活动期间内新购、续费、升级用户均可参加,通过活动页领取优惠券后购买超级订阅可享受满减,不同额度优惠券一人仅限领取1张,优惠券仅限领取后活动期内使用,过期无效。'
  266. },
  267. {
  268. text: '福利二:做任务 得2个月超级订阅:活动期内,用户分别完成各任务即可获得相对应的剑鱼币,达到1000剑鱼币领1个月超级订阅,达到1500剑鱼币领1个月超级订阅,领取后在原有购买时间上延长所领取奖励的时长,在订单支付期间,完成【购买超级订阅】可获得800剑鱼币,用户新购、续费、升级皆可获得剑鱼币奖励,完成【邀请领好礼】可获得500剑鱼币,完成【分享活动】可获得200剑鱼币;完成购买超级订阅、邀请领好礼、分享活动三个任务且活动页剑鱼币累计达到1000剑鱼币或1500剑鱼币即可领取超级订阅,累计可领2个月,通过其他形式获取的剑鱼币将不作为领取奖励的依据,领取后在【我的奖励】中查看。'
  269. },
  270. {
  271. text: '福利三:大会员最高立减7999元 送6个月使用时长:活动期内商机版2.0最高立减3199元,购买赠送6个月使用时长,专家版2.0最高立减7999元,购买赠送6个月使用时长,点击【了解更多】可详细了解大会员服务内容,详情请致电咨询:400-108-6670,线下购买享优惠。'
  272. },
  273. {
  274. text: '本次活动不支持作弊行为,涉嫌违法、违规参与活动的用户,剑鱼标讯将有权取消您的活动参与资格,并回收已获得的相关奖励,由于不可抗力因素等情况导致活动异常,剑鱼标讯将有权采取调整等措施。'
  275. },
  276. {
  277. text: '法律许可范围内本次活动解释权归北京剑鱼信息技术有限公司所有。'
  278. }
  279. ]
  280. },
  281. computed: {
  282. rate: function () {
  283. var calcRate = (this.progress.current / this.progress.max) * 100
  284. if (calcRate > 100) {
  285. calcRate = 100
  286. }
  287. if (calcRate < 0) {
  288. calcRate = 0
  289. }
  290. return calcRate
  291. },
  292. blinkTextShow: function () {
  293. var anchorList = this.progress.anchorList
  294. var rate = this.rate
  295. var exist = false
  296. for (var i = 0; i < anchorList.length; i++) {
  297. if (rate === anchorList[i].rate) {
  298. exist = true
  299. break
  300. }
  301. }
  302. return !exist
  303. },
  304. progressAnchorList: function () {
  305. return this.progress.anchorList
  306. },
  307. lastTimeText: function () {
  308. if (this.lastTimestamp > 0) {
  309. var lastTimeConf = this.calcLastTimeDiff(this.lastTimestamp)
  310. var days = lastTimeConf.days
  311. var hours = lastTimeConf.hours
  312. var minutes = lastTimeConf.minutes
  313. var seconds = lastTimeConf.seconds
  314. var hms = [this.add0(hours), this.add0(minutes), this.add0(seconds)].join(':')
  315. if (days > 0) {
  316. return days + '天 ' + hms
  317. } else {
  318. return hms
  319. }
  320. // return days + '天 ' + hms
  321. } else {
  322. return ''
  323. }
  324. },
  325. yureSectionShow: function () {
  326. return this.activeState === 'waiting' || this.activeState === 'yureing'
  327. },
  328. yureButtonShow: function () {
  329. var lastTimeConf = this.calcLastTimeDiff(this.lastTimestamp)
  330. var days = lastTimeConf.days
  331. if (this.yureInfo.buttonText) {
  332. return !(days < 1 && this.yureConf.total <= 0)
  333. } else {
  334. return false
  335. }
  336. }
  337. },
  338. created: function () {
  339. this.ajaxActiveStatus()
  340. this.ajaxProgress()
  341. this.ajaxList()
  342. },
  343. mounted: function () {
  344. // this.calcPointList()
  345. this.stickyTopEvents()
  346. },
  347. methods: {
  348. add0: function (t) {
  349. return t < 10 ? ('0' + t) : t
  350. },
  351. ajaxActiveStatus: function () {
  352. var _this = this
  353. $.ajax({
  354. url: '/jyActivity/membershipDay/period',
  355. type: 'post',
  356. success: function (res) {
  357. if (res.data) {
  358. for (var key in _this.conf) {
  359. _this.conf[key] = res.data[key]
  360. }
  361. if (Math.abs(initPageTime - res.data.now * 1000) > 5000) {
  362. initPageTime = res.data.now
  363. }
  364. activeOverCheck(res.data.end * 1000, function () {
  365. showDialogOfType('over')
  366. })
  367. _this.initPageState()
  368. }
  369. },
  370. complete: function () {
  371. _this.getYuReCouponCount()
  372. _this.getFuLi2CouponList()
  373. }
  374. })
  375. },
  376. initPageState: function () {
  377. var state = this.checkActiveState()
  378. var yureTextDOM = $('.timeline-item.yure .t-r-b-r')
  379. if (state === 'yureing') {
  380. this.startTopTimer()
  381. yureTextDOM.text('进行中')
  382. } else {
  383. yureTextDOM.text('已结束')
  384. if (state === 'activating') {
  385. // 活动进行中
  386. } else {
  387. }
  388. }
  389. },
  390. // 检查状态
  391. checkActiveState: function (now) {
  392. if (!now) {
  393. now = Date.now()
  394. }
  395. var before = this.conf.before * 1000
  396. var start = this.conf.start * 1000
  397. var end = this.conf.end * 1000
  398. var stateArr = ['waiting', 'yureing', 'activating', 'ended']
  399. var state = 'waiting'
  400. if (now < before) {
  401. state = stateArr[0] // 预热未开始
  402. } else if (before <= now && now < start) {
  403. state = stateArr[1] // 预热中
  404. } else if (start <= now && now < end) {
  405. state = stateArr[2] // 活动进行中
  406. } else {
  407. state = stateArr[3] // 活动已结束
  408. }
  409. this.activeState = state
  410. return state
  411. },
  412. // type=yure判断预热是否开始
  413. // type=active 判断活动是否开始
  414. activeNotStartToast: function (type) {
  415. var state = this.checkActiveState()
  416. type = type || 'active'
  417. if (state === 'ended') {
  418. toastFn('活动已结束')
  419. } else if (state === 'waiting') {
  420. toastFn('活动尚未开始,敬请期待')
  421. } else {
  422. if (type === 'yure') {
  423. if (state === 'activating') {
  424. // 预热已结束
  425. toastFn('预热已结束')
  426. }
  427. } else {
  428. if (state === 'yureing') {
  429. toastFn('活动尚未开始,敬请期待')
  430. }
  431. }
  432. }
  433. },
  434. startTopTimer: function () {
  435. var _this = this
  436. var start = this.conf.start * 1000
  437. var timerId = setInterval(function () {
  438. var current = Date.now()
  439. if (_this.lastTimestamp < 0) {
  440. clearInterval(timerId)
  441. }
  442. _this.lastTimestamp = start - current
  443. }, 1000)
  444. },
  445. calcYuReText: function () {
  446. var _this = this
  447. var buttonText = ''
  448. var tipText = ''
  449. var buttonDisabled = true
  450. if (this.yureInfo.timerId) {
  451. clearInterval(this.yureInfo.timerId)
  452. }
  453. if (this.activeState === 'yureing') {
  454. // 当天时间
  455. var todayString = new Date().pattern('yyyy/MM/dd')
  456. // 当领券开始时间
  457. var yureCouponStartTime = [todayString, this.conf.clock].join(' ')
  458. var yureCouponStartStamp = +new Date(yureCouponStartTime)
  459. // 计算倒计时
  460. var diff = yureCouponStartStamp - Date.now()
  461. if (diff > 0) {
  462. // 预热当天未开始抢券
  463. buttonDisabled = true
  464. buttonText = '今日10点开抢'
  465. // 创建定时器刷新倒计时
  466. this.yureInfo.timerId = setInterval(function () {
  467. var d = yureCouponStartStamp - Date.now()
  468. var obj = _this.calcLastTimeDiff(d)
  469. if (d <= 0) {
  470. clearInterval(_this.yureInfo.timerId)
  471. _this.calcYuReText()
  472. } else {
  473. // 计算倒计时
  474. tipText = [_this.add0(obj.hours), _this.add0(obj.minutes), _this.add0(obj.seconds)].join(':')
  475. _this.yureInfo.tipText = tipText
  476. }
  477. }, 1000)
  478. } else {
  479. if (this.yureConf.got) {
  480. // 已领取过
  481. buttonDisabled = false
  482. buttonText = '去查看'
  483. tipText = '已领取成功'
  484. } else {
  485. buttonDisabled = this.yureConf.total <= 0
  486. // 券是否有剩余
  487. if (this.yureConf.total > 0) {
  488. buttonText = '点击免费领'
  489. tipText = '今日还剩<span class="num">' + this.yureConf.total + '</span>份'
  490. } else {
  491. // 今日券领完了
  492. buttonText = '今天已抢完'
  493. tipText = '今天已经抢完啦~明天再来吧'
  494. }
  495. }
  496. }
  497. } else {
  498. // 预热未开始或者预热结束
  499. }
  500. this.yureInfo.buttonDisabled = buttonDisabled
  501. this.yureInfo.buttonText = buttonText
  502. this.yureInfo.tipText = tipText
  503. },
  504. calcLastTimeDiff: function (timestamp) {
  505. var diff = moment.duration(Math.abs(timestamp))
  506. var days = diff.days()
  507. var hours = diff.hours()
  508. var minutes = diff.minutes()
  509. var seconds = diff.seconds()
  510. return {
  511. days: days,
  512. hours: hours,
  513. minutes: minutes,
  514. seconds: seconds
  515. }
  516. },
  517. // 预热优惠券数量查询
  518. getYuReCouponCount: function () {
  519. var _this = this
  520. $.ajax({
  521. url: '/jyActivity/membershipDay/getDailyBoonDetail',
  522. type: 'post',
  523. success: function (res) {
  524. if (res.data) {
  525. _this.yureConf.got = res.data.got || false
  526. _this.yureConf.total = res.data.total || 0
  527. _this.calcYuReText()
  528. }
  529. }
  530. })
  531. },
  532. receiveYuReCoupon: function () {
  533. if (this.yureInfo.buttonDisabled) {
  534. toastFn('活动尚未开始,敬请期待')
  535. } else if (this.yureInfo.buttonText === '去查看') {
  536. // 领过了
  537. this.toBuyVip()
  538. } else {
  539. // 没领过
  540. this.receiveYuReCouponAjax()
  541. }
  542. },
  543. // 领取预热优惠券
  544. receiveYuReCouponAjax: function () {
  545. var _this = this
  546. $.ajax({
  547. url: '/jyActivity/membershipDay/getDailyBoonSVip',
  548. type: 'post',
  549. success: function (res) {
  550. if (res.data) {
  551. _this.getYuReCouponCount()
  552. // 刷新我的奖励列表
  553. _this.ajaxList()
  554. }
  555. }
  556. })
  557. },
  558. receiveActiveButtonText: function (item) {
  559. if (item.IsReceive) {
  560. return '立即领取'
  561. } else {
  562. if (item.IsUser) {
  563. return '去使用'
  564. } else {
  565. return '已使用'
  566. }
  567. }
  568. },
  569. receiveActiveCoupon: function (coupons) {
  570. if (this.activeState !== 'activating') {
  571. return this.activeNotStartToast()
  572. }
  573. if (coupons.length === 0) return
  574. if (coupons.length === 1) {
  575. var item = coupons[0]
  576. if (!item.IsReceive && item.IsUser) {
  577. return this.toBuyVip()
  578. }
  579. }
  580. var idArr = []
  581. coupons.forEach(function (item) {
  582. if (item.IsReceive) {
  583. idArr.push(item.LotteryIdStr)
  584. }
  585. })
  586. this.receiveActiveCouponAjax(idArr)
  587. },
  588. // 领取活动优惠券
  589. receiveActiveCouponAjax: function (ids) {
  590. if (ids.length === 0) return
  591. var _this = this
  592. $.ajax({
  593. url: '/jyActivity/membershipDay/getLottery',
  594. type: 'post',
  595. contentType: 'application/json',
  596. data: JSON.stringify({
  597. lotteryIds: ids.join(',')
  598. }),
  599. success: function (res) {
  600. if (res.data) {
  601. _this.couponList.forEach(function (item) {
  602. if (ids.indexOf(item.LotteryIdStr) !== -1) {
  603. item.IsReceive = false
  604. }
  605. })
  606. // 刷新我的奖励列表
  607. _this.ajaxList()
  608. }
  609. }
  610. })
  611. },
  612. addTipText: function (list) {
  613. var prefix = '超级订阅'
  614. var priceArr = [
  615. {
  616. price: 38,
  617. text: '1个月+1个省'
  618. },
  619. {
  620. price: 99,
  621. text: '1个季+1个省'
  622. },
  623. {
  624. price: 380,
  625. text: '1年+1个省'
  626. },
  627. {
  628. price: 599,
  629. text: '1个月+全国'
  630. },
  631. ]
  632. var arr = list.sort(function (a, b) {
  633. return a.Reduce - b.Reduce
  634. })
  635. list.forEach(function (item) {
  636. var reduce = item.Reduce
  637. var full = item.Full
  638. for (var i = 0; i < priceArr.length; i++) {
  639. if (priceArr[i].price - full >= 0) {
  640. var pay = priceArr[i].price - reduce
  641. item.tipText = prefix + priceArr[i].text + ':券后' + pay + '元'
  642. break
  643. }
  644. }
  645. })
  646. return arr
  647. },
  648. // 获取福利2优惠券列表
  649. getFuLi2CouponList: function () {
  650. var _this = this
  651. $.ajax({
  652. url: '/jyActivity/membershipDay/lotteryList',
  653. type: 'post',
  654. success: function (res) {
  655. if (res.data) {
  656. _this.couponList = _this.addTipText(res.data) || []
  657. // 刷新我的奖励列表
  658. _this.ajaxList()
  659. }
  660. }
  661. })
  662. },
  663. calcPointList: function () {
  664. var dom = this.$refs.missions
  665. window.points = new RandomCoordinate({
  666. el: dom,
  667. total: this.missionsList.length,
  668. pointSize: new Map(142, 160)
  669. })
  670. var pointList = points.pointCoordList
  671. for (var i = 0; i < this.missionsList.length; i++) {
  672. this.missionsList[i].x = pointList[i].x
  673. this.missionsList[i].y = pointList[i].y
  674. }
  675. },
  676. leaveCanvas: function (item) {
  677. var dom = $('.mission-list-item.' + item.id)
  678. dom.removeClass('floating')
  679. var baseX = 84
  680. var baseY = 34
  681. // 终点坐标
  682. var current = {
  683. x: baseX + 1000 * this.rate / 100,
  684. y: baseY + $('.mission-list').height() - $('.blink-point').height() / 2
  685. }
  686. item.x = current.x
  687. item.y = current.y
  688. this.$nextTick(function () {
  689. dom.addClass('exit')
  690. })
  691. },
  692. onClickListItem: function (item) {
  693. if (item.icon === 'jy-svip') {
  694. window.open('/front/swordfish/toMyOrder')
  695. } else if (item.icon === 'jy-coin') {
  696. window.open('/swordfish/integral/index/detail')
  697. } else {
  698. // 跳转我的奖券
  699. window.open('/swordfish/coupon/')
  700. // this.toBuyVip()
  701. }
  702. },
  703. onClickReceive: function (type, item) {
  704. if (this.activeState !== 'activating') return toastFn('活动尚未开始,敬请期待')
  705. if (item.className === 'received') return
  706. var status = false
  707. if (type === 'schedule') {
  708. if (item.className === 'wait') {
  709. status = true
  710. } else {
  711. var text = '尚未达到领取条件,无法领取'
  712. switch (item.id) {
  713. // 800
  714. case this.progressAnchorList[1].id: {
  715. text = '尚未达到'+ this.progressAnchorList[1].id +'剑鱼币,无法领取'
  716. break
  717. }
  718. // 1500
  719. case this.progressAnchorList[2].id: {
  720. text = '尚未达到'+ this.progressAnchorList[2].id +'剑鱼币,无法领取'
  721. break
  722. }
  723. }
  724. return toastFn(text, 1500)
  725. }
  726. } else if (type === 'mission' && item.complete) {
  727. status = true
  728. }
  729. if (!status) {
  730. var _this = this
  731. switch (item.id) {
  732. case 'buyvip': {
  733. this.toBuyVip()
  734. break
  735. }
  736. case 'invite': {
  737. window.open('/swordfish/frontPage/share/sess/index')
  738. break
  739. }
  740. case 'share': {
  741. // 分享
  742. _this.scrollTo('.copy-share-container')
  743. break
  744. }
  745. }
  746. return
  747. }
  748. var _this = this
  749. if (type === 'mission') {
  750. this.leaveCanvas(item)
  751. }
  752. this.ajaxReceive({ type: type, value: item.id }, function (result, msg) {
  753. if (result) {
  754. switch (item.id) {
  755. case 'buyvip':
  756. case 'invite':
  757. case 'share': {
  758. toastFn('已成功领取' + item.num + '剑鱼币', 1500)
  759. break
  760. }
  761. case '800': {
  762. $('.active-tip--success .text-give-day').text('7天')
  763. showDialogOfType('success')
  764. break
  765. }
  766. case '1500': {
  767. $('.active-tip--success .text-give-day').text('1个月')
  768. showDialogOfType('success')
  769. break
  770. }
  771. }
  772. _this.ajaxActiveStatus()
  773. _this.ajaxProgress()
  774. _this.ajaxList()
  775. } else {
  776. toastFn(msg, 1500)
  777. }
  778. })
  779. },
  780. ajaxReceive: function (data, callback) {
  781. var _this = this
  782. $.ajax({
  783. url: '/jyActivity/membershipDay/receive',
  784. type: 'post',
  785. contentType: 'application/json',
  786. data: JSON.stringify(data),
  787. success: function (res) {
  788. callback(res.data, res.error_msg)
  789. // 刷新我的奖励列表
  790. _this.ajaxList()
  791. }
  792. })
  793. },
  794. ajaxProgress: function () {
  795. var _this = this
  796. $.ajax({
  797. url: '/jyActivity/membershipDay/schedule',
  798. type: 'post',
  799. success: function (res) {
  800. if (res.error_code === 0 && res.data) {
  801. _this.progress.current = res.data.nowNum
  802. _this.missionsList[0].complete = res.data.missions.buyvip !== 0
  803. _this.missionsList[1].complete = res.data.missions.invite !== 0
  804. _this.missionsList[2].complete = res.data.missions.share !== 0
  805. _this.missionsList[0].hide = res.data.missions.buyvip === -1
  806. _this.missionsList[1].hide = res.data.missions.invite === -1
  807. _this.missionsList[2].hide = res.data.missions.share === -1
  808. var anchorStatus = {
  809. 1: 'wait',
  810. 0: 'unreceived',
  811. '-1': 'received',
  812. }
  813. var imgStatus = {
  814. 1: 'unreceived',
  815. 0: 'unreceived',
  816. '-1': 'received',
  817. }
  818. _this.progress.anchorList[1].className = anchorStatus[res.data.schedule['800']]
  819. _this.progress.anchorList[2].className = anchorStatus[res.data.schedule['1500']]
  820. _this.progress.anchorList[1].pointImg = imgStatus[res.data.schedule['800']]
  821. _this.progress.anchorList[2].pointImg = imgStatus[res.data.schedule['1500']]
  822. }
  823. }
  824. })
  825. },
  826. ajaxList: function () {
  827. var _this = this
  828. $.ajax({
  829. url: '/jyActivity/myAward/awardlist',
  830. type: 'post',
  831. contentType: 'application/json',
  832. data: JSON.stringify({
  833. code: 'membershipDay',
  834. pageSize: 10,
  835. pageNum: 0
  836. }),
  837. success: function (res) {
  838. if (res.error_code === 0 && res.data) {
  839. if (res.data.list && typeof res.data.list.map === 'function') {
  840. _this.rewardList = res.data.list.map(function (v) {
  841. var icon = ''
  842. if (v.award.indexOf('剑鱼币') > -1) {
  843. icon = 'jy-coin'
  844. } else if (v.award.indexOf('订阅') > -1) {
  845. icon = 'jy-svip'
  846. } else {
  847. icon = 'jy-coupon'
  848. }
  849. return {
  850. id: v._id,
  851. icon: icon,
  852. rewardText: v.award,
  853. receiveTime: new Date(v.date * 1000).pattern('yyyy-MM-dd HH:mm:ss'),
  854. receiveFrom: v.getway
  855. }
  856. })
  857. }
  858. }
  859. }
  860. })
  861. },
  862. receiveFuli3: function () {
  863. if (this.activeState !== 'activating') {
  864. return this.activeNotStartToast()
  865. }
  866. vm.isNeedSubmit('super_membership_day',function(){
  867. vm.showSuccess = true
  868. })
  869. },
  870. doCopy: function () {
  871. if (this.activeState === 'activating') {
  872. var _this = this
  873. $.ajax({
  874. url: '/jyActivity/membershipDay/doShare',
  875. type: 'post',
  876. success: function (res) {
  877. if (res.data) {
  878. _this.$toast('复制成功')
  879. _this.ajaxProgress()
  880. }
  881. }
  882. })
  883. } else {
  884. // toastFn('活动尚未开始,敬请期待')
  885. this.activeNotStartToast()
  886. }
  887. this.copyText('快来和我一起参与吧!剑鱼超级会员节,百万补贴限量抢,快速获取商机信息》\n' + this.copyLinkText)
  888. },
  889. copyText: function (text) {
  890. const input = document.createElement('textarea') // js创建一个input输入框
  891. input.value = text // 将需要复制的文本赋值到创建的input输入框中
  892. document.body.appendChild(input) // 将输入框暂时创建到实例里面
  893. input.select() // 选中输入框中的内容
  894. document.execCommand('copy') // 执行复制操作
  895. document.body.removeChild(input) // 最后删除实例中临时创建的input输入框,完成复制操作
  896. },
  897. scrollTo: function (className) {
  898. setTimeout(function () {
  899. var offsetTop = $(className)[0].offsetTop - 64 * 2
  900. $(window).scrollTop(offsetTop)
  901. }, 100)
  902. },
  903. stickyTopEvents: function () {
  904. var _this = this
  905. var fixedTop = $('.fixed-top.top-timeline')
  906. var showHide = function () {
  907. var scrollTop = $(window).scrollTop()
  908. if (scrollTop > 600) {
  909. fixedTop.show()
  910. } else {
  911. fixedTop.hide()
  912. }
  913. }
  914. showHide()
  915. $(window).on('scroll', function () {
  916. showHide()
  917. })
  918. fixedTop.on('click', '.timeline-item', function (e) {
  919. $(e.currentTarget).addClass('active').siblings().removeClass('active')
  920. var className = $(e.currentTarget).attr('data-s-class')
  921. _this.scrollTo('.' + className)
  922. })
  923. },
  924. toMemberPage: function () {
  925. window.open('/big/page/index')
  926. },
  927. toBuyVip: function () {
  928. if (window.vipStatus > 0) {
  929. window.open('/swordfish/page_big_pc/free/svip/buy?type=upgrade')
  930. } else {
  931. // 去购买
  932. window.open('/swordfish/page_big_pc/free/svip/buy?type=buy')
  933. }
  934. }
  935. }
  936. })