today.js 8.5 KB

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