抖音小程序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.

503 line
18 KiB

  1. const navigationBarHeight = (getApp().statusBarHeight + 50) + 'px'
  2. var config = require("../../config/config.js");
  3. var app = getApp();
  4. const Http = require("../../utils/HttpBasics");
  5. Page({
  6. data: {
  7. navigationBarHeight,
  8. path: null,
  9. couponChannelId: null,
  10. cuserId: null,
  11. coverImg: null,
  12. couponOrderId: null,
  13. optionData: null,
  14. fromflag: '',
  15. couponChannelIdflag: '',
  16. wjId: "",
  17. composeOrderType: "",
  18. fillIndentId: "",
  19. url: null,//游戏路径
  20. id: null,//游戏id,
  21. gameId: null,//游戏gameId
  22. },
  23. backHome() {
  24. tt.navigateBack({
  25. delta: 1,
  26. success: (res) => {
  27. },
  28. fail: (res) => {
  29. tt.reLaunch({
  30. url: "/index/index",
  31. success: (res) => {
  32. },
  33. fail: (res) => {
  34. },
  35. });
  36. },
  37. });
  38. // tt.reLaunch({
  39. // url: "/pages/index/index",
  40. // success: (res) => {
  41. // },
  42. // fail: (res) => {
  43. // },
  44. // });
  45. },
  46. //是否授权手机号
  47. judgePhonelngo() {
  48. Http.get({
  49. url: config.api.checkPhoneStatus,
  50. data: {}
  51. }).then(res => {
  52. var tempSkip = app.globalData.skip
  53. if (tempSkip == 'redirectTo') {
  54. tt.redirectTo({
  55. url: app.globalData.skipUrl,
  56. })
  57. } else if (tempSkip == 'navigateTo') {
  58. tt.navigateTo({
  59. url: app.globalData.skipUrl,
  60. })
  61. } else if (tempSkip == 'reLaunch') {
  62. tt.reLaunch({
  63. url: app.globalData.skipUrl,
  64. })
  65. } else if (tempSkip == 'switchTab') {
  66. tt.switchTab({
  67. url: app.globalData.skipUrl,
  68. })
  69. }
  70. }).catch(err => {
  71. if(app.globalData.ifCongPh==1){
  72. tt.redirectTo({
  73. url: `/pages/getPhone/getPhone?skipUrl=1`
  74. });
  75. }else{
  76. tt.navigateBack({
  77. delta: 1,
  78. })
  79. }
  80. })
  81. },
  82. onLoad: function (options) {
  83. console.log(app.globalData.skip, app.globalData.skipUrl, app.globalData.type, "跳转地址")
  84. var that = this;
  85. // options.fromflag == 'coupondetail';
  86. // 游戏页面
  87. if (options && options.url && options.id && options.gameId) {
  88. that.setData({
  89. url: options.url,//游戏路径
  90. id: options.id,//游戏id,
  91. gameId: options.gameId,//游戏gameId
  92. })
  93. }
  94. // 来自优惠券详情页面
  95. if (options && options.fromflag) {
  96. that.setData({
  97. fromflag: options.fromflag
  98. })
  99. }
  100. if (options && options.composeOrderType) {
  101. that.setData({
  102. composeOrderType: options.composeOrderType
  103. })
  104. }
  105. //线上配送 填写订单
  106. if (options && options.fillIndentId && couponId && options.couponId) {
  107. that.setData({
  108. fillIndentId: options.fillIndentId,
  109. couponId: options.couponId
  110. })
  111. }
  112. // 来自优惠券列表券详情页面的 couponChannelId
  113. if (options && options.couponChannelIdflag) {
  114. that.setData({
  115. couponChannelIdflag: options.couponChannelIdflag
  116. })
  117. }
  118. //调查问卷
  119. if (options && !options.wjId || options.wjId) {
  120. this.setData({
  121. wjId: options.wjId
  122. })
  123. }
  124. if (options && options.spellGroup) {
  125. that.setData({
  126. spellGroup: options.spellGroup
  127. })
  128. } else {
  129. that.setData({
  130. spellGroup: null
  131. })
  132. }
  133. if (options.couponChannelId && !options.cuserId || options.orderId) {
  134. that.setData({
  135. couponChannelId: options.couponChannelId,
  136. orderId: options.orderId
  137. })
  138. }
  139. if (options && options.frommd && options.id) {
  140. that.setData({
  141. id: options.id,
  142. frommd: options.frommd
  143. })
  144. }
  145. // that.setData({
  146. // optionData: null
  147. // })
  148. console.log(tt.getStorageSync('options'), 6666)
  149. that.setData({
  150. optionData: tt.getStorageSync('options') ? JSON.parse(tt.getStorageSync('options')) : null
  151. })
  152. if (options && options.path == 'index') {
  153. that.setData({
  154. path: options.path
  155. })
  156. }
  157. /**
  158. * 来自转赠
  159. */
  160. if (options.couponChannelId && options.cuserId) {
  161. that.setData({
  162. couponChannelId: options.couponChannelId,
  163. cuserId: options.cuserId,
  164. updateDate: options.updateDate,
  165. coverImg: options.coverImg,
  166. userName: options.userName,
  167. avatarUrl: options.avatarUrl,
  168. couponOrderId: options.couponOrderId
  169. })
  170. }
  171. Http.get({
  172. url: config.api.marketicon,
  173. data: {
  174. appId: app.globalData.appId
  175. }
  176. }).then(res => {
  177. that.setData({
  178. mallImgUrl: res.data.mallImgUrl
  179. });
  180. tt.setNavigationBarTitle({
  181. title: res.data.mallName
  182. })
  183. })
  184. .catch(err => {
  185. tt.showToast({
  186. title: err.errMsg,
  187. icon: 'none',
  188. duration: 2000,
  189. mask: false
  190. });
  191. })
  192. },
  193. onShow: function () {
  194. tt.checkSession({
  195. success() {
  196. //session_key 未过期,并且在本生命周期一直有效
  197. },
  198. fail() {
  199. console.log("session_key 过期")
  200. // session_key 已经失效,需要重新执行登录流程
  201. tt.login({
  202. success: (res) => {
  203. if (res.code) {
  204. let usrdata = {
  205. appId: app.globalData.appId,
  206. code: res.code,
  207. }
  208. Http.post({
  209. url: config.api.login,
  210. data: usrdata
  211. }).then(res => {
  212. Http.setToken(res.data.token);
  213. app.globalData.token = res.data.token;
  214. })
  215. }
  216. }
  217. })
  218. }
  219. })
  220. },
  221. bindGetUserInfo(e) {
  222. //session_key 未过期,并且在本生命周期一直有效
  223. tt.getUserProfile({
  224. title: '温馨提示',
  225. desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
  226. success: (res) => {
  227. let that = this;
  228. var iv = res.iv;
  229. var encryptedData = res.encryptedData;
  230. Http.post({
  231. url: config.api.getUserInfo,
  232. data: {
  233. encryptedData: encryptedData,
  234. iv: iv
  235. }
  236. }).then(res => {
  237. if (app.globalData.type == 'gm' && that.data.id && that.data.gameId && that.data.url) {//游戏页面
  238. app.globalData.skipUrl = '/pages/game/index?url=' + that.data.url + "&id=" + that.data.id + "&gameId=" + that.data.gameId,
  239. app.globalData.skip = 'redirectTo'
  240. that.judgePhonelngo()
  241. return;
  242. }
  243. if (that.data.wjId) {
  244. app.globalData.skipUrl = `/pages/questionnaire/questionnaire?id=${that.data.wjId}`
  245. app.globalData.skip = 'redirectTo'
  246. that.judgePhonelngo()
  247. return;
  248. }
  249. if (that.data.fromflag == 'poster') {
  250. app.globalData.skipUrl = `/pages/canvas/index?couponChannelId=${that.data.couponChannelId}`
  251. app.globalData.skip = 'redirectTo'
  252. that.judgePhonelngo()
  253. return;
  254. }
  255. //
  256. if (that.data.optionData != null && that.data.optionData.orderGroupId != null && that.data.optionData.orderGroupId != "") {
  257. app.globalData.skipUrl = `/pages/joinFrDpell/index?couponId=${that.data.optionData.couponId}&orderGroupId=${that.data.optionData.orderGroupId}&couponChannelId=${that.data.optionData.couponChannelId}&orderId=${that.data.optionData.orderId}&avatarUrl=${that.data.optionData.avatarUrl}&nickName=${that.data.optionData.nickName}`
  258. app.globalData.skip = 'reLaunch'
  259. that.judgePhonelngo()
  260. return;
  261. }
  262. if (that.data.path == 'index') {
  263. app.globalData.skipUrl = "/pages/game/index"
  264. app.globalData.skip = 'reLaunch'
  265. that.judgePhonelngo()
  266. } else {
  267. //返回主页
  268. // if (that.data.couponChannelId && !that.data.cuserId && !that.data.spellGroup||that.data.couponChannelId && !that.data.cuserId&&app.globalData.type == 'cd') {
  269. if (that.data.couponChannelId && !that.data.cuserId && !that.data.spellGroup && app.globalData.type == 'cd') {
  270. // 跳转普通券/消费卡/限时秒杀/砍价详情
  271. app.globalData.skipUrl = `/pages/coupon/detail/index?couponChannelId=${that.data.couponChannelId}`
  272. app.globalData.skip = 'navigateTo'
  273. that.judgePhonelngo()
  274. } else if (that.data.couponChannelId && that.data.cuserId && !that.data.spellGroup && app.globalData.type != 'sd') {
  275. // 来自转赠
  276. app.globalData.skipUrl = `/pages/coupon/detail/index?couponChannelId=${that.data.couponChannelId}&cuserId=${that.data.cuserId}&coverImg=${that.data.coverImg}&userName=${that.data.userName}&avatarUrl=${that.data.avatarUrl}&couponOrderId=${that.data.couponOrderId}&updateDate=${that.data.updateDate}`
  277. app.globalData.skip = 'reLaunch'
  278. that.judgePhonelngo()
  279. } else if (that.data.couponChannelId && app.globalData.type == 'sd' || that.data.couponChannelId && that.data.spellGroup) {
  280. // 拼团详情页
  281. app.globalData.skipUrl = `/pages/spellGroup/mySpellGroup/index?couponChannelId=${that.data.couponChannelId}`
  282. app.globalData.skip = 'redirectTo'
  283. that.judgePhonelngo()
  284. } else if (that.data.optionData != null && that.data.optionData.id && app.globalData.type == 'gm') {
  285. // 游戏页面
  286. that.getGameOne(app.globalData.token, that.data.optionData.id)
  287. } else if (that.data.optionData != null && that.data.optionData.id && app.globalData.type == 'td') {
  288. app.globalData.skipUrl = `/pages/topicDetail/index?id=${that.data.optionData.id}`
  289. app.globalData.skip = 'redirectTo'
  290. that.judgePhonelngo()
  291. }
  292. // 报名活动
  293. else if (that.data.optionData != null && that.data.optionData.id && app.globalData.type == 'ra') {
  294. app.globalData.skipUrl = `/pages/radetail/index?id=${that.data.optionData.id}`,
  295. app.globalData.skip = 'redirectTo'
  296. that.judgePhonelngo()
  297. }
  298. // 报名签到
  299. else if (that.data.optionData != null && that.data.optionData.id && app.globalData.type == 'si') {
  300. app.globalData.skipUrl = `/pages/acSignIn/index?id=${that.data.optionData.id}`,
  301. app.globalData.skip = 'redirectTo'
  302. that.judgePhonelngo()
  303. }
  304. // 门店详情
  305. else if (that.data.optionData != null && that.data.optionData.id && app.globalData.type == 'md') {
  306. app.globalData.skipUrl = `/pages/index/searchbar/detail/index?id=${that.data.optionData.id}`,
  307. app.globalData.skip = 'redirectTo'
  308. that.judgePhonelngo()
  309. }
  310. // 通过分享进入的门店详情页面
  311. else if (that.data.id && that.data.frommd == 'md') {
  312. app.globalData.skipUrl = `/pages/index/searchbar/detail/index?id=${that.data.id}`,
  313. app.globalData.skip = 'redirectTo'
  314. that.judgePhonelngo()
  315. } else if (that.data.optionData != null && that.data.optionData.bt && that.data.optionData.id && app.globalData.type == 'bd') {
  316. // 宣传页详情
  317. if (that.data.optionData != null && that.data.optionData.bt == '2') {
  318. // 自由图文
  319. app.globalData.skipUrl = `/pages/freeBannerDetail/index?id=${that.data.optionData.id}`,
  320. app.globalData.skip = 'redirectTo'
  321. that.judgePhonelngo()
  322. } else {
  323. // 标准格式
  324. app.globalData.skipUrl = `/pages/bannerdetail/index?id=${that.data.optionData.id}`,
  325. app.globalData.skip = 'redirectTo'
  326. that.judgePhonelngo()
  327. }
  328. } else if (that.data.orderId || that.data.orderId && app.globalData.type == 'bg') {
  329. // 参与砍价
  330. app.globalData.skipUrl = `/pages/bargain/bargainDatail/bargainDatail?orderId=${that.data.orderId}&composeOrderType=${that.composeOrderType}`,
  331. app.globalData.skip = 'navigateTo'
  332. that.judgePhonelngo()
  333. } else if (app.globalData.type == 'uc') {
  334. // 我的
  335. app.globalData.skipUrl = '/index/user',
  336. app.globalData.skip = 'redirectTo'
  337. that.judgePhonelngo()
  338. } else if (app.globalData.type == 'in') {
  339. // 首页
  340. app.globalData.skipUrl = app.globalData.goHomeUrl,
  341. app.globalData.skip = 'redirectTo'
  342. that.judgePhonelngo()
  343. } else if (app.globalData.type == "qd") {
  344. //每日签到
  345. app.globalData.skipUrl = "/pages/activityCalendar/activityCalendar"
  346. app.globalData.skip = 'reLaunch'
  347. that.judgePhonelngo()
  348. } else if (app.globalData.type == "hdrl") {
  349. //活动日历
  350. app.globalData.skipUrl = `/pages/radetail/index?id=${app.globalData.activityId}`
  351. app.globalData.skip = 'redirectTo'
  352. that.judgePhonelngo()
  353. }
  354. // 积分
  355. else if (app.globalData.type == 'jf') {
  356. app.globalData.skipUrl = '/pages/integralmall/index',
  357. app.globalData.skip = 'redirectTo'
  358. that.judgePhonelngo()
  359. } else if (app.globalData.type == 'pc') {
  360. // 停车
  361. app.globalData.skipUrl = '/index/passCar',
  362. app.globalData.skip = 'redirectTo'
  363. that.judgePhonelngo()
  364. } else if (app.globalData.type == 'mc') {
  365. // 我的券包
  366. app.globalData.skipUrl = '/pages/couponorder/index/index',
  367. app.globalData.skip = 'redirectTo'
  368. that.judgePhonelngo()
  369. } else if (app.globalData.type == 'mo') {
  370. // 我的订单
  371. app.globalData.skipUrl = '/pages/order/index/index?id=all',
  372. app.globalData.skip = 'redirectTo'
  373. that.judgePhonelngo()
  374. } else if (app.globalData.type == 'ca') {
  375. // 我的卡包
  376. app.globalData.skipUrl = '/pages/cardorder/index/index',
  377. app.globalData.skip = 'redirectTo'
  378. that.judgePhonelngo()
  379. } else if (app.globalData.type == 'sc') {
  380. // 特享礼遇
  381. app.globalData.skipUrl = '/pages/specialcourtesy/specialcourtesy',
  382. app.globalData.skip = 'redirectTo'
  383. that.judgePhonelngo()
  384. } else if (app.globalData.type == 'rb') {
  385. // 限时秒杀
  386. app.globalData.skipUrl = '/pages/rushToBuy/index',
  387. app.globalData.skip = 'redirectTo'
  388. that.judgePhonelngo()
  389. } else if (app.globalData.type == 'bl') {
  390. // 砍价专场
  391. app.globalData.skipUrl = '/pages/bargain/bargain',
  392. app.globalData.skip = 'redirectTo'
  393. that.judgePhonelngo()
  394. } else if (app.globalData.type == 'mb') {
  395. // 我的砍价
  396. app.globalData.skipUrl = '/pages/bargain/bargain?from=myhtml',
  397. app.globalData.skip = 'redirectTo'
  398. that.judgePhonelngo()
  399. } else if (app.globalData.type == 'sl') {
  400. // 拼团专场
  401. app.globalData.skipUrl = '/pages/spellGroup/spellGroup',
  402. app.globalData.skip = 'redirectTo'
  403. that.judgePhonelngo()
  404. } else if (app.globalData.type == 'ms') {
  405. // 我的拼团
  406. app.globalData.skipUrl = '/pages/spellGroup/spellGroup?from=myhtml',
  407. app.globalData.skip = 'redirectTo'
  408. that.judgePhonelngo()
  409. } else if (app.globalData.type == 'dc') {
  410. // 消费卡
  411. app.globalData.skipUrl = '/pages/discountCardList/discountCardList',
  412. app.globalData.skip = 'redirectTo'
  413. that.judgePhonelngo()
  414. } else if (app.globalData.type == 'td') {
  415. // 专题活动页
  416. app.globalData.skipUrl = '/pages/topicDetail/index',
  417. app.globalData.skip = 'redirectTo'
  418. that.judgePhonelngo()
  419. } else if (app.globalData.type == 'ml') {
  420. // 门店
  421. app.globalData.skipUrl = '/index/searchbar',
  422. app.globalData.skip = 'redirectTo'
  423. that.judgePhonelngo()
  424. } else if (that.data.fromflag == 'coupondetail' && that.data.couponChannelIdflag) {
  425. app.globalData.skipUrl = `/pages/coupon/detail/index?couponChannelId=${that.data.couponChannelIdflag}`,
  426. app.globalData.skip = 'redirectTo'
  427. that.judgePhonelngo()
  428. } else if (that.data.fromflag == 'spellcoupondetail' && that.data.couponChannelIdflag) {
  429. app.globalData.skipUrl = `/pages/spellGroup/mySpellGroup/index?couponChannelId=${that.data.couponChannelIdflag}`,
  430. app.globalData.skip = 'redirectTo'
  431. that.judgePhonelngo()
  432. } else if (that.data.fromflag == 'fillIndent' && that.data.fillIndentId && that.data.couponId) {
  433. //线上配送 填写订单
  434. app.globalData.skipUrl = `/pages/fillIndent/fillIndent?id=${that.data.fillIndentId}&couponId=${that.data.couponId}`,
  435. app.globalData.skip = 'redirectTo'
  436. that.judgePhonelngo()
  437. } else {
  438. app.globalData.skipUrl = app.globalData.goHomeUrl,
  439. app.globalData.skip = 'redirectTo'
  440. that.judgePhonelngo()
  441. }
  442. }
  443. })
  444. .catch(err => {
  445. tt.showToast({
  446. title: err.code,
  447. icon: 'none',
  448. duration: 2000,
  449. mask: false
  450. });
  451. })
  452. },
  453. fail: (err => {
  454. console.log(err)
  455. })
  456. })
  457. },
  458. getGameOne: function (token, id) {
  459. let _this = this;
  460. Http.get({
  461. url: config.api.getOneGame,
  462. data: {
  463. token: token,
  464. id: id
  465. }
  466. }).then(res => {
  467. tt.redirectTo({
  468. url: '/pages/game/index?url=' + res.data.url + "&id=" + res.data.id + "&gameId=" + res.data.gameId,
  469. })
  470. })
  471. .catch(err => {
  472. tt.showModal({
  473. title: '提示',
  474. content: err.message,
  475. showCancel: false,
  476. success: function (res) {
  477. // 如果游戏下架或者找不到,重启首页
  478. if (res.confirm) {
  479. tt.reLaunch({
  480. url: '/pages/index/index',
  481. })
  482. }
  483. }
  484. })
  485. this.alphaClick();
  486. })
  487. },
  488. });