index.js 21 KB

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