item.js 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  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. chart = echarts.init(canvas, null, {
  17. width: width,
  18. height: height,
  19. devicePixelRatio: dpr // new
  20. });
  21. canvas.setChart(chart);
  22. console.log(data)
  23. var option ={
  24. title: {//标题
  25. text: '',
  26. left: 'center'
  27. },
  28. tooltip: {
  29. trigger: 'axis',
  30. axisPointer: {
  31. type: 'cross',
  32. label: {
  33. backgroundColor: '#6a7985'
  34. }
  35. }
  36. },
  37. renderAsImage: true, //支持渲染为图片模式
  38. color: [data.color, "#80CDF8"],//图例图标颜色
  39. legend: {
  40. show: true,
  41. itemGap: 25,//每个图例间的间隔
  42. // top: 30,
  43. x: 30,//水平安放位置,离容器左侧的距离 'left'
  44. z: 100,
  45. textStyle: {
  46. color: '#383838'
  47. },
  48. },
  49. grid: {//网格
  50. // left: 30,
  51. // top:100,
  52. containLabel: true,//grid 区域是否包含坐标轴的刻度标签
  53. },
  54. xAxis: {//横坐标
  55. type: 'category',
  56. // nameTextStyle: {//在name值存在下,设置name的样式
  57. // color: 'white',
  58. // fontStyle: 'normal'
  59. // },
  60. nameLocation:'end',
  61. splitLine: {//坐标轴在 grid 区域中的分隔线。
  62. show: true,
  63. lineStyle: {
  64. type: 'dashed',
  65. color: ['#2B2B2B']
  66. }
  67. },
  68. boundaryGap: false,//1.true 数据点在2个刻度直接 2.fals 数据点在分割线上,即刻度值上
  69. data: data.timeData,
  70. axisLine: {onZero: true},
  71. axisLabel: {
  72. textStyle: {
  73. fontSize: 13,
  74. color: '#5D5D5D'
  75. }
  76. }
  77. },
  78. dataZoom: [
  79. {
  80. type: 'slider',
  81. xAxisIndex: 0,
  82. filterMode: 'empty',
  83. // startValue: data.prediction? data.prediction.length -7:0,
  84. // endValue: data.prediction?data.prediction.length:3 ,
  85. 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',
  86. handleSize: '80%',
  87. handleStyle: {
  88. color: '#fff',
  89. shadowBlur: 3,
  90. shadowColor: 'rgba(0, 0, 0, 0.6)',
  91. shadowOffsetX: 2,
  92. shadowOffsetY: 2
  93. }
  94. },
  95. {
  96. type: 'inside',
  97. realtime: true,
  98. }
  99. ],
  100. yAxis: {//纵坐标
  101. type: 'value',
  102. position:'right',
  103. // nameTextStyle:{//在name值存在下,设置name的样式
  104. // color:'red',
  105. // fontStyle:'normal'
  106. // },
  107. splitNumber: 5,//坐标轴的分割段数
  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: data.color
  150. }, {
  151. offset: 1,
  152. color: '#1C1C1C'
  153. }])
  154. },
  155. itemStyle: {
  156. normal: {
  157. lineStyle: {
  158. color: data.color
  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. /**
  181. * 页面的初始数据
  182. */
  183. data: {
  184. // 页面配置
  185. winWidth: 0,
  186. winHeight: 0,
  187. // tab切换
  188. currentTab: 0,
  189. button:"关注",
  190. ec: {
  191. // onInit: initChart
  192. },
  193. realchartData:{
  194. // actual:[572,556,3555,4744,552,576,3555],
  195. // prediction:[572,556,3555,4744,552,576,3555],
  196. // timeData : [
  197. // '2020/6/1', '2020/6/2', '2020/6/3', '2020/6/4', '2020/6/5', '2020/6/6', '2020/6/7'
  198. // ],
  199. // color:"crimson"
  200. },
  201. nextchartData:{
  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. // color:"crimson"
  208. },
  209. object:{
  210. Name:"appl",
  211. value:"545455",
  212. color:'crimson',
  213. plateId:""
  214. },
  215. newsData:[],
  216. },
  217. catchTouchMove:function(res){
  218. return false
  219. },
  220. // 滑动切换tab
  221. bindChange: function(e) {
  222. var that = this;
  223. that.setData({
  224. currentTab: e.detail.current
  225. })
  226. },
  227. //点击新闻
  228. onFold:function(e){
  229. console.log( e.currentTarget.dataset.id);
  230. wx.navigateTo({
  231. url:"../news/news?newsId="+e.currentTarget.dataset.id
  232. });
  233. },
  234. // 点击tab切换
  235. swichNav: function(e) {
  236. // console.log(e)
  237. var that = this;
  238. if (this.data.currentTab === e.target.dataset.current) {
  239. return false;
  240. } else {
  241. that.setData({
  242. currentTab: e.target.dataset.current
  243. })
  244. }
  245. },
  246. /**
  247. * 生命周期函数--监听页面加载
  248. */
  249. onLoad: function (options) {
  250. // console.log(options)
  251. var that = this;
  252. var Name = "object.Name"
  253. var value = "object.value"
  254. var color='object.color'
  255. var plateId='object.plateId'
  256. let Values,colors
  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. console.log(app.globalData.userInfo)
  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. that.postfollow()
  274. },
  275. postfollow:function(){
  276. var that = this;
  277. console.log(app.globalData.userInfo)
  278. var data={
  279. plateId: this.data.object.plateId,
  280. plateName: this.data.object.Name,
  281. userId: wx.getStorageSync('openid'),
  282. userName: app.globalData.userInfo.nickName,
  283. }
  284. console.log(data)
  285. var postfollow = wxRequest.postRequest(Api.postfollow(),data);
  286. },
  287. //获取数据
  288. posthisfind:function(row){
  289. // console.log(row)
  290. var that = this;
  291. var postbyiid = wxRequest.postRequest(Api.posthisfind(),[row]);
  292. postbyiid.then((res)=>{
  293. console.log(res)
  294. // console.log(that.recursion(res.data))
  295. if(res.statusCode==200){
  296. that.setData({
  297. realchartData:that.recursion(res.data.data),
  298. newsData:res.data.data.news,
  299. })
  300. initChart(real.detail.canvas, real.detail.width, real.detail.height,real.detail.dpr,that.recursion(res.data.data));
  301. }
  302. })
  303. },
  304. echartInit(e) {
  305. console.log(e);
  306. real=e
  307. // initChart(e.detail.canvas, e.detail.width, e.detail.height,e.detail.dpr,e.target.dataset.record);
  308. },
  309. echartInitunder(e){
  310. console.log(e);
  311. under=e
  312. // initChart(e.detail.canvas, e.detail.width, e.detail.height,e.detail.dpr,e.target.dataset.record);
  313. },
  314. //获取下周预测数据
  315. postpredfind:function(row){
  316. var that = this;
  317. var postbyiid = wxRequest.postRequest(Api.postpredfind(),[row]);
  318. postbyiid.then((res)=>{
  319. console.log(res)
  320. if(res.statusCode==200){
  321. that.setData({
  322. nextchartData:that.recursion(res.data.data),
  323. })
  324. initChart(under.detail.canvas, under.detail.width, under.detail.height,under.detail.dpr,that.recursion(res.data.data));
  325. }
  326. })
  327. },
  328. recursion:function(row,a=[],b=[],c=[],d){
  329. for(let i in row.actuals){
  330. a.unshift(row.actuals[i].industryDate)
  331. b.unshift(row.actuals[i].close)
  332. c.unshift(row.actuals[i].pred)
  333. }
  334. if(row.tag){
  335. d="#D81E06"
  336. }else{
  337. d="#07c160"
  338. }
  339. return {"timeData":a,"actual":b,"prediction":c,"color":d}
  340. },
  341. /**
  342. * 生命周期函数--监听页面初次渲染完成
  343. */
  344. onReady: function () {
  345. },
  346. /**
  347. * 生命周期函数--监听页面显示
  348. */
  349. onShow: function () {
  350. },
  351. /**
  352. * 生命周期函数--监听页面隐藏
  353. */
  354. onHide: function () {
  355. },
  356. /**
  357. * 生命周期函数--监听页面卸载
  358. */
  359. onUnload: function () {
  360. },
  361. /**
  362. * 页面相关事件处理函数--监听用户下拉动作
  363. */
  364. onPullDownRefresh: function () {
  365. },
  366. /**
  367. * 页面上拉触底事件的处理函数
  368. */
  369. onReachBottom: function () {
  370. },
  371. /**
  372. * 用户点击右上角分享
  373. */
  374. onShareAppMessage: function () {
  375. }
  376. })