matchdetail.js 6.5 KB

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