抖音小程序C端
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

569 linhas
18 KiB

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