matchdetail.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. // pages/matchdetail/matchdetail.js
  2. const app = getApp()
  3. import * as echarts from '../../ec-canvas/echarts';
  4. const $api = require('../../utils/api.js').API;
  5. var records = [], today_stock=[];
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. datas:{},
  12. user_id:'',
  13. match_id:'',
  14. date:'',
  15. days:[],
  16. ec: {
  17. onInit: null
  18. },
  19. ec1: {
  20. onInit: null
  21. }
  22. },
  23. /**
  24. * 生命周期函数--监听页面加载
  25. */
  26. onLoad(options) {
  27. this.setData({
  28. user_id:options.user_id,
  29. match_id:options.match_id,
  30. })
  31. this.getMatchData()
  32. },
  33. /**
  34. * 生命周期函数--监听页面初次渲染完成
  35. */
  36. onReady() {
  37. },
  38. /**
  39. * 生命周期函数--监听页面显示
  40. */
  41. onShow() {
  42. },
  43. /**
  44. * 生命周期函数--监听页面隐藏
  45. */
  46. onHide() {
  47. },
  48. /**
  49. * 生命周期函数--监听页面卸载
  50. */
  51. onUnload() {
  52. },
  53. /**
  54. * 页面相关事件处理函数--监听用户下拉动作
  55. */
  56. onPullDownRefresh() {
  57. },
  58. /**
  59. * 页面上拉触底事件的处理函数
  60. */
  61. onReachBottom() {
  62. },
  63. /**
  64. * 用户点击右上角分享
  65. */
  66. onShareAppMessage() {
  67. },
  68. getMatchData(){
  69. wx.showNavigationBarLoading();
  70. var data = {}
  71. data.user_id = this.data.user_id
  72. data.id = this.data.match_id
  73. $api.getPlayerMatch(data).then(res=>{
  74. let stock_date=res.data.data.today_record.stock_date.split('-')
  75. records = res.data.data.records
  76. today_stock = res.data.data.today_record.today_stock
  77. console.log(records,2323)
  78. this.setData({
  79. datas: res.data.data,
  80. date: stock_date[0] + '-' + stock_date[1],
  81. ec: {
  82. onInit: initChart
  83. },
  84. // ec1: {
  85. // onInit: initChart1
  86. // }
  87. })
  88. this.getDays()
  89. wx.hideNavigationBarLoading()
  90. })
  91. .catch(err=>{
  92. wx.hideNavigationBarLoading()
  93. })
  94. },
  95. getDays(){
  96. $api.getCalendar({
  97. user_id:this.data.user_id,
  98. match_id:this.data.match_id,
  99. month: this.data.date
  100. }).then(res=>{
  101. var days = [], w = new Date(this.data.date + '-01').getDay();
  102. for (let i = 0; i < w; i++) {
  103. days.push({
  104. day: '',
  105. income: ''
  106. })
  107. }
  108. for (let i = 0; i < res.data.data.length; i++) {
  109. days.push({
  110. day: i+1,
  111. income: res.data.data[i].today_income
  112. })
  113. }
  114. this.setData({
  115. days: days
  116. })
  117. })
  118. },
  119. bindDateChange(e){
  120. this.setData({
  121. date: e.detail.value
  122. })
  123. this.getDays()
  124. },
  125. prev(){
  126. var date=this.data.date.split('-'),y=date[0],m=date[1];
  127. if(m>1){
  128. m--
  129. }else{
  130. m=12
  131. y--
  132. }
  133. m=(m>9)?m:'0'+m
  134. this.setData({
  135. date: y+'-'+m
  136. })
  137. this.getDays()
  138. },
  139. next() {
  140. var date = this.data.date.split('-'), y = date[0], m = date[1];
  141. if (m < 12) {
  142. m++
  143. } else {
  144. m = 1
  145. y++
  146. }
  147. m = (m > 9) ? m : '0' + m
  148. this.setData({
  149. date: y + '-' + m
  150. })
  151. this.getDays()
  152. },
  153. })
  154. function initChart(canvas, width, height, dpr) {
  155. var xdata = [], ydata = [];
  156. for (let i = 0; i < records.length; i++) {
  157. let date = records[i].stock_date.split('-');
  158. xdata.push(date[1] + '/' + date[2])
  159. let y = records[i].total_income.replace('%', '')
  160. ydata.push(Number(y))
  161. }
  162. xdata = xdata.reverse()
  163. ydata = ydata.reverse()
  164. const chart = echarts.init(canvas, null, {
  165. width: width,
  166. height: height,
  167. devicePixelRatio: dpr // new
  168. });
  169. canvas.setChart(chart);
  170. var option = {
  171. legend: {
  172. show: false
  173. },
  174. grid: {
  175. x: 50,
  176. y: 40,
  177. x2: 10,
  178. y2: 35
  179. },
  180. tooltip: {
  181. show: true,
  182. trigger: 'axis',
  183. formatter: '{b0}: {c0}%'
  184. },
  185. xAxis: {
  186. type: 'category',
  187. data: xdata,
  188. axisLabel: {
  189. interval: 0,
  190. rotate: 40,
  191. color: '#999999',
  192. interval: 2
  193. }
  194. },
  195. yAxis: {
  196. axisLine: {
  197. show: true
  198. },
  199. type: 'value',
  200. name: '收益曲线',
  201. axisLabel: {
  202. formatter: function (value, index) {//隐藏 0
  203. let texts = [];
  204. texts.push(value + '%')
  205. return texts;
  206. },
  207. show: true
  208. },
  209. },
  210. series: [{
  211. name: 'A',
  212. type: 'line',
  213. smooth: true,
  214. symbolSize: 8,
  215. lineStyle: {
  216. color: '#FF2D68'
  217. // color: new echarts.graphic.LinearGradient(1, 0, 0, 0, [{
  218. // offset: 0,
  219. // color: '#FF2D68'
  220. // }, {
  221. // offset: 1,
  222. // color: '#4C4BFF'
  223. // }]),
  224. },
  225. itemStyle: {
  226. borderWidth: 5,
  227. borderColor: '#FFAD52',
  228. color: '#FFAD52'
  229. },
  230. data: ydata
  231. }]
  232. };
  233. chart.setOption(option);
  234. return chart;
  235. }
  236. function initChart1(canvas, width, height, dpr) {
  237. const chart = echarts.init(canvas, null, {
  238. width: width,
  239. height: height,
  240. devicePixelRatio: dpr // new
  241. });
  242. canvas.setChart(chart);
  243. today_stock.forEach(item=>{
  244. item.value = item.fund
  245. })
  246. var radius = today_stock.length<9?'65%':'50%';
  247. var option = {
  248. backgroundColor: "#ffffff",
  249. legend: {
  250. show: true,
  251. orient: 'vertical',
  252. right: '1%',
  253. formatter: function (name){
  254. var index = 0;
  255. today_stock.forEach(function (value, i) {
  256. if (value.name == name) {
  257. index = i;
  258. }
  259. });
  260. return name + " " + today_stock[index].value;
  261. }
  262. },
  263. series: [{
  264. label: {
  265. normal: {
  266. show: true,
  267. fontSize: 12,
  268. formatter: function (a) {
  269. return Math.round(a.percent)+'%'
  270. }
  271. }
  272. },
  273. type: 'pie',
  274. center: ['37%', '40%'],
  275. radius: ['0%', radius],
  276. data: today_stock
  277. }]
  278. };
  279. chart.setOption(option);
  280. return chart;
  281. }