matchdetail.js 6.8 KB

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