today.js 7.1 KB

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