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:'',
  11. desc:'',
  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.errMsg,
  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. console.log(err);
  112. if (err.errMsg == '请求超时,请检查您的网络设置!') {
  113. that.setData({
  114. loading: false,
  115. loadingtext: "请求超时,请检查您的网络设置!"
  116. })
  117. }
  118. wx.showToast({
  119. title: err.errMsg,
  120. icon: 'none',
  121. duration: 2000,
  122. mask: false
  123. });
  124. });
  125. },
  126. onShow:function(){
  127. this.setData({
  128. havePlayEd: app.globalData.havePlayEd ? app.globalData.havePlayEd:false
  129. })
  130. let num = wx.getStorageSync('couponNum');
  131. if (num =='couponNum'){
  132. wx.showTabBarRedDot({
  133. index: 2
  134. })
  135. };
  136. },
  137. /**
  138. * 下拉刷新
  139. */
  140. onPullDownRefresh: function(e) {
  141. let that = this;
  142. that.userLogin();
  143. if (that.data.code == 0 || that.data.code == undefined) {
  144. that.selectComponent("#lists").getList(0, 1);
  145. wx.stopPullDownRefresh();
  146. } else {
  147. that.selectComponent("#lists").getList(that.data.code, 1);
  148. wx.stopPullDownRefresh();
  149. };
  150. },
  151. onGetCode: function(e) {
  152. //子组件传递给父组件的值
  153. this.setData({
  154. code: e.detail.val,
  155. page: e.detail.pageNum
  156. });
  157. },
  158. /**
  159. * 用户登录
  160. */
  161. userLogin: function (couponChannelId,couponId) {
  162. var that = this;
  163. // 登录
  164. wx.login({
  165. success: ({
  166. code
  167. }) => {
  168. wx.getSystemInfo({
  169. success: function (res) {
  170. that.setData({
  171. systemInfo: JSON.stringify(res)
  172. })
  173. }
  174. })
  175. var usrdata = {
  176. appId: config.weapp.AppId,
  177. code: code,
  178. sceneAddress: app.globalData.sceneAddress,
  179. scene: that.data.scene,
  180. systemInfo: that.data.systemInfo
  181. };
  182. if (app.globalData.locationInfo) {
  183. usrdata = {
  184. appId: config.weapp.AppId,
  185. code: code,
  186. sceneAddress: app.globalData.sceneAddress,
  187. latitude: "" + app.globalData.locationInfo.latitude,
  188. longitude: "" + app.globalData.locationInfo.longitude,
  189. scene: that.data.scene,
  190. systemInfo: that.data.systemInfo
  191. };
  192. }
  193. Http.post({
  194. url: config.api.login,
  195. data: usrdata
  196. })
  197. .then(res => {
  198. app.globalData.token = res.data.token;
  199. if (res.data.token){
  200. that.getGameOne(res.data.token)
  201. that.getStaticGame(res.data.token)
  202. }
  203. Http.setToken(res.data.token);
  204. that.checkUserCarStatus();
  205. that.getUserInfo();
  206. that.getBannerlist();
  207. if (app.couponChannelListCallback) {
  208. app.couponChannelListCallback(app.globalData.token);
  209. }
  210. if (app.couponListCallback) {
  211. app.couponListCallback(app.globalData.token);
  212. }
  213. if (app.businessListCallback) {
  214. app.businessListCallback(app.globalData.token);
  215. }
  216. that.checkuerstatus(couponChannelId, couponId);
  217. })
  218. .catch(err => {
  219. });
  220. }
  221. });
  222. },
  223. checkuerstatus(couponChannelId, couponId){
  224. Http.post({
  225. url: config.api.checkUserStatus,
  226. data: {}
  227. })
  228. .then(res => {
  229. if (couponChannelId && couponId) {
  230. wx.navigateTo({
  231. url: `/pages/coupon/detail/index?couponChannelId=${couponChannelId}&couponId=${couponId}`,
  232. })
  233. }
  234. })
  235. .catch(err => {
  236. if (err.code == 11004) {
  237. // 用户昵称未授权
  238. if (couponChannelId && couponId) {
  239. wx.redirectTo({
  240. url: `/pages/getuserinfo/index?couponChannelId=${couponChannelId}&couponId=${couponId}`
  241. });
  242. } else {
  243. wx.redirectTo({
  244. url: '/pages/getuserinfo/index'
  245. });
  246. }
  247. }
  248. });
  249. },
  250. getStaticGame(token){
  251. let _this = this;
  252. Http.get({
  253. url: config.api.getGame,
  254. data: {
  255. triggleAction:2,
  256. token: token
  257. }
  258. }).then(res => {
  259. if (res.data.id) {
  260. _this.setData({
  261. showIf:true
  262. })
  263. }
  264. _this.setData({
  265. staticGamedata: res.data
  266. })
  267. })
  268. .catch(err => {
  269. console.log(err)
  270. })
  271. },
  272. getGameOne:function(token){
  273. let _this=this;
  274. Http.get({
  275. url: config.api.getGame,
  276. data:{
  277. triggleAction: 1,
  278. token: token
  279. }
  280. }).then(res => {
  281. if (res.data.id){
  282. _this.setData({
  283. showGame: true
  284. })
  285. }
  286. _this.setData({
  287. gamedata:res.data
  288. })
  289. })
  290. .catch(err => {
  291. console.log(err)
  292. })
  293. },
  294. /**
  295. * banner
  296. */
  297. getBannerlist: function() {
  298. let that = this;
  299. Http.get({
  300. url: config.api.bannerlist,
  301. data: {
  302. pageNum: 1,
  303. pageSize: 7
  304. }
  305. }).then(res => {
  306. that.setData({
  307. list: res.data.list
  308. });
  309. });
  310. },
  311. /**
  312. * 检查用户是否有车
  313. */
  314. checkUserCarStatus: function() {
  315. var that = this;
  316. Http.get({
  317. url: config.api.userCarCount,
  318. data: {}
  319. }).then(res => {
  320. if (res.data > 0) {
  321. // 用户名下有车
  322. app.globalData.phone = res.data.phone;
  323. app.globalData.supportCar = true;
  324. // 共同登录
  325. that.userCarLogin();
  326. }
  327. });
  328. },
  329. /**
  330. * car共同登录
  331. */
  332. userCarLogin: function() {
  333. var that = this;
  334. if (!app.globalData.carLogin) {
  335. // 共同登录
  336. Http.post({
  337. url: config.api.carInit,
  338. data: {
  339. phone: app.globalData.phone
  340. }
  341. }).then(res => {
  342. app.globalData.carLogin = true;
  343. app.globalData.parkVendor = res.data.vendor;
  344. if (res.data.token != "undefined") {
  345. app.globalData.etcpToken = res.data.token;
  346. }
  347. });
  348. }
  349. },
  350. /**
  351. * 获取用户信息
  352. */
  353. getUserInfo: function() {
  354. // 获取用户信息
  355. wx.getSetting({
  356. success: res => {
  357. if (res.authSetting["scope.userInfo"]) {
  358. // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
  359. wx.getUserInfo({
  360. success: res => {
  361. // 可以将 res 发送给后台解码出 unionId
  362. }
  363. });
  364. }
  365. }
  366. });
  367. },
  368. //下拉加载更多
  369. onReachBottom: function() {
  370. let that = this;
  371. that.data.page++;
  372. that.setData({
  373. page: that.data.page
  374. });
  375. //父组件获得子组件的方法
  376. //如果code == 0
  377. if (that.data.code == 0 || that.data.code == undefined) {
  378. that.selectComponent("#lists").getList(0, that.data.page);
  379. } else {
  380. that.selectComponent("#lists").getList(that.data.code, that.data.page);
  381. }
  382. },
  383. // 用户点击右上角分享
  384. onShareAppMessage: function() {
  385. return {
  386. title: this.data.title,
  387. desc: this.data.desc,
  388. success: function(res) {
  389. wx.showToast({
  390. title: "分享成功",
  391. duration: 1000,
  392. icon: "success"
  393. });
  394. }
  395. };
  396. }
  397. });