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.

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