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.

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