web-africa-h5/pages/market/performance/directPush/Recommended.vue

308 lines
7.0 KiB
Vue

<template>
<view class="content">
<view class="content-picker d-e-c">
<view class="picker-small" @click="openCalendar2">
<text
class="mr10">{{ checkDay2?checkDay2[0]+' ' + $t('w_0139')+ ' ' +checkDay2[1]:$t('CK_KS_38') }}</text>
<u-icon name="arrow-down-fill" size="28rpx" color="#333"></u-icon>
</view>
</view>
<canvas canvas-id="UdaKiTnYTHLxuZItgHFhiCtezzDQzLfD" id="UdaKiTnYTHLxuZItgHFhiCtezzDQzLfD" class="charts"
@touchend="tap" />
<liu-calendar-date ref="calendar2" isRange @checked='getDate2'></liu-calendar-date>
</view>
</template>
<script>
import uCharts from '@/uni_modules/qiun-data-charts/js_sdk/u-charts/u-charts.js';
var uChartsInstance = {};
var getStarDay = function() {
let date = new Date();
let year = date.getFullYear();
let month = date.getMonth() + 1;
month = (month > 9) ? month : ("0" + month);
return year + '-' + month + '-01';
}
var getEndDay = function() {
let date = new Date();
let year = date.getFullYear();
let month = date.getMonth() + 1;
month = (month > 9) ? month : ("0" + month);
let day = date.getDate();
if (day > 1) {
day -= 1
}
day = (day < 10) ? ("0" + day) : day;
return year + '-' + month + '-' + day;
}
export default {
data() {
return {
cWidth: 750,
cHeight: 500,
checkDay2: [getStarDay(), getEndDay()]
};
},
onReady() {
//这里的 750 对应 css .charts 的 width
this.cWidth = uni.upx2px(750);
//这里的 500 对应 css .charts 的 height
this.cHeight = uni.upx2px(1000);
this.getServerData();
},
methods: { //打开选择器
openCalendar2() {
this.$refs.calendar2.open()
},
//日期区间选择成功
getDate2(e) {
this.checkDay2 = e.value;
this.getServerData();
},
getServerData() {
let self = this;
self._post('member/api/achieve/parent-achieve-left', {
startDate: self.checkDay2[0],
endDate: self.checkDay2[1],
}, res => {
let list = res.data;
let obj = {
categories: [],
series: [{
name: "海粉",
data: [],
pkGradeKey: 4303
},
{
name: self.$t('ENU_CUS_T_4'),
data: [],
pkGradeKey: 4339
},
{
name: "优客",
data: [],
pkGradeKey: 4305
},
{
name: "创客",
data: [],
pkGradeKey: 4306
},
{
name: "VIP",
data: [],
pkGradeKey: 4307
},
{
name: "SVIP",
data: [],
pkGradeKey: 4308
}
]
}
list.forEach((item, index) => {
obj.categories.push(item.memberName);
})
obj.series.forEach((sitem, sindex) => {
list.forEach((item, index) => {
sitem.data.push(0);
})
})
obj.series.forEach((sitem, sindex) => {
list.forEach((item, index) => {
item.umbrellaList.forEach((uitem, uindex) => {
if (sitem.pkGradeKey == uitem.pkGradeKey) {
sitem.data[index] = uitem.achieve * 1
}
})
})
})
console.log(obj)
self.drawCharts('UdaKiTnYTHLxuZItgHFhiCtezzDQzLfD', obj);
})
},
drawCharts(id, data) {
const ctx = uni.createCanvasContext(id, this);
uChartsInstance[id] = new uCharts({
type: "column",
context: ctx,
width: this.cWidth,
height: this.cHeight,
categories: data.categories,
series: data.series,
animation: true,
timing: "easeOut",
duration: 1000,
rotate: false,
rotateLock: false,
background: "#FFFFFF",
color: ["#c0c1c1", "#c0c1c1", "#c8d6e5", "#31d2d7", "#ecd884", "#7090ff", "#FC8452", "#9A60B4",
"#ea7ccc"
],
padding: [15, 15, 0, 5],
fontSize: 11,
fontColor: "#666666",
dataLabel: false,
dataPointShape: true,
dataPointShapeType: "solid",
touchMoveLimit: 60,
enableScroll: false,
enableMarkLine: false,
legend: {
show: true,
position: "bottom",
float: "center",
padding: 5,
margin: 5,
backgroundColor: "rgba(0,0,0,0)",
borderColor: "rgba(0,0,0,0)",
borderWidth: 0,
fontSize: 11,
fontColor: "#666666",
lineHeight: 11,
hiddenColor: "#CECECE",
itemGap: 10
},
xAxis: {
disableGrid: true,
disabled: false,
axisLine: true,
axisLineColor: "#CCCCCC",
calibration: false,
fontColor: "#666666",
fontSize: 11,
lineHeight: 20,
marginTop: 20,
rotateLabel: true,
rotateAngle: 45,
itemCount: 5,
boundaryGap: "center",
splitNumber: 5,
gridColor: "#CCCCCC",
gridType: "solid",
dashLength: 4,
gridEval: 1,
scrollShow: false,
scrollAlign: "left",
scrollColor: "#A6A6A6",
scrollBackgroundColor: "#EFEBEF",
title: "",
titleFontSize: 11,
titleOffsetY: 0,
titleOffsetX: 0,
titleFontColor: "#666666",
formatter: ""
},
yAxis: {
data: [{
min: 0
}],
disabled: false,
disableGrid: false,
splitNumber: 5,
gridType: "solid",
dashLength: 8,
gridColor: "#CCCCCC",
padding: 10,
showTitle: false
},
extra: {
column: {
type: "stack",
width: 30,
activeBgColor: "#000000",
activeBgOpacity: 0.08,
seriesGap: 2,
categoryGap: 3,
barBorderCircle: false,
linearType: "custom",
linearOpacity: 0.4,
customColor: [
"#c0c1c1",
"#c0c1c1",
"#c8d6e5",
"#31d2d7",
"#ecd884",
"#7090ff"
],
colorStop: 0,
meterBorder: 1,
meterFillColor: "#FFFFFF",
labelPosition: "outside"
},
tooltip: {
showBox: true,
showArrow: true,
showCategory: false,
borderWidth: 0,
borderRadius: 0,
borderColor: "#000000",
borderOpacity: 0.7,
bgColor: "#000000",
bgOpacity: 0.7,
gridType: "solid",
dashLength: 4,
gridColor: "#CCCCCC",
boxPadding: 3,
fontSize: 11,
lineHeight: 20,
fontColor: "#FFFFFF",
legendShow: true,
legendShape: "auto",
splitLine: true,
horizentalLine: false,
xAxisLabel: false,
yAxisLabel: false,
labelBgColor: "#FFFFFF",
labelBgOpacity: 0.7,
labelFontColor: "#666666"
},
markLine: {
type: "solid",
dashLength: 4,
data: []
}
}
});
},
tap(e) {
uChartsInstance[e.target.id].touchLegend(e);
uChartsInstance[e.target.id].showToolTip(e);
}
}
};
</script>
<style scoped>
page {
background: #ffffff;
}
.content {
min-height: 100vh;
background-color: #fff;
}
.content-picker {
padding: 26rpx 22rpx 26rpx 23rpx;
}
.picker-small {
height: 72rpx;
border: 1rpx solid #EEEEEE;
border-radius: 15rpx;
font-size: 28rpx;
padding: 0 28rpx 0 20rpx;
display: flex;
justify-content: space-between;
align-items: center;
box-sizing: border-box;
}
.charts {
width: 750rpx;
height: 1000rpx;
}
</style>