today.js 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  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. role: res.data.data.role
  40. })
  41. })
  42. this.getData();
  43. this.getzan()
  44. this.getComment()
  45. },
  46. getzan(){
  47. $api.getZanCount({record_id:record_id}).then(res=>{
  48. this.setData({
  49. zan_count:res.data.data
  50. })
  51. })
  52. },
  53. getComment(){
  54. $api.getComment({record_id:record_id}).then(res=>{
  55. if(res.data.code == 0){
  56. this.setData({
  57. comment_list:res.data.data.list,
  58. comment_count:res.data.data.total
  59. })
  60. }
  61. })
  62. },
  63. answer(e){
  64. this.setData({
  65. focus:true,
  66. text:'回复'+e.target.dataset.name,
  67. pid:e.target.dataset.id
  68. })
  69. },
  70. tab(e){
  71. this.setData({
  72. page:e.target.dataset.id
  73. })
  74. },
  75. getDays(){
  76. // match_id player_id month: "2021-12"
  77. $api.getCalendar({
  78. player_id: this.data.player_id,
  79. match_id:this.data.id,
  80. month: this.data.date
  81. }).then(res=>{
  82. var days = [], w = new Date(this.data.date + '-01').getDay();
  83. for (let i = 0; i < w; i++) {
  84. days.push({
  85. day: '',
  86. income: ''
  87. })
  88. }
  89. for (let i = 0; i < res.data.data.length; i++) {
  90. days.push({
  91. day: i+1,
  92. income: res.data.data[i].today_income
  93. })
  94. }
  95. this.setData({
  96. days: days
  97. })
  98. })
  99. },
  100. getData(){
  101. wx.showNavigationBarLoading();
  102. var data = {}
  103. if (this.data.id) {
  104. data.id = this.data.id
  105. }
  106. if (this.data.player_id) {
  107. data.player_id = this.data.player_id
  108. }
  109. if (this.data.record_id) {
  110. data.record_id = this.data.record_id
  111. }
  112. $api.getPlayerMatch(data).then(res=>{
  113. let stock_date=res.data.data.today_record.stock_date.split('-')
  114. this.setData({
  115. datas: res.data.data,
  116. date: stock_date[0] + '-' + stock_date[1],
  117. is_follow: res.data.data.is_follow,
  118. player_id: res.data.data.today_record.player_id,
  119. followers:res.data.data.followers,
  120. fans:res.data.data.fans,
  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. wx.hideNavigationBarLoading()
  132. })
  133. .catch(err=>{
  134. wx.hideNavigationBarLoading()
  135. })
  136. //每日持股
  137. var parm={
  138. id: data.id, player_id: this.data.player_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.player_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. zan(){
  230. $api.zan({record_id:record_id}).then(res=>{
  231. if(res.data.code == 0){
  232. this.getzan()
  233. }
  234. })
  235. },
  236. /**
  237. * 生命周期函数--监听页面初次渲染完成
  238. */
  239. onReady: function () {
  240. },
  241. /**
  242. * 生命周期函数--监听页面显示
  243. */
  244. onShow: function () {
  245. },
  246. /**
  247. * 生命周期函数--监听页面隐藏
  248. */
  249. onHide: function () {
  250. },
  251. /**
  252. * 生命周期函数--监听页面卸载
  253. */
  254. onUnload: function () {
  255. },
  256. /**
  257. * 页面相关事件处理函数--监听用户下拉动作
  258. */
  259. onPullDownRefresh: function () {
  260. },
  261. /**
  262. * 页面上拉触底事件的处理函数
  263. */
  264. onReachBottom: function () {
  265. },
  266. /**
  267. * 用户点击右上角分享
  268. */
  269. onShareAppMessage: function () {
  270. }
  271. })
  272. /**折线图 */
  273. function initChart(canvas, width, height, dpr) {
  274. var xdata = [], ydata = [];
  275. for (let i = 0; i < records.length; i++) {
  276. let date = records[i].stock_date.split('-');
  277. xdata.push(date[1] + '/' + date[2])
  278. let y = records[i].total_income.replace('%', '')
  279. ydata.push(Number(y))
  280. }
  281. xdata = xdata.reverse()
  282. ydata = ydata.reverse()
  283. const chart = echarts.init(canvas, null, {
  284. width: width,
  285. height: height,
  286. devicePixelRatio: dpr // new
  287. });
  288. canvas.setChart(chart);
  289. var option = {
  290. legend: {
  291. show: false
  292. },
  293. grid: {
  294. x: 50,
  295. y: 40,
  296. x2: 10,
  297. y2: 35
  298. },
  299. tooltip: {
  300. show: true,
  301. trigger: 'axis',
  302. formatter: '{b0}: {c0}%'
  303. },
  304. xAxis: {
  305. type: 'category',
  306. data: xdata,
  307. axisLabel: {
  308. interval: 0,
  309. rotate: 40,
  310. color: '#999999',
  311. interval: 2
  312. }
  313. },
  314. yAxis: {
  315. axisLine: {
  316. show: true
  317. },
  318. type: 'value',
  319. name: '收益曲线',
  320. axisLabel: {
  321. formatter: function (value, index) {//隐藏 0
  322. let texts = [];
  323. texts.push(value + '%')
  324. return texts;
  325. },
  326. show: true
  327. },
  328. },
  329. series: [{
  330. name: 'A',
  331. type: 'line',
  332. smooth: true,
  333. symbolSize: 8,
  334. lineStyle: {
  335. color: '#FF2D68'
  336. // color: new echarts.graphic.LinearGradient(1, 0, 0, 0, [{
  337. // offset: 0,
  338. // color: '#FF2D68'
  339. // }, {
  340. // offset: 1,
  341. // color: '#4C4BFF'
  342. // }]),
  343. },
  344. itemStyle: {
  345. borderWidth: 5,
  346. borderColor: '#FFAD52',
  347. color: '#FFAD52'
  348. },
  349. data: ydata
  350. }]
  351. };
  352. chart.setOption(option);
  353. return chart;
  354. }
  355. function initChart1(canvas, width, height, dpr) {
  356. const chart = echarts.init(canvas, null, {
  357. width: width,
  358. height: height,
  359. devicePixelRatio: dpr // new
  360. });
  361. canvas.setChart(chart);
  362. today_stock.forEach(item=>{
  363. item.value = item.fund
  364. })
  365. var radius = today_stock.length<9?'65%':'50%';
  366. var option = {
  367. backgroundColor: "#ffffff",
  368. legend: {
  369. show: true,
  370. orient: 'vertical',
  371. right: '1%',
  372. formatter: function (name){
  373. var index = 0;
  374. today_stock.forEach(function (value, i) {
  375. if (value.name == name) {
  376. index = i;
  377. }
  378. });
  379. return name + " " + today_stock[index].value;
  380. }
  381. },
  382. series: [{
  383. label: {
  384. normal: {
  385. show: true,
  386. fontSize: 12,
  387. formatter: function (a) {
  388. return Math.round(a.percent)+'%'
  389. }
  390. }
  391. },
  392. type: 'pie',
  393. center: ['37%', '40%'],
  394. radius: ['0%', radius],
  395. data: today_stock
  396. }]
  397. };
  398. chart.setOption(option);
  399. return chart;
  400. }