123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374 |
- <template>
- <view class="order-statistics">
- <view class="select-date">
- <u-input
- style="flex: 1;"
- v-model="timeRange"
- type="select"
- :selectOpen="show"
- border
- placeholder="选择时间范围"
- @click="show = true"
- height="76rpx"
- />
- <view style="margin-left: 16rpx;"><u-icon name="download" size="48"></u-icon></view>
- <u-calendar
- v-model="show"
- mode="range"
- @change="bindDateChange"
- startText="开始日期"
- endText="结束日期"
- active-bg-color="#00C18A"
- active-color="#FFFFFF"
- range-bg-color="#00C18A"
- rangeColor="#FFFFFF"
- zIndex="9999999"
- >
- </u-calendar>
- </view>
- <!-- 四个框框(统计数据) -->
- <view class="overview-data-box">
- <view class="data-item" v-for="(item, index) in overviewData" :key="index">
- <data-item :dataItem="item" :globalImages="globalImages"/>
- </view>
- </view>
-
- <u-card v-show="!show" padding="32" full :showHead="false">
- <view slot="body" style="width: 100%;height: 400rpx;position: relative;">
- <BtnGroup v-model="orderSelect" :defaultVal="2" :options="orderOptions"></BtnGroup>
- <uni-ec-canvas class="uni-ec-canvas" id="order-revenue" canvas-id="order-revenue-chart" :ec="ec1" ref="canvas1"></uni-ec-canvas>
- </view>
- </u-card>
- <view></view>
- <u-card v-show="!show" padding="32" full :showHead="false">
- <view slot="body" style="width: 100%;height: 400rpx;position: relative;">
- <BtnGroup v-model="compareSelect" :defaultVal="2" :options="compareOptions"></BtnGroup>
- <uni-ec-canvas class="uni-ec-canvas" id="data-compare" canvas-id="data-compare-chart" :ec="ec2" ref="canvas2"></uni-ec-canvas>
- </view>
- </u-card>
- </view>
- </template>
- <script>
- import DataItem from './DataItem.vue'
- import BtnGroup from './BtnGroup.vue'
- import uniEcCanvas from '@/components/uni-ec-canvas/uni-ec-canvas'
- import * as echarts from '@/components/uni-ec-canvas/echarts.js'
- import { waitForGlobalImages } from '@/utils/globalImageLoader'
-
- export default {
- components: { DataItem, BtnGroup, uniEcCanvas },
- data() {
- return {
- globalImages: null,
- // 表示选中的日期,格式为"YYYY-MM-DD"
- timeRange: null,
- show: false,
- overviewData: [
- { title: '订单总量', value: '1248', status: 'up', fluctuate: '12.5%', bg: '#E8FBF6', valueColor: '#00C18A' },
- { title: '总收入', value: '¥8642', status: 'up', fluctuate: '8.3%', bg: '#FCF6EC', valueColor: '#E6A23C' },
- { title: '完成率', value: '98.7%', status: 'up', fluctuate: '1.2%', bg: '#ECF5FF', valueColor: '#409EFF' },
- { title: '平均评分', value: '4.9', status: 'down', fluctuate: '0.1', bg: '#FFE9E9', valueColor: '#F56C6C' },
- ],
- ec1: {
- option: {},
- },
- ec2: {
- option: {},
- },
- a: '',
- orderSelect: null,
- orderOptions: [
- { label: '日', value: 1 },
- { label: '周', value: 2 },
- { label: '月', value: 3 },
- ],
- compareSelect: null,
- compareOptions: [
- { label: '环比', value: 1 },
- { label: '同比', value: 2 },
- ],
- }
- },
- onLoad(e) {
- waitForGlobalImages().then((path) => {
- this.globalImages = path
- })
- setTimeout(() => {
- this.$nextTick(() => {
- this.$refs.canvas1.init(this.initChart1)
- this.$refs.canvas2.init(this.initChart2)
- })
- }, 20)
- },
- watch: {
- orderSelect(newVal) {
- if(newVal) {
- this.$refs.canvas1.init(this.initChart1)
- }
- },
- compareSelect(newVal) {
- if(newVal) {
- this.$refs.canvas2.init(this.initChart2)
- }
- },
- },
- methods: {
- // { startYear, startMonth, startDay, startDate, startWeek, endYear, endMonth, endDay, endDate, endWeek }
- bindDateChange(event) {
- this.timeRange = event.startDate + ' - ' + event.endDate
- },
- initChart1(canvas, width, height, canvasDpr) {
- let chart = echarts.init(canvas, null, {
- width: width,
- height: height,
- devicePixelRatio: canvasDpr
- })
-
- canvas.setChart(chart)
- let option = {
- title: {
- text: '订单与收入趋势',
- left: 0,
- top: 0,
- textStyle: {
- fontSize: 14
- },
- },
- grid: {
- top: '36%',
- left: '5%',
- right: '0%',
- bottom: '20%',
- containLabel: true,
- },
- legend: {
- bottom: 0,
- itemGap: 20,
- data: ['订单量', '收入'],
- },
- xAxis: {
- type: 'category',
- data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日'],
- boundaryGap: ['20%', '20%'],
- axisTick: {
- show: false,
- },
- splitLine: {
- show: false,
- },
- axisLine: {
- lineStyle: {
- color: '#E4E7ED',
- },
- },
- axisLabel: {
- color: '#333333',
- }
- },
- yAxis: [
- {
- type: 'value',
- name: '订单量',
- nameGap: 24,
- nameLocation: 'end',
- nameTextStyle: {
- align: 'right',
- padding: [0, 10, 0, 0],
- color: '#333333',
- },
- boundaryGap: ['10%', '10%'],
- axisTick: {
- show: false,
- },
- axisLine: {
- show: false,
- },
- splitLine: {
- lineStyle: {
- color: '#E4E7ED',
- },
- },
- axisLabel: {
- color: '#333333',
- },
- splitNumber: 3,
- },
- {
- type: 'value',
- name: '收入',
- nameGap: 24,
- nameLocation: 'end',
- nameTextStyle: {
- align: 'left',
- padding: [0, 0, 0, 20],
- color: '#333333',
- },
- axisLabel: {
- formatter: '¥ {value}',
- color: '#333333',
- },
- boundaryGap: ['10%', '10%'],
- axisTick: {
- show: false,
- },
- axisLine: {
- show: false,
- },
- splitLine: {
- lineStyle: {
- color: '#E4E7ED',
- },
- },
- splitNumber: 3,
- },
- ],
- series: [
- {
- name: '订单量',
- data: [120, 200, 150, 80, 70, 110, 130],
- type: 'bar',
- yAxisIndex: 0,
- itemStyle: {
- color: '#E8FBF6',
- borderRadius: [5, 5, 0, 0]
- },
- barWidth: 10,
- },
- {
- name: '收入',
- data: [120, 200, 150, 80, 70, 110, 130],
- type: 'line',
- yAxisIndex: 1,
- itemStyle: {
- color: '#00C18A',
- },
- // symbolSize: 8,
- }
- ]
- }
- chart.setOption(option)
- return chart
- },
- initChart2(canvas, width, height, canvasDpr) {
- let chart = echarts.init(canvas, null, {
- width: width,
- height: height,
- devicePixelRatio: canvasDpr
- })
-
- canvas.setChart(chart)
- let option = {
- title: {
- text: '数据对比',
- left: 0,
- top: 0,
- textStyle: {
- fontSize: 14
- },
- },
- grid: {
- top: '36%',
- left: '5%',
- right: '0%',
- bottom: '20%',
- containLabel: true,
- },
- legend: {
- bottom: 0,
- itemGap: 20,
- data: ['本周', '上周'],
- icon: 'roundRect',
- },
- xAxis: {
- type: 'category',
- data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日'],
- boundaryGap: [50, 50],
- axisTick: {
- show: false,
- },
- splitLine: {
- show: false,
- }
- },
- yAxis: {
- type: 'value',
- name: '订单量',
- nameGap: 30,
- nameLocation: 'end',
- nameTextStyle: {
- align: 'right',
- padding: [0, 10, 0, 0]
- },
- boundaryGap: ['10%', '10%'],
- splitNumber: 4,
- axisTick: {
- show: false,
- },
- axisLine: {
- show: false,
- },
- splitLine: {
- lineStyle: {
- color: '#E4E7ED',
- },
- },
- },
- series: [
- {
- name: '本周',
- data: [120, 200, 150, 80, 70, 110, 130],
- type: 'bar',
- itemStyle: {
- color: '#F56C6C',
- borderRadius: [5, 5, 0, 0]
- },
- barWidth: 10,
- },
- {
- name: '上周',
- data: [110, 190, 130, 60, 50, 90, 110],
- type: 'bar',
- itemStyle: {
- color: '#00C18A',
- borderRadius: [5, 5, 0, 0]
- },
- barWidth: 10,
- }
- ]
- }
- chart.setOption(option)
- return chart
- },
- },
- }
- </script>
- <style lang="scss">
- .order-statistics {
- width: 100%;
- position: relative;
- padding: 16rpx 32rpx;
- box-sizing: border-box;
-
- .select-date {
- display: flex;
- justify-content: space-between;
- align-items: center;
- margin-top: 16rpx;
- }
-
- .overview-data-box {
- margin-top: 24rpx;
- display: flex;
- flex-wrap: wrap;
- gap: 24rpx; /* 控制间距 */
- width: 100%;
-
- .data-item {
- flex: 1 1 calc(50% - 24rpx);
- position: relative;
- }
- }
- }
- </style>
|