item.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812
  1. // pages/item/item.js
  2. import * as echarts from '../../ec-canvas/echarts';
  3. var Api = require('../../utils/api.js');
  4. var wxRequest = require('../../utils/wxRequest.js')
  5. var timeData = [
  6. '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',
  7. ];
  8. timeData = timeData.map(function (str) {
  9. return str.replace('2009/', '');
  10. });
  11. var app = getApp()
  12. // let chart = null;
  13. let real=null
  14. let under=null
  15. // function initChart(canvas, width, height, dpr, data) {
  16. // const chart = echarts.init(canvas, null, {
  17. // width: width,
  18. // height: height,
  19. // devicePixelRatio: dpr // new
  20. // });
  21. // canvas.setChart(chart);
  22. // var option ={
  23. // title: {//标题
  24. // text: '',
  25. // left: 'center'
  26. // },
  27. // tooltip: {
  28. // trigger: 'axis',
  29. // axisPointer: {
  30. // type: 'cross',
  31. // label: {
  32. // backgroundColor: '#6a7985'
  33. // }
  34. // }
  35. // },
  36. // renderAsImage: true, //支持渲染为图片模式
  37. // color: [data.color, "#80CDF8"],//图例图标颜色
  38. // legend: {
  39. // show: true,
  40. // itemGap: 25,//每个图例间的间隔
  41. // // top: 30,
  42. // x: 30,//水平安放位置,离容器左侧的距离 'left'
  43. // z: 100,
  44. // textStyle: {
  45. // color: '#383838'
  46. // },
  47. // },
  48. // grid: {//网格
  49. // // left: 30,
  50. // // top:100,
  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.fals 数据点在分割线上,即刻度值上
  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 -7: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. // splitLine: {//坐标轴在 grid 区域中的分隔线。
  108. // show: true,
  109. // lineStyle: {
  110. // type: 'dashed',
  111. // color: ['#2B2B2B']
  112. // }
  113. // },
  114. // axisLabel: {//坐标轴刻度标签
  115. // // formatter: function (value) {
  116. // // var xLable = [];
  117. // // if (value == 20) {
  118. // // xLable.push('25,883');
  119. // // }
  120. // // if (value == 40) {
  121. // // xLable.push('26,035');
  122. // // }
  123. // // if (value == 60) {
  124. // // xLable.push('26,187');
  125. // // }
  126. // // if (value == 80) {
  127. // // xLable.push('26,339');
  128. // // }
  129. // // return xLable
  130. // // },
  131. // textStyle: {
  132. // fontSize: 13,
  133. // color: '#5D5D5D',
  134. // }
  135. // },
  136. // // min: 0,
  137. // // max: 100,
  138. // },
  139. // series: [{
  140. // name: '实际',
  141. // type: 'line',
  142. // // smooth:true,
  143. // data:data.actual,
  144. // symbol: 'none',
  145. // areaStyle: {
  146. // color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
  147. // offset: 0,
  148. // color: data.color
  149. // }, {
  150. // offset: 1,
  151. // color: '#1C1C1C'
  152. // }])
  153. // },
  154. // itemStyle: {
  155. // normal: {
  156. // lineStyle: {
  157. // color: data.color
  158. // }
  159. // }
  160. // }
  161. // }, {
  162. // name: '预测',
  163. // type: 'line',
  164. // data: data.prediction,
  165. // symbol: 'none',
  166. // itemStyle: {
  167. // normal: {
  168. // lineStyle: {
  169. // color: '#80CDF8'
  170. // }
  171. // }
  172. // }
  173. // }],
  174. // };
  175. // chart.setOption(option);
  176. // return chart;
  177. // }
  178. Page({
  179. /**
  180. * 页面的初始数据
  181. */
  182. data: {
  183. // 页面配置
  184. winWidth: 0,
  185. winHeight: 0,
  186. // tab切换
  187. currentTab: 0,
  188. follow:"",
  189. ec: {
  190. onInit: true
  191. },
  192. realchartData:{
  193. // actual:[5372,5556,3555,4734,5567,5556,3545,null,null],
  194. // prediction:[5722,5246,3555,4744,5542,5756,3755,2235,4556],
  195. // timeData : [
  196. // '2020/6/1', '2020/6/2', '2020/6/3', '2020/6/4', '2020/6/5', '2020/6/6', '2020/6/7',"sss","dsd"
  197. // ],
  198. // color:"crimson"
  199. },
  200. nextchartData:{
  201. // actual:[572,556,3555,4744,552,576,3555],
  202. // prediction:[352,246,385,2424,542,546,255],
  203. // timeData : [
  204. // '2020/6/1', '2020/6/2', '2020/6/3', '2020/6/4', '2020/6/5', '2020/6/6', '2020/6/7'
  205. // ],
  206. // color:"crimson"
  207. },
  208. object:{
  209. Name:"appl",
  210. value:"545455",
  211. color:'crimson',
  212. plateId:""
  213. },
  214. newsData:[],
  215. },
  216. catchTouchMove:function(res){
  217. return false
  218. },
  219. // 滑动切换tab
  220. bindChange: function(e) {
  221. var that = this;
  222. that.setData({
  223. currentTab: e.detail.current
  224. })
  225. },
  226. //点击新闻
  227. onFold:function(e){
  228. console.log( e.currentTarget.dataset.id);
  229. wx.navigateTo({
  230. url:"../news/news?newsId="+e.currentTarget.dataset.id
  231. });
  232. },
  233. // 点击tab切换
  234. swichNav: function(e) {
  235. // console.log(e)
  236. var that = this;
  237. if (this.data.currentTab === e.target.dataset.current) {
  238. return false;
  239. } else {
  240. that.setData({
  241. currentTab: e.target.dataset.current
  242. })
  243. }
  244. },
  245. /**
  246. * 生命周期函数--监听页面加载
  247. */
  248. onLoad: function (options) {
  249. var that = this;
  250. var Name = "object.Name"
  251. var value = "object.value"
  252. var color='object.color'
  253. var plateId='object.plateId'
  254. let Values,colors
  255. this.actualComponent = this.selectComponent('#mychart-dom-line-actual');
  256. this.underComponnet = this.selectComponent('#mychart-dom-line-under');
  257. if(JSON.parse(options.row).industryTag){
  258. Values="+"+JSON.parse(options.row).industryValue.toFixed(2)+"%";
  259. colors="#D81E06";
  260. }else{
  261. Values=JSON.parse(options.row).industryValue.toFixed(2)+"%"
  262. colors="#07c160"
  263. }
  264. this.setData({
  265. [Name]:JSON.parse(options.row).industryName,
  266. [plateId]:JSON.parse(options.row).industryId,
  267. [value]:Values,
  268. [color]:colors,
  269. })
  270. that.posthisfind(JSON.parse(options.row).industryId,)
  271. that.postpredfind(JSON.parse(options.row).industryId,)
  272. // console.log(app.globalData.userInfo)
  273. },
  274. onPullDownRefresh: function () {
  275. console.log('sss')
  276. wx.showNavigationBarLoading()
  277. var that = this;
  278. this.onLoad(); //重新加载onLoad()
  279. },
  280. postfollow:function(){
  281. var that = this;
  282. var data={
  283. plateId: this.data.object.plateId,
  284. plateName: this.data.object.Name,
  285. userId: wx.getStorageSync('openid'),
  286. userName: app.globalData.userInfo.nickName,
  287. }
  288. var postfollow = wxRequest.postRequest(Api.postfollow(),data);
  289. var postfollowcancel=wxRequest.postRequest(Api.postfollowcancel(),data);
  290. if(this.data.follow=="关注"){
  291. postfollow.then((res)=>{
  292. if(res.statusCode==200){
  293. that.setData({
  294. follow:res.data.data==1? "已关注":"关注"
  295. })
  296. wx.showToast({
  297. title: res.data.message,
  298. icon: 'success',
  299. duration: 2000
  300. })
  301. }
  302. })
  303. }else{
  304. postfollowcancel.then((res)=>{
  305. if(res.statusCode==200){
  306. that.setData({
  307. follow:res.data.data==1? "关注":"已关注"
  308. })
  309. wx.showToast({
  310. title: res.data.message,
  311. icon: 'success',
  312. duration: 2000
  313. })
  314. }
  315. })
  316. }
  317. },
  318. //获取数据
  319. posthisfind:function(row){
  320. // console.log(row)
  321. var that = this;
  322. var data=[{
  323. plateId: row,
  324. userId: wx.getStorageSync('openid')
  325. }
  326. ]
  327. var postbyiid = wxRequest.postRequest(Api.posthisfind(),data);
  328. wx.showLoading({title: '加载中…'})
  329. postbyiid.then((res)=>{
  330. console.log(res)
  331. wx.hideLoading()
  332. wx.stopPullDownRefresh()
  333. // console.log(that.recursion(res.data))
  334. if(res.statusCode==200){
  335. that.setData({
  336. // realchartData:that.recursion(res.data.data),
  337. newsData:res.data.data.news,
  338. follow:res.data.data.isFollowed ? "已关注":"关注"
  339. })
  340. // initChart(real.detail.canvas, real.detail.width, real.detail.height,real.detail.dpr,that.recursion(res.data.data));
  341. this.actualComponent.init((canvas, width, height,dpr) => {
  342. // 初始化图表
  343. const Chart = echarts.init(canvas, null, {
  344. width: width,
  345. height: height,
  346. devicePixelRatio: dpr // new
  347. });
  348. Chart.setOption(this.getOption(that.recursion(res.data.data)));
  349. return Chart;
  350. });
  351. }
  352. })
  353. },
  354. // echartInit(e) {
  355. // real=e
  356. // // initChart(e.detail.canvas, e.detail.width, e.detail.height,e.detail.dpr,e.target.dataset.record);
  357. // },
  358. // echartInitunder(e){
  359. // under=e
  360. // // initChart(e.detail.canvas, e.detail.width, e.detail.height,e.detail.dpr,e.target.dataset.record);
  361. // },
  362. //获取下周预测数据
  363. postpredfind:function(row){
  364. var that = this;
  365. var data=[ {
  366. plateId: row,
  367. userId: wx.getStorageSync('openid')
  368. }
  369. ]
  370. var postbyiid = wxRequest.postRequest(Api.postpredfind(),data);
  371. wx.showLoading({title: '加载中…'})
  372. postbyiid.then((res)=>{
  373. wx.hideLoading()
  374. wx.stopPullDownRefresh()
  375. if(res.statusCode==200){
  376. that.setData({
  377. // nextchartData:that.recursion(res.data.data),
  378. })
  379. // initChart(under.detail.canvas, under.detail.width, under.detail.height,under.detail.dpr,that.recursion(res.data.data));
  380. this.underComponnet.init((canvas, width, height,dpr) => {
  381. // 初始化图表
  382. const Chart = echarts.init(canvas, null, {
  383. width: width,
  384. height: height,
  385. devicePixelRatio: dpr // new
  386. });
  387. Chart.setOption(this.getOption(that.recursion(res.data.data)));
  388. return Chart;
  389. });
  390. }
  391. })
  392. },
  393. recursion:function(row,a=[],b=[],c=[],d){
  394. for(let i in row.actuals){
  395. a.unshift(row.actuals[i].industryDate)
  396. b.unshift(row.actuals[i].close)
  397. c.unshift(row.actuals[i].pred)
  398. }
  399. // if(row.tag){
  400. // d="#D81E06"
  401. // }else{
  402. // d="#07c160"
  403. // }
  404. d=this.data.object.color
  405. return {"timeData":a,"actual":b,"prediction":c,"color":d}
  406. },
  407. getOption:function(data){
  408. return {
  409. title: {//标题
  410. text: '',
  411. left: 'center'
  412. },
  413. tooltip: {
  414. trigger: 'axis',
  415. axisPointer: {
  416. type: 'cross',
  417. label: {
  418. backgroundColor: '#6a7985'
  419. }
  420. }
  421. },
  422. renderAsImage: true, //支持渲染为图片模式
  423. color: [data.color, "#80CDF8"],//图例图标颜色
  424. legend: {
  425. show: true,
  426. itemGap: 25,//每个图例间的间隔
  427. // top: 30,
  428. x: 30,//水平安放位置,离容器左侧的距离 'left'
  429. z: 100,
  430. textStyle: {
  431. color: '#383838'
  432. },
  433. },
  434. grid: {//网格
  435. // left: 30,
  436. // top:100,
  437. containLabel: true,//grid 区域是否包含坐标轴的刻度标签
  438. },
  439. xAxis: {//横坐标
  440. type: 'category',
  441. // nameTextStyle: {//在name值存在下,设置name的样式
  442. // color: 'white',
  443. // fontStyle: 'normal'
  444. // },
  445. nameLocation:'end',
  446. splitLine: {//坐标轴在 grid 区域中的分隔线。
  447. show: true,
  448. lineStyle: {
  449. type: 'dashed',
  450. color: ['#2B2B2B']
  451. }
  452. },
  453. boundaryGap: false,//1.true 数据点在2个刻度直接 2.fals 数据点在分割线上,即刻度值上
  454. data: data.timeData,
  455. axisLine: {onZero: true},
  456. axisLabel: {
  457. textStyle: {
  458. fontSize: 13,
  459. color: '#5D5D5D'
  460. }
  461. }
  462. },
  463. dataZoom: [
  464. {
  465. type: 'slider',
  466. xAxisIndex: 0,
  467. filterMode: 'empty',
  468. // startValue: data.prediction? data.prediction.length -7:0,
  469. // endValue: data.prediction?data.prediction.length:3 ,
  470. 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',
  471. handleSize: '80%',
  472. handleStyle: {
  473. color: '#fff',
  474. shadowBlur: 3,
  475. shadowColor: 'rgba(0, 0, 0, 0.6)',
  476. shadowOffsetX: 2,
  477. shadowOffsetY: 2
  478. }
  479. },
  480. {
  481. type: 'inside',
  482. realtime: true,
  483. }
  484. ],
  485. yAxis: {//纵坐标
  486. type: 'value',
  487. position:'right',
  488. // nameTextStyle:{//在name值存在下,设置name的样式
  489. // color:'red',
  490. // fontStyle:'normal'
  491. // },
  492. splitNumber: 5,//坐标轴的分割段数
  493. scale:true,
  494. splitLine: {//坐标轴在 grid 区域中的分隔线。
  495. show: true,
  496. lineStyle: {
  497. type: 'dashed',
  498. color: ['#2B2B2B']
  499. }
  500. },
  501. axisLabel: {//坐标轴刻度标签
  502. // formatter: function (value) {
  503. // var xLable = [];
  504. // if (value == 20) {
  505. // xLable.push('25,883');
  506. // }
  507. // if (value == 40) {
  508. // xLable.push('26,035');
  509. // }
  510. // if (value == 60) {
  511. // xLable.push('26,187');
  512. // }
  513. // if (value == 80) {
  514. // xLable.push('26,339');
  515. // }
  516. // return xLable
  517. // },
  518. textStyle: {
  519. fontSize: 13,
  520. color: '#5D5D5D',
  521. }
  522. },
  523. // min: 0,
  524. // max: 100,
  525. },
  526. series: [{
  527. name: '实际',
  528. type: 'line',
  529. // smooth:true,
  530. data:data.actual,
  531. symbol: 'none',
  532. areaStyle: {
  533. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
  534. offset: 0,
  535. color: data.color
  536. }, {
  537. offset: 1,
  538. color: '#1C1C1C'
  539. }])
  540. },
  541. itemStyle: {
  542. normal: {
  543. lineStyle: {
  544. color: data.color
  545. }
  546. }
  547. }
  548. }, {
  549. name: '预测',
  550. type: 'line',
  551. data: data.prediction,
  552. symbol: 'none',
  553. itemStyle: {
  554. normal: {
  555. lineStyle: {
  556. color: '#80CDF8'
  557. }
  558. }
  559. }
  560. }],
  561. };
  562. },
  563. /**
  564. * 生命周期函数--监听页面初次渲染完成
  565. */
  566. onReady: function () {
  567. },
  568. /**
  569. * 生命周期函数--监听页面显示
  570. */
  571. onShow: function () {
  572. },
  573. /**
  574. * 生命周期函数--监听页面隐藏
  575. */
  576. onHide: function () {
  577. },
  578. /**
  579. * 生命周期函数--监听页面卸载
  580. */
  581. onUnload: function () {
  582. },
  583. /**
  584. * 页面上拉触底事件的处理函数
  585. */
  586. onReachBottom: function () {
  587. },
  588. /**
  589. * 用户点击右上角分享
  590. */
  591. onShareAppMessage: function () {
  592. }
  593. })