C端小程序
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

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