homepage.js 7.0 KB

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