today.js 9.9 KB

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