gameDetail.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. import * as echarts from '../../ec-canvas/echarts';
  2. const app = getApp();
  3. var host = app.globalData.host;
  4. var id, record_id;
  5. Page({
  6. onShareAppMessage: function (res) {
  7. return {
  8. title: 'ECharts 可以在微信小程序中使用啦!',
  9. path: '/pages/index/index',
  10. success: function () { },
  11. fail: function () { }
  12. }
  13. },
  14. data: {
  15. ec: {
  16. onInit: initChart
  17. }
  18. },
  19. onLoad(options) {
  20. id = options.id, record_id = options.record_id
  21. this.setData({
  22. id:id,
  23. record_id: record_id
  24. })
  25. wx.showNavigationBarLoading()
  26. /**获取token */
  27. wx.getStorage({
  28. key: 'userInfo',
  29. success: res => {
  30. this.setData({
  31. userInfo: res.data
  32. })
  33. this.getData(id, record_id);
  34. },
  35. fail: error => {
  36. //跳转到登陆页面
  37. wx.switchTab({
  38. url: '../user/user',
  39. })
  40. }
  41. })
  42. },
  43. getData(id, record_id) {
  44. var data={}
  45. if(id){
  46. data.id=id
  47. }
  48. if (record_id) {
  49. data.record_id = record_id
  50. }
  51. wx.request({
  52. url: host + '/api/wx/player/match',
  53. data: data,
  54. header: {
  55. 'Authorization': this.data.userInfo.token
  56. },
  57. success: res => {
  58. console.log(res)
  59. this.setData({
  60. datas: res.data.data
  61. })
  62. wx.hideNavigationBarLoading()
  63. },
  64. fail: error => {
  65. //跳转到登陆页面
  66. wx.switchTab({
  67. url: '../user/user',
  68. })
  69. }
  70. })
  71. },
  72. });
  73. /**折线图 */
  74. function initChart(canvas, width, height, dpr) {
  75. var data = {}
  76. if (id) {
  77. data.id = id
  78. }
  79. if (record_id) {
  80. data.record_id = record_id
  81. }
  82. wx.getStorage({
  83. key: 'userInfo',
  84. success: res => {
  85. var info = res.data
  86. wx.request({
  87. url: host + '/api/wx/player/match',
  88. data: data,
  89. header: {
  90. 'Authorization': info.token
  91. },
  92. success: res => {
  93. var records = res.data.data.records, xdata = [], ydata = [];
  94. for (let i = 0; i < records.length; i++) {
  95. let date = records[i].stock_date.split('-');
  96. xdata.push(date[1] + '/' + date[2])
  97. ydata.push(records[i].today_fund)
  98. }
  99. xdata = xdata.reverse()
  100. ydata = ydata.reverse()
  101. const chart = echarts.init(canvas, null, {
  102. width: width,
  103. height: height,
  104. devicePixelRatio: dpr // new
  105. });
  106. canvas.setChart(chart);
  107. var option = {
  108. legend: {
  109. show: false
  110. },
  111. grid: {
  112. x: 35,
  113. y: 40,
  114. x2: 10,
  115. y2: 35
  116. },
  117. tooltip: {
  118. show: true,
  119. trigger: 'axis'
  120. },
  121. xAxis: {
  122. type: 'category',
  123. data: xdata,
  124. axisLabel: {
  125. interval: 0,
  126. rotate: 40,
  127. color: '#999999'
  128. }
  129. },
  130. yAxis: {
  131. axisLine: {
  132. show: true
  133. },
  134. type: 'value',
  135. name: '收益曲线',
  136. },
  137. series: [{
  138. name: 'A',
  139. type: 'line',
  140. smooth: true,
  141. symbolSize: 8,
  142. lineStyle: {
  143. color: new echarts.graphic.LinearGradient(1, 0, 0, 0, [{
  144. offset: 0,
  145. color: '#FF2D68'
  146. }, {
  147. offset: 1,
  148. color: '#4C4BFF'
  149. }]),
  150. },
  151. itemStyle: {
  152. borderWidth: 5,
  153. borderColor: '#FFAD52',
  154. color: '#FFAD52'
  155. },
  156. data: ydata
  157. }]
  158. };
  159. chart.setOption(option);
  160. return chart;
  161. }
  162. })
  163. },
  164. })
  165. }