C端小程序
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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