C端小程序
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

539 righe
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. 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 == 'ml') {
  324. wx.switchTab({
  325. url: '/index/searchbar'
  326. })
  327. }
  328. // 兑换
  329. else if (app.globalData.type == 'ec') {
  330. wx.redirectTo({
  331. url: '/pages/exchange/exchange'
  332. })
  333. }
  334. // 通过分享进入的门店详情
  335. else if (options && options.id && options.frommd == 'md') {
  336. wx.redirectTo({
  337. url: `/pages/index/searchbar/detail/index?id=${options.id}`
  338. });
  339. } else {
  340. // 主页
  341. wx.switchTab({
  342. url: '/index/index'
  343. })
  344. }
  345. })
  346. .catch(err => {
  347. console.log(err)
  348. if (err.code == 11004) {
  349. // 用户昵称未授权
  350. if (options && options.orderGroupId) {
  351. wx.redirectTo({
  352. url: `/pages/getuserinfo/index?couponId=${options.couponId}&orderGroupId=${options.orderGroupId}&couponChannelId=${options.couponChannelId}&orderId=${options.orderId}&avatarUrl=${options.avatarUrl}&nickName=${options.nickName}`
  353. })
  354. }
  355. /**
  356. * spellGroup
  357. * 区分是通过拼团详情分享过来的还是从普通券分享过来的
  358. * 注意:拼团券和普通券是两个页面
  359. */
  360. if (options && options.couponChannelId && !options.cuserId && !options.spellGroup) {
  361. wx.redirectTo({
  362. url: `/pages/getuserinfo/index?couponChannelId=${options.couponChannelId}`
  363. })
  364. } else if (options && options.couponChannelId && !options.cuserId && options.spellGroup) {
  365. wx.redirectTo({
  366. url: `/pages/getuserinfo/index?couponChannelId=${options.couponChannelId}&spellGroup=${options.spellGroup}`
  367. })
  368. } else if (options && options.couponChannelId && options.cuserId) {
  369. /**
  370. * 转赠判断
  371. */
  372. wx.redirectTo({
  373. 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}`
  374. })
  375. } else if (options && options.orderId) {
  376. wx.redirectTo({
  377. url: `/pages/getuserinfo/index?orderId=${options.orderId}&from='${"discount"}`
  378. })
  379. }
  380. // 通过分享进入的门店详情
  381. else if (options && options.id && options.frommd == 'md') {
  382. wx.redirectTo({
  383. url: `/pages/getuserinfo/index?id=${options.id}&frommd=md`
  384. });
  385. }// 门店详情
  386. else if (options && options.id && app.globalData.type == 'md') {
  387. wx.redirectTo({
  388. url: `/pages/index/searchbar/detail/index?id=${options.id}`
  389. });
  390. } else if (app.globalData.type == 'uc') {
  391. wx.switchTab({
  392. url: '/index/user'
  393. });
  394. }
  395. // 积分
  396. else if (app.globalData.type == 'jf') {
  397. wx.redirectTo({
  398. url: '/pages/integralmall/index'
  399. });
  400. }
  401. // 首页
  402. else if (app.globalData.type == 'in') {
  403. wx.switchTab({
  404. url: '/index/index'
  405. });
  406. }
  407. // 停车
  408. else if (app.globalData.type == 'pc') {
  409. // 停车
  410. wx.switchTab({
  411. url: '/index/passCar'
  412. });
  413. }
  414. // 我的券包
  415. else if (app.globalData.type == 'mc') {
  416. // 我的券包
  417. wx.redirectTo({
  418. url: '/pages/couponorder/index/index'
  419. });
  420. }
  421. // 我的订单
  422. else if (app.globalData.type == 'mo') {
  423. // 我的订单
  424. wx.redirectTo({
  425. url: '/pages/order/index/index?id=all'
  426. });
  427. }
  428. // 我的卡包
  429. else if (app.globalData.type == 'ca') {
  430. // 我的卡包
  431. wx.redirectTo({
  432. url: '/pages/cardorder/index/index'
  433. });
  434. }
  435. // 特享礼遇
  436. else if (app.globalData.type == 'sc') {
  437. // 特享礼遇
  438. wx.redirectTo({
  439. url: '/pages/specialcourtesy/specialcourtesy'
  440. });
  441. }
  442. // 限时秒杀
  443. else if (app.globalData.type == 'rb') {
  444. // 限时秒杀
  445. wx.redirectTo({
  446. url: '/pages/rushToBuy/index'
  447. })
  448. }
  449. // 砍价专场
  450. else if (app.globalData.type == 'bl') {
  451. // 砍价专场
  452. wx.redirectTo({
  453. url: '/pages/bargain/bargain'
  454. })
  455. }
  456. // 我的砍价
  457. else if (app.globalData.type == 'mb') {
  458. // 我的砍价
  459. wx.redirectTo({
  460. url: '/pages/bargain/bargain?from=myhtml'
  461. })
  462. }
  463. // 拼团专场
  464. else if (app.globalData.type == 'sl') {
  465. // 拼团专场
  466. wx.redirectTo({
  467. url: '/pages/spellGroup/spellGroup'
  468. })
  469. }
  470. // 我的拼团
  471. else if (app.globalData.type == 'ms') {
  472. wx.redirectTo({
  473. url: '/pages/spellGroup/spellGroup?from=myhtml'
  474. })
  475. }
  476. // 消费卡
  477. else if (app.globalData.type == 'dc') {
  478. // 消费卡
  479. wx.redirectTo({
  480. url: '/pages/discountCardList/discountCardList'
  481. })
  482. }
  483. // 兑换
  484. else if (app.globalData.type == 'ec') {
  485. wx.redirectTo({
  486. url: '/pages/exchange/exchange'
  487. })
  488. }
  489. // 门店
  490. else if (app.globalData.type == 'ml') {
  491. wx.switchTab({
  492. url: '/index/searchbar'
  493. })
  494. } else {
  495. wx.switchTab({
  496. url: '/index/index',
  497. })
  498. }
  499. }
  500. })
  501. },
  502. getGameOne: function(token, id) {
  503. let _this = this;
  504. Http.get({
  505. url: config.api.getOneGame,
  506. data: {
  507. token: token,
  508. id: id
  509. }
  510. }).then(res => {
  511. wx.redirectTo({
  512. url: '/pages/game/index?url=' + res.data.url + "&id=" + res.data.id + "&gameId=" + res.data.gameId,
  513. })
  514. })
  515. .catch(err => {
  516. wx.showModal({
  517. title: '提示',
  518. content: err.message,
  519. showCancel: false,
  520. success: function(res) {
  521. // 如果游戏下架或者找不到,重启首页
  522. if (res.confirm) {
  523. wx.reLaunch({
  524. url: '/pages/index/index',
  525. })
  526. }
  527. }
  528. })
  529. this.alphaClick();
  530. })
  531. },
  532. })