gameDetail.js 4.0 KB

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