homepage.js 7.5 KB

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