homepage.js 8.1 KB

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