today.js 8.6 KB

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