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

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