C端小程序
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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