today.js 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  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. /**
  262. * 生命周期函数--监听页面初次渲染完成
  263. */
  264. onReady: function () {
  265. },
  266. /**
  267. * 生命周期函数--监听页面显示
  268. */
  269. onShow: function () {
  270. },
  271. /**
  272. * 生命周期函数--监听页面隐藏
  273. */
  274. onHide: function () {
  275. },
  276. /**
  277. * 生命周期函数--监听页面卸载
  278. */
  279. onUnload: function () {
  280. },
  281. /**
  282. * 页面相关事件处理函数--监听用户下拉动作
  283. */
  284. onPullDownRefresh: function () {
  285. },
  286. /**
  287. * 页面上拉触底事件的处理函数
  288. */
  289. onReachBottom: function () {
  290. },
  291. /**
  292. * 用户点击右上角分享
  293. */
  294. onShareAppMessage: function () {
  295. }
  296. })
  297. /**折线图 */
  298. function initChart(canvas, width, height, dpr) {
  299. var xdata = [], ydata = [];
  300. for (let i = 0; i < records.length; i++) {
  301. let date = records[i].stock_date.split('-');
  302. xdata.push(date[1] + '/' + date[2])
  303. let y = records[i].total_income.replace('%', '')
  304. ydata.push(Number(y))
  305. }
  306. xdata = xdata.reverse()
  307. ydata = ydata.reverse()
  308. const chart = echarts.init(canvas, null, {
  309. width: width,
  310. height: height,
  311. devicePixelRatio: dpr // new
  312. });
  313. canvas.setChart(chart);
  314. var option = {
  315. legend: {
  316. show: false
  317. },
  318. grid: {
  319. x: 40,
  320. y: 10,
  321. x2: 10,
  322. y2: 35
  323. },
  324. tooltip: {
  325. show: true,
  326. trigger: 'axis',
  327. formatter: '{b0}: {c0}%',
  328. },
  329. xAxis: {
  330. type: 'category',
  331. data: xdata,
  332. axisLabel: {
  333. interval: 0,
  334. rotate: 40,
  335. color: '#999999',
  336. interval: 2
  337. }
  338. },
  339. yAxis: {
  340. axisLine: {
  341. show: true,
  342. },
  343. type: 'value',
  344. // name: '收益曲线',
  345. axisLabel: {
  346. color: '#999999',
  347. formatter: function (value, index) {//隐藏 0
  348. let texts = [];
  349. texts.push(value + '%')
  350. return texts;
  351. },
  352. show: true
  353. },
  354. },
  355. series: [{
  356. name: 'A',
  357. type: 'line',
  358. smooth: true,
  359. symbolSize: 4,
  360. lineStyle: {
  361. color: '#FF2D68'
  362. // color: new echarts.graphic.LinearGradient(1, 0, 0, 0, [{
  363. // offset: 0,
  364. // color: '#FF2D68'
  365. // }, {
  366. // offset: 1,
  367. // color: '#4C4BFF'
  368. // }]),
  369. },
  370. itemStyle: {
  371. borderWidth: 5,
  372. borderColor: '#FFAD52',
  373. color: '#FFAD52'
  374. },
  375. data: ydata
  376. }]
  377. };
  378. chart.setOption(option);
  379. return chart;
  380. }
  381. function initChart1(canvas, width, height, dpr) {
  382. const chart = echarts.init(canvas, null, {
  383. width: width,
  384. height: height,
  385. devicePixelRatio: dpr // new
  386. });
  387. canvas.setChart(chart);
  388. console.log(today_stock)
  389. today_stock.forEach(item=>{
  390. if(item.fund != '0.0'){
  391. item.value = item.fund
  392. }
  393. })
  394. var radius = today_stock.length<9?'65%':'50%';
  395. var option = {
  396. backgroundColor: "#ffffff",
  397. legend: {
  398. show: true,
  399. orient: 'vertical',
  400. right: 0,
  401. itemWidth:10,
  402. itemHeight:10,
  403. textStyle:{
  404. fontSize:12
  405. },
  406. formatter: function (name){
  407. var index = 0;
  408. today_stock.forEach(function (value, i) {
  409. if (value.name == name) {
  410. index = i;
  411. }
  412. });
  413. return '';
  414. // + " " + today_stock[index].value+ " " + today_stock[index].money
  415. }
  416. },
  417. grid:{
  418. // right:'10%'
  419. },
  420. series: [{
  421. label: {
  422. normal: {
  423. show: true,
  424. fontSize: 12,
  425. formatter: function (a) {
  426. return Math.round(a.percent)+'%'
  427. }
  428. }
  429. },
  430. type: 'pie',
  431. center: ['45%', '40%'],
  432. radius: ['0%', radius],
  433. data: today_stock
  434. }]
  435. };
  436. chart.setOption(option);
  437. return chart;
  438. }