today.js 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  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.getDays()
  131. this.getzan()
  132. this.getComment()
  133. wx.hideNavigationBarLoading()
  134. })
  135. .catch(err=>{
  136. wx.hideNavigationBarLoading()
  137. })
  138. //每日持股
  139. var parm={
  140. id: data.id, user_id: this.data.user_id
  141. }
  142. // $api.getRecordList(parm).then(res=>{
  143. // this.setData({
  144. // stockList:res.data.data.list
  145. // })
  146. // })
  147. },
  148. bindDateChange(e){
  149. this.setData({
  150. date: e.detail.value
  151. })
  152. this.getDays()
  153. },
  154. prev(){
  155. var date=this.data.date.split('-'),y=date[0],m=date[1];
  156. if(m>1){
  157. m--
  158. }else{
  159. m=12
  160. y--
  161. }
  162. m=(m>9)?m:'0'+m
  163. this.setData({
  164. date: y+'-'+m
  165. })
  166. this.getDays()
  167. },
  168. next() {
  169. var date = this.data.date.split('-'), y = date[0], m = date[1];
  170. if (m < 12) {
  171. m++
  172. } else {
  173. m = 1
  174. y++
  175. }
  176. m = (m > 9) ? m : '0' + m
  177. this.setData({
  178. date: y + '-' + m
  179. })
  180. this.getDays()
  181. },
  182. //预览
  183. preview(e) {
  184. wx.previewImage({
  185. urls: e.target.dataset.urls,
  186. current: e.target.dataset.src
  187. })
  188. },
  189. followPlayer(e){
  190. let action = e.target.dataset.action;
  191. $api.follow({ follow_id: this.data.user_id, action:action}).then(res=>{
  192. wx.showToast({
  193. title: action?'取消成功':'已关注',
  194. })
  195. this.setData({
  196. is_follow: !this.data.is_follow
  197. })
  198. app.globalData.follow=1
  199. })
  200. },
  201. inputchange(e) {
  202. this.setData({
  203. comment: e.detail.value
  204. })
  205. },
  206. blur(){
  207. this.setData({
  208. comment:'',
  209. pid:null,
  210. text:'留言'
  211. })
  212. },
  213. sendmsg(){
  214. var data={
  215. record_id:this.data.record_id,
  216. cotent:this.data.comment,
  217. pid:this.data.pid,
  218. match_id:this.data.id
  219. }
  220. if(!data.cotent){
  221. return
  222. }
  223. $api.postcomment(data).then(res=>{
  224. this.getComment()
  225. this.setData({
  226. comment:'',
  227. pid:null,
  228. text:'留言'
  229. })
  230. })
  231. },
  232. delmsg(e){
  233. var data={
  234. id:e.target.dataset.id
  235. }
  236. $api.delcomment(data).then(res=>{
  237. this.getComment()
  238. })
  239. },
  240. zan(){
  241. $api.zan({record_id:this.data.record_id,match_id:this.data.id}).then(res=>{
  242. if(res.data.code == 0){
  243. this.getzan()
  244. this.setData({
  245. zan:1
  246. })
  247. setTimeout(()=>{
  248. this.setData({
  249. zan:0
  250. })
  251. },3000)
  252. }
  253. })
  254. },
  255. pushToday(e){
  256. $push.pushToday(e.currentTarget.dataset)
  257. },
  258. /**
  259. * 生命周期函数--监听页面初次渲染完成
  260. */
  261. onReady: function () {
  262. },
  263. /**
  264. * 生命周期函数--监听页面显示
  265. */
  266. onShow: function () {
  267. },
  268. /**
  269. * 生命周期函数--监听页面隐藏
  270. */
  271. onHide: function () {
  272. },
  273. /**
  274. * 生命周期函数--监听页面卸载
  275. */
  276. onUnload: function () {
  277. },
  278. /**
  279. * 页面相关事件处理函数--监听用户下拉动作
  280. */
  281. onPullDownRefresh: function () {
  282. },
  283. /**
  284. * 页面上拉触底事件的处理函数
  285. */
  286. onReachBottom: function () {
  287. },
  288. /**
  289. * 用户点击右上角分享
  290. */
  291. onShareAppMessage: function () {
  292. }
  293. })
  294. /**折线图 */
  295. function initChart(canvas, width, height, dpr) {
  296. var xdata = [], ydata = [];
  297. for (let i = 0; i < records.length; i++) {
  298. let date = records[i].stock_date.split('-');
  299. xdata.push(date[1] + '/' + date[2])
  300. let y = records[i].total_income.replace('%', '')
  301. ydata.push(Number(y))
  302. }
  303. xdata = xdata.reverse()
  304. ydata = ydata.reverse()
  305. const chart = echarts.init(canvas, null, {
  306. width: width,
  307. height: height,
  308. devicePixelRatio: dpr // new
  309. });
  310. canvas.setChart(chart);
  311. var option = {
  312. legend: {
  313. show: false
  314. },
  315. grid: {
  316. x: 40,
  317. y: 10,
  318. x2: 10,
  319. y2: 35
  320. },
  321. tooltip: {
  322. show: true,
  323. trigger: 'axis',
  324. formatter: '{b0}: {c0}%',
  325. },
  326. xAxis: {
  327. type: 'category',
  328. data: xdata,
  329. axisLabel: {
  330. interval: 0,
  331. rotate: 40,
  332. color: '#999999',
  333. interval: 2
  334. }
  335. },
  336. yAxis: {
  337. axisLine: {
  338. show: true,
  339. },
  340. type: 'value',
  341. // name: '收益曲线',
  342. axisLabel: {
  343. color: '#999999',
  344. formatter: function (value, index) {//隐藏 0
  345. let texts = [];
  346. texts.push(value + '%')
  347. return texts;
  348. },
  349. show: true
  350. },
  351. },
  352. series: [{
  353. name: 'A',
  354. type: 'line',
  355. smooth: true,
  356. symbolSize: 4,
  357. lineStyle: {
  358. color: '#FF2D68'
  359. // color: new echarts.graphic.LinearGradient(1, 0, 0, 0, [{
  360. // offset: 0,
  361. // color: '#FF2D68'
  362. // }, {
  363. // offset: 1,
  364. // color: '#4C4BFF'
  365. // }]),
  366. },
  367. itemStyle: {
  368. borderWidth: 5,
  369. borderColor: '#FFAD52',
  370. color: '#FFAD52'
  371. },
  372. data: ydata
  373. }]
  374. };
  375. chart.setOption(option);
  376. return chart;
  377. }
  378. function initChart1(canvas, width, height, dpr) {
  379. const chart = echarts.init(canvas, null, {
  380. width: width,
  381. height: height,
  382. devicePixelRatio: dpr // new
  383. });
  384. canvas.setChart(chart);
  385. today_stock.forEach(item=>{
  386. item.value = item.fund
  387. })
  388. var radius = today_stock.length<9?'65%':'50%';
  389. var option = {
  390. backgroundColor: "#ffffff",
  391. legend: {
  392. show: true,
  393. orient: 'vertical',
  394. right: '1%',
  395. formatter: function (name){
  396. var index = 0;
  397. today_stock.forEach(function (value, i) {
  398. if (value.name == name) {
  399. index = i;
  400. }
  401. });
  402. return name + " " + today_stock[index].value;
  403. }
  404. },
  405. series: [{
  406. label: {
  407. normal: {
  408. show: true,
  409. fontSize: 12,
  410. formatter: function (a) {
  411. return Math.round(a.percent)+'%'
  412. }
  413. }
  414. },
  415. type: 'pie',
  416. center: ['37%', '40%'],
  417. radius: ['0%', radius],
  418. data: today_stock
  419. }]
  420. };
  421. chart.setOption(option);
  422. return chart;
  423. }