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.

404 lines
10 KiB

  1. const Http = require("../../utils/HttpBasics");
  2. const config = require("../../config/config");
  3. let app = getApp();
  4. Page({
  5. data: {
  6. market: app.globalData.market,
  7. list: [],
  8. loading: true,
  9. swiperCurrent: 0,
  10. title: null,
  11. desc: null,
  12. scrollTop: 0,
  13. showGame: false,
  14. gamedata: {},
  15. couponId: '',//游戏返回时传回的字段
  16. played: false,//从游戏页面跳回首页返回true
  17. havePlayEd: app.globalData.havePlayEd,
  18. staticGamedata: {},
  19. showIf: false,
  20. page: 1 // 刷新进入页面时已经加载了第一页数据,onReachBottom时 page++,从第2页开始加载
  21. },
  22. swiperChange: function (e) {
  23. this.setData({
  24. swiperCurrent: e.detail.current
  25. });
  26. },
  27. gotogame: function () {
  28. let that = this;
  29. Http.post({
  30. url: config.api.checkPhoneStatus,
  31. data: {}
  32. })
  33. .then(res => {
  34. var data = {
  35. couponChannelId: "" + that.data.couponChannelId,
  36. couponId: "" + that.data.couponId
  37. };
  38. if (that.data.couponChannelId == null) {
  39. var data = {
  40. couponId: "" + that.data.couponId
  41. };
  42. }
  43. wx.navigateTo({
  44. url: '/pages/game/index?url=' + that.data.staticGamedata.url + "&id=" + that.data.staticGamedata.id + "&gameId=" + that.data.staticGamedata.gameId,
  45. })
  46. })
  47. .catch(err => {
  48. if (err.code == 11005) {
  49. // 用户手机未授权
  50. /**
  51. * 将值传到用户手机号授权的页面
  52. *
  53. */
  54. wx.redirectTo({
  55. url: "/pages/getphoneInfo/index?path=index&url=" + that.data.staticGamedata.url + "&id=" + that.data.staticGamedata.id + "&gameId=" + that.data.staticGamedata.gameId,
  56. });
  57. } else if (err.code == 11006) {
  58. // 用户手机已加密
  59. wx.redirectTo({
  60. url: "/pages/phoneinput/phoneinput?path=index&url=" + that.data.staticGamedata.url + "&id=" + that.data.staticGamedata.id + "&gameId=" + that.data.staticGamedata.gameId,
  61. });
  62. } else {
  63. wx.showToast({
  64. title: err.message,
  65. icon: 'none',
  66. duration: 2000,
  67. mask: false
  68. });
  69. }
  70. })
  71. },
  72. /**
  73. * 生命周期函数--监听页面初次渲染完成
  74. */
  75. onLoad: function (options) {
  76. if (options.played == "true") {
  77. this.setData({
  78. played: true
  79. })
  80. }
  81. var that = this;
  82. if (decodeURIComponent(options.scene) == "undefined") {
  83. that.setData({
  84. scene: 0
  85. });
  86. } else {
  87. that.setData({
  88. scene: decodeURIComponent(options.scene)
  89. });
  90. }
  91. app.getLocation();
  92. if (options.couponChannelId && options.couponId) {
  93. that.userLogin(options.couponChannelId, options.couponId);
  94. } else {
  95. that.userLogin()
  96. }
  97. Http.get({
  98. url: config.api.getWeapNote,
  99. data: {
  100. appId: config.weapp.AppId,
  101. }
  102. })
  103. .then(res => {
  104. let weapNote = JSON.parse(res.data.weapNote);
  105. that.setData({
  106. desc: weapNote.firstpage.desc,
  107. title: weapNote.firstpage.title
  108. })
  109. })
  110. .catch(err => {
  111. wx.showModal({
  112. title: "提示",
  113. content:err.errMsg,
  114. showCancel:false
  115. });
  116. });
  117. },
  118. onShow: function () {
  119. this.setData({
  120. havePlayEd: app.globalData.havePlayEd ? app.globalData.havePlayEd : false
  121. })
  122. let num = wx.getStorageSync('couponNum');
  123. if (num == 'couponNum') {
  124. wx.showTabBarRedDot({
  125. index: 2
  126. })
  127. };
  128. },
  129. /**
  130. *
  131. * @param {code,page}
  132. * 子组件向父组件传值
  133. */
  134. onGetCode: function (e) {
  135. this.setData({
  136. code: e.detail.val,
  137. page: e.detail.pageNum,
  138. });
  139. console.log(e.detail.val)
  140. console.log(e.detail.pageNum)
  141. },
  142. /**
  143. * 用户登录
  144. */
  145. userLogin: function (couponChannelId, couponId) {
  146. var that = this;
  147. // 登录
  148. wx.login({
  149. success: ({
  150. code
  151. }) => {
  152. wx.getSystemInfo({
  153. success: function (res) {
  154. that.setData({
  155. systemInfo: JSON.stringify(res)
  156. })
  157. }
  158. })
  159. var usrdata = {
  160. appId: config.weapp.AppId,
  161. code: code,
  162. sceneAddress: app.globalData.sceneAddress,
  163. scene: that.data.scene,
  164. systemInfo: that.data.systemInfo
  165. };
  166. if (app.globalData.locationInfo) {
  167. usrdata = {
  168. appId: config.weapp.AppId,
  169. code: code,
  170. sceneAddress: app.globalData.sceneAddress,
  171. latitude: "" + app.globalData.locationInfo.latitude,
  172. longitude: "" + app.globalData.locationInfo.longitude,
  173. scene: that.data.scene,
  174. systemInfo: that.data.systemInfo
  175. };
  176. }
  177. Http.post({
  178. url: config.api.login,
  179. data: usrdata
  180. })
  181. .then(res => {
  182. app.globalData.token = res.data.token;
  183. if (res.data.token){
  184. that.getGameOne(res.data.token)
  185. that.getStaticGame(res.data.token)
  186. }
  187. Http.setToken(res.data.token);
  188. that.checkUserCarStatus();
  189. that.getUserInfo();
  190. that.getBannerlist();
  191. if (app.couponChannelListCallback) {
  192. app.couponChannelListCallback(app.globalData.token);
  193. }
  194. if (app.couponListCallback) {
  195. app.couponListCallback(app.globalData.token);
  196. }
  197. if (app.businessListCallback) {
  198. app.businessListCallback(app.globalData.token);
  199. }
  200. that.checkuerstatus(couponChannelId, couponId);
  201. })
  202. .catch(err => {
  203. });
  204. }
  205. });
  206. },
  207. checkuerstatus(couponChannelId, couponId) {
  208. Http.post({
  209. url: config.api.checkUserStatus,
  210. data: {}
  211. })
  212. .then(res => {
  213. if (couponChannelId && couponId) {
  214. wx.navigateTo({
  215. url: `/pages/coupon/detail/index?couponChannelId=${couponChannelId}&couponId=${couponId}`,
  216. })
  217. }
  218. })
  219. .catch(err => {
  220. if (err.code == 11004) {
  221. // 用户昵称未授权
  222. if (couponChannelId && couponId) {
  223. wx.redirectTo({
  224. url: `/pages/getuserinfo/index?couponChannelId=${couponChannelId}&couponId=${couponId}`
  225. });
  226. } else {
  227. wx.redirectTo({
  228. url: '/pages/getuserinfo/index'
  229. });
  230. }
  231. }
  232. });
  233. },
  234. getStaticGame(token) {
  235. let _this = this;
  236. Http.get({
  237. url: config.api.getGame,
  238. data: {
  239. triggleAction: 2,
  240. token: token
  241. }
  242. }).then(res => {
  243. if (res.data.id) {
  244. _this.setData({
  245. showIf:true
  246. })
  247. }
  248. _this.setData({
  249. staticGamedata: res.data
  250. })
  251. })
  252. .catch(err => {
  253. console.log(err)
  254. })
  255. },
  256. getGameOne: function (token) {
  257. let _this = this;
  258. Http.get({
  259. url: config.api.getGame,
  260. data:{
  261. triggleAction: 1,
  262. token: token
  263. }
  264. }).then(res => {
  265. if (res.data.id) {
  266. _this.setData({
  267. showGame: true
  268. })
  269. }
  270. _this.setData({
  271. gamedata: res.data
  272. })
  273. })
  274. .catch(err => {
  275. console.log(err)
  276. })
  277. },
  278. /**
  279. * banner
  280. */
  281. getBannerlist: function () {
  282. let that = this;
  283. Http.get({
  284. url: config.api.bannerlist,
  285. data: {
  286. pageNum: 1,
  287. pageSize: 7
  288. }
  289. }).then(res => {
  290. that.setData({
  291. list: res.data.list
  292. });
  293. });
  294. },
  295. /**
  296. * 检查用户是否有车
  297. */
  298. checkUserCarStatus: function () {
  299. var that = this;
  300. Http.get({
  301. url: config.api.userCarCount,
  302. data: {}
  303. }).then(res => {
  304. if (res.data > 0) {
  305. // 用户名下有车
  306. app.globalData.phone = res.data.phone;
  307. app.globalData.supportCar = true;
  308. // 共同登录
  309. that.userCarLogin();
  310. }
  311. });
  312. },
  313. /**
  314. * car共同登录
  315. */
  316. userCarLogin: function () {
  317. var that = this;
  318. if (!app.globalData.carLogin) {
  319. // 共同登录
  320. Http.post({
  321. url: config.api.carInit,
  322. data: {
  323. phone: app.globalData.phone
  324. }
  325. }).then(res => {
  326. app.globalData.carLogin = true;
  327. app.globalData.parkVendor = res.data.vendor;
  328. if (res.data.token != "undefined") {
  329. app.globalData.etcpToken = res.data.token;
  330. }
  331. });
  332. }
  333. },
  334. /**
  335. * 获取用户信息
  336. */
  337. getUserInfo: function () {
  338. // 获取用户信息
  339. wx.getSetting({
  340. success: res => {
  341. if (res.authSetting["scope.userInfo"]) {
  342. // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
  343. wx.getUserInfo({
  344. success: res => {
  345. // 可以将 res 发送给后台解码出 unionId
  346. }
  347. });
  348. }
  349. }
  350. });
  351. },
  352. /**
  353. * 刷新
  354. */
  355. onPullDownRefresh: function (e) {
  356. let that = this;
  357. that.userLogin();
  358. that.setData({
  359. page:1
  360. })
  361. if (that.data.code == 0 || that.data.code == undefined) {
  362. that.selectComponent("#lists").getList(0, 1, "refresh");
  363. wx.stopPullDownRefresh();
  364. } else {
  365. that.selectComponent("#lists").getList(that.data.code, 1, "refresh");
  366. wx.stopPullDownRefresh();
  367. };
  368. },
  369. //加载更多
  370. onReachBottom: function () {
  371. let that = this;
  372. that.data.page++;
  373. that.setData({
  374. page: that.data.page
  375. });
  376. console.log("加载更多页数"+that.data.page);
  377. console.log("加载更多key"+that.data.code);
  378. //父组件获得子组件的方法
  379. //如果code == 0
  380. if (that.data.code == 0 || that.data.code == undefined) {
  381. that.selectComponent("#lists").getList(0, that.data.page);
  382. } else {
  383. that.selectComponent("#lists").getList(that.data.code, that.data.page);
  384. }
  385. },
  386. // 用户点击右上角分享
  387. onShareAppMessage: function () {
  388. return {
  389. title: this.data.title,
  390. desc: this.data.desc,
  391. success: function (res) {
  392. wx.showToast({
  393. title: "分享成功",
  394. duration: 1000,
  395. icon: "success"
  396. });
  397. }
  398. };
  399. }
  400. });