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.

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