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.

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