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

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