today.js 6.9 KB

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