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.

314 lines
7.9 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. swiperCurrent: 0,
  9. title:'',
  10. desc:'',
  11. scrollTop: 0,
  12. showGame:false,
  13. gamedata:{},
  14. couponId:'',//游戏返回时传回的字段
  15. played:false,//从游戏页面跳回首页返回true
  16. havePlayEd: app.globalData.havePlayEd,
  17. page: 1 // 刷新进入页面时已经加载了第一页数据,onReachBottom时 page++,从第2页开始加载
  18. },
  19. swiperChange: function(e) {
  20. this.setData({
  21. swiperCurrent: e.detail.current
  22. });
  23. },
  24. gotogame:function(){
  25. wx.navigateTo({
  26. url: '../game/index',
  27. })
  28. },
  29. /**
  30. * 生命周期函数--监听页面初次渲染完成
  31. */
  32. onLoad: function(options) {
  33. console.log(options,2222222)
  34. if(options.played=="true"){
  35. this.setData({
  36. played:true
  37. })
  38. }
  39. var that = this;
  40. console.log(options);
  41. console.log("这是options")
  42. var scene = decodeURIComponent(options.scene);
  43. that.setData({
  44. scene:scene
  45. });
  46. // console.log(that.data.scene)
  47. // console.log(scene);
  48. app.getLocation();
  49. if (options.couponChannelId && options.couponId){
  50. that.userLogin(options.couponChannelId, options.couponId);
  51. }else{
  52. that.userLogin()
  53. }
  54. Http.get({
  55. url: config.api.getWeapNote,
  56. data: {
  57. appId: config.weapp.AppId,
  58. }
  59. })
  60. .then(res=>{
  61. // console.log(res.data.weapNote);
  62. let weapNote = JSON.parse(res.data.weapNote);
  63. // console.log(weapNote.firstpage);
  64. that.setData({
  65. desc: weapNote.firstpage.desc,
  66. title: weapNote.firstpage.title
  67. })
  68. })
  69. },
  70. onShow:function(){
  71. // console.log(app.globalData.havePlayEd)
  72. this.setData({
  73. havePlayEd: app.globalData.havePlayEd ? app.globalData.havePlayEd:false
  74. })
  75. let num = wx.getStorageSync('couponNum');
  76. if (num =='couponNum'){
  77. wx.showTabBarRedDot({
  78. index: 2
  79. })
  80. };
  81. },
  82. /**
  83. * 下拉刷新
  84. */
  85. onPullDownRefresh: function(e) {
  86. let that = this;
  87. that.userLogin();
  88. // console.log(this.data.code);
  89. if (that.data.code == 0 || that.data.code == undefined) {
  90. that.selectComponent("#lists").getList(0, 1);
  91. wx.stopPullDownRefresh();
  92. // console.log("下拉刷新");
  93. } else {
  94. that.selectComponent("#lists").getList(that.data.code, 1);
  95. wx.stopPullDownRefresh();
  96. };
  97. },
  98. onGetCode: function(e) {
  99. //子组件传递给父组件的值
  100. this.setData({
  101. code: e.detail.val,
  102. page: e.detail.pageNum
  103. });
  104. },
  105. /**
  106. * 用户登录
  107. */
  108. userLogin: function (couponChannelId,couponId) {
  109. var that = this;
  110. // 登录
  111. wx.login({
  112. success: ({
  113. code
  114. }) => {
  115. wx.getSystemInfo({
  116. success: function (res) {
  117. // console.log(JSON.stringify(res))
  118. that.setData({
  119. systemInfo: JSON.stringify(res)
  120. })
  121. }
  122. })
  123. var usrdata = {
  124. appId: config.weapp.AppId,
  125. code: code,
  126. sceneAddress: app.globalData.sceneAddress,
  127. scene: that.data.scene,
  128. systemInfo: that.data.systemInfo
  129. };
  130. if (app.globalData.locationInfo) {
  131. usrdata = {
  132. appId: config.weapp.AppId,
  133. code: code,
  134. sceneAddress: app.globalData.sceneAddress,
  135. latitude: "" + app.globalData.locationInfo.latitude,
  136. longitude: "" + app.globalData.locationInfo.longitude,
  137. scene: that.data.scene,
  138. systemInfo: that.data.systemInfo
  139. };
  140. }
  141. Http.post({
  142. url: config.api.login,
  143. data: usrdata
  144. })
  145. .then(res => {
  146. app.globalData.token = res.data.token;
  147. if (res.data.token && couponChannelId && couponId){
  148. wx.navigateTo({
  149. url: `/pages/coupon/detail/index?couponChannelId=${couponChannelId}&couponId=${couponId}`,
  150. })
  151. }
  152. if (res.data.token){
  153. that.setData({
  154. showGame: true
  155. })
  156. that.getGameOne(res.data.token)
  157. }
  158. Http.setToken(res.data.token);
  159. that.checkUserCarStatus();
  160. // that.getUserInfo();
  161. that.getBannerlist();
  162. if (app.couponChannelListCallback) {
  163. app.couponChannelListCallback(app.globalData.token);
  164. }
  165. if (app.couponListCallback) {
  166. app.couponListCallback(app.globalData.token);
  167. }
  168. if (app.businessListCallback) {
  169. app.businessListCallback(app.globalData.token);
  170. }
  171. return Http.post({
  172. url: config.api.checkUserStatus,
  173. data: {}
  174. });
  175. })
  176. .then(res => {
  177. console.log("checkUserStatus:res", res);
  178. })
  179. .catch(err => {
  180. console.log("checkUserStatus:err", err);
  181. if (err.code == 11004) {
  182. // 用户昵称未授权
  183. wx.redirectTo({
  184. url: "/pages/getuserinfo/index"
  185. });
  186. }
  187. });
  188. }
  189. });
  190. },
  191. getGameOne:function(token){
  192. let _this=this;
  193. Http.get({
  194. url: config.api.getGame,
  195. data:{
  196. token: token
  197. }
  198. }).then(res => {
  199. console.log(res.data,77777)
  200. _this.setData({
  201. gamedata:res.data
  202. })
  203. })
  204. },
  205. /**
  206. * banner
  207. */
  208. getBannerlist: function() {
  209. let that = this;
  210. Http.get({
  211. url: config.api.bannerlist,
  212. data: {
  213. pageNum: 1,
  214. pageSize: 7
  215. }
  216. }).then(res => {
  217. that.setData({
  218. list: res.data.list
  219. });
  220. });
  221. },
  222. /**
  223. * 检查用户是否有车
  224. */
  225. checkUserCarStatus: function() {
  226. var that = this;
  227. Http.get({
  228. url: config.api.userCarCount,
  229. data: {}
  230. }).then(res => {
  231. if (res.data > 0) {
  232. // 用户名下有车
  233. app.globalData.phone = res.data.phone;
  234. app.globalData.supportCar = true;
  235. // 共同登录
  236. that.userCarLogin();
  237. }
  238. });
  239. },
  240. /**
  241. * car共同登录
  242. */
  243. userCarLogin: function() {
  244. var that = this;
  245. if (!app.globalData.carLogin) {
  246. // 共同登录
  247. Http.post({
  248. url: config.api.carInit,
  249. data: {
  250. phone: app.globalData.phone
  251. }
  252. }).then(res => {
  253. app.globalData.carLogin = true;
  254. app.globalData.parkVendor = res.data.vendor;
  255. if (res.data.token != "undefined") {
  256. app.globalData.etcpToken = res.data.token;
  257. }
  258. });
  259. }
  260. },
  261. /**
  262. * 获取用户信息
  263. */
  264. getUserInfo: function() {
  265. // 获取用户信息
  266. wx.getSetting({
  267. success: res => {
  268. if (res.authSetting["scope.userInfo"]) {
  269. // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
  270. wx.getUserInfo({
  271. success: res => {
  272. // 可以将 res 发送给后台解码出 unionId
  273. debugger
  274. console.log("getUserInfo", res);
  275. }
  276. });
  277. }
  278. }
  279. });
  280. },
  281. //下拉加载更多
  282. onReachBottom: function() {
  283. let that = this;
  284. that.data.page++;
  285. that.setData({
  286. page: that.data.page
  287. });
  288. // console.log("我是第" + that.data.page + "几页")
  289. //父组件获得子组件的方法
  290. //如果code == 0
  291. if (that.data.code == 0 || that.data.code == undefined) {
  292. that.selectComponent("#lists").getList(0, that.data.page);
  293. } else {
  294. that.selectComponent("#lists").getList(that.data.code, that.data.page);
  295. }
  296. },
  297. // 用户点击右上角分享
  298. onShareAppMessage: function() {
  299. return {
  300. title: this.data.title,
  301. desc: this.data.desc,
  302. success: function(res) {
  303. wx.showToast({
  304. title: "分享成功",
  305. duration: 1000,
  306. icon: "success"
  307. });
  308. }
  309. };
  310. }
  311. });