today.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  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. let user = wx.getStorageSync('user')
  229. var cdata={
  230. content:this.data.comment,
  231. openid:user.openid
  232. }
  233. if(!cdata.content){
  234. return
  235. }
  236. $api.contentCheck(cdata).then(res=>{
  237. var result = res.data.data.result
  238. console.log(res.data.data,cdata)
  239. if(result.suggest == 'pass'){
  240. var data={
  241. record_id:this.data.record_id,
  242. cotent:this.data.comment,
  243. pid:this.data.pid,
  244. match_id:this.data.id
  245. }
  246. $api.postcomment(data).then(res=>{
  247. this.getComment()
  248. this.setData({
  249. comment:'',
  250. pid:null,
  251. text:'留言'
  252. })
  253. })
  254. } else{
  255. wx.showToast({
  256. icon: 'none',
  257. title: '留言含违规信息'
  258. })
  259. }
  260. })
  261. },
  262. delmsg(e){
  263. var data={
  264. id:e.target.dataset.id
  265. }
  266. $api.delcomment(data).then(res=>{
  267. this.getComment()
  268. })
  269. },
  270. zan(){
  271. $api.zan({record_id:this.data.record_id,match_id:this.data.id}).then(res=>{
  272. if(res.data.code == 0){
  273. this.getzan()
  274. this.setData({
  275. zan:1
  276. })
  277. setTimeout(()=>{
  278. this.setData({
  279. zan:0
  280. })
  281. },3000)
  282. }
  283. })
  284. },
  285. pushToday(e){
  286. $push.pushToday(e.currentTarget.dataset)
  287. },
  288. userCenter(e){
  289. wx.navigateTo({
  290. url: '../homepage/homepage?user_id=' + e.currentTarget.dataset.id,
  291. })
  292. },
  293. /**
  294. * 生命周期函数--监听页面初次渲染完成
  295. */
  296. onReady: function () {
  297. },
  298. /**
  299. * 生命周期函数--监听页面显示
  300. */
  301. onShow: function () {
  302. },
  303. /**
  304. * 生命周期函数--监听页面隐藏
  305. */
  306. onHide: function () {
  307. },
  308. /**
  309. * 生命周期函数--监听页面卸载
  310. */
  311. onUnload: function () {
  312. },
  313. /**
  314. * 页面相关事件处理函数--监听用户下拉动作
  315. */
  316. onPullDownRefresh: function () {
  317. },
  318. /**
  319. * 页面上拉触底事件的处理函数
  320. */
  321. onReachBottom: function () {
  322. },
  323. /**
  324. * 用户点击右上角分享
  325. */
  326. onShareAppMessage: function () {
  327. }
  328. })
  329. /**折线图 */
  330. function initChart(canvas, width, height, dpr) {
  331. var xdata = [], ydata = [];
  332. for (let i = 0; i < records.length; i++) {
  333. let date = records[i].stock_date.split('-');
  334. xdata.push(date[1] + '/' + date[2])
  335. let y = records[i].total_income.replace('%', '')
  336. ydata.push(Number(y))
  337. }
  338. xdata = xdata.reverse()
  339. ydata = ydata.reverse()
  340. const chart = echarts.init(canvas, null, {
  341. width: width,
  342. height: height,
  343. devicePixelRatio: dpr // new
  344. });
  345. canvas.setChart(chart);
  346. var option = {
  347. legend: {
  348. show: false
  349. },
  350. grid: {
  351. x: 40,
  352. y: 10,
  353. x2: 10,
  354. y2: 35
  355. },
  356. tooltip: {
  357. show: true,
  358. trigger: 'axis',
  359. formatter: '{b0}: {c0}%',
  360. },
  361. xAxis: {
  362. type: 'category',
  363. data: xdata,
  364. axisLabel: {
  365. interval: 0,
  366. rotate: 40,
  367. color: '#999999',
  368. interval: 2
  369. }
  370. },
  371. yAxis: {
  372. axisLine: {
  373. show: true,
  374. },
  375. type: 'value',
  376. // name: '收益曲线',
  377. axisLabel: {
  378. color: '#999999',
  379. formatter: function (value, index) {//隐藏 0
  380. let texts = [];
  381. texts.push(value + '%')
  382. return texts;
  383. },
  384. show: true
  385. },
  386. },
  387. series: [{
  388. name: 'A',
  389. type: 'line',
  390. smooth: true,
  391. symbolSize: 4,
  392. lineStyle: {
  393. color: '#FF2D68'
  394. // color: new echarts.graphic.LinearGradient(1, 0, 0, 0, [{
  395. // offset: 0,
  396. // color: '#FF2D68'
  397. // }, {
  398. // offset: 1,
  399. // color: '#4C4BFF'
  400. // }]),
  401. },
  402. itemStyle: {
  403. borderWidth: 5,
  404. borderColor: '#FFAD52',
  405. color: '#FFAD52'
  406. },
  407. data: ydata
  408. }]
  409. };
  410. chart.setOption(option);
  411. return chart;
  412. }
  413. function initChart1(canvas, width, height, dpr) {
  414. const chart = echarts.init(canvas, null, {
  415. width: width,
  416. height: height,
  417. devicePixelRatio: dpr // new
  418. });
  419. canvas.setChart(chart);
  420. console.log(today_stock)
  421. today_stock.forEach(item=>{
  422. if(item.fund != '0.0'){
  423. item.value = item.fund
  424. }
  425. })
  426. var radius = today_stock.length<9?'65%':'50%';
  427. var option = {
  428. backgroundColor: "#ffffff",
  429. legend: {
  430. show: true,
  431. orient: 'vertical',
  432. right: 0,
  433. itemWidth:10,
  434. itemHeight:10,
  435. textStyle:{
  436. fontSize:12
  437. },
  438. formatter: function (name){
  439. var index = 0;
  440. today_stock.forEach(function (value, i) {
  441. if (value.name == name) {
  442. index = i;
  443. }
  444. });
  445. return '';
  446. // + " " + today_stock[index].value+ " " + today_stock[index].money
  447. }
  448. },
  449. grid:{
  450. // right:'10%'
  451. },
  452. series: [{
  453. label: {
  454. normal: {
  455. show: true,
  456. fontSize: 12,
  457. formatter: function (a) {
  458. return Math.round(a.percent)+'%'
  459. }
  460. }
  461. },
  462. type: 'pie',
  463. center: ['45%', '40%'],
  464. radius: ['0%', radius],
  465. data: today_stock
  466. }]
  467. };
  468. chart.setOption(option);
  469. return chart;
  470. }