today.js 9.5 KB

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