today.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. // pages/today/today.js
  2. import * as echarts from '../../ec-canvas/echarts';
  3. const $api = require('../../utils/api.js').API;
  4. var id, record_id, records = [], today_stock=[];
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. ec: {
  11. onInit: null
  12. },
  13. ec1: {
  14. onInit: null
  15. }
  16. },
  17. /**
  18. * 生命周期函数--监听页面加载
  19. */
  20. onLoad: function (options) {
  21. // options.id = 7, options.record_id = 29014
  22. id = options.id, record_id = options.record_id
  23. this.setData({
  24. id: id,
  25. record_id: record_id,
  26. player_id: options.player_id ? options.player_id:''
  27. })
  28. this.getData();
  29. },
  30. getData(){
  31. wx.showNavigationBarLoading();
  32. var data = {}
  33. if (this.data.id) {
  34. data.id = this.data.id
  35. }
  36. if (this.data.record_id) {
  37. data.record_id = this.data.record_id
  38. }
  39. $api.getPlayerMatch(data).then(res=>{
  40. this.setData({
  41. datas: res.data.data,
  42. is_follow: res.data.data.is_follow,
  43. ec: {
  44. onInit: initChart
  45. },
  46. ec1: {
  47. onInit: initChart1
  48. }
  49. })
  50. records = res.data.data.records
  51. today_stock = res.data.data.today_record.today_stock
  52. wx.hideNavigationBarLoading()
  53. })
  54. .catch(err=>{
  55. wx.hideNavigationBarLoading()
  56. })
  57. //每日持股
  58. var parm={
  59. id: data.id, player_id: this.data.player_id
  60. }
  61. $api.getRecordList(parm).then(res=>{
  62. this.setData({
  63. stockList:res.data.data.list
  64. })
  65. })
  66. },
  67. //预览
  68. preview(e) {
  69. wx.previewImage({
  70. urls: e.target.dataset.urls,
  71. current: e.target.dataset.src
  72. })
  73. },
  74. followPlayer(e){
  75. let action = e.target.dataset.action;
  76. $api.follow({ follow_id: this.data.player_id, action:action}).then(res=>{
  77. wx.showToast({
  78. title: action?'取消成功':'已关注',
  79. })
  80. this.setData({
  81. is_follow: !this.data.is_follow
  82. })
  83. })
  84. },
  85. /**
  86. * 生命周期函数--监听页面初次渲染完成
  87. */
  88. onReady: function () {
  89. },
  90. /**
  91. * 生命周期函数--监听页面显示
  92. */
  93. onShow: function () {
  94. },
  95. /**
  96. * 生命周期函数--监听页面隐藏
  97. */
  98. onHide: function () {
  99. },
  100. /**
  101. * 生命周期函数--监听页面卸载
  102. */
  103. onUnload: function () {
  104. },
  105. /**
  106. * 页面相关事件处理函数--监听用户下拉动作
  107. */
  108. onPullDownRefresh: function () {
  109. },
  110. /**
  111. * 页面上拉触底事件的处理函数
  112. */
  113. onReachBottom: function () {
  114. },
  115. /**
  116. * 用户点击右上角分享
  117. */
  118. onShareAppMessage: function () {
  119. }
  120. })
  121. /**折线图 */
  122. function initChart(canvas, width, height, dpr) {
  123. var xdata = [], ydata = [];
  124. for (let i = 0; i < records.length; i++) {
  125. let date = records[i].stock_date.split('-');
  126. xdata.push(date[1] + '/' + date[2])
  127. let y = records[i].total_income.replace('%', '')
  128. ydata.push(Number(y))
  129. }
  130. xdata = xdata.reverse()
  131. ydata = ydata.reverse()
  132. const chart = echarts.init(canvas, null, {
  133. width: width,
  134. height: height,
  135. devicePixelRatio: dpr // new
  136. });
  137. canvas.setChart(chart);
  138. var option = {
  139. legend: {
  140. show: false
  141. },
  142. grid: {
  143. x: 50,
  144. y: 40,
  145. x2: 10,
  146. y2: 35
  147. },
  148. tooltip: {
  149. show: true,
  150. trigger: 'axis',
  151. formatter: '{b0}: {c0}%'
  152. },
  153. xAxis: {
  154. type: 'category',
  155. data: xdata,
  156. axisLabel: {
  157. interval: 0,
  158. rotate: 40,
  159. color: '#999999',
  160. interval: 2
  161. }
  162. },
  163. yAxis: {
  164. axisLine: {
  165. show: true
  166. },
  167. type: 'value',
  168. name: '收益曲线',
  169. axisLabel: {
  170. formatter: function (value, index) {//隐藏 0
  171. let texts = [];
  172. texts.push(value + '%')
  173. return texts;
  174. },
  175. show: true
  176. },
  177. },
  178. series: [{
  179. name: 'A',
  180. type: 'line',
  181. smooth: true,
  182. symbolSize: 8,
  183. lineStyle: {
  184. color: '#FF2D68'
  185. // color: new echarts.graphic.LinearGradient(1, 0, 0, 0, [{
  186. // offset: 0,
  187. // color: '#FF2D68'
  188. // }, {
  189. // offset: 1,
  190. // color: '#4C4BFF'
  191. // }]),
  192. },
  193. itemStyle: {
  194. borderWidth: 5,
  195. borderColor: '#FFAD52',
  196. color: '#FFAD52'
  197. },
  198. data: ydata
  199. }]
  200. };
  201. chart.setOption(option);
  202. return chart;
  203. }
  204. function initChart1(canvas, width, height, dpr) {
  205. const chart = echarts.init(canvas, null, {
  206. width: width,
  207. height: height,
  208. devicePixelRatio: dpr // new
  209. });
  210. canvas.setChart(chart);
  211. today_stock.forEach(item=>{
  212. item.value = item.fund
  213. })
  214. var option = {
  215. backgroundColor: "#ffffff",
  216. legend: {
  217. show: true,
  218. orient: 'vertical',
  219. left: '70%'
  220. },
  221. series: [{
  222. label: {
  223. normal: {
  224. fontSize: 14
  225. }
  226. },
  227. type: 'pie',
  228. center: ['40%', '40%'],
  229. radius: ['0%', '65%'],
  230. data: today_stock
  231. }]
  232. };
  233. chart.setOption(option);
  234. return chart;
  235. }