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.

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