C端小程序
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

430 satır
14 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. /**
  17. * 根据接收到的参数的值,判断跳转到哪个页面
  18. */
  19. if (options && options.type) {
  20. app.globalData.type = options.type;
  21. }
  22. if (decodeURIComponent(options.scene) == "undefined") {
  23. that.setData({
  24. scene: 0
  25. });
  26. } else {
  27. that.setData({
  28. scene: decodeURIComponent(options.scene)
  29. });
  30. that.setData({
  31. newArr: this.data.scene.split(':')
  32. })
  33. console.log(this.data.newArr)
  34. //// 大屏-二维码-start
  35. if (this.data.newArr[0] == 'JC') {
  36. // 跳转券详情
  37. options.couponChannelId = this.data.newArr[1];
  38. } else if (this.data.newArr[0] == 'JG') {
  39. // 跳转拼团详情
  40. options.couponChannelId = this.data.newArr[1];
  41. options.path = 'daping'
  42. }
  43. else if (this.data.newArr[0] == 't') {
  44. // 普通二维码
  45. options.type = this.data.newArr[1];
  46. app.globalData.type = options.type;
  47. if(options.type == 'cd') {
  48. options.couponChannelId = this.data.newArr[2];
  49. } else if (options.type == 'bd') {
  50. options.bt = this.data.newArr[2];
  51. options.id = this.data.newArr[3];
  52. } else if (options.type == 'gm') {
  53. options.id = this.data.newArr[2];
  54. } else if (options.type == 'sd') {
  55. options.couponChannelId = this.data.newArr[2];
  56. } else if (options.type == 'td') {
  57. // 专题活动页
  58. options.id = this.data.newArr[2];
  59. }
  60. }
  61. }
  62. wx.showToast({
  63. title: '加载中',
  64. icon: "loading",
  65. duration: 2000
  66. })
  67. wx.setStorageSync('options', JSON.stringify(options))
  68. wx.setStorageSync('imgurl', imgurl)
  69. app.getLocation();
  70. if (options.couponChannelId || options.orderId || options.id) {
  71. that.userLogin(options);
  72. }
  73. },
  74. onShow(){
  75. let that = this;
  76. that.userLogin();
  77. console.log("onshow-----------------------------------login")
  78. },
  79. checkuserstatus(options) {
  80. let that = this;
  81. Http.get({
  82. url: config.api.checkUserStatus,
  83. data: {}
  84. })
  85. .then(res => {
  86. //参与拼团
  87. if (options && options.orderGroupId) {
  88. wx.redirectTo({
  89. url: `/pages/joinFrDpell/index?couponId=${options.couponId}&orderGroupId=${options.orderGroupId}&couponChannelId=${options.couponChannelId}&orderId=${options.orderId}&avatarUrl=${options.avatarUrl}&nickName=${options.nickName}`
  90. })
  91. return;
  92. }
  93. //来自大屏的跳转拼团券详情
  94. else if (options && options.couponChannelId && options.path == 'daping') {
  95. /**
  96. * 主要是为了拿couponId
  97. */
  98. Http.get({
  99. url: config.api.couponDetail,
  100. data: {
  101. couponChannelId: options.couponChannelId
  102. }
  103. }).then(res => {
  104. let data = res.data;
  105. wx.redirectTo({
  106. url: `/pages/spellGroup/mySpellGroup/index?couponChannelId=${options.couponChannelId}&couponId=${data.couponId}`
  107. })
  108. });
  109. return;
  110. }
  111. else if (options && options.couponChannelId && !options.spellGroup) {
  112. // 转赠判断
  113. if (options.cuserId){
  114. wx.redirectTo({
  115. 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}`,
  116. })
  117. }else{
  118. // 跳转普通券/消费卡/限时秒杀/砍价详情
  119. wx.redirectTo({
  120. url: `/pages/coupon/detail/index?couponChannelId=${options.couponChannelId}`,
  121. })
  122. }
  123. }
  124. // 拼团详情页(只有通过扫码进入才可能进入拼团详情页面,只有这一个入口)
  125. else if (options && options.couponChannelId && app.globalData.type == 'sd' || options && options.couponChannelId && options.spellGroup) {
  126. wx.redirectTo({
  127. url: `/pages/spellGroup/mySpellGroup/index?couponChannelId=${options.couponChannelId}`,
  128. })
  129. }
  130. // 游戏页面
  131. else if (options && options.id && app.globalData.type == 'gm') {
  132. that.getGameOne(app.globalData.token, options.id)
  133. }
  134. // 宣传页详情
  135. else if (options && options.bt && options.id && app.globalData.type == 'bd') {
  136. if (options.bt == '2') {
  137. // 自由图文
  138. wx.redirectTo({
  139. url: `/pages/freeBannerDetail/index?id=${options.id}`,
  140. })
  141. } else {
  142. // 标准格式
  143. wx.redirectTo({
  144. url: `/pages/bannerdetail/index?id=${options.id}`,
  145. })
  146. }
  147. }
  148. // 专题
  149. else if (options && options.id && app.globalData.type == 'td'){
  150. wx.redirectTo({
  151. url: `/pages/topicDetail/index?id=${options.id}`
  152. });
  153. }
  154. // 参与砍价
  155. else if (options && options.orderId) {
  156. wx.redirectTo({
  157. url: `/pages/bargain/bargainDatail/bargainDatail?orderId=${options.orderId}&from=${"discount"}`,
  158. })
  159. }
  160. // 我的
  161. else if (app.globalData.type == 'uc') {
  162. wx.switchTab({
  163. url: '/pages/user/index'
  164. });
  165. }
  166. // 积分
  167. else if (app.globalData.type == 'jf') {
  168. wx.redirectTo({
  169. url: '/pages/integralmall/index'
  170. });
  171. }
  172. // 首页
  173. else if (app.globalData.type == 'in') {
  174. wx.switchTab({
  175. url: '/pages/main/index'
  176. });
  177. }
  178. // 停车
  179. else if (app.globalData.type == 'pc') {
  180. // 停车
  181. wx.switchTab({
  182. url: '/pages/passCar/passCar'
  183. });
  184. }
  185. // 我的券包
  186. else if (app.globalData.type == 'mc') {
  187. // 我的券包
  188. wx.redirectTo({
  189. url: '/pages/couponorder/index/index'
  190. });
  191. }
  192. // 我的订单
  193. else if (app.globalData.type == 'mo') {
  194. // 我的订单
  195. wx.redirectTo({
  196. url: '/pages/order/index/index?id=all'
  197. });
  198. }
  199. // 我的卡包
  200. else if (app.globalData.type == 'ca') {
  201. // 我的卡包
  202. wx.redirectTo({
  203. url: '/pages/cardorder/index/index'
  204. });
  205. }
  206. // 特享礼遇
  207. else if (app.globalData.type == 'sc') {
  208. // 特享礼遇
  209. wx.redirectTo({
  210. url: '/pages/specialcourtesy/specialcourtesy'
  211. });
  212. }
  213. // 限时秒杀
  214. else if (app.globalData.type == 'rb') {
  215. // 限时秒杀
  216. wx.redirectTo({
  217. url: '/pages/rushToBuy/index'
  218. });
  219. }
  220. // 砍价专场
  221. else if (app.globalData.type == 'bl') {
  222. // 砍价专场
  223. wx.redirectTo({
  224. url: '/pages/bargain/bargain'
  225. });
  226. }
  227. // 我的砍价
  228. else if (app.globalData.type == 'mb') {
  229. // 我的砍价
  230. wx.redirectTo({
  231. url: '/pages/bargain/bargain?from=myhtml'
  232. });
  233. }
  234. // 拼团专场
  235. else if (app.globalData.type == 'sl') {
  236. // 拼团专场
  237. wx.redirectTo({
  238. url: '/pages/spellGroup/spellGroup'
  239. });
  240. }
  241. // 我的拼团
  242. else if (app.globalData.type == 'ms') {
  243. // 我的拼团
  244. wx.redirectTo({
  245. url: '/pages/spellGroup/spellGroup?from=myhtml'
  246. });
  247. }
  248. // 消费卡
  249. else if (app.globalData.type == 'dc') {
  250. // 消费卡
  251. wx.redirectTo({
  252. url: '/pages/discountCardList/discountCardList'
  253. });
  254. }
  255. // 门店
  256. else if (app.globalData.type == 'ml') {
  257. // 门店
  258. wx.switchTab({
  259. url: '/pages/index/searchbar/index'
  260. });
  261. } else {
  262. // 主页
  263. wx.switchTab({
  264. url: '/pages/main/index'
  265. });
  266. }
  267. })
  268. .catch(err => {
  269. if (err.code == 11004) {
  270. // 用户昵称未授权
  271. if (options && options.orderGroupId) {
  272. wx.redirectTo({
  273. url: `/pages/getuserinfo/index?couponId=${options.couponId}&orderGroupId=${options.orderGroupId}&couponChannelId=${options.couponChannelId}&orderId=${options.orderId}&avatarUrl=${options.avatarUrl}&nickName=${options.nickName}`
  274. })
  275. return;
  276. }
  277. /**
  278. * spellGroup
  279. * 区分是通过拼团详情分享过来的还是从普通券分享过来的
  280. * 注意:拼团券和普通券是两个页面
  281. */
  282. if (options && options.couponChannelId && !options.cuserId && !options.spellGroup) {
  283. wx.redirectTo({
  284. url: `/pages/getuserinfo/index?couponChannelId=${options.couponChannelId}`
  285. });
  286. } else if (options && options.couponChannelId && !options.cuserId && options.spellGroup) {
  287. wx.redirectTo({
  288. url: `/pages/getuserinfo/index?couponChannelId=${options.couponChannelId}&spellGroup=${options.spellGroup}`
  289. });
  290. } else if (options && options.couponChannelId && options.cuserId) {
  291. /**
  292. * 转赠判断
  293. */
  294. wx.redirectTo({
  295. 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}`
  296. });
  297. } else if (options && options.orderId) {
  298. wx.redirectTo({
  299. url: `/pages/getuserinfo/index?orderId=${options.orderId}&from='${"discount"}`
  300. });
  301. } else {
  302. wx.redirectTo({
  303. url: `/pages/getuserinfo/index`
  304. });
  305. }
  306. }
  307. });
  308. },
  309. /**
  310. * 用户登录
  311. */
  312. userLogin: function (options) {
  313. var that = this;
  314. // 登录
  315. wx.login({
  316. success: ({
  317. code
  318. }) => {
  319. wx.getSystemInfo({
  320. success: function (res) {
  321. that.setData({
  322. systemInfo: JSON.stringify(res)
  323. })
  324. }
  325. })
  326. var usrdata = {
  327. appId: config.weapp.AppId,
  328. code: code,
  329. sceneAddress: app.globalData.sceneAddress,
  330. scene: that.data.scene,
  331. systemInfo: that.data.systemInfo
  332. };
  333. if (app.globalData.locationInfo) {
  334. usrdata = {
  335. appId: config.weapp.AppId,
  336. code: code,
  337. sceneAddress: app.globalData.sceneAddress,
  338. latitude: "" + app.globalData.locationInfo.latitude,
  339. longitude: "" + app.globalData.locationInfo.longitude,
  340. scene: that.data.scene,
  341. systemInfo: that.data.systemInfo
  342. };
  343. }
  344. Http.post({
  345. url: config.api.login,
  346. data: usrdata
  347. })
  348. .then(res => {
  349. that.setData({
  350. showPages: true
  351. })
  352. app.globalData.token = res.data.token;
  353. app.globalData.openId = res.data.openId;
  354. // 初始化websocket
  355. if (extConfig.attr.ifHaveWebSocket == 1) {
  356. app.initSocket();
  357. // 回调发送给自己的消息
  358. app.globalData.socketReceiver = function (e) {
  359. let msgList = that.data.msgList
  360. msgList.push(e)
  361. that.setData({
  362. msgList: msgList
  363. })
  364. }
  365. }
  366. if (res.data && res.data.score) {
  367. if (res.data.score != 0) {
  368. app.globalData.score = res.data.score;
  369. }
  370. }
  371. Http.setToken(res.data.token);
  372. if (options && (options.couponChannelId || options.orderId || options.id)) {
  373. that.checkuserstatus(options);
  374. } else {
  375. that.checkuserstatus();
  376. }
  377. })
  378. .catch(err => {
  379. wx.showModal({
  380. title: '提示',
  381. showCancel: false,
  382. content: '登录失败,请重新尝试',
  383. success: function (res) {
  384. if (res.cancel) {
  385. //点击取消,默认隐藏弹框
  386. } else {
  387. //点击确定
  388. wx.reLaunch({
  389. url: '/pages/index/index',
  390. })
  391. }
  392. }
  393. })
  394. });
  395. }
  396. });
  397. },
  398. getGameOne: function (token, id) {
  399. let _this = this;
  400. Http.get({
  401. url: config.api.getOneGame,
  402. data: {
  403. token: token,
  404. id: id
  405. }
  406. }).then(res => {
  407. wx.redirectTo({
  408. url: '/pages/game/index?url=' + res.data.url + "&id=" + res.data.id + "&gameId=" + res.data.gameId,
  409. })
  410. })
  411. .catch(err => {
  412. wx.showModal({
  413. title: '提示',
  414. content: err.message,
  415. showCancel: false,
  416. success:function(res){
  417. // 如果游戏下架或者找不到,重启首页
  418. if (res.confirm){
  419. wx.reLaunch({
  420. url: '/pages/index/index',
  421. })
  422. }
  423. }
  424. })
  425. this.alphaClick();
  426. })
  427. },
  428. })