today.js 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  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}).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}).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. }
  217. if(!data.cotent){
  218. return
  219. }
  220. $api.postcomment(data).then(res=>{
  221. this.getComment()
  222. this.setData({
  223. comment:'',
  224. pid:null,
  225. text:'留言'
  226. })
  227. })
  228. },
  229. delmsg(e){
  230. var data={
  231. id:e.target.dataset.id
  232. }
  233. $api.delcomment(data).then(res=>{
  234. this.getComment()
  235. })
  236. },
  237. zan(){
  238. $api.zan({record_id:this.data.record_id}).then(res=>{
  239. if(res.data.code == 0){
  240. this.getzan()
  241. this.setData({
  242. zan:1
  243. })
  244. setTimeout(()=>{
  245. this.setData({
  246. zan:0
  247. })
  248. },3000)
  249. }
  250. })
  251. },
  252. /**
  253. * 生命周期函数--监听页面初次渲染完成
  254. */
  255. onReady: function () {
  256. },
  257. /**
  258. * 生命周期函数--监听页面显示
  259. */
  260. onShow: function () {
  261. },
  262. /**
  263. * 生命周期函数--监听页面隐藏
  264. */
  265. onHide: function () {
  266. },
  267. /**
  268. * 生命周期函数--监听页面卸载
  269. */
  270. onUnload: function () {
  271. },
  272. /**
  273. * 页面相关事件处理函数--监听用户下拉动作
  274. */
  275. onPullDownRefresh: function () {
  276. },
  277. /**
  278. * 页面上拉触底事件的处理函数
  279. */
  280. onReachBottom: function () {
  281. },
  282. /**
  283. * 用户点击右上角分享
  284. */
  285. onShareAppMessage: function () {
  286. }
  287. })
  288. /**折线图 */
  289. function initChart(canvas, width, height, dpr) {
  290. var xdata = [], ydata = [];
  291. for (let i = 0; i < records.length; i++) {
  292. let date = records[i].stock_date.split('-');
  293. xdata.push(date[1] + '/' + date[2])
  294. let y = records[i].total_income.replace('%', '')
  295. ydata.push(Number(y))
  296. }
  297. xdata = xdata.reverse()
  298. ydata = ydata.reverse()
  299. const chart = echarts.init(canvas, null, {
  300. width: width,
  301. height: height,
  302. devicePixelRatio: dpr // new
  303. });
  304. canvas.setChart(chart);
  305. var option = {
  306. legend: {
  307. show: false
  308. },
  309. grid: {
  310. x: 50,
  311. y: 40,
  312. x2: 10,
  313. y2: 35
  314. },
  315. tooltip: {
  316. show: true,
  317. trigger: 'axis',
  318. formatter: '{b0}: {c0}%'
  319. },
  320. xAxis: {
  321. type: 'category',
  322. data: xdata,
  323. axisLabel: {
  324. interval: 0,
  325. rotate: 40,
  326. color: '#999999',
  327. interval: 2
  328. }
  329. },
  330. yAxis: {
  331. axisLine: {
  332. show: true
  333. },
  334. type: 'value',
  335. name: '收益曲线',
  336. axisLabel: {
  337. formatter: function (value, index) {//隐藏 0
  338. let texts = [];
  339. texts.push(value + '%')
  340. return texts;
  341. },
  342. show: true
  343. },
  344. },
  345. series: [{
  346. name: 'A',
  347. type: 'line',
  348. smooth: true,
  349. symbolSize: 8,
  350. lineStyle: {
  351. color: '#FF2D68'
  352. // color: new echarts.graphic.LinearGradient(1, 0, 0, 0, [{
  353. // offset: 0,
  354. // color: '#FF2D68'
  355. // }, {
  356. // offset: 1,
  357. // color: '#4C4BFF'
  358. // }]),
  359. },
  360. itemStyle: {
  361. borderWidth: 5,
  362. borderColor: '#FFAD52',
  363. color: '#FFAD52'
  364. },
  365. data: ydata
  366. }]
  367. };
  368. chart.setOption(option);
  369. return chart;
  370. }
  371. function initChart1(canvas, width, height, dpr) {
  372. const chart = echarts.init(canvas, null, {
  373. width: width,
  374. height: height,
  375. devicePixelRatio: dpr // new
  376. });
  377. canvas.setChart(chart);
  378. today_stock.forEach(item=>{
  379. item.value = item.fund
  380. })
  381. var radius = today_stock.length<9?'65%':'50%';
  382. var option = {
  383. backgroundColor: "#ffffff",
  384. legend: {
  385. show: true,
  386. orient: 'vertical',
  387. right: '1%',
  388. formatter: function (name){
  389. var index = 0;
  390. today_stock.forEach(function (value, i) {
  391. if (value.name == name) {
  392. index = i;
  393. }
  394. });
  395. return name + " " + today_stock[index].value;
  396. }
  397. },
  398. series: [{
  399. label: {
  400. normal: {
  401. show: true,
  402. fontSize: 12,
  403. formatter: function (a) {
  404. return Math.round(a.percent)+'%'
  405. }
  406. }
  407. },
  408. type: 'pie',
  409. center: ['37%', '40%'],
  410. radius: ['0%', radius],
  411. data: today_stock
  412. }]
  413. };
  414. chart.setOption(option);
  415. return chart;
  416. }