today.js 9.0 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. 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. cur_user_id: res.data.data.today_record.user_id,
  119. followers:res.data.data.followers,
  120. fans:res.data.data.fans,
  121. record_id: this.data.record_id ? this.data.record_id:res.data.data.today_record.id,
  122. ec: {
  123. onInit: initChart
  124. },
  125. ec1: {
  126. onInit: initChart1
  127. }
  128. })
  129. records = res.data.data.records
  130. today_stock = res.data.data.today_record.today_stock
  131. this.getDays()
  132. this.getzan()
  133. this.getComment()
  134. wx.hideNavigationBarLoading()
  135. })
  136. .catch(err=>{
  137. wx.hideNavigationBarLoading()
  138. })
  139. //每日持股
  140. var parm={
  141. id: data.id, player_id: this.data.player_id
  142. }
  143. $api.getRecordList(parm).then(res=>{
  144. this.setData({
  145. stockList:res.data.data.list
  146. })
  147. })
  148. },
  149. bindDateChange(e){
  150. this.setData({
  151. date: e.detail.value
  152. })
  153. this.getDays()
  154. },
  155. prev(){
  156. var date=this.data.date.split('-'),y=date[0],m=date[1];
  157. if(m>1){
  158. m--
  159. }else{
  160. m=12
  161. y--
  162. }
  163. m=(m>9)?m:'0'+m
  164. this.setData({
  165. date: y+'-'+m
  166. })
  167. this.getDays()
  168. },
  169. next() {
  170. var date = this.data.date.split('-'), y = date[0], m = date[1];
  171. if (m < 12) {
  172. m++
  173. } else {
  174. m = 1
  175. y++
  176. }
  177. m = (m > 9) ? m : '0' + m
  178. this.setData({
  179. date: y + '-' + m
  180. })
  181. this.getDays()
  182. },
  183. //预览
  184. preview(e) {
  185. wx.previewImage({
  186. urls: e.target.dataset.urls,
  187. current: e.target.dataset.src
  188. })
  189. },
  190. followPlayer(e){
  191. let action = e.target.dataset.action;
  192. $api.follow({ follow_id: this.data.player_id, action:action}).then(res=>{
  193. wx.showToast({
  194. title: action?'取消成功':'已关注',
  195. })
  196. this.setData({
  197. is_follow: !this.data.is_follow
  198. })
  199. app.globalData.follow=1
  200. })
  201. },
  202. inputchange(e) {
  203. this.setData({
  204. comment: e.detail.value
  205. })
  206. },
  207. blur(){
  208. this.setData({
  209. comment:'',
  210. pid:null,
  211. text:'留言'
  212. })
  213. },
  214. sendmsg(){
  215. var data={
  216. record_id:this.data.record_id,
  217. cotent:this.data.comment,
  218. pid:this.data.pid
  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}).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: 50,
  314. y: 40,
  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. formatter: function (value, index) {//隐藏 0
  341. let texts = [];
  342. texts.push(value + '%')
  343. return texts;
  344. },
  345. show: true
  346. },
  347. },
  348. series: [{
  349. name: 'A',
  350. type: 'line',
  351. smooth: true,
  352. symbolSize: 8,
  353. lineStyle: {
  354. color: '#FF2D68'
  355. // color: new echarts.graphic.LinearGradient(1, 0, 0, 0, [{
  356. // offset: 0,
  357. // color: '#FF2D68'
  358. // }, {
  359. // offset: 1,
  360. // color: '#4C4BFF'
  361. // }]),
  362. },
  363. itemStyle: {
  364. borderWidth: 5,
  365. borderColor: '#FFAD52',
  366. color: '#FFAD52'
  367. },
  368. data: ydata
  369. }]
  370. };
  371. chart.setOption(option);
  372. return chart;
  373. }
  374. function initChart1(canvas, width, height, dpr) {
  375. const chart = echarts.init(canvas, null, {
  376. width: width,
  377. height: height,
  378. devicePixelRatio: dpr // new
  379. });
  380. canvas.setChart(chart);
  381. today_stock.forEach(item=>{
  382. item.value = item.fund
  383. })
  384. var radius = today_stock.length<9?'65%':'50%';
  385. var option = {
  386. backgroundColor: "#ffffff",
  387. legend: {
  388. show: true,
  389. orient: 'vertical',
  390. right: '1%',
  391. formatter: function (name){
  392. var index = 0;
  393. today_stock.forEach(function (value, i) {
  394. if (value.name == name) {
  395. index = i;
  396. }
  397. });
  398. return name + " " + today_stock[index].value;
  399. }
  400. },
  401. series: [{
  402. label: {
  403. normal: {
  404. show: true,
  405. fontSize: 12,
  406. formatter: function (a) {
  407. return Math.round(a.percent)+'%'
  408. }
  409. }
  410. },
  411. type: 'pie',
  412. center: ['37%', '40%'],
  413. radius: ['0%', radius],
  414. data: today_stock
  415. }]
  416. };
  417. chart.setOption(option);
  418. return chart;
  419. }