item.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  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. 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. if(JSON.parse(options.row).industryTag){
  257. Values="+"+JSON.parse(options.row).industryValue.toFixed(2)+"%";
  258. colors="#D81E06";
  259. }else{
  260. Values=JSON.parse(options.row).industryValue.toFixed(2)+"%"
  261. colors="#07c160"
  262. }
  263. this.setData({
  264. [Name]:JSON.parse(options.row).industryName,
  265. [plateId]:JSON.parse(options.row).industryId,
  266. [value]:Values,
  267. [color]:colors,
  268. })
  269. that.posthisfind(JSON.parse(options.row).industryId,)
  270. that.postpredfind(JSON.parse(options.row).industryId,)
  271. },
  272. postfollow:function(){
  273. var that = this;
  274. var data={
  275. plateId: this.data.object.plateId,
  276. plateName: this.data.object.Name,
  277. userId: wx.getStorageSync('openid'),
  278. userName: app.globalData.userInfo.nickName,
  279. }
  280. var postfollow = wxRequest.postRequest(Api.postfollow(),data);
  281. postfollow.then((res)=>{
  282. if(res.statusCode==200){
  283. that.setData({
  284. follow:res.data.data==1? "已关注":"关注"
  285. })
  286. wx.showToast({
  287. title: res.data.message,
  288. icon: 'success',
  289. duration: 2000
  290. })
  291. }
  292. })
  293. },
  294. //获取数据
  295. posthisfind:function(row){
  296. // console.log(row)
  297. var that = this;
  298. var data=[{
  299. plateId: row,
  300. userId: wx.getStorageSync('openid')
  301. }
  302. ]
  303. var postbyiid = wxRequest.postRequest(Api.posthisfind(),data);
  304. postbyiid.then((res)=>{
  305. console.log(res)
  306. // console.log(that.recursion(res.data))
  307. if(res.statusCode==200){
  308. that.setData({
  309. realchartData:that.recursion(res.data.data),
  310. newsData:res.data.data.news,
  311. follow:res.data.data.isFollowed ? "已关注":"关注"
  312. })
  313. initChart(real.detail.canvas, real.detail.width, real.detail.height,real.detail.dpr,that.recursion(res.data.data));
  314. }
  315. })
  316. },
  317. echartInit(e) {
  318. real=e
  319. // initChart(e.detail.canvas, e.detail.width, e.detail.height,e.detail.dpr,e.target.dataset.record);
  320. },
  321. echartInitunder(e){
  322. under=e
  323. // initChart(e.detail.canvas, e.detail.width, e.detail.height,e.detail.dpr,e.target.dataset.record);
  324. },
  325. //获取下周预测数据
  326. postpredfind:function(row){
  327. var that = this;
  328. var data=[ {
  329. plateId: row,
  330. userId: wx.getStorageSync('openid')
  331. }
  332. ]
  333. var postbyiid = wxRequest.postRequest(Api.postpredfind(),data);
  334. postbyiid.then((res)=>{
  335. if(res.statusCode==200){
  336. that.setData({
  337. nextchartData:that.recursion(res.data.data),
  338. })
  339. initChart(under.detail.canvas, under.detail.width, under.detail.height,under.detail.dpr,that.recursion(res.data.data));
  340. }
  341. })
  342. },
  343. recursion:function(row,a=[],b=[],c=[],d){
  344. for(let i in row.actuals){
  345. a.unshift(row.actuals[i].industryDate)
  346. b.unshift(row.actuals[i].close)
  347. c.unshift(row.actuals[i].pred)
  348. }
  349. if(row.tag){
  350. d="#D81E06"
  351. }else{
  352. d="#07c160"
  353. }
  354. return {"timeData":a,"actual":b,"prediction":c,"color":d}
  355. },
  356. /**
  357. * 生命周期函数--监听页面初次渲染完成
  358. */
  359. onReady: function () {
  360. },
  361. /**
  362. * 生命周期函数--监听页面显示
  363. */
  364. onShow: function () {
  365. },
  366. /**
  367. * 生命周期函数--监听页面隐藏
  368. */
  369. onHide: function () {
  370. },
  371. /**
  372. * 生命周期函数--监听页面卸载
  373. */
  374. onUnload: function () {
  375. },
  376. /**
  377. * 页面相关事件处理函数--监听用户下拉动作
  378. */
  379. onPullDownRefresh: function () {
  380. },
  381. /**
  382. * 页面上拉触底事件的处理函数
  383. */
  384. onReachBottom: function () {
  385. },
  386. /**
  387. * 用户点击右上角分享
  388. */
  389. onShareAppMessage: function () {
  390. }
  391. })