| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278 |
- // pages/today/today.js
- import * as echarts from '../../ec-canvas/echarts';
- const $api = require('../../utils/api.js').API;
- var id, record_id, records = [], today_stock=[];
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- ec: {
- onInit: null
- },
- ec1: {
- onInit: null
- }
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- // options.id = 7, options.record_id = 29014
- id = options.id, record_id = options.record_id
- this.setData({
- id: id,
- record_id: record_id,
- player_id: options.player_id ? options.player_id:''
- })
- this.getData();
- },
- getData(){
- wx.showNavigationBarLoading();
- var data = {}
- if (this.data.id) {
- data.id = this.data.id
- }
- if (this.data.player_id) {
- data.player_id = this.data.player_id
- }
- if (this.data.record_id) {
- data.record_id = this.data.record_id
- }
- $api.getPlayerMatch(data).then(res=>{
- this.setData({
- datas: res.data.data,
- is_follow: res.data.data.is_follow,
- ec: {
- onInit: initChart
- },
- ec1: {
- onInit: initChart1
- }
- })
- records = res.data.data.records
- today_stock = res.data.data.today_record.today_stock
- wx.hideNavigationBarLoading()
- })
- .catch(err=>{
- wx.hideNavigationBarLoading()
- })
- //每日持股
- var parm={
- id: data.id, player_id: this.data.player_id
- }
- $api.getRecordList(parm).then(res=>{
- this.setData({
- stockList:res.data.data.list
- })
- })
- },
- //预览
- preview(e) {
- wx.previewImage({
- urls: e.target.dataset.urls,
- current: e.target.dataset.src
- })
- },
- followPlayer(e){
- let action = e.target.dataset.action;
- $api.follow({ follow_id: this.data.player_id, action:action}).then(res=>{
- wx.showToast({
- title: action?'取消成功':'已关注',
- })
- this.setData({
- is_follow: !this.data.is_follow
- })
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
- /**折线图 */
- function initChart(canvas, width, height, dpr) {
- var xdata = [], ydata = [];
- for (let i = 0; i < records.length; i++) {
- let date = records[i].stock_date.split('-');
- xdata.push(date[1] + '/' + date[2])
- let y = records[i].total_income.replace('%', '')
- ydata.push(Number(y))
- }
- xdata = xdata.reverse()
- ydata = ydata.reverse()
- const chart = echarts.init(canvas, null, {
- width: width,
- height: height,
- devicePixelRatio: dpr // new
- });
- canvas.setChart(chart);
- var option = {
- legend: {
- show: false
- },
- grid: {
- x: 50,
- y: 40,
- x2: 10,
- y2: 35
- },
- tooltip: {
- show: true,
- trigger: 'axis',
- formatter: '{b0}: {c0}%'
- },
- xAxis: {
- type: 'category',
- data: xdata,
- axisLabel: {
- interval: 0,
- rotate: 40,
- color: '#999999',
- interval: 2
- }
- },
- yAxis: {
- axisLine: {
- show: true
- },
- type: 'value',
- name: '收益曲线',
- axisLabel: {
- formatter: function (value, index) {//隐藏 0
- let texts = [];
- texts.push(value + '%')
- return texts;
- },
- show: true
- },
- },
- series: [{
- name: 'A',
- type: 'line',
- smooth: true,
- symbolSize: 8,
- lineStyle: {
- color: '#FF2D68'
- // color: new echarts.graphic.LinearGradient(1, 0, 0, 0, [{
- // offset: 0,
- // color: '#FF2D68'
- // }, {
- // offset: 1,
- // color: '#4C4BFF'
- // }]),
- },
- itemStyle: {
- borderWidth: 5,
- borderColor: '#FFAD52',
- color: '#FFAD52'
- },
- data: ydata
- }]
- };
- chart.setOption(option);
- return chart;
- }
- function initChart1(canvas, width, height, dpr) {
- const chart = echarts.init(canvas, null, {
- width: width,
- height: height,
- devicePixelRatio: dpr // new
- });
- canvas.setChart(chart);
- today_stock.forEach(item=>{
- item.value = item.fund
- })
- var radius = today_stock.length<9?'65%':'50%';
- var option = {
- backgroundColor: "#ffffff",
- legend: {
- show: true,
- orient: 'vertical',
- right: '1%',
- formatter: function (name){
- var index = 0;
- today_stock.forEach(function (value, i) {
- if (value.name == name) {
- index = i;
- }
- });
- return name + " " + today_stock[index].value;
- }
- },
- series: [{
- label: {
-
- normal: {
- show: true,
- fontSize: 12,
- formatter: function (a) {
- return Math.round(a.percent)+'%'
- }
- }
- },
- type: 'pie',
- center: ['37%', '40%'],
- radius: ['0%', radius],
- data: today_stock
-
- }]
- };
- chart.setOption(option);
- return chart;
- }
|