homepage.js 8.1 KB

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