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. ec: {
  17. onInit: null
  18. },
  19. ec1: {
  20. onInit: null
  21. }
  22. },
  23. /**
  24. * 生命周期函数--监听页面加载
  25. */
  26. onLoad: function (options) {
  27. // options.id = 9, options.player_id = 3520
  28. id = options.id, record_id = options.record_id
  29. this.setData({
  30. id: id,
  31. record_id: record_id,
  32. player_id: options.player_id ? options.player_id:''
  33. })
  34. $api.getAuthinfo().then(res=>{
  35. wx.setNavigationBarTitle({
  36. title: '',
  37. })
  38. this.setData({
  39. 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}).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}).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. // match_id player_id month: "2021-12"
  76. $api.getCalendar({
  77. player_id: this.data.player_id,
  78. match_id:this.data.id,
  79. month: this.data.date
  80. }).then(res=>{
  81. var days = [], w = new Date(this.data.date + '-01').getDay();
  82. for (let i = 0; i < w; i++) {
  83. days.push({
  84. day: '',
  85. income: ''
  86. })
  87. }
  88. for (let i = 0; i < res.data.data.length; i++) {
  89. days.push({
  90. day: i+1,
  91. income: res.data.data[i].today_income
  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.player_id) {
  106. data.player_id = this.data.player_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. player_id: res.data.data.today_record.player_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, player_id: this.data.player_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.player_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. }
  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}).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. }