index.js 22 KB

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