today.js 9.0 KB

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