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

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