C端小程序
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

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