C端小程序
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

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