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.

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