C端小程序
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

403 行
13 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. }
  69. }
  70. }
  71. wx.setStorageSync('options', JSON.stringify(options))
  72. wx.setStorageSync('imgurl', imgurl);
  73. if (app.globalData.token) {
  74. this.updateUserInfo();
  75. if (options.couponChannelId || options.orderId || options.id) {
  76. that.userStatus(options);
  77. } else {
  78. that.userStatus();
  79. }
  80. } else {
  81. // 由于 token 是网络请求,可能会在 Page.onLoad 之后才返回
  82. // 所以此处加入 callback 以防止这种情况
  83. app.tokenCallback = token => {
  84. this.updateUserInfo();
  85. if (options.couponChannelId || options.orderId || options.id) {
  86. that.userStatus(options);
  87. } else {
  88. that.userStatus();
  89. }
  90. }
  91. }
  92. },
  93. /**
  94. * 检查用户的状态
  95. */
  96. userStatus: function(options) {
  97. var that = this;
  98. if (options && (options.couponChannelId || options.orderId || options.id)) {
  99. that.checkuserstatus(options);
  100. } else {
  101. that.checkuserstatus();
  102. }
  103. },
  104. /**
  105. * 获取手机信息
  106. */
  107. updateUserInfo() {
  108. wx.getSystemInfo({
  109. success: function (res) {
  110. Http.post({
  111. url: config.api.updateUserInfo,
  112. data: {
  113. systemInfo: JSON.stringify(res)
  114. }
  115. }).then(res => {
  116. console.log(res)
  117. })
  118. }
  119. })
  120. },
  121. checkuserstatus(options) {
  122. let that = this;
  123. Http.get({
  124. url: config.api.checkUserStatus,
  125. data: {
  126. token:app.globalData.token
  127. }
  128. })
  129. .then(res => {
  130. //参与拼团
  131. if (options && options.orderGroupId) {
  132. wx.redirectTo({
  133. url: `/pages/joinFrDpell/index?couponId=${options.couponId}&orderGroupId=${options.orderGroupId}&couponChannelId=${options.couponChannelId}&orderId=${options.orderId}&avatarUrl=${options.avatarUrl}&nickName=${options.nickName}`
  134. })
  135. }
  136. //来自大屏的跳转拼团券详情
  137. else if (options && options.couponChannelId && options.path == 'daping') {
  138. /**
  139. * 主要是为了拿couponId
  140. */
  141. Http.get({
  142. url: config.api.couponDetail,
  143. data: {
  144. couponChannelId: options.couponChannelId
  145. }
  146. }).then(res => {
  147. let data = res.data;
  148. wx.redirectTo({
  149. url: `/pages/spellGroup/mySpellGroup/index?couponChannelId=${options.couponChannelId}&couponId=${data.couponId}`
  150. })
  151. })
  152. } else if (options && options.couponChannelId && !options.spellGroup && app.globalData.type != 'sd') {
  153. // 转赠判断
  154. if (options.cuserId) {
  155. wx.redirectTo({
  156. 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}`,
  157. })
  158. } else {
  159. // 跳转普通券/消费卡/限时秒杀/砍价详情
  160. wx.redirectTo({
  161. url: `/pages/coupon/detail/index?couponChannelId=${options.couponChannelId}`,
  162. })
  163. }
  164. }
  165. // 拼团详情页(只有通过扫码进入才可能进入拼团详情页面,只有这一个入口)
  166. else if (options && options.couponChannelId && app.globalData.type == 'sd' || options && options.couponChannelId && options.spellGroup) {
  167. wx.redirectTo({
  168. url: `/pages/spellGroup/mySpellGroup/index?couponChannelId=${options.couponChannelId}`,
  169. })
  170. }
  171. // 游戏页面
  172. else if (options && options.id && app.globalData.type == 'gm') {
  173. that.getGameOne(app.globalData.token, options.id)
  174. }
  175. // 宣传页详情
  176. else if (options && options.bt && options.id && app.globalData.type == 'bd') {
  177. if (options.bt == '2') {
  178. // 自由图文
  179. wx.redirectTo({
  180. url: `/pages/freeBannerDetail/index?id=${options.id}`,
  181. })
  182. } else {
  183. // 标准格式
  184. wx.redirectTo({
  185. url: `/pages/bannerdetail/index?id=${options.id}`,
  186. })
  187. }
  188. }
  189. // 专题
  190. else if (options && options.id && app.globalData.type == 'td') {
  191. wx.redirectTo({
  192. url: `/pages/topicDetail/index?id=${options.id}`
  193. });
  194. }
  195. // 门店详情
  196. else if (options && options.id && app.globalData.type == 'md') {
  197. wx.redirectTo({
  198. url: `/pages/index/searchbar/detail/index?id=${options.id}`
  199. });
  200. }
  201. // 参与砍价
  202. else if (options && options.orderId) {
  203. wx.redirectTo({
  204. url: `/pages/bargain/bargainDatail/bargainDatail?orderId=${options.orderId}&from=${"discount"}`,
  205. })
  206. }
  207. // 我的
  208. else if (app.globalData.type == 'uc') {
  209. wx.switchTab({
  210. url: '/pages/user/index'
  211. });
  212. }
  213. // 积分
  214. else if (app.globalData.type == 'jf') {
  215. wx.redirectTo({
  216. url: '/pages/integralmall/index'
  217. });
  218. }
  219. // 首页
  220. else if (app.globalData.type == 'in') {
  221. wx.switchTab({
  222. url: '/pages/main/index'
  223. });
  224. }
  225. // 停车
  226. else if (app.globalData.type == 'pc') {
  227. // 停车
  228. wx.switchTab({
  229. url: '/pages/passCar/passCar'
  230. });
  231. }
  232. // 我的券包
  233. else if (app.globalData.type == 'mc') {
  234. // 我的券包
  235. wx.redirectTo({
  236. url: '/pages/couponorder/index/index'
  237. });
  238. }
  239. // 我的订单
  240. else if (app.globalData.type == 'mo') {
  241. // 我的订单
  242. wx.redirectTo({
  243. url: '/pages/order/index/index?id=all'
  244. });
  245. }
  246. // 我的卡包
  247. else if (app.globalData.type == 'ca') {
  248. // 我的卡包
  249. wx.redirectTo({
  250. url: '/pages/cardorder/index/index'
  251. });
  252. }
  253. // 特享礼遇
  254. else if (app.globalData.type == 'sc') {
  255. // 特享礼遇
  256. wx.redirectTo({
  257. url: '/pages/specialcourtesy/specialcourtesy'
  258. });
  259. }
  260. // 限时秒杀
  261. else if (app.globalData.type == 'rb') {
  262. // 限时秒杀
  263. wx.redirectTo({
  264. url: '/pages/rushToBuy/index'
  265. })
  266. }
  267. // 砍价专场
  268. else if (app.globalData.type == 'bl') {
  269. // 砍价专场
  270. wx.redirectTo({
  271. url: '/pages/bargain/bargain'
  272. })
  273. }
  274. // 我的砍价
  275. else if (app.globalData.type == 'mb') {
  276. // 我的砍价
  277. wx.redirectTo({
  278. url: '/pages/bargain/bargain?from=myhtml'
  279. })
  280. }
  281. // 拼团专场
  282. else if (app.globalData.type == 'sl') {
  283. // 拼团专场
  284. wx.redirectTo({
  285. url: '/pages/spellGroup/spellGroup'
  286. })
  287. }
  288. // 我的拼团
  289. else if (app.globalData.type == 'ms') {
  290. // 我的拼团
  291. wx.redirectTo({
  292. url: '/pages/spellGroup/spellGroup?from=myhtml'
  293. })
  294. }
  295. // 消费卡
  296. else if (app.globalData.type == 'dc') {
  297. // 消费卡
  298. wx.redirectTo({
  299. url: '/pages/discountCardList/discountCardList'
  300. })
  301. }
  302. // 门店
  303. else if (app.globalData.type == 'ml') {
  304. wx.switchTab({
  305. url: '/pages/index/searchbar/index'
  306. })
  307. }
  308. // 通过分享进入的门店详情
  309. else if (options && options.id && options.frommd == 'md') {
  310. wx.redirectTo({
  311. url: `/pages/index/searchbar/detail/index?id=${options.id}`
  312. });
  313. }else {
  314. // 主页
  315. wx.switchTab({
  316. url: '/pages/main/index'
  317. })
  318. }
  319. })
  320. .catch(err => {
  321. console.log(err)
  322. if (err.code == 11004) {
  323. // 用户昵称未授权
  324. if (options && options.orderGroupId) {
  325. wx.redirectTo({
  326. url: `/pages/getuserinfo/index?couponId=${options.couponId}&orderGroupId=${options.orderGroupId}&couponChannelId=${options.couponChannelId}&orderId=${options.orderId}&avatarUrl=${options.avatarUrl}&nickName=${options.nickName}`
  327. })
  328. }
  329. /**
  330. * spellGroup
  331. * 区分是通过拼团详情分享过来的还是从普通券分享过来的
  332. * 注意:拼团券和普通券是两个页面
  333. */
  334. if (options && options.couponChannelId && !options.cuserId && !options.spellGroup) {
  335. wx.redirectTo({
  336. url: `/pages/getuserinfo/index?couponChannelId=${options.couponChannelId}`
  337. })
  338. } else if (options && options.couponChannelId && !options.cuserId && options.spellGroup) {
  339. wx.redirectTo({
  340. url: `/pages/getuserinfo/index?couponChannelId=${options.couponChannelId}&spellGroup=${options.spellGroup}`
  341. })
  342. } else if (options && options.couponChannelId && options.cuserId) {
  343. /**
  344. * 转赠判断
  345. */
  346. wx.redirectTo({
  347. 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}`
  348. })
  349. } else if (options && options.orderId) {
  350. wx.redirectTo({
  351. url: `/pages/getuserinfo/index?orderId=${options.orderId}&from='${"discount"}`
  352. })
  353. }
  354. // 通过分享进入的门店详情
  355. else if (options && options.id && options.frommd == 'md') {
  356. wx.redirectTo({
  357. url: `/pages/getuserinfo/index?id=${options.id}&frommd=md`
  358. });
  359. } else {
  360. wx.redirectTo({
  361. url: `/pages/getuserinfo/index`
  362. });
  363. }
  364. }
  365. });
  366. },
  367. getGameOne: function(token, id) {
  368. let _this = this;
  369. Http.get({
  370. url: config.api.getOneGame,
  371. data: {
  372. token: token,
  373. id: id
  374. }
  375. }).then(res => {
  376. wx.redirectTo({
  377. url: '/pages/game/index?url=' + res.data.url + "&id=" + res.data.id + "&gameId=" + res.data.gameId,
  378. })
  379. })
  380. .catch(err => {
  381. wx.showModal({
  382. title: '提示',
  383. content: err.message,
  384. showCancel: false,
  385. success: function(res) {
  386. // 如果游戏下架或者找不到,重启首页
  387. if (res.confirm) {
  388. wx.reLaunch({
  389. url: '/pages/index/index',
  390. })
  391. }
  392. }
  393. })
  394. this.alphaClick();
  395. })
  396. },
  397. })