C端小程序
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

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