index.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559
  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. const app = getApp()
  7. Page({
  8. data: {
  9. url:'../../images/timg.jpg',
  10. motto: '',
  11. currentTab: 0,
  12. winheight:0,
  13. userInfo: {},
  14. hasUserInfo: false,
  15. canIUse: wx.canIUse('button.open-type.getUserInfo'),
  16. currPage:1,//当前页
  17. pages:0,//每页条数
  18. total:0,//总条数
  19. aa:[],//列表
  20. loading: false,
  21. imagewidth: 0,//缩放后的宽
  22. imageheight: 0,//缩放后的高
  23. chartData:{
  24. },
  25. chartDatas:{
  26. },
  27. ec: {
  28. onInit: true,
  29. // lazyLoad: true // 延迟加载
  30. },
  31. aa:[
  32. ],
  33. },
  34. //事件处理函数
  35. bindViewTap: function() {
  36. wx.navigateTo({
  37. url: '../logs/logs'
  38. })
  39. },
  40. //上证
  41. getHz:function(){
  42. apiServer.getHz().then((res) =>{
  43. if(res.statusCode == 200){
  44. this.setData({
  45. loading:false
  46. })
  47. this.onComponent.init((canvas, width, height,dpr) => {
  48. // 初始化图表
  49. const Chart = echarts.init(canvas, null, {
  50. width: width,
  51. height: height,
  52. devicePixelRatio: dpr // new
  53. });
  54. Chart.setOption(this.getOption(this.recursion(res.data.data)));
  55. return Chart;
  56. });
  57. }
  58. })
  59. },
  60. //深证
  61. getSz:function(){
  62. apiServer.getSz().then((res) =>{
  63. if(res.statusCode == 200){
  64. console.log(res);
  65. this.setData({
  66. loading:false
  67. })
  68. this.deppComponnet.init((canvas, width, height,dpr) => {
  69. // 初始化图表
  70. const Chart = echarts.init(canvas, null, {
  71. width: width,
  72. height: height,
  73. devicePixelRatio: dpr // new
  74. });
  75. Chart.setOption(this.getOption(this.recursion(res.data.data)));
  76. return Chart;
  77. });
  78. }
  79. })
  80. },
  81. recursion:function(row,a=[],b=[],c=[],d){
  82. for(let i in row.actuals){
  83. a.unshift(row.actuals[i].industryDate)
  84. b.unshift(row.actuals[i].close)
  85. c.unshift(row.actuals[i].pred)
  86. }
  87. if(row.tag){
  88. d="#D81E06"
  89. }else{
  90. d="#07c160"
  91. }
  92. return {"timeData":a,"actual":b,"prediction":c,"color":d}
  93. },
  94. getOption:function(data){
  95. return {
  96. title: {//标题
  97. text: '',
  98. left: 'center'
  99. },
  100. tooltip: {
  101. trigger: 'axis',
  102. axisPointer: {
  103. type: 'cross',
  104. label: {
  105. backgroundColor: '#6a7985'
  106. }
  107. }
  108. },
  109. renderAsImage: true, //支持渲染为图片模式
  110. color: [data.color, "#80CDF8"],//图例图标颜色
  111. legend: {
  112. show: true,
  113. itemGap: 25,//每个图例间的间隔
  114. // top: 30,
  115. x: 30,//水平安放位置,离容器左侧的距离 'left'
  116. z: 100,
  117. textStyle: {
  118. color: '#383838'
  119. },
  120. },
  121. grid: {//网格
  122. top:"8%",
  123. left: "2%",
  124. right:"2%",
  125. containLabel: true,//grid 区域是否包含坐标轴的刻度标签
  126. },
  127. xAxis: {//横坐标
  128. type: 'category',
  129. // nameTextStyle: {//在name值存在下,设置name的样式
  130. // color: 'white',
  131. // fontStyle: 'normal'
  132. // },
  133. // splitNumber: 7,//坐标轴的分割段数
  134. nameLocation:'end',//坐标轴名称显示位置。
  135. splitLine: {//坐标轴在 grid 区域中的分隔线。
  136. show: true,
  137. lineStyle: {
  138. type: 'dashed',
  139. color: ['#2B2B2B']
  140. }
  141. },
  142. boundaryGap: false,//1.true 数据点在2个刻度直接 2.fals 数据点在分割线上,即刻度值上
  143. data: data.timeData,
  144. axisLine: {onZero: true},
  145. axisLabel: {
  146. textStyle: {
  147. fontSize: 13,
  148. color: '#5D5D5D'
  149. }
  150. }
  151. },
  152. dataZoom: [
  153. {
  154. type: 'slider',
  155. xAxisIndex: 0,
  156. filterMode: 'empty',
  157. startValue: data.prediction? data.prediction.length -4:0,
  158. endValue: data.prediction?data.prediction.length:3 ,
  159. 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',
  160. handleSize: '80%',
  161. handleStyle: {
  162. color: '#fff',
  163. shadowBlur: 3,
  164. shadowColor: 'rgba(0, 0, 0, 0.6)',
  165. shadowOffsetX: 2,
  166. shadowOffsetY: 2
  167. }
  168. },
  169. {
  170. type: 'inside',
  171. realtime: true
  172. }
  173. ],
  174. yAxis: {//纵坐标
  175. type: 'value',
  176. position:'right',
  177. // nameTextStyle:{//在name值存在下,设置name的样式
  178. // color:'red',
  179. // fontStyle:'normal'
  180. // },
  181. splitNumber: 5,//坐标轴的分割段数
  182. scale:true,
  183. splitLine: {//坐标轴在 grid 区域中的分隔线。
  184. show: true,
  185. lineStyle: {
  186. type: 'dashed',
  187. color: ['#2B2B2B']
  188. }
  189. },
  190. axisLabel: {//坐标轴刻度标签
  191. // formatter: function (value) {
  192. // var xLable = [];
  193. // if (value == 20) {
  194. // xLable.push('25,883');
  195. // }
  196. // if (value == 40) {
  197. // xLable.push('26,035');
  198. // }
  199. // if (value == 60) {
  200. // xLable.push('26,187');
  201. // }
  202. // if (value == 80) {
  203. // xLable.push('26,339');
  204. // }
  205. // return xLable
  206. // },
  207. textStyle: {
  208. fontSize: 13,
  209. color: '#5D5D5D',
  210. }
  211. },
  212. // min: 0,
  213. // max: 100,
  214. },
  215. series: [{
  216. name: '实际',
  217. type: 'line',
  218. // smooth:true,
  219. data:data.actual,
  220. symbol: 'none',
  221. areaStyle: {
  222. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
  223. offset: 0,
  224. color: data.color
  225. }, {
  226. offset: 1,
  227. color: '#1C1C1C'
  228. }])
  229. },
  230. itemStyle: {
  231. normal: {
  232. lineStyle: {
  233. color: data.color
  234. }
  235. }
  236. }
  237. }, {
  238. name: '预测',
  239. type: 'line',
  240. data: data.prediction,
  241. symbol: 'none',
  242. itemStyle: {
  243. normal: {
  244. lineStyle: {
  245. color: '#80CDF8'
  246. }
  247. }
  248. }
  249. }],
  250. };
  251. },
  252. onReady: function (e) {
  253. this.computeScrollViewHeight();
  254. // var query = wx.createSelectorQuery()
  255. // query.select('#test').boundingClientRect(function (res) {
  256. // console.log(res.top);
  257. // }).exec();
  258. },
  259. //下拉刷新
  260. onRefresh: function(e) {
  261. this.setData({
  262. currentPage: 1,
  263. loading:true
  264. })
  265. this.getHz();
  266. this.getSz();
  267. getNewsList(this);
  268. },
  269. onLoad: function (options) {
  270. this.onComponent = this.selectComponent('#mychart-dom-line-on');
  271. this.deppComponnet = this.selectComponent('#mychart-dom-line-depp');
  272. this.getHz();
  273. this.getSz();
  274. getNewsList(this);
  275. let sysinfo = wx.getSystemInfoSync(),
  276. windowHeight = sysinfo.windowHeight,
  277. statusHeight = sysinfo.statusBarHeight,
  278. isiOS = sysinfo.system.indexOf('iOS') > -1,
  279. navHeight;
  280. if (!isiOS) {
  281. navHeight = 48;
  282. } else {
  283. navHeight = 44;
  284. }
  285. let height = windowHeight-statusHeight-navHeight;
  286. this.setData({
  287. winheight:height
  288. })
  289. },
  290. /**
  291. * 页面相关事件处理函数--监听用户下拉动作
  292. */
  293. onPullDownRefresh: function () {
  294. //下拉刷新,重新初始化,isMerge = false
  295. getNewsList(this);
  296. },
  297. /**
  298. * 页面上拉触底事件的处理函数
  299. */
  300. onReachBottom: function () {
  301. console.log("触发")
  302. setPage(this);
  303. },
  304. scrolltolower:function() {
  305. console.log("dgff");
  306. // var that = this;
  307. // var tempCurrentPage = that.data.currentPage;
  308. // tempCurrentPage = tempCurrentPage + 1;
  309. // if(that.data.currentPage==that.data.totalpages){
  310. // wx.showLoading({title: '已经到底啦'})
  311. // setTimeout(function(){
  312. // wx.hideLoading()
  313. // },600);
  314. // return
  315. // }
  316. // that.setData({
  317. // currentPage: tempCurrentPage,
  318. // })
  319. // getNewsList(this);
  320. setPage(this);
  321. },
  322. computeScrollViewHeight() {
  323. // var that = this
  324. // let query = wx.createSelectorQuery().in(that)
  325. // query.select('.swiper-tab').boundingClientRect()
  326. // query.select('.chart').boundingClientRect()
  327. // query.select('.news').boundingClientRect()
  328. // query.exec(res => {
  329. // let topHeight = res[0].height
  330. // let searchHeight = res[1].height
  331. // let titleHeight = res[2].height
  332. // let windowHeight = wx.getSystemInfoSync().windowHeight
  333. // let windowWidth = wx.getSystemInfoSync().windowWidth
  334. // let height = windowHeight - topHeight - searchHeight - titleHeight
  335. // let ratio = 750 / windowWidth
  336. // let scrollHeight = height * ratio
  337. // that.setData({ scrollHeight: scrollHeight})
  338. // })
  339. },
  340. imageLoad: function (e) {
  341. var imageSize = imageUtil.imageUtil(e)
  342. this.setData({
  343. imagewidth: imageSize.imageWidth,
  344. imageheight: imageSize.imageHeight
  345. })
  346. this.computeScrollViewHeight();
  347. },
  348. onFold:function(e){
  349. wx.navigateTo({
  350. url:'../news/news?newsId='+e.currentTarget.dataset.id
  351. });
  352. },
  353. choose:function(e){
  354. wx.navigateTo({
  355. url:"../filter/filter"
  356. })
  357. },
  358. swichNav: function(e) {
  359. var that = this;
  360. if (this.data.currentTab === e.target.dataset.current) {
  361. return false;
  362. } else {
  363. that.setData({
  364. currentTab: e.target.dataset.current
  365. })
  366. }
  367. },
  368. // 滑动切换tab
  369. bindChange: function(e) {
  370. var that = this;
  371. that.setData({
  372. currentTab: e.detail.current
  373. });
  374. },
  375. catchTouchMove:function(res){
  376. return false
  377. },
  378. getUserInfo: function(e) {
  379. console.log(e)
  380. app.globalData.userInfo = e.detail.userInfo
  381. this.setData({
  382. userInfo: e.detail.userInfo,
  383. hasUserInfo: true
  384. })
  385. }
  386. })
  387. /**
  388. * method:分页加载控制函数
  389. *
  390. */
  391. function setPage(that) {
  392. const {
  393. currPage,
  394. pages,
  395. total
  396. } = that.data;
  397. // const totalPages = getTotalPages(total,pages);
  398. if (currPage >= pages || that.isLoading) {
  399. //控制触底是否加载需要两个条件,满足一下两个条件,都不能调用请求函数
  400. // 1.当前页是最后一页,
  401. // 2. 正在加载中
  402. return
  403. }
  404. //分页加载需要传递isMerge=true参数,表示需要合并到原来的数组上
  405. getNewsList(that,true)
  406. }
  407. /**
  408. * method:得到总页数
  409. * @param {Number,String} total 列表总数
  410. * @param {Number,String} pages 每一页的条数
  411. * @return {Number} totalPages 总页数
  412. */
  413. function getTotalPages(total,pages){
  414. //总数除以每一页条数 如果余数!=0,结果需要+1
  415. const remainder = Number(total) % Number(pages);
  416. const value = Math.floor(total / pages);
  417. const totalPages = remainder == 0 ? value : Number(value) + 1;
  418. return totalPages
  419. }
  420. //获取新闻列表
  421. function getNewsList(that,isMerge){
  422. // that.isLoading = true
  423. // wx.showLoading({
  424. // title: '加载中',
  425. // })
  426. const data = {};
  427. data.currPage = Number(that.data.currPage) + 1;
  428. if(!isMerge){
  429. //不合并,页码需要重新设置为1
  430. data.currPage = 1;
  431. }
  432. apiServer.getNewsList(data).then((res)=>{
  433. if(res.statusCode == 200){
  434. let aa = that.data.aa;
  435. if(!isMerge){
  436. aa = [];
  437. }
  438. aa = aa.concat(res.data.data.incInfos)
  439. that.setData({
  440. aa,
  441. currPage:res.data.data.current,
  442. pages: res.data.data.pages,
  443. total: res.data.data.total,
  444. loading:false
  445. })
  446. }
  447. // that.isLoading = false
  448. wx.stopPullDownRefresh();
  449. // setTimeout(function(){
  450. // wx.hideLoading()
  451. // },500)
  452. })
  453. }