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

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