today.js 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  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. var id, record_id, records = [], today_stock=[];
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. page:0,
  12. focus:false,
  13. date:'2021-11',
  14. text:'留言',
  15. days:[],
  16. author_user_id:'',
  17. ec: {
  18. onInit: null
  19. },
  20. ec1: {
  21. onInit: null
  22. }
  23. },
  24. /**
  25. * 生命周期函数--监听页面加载
  26. */
  27. onLoad: function (options) {
  28. id = options.id, record_id = options.record_id
  29. this.setData({
  30. id: id,
  31. record_id: record_id,
  32. user_id: options.user_id ? options.user_id:''
  33. })
  34. $api.getAuthinfo().then(res=>{
  35. wx.setNavigationBarTitle({
  36. title: '',
  37. })
  38. this.setData({
  39. author_user_id:res.data.data.id,
  40. role: res.data.data.role
  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. /**
  256. * 生命周期函数--监听页面初次渲染完成
  257. */
  258. onReady: function () {
  259. },
  260. /**
  261. * 生命周期函数--监听页面显示
  262. */
  263. onShow: function () {
  264. },
  265. /**
  266. * 生命周期函数--监听页面隐藏
  267. */
  268. onHide: function () {
  269. },
  270. /**
  271. * 生命周期函数--监听页面卸载
  272. */
  273. onUnload: function () {
  274. },
  275. /**
  276. * 页面相关事件处理函数--监听用户下拉动作
  277. */
  278. onPullDownRefresh: function () {
  279. },
  280. /**
  281. * 页面上拉触底事件的处理函数
  282. */
  283. onReachBottom: function () {
  284. },
  285. /**
  286. * 用户点击右上角分享
  287. */
  288. onShareAppMessage: function () {
  289. }
  290. })
  291. /**折线图 */
  292. function initChart(canvas, width, height, dpr) {
  293. var xdata = [], ydata = [];
  294. for (let i = 0; i < records.length; i++) {
  295. let date = records[i].stock_date.split('-');
  296. xdata.push(date[1] + '/' + date[2])
  297. let y = records[i].total_income.replace('%', '')
  298. ydata.push(Number(y))
  299. }
  300. xdata = xdata.reverse()
  301. ydata = ydata.reverse()
  302. const chart = echarts.init(canvas, null, {
  303. width: width,
  304. height: height,
  305. devicePixelRatio: dpr // new
  306. });
  307. canvas.setChart(chart);
  308. var option = {
  309. legend: {
  310. show: false
  311. },
  312. grid: {
  313. x: 40,
  314. y: 10,
  315. x2: 10,
  316. y2: 35
  317. },
  318. tooltip: {
  319. show: true,
  320. trigger: 'axis',
  321. formatter: '{b0}: {c0}%',
  322. },
  323. xAxis: {
  324. type: 'category',
  325. data: xdata,
  326. axisLabel: {
  327. interval: 0,
  328. rotate: 40,
  329. color: '#999999',
  330. interval: 2
  331. }
  332. },
  333. yAxis: {
  334. axisLine: {
  335. show: true,
  336. },
  337. type: 'value',
  338. // name: '收益曲线',
  339. axisLabel: {
  340. color: '#999999',
  341. formatter: function (value, index) {//隐藏 0
  342. let texts = [];
  343. texts.push(value + '%')
  344. return texts;
  345. },
  346. show: true
  347. },
  348. },
  349. series: [{
  350. name: 'A',
  351. type: 'line',
  352. smooth: true,
  353. symbolSize: 4,
  354. lineStyle: {
  355. color: '#FF2D68'
  356. // color: new echarts.graphic.LinearGradient(1, 0, 0, 0, [{
  357. // offset: 0,
  358. // color: '#FF2D68'
  359. // }, {
  360. // offset: 1,
  361. // color: '#4C4BFF'
  362. // }]),
  363. },
  364. itemStyle: {
  365. borderWidth: 5,
  366. borderColor: '#FFAD52',
  367. color: '#FFAD52'
  368. },
  369. data: ydata
  370. }]
  371. };
  372. chart.setOption(option);
  373. return chart;
  374. }
  375. function initChart1(canvas, width, height, dpr) {
  376. const chart = echarts.init(canvas, null, {
  377. width: width,
  378. height: height,
  379. devicePixelRatio: dpr // new
  380. });
  381. canvas.setChart(chart);
  382. today_stock.forEach(item=>{
  383. item.value = item.fund
  384. })
  385. var radius = today_stock.length<9?'65%':'50%';
  386. var option = {
  387. backgroundColor: "#ffffff",
  388. legend: {
  389. show: true,
  390. orient: 'vertical',
  391. right: '1%',
  392. formatter: function (name){
  393. var index = 0;
  394. today_stock.forEach(function (value, i) {
  395. if (value.name == name) {
  396. index = i;
  397. }
  398. });
  399. return name + " " + today_stock[index].value;
  400. }
  401. },
  402. series: [{
  403. label: {
  404. normal: {
  405. show: true,
  406. fontSize: 12,
  407. formatter: function (a) {
  408. return Math.round(a.percent)+'%'
  409. }
  410. }
  411. },
  412. type: 'pie',
  413. center: ['37%', '40%'],
  414. radius: ['0%', radius],
  415. data: today_stock
  416. }]
  417. };
  418. chart.setOption(option);
  419. return chart;
  420. }