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.

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