C端小程序
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

556 行
18 KiB

  1. const extConfig = wx.getExtConfigSync ? wx.getExtConfigSync() : {}
  2. const Http = require("../../utils/HttpBasics");
  3. const imgurl = require("../../utils/imgurl");
  4. const config = require("../../config/config");
  5. let app = getApp();
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {},
  11. /**
  12. * 生命周期函数--监听页面加载
  13. */
  14. onLoad: function(options) {
  15. let that = this;
  16. console.log(options);
  17. wx.showToast({
  18. title: '加载中',
  19. icon: "loading",
  20. duration: 2000
  21. })
  22. /**
  23. * 根据接收到的参数的值,判断跳转到哪个页面
  24. */
  25. if (options && options.type) {
  26. app.globalData.type = options.type;
  27. }
  28. if (decodeURIComponent(options.scene) == "undefined") {
  29. that.setData({
  30. scene: 0
  31. })
  32. app.globalData.scene = 0;
  33. } else {
  34. that.setData({
  35. scene: decodeURIComponent(options.scene)
  36. });
  37. app.globalData.scene = decodeURIComponent(options.scene)
  38. that.setData({
  39. newArr: this.data.scene.split(':')
  40. })
  41. //// 大屏-二维码-start
  42. if (this.data.newArr[0] == 'JC') {
  43. // 跳转券详情
  44. options.couponChannelId = this.data.newArr[1];
  45. } else if (this.data.newArr[0] == 'JG') {
  46. // 跳转拼团详情
  47. options.couponChannelId = this.data.newArr[1];
  48. options.path = 'daping'
  49. } else if (this.data.newArr[0] == 't') {
  50. // 普通二维码
  51. options.type = this.data.newArr[1];
  52. app.globalData.type = options.type;
  53. if (options.type == 'cd') {
  54. options.couponChannelId = this.data.newArr[2];
  55. } else if (options.type == 'bd') {
  56. options.bt = this.data.newArr[2];
  57. options.id = this.data.newArr[3];
  58. } else if (options.type == 'gm') {
  59. options.id = this.data.newArr[2];
  60. } else if (options.type == 'sd') {
  61. options.couponChannelId = this.data.newArr[2];
  62. } else if (options.type == 'td') {
  63. // 专题活动页
  64. options.id = this.data.newArr[2];
  65. } else if (options.type == 'md') {
  66. // 门店详情
  67. options.id = this.data.newArr[2];
  68. } else if (options.type == 'ra') {
  69. //活动详情
  70. options.id = this.data.newArr[2];
  71. } else if (options.type == 'si') {
  72. //活动签到
  73. options.id = this.data.newArr[2];
  74. }
  75. }
  76. }
  77. wx.setStorageSync('options', JSON.stringify(options))
  78. wx.setStorageSync('imgurl', imgurl);
  79. if (app.globalData.token) {
  80. this.updateUserInfo();
  81. if (options.couponChannelId || options.orderId || options.id) {
  82. that.userStatus(options);
  83. } else {
  84. that.userStatus();
  85. }
  86. } else {
  87. // 由于 token 是网络请求,可能会在 Page.onLoad 之后才返回
  88. // 所以此处加入 callback 以防止这种情况
  89. app.tokenCallback = token => {
  90. this.updateUserInfo();
  91. if (options.couponChannelId || options.orderId || options.id) {
  92. that.userStatus(options);
  93. } else {
  94. that.userStatus();
  95. }
  96. }
  97. }
  98. },
  99. /**
  100. * 检查用户的状态
  101. */
  102. userStatus: function(options) {
  103. var that = this;
  104. if (options && (options.couponChannelId || options.orderId || options.id)) {
  105. that.checkuserstatus(options);
  106. } else {
  107. that.checkuserstatus();
  108. }
  109. },
  110. /**
  111. * 获取手机信息
  112. */
  113. updateUserInfo() {
  114. wx.getSystemInfo({
  115. success: function (res) {
  116. Http.post({
  117. url: config.api.updateUserInfo,
  118. data: {
  119. systemInfo: JSON.stringify(res)
  120. }
  121. }).then(res => {
  122. console.log(res)
  123. })
  124. }
  125. })
  126. },
  127. checkuserstatus(options) {
  128. let that = this;
  129. Http.get({
  130. url: config.api.checkUserStatus,
  131. data: {
  132. token: app.globalData.token
  133. }
  134. })
  135. .then(res => {
  136. // res = JSON.parse('{"code":11004,"message":"用户昵称未授权,请跳转到用户昵称授权页!","data":{}}')
  137. //参与拼团
  138. if (options && options.orderGroupId) {
  139. wx.redirectTo({
  140. url: `/pages/joinFrDpell/index?couponId=${options.couponId}&orderGroupId=${options.orderGroupId}&couponChannelId=${options.couponChannelId}&orderId=${options.orderId}&avatarUrl=${options.avatarUrl}&nickName=${options.nickName}`
  141. })
  142. }
  143. //来自大屏的跳转拼团券详情
  144. else if (options && options.couponChannelId && options.path == 'daping') {
  145. /**
  146. * 主要是为了拿couponId
  147. */
  148. Http.get({
  149. url: config.api.couponDetail,
  150. data: {
  151. couponChannelId: options.couponChannelId
  152. }
  153. }).then(res => {
  154. let data = res.data;
  155. wx.redirectTo({
  156. url: `/pages/spellGroup/mySpellGroup/index?couponChannelId=${options.couponChannelId}&couponId=${data.couponId}`
  157. })
  158. })
  159. } else if (options && options.couponChannelId && !options.spellGroup && app.globalData.type != 'sd') {
  160. console.log(3333333333333333)
  161. // 转赠判断
  162. if (options.cuserId) {
  163. wx.redirectTo({
  164. url: `/pages/coupon/detail/index?couponChannelId=${options.couponChannelId}&cuserId=${options.cuserId}&coverImg=${options.coverImg}&userName=${options.userName}&avatarUrl=${options.avatarUrl}&couponOrderId=${options.couponOrderId}&updateDate=${options.updateDate}`,
  165. })
  166. } else {
  167. // 跳转普通券/消费卡/限时秒杀/砍价详情
  168. wx.redirectTo({
  169. url: `/pages/coupon/detail/index?couponChannelId=${options.couponChannelId}`,
  170. })
  171. }
  172. }
  173. // 拼团详情页(只有通过扫码进入才可能进入拼团详情页面,只有这一个入口)
  174. else if ((options && options.couponChannelId && app.globalData.type == 'sd') || (options && options.couponChannelId && options.spellGroup)) {
  175. wx.redirectTo({
  176. url: `/pages/spellGroup/mySpellGroup/index?couponChannelId=${options.couponChannelId}`,
  177. })
  178. }
  179. // 游戏页面
  180. else if (options && options.id && app.globalData.type == 'gm') {
  181. that.getGameOne(app.globalData.token, options.id)
  182. }
  183. // 报名活动页面
  184. else if (options && options.id && app.globalData.type == 'ra') {
  185. wx.redirectTo({
  186. url: `/pages/radetail/index?id=${options.id}`,
  187. })
  188. }
  189. //活动签到
  190. else if (options && options.id && app.globalData.type == 'si') {
  191. wx.redirectTo({
  192. url: `/pages/acSignIn/index?id=${options.id}`,
  193. })
  194. }
  195. // 宣传页详情
  196. else if (options && options.bt && options.id && app.globalData.type == 'bd') {
  197. if (options.bt == '2') {
  198. // 自由图文
  199. wx.redirectTo({
  200. url: `/pages/freeBannerDetail/index?id=${options.id}`,
  201. })
  202. } else {
  203. // 标准格式
  204. wx.redirectTo({
  205. url: `/pages/bannerdetail/index?id=${options.id}`,
  206. })
  207. }
  208. }
  209. // 专题
  210. else if (options && options.id && app.globalData.type == 'td') {
  211. wx.redirectTo({
  212. url: `/pages/topicDetail/index?id=${options.id}`
  213. });
  214. }
  215. // 门店详情
  216. else if (options && options.id && app.globalData.type == 'md') {
  217. wx.redirectTo({
  218. url: `/pages/index/searchbar/detail/index?id=${options.id}`
  219. });
  220. }
  221. // 参与砍价
  222. else if (options && options.orderId) {
  223. wx.redirectTo({
  224. url: `/pages/bargain/bargainDatail/bargainDatail?orderId=${options.orderId}&from=${"discount"}`,
  225. })
  226. }
  227. // 我的
  228. else if (app.globalData.type == 'uc') {
  229. wx.switchTab({
  230. url: '/index/user'
  231. });
  232. }
  233. // 积分
  234. else if (app.globalData.type == 'jf') {
  235. wx.redirectTo({
  236. url: '/pages/integralmall/index'
  237. });
  238. }
  239. // 首页
  240. else if (app.globalData.type == 'in') {
  241. wx.switchTab({
  242. url: '/index/index'
  243. });
  244. }
  245. // 停车
  246. else if (app.globalData.type == 'pc') {
  247. // 停车
  248. wx.switchTab({
  249. url: '/index/passCar'
  250. });
  251. }
  252. // 我的券包
  253. else if (app.globalData.type == 'mc') {
  254. // 我的券包
  255. wx.redirectTo({
  256. url: '/pages/couponorder/index/index'
  257. });
  258. }
  259. // 我的订单
  260. else if (app.globalData.type == 'mo') {
  261. // 我的订单
  262. wx.redirectTo({
  263. url: '/pages/order/index/index?id=all'
  264. });
  265. }
  266. // 我的卡包
  267. else if (app.globalData.type == 'ca') {
  268. // 我的卡包
  269. wx.redirectTo({
  270. url: '/pages/cardorder/index/index'
  271. });
  272. }
  273. // 特享礼遇
  274. else if (app.globalData.type == 'sc') {
  275. // 特享礼遇
  276. wx.redirectTo({
  277. url: '/pages/specialcourtesy/specialcourtesy'
  278. });
  279. }
  280. // 限时秒杀
  281. else if (app.globalData.type == 'rb') {
  282. // 限时秒杀
  283. wx.redirectTo({
  284. url: '/pages/rushToBuy/index'
  285. })
  286. }
  287. // 砍价专场
  288. else if (app.globalData.type == 'bl') {
  289. // 砍价专场
  290. wx.redirectTo({
  291. url: '/pages/bargain/bargain'
  292. })
  293. }
  294. // 我的砍价
  295. else if (app.globalData.type == 'mb') {
  296. // 我的砍价
  297. wx.redirectTo({
  298. url: '/pages/bargain/bargain?from=myhtml'
  299. })
  300. }
  301. // 拼团专场
  302. else if (app.globalData.type == 'sl') {
  303. // 拼团专场
  304. wx.redirectTo({
  305. url: '/pages/spellGroup/spellGroup'
  306. })
  307. }
  308. // 我的拼团
  309. else if (app.globalData.type == 'ms') {
  310. // 我的拼团
  311. wx.redirectTo({
  312. url: '/pages/spellGroup/spellGroup?from=myhtml'
  313. })
  314. }
  315. // 消费卡
  316. else if (app.globalData.type == 'dc') {
  317. // 消费卡
  318. wx.redirectTo({
  319. url: '/pages/discountCardList/discountCardList'
  320. })
  321. }
  322. //直播
  323. else if (app.globalData.type == 'zb') {
  324. wx.redirectTo({
  325. url: `/pages2/live/livelist/index`
  326. });
  327. }
  328. //活动日历
  329. else if (app.globalData.type == 'arl') {
  330. wx.redirectTo({
  331. url: `/pages/dateLsit/dateLsit`
  332. });
  333. }
  334. //每日签到
  335. else if (app.globalData.type == 'qd') {
  336. wx.redirectTo({
  337. url: `/pages/activityCalendar/activityCalendar`
  338. });
  339. }
  340. // 门店
  341. else if (app.globalData.type == 'ml') {
  342. wx.switchTab({
  343. url: '/index/searchbar'
  344. })
  345. }
  346. // 兑换
  347. else if (app.globalData.type == 'ec') {
  348. wx.redirectTo({
  349. url: '/pages/exchange/exchange'
  350. })
  351. }
  352. // 通过分享进入的门店详情
  353. else if (options && options.id && options.frommd == 'md') {
  354. wx.redirectTo({
  355. url: `/pages/index/searchbar/detail/index?id=${options.id}`
  356. });
  357. } else {
  358. // 主页
  359. wx.switchTab({
  360. url: '/index/index'
  361. })
  362. }
  363. })
  364. .catch(err => {
  365. console.log(err)
  366. if (err.code == 11004) {
  367. // 用户昵称未授权
  368. if (options && options.orderGroupId) {
  369. wx.redirectTo({
  370. url: `/pages/getuserinfo/index?couponId=${options.couponId}&orderGroupId=${options.orderGroupId}&couponChannelId=${options.couponChannelId}&orderId=${options.orderId}&avatarUrl=${options.avatarUrl}&nickName=${options.nickName}`
  371. })
  372. }
  373. /**
  374. * spellGroup
  375. * 区分是通过拼团详情分享过来的还是从普通券分享过来的
  376. * 注意:拼团券和普通券是两个页面
  377. */
  378. if (options && options.couponChannelId && !options.cuserId && !options.spellGroup) {
  379. wx.redirectTo({
  380. url: `/pages/getuserinfo/index?couponChannelId=${options.couponChannelId}`
  381. })
  382. } else if (options && options.couponChannelId && !options.cuserId && options.spellGroup) {
  383. wx.redirectTo({
  384. url: `/pages/getuserinfo/index?couponChannelId=${options.couponChannelId}&spellGroup=${options.spellGroup}`
  385. })
  386. } else if (options && options.couponChannelId && options.cuserId) {
  387. /**
  388. * 转赠判断
  389. */
  390. wx.redirectTo({
  391. url: `/pages/getuserinfo/index?couponChannelId=${options.couponChannelId}&cuserId=${options.cuserId}&coverImg=${options.coverImg}&userName=${options.userName}&avatarUrl=${options.avatarUrl}&couponOrderId=${options.couponOrderId}&updateDate=${options.updateDate}`
  392. })
  393. } else if (options && options.orderId) {
  394. wx.redirectTo({
  395. url: `/pages/getuserinfo/index?orderId=${options.orderId}&from='${"discount"}`
  396. })
  397. }
  398. // 通过分享进入的门店详情
  399. else if (options && options.id && options.frommd == 'md') {
  400. wx.redirectTo({
  401. url: `/pages/getuserinfo/index?id=${options.id}&frommd=md`
  402. });
  403. }// 门店详情
  404. else if (options && options.id && app.globalData.type == 'md') {
  405. wx.redirectTo({
  406. url: `/pages/index/searchbar/detail/index?id=${options.id}`
  407. });
  408. } else if (app.globalData.type == 'uc') {
  409. wx.switchTab({
  410. url: '/index/user'
  411. });
  412. }
  413. // 积分
  414. else if (app.globalData.type == 'jf') {
  415. wx.redirectTo({
  416. url: '/pages/integralmall/index'
  417. });
  418. }
  419. // 首页
  420. else if (app.globalData.type == 'in') {
  421. wx.switchTab({
  422. url: '/index/index'
  423. });
  424. }
  425. // 停车
  426. else if (app.globalData.type == 'pc') {
  427. // 停车
  428. wx.switchTab({
  429. url: '/index/passCar'
  430. });
  431. }
  432. // 我的券包
  433. else if (app.globalData.type == 'mc') {
  434. // 我的券包
  435. wx.redirectTo({
  436. url: '/pages/couponorder/index/index'
  437. });
  438. }
  439. // 我的订单
  440. else if (app.globalData.type == 'mo') {
  441. // 我的订单
  442. wx.redirectTo({
  443. url: '/pages/order/index/index?id=all'
  444. });
  445. }
  446. // 我的卡包
  447. else if (app.globalData.type == 'ca') {
  448. // 我的卡包
  449. wx.redirectTo({
  450. url: '/pages/cardorder/index/index'
  451. });
  452. }
  453. // 特享礼遇
  454. else if (app.globalData.type == 'sc') {
  455. // 特享礼遇
  456. wx.redirectTo({
  457. url: '/pages/specialcourtesy/specialcourtesy'
  458. });
  459. }
  460. // 限时秒杀
  461. else if (app.globalData.type == 'rb') {
  462. // 限时秒杀
  463. wx.redirectTo({
  464. url: '/pages/rushToBuy/index'
  465. })
  466. }
  467. // 砍价专场
  468. else if (app.globalData.type == 'bl') {
  469. // 砍价专场
  470. wx.redirectTo({
  471. url: '/pages/bargain/bargain'
  472. })
  473. }
  474. // 我的砍价
  475. else if (app.globalData.type == 'mb') {
  476. // 我的砍价
  477. wx.redirectTo({
  478. url: '/pages/bargain/bargain?from=myhtml'
  479. })
  480. }
  481. // 拼团专场
  482. else if (app.globalData.type == 'sl') {
  483. // 拼团专场
  484. wx.redirectTo({
  485. url: '/pages/spellGroup/spellGroup'
  486. })
  487. }
  488. // 我的拼团
  489. else if (app.globalData.type == 'ms') {
  490. wx.redirectTo({
  491. url: '/pages/spellGroup/spellGroup?from=myhtml'
  492. })
  493. }
  494. // 消费卡
  495. else if (app.globalData.type == 'dc') {
  496. // 消费卡
  497. wx.redirectTo({
  498. url: '/pages/discountCardList/discountCardList'
  499. })
  500. }
  501. // 兑换
  502. else if (app.globalData.type == 'ec') {
  503. wx.redirectTo({
  504. url: '/pages/exchange/exchange'
  505. })
  506. }
  507. // 门店
  508. else if (app.globalData.type == 'ml') {
  509. wx.switchTab({
  510. url: '/index/searchbar'
  511. })
  512. } else {
  513. wx.switchTab({
  514. url: '/index/index',
  515. })
  516. }
  517. }
  518. })
  519. },
  520. getGameOne: function(token, id) {
  521. let _this = this;
  522. Http.get({
  523. url: config.api.getOneGame,
  524. data: {
  525. token: token,
  526. id: id
  527. }
  528. }).then(res => {
  529. wx.redirectTo({
  530. url: '/pages/game/index?url=' + res.data.url + "&id=" + res.data.id + "&gameId=" + res.data.gameId,
  531. })
  532. })
  533. .catch(err => {
  534. wx.showModal({
  535. title: '提示',
  536. content: err.message,
  537. showCancel: false,
  538. success: function(res) {
  539. // 如果游戏下架或者找不到,重启首页
  540. if (res.confirm) {
  541. wx.reLaunch({
  542. url: '/pages/index/index',
  543. })
  544. }
  545. }
  546. })
  547. this.alphaClick();
  548. })
  549. },
  550. })