today.js 5.6 KB

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