matchdetail.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  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.getWeek(records)
  94. this.setData({
  95. datas: res.data.data,
  96. total_money:tmoney,
  97. date: stock_date[0] + '-' + stock_date[1],
  98. ec: {
  99. onInit: initChart
  100. },
  101. // ec1: {
  102. // onInit: initChart1
  103. // }
  104. })
  105. // this.getDays()
  106. wx.hideNavigationBarLoading()
  107. wx.setNavigationBarTitle({
  108. title: res.data.data.userinfo.username,
  109. })
  110. if(this.data.total_money >= 0){
  111. wx.setNavigationBarColor({
  112. backgroundColor: '#D94B24',
  113. frontColor: '#ffffff',
  114. })
  115. } else{
  116. wx.setNavigationBarColor({
  117. backgroundColor: '#07B20B',
  118. frontColor: '#ffffff',
  119. })
  120. }
  121. })
  122. .catch(err=>{
  123. wx.hideNavigationBarLoading()
  124. })
  125. },
  126. toThousandFilter(num) {
  127. return (+num || 0).toString().replace(/^-?\d+/g, m => m.replace(/(?=(?!\b)(\d{3})+$)/g, ','))
  128. },
  129. getWeek(list){
  130. var week=['一','二','三','四','五','六','七','八','九','十','十一','十二','十三','十四','十五']
  131. var days=list,weeks=[[]]
  132. days=days.reverse()
  133. week.forEach((item,index)=>{
  134. weeks[index]={
  135. name:'第'+item+'周',
  136. data:[],
  137. total:0
  138. }
  139. })
  140. var i=0
  141. days.forEach(item=>{
  142. var w=new Date(item.stock_date).getDay()
  143. item.day=w
  144. if(w==1){
  145. i++
  146. }
  147. weeks[i].data.push(item)
  148. })
  149. weeks.forEach(item=>{
  150. if(item.data.length>0){
  151. var total=0
  152. var money = 10000.0
  153. item.data.forEach(i=>{
  154. var incom=Number(i.today_income.replace('%',''))
  155. money += money*incom/100.0
  156. i.date=(new Date(i.stock_date).getMonth()+1)+'/'+(new Date(i.stock_date).getDate())
  157. })
  158. total = (money-10000)*100.0/10000.0
  159. item.total=total.toFixed(2)
  160. }
  161. })
  162. this.setData({
  163. days:weeks.reverse()
  164. })
  165. },
  166. getDays(){
  167. $api.getCalendar({
  168. user_id:this.data.user_id,
  169. match_id:this.data.match_id,
  170. month: this.data.date
  171. }).then(res=>{
  172. var days = [], w = new Date(this.data.date + '-01').getDay();
  173. for (let i = 0; i < w; i++) {
  174. days.push({
  175. day: '',
  176. income: ''
  177. })
  178. }
  179. for (let i = 0; i < res.data.data.length; i++) {
  180. days.push({
  181. day: i+1,
  182. income: res.data.data[i].today_income,
  183. record_id:res.data.data[i].record_id,
  184. })
  185. }
  186. this.setData({
  187. days: days
  188. })
  189. })
  190. },
  191. preview(e){
  192. console.log(e)
  193. wx.previewImage({
  194. urls: e.target.dataset.urls,
  195. current: e.target.dataset.src
  196. })
  197. },
  198. bindDateChange(e){
  199. this.setData({
  200. date: e.detail.value
  201. })
  202. this.getDays()
  203. },
  204. prev(){
  205. var date=this.data.date.split('-'),y=date[0],m=date[1];
  206. if(m>1){
  207. m--
  208. }else{
  209. m=12
  210. y--
  211. }
  212. m=(m>9)?m:'0'+m
  213. this.setData({
  214. date: y+'-'+m
  215. })
  216. this.getDays()
  217. },
  218. next() {
  219. var date = this.data.date.split('-'), y = date[0], m = date[1];
  220. if (m < 12) {
  221. m++
  222. } else {
  223. m = 1
  224. y++
  225. }
  226. m = (m > 9) ? m : '0' + m
  227. this.setData({
  228. date: y + '-' + m
  229. })
  230. this.getDays()
  231. },
  232. })
  233. function initChart(canvas, width, height, dpr) {
  234. var xdata = [], ydata = [];
  235. records = records.reverse()
  236. for (let i = 0; i < records.length; i++) {
  237. let date = records[i].stock_date.split('-');
  238. xdata.push(date[1] + '/' + date[2])
  239. let y = records[i].total_income.replace('%', '')
  240. ydata.push(Number(y))
  241. }
  242. xdata = xdata.reverse()
  243. ydata = ydata.reverse()
  244. const chart = echarts.init(canvas, null, {
  245. width: width,
  246. height: height,
  247. devicePixelRatio: dpr // new
  248. });
  249. canvas.setChart(chart);
  250. var option = {
  251. legend: {
  252. show: false
  253. },
  254. grid: {
  255. x: 50,
  256. y: 10,
  257. x2: 10,
  258. y2: 35
  259. },
  260. tooltip: {
  261. show: true,
  262. trigger: 'axis',
  263. formatter: '{b0}: {c0}%'
  264. },
  265. xAxis: {
  266. type: 'category',
  267. data: xdata,
  268. axisLabel: {
  269. interval: 0,
  270. rotate: 40,
  271. color: '#999999',
  272. interval: 2
  273. }
  274. },
  275. yAxis: {
  276. axisLine: {
  277. show: true
  278. },
  279. type: 'value',
  280. name: '',
  281. axisLabel: {
  282. formatter: function (value, index) {//隐藏 0
  283. let texts = [];
  284. texts.push(value + '%')
  285. return texts;
  286. },
  287. show: true
  288. },
  289. },
  290. series: [{
  291. name: 'A',
  292. type: 'line',
  293. smooth: true,
  294. symbolSize: 4,
  295. lineStyle: {
  296. color: '#FF2D68'
  297. // color: new echarts.graphic.LinearGradient(1, 0, 0, 0, [{
  298. // offset: 0,
  299. // color: '#FF2D68'
  300. // }, {
  301. // offset: 1,
  302. // color: '#4C4BFF'
  303. // }]),
  304. },
  305. itemStyle: {
  306. borderWidth: 5,
  307. borderColor: '#FFAD52',
  308. color: '#FFAD52'
  309. },
  310. data: ydata
  311. }]
  312. };
  313. chart.setOption(option);
  314. return chart;
  315. }
  316. function initChart1(canvas, width, height, dpr) {
  317. const chart = echarts.init(canvas, null, {
  318. width: width,
  319. height: height,
  320. devicePixelRatio: dpr // new
  321. });
  322. canvas.setChart(chart);
  323. today_stock.forEach(item=>{
  324. item.value = item.fund
  325. })
  326. var radius = today_stock.length<9?'65%':'50%';
  327. var option = {
  328. backgroundColor: "#ffffff",
  329. legend: {
  330. show: true,
  331. orient: 'vertical',
  332. right: '1%',
  333. formatter: function (name){
  334. var index = 0;
  335. today_stock.forEach(function (value, i) {
  336. if (value.name == name) {
  337. index = i;
  338. }
  339. });
  340. return name + " " + today_stock[index].value;
  341. }
  342. },
  343. series: [{
  344. label: {
  345. normal: {
  346. show: true,
  347. fontSize: 12,
  348. formatter: function (a) {
  349. return Math.round(a.percent)+'%'
  350. }
  351. }
  352. },
  353. type: 'pie',
  354. center: ['37%', '40%'],
  355. radius: ['0%', radius],
  356. data: today_stock
  357. }]
  358. };
  359. chart.setOption(option);
  360. return chart;
  361. }