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

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