homepage.js 7.3 KB

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