C端小程序
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

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