today.js 9.0 KB

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