homepage.js 7.5 KB

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