index.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766
  1. //index.js
  2. //获取应用实例
  3. import * as echarts from '../../ec-canvas/echarts';
  4. var imageUtil = require('../../utils/window.js');
  5. const apiServer = require('../../api/request');
  6. var Chart = null;
  7. const app = getApp()
  8. var timeData = [
  9. '2020/6/1', '2009/6/2', '2009/6/3', '2009/6/4', '2009/6/5', '2009/6/6', '2009/6/7', '2009/6/8', '2009/6/9', '2009/6/10',
  10. ];
  11. timeData = timeData.map(function (str) {
  12. return str.replace('2009/', '');
  13. });
  14. function initChart(canvas, width, height, dpr, data) {
  15. const chart = echarts.init(canvas, null, {
  16. width: width,
  17. height: height,
  18. devicePixelRatio: dpr // new
  19. });
  20. canvas.setChart(chart);
  21. var option = {
  22. title: {//标题
  23. text: '',
  24. left: 'center'
  25. },
  26. renderAsImage: true, //支持渲染为图片模式
  27. color: ["#DF3E3E", "#80CDF8"],//图例图标颜色
  28. legend: {
  29. show: true,
  30. itemGap: 25,//每个图例间的间隔
  31. top: 30,
  32. x: 30,//水平安放位置,离容器左侧的距离 'left'
  33. z: 100,
  34. textStyle: {
  35. color: '#383838'
  36. },
  37. },
  38. grid: {//网格
  39. // left: 30,
  40. // top:100,
  41. containLabel: true,//grid 区域是否包含坐标轴的刻度标签
  42. },
  43. xAxis: {//横坐标
  44. type: 'category',
  45. // nameTextStyle: {//在name值存在下,设置name的样式
  46. // color: 'white',
  47. // fontStyle: 'normal'
  48. // },
  49. nameLocation:'end',
  50. splitLine: {//坐标轴在 grid 区域中的分隔线。
  51. show: true,
  52. lineStyle: {
  53. type: 'dashed',
  54. color: ['#2B2B2B']
  55. }
  56. },
  57. boundaryGap: false,//1.true 数据点在2个刻度直接 2.false 数据点在分割线上,即刻度值上
  58. data: data.timeData,
  59. axisLine: {onZero: true},
  60. axisLabel: {
  61. textStyle: {
  62. fontSize: 13,
  63. color: '#5D5D5D'
  64. }
  65. }
  66. },
  67. dataZoom: [
  68. {
  69. type: 'slider',
  70. xAxisIndex: 0,
  71. filterMode: 'empty',
  72. startValue: data.prediction? data.prediction.length -7:0,
  73. endValue: data.prediction?data.prediction.length:3 ,
  74. handleIcon: 'M10.7,11.9v-1.3H9.3v1.3c-4.9,0.3-8.8,4.4-8.8,9.4c0,5,3.9,9.1,8.8,9.4v1.3h1.3v-1.3c4.9-0.3,8.8-4.4,8.8-9.4C19.5,16.3,15.6,12.2,10.7,11.9z M13.3,24.4H6.7V23h6.6V24.4z M13.3,19.6H6.7v-1.4h6.6V19.6z',
  75. handleSize: '80%',
  76. handleStyle: {
  77. color: '#fff',
  78. shadowBlur: 3,
  79. shadowColor: 'rgba(0, 0, 0, 0.6)',
  80. shadowOffsetX: 2,
  81. shadowOffsetY: 2
  82. }
  83. },
  84. {
  85. type: 'inside',
  86. realtime: true,
  87. }
  88. ],
  89. yAxis: {//纵坐标
  90. type: 'value',
  91. position:'right',
  92. // nameTextStyle:{//在name值存在下,设置name的样式
  93. // color:'red',
  94. // fontStyle:'normal'
  95. // },
  96. splitNumber: 5,//坐标轴的分割段数
  97. scale:true,
  98. splitLine: {//坐标轴在 grid 区域中的分隔线。
  99. show: true,
  100. lineStyle: {
  101. type: 'dashed',
  102. color: ['#2B2B2B']
  103. }
  104. },
  105. axisLabel: {//坐标轴刻度标签
  106. // formatter: function (value) {
  107. // var xLable = [];
  108. // if (value == 20) {
  109. // xLable.push('25,883');
  110. // }
  111. // if (value == 40) {
  112. // xLable.push('26,035');
  113. // }
  114. // if (value == 60) {
  115. // xLable.push('26,187');
  116. // }
  117. // if (value == 80) {
  118. // xLable.push('26,339');
  119. // }
  120. // return xLable
  121. // },
  122. textStyle: {
  123. fontSize: 13,
  124. color: '#5D5D5D',
  125. }
  126. },
  127. // min: 0,
  128. // max: 100,
  129. },
  130. series: [{
  131. name: '实际',
  132. type: 'line',
  133. // smooth:true,
  134. data:data.actual,
  135. symbol: 'none',
  136. areaStyle: {
  137. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
  138. offset: 0,
  139. color: '#DF3E3E'
  140. }, {
  141. offset: 1,
  142. color: '#1C1C1C'
  143. }])
  144. },
  145. itemStyle: {
  146. normal: {
  147. lineStyle: {
  148. color: '#DF3E3E'
  149. }
  150. }
  151. }
  152. }, {
  153. name: '预测',
  154. type: 'line',
  155. data: data.prediction,
  156. symbol: 'none',
  157. itemStyle: {
  158. normal: {
  159. lineStyle: {
  160. color: '#80CDF8'
  161. }
  162. }
  163. }
  164. }],
  165. };
  166. chart.setOption(option);
  167. return chart;
  168. }
  169. Page({
  170. data: {
  171. url:'../../images/timg.jpg',
  172. motto: '',
  173. currentTab: 0,
  174. userInfo: {},
  175. hasUserInfo: false,
  176. canIUse: wx.canIUse('button.open-type.getUserInfo'),
  177. currPage:1,//当前页
  178. pages:0,//每页条数
  179. total:0,//总条数
  180. aa:[],//列表
  181. imagewidth: 0,//缩放后的宽
  182. imageheight: 0,//缩放后的高
  183. chartData:{
  184. // actual:[552,586,3555,4454,552,556,4455],
  185. // prediction:[552,546,3585,4424,542,546,35,44,524,56,355,444,2224,421],
  186. // timeData : [
  187. // '2020/6/1', '2020/6/2', '2020/6/3', '2020/6/4', '2020/6/5', '2020/6/6', '2020/6/7', '2020/6/8', '2020/6/9', '2020/6/10','2020/6/11',
  188. // '2020/6/12','2020/6/13','2020/6/14',
  189. // ]
  190. },
  191. chartDatas:{
  192. // actual:[572,556,3555,4744,552,576,3555],
  193. // prediction:[352,246,385,2424,542,546,255],
  194. // timeData : [
  195. // '2020/6/1', '2020/6/2', '2020/6/3', '2020/6/4', '2020/6/5', '2020/6/6', '2020/6/7'
  196. // ]
  197. },
  198. ec: {
  199. onInit: initChart,
  200. // lazyLoad: true // 延迟加载
  201. },
  202. // ec: {
  203. // onInit: function (canvas, width, height) {
  204. // chart = echarts.init(canvas, null, {
  205. // width: width,
  206. // height: height
  207. // });
  208. // canvas.setChart(chart);
  209. // return chart;
  210. // },
  211. // lazyLoad: true // 延迟加载
  212. // },
  213. aa:[
  214. // {
  215. // id:'0',
  216. // from:"Investing.com 中文",
  217. // nickName:"买入波音(BA.US)好时机?两个问题没解决之前劝你住手",
  218. // reward:"今年迄今,美股航空板块受到公共卫生事件的冲击.....",
  219. // time:"6天前"
  220. // },
  221. // {
  222. // id:'1',
  223. // from:"chinese.aljazeera.net",
  224. // nickName: "波音裁员超1.2万人与警惕最坏时刻尚未到来",
  225. // reward: "波音公司当地时间27日宣布,将在美国裁减超1...",
  226. // time:"6天前"
  227. // },
  228. // {
  229. // id:'2',
  230. // from:"Investing.com 中文",
  231. // nickName: "美股异动|波音737MAX客机恢复生产,盘前涨逾5%",
  232. // reward: "Reuters.美股异动|波音(BA.US)737MAX客...",
  233. // time:"5天前"
  234. // },
  235. // {
  236. // id:'3',
  237. // from:"Investing.com 中文",
  238. // nickName:"买入波音(BA.US)好时机?两个问题没解决之前劝你住手",
  239. // reward:"今年迄今,美股航空板块受到公共卫生事件的冲击.....",
  240. // time:"6天前"
  241. // },
  242. // {
  243. // id:'4',
  244. // from:"chinese.aljazeera.net",
  245. // nickName: "波音裁员超1.2万人与警惕最坏时刻尚未到来",
  246. // reward: "波音公司当地时间27日宣布,将在美国裁减超1...",
  247. // time:"6天前"
  248. // },
  249. // {
  250. // id:'5',
  251. // from:"Investing.com 中文",
  252. // nickName: "美股异动|波音737MAX客机恢复生产,盘前涨逾5%",
  253. // reward: "Reuters.美股异动|波音(BA.US)737MAX客...",
  254. // time:"5天前"
  255. // },
  256. // {
  257. // id:'6',
  258. // from:"Investing.com 中文",
  259. // nickName:"买入波音(BA.US)好时机?两个问题没解决之前劝你住手",
  260. // reward:"今年迄今,美股航空板块受到公共卫生事件的冲击.....",
  261. // time:"6天前"
  262. // },
  263. // {
  264. // id:'7',
  265. // from:"chinese.aljazeera.net",
  266. // nickName: "波音裁员超1.2万人与警惕最坏时刻尚未到来",
  267. // reward: "波音公司当地时间27日宣布,将在美国裁减超1...",
  268. // time:"6天前"
  269. // },
  270. // {
  271. // id:'8',
  272. // from:"Investing.com 中文",
  273. // nickName: "美股异动|波音737MAX客机恢复生产,盘前涨逾5%",
  274. // reward: "Reuters.美股异动|波音(BA.US)737MAX客...",
  275. // time:"5天前"
  276. // },
  277. // {
  278. // id:'9',
  279. // from:"Investing.com 中文",
  280. // nickName:"买入波音(BA.US)好时机?两个问题没解决之前劝你住手",
  281. // reward:"今年迄今,美股航空板块受到公共卫生事件的冲击.....",
  282. // time:"6天前"
  283. // },
  284. // {
  285. // id:'10',
  286. // from:"chinese.aljazeera.net",
  287. // nickName: "波音裁员超1.2万人与警惕最坏时刻尚未到来",
  288. // reward: "波音公司当地时间27日宣布,将在美国裁减超1...",
  289. // time:"6天前"
  290. // },
  291. // {
  292. // id:'11',
  293. // from:"Investing.com 中文",
  294. // nickName: "美股异动|波音737MAX客机恢复生产,盘前涨逾5%",
  295. // reward: "Reuters.美股异动|波音(BA.US)737MAX客...",
  296. // time:"5天前"
  297. // },
  298. // {
  299. // id:'12',
  300. // from:"Investing.com 中文",
  301. // nickName:"买入波音(BA.US)好时机?两个问题没解决之前劝你住手",
  302. // reward:"今年迄今,美股航空板块受到公共卫生事件的冲击.....",
  303. // time:"6天前"
  304. // },
  305. // {
  306. // id:'13',
  307. // from:"chinese.aljazeera.net",
  308. // nickName: "波音裁员超1.2万人与警惕最坏时刻尚未到来",
  309. // reward: "波音公司当地时间27日宣布,将在美国裁减超1...",
  310. // time:"6天前"
  311. // },
  312. // {
  313. // id:'14',
  314. // from:"Investing.com 中文",
  315. // nickName: "美股异动|波音737MAX客机恢复生产,盘前涨逾5%",
  316. // reward: "Reuters.美股异动|波音(BA.US)737MAX客...",
  317. // time:"5天前"
  318. // },
  319. ],
  320. },
  321. //事件处理函数
  322. bindViewTap: function() {
  323. wx.navigateTo({
  324. url: '../logs/logs'
  325. })
  326. },
  327. //上证
  328. getHz:function(){
  329. apiServer.getHz().then((res) =>{
  330. if(res.statusCode == 200){
  331. console.log(res);
  332. this.setData({
  333. chartDatas:this.recursion(res.data.data),
  334. })
  335. }
  336. })
  337. },
  338. //深证
  339. getSz:function(){
  340. apiServer.getSz().then((res) =>{
  341. if(res.statusCode == 200){
  342. console.log(res);
  343. this.setData({
  344. chartData:this.recursion(res.data.data),
  345. })
  346. }
  347. })
  348. },
  349. recursion:function(row,a=[],b=[],c=[],d){
  350. for(let i in row.actuals){
  351. a.unshift(row.actuals[i].industryDate)
  352. b.unshift(row.actuals[i].close)
  353. c.unshift(row.actuals[i].pred)
  354. }
  355. if(row.tag){
  356. d="#D81E06"
  357. }else{
  358. d="#07c160"
  359. }
  360. return {"timeData":a,"actual":b,"prediction":c,"color":d}
  361. },
  362. onReady: function (e) {
  363. this.computeScrollViewHeight();
  364. // var query = wx.createSelectorQuery()
  365. // query.select('#test').boundingClientRect(function (res) {
  366. // console.log(res.top);
  367. // }).exec();
  368. },
  369. onLoad: function (options) {
  370. this.getHz();
  371. this.getSz();
  372. getNewsList(this);
  373. let sysinfo = wx.getSystemInfoSync(),
  374. windowHeight = sysinfo.windowHeight,
  375. statusHeight = sysinfo.statusBarHeight,
  376. isiOS = sysinfo.system.indexOf('iOS') > -1,
  377. navHeight;
  378. if (!isiOS) {
  379. navHeight = 48;
  380. } else {
  381. navHeight = 44;
  382. }
  383. let height = windowHeight-statusHeight-navHeight;
  384. this.setData({
  385. height:height
  386. })
  387. // this.echartsComponnet = this.selectComponent('#mychart');
  388. // console.log(this.echartsComponnet);
  389. // //如果是第一次绘制
  390. // if (!Chart) {
  391. // this.init_echarts(); //初始化图表
  392. // } else {
  393. // this.setOption(Chart); //更新数据
  394. // }
  395. // this.computeScrollViewHeight();
  396. // if (app.globalData.userInfo) {
  397. // this.setData({
  398. // userInfo: app.globalData.userInfo,
  399. // hasUserInfo: true
  400. // })
  401. // } else if (this.data.canIUse){
  402. // // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
  403. // // 所以此处加入 callback 以防止这种情况
  404. // app.userInfoReadyCallback = res => {
  405. // this.setData({
  406. // userInfo: res.userInfo,
  407. // hasUserInfo: true
  408. // })
  409. // }
  410. // } else {
  411. // // 在没有 open-type=getUserInfo 版本的兼容处理
  412. // wx.getUserInfo({
  413. // success: res => {
  414. // app.globalData.userInfo = res.userInfo
  415. // this.setData({
  416. // userInfo: res.userInfo,
  417. // hasUserInfo: true
  418. // })
  419. // }
  420. // })
  421. // }
  422. },
  423. /**
  424. * 页面相关事件处理函数--监听用户下拉动作
  425. */
  426. onPullDownRefresh: function () {
  427. //下拉刷新,重新初始化,isMerge = false
  428. getNewsList(this);
  429. },
  430. /**
  431. * 页面上拉触底事件的处理函数
  432. */
  433. onReachBottom: function () {
  434. console.log("触发")
  435. setPage(this);
  436. },
  437. scrolltolower:function() {
  438. console.log("dgff");
  439. // var that = this;
  440. // var tempCurrentPage = that.data.currentPage;
  441. // tempCurrentPage = tempCurrentPage + 1;
  442. // if(that.data.currentPage==that.data.totalpages){
  443. // wx.showLoading({title: '已经到底啦'})
  444. // setTimeout(function(){
  445. // wx.hideLoading()
  446. // },600);
  447. // return
  448. // }
  449. // that.setData({
  450. // currentPage: tempCurrentPage,
  451. // })
  452. // getNewsList(this);
  453. setPage(this);
  454. },
  455. computeScrollViewHeight() {
  456. var that = this
  457. let query = wx.createSelectorQuery().in(that)
  458. query.select('.swiper-tab').boundingClientRect()
  459. query.select('.chart').boundingClientRect()
  460. query.select('.news').boundingClientRect()
  461. query.exec(res => {
  462. let topHeight = res[0].height
  463. let searchHeight = res[1].height
  464. let titleHeight = res[2].height
  465. let windowHeight = wx.getSystemInfoSync().windowHeight
  466. let windowWidth = wx.getSystemInfoSync().windowWidth
  467. let height = windowHeight - topHeight - searchHeight - titleHeight
  468. let ratio = 750 / windowWidth
  469. let scrollHeight = height * ratio
  470. that.setData({ scrollHeight: scrollHeight})
  471. })
  472. },
  473. imageLoad: function (e) {
  474. var imageSize = imageUtil.imageUtil(e)
  475. this.setData({
  476. imagewidth: imageSize.imageWidth,
  477. imageheight: imageSize.imageHeight
  478. })
  479. this.computeScrollViewHeight();
  480. },
  481. onFold:function(e){
  482. wx.navigateTo({
  483. url:'../news/news?newsId='+e.currentTarget.dataset.id
  484. });
  485. },
  486. choose:function(e){
  487. wx.navigateTo({
  488. url:"../filter/filter"
  489. })
  490. },
  491. swichNav: function(e) {
  492. var that = this;
  493. if (this.data.currentTab === e.target.dataset.current) {
  494. return false;
  495. } else {
  496. that.setData({
  497. currentTab: e.target.dataset.current
  498. })
  499. }
  500. },
  501. // 滑动切换tab
  502. bindChange: function(e) {
  503. var that = this;
  504. that.setData({
  505. currentTab: e.detail.current
  506. });
  507. },
  508. catchTouchMove:function(res){
  509. return false
  510. },
  511. //初始化图表
  512. init_echarts: function () {
  513. this.echartsComponnet.init((canvas, width, height) => {
  514. // 初始化图表
  515. const Chart = echarts.init(canvas, null, {
  516. width: width,
  517. height: height
  518. });
  519. this.setOption(Chart)
  520. // 注意这里一定要返回 chart 实例,否则会影响事件处理等
  521. return Chart
  522. });
  523. },
  524. setOption: function (Chart) {
  525. Chart.clear(); // 清除
  526. Chart.setOption(this.getOption()); //获取新数据
  527. },
  528. // 图表配置项
  529. getOption() {
  530. var self = this;
  531. var option = {
  532. title: {//标题
  533. text: '',
  534. left: 'center'
  535. },
  536. renderAsImage: true, //支持渲染为图片模式
  537. color: ["#DF3E3E", "#80CDF8"],//图例图标颜色
  538. legend: {
  539. // left:'right',
  540. show: true,
  541. itemGap: 25,//每个图例间的间隔
  542. top: 20,
  543. right:20,
  544. x: 100,//水平安放位置,离容器左侧的距离 'left'
  545. z: 100,
  546. textStyle: {
  547. color: '#383838'
  548. },
  549. data: [//图例具体内容
  550. {
  551. name: '实际',
  552. textStyle: {
  553. fontSize: 13,
  554. color: 'white'
  555. },
  556. icon: 'line'
  557. },
  558. {
  559. name: '预测',
  560. textStyle: {
  561. fontSize: 13,
  562. color: 'white'
  563. },
  564. icon: 'line',
  565. }
  566. ]
  567. },
  568. grid: {//网格
  569. // left: 50,
  570. // top:100,
  571. containLabel: true,//grid 区域是否包含坐标轴的刻度标签
  572. },
  573. xAxis: {//横坐标
  574. type: 'category',
  575. // name: '区间',//横坐标名称
  576. nameTextStyle: {//在name值存在下,设置name的样式
  577. color: 'white',
  578. fontStyle: 'normal'
  579. },
  580. nameLocation:'end',
  581. splitLine: {//坐标轴在 grid 区域中的分隔线。
  582. show: true,
  583. lineStyle: {
  584. type: 'dashed',
  585. color: ['#2B2B2B']
  586. }
  587. },
  588. boundaryGap: false,//1.true 数据点在2个刻度直接 2.fals 数据点在分割线上,即刻度值上
  589. data: ['2020/6/29', '2020/6/30', '2020/7/1', '2020/7/2', '2020/7/3'],
  590. axisLine: {onZero: true},
  591. axisLabel: {
  592. textStyle: {
  593. fontSize: 13,
  594. color: '#5D5D5D'
  595. }
  596. }
  597. },
  598. yAxis: {//纵坐标
  599. type: 'value',
  600. position:'right',
  601. name: '股票值',//纵坐标名称
  602. nameTextStyle:{//在name值存在下,设置name的样式
  603. color:'red',
  604. fontStyle:'normal'
  605. },
  606. splitNumber: 5,//坐标轴的分割段数
  607. splitLine: {//坐标轴在 grid 区域中的分隔线。
  608. show: true,
  609. lineStyle: {
  610. type: 'dashed',
  611. color: ['#2B2B2B']
  612. }
  613. },
  614. axisLabel: {//坐标轴刻度标签
  615. // formatter: function (value) {
  616. // var xLable = [];
  617. // if (value == 20) {
  618. // xLable.push('1000');
  619. // }
  620. // if (value == 40) {
  621. // xLable.push('2000');
  622. // }
  623. // if (value == 60) {
  624. // xLable.push('4000');
  625. // }
  626. // if (value == 80) {
  627. // xLable.push('6000');
  628. // }
  629. // return xLable
  630. // },
  631. textStyle: {
  632. fontSize: 13,
  633. color: '#5D5D5D',
  634. }
  635. },
  636. // min: 0,
  637. // max: 100,
  638. },
  639. series: [{
  640. name: '实际',
  641. type: 'line',
  642. // smooth:true,
  643. data: [1888, 3666, 6555, 3000, 7888, 4000, 3333],
  644. symbol: 'none',
  645. areaStyle: {
  646. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  647. {
  648. offset: 0,
  649. color: '#DF3E3E'
  650. },
  651. {
  652. offset: 1,
  653. color: '#1C1C1C'
  654. }
  655. ])
  656. },
  657. itemStyle: {
  658. normal: {
  659. lineStyle: {
  660. color: '#DF3E3E'
  661. }
  662. }
  663. }
  664. }, {
  665. name: '预测',
  666. type: 'line',
  667. data: [1000, 3000, 3111, 5000, 4000, 2000, 1000],
  668. symbol: 'none',
  669. itemStyle: {
  670. normal: {
  671. lineStyle: {
  672. color: '#80CDF8'
  673. }
  674. }
  675. }
  676. }],
  677. }
  678. return option;
  679. },
  680. getUserInfo: function(e) {
  681. console.log(e)
  682. app.globalData.userInfo = e.detail.userInfo
  683. this.setData({
  684. userInfo: e.detail.userInfo,
  685. hasUserInfo: true
  686. })
  687. }
  688. })
  689. /**
  690. * method:分页加载控制函数
  691. *
  692. */
  693. function setPage(that) {
  694. const {
  695. currPage,
  696. pages,
  697. total
  698. } = that.data;
  699. // const totalPages = getTotalPages(total,pages);
  700. if (currPage >= pages || that.isLoading) {
  701. //控制触底是否加载需要两个条件,满足一下两个条件,都不能调用请求函数
  702. // 1.当前页是最后一页,
  703. // 2. 正在加载中
  704. return
  705. }
  706. //分页加载需要传递isMerge=true参数,表示需要合并到原来的数组上
  707. getNewsList(that,true)
  708. }
  709. /**
  710. * method:得到总页数
  711. * @param {Number,String} total 列表总数
  712. * @param {Number,String} pages 每一页的条数
  713. * @return {Number} totalPages 总页数
  714. */
  715. function getTotalPages(total,pages){
  716. //总数除以每一页条数 如果余数!=0,结果需要+1
  717. const remainder = Number(total) % Number(pages);
  718. const value = Math.floor(total / pages);
  719. const totalPages = remainder == 0 ? value : Number(value) + 1;
  720. return totalPages
  721. }
  722. //获取新闻列表
  723. function getNewsList(that,isMerge){
  724. // that.isLoading = true
  725. // wx.showLoading({
  726. // title: '加载中',
  727. // })
  728. const data = {};
  729. data.currPage = Number(that.data.currPage) + 1;
  730. if(!isMerge){
  731. //不合并,页码需要重新设置为1
  732. data.currPage = 1;
  733. }
  734. apiServer.getNewsList(data).then((res)=>{
  735. if(res.statusCode == 200){
  736. let aa = that.data.aa;
  737. if(!isMerge){
  738. aa = [];
  739. }
  740. aa = aa.concat(res.data.data.incInfos)
  741. that.setData({
  742. aa,
  743. currPage:res.data.data.current,
  744. pages: res.data.data.pages,
  745. total: res.data.data.total
  746. })
  747. }
  748. // that.isLoading = false
  749. wx.stopPullDownRefresh();
  750. // setTimeout(function(){
  751. // wx.hideLoading()
  752. // },500)
  753. })
  754. }