C端小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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