item.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804
  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: initChart
  191. },
  192. realchartData:{
  193. // actual:[572,556,3555,4744,552,576,3555],
  194. // prediction:[572,556,3555,4744,552,576,3555],
  195. // timeData : [
  196. // '2020/6/1', '2020/6/2', '2020/6/3', '2020/6/4', '2020/6/5', '2020/6/6', '2020/6/7'
  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. // console.log(options)
  250. var that = this;
  251. var Name = "object.Name"
  252. var value = "object.value"
  253. var color='object.color'
  254. var plateId='object.plateId'
  255. let Values,colors
  256. this.actualComponent = this.selectComponent('#mychart-dom-line-actual');
  257. this.underComponnet = this.selectComponent('#mychart-dom-line-under');
  258. if(JSON.parse(options.row).industryTag){
  259. Values="+"+JSON.parse(options.row).industryValue.toFixed(2)+"%";
  260. colors="#D81E06";
  261. }else{
  262. Values=JSON.parse(options.row).industryValue.toFixed(2)+"%"
  263. colors="#07c160"
  264. }
  265. this.setData({
  266. [Name]:JSON.parse(options.row).industryName,
  267. [plateId]:JSON.parse(options.row).industryId,
  268. [value]:Values,
  269. [color]:colors,
  270. })
  271. that.posthisfind(JSON.parse(options.row).industryId,)
  272. that.postpredfind(JSON.parse(options.row).industryId,)
  273. console.log(app.globalData.userInfo)
  274. },
  275. postfollow:function(){
  276. var that = this;
  277. var data={
  278. plateId: this.data.object.plateId,
  279. plateName: this.data.object.Name,
  280. userId: wx.getStorageSync('openid'),
  281. userName: app.globalData.userInfo.nickName,
  282. }
  283. var postfollow = wxRequest.postRequest(Api.postfollow(),data);
  284. var postfollowcancel=wxRequest.postRequest(Api.postfollowcancel(),data);
  285. if(this.data.follow=="关注"){
  286. postfollow.then((res)=>{
  287. if(res.statusCode==200){
  288. that.setData({
  289. follow:res.data.data==1? "已关注":"关注"
  290. })
  291. wx.showToast({
  292. title: res.data.message,
  293. icon: 'success',
  294. duration: 2000
  295. })
  296. }
  297. })
  298. }else{
  299. postfollowcancel.then((res)=>{
  300. if(res.statusCode==200){
  301. that.setData({
  302. follow:res.data.data==1? "关注":"已关注"
  303. })
  304. wx.showToast({
  305. title: res.data.message,
  306. icon: 'success',
  307. duration: 2000
  308. })
  309. }
  310. })
  311. }
  312. },
  313. //获取数据
  314. posthisfind:function(row){
  315. // console.log(row)
  316. var that = this;
  317. var data=[{
  318. plateId: row,
  319. userId: wx.getStorageSync('openid')
  320. }
  321. ]
  322. var postbyiid = wxRequest.postRequest(Api.posthisfind(),data);
  323. postbyiid.then((res)=>{
  324. console.log(res)
  325. // console.log(that.recursion(res.data))
  326. if(res.statusCode==200){
  327. that.setData({
  328. realchartData:that.recursion(res.data.data),
  329. newsData:res.data.data.news,
  330. follow:res.data.data.isFollowed ? "已关注":"关注"
  331. })
  332. // initChart(real.detail.canvas, real.detail.width, real.detail.height,real.detail.dpr,that.recursion(res.data.data));
  333. this.actualComponent.init((canvas, width, height) => {
  334. // 初始化图表
  335. const Chart = echarts.init(canvas, null, {
  336. width: width,
  337. height: height
  338. });
  339. Chart.setOption(this.getOption(that.recursion(res.data.data)));
  340. return Chart;
  341. });
  342. }
  343. })
  344. },
  345. // echartInit(e) {
  346. // real=e
  347. // // initChart(e.detail.canvas, e.detail.width, e.detail.height,e.detail.dpr,e.target.dataset.record);
  348. // },
  349. // echartInitunder(e){
  350. // under=e
  351. // // initChart(e.detail.canvas, e.detail.width, e.detail.height,e.detail.dpr,e.target.dataset.record);
  352. // },
  353. //获取下周预测数据
  354. postpredfind:function(row){
  355. var that = this;
  356. var data=[ {
  357. plateId: row,
  358. userId: wx.getStorageSync('openid')
  359. }
  360. ]
  361. var postbyiid = wxRequest.postRequest(Api.postpredfind(),data);
  362. postbyiid.then((res)=>{
  363. if(res.statusCode==200){
  364. that.setData({
  365. nextchartData:that.recursion(res.data.data),
  366. })
  367. // initChart(under.detail.canvas, under.detail.width, under.detail.height,under.detail.dpr,that.recursion(res.data.data));
  368. this.underComponnet.init((canvas, width, height) => {
  369. // 初始化图表
  370. const Chart = echarts.init(canvas, null, {
  371. width: width,
  372. height: height
  373. });
  374. Chart.setOption(this.getOption(that.recursion(res.data.data)));
  375. return Chart;
  376. });
  377. }
  378. })
  379. },
  380. recursion:function(row,a=[],b=[],c=[],d){
  381. for(let i in row.actuals){
  382. a.unshift(row.actuals[i].industryDate)
  383. b.unshift(row.actuals[i].close)
  384. c.unshift(row.actuals[i].pred)
  385. }
  386. if(row.tag){
  387. d="#D81E06"
  388. }else{
  389. d="#07c160"
  390. }
  391. return {"timeData":a,"actual":b,"prediction":c,"color":d}
  392. },
  393. getOption:function(data){
  394. return {
  395. title: {//标题
  396. text: '',
  397. left: 'center'
  398. },
  399. tooltip: {
  400. trigger: 'axis',
  401. axisPointer: {
  402. type: 'cross',
  403. label: {
  404. backgroundColor: '#6a7985'
  405. }
  406. }
  407. },
  408. renderAsImage: true, //支持渲染为图片模式
  409. color: [data.color, "#80CDF8"],//图例图标颜色
  410. legend: {
  411. show: true,
  412. itemGap: 25,//每个图例间的间隔
  413. // top: 30,
  414. x: 30,//水平安放位置,离容器左侧的距离 'left'
  415. z: 100,
  416. textStyle: {
  417. color: '#383838'
  418. },
  419. },
  420. grid: {//网格
  421. // left: 30,
  422. // top:100,
  423. containLabel: true,//grid 区域是否包含坐标轴的刻度标签
  424. },
  425. xAxis: {//横坐标
  426. type: 'category',
  427. // nameTextStyle: {//在name值存在下,设置name的样式
  428. // color: 'white',
  429. // fontStyle: 'normal'
  430. // },
  431. nameLocation:'end',
  432. splitLine: {//坐标轴在 grid 区域中的分隔线。
  433. show: true,
  434. lineStyle: {
  435. type: 'dashed',
  436. color: ['#2B2B2B']
  437. }
  438. },
  439. boundaryGap: false,//1.true 数据点在2个刻度直接 2.fals 数据点在分割线上,即刻度值上
  440. data: data.timeData,
  441. axisLine: {onZero: true},
  442. axisLabel: {
  443. textStyle: {
  444. fontSize: 13,
  445. color: '#5D5D5D'
  446. }
  447. }
  448. },
  449. dataZoom: [
  450. {
  451. type: 'slider',
  452. xAxisIndex: 0,
  453. filterMode: 'empty',
  454. // startValue: data.prediction? data.prediction.length -7:0,
  455. // endValue: data.prediction?data.prediction.length:3 ,
  456. 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',
  457. handleSize: '80%',
  458. handleStyle: {
  459. color: '#fff',
  460. shadowBlur: 3,
  461. shadowColor: 'rgba(0, 0, 0, 0.6)',
  462. shadowOffsetX: 2,
  463. shadowOffsetY: 2
  464. }
  465. },
  466. {
  467. type: 'inside',
  468. realtime: true,
  469. }
  470. ],
  471. yAxis: {//纵坐标
  472. type: 'value',
  473. position:'right',
  474. // nameTextStyle:{//在name值存在下,设置name的样式
  475. // color:'red',
  476. // fontStyle:'normal'
  477. // },
  478. splitNumber: 5,//坐标轴的分割段数
  479. splitLine: {//坐标轴在 grid 区域中的分隔线。
  480. show: true,
  481. lineStyle: {
  482. type: 'dashed',
  483. color: ['#2B2B2B']
  484. }
  485. },
  486. axisLabel: {//坐标轴刻度标签
  487. // formatter: function (value) {
  488. // var xLable = [];
  489. // if (value == 20) {
  490. // xLable.push('25,883');
  491. // }
  492. // if (value == 40) {
  493. // xLable.push('26,035');
  494. // }
  495. // if (value == 60) {
  496. // xLable.push('26,187');
  497. // }
  498. // if (value == 80) {
  499. // xLable.push('26,339');
  500. // }
  501. // return xLable
  502. // },
  503. textStyle: {
  504. fontSize: 13,
  505. color: '#5D5D5D',
  506. }
  507. },
  508. // min: 0,
  509. // max: 100,
  510. },
  511. series: [{
  512. name: '实际',
  513. type: 'line',
  514. // smooth:true,
  515. data:data.actual,
  516. symbol: 'none',
  517. areaStyle: {
  518. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
  519. offset: 0,
  520. color: data.color
  521. }, {
  522. offset: 1,
  523. color: '#1C1C1C'
  524. }])
  525. },
  526. itemStyle: {
  527. normal: {
  528. lineStyle: {
  529. color: data.color
  530. }
  531. }
  532. }
  533. }, {
  534. name: '预测',
  535. type: 'line',
  536. data: data.prediction,
  537. symbol: 'none',
  538. itemStyle: {
  539. normal: {
  540. lineStyle: {
  541. color: '#80CDF8'
  542. }
  543. }
  544. }
  545. }],
  546. };
  547. },
  548. /**
  549. * 生命周期函数--监听页面初次渲染完成
  550. */
  551. onReady: function () {
  552. },
  553. /**
  554. * 生命周期函数--监听页面显示
  555. */
  556. onShow: function () {
  557. },
  558. /**
  559. * 生命周期函数--监听页面隐藏
  560. */
  561. onHide: function () {
  562. },
  563. /**
  564. * 生命周期函数--监听页面卸载
  565. */
  566. onUnload: function () {
  567. },
  568. /**
  569. * 页面相关事件处理函数--监听用户下拉动作
  570. */
  571. onPullDownRefresh: function () {
  572. },
  573. /**
  574. * 页面上拉触底事件的处理函数
  575. */
  576. onReachBottom: function () {
  577. },
  578. /**
  579. * 用户点击右上角分享
  580. */
  581. onShareAppMessage: function () {
  582. }
  583. })