抖音小程序C端
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

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