C端小程序
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

318 wiersze
8.0 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. /**
  157. * 暂时注释
  158. */
  159. // that.getGameOne(res.data.token)
  160. }
  161. Http.setToken(res.data.token);
  162. that.checkUserCarStatus();
  163. that.getUserInfo();
  164. that.getBannerlist();
  165. if (app.couponChannelListCallback) {
  166. app.couponChannelListCallback(app.globalData.token);
  167. }
  168. if (app.couponListCallback) {
  169. app.couponListCallback(app.globalData.token);
  170. }
  171. if (app.businessListCallback) {
  172. app.businessListCallback(app.globalData.token);
  173. }
  174. return Http.post({
  175. url: config.api.checkUserStatus,
  176. data: {}
  177. });
  178. })
  179. .then(res => {
  180. console.log("checkUserStatus:res", res);
  181. })
  182. .catch(err => {
  183. console.log("checkUserStatus:err", err);
  184. if (err.code == 11004) {
  185. // 用户昵称未授权
  186. wx.redirectTo({
  187. url: "/pages/getuserinfo/index"
  188. });
  189. }
  190. });
  191. }
  192. });
  193. },
  194. getGameOne:function(token){
  195. let _this=this;
  196. Http.get({
  197. url: config.api.getGame,
  198. data:{
  199. token: token
  200. }
  201. }).then(res => {
  202. console.log(res.data,77777)
  203. _this.setData({
  204. gamedata:res.data
  205. })
  206. })
  207. },
  208. /**
  209. * banner
  210. */
  211. getBannerlist: function() {
  212. let that = this;
  213. Http.get({
  214. url: config.api.bannerlist,
  215. data: {
  216. pageNum: 1,
  217. pageSize: 7
  218. }
  219. }).then(res => {
  220. that.setData({
  221. list: res.data.list
  222. });
  223. });
  224. },
  225. /**
  226. * 检查用户是否有车
  227. */
  228. checkUserCarStatus: function() {
  229. var that = this;
  230. Http.get({
  231. url: config.api.userCarCount,
  232. data: {}
  233. }).then(res => {
  234. if (res.data > 0) {
  235. // 用户名下有车
  236. app.globalData.phone = res.data.phone;
  237. app.globalData.supportCar = true;
  238. // 共同登录
  239. that.userCarLogin();
  240. }
  241. });
  242. },
  243. /**
  244. * car共同登录
  245. */
  246. userCarLogin: function() {
  247. var that = this;
  248. if (!app.globalData.carLogin) {
  249. // 共同登录
  250. Http.post({
  251. url: config.api.carInit,
  252. data: {
  253. phone: app.globalData.phone
  254. }
  255. }).then(res => {
  256. app.globalData.carLogin = true;
  257. app.globalData.parkVendor = res.data.vendor;
  258. if (res.data.token != "undefined") {
  259. app.globalData.etcpToken = res.data.token;
  260. }
  261. });
  262. }
  263. },
  264. /**
  265. * 获取用户信息
  266. */
  267. getUserInfo: function() {
  268. // 获取用户信息
  269. wx.getSetting({
  270. success: res => {
  271. if (res.authSetting["scope.userInfo"]) {
  272. // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
  273. wx.getUserInfo({
  274. success: res => {
  275. // 可以将 res 发送给后台解码出 unionId
  276. console.log("getUserInfo", res);
  277. }
  278. });
  279. }
  280. }
  281. });
  282. },
  283. //下拉加载更多
  284. onReachBottom: function() {
  285. let that = this;
  286. that.data.page++;
  287. that.setData({
  288. page: that.data.page
  289. });
  290. // console.log("我是第" + that.data.page + "几页")
  291. //父组件获得子组件的方法
  292. //如果code == 0
  293. if (that.data.code == 0 || that.data.code == undefined) {
  294. that.selectComponent("#lists").getList(0, that.data.page);
  295. } else {
  296. that.selectComponent("#lists").getList(that.data.code, that.data.page);
  297. }
  298. },
  299. // 用户点击右上角分享
  300. onShareAppMessage: function() {
  301. return {
  302. title: this.data.title,
  303. desc: this.data.desc,
  304. success: function(res) {
  305. wx.showToast({
  306. title: "分享成功",
  307. duration: 1000,
  308. icon: "success"
  309. });
  310. }
  311. };
  312. }
  313. });