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.

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