today.js 6.9 KB

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