today.js 8.4 KB

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