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.

536 lines
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. //参与拼团
  137. if (options && options.orderGroupId) {
  138. wx.redirectTo({
  139. url: `/pages/joinFrDpell/index?couponId=${options.couponId}&orderGroupId=${options.orderGroupId}&couponChannelId=${options.couponChannelId}&orderId=${options.orderId}&avatarUrl=${options.avatarUrl}&nickName=${options.nickName}`
  140. })
  141. }
  142. //来自大屏的跳转拼团券详情
  143. else if (options && options.couponChannelId && options.path == 'daping') {
  144. /**
  145. * 主要是为了拿couponId
  146. */
  147. Http.get({
  148. url: config.api.couponDetail,
  149. data: {
  150. couponChannelId: options.couponChannelId
  151. }
  152. }).then(res => {
  153. let data = res.data;
  154. wx.redirectTo({
  155. url: `/pages/spellGroup/mySpellGroup/index?couponChannelId=${options.couponChannelId}&couponId=${data.couponId}`
  156. })
  157. })
  158. } else if (options && options.couponChannelId && !options.spellGroup && app.globalData.type != 'sd') {
  159. // 转赠判断
  160. if (options.cuserId) {
  161. wx.redirectTo({
  162. 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}`,
  163. })
  164. } else {
  165. // 跳转普通券/消费卡/限时秒杀/砍价详情
  166. wx.redirectTo({
  167. url: `/pages/coupon/detail/index?couponChannelId=${options.couponChannelId}`,
  168. })
  169. }
  170. }
  171. // 拼团详情页(只有通过扫码进入才可能进入拼团详情页面,只有这一个入口)
  172. else if ((options && options.couponChannelId && app.globalData.type == 'sd') || (options && options.couponChannelId && options.spellGroup)) {
  173. wx.redirectTo({
  174. url: `/pages/spellGroup/mySpellGroup/index?couponChannelId=${options.couponChannelId}`,
  175. })
  176. }
  177. // 游戏页面
  178. else if (options && options.id && app.globalData.type == 'gm') {
  179. that.getGameOne(app.globalData.token, options.id)
  180. }
  181. // 报名活动页面
  182. else if (options && options.id && app.globalData.type == 'ra') {
  183. wx.redirectTo({
  184. url: `/pages/radetail/index?id=${options.id}`,
  185. })
  186. }
  187. //活动签到
  188. else if (options && options.id && app.globalData.type == 'si') {
  189. wx.redirectTo({
  190. url: `/pages/acSignIn/index?id=${options.id}`,
  191. })
  192. }
  193. // 宣传页详情
  194. else if (options && options.bt && options.id && app.globalData.type == 'bd') {
  195. if (options.bt == '2') {
  196. // 自由图文
  197. wx.redirectTo({
  198. url: `/pages/freeBannerDetail/index?id=${options.id}`,
  199. })
  200. } else {
  201. // 标准格式
  202. wx.redirectTo({
  203. url: `/pages/bannerdetail/index?id=${options.id}`,
  204. })
  205. }
  206. }
  207. // 专题
  208. else if (options && options.id && app.globalData.type == 'td') {
  209. wx.redirectTo({
  210. url: `/pages/topicDetail/index?id=${options.id}`
  211. });
  212. }
  213. // 门店详情
  214. else if (options && options.id && app.globalData.type == 'md') {
  215. wx.redirectTo({
  216. url: `/pages/index/searchbar/detail/index?id=${options.id}`
  217. });
  218. }
  219. // 参与砍价
  220. else if (options && options.orderId) {
  221. wx.redirectTo({
  222. url: `/pages/bargain/bargainDatail/bargainDatail?orderId=${options.orderId}&from=${"discount"}`,
  223. })
  224. }
  225. // 我的
  226. else if (app.globalData.type == 'uc') {
  227. wx.switchTab({
  228. url: '/index/user'
  229. });
  230. }
  231. // 积分
  232. else if (app.globalData.type == 'jf') {
  233. wx.redirectTo({
  234. url: '/pages/integralmall/index'
  235. });
  236. }
  237. // 首页
  238. else if (app.globalData.type == 'in') {
  239. wx.switchTab({
  240. url: '/index/index'
  241. });
  242. }
  243. // 停车
  244. else if (app.globalData.type == 'pc') {
  245. // 停车
  246. wx.switchTab({
  247. url: '/index/passCar'
  248. });
  249. }
  250. // 我的券包
  251. else if (app.globalData.type == 'mc') {
  252. // 我的券包
  253. wx.redirectTo({
  254. url: '/pages/couponorder/index/index'
  255. });
  256. }
  257. // 我的订单
  258. else if (app.globalData.type == 'mo') {
  259. // 我的订单
  260. wx.redirectTo({
  261. url: '/pages/order/index/index?id=all'
  262. });
  263. }
  264. // 我的卡包
  265. else if (app.globalData.type == 'ca') {
  266. // 我的卡包
  267. wx.redirectTo({
  268. url: '/pages/cardorder/index/index'
  269. });
  270. }
  271. // 特享礼遇
  272. else if (app.globalData.type == 'sc') {
  273. // 特享礼遇
  274. wx.redirectTo({
  275. url: '/pages/specialcourtesy/specialcourtesy'
  276. });
  277. }
  278. // 限时秒杀
  279. else if (app.globalData.type == 'rb') {
  280. // 限时秒杀
  281. wx.redirectTo({
  282. url: '/pages/rushToBuy/index'
  283. })
  284. }
  285. // 砍价专场
  286. else if (app.globalData.type == 'bl') {
  287. // 砍价专场
  288. wx.redirectTo({
  289. url: '/pages/bargain/bargain'
  290. })
  291. }
  292. // 我的砍价
  293. else if (app.globalData.type == 'mb') {
  294. // 我的砍价
  295. wx.redirectTo({
  296. url: '/pages/bargain/bargain?from=myhtml'
  297. })
  298. }
  299. // 拼团专场
  300. else if (app.globalData.type == 'sl') {
  301. // 拼团专场
  302. wx.redirectTo({
  303. url: '/pages/spellGroup/spellGroup'
  304. })
  305. }
  306. // 我的拼团
  307. else if (app.globalData.type == 'ms') {
  308. // 我的拼团
  309. wx.redirectTo({
  310. url: '/pages/spellGroup/spellGroup?from=myhtml'
  311. })
  312. }
  313. // 消费卡
  314. else if (app.globalData.type == 'dc') {
  315. // 消费卡
  316. wx.redirectTo({
  317. url: '/pages/discountCardList/discountCardList'
  318. })
  319. }
  320. // 门店
  321. else if (app.globalData.type == 'ml') {
  322. wx.switchTab({
  323. url: '/index/searchbar'
  324. })
  325. }
  326. // 兑换
  327. else if (app.globalData.type == 'ec') {
  328. wx.redirectTo({
  329. url: '/pages/exchange/exchange'
  330. })
  331. }
  332. // 通过分享进入的门店详情
  333. else if (options && options.id && options.frommd == 'md') {
  334. wx.redirectTo({
  335. url: `/pages/index/searchbar/detail/index?id=${options.id}`
  336. });
  337. } else {
  338. // 主页
  339. wx.switchTab({
  340. url: '/index/index'
  341. })
  342. }
  343. })
  344. .catch(err => {
  345. console.log(err)
  346. if (err.code == 11004) {
  347. // 用户昵称未授权
  348. if (options && options.orderGroupId) {
  349. wx.redirectTo({
  350. url: `/pages/getuserinfo/index?couponId=${options.couponId}&orderGroupId=${options.orderGroupId}&couponChannelId=${options.couponChannelId}&orderId=${options.orderId}&avatarUrl=${options.avatarUrl}&nickName=${options.nickName}`
  351. })
  352. }
  353. /**
  354. * spellGroup
  355. * 区分是通过拼团详情分享过来的还是从普通券分享过来的
  356. * 注意:拼团券和普通券是两个页面
  357. */
  358. if (options && options.couponChannelId && !options.cuserId && !options.spellGroup) {
  359. wx.redirectTo({
  360. url: `/pages/getuserinfo/index?couponChannelId=${options.couponChannelId}`
  361. })
  362. } else if (options && options.couponChannelId && !options.cuserId && options.spellGroup) {
  363. wx.redirectTo({
  364. url: `/pages/getuserinfo/index?couponChannelId=${options.couponChannelId}&spellGroup=${options.spellGroup}`
  365. })
  366. } else if (options && options.couponChannelId && options.cuserId) {
  367. /**
  368. * 转赠判断
  369. */
  370. wx.redirectTo({
  371. 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}`
  372. })
  373. } else if (options && options.orderId) {
  374. wx.redirectTo({
  375. url: `/pages/getuserinfo/index?orderId=${options.orderId}&from='${"discount"}`
  376. })
  377. }
  378. // 通过分享进入的门店详情
  379. else if (options && options.id && options.frommd == 'md') {
  380. wx.redirectTo({
  381. url: `/pages/getuserinfo/index?id=${options.id}&frommd=md`
  382. });
  383. }// 门店详情
  384. else if (options && options.id && app.globalData.type == 'md') {
  385. wx.redirectTo({
  386. url: `/pages/index/searchbar/detail/index?id=${options.id}`
  387. });
  388. } else if (app.globalData.type == 'uc') {
  389. wx.switchTab({
  390. url: '/index/user'
  391. });
  392. }
  393. // 积分
  394. else if (app.globalData.type == 'jf') {
  395. wx.redirectTo({
  396. url: '/pages/integralmall/index'
  397. });
  398. }
  399. // 首页
  400. else if (app.globalData.type == 'in') {
  401. wx.switchTab({
  402. url: '/index/index'
  403. });
  404. }
  405. // 停车
  406. else if (app.globalData.type == 'pc') {
  407. // 停车
  408. wx.switchTab({
  409. url: '/index/passCar'
  410. });
  411. }
  412. // 我的券包
  413. else if (app.globalData.type == 'mc') {
  414. // 我的券包
  415. wx.redirectTo({
  416. url: '/pages/couponorder/index/index'
  417. });
  418. }
  419. // 我的订单
  420. else if (app.globalData.type == 'mo') {
  421. // 我的订单
  422. wx.redirectTo({
  423. url: '/pages/order/index/index?id=all'
  424. });
  425. }
  426. // 我的卡包
  427. else if (app.globalData.type == 'ca') {
  428. // 我的卡包
  429. wx.redirectTo({
  430. url: '/pages/cardorder/index/index'
  431. });
  432. }
  433. // 特享礼遇
  434. else if (app.globalData.type == 'sc') {
  435. // 特享礼遇
  436. wx.redirectTo({
  437. url: '/pages/specialcourtesy/specialcourtesy'
  438. });
  439. }
  440. // 限时秒杀
  441. else if (app.globalData.type == 'rb') {
  442. // 限时秒杀
  443. wx.redirectTo({
  444. url: '/pages/rushToBuy/index'
  445. })
  446. }
  447. // 砍价专场
  448. else if (app.globalData.type == 'bl') {
  449. // 砍价专场
  450. wx.redirectTo({
  451. url: '/pages/bargain/bargain'
  452. })
  453. }
  454. // 我的砍价
  455. else if (app.globalData.type == 'mb') {
  456. // 我的砍价
  457. wx.redirectTo({
  458. url: '/pages/bargain/bargain?from=myhtml'
  459. })
  460. }
  461. // 拼团专场
  462. else if (app.globalData.type == 'sl') {
  463. // 拼团专场
  464. wx.redirectTo({
  465. url: '/pages/spellGroup/spellGroup'
  466. })
  467. }
  468. // 我的拼团
  469. else if (app.globalData.type == 'ms') {
  470. wx.redirectTo({
  471. url: '/pages/spellGroup/spellGroup?from=myhtml'
  472. })
  473. }
  474. // 消费卡
  475. else if (app.globalData.type == 'dc') {
  476. // 消费卡
  477. wx.redirectTo({
  478. url: '/pages/discountCardList/discountCardList'
  479. })
  480. }
  481. // 兑换
  482. else if (app.globalData.type == 'ec') {
  483. wx.redirectTo({
  484. url: '/pages/exchange/exchange'
  485. })
  486. }
  487. // 门店
  488. else if (app.globalData.type == 'ml') {
  489. wx.switchTab({
  490. url: '/index/searchbar'
  491. })
  492. } else {
  493. wx.switchTab({
  494. url: '/index/index',
  495. })
  496. }
  497. }
  498. })
  499. },
  500. getGameOne: function(token, id) {
  501. let _this = this;
  502. Http.get({
  503. url: config.api.getOneGame,
  504. data: {
  505. token: token,
  506. id: id
  507. }
  508. }).then(res => {
  509. wx.redirectTo({
  510. url: '/pages/game/index?url=' + res.data.url + "&id=" + res.data.id + "&gameId=" + res.data.gameId,
  511. })
  512. })
  513. .catch(err => {
  514. wx.showModal({
  515. title: '提示',
  516. content: err.message,
  517. showCancel: false,
  518. success: function(res) {
  519. // 如果游戏下架或者找不到,重启首页
  520. if (res.confirm) {
  521. wx.reLaunch({
  522. url: '/pages/index/index',
  523. })
  524. }
  525. }
  526. })
  527. this.alphaClick();
  528. })
  529. },
  530. })