homepage.js 7.0 KB

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