homepage.js 7.4 KB

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