smartswrtch-app/pages/tj.vue

552 lines
13 KiB
Vue
Raw Normal View History

2023-12-05 16:45:28 +08:00
<template>
2024-06-08 18:04:47 +08:00
<view class="page" >
2024-12-03 14:40:32 +08:00
<u-navbar :is-back="false" title="统计" :border-bottom="false" :background="bgc" title-color='#fff'
2024-05-24 16:48:42 +08:00
title-size='44' height='48' id="navbar">
2024-05-10 17:37:36 +08:00
</u-navbar>
2024-12-03 14:40:32 +08:00
<view style="padding-top: 30rpx;">
2024-05-10 17:37:36 +08:00
<view class="card">
<view class="xzsj">
2024-05-10 21:35:42 +08:00
<u-picker mode="time" v-model="show" :params="params" @confirm="confirm"></u-picker>
2024-05-10 17:37:36 +08:00
</view>
2024-12-03 14:40:32 +08:00
<view class="month" style="display: flex;">
<text @click="btnshow(1)">{{yeartime.year + '' + yeartime.month + '' + yeartime.day + ''}} </text>
<view class="" style="margin: 0 10rpx;">
-
</view>
<view @click="btnshow(2)">{{yeartimes.year + '' + yeartimes.month + '' + yeartimes.day + ''}} <u-icon style="margin-left: 10rpx;margin-top: 6rpx;"name="arrow-down-fill"></u-icon></view>
2024-05-10 17:37:36 +08:00
</view>
<view class="tit">
2024-12-03 14:40:32 +08:00
当前时间段收入{{recharge.toFixed(2)}} 累计收入{{totalRecharge.toFixed(2)}}
2024-05-10 17:37:36 +08:00
</view>
2024-05-10 21:35:42 +08:00
2024-05-24 16:48:42 +08:00
<view class="echarts" >
<uni-ec-canvas class="uni-ec-canvas" id="uni-ec-canvas" ref="canvas" canvas-id="uni-ec-canvas" :ec="ec"></uni-ec-canvas>
2024-05-10 17:37:36 +08:00
</view>
2024-01-24 11:55:35 +08:00
</view>
2024-05-24 16:48:42 +08:00
<view class="list" style="padding-bottom: 240rpx;">
2024-06-14 18:51:43 +08:00
<view class="card_list" v-for="(item,index) in timelists" :key="index">
2024-05-10 17:37:36 +08:00
<view class="left">
2024-12-03 14:40:32 +08:00
<!-- // {{yeartime.year + '年' + yeartime.month + '月' + item.createDay + '日'}} -->
{{item.key}}
2024-05-10 17:37:36 +08:00
</view>
<view class="right">
2024-12-03 14:40:32 +08:00
{{item.value}}
2024-05-10 17:37:36 +08:00
</view>
</view>
2024-01-24 11:55:35 +08:00
</view>
2024-05-10 17:37:36 +08:00
</view>
<view v-if="userType=='00'">
<view class="title">
统计
2024-01-24 11:55:35 +08:00
</view>
2024-05-10 17:37:36 +08:00
<view class="card">
<view class="xzsj">
<u-picker mode="time" v-model="show" :params="params" @confirm="confirm"></u-picker>
</view>
<view class="month" @click="show = true">
2024-12-03 14:40:32 +08:00
{{yeartime.year + '年' + yeartime.month + '月' + yeartime.day + '日'}}
2024-01-27 16:37:52 +08:00
</view>
2024-05-10 17:37:36 +08:00
<view class="tit">
本月用电量
</view>
<div class="txt">
{{quantity}}
</div>
<view class="echarts" v-if="loging">
</view>
</view>
2024-01-27 16:37:52 +08:00
</view>
2024-12-03 14:40:32 +08:00
<!-- <view class="name">
更多功能
</view>
<view class="gongneng">
<image @click="btndingdan" src="https://api.ccttiot.com/smartmeter/img/static/uabiTqXSZVFrY5ck0MoK" mode=""></image>
<image @click="btnshebie" src="https://api.ccttiot.com/smartmeter/img/static/u5SKuZPtnuFJPdQOYe4u" mode=""></image>
<image @click="btndianpu" src="https://api.ccttiot.com/smartmeter/img/static/ubVQt7h69i4GKsvRK64V" mode=""></image>
<image @click="btngeren" src="https://api.ccttiot.com/smartmeter/img/static/uUnZuUCeUajUb5gD23O4" mode=""></image>
</view> -->
<tab-bar :indexs='1' style=""></tab-bar>
2023-12-05 16:45:28 +08:00
</view>
</template>
<script>
2024-05-10 21:35:42 +08:00
import uniEcCanvas from '@/components/uni-ec-canvas/uni-ec-canvas.vue'
import * as echarts from '@/components/uni-ec-canvas/echarts'
let chart = null
2023-12-05 16:45:28 +08:00
export default {
2024-01-24 11:55:35 +08:00
components: {
2024-05-10 21:35:42 +08:00
uniEcCanvas
2024-01-24 11:55:35 +08:00
},
2023-12-05 16:45:28 +08:00
data() {
return {
2024-05-10 21:35:42 +08:00
ec: {
lazyLoad: true
},
2024-03-25 19:46:07 +08:00
params: {
year: true,
month: true,
2024-12-03 14:40:32 +08:00
day: true,
2024-03-25 19:46:07 +08:00
hour: false,
minute: false,
second: false
},
2024-05-10 21:35:42 +08:00
recharge: 0,
2024-05-10 17:37:36 +08:00
bgc: {
2024-05-21 18:02:34 +08:00
backgroundColor: "#8883f0",
2024-05-10 17:37:36 +08:00
},
2024-03-25 19:46:07 +08:00
show: false,
yeartime: {
year: '',
2024-12-03 14:40:32 +08:00
month: '',
day:''
},
yeartimes: {
year: '',
month: '',
day:''
2024-03-25 19:46:07 +08:00
},
timelist: '',
quantity: 0, //电量
chartData: [],
2024-05-10 21:35:42 +08:00
chartday: [],
loging: true,
deviceId: '',
userType: '',
totalRecharge: 0,
2024-06-14 18:51:43 +08:00
dateday:'',
timelists:'',
2024-12-03 14:40:32 +08:00
monthdui:'',
employId:'',
sceneValue:'',
kstime:'',
jstime:'',
num:''
2024-01-23 19:15:52 +08:00
}
},
2024-07-17 17:59:51 +08:00
// 分享到好友(会话)
onShareAppMessage: function () {
return {
title: '创想物联',
path: '/pages/shouye/index'
}
},
// 分享到朋友圈
onShareTimeline: function () {
return {
title: '创想物联',
query: '',
path: '/pages/shouye/index'
}
},
2024-12-03 14:40:32 +08:00
onLoad(option) {
if(option.q){
function getQueryParam(url, paramName) {
let regex = new RegExp(`[?&]${paramName}=([^&]*)`);
let results = regex.exec(url);
return results ? decodeURIComponent(results[1].replace(/\+/g, ' ')) : null
}
this.sceneValue = option.q
let decodedValue = decodeURIComponent(this.sceneValue);
let id = getQueryParam(decodedValue, 'i')
this.employId = id
let that = this
uni.showModal({
title: '温馨提示',
content: '您确定要成为合伙人吗?',
showCancel: true,
success: function(res) {
if (res.confirm) {
that.$u.put(`/app/storeStaff/bindUser?employId=${that.employId}`).then(res => {
if (res.code == 200) {
uni.showToast({
title:'绑定成功',
icon: 'success',
duration: 2000
})
}else if(res.code == 401){
uni.reLaunch({
url:'/pages/login/login'
})
}else{
uni.showToast({
title: res.msg,
icon: 'none',
duration: 2000
})
}
})
} else if (res.cancel) {
uni.reLaunch({
url:'/pages/shouye/index'
})
}
}
})
}
2024-03-25 19:46:07 +08:00
},
onShow() {
2024-05-27 16:06:08 +08:00
this.timelist = []
2024-05-11 13:33:17 +08:00
setTimeout(() => {
2024-11-21 17:33:15 +08:00
console.log(this.$refs)
2024-05-11 13:33:17 +08:00
this.$refs.canvas.init(this.initChart)
2024-05-27 16:06:08 +08:00
}, 500)
2024-05-10 17:37:36 +08:00
this.recharge = 0
2024-05-10 21:35:42 +08:00
const now = new Date();
2024-12-03 14:40:32 +08:00
this.yeartime = {
year: now.getFullYear(),
month: now.getMonth() + 1, // 月份从0开始所以需要+1
day: 1 // 设置为月份的第一天
}
this.kstime = this.yeartime.year + '-' + this.yeartime.month + '-' + (this.yeartime.day < 10 ? '0' + this.yeartime.day : this.yeartime.day)
this.yeartimes.year = now.getFullYear()
this.yeartimes.month = now.getMonth() + 1
this.yeartimes.day = now.getDate()
this.jstime = this.yeartimes.year + '-' + this.yeartimes.month + '-' + (this.yeartimes.day < 10 ? '0' + this.yeartimes.day : this.yeartimes.day)
2024-05-11 13:33:17 +08:00
this.gettime()
2024-01-24 11:55:35 +08:00
},
2024-01-23 19:15:52 +08:00
methods: {
2024-12-03 14:40:32 +08:00
// 选择时间
btnshow(num){
this.show = true
this.num = num
},
// 点击跳转到管理店铺
btndianpu(){
uni.navigateTo({
url:'/page_fenbao/statulist/myshop/index?types=' + 11
})
},
// 点击返回首页
btns(){
uni.reLaunch({
url:'/pages/shouye/index'
})
},
// 点击跳转到个人中心
btngeren(){
uni.navigateTo({
url:'/page_fenbao/hehuoren/geren'
})
},
// 点击跳转到订单管理
btndingdan(){
uni.navigateTo({
url:'/page_user/switchs?type=' + 11
})
},
// 点击跳转到设备列表
btnshebie(){
uni.navigateTo({
url:'/page_fenbao/hehuoren/shebeilist'
})
},
2024-03-25 19:46:07 +08:00
// 点击获取时间
confirm(e) {
2024-12-03 14:40:32 +08:00
console.log(e);
2024-05-10 17:37:36 +08:00
this.recharge = 0
2024-12-03 14:40:32 +08:00
if(this.num == 1){
this.yeartime = e
this.kstime = this.yeartime.year + '-' + this.yeartime.month + '-' + this.yeartime.day
}else{
this.yeartimes = e
this.jstime = this.yeartimes.year + '-' + this.yeartimes.month + '-' + this.yeartimes.day
}
2024-03-25 19:46:07 +08:00
this.gettime()
2024-05-11 13:33:17 +08:00
setTimeout(() => {
2024-11-21 17:33:15 +08:00
console.log(this.$refs)
2024-05-11 13:33:17 +08:00
this.$refs.canvas.init(this.initChart)
2024-05-27 16:06:08 +08:00
}, 500)
2024-03-25 19:46:07 +08:00
},
// 进行获取用电量请求
gettime() {
2024-12-03 14:40:32 +08:00
// let data = {
// year: this.yeartime.year,
// month: this.yeartime.month,
// groupBy: 'create_date'
// }
2024-05-10 21:35:42 +08:00
this.loging = false
2024-12-03 14:40:32 +08:00
this.$u.get(`/app/dashboard/bonusDailyAmount?payDateStart=${this.kstime}&payDateEnd=${this.jstime}`).then((res) => {
2024-03-25 19:46:07 +08:00
if (res.code == 200) {
this.timelist = res.data
2024-12-03 14:40:32 +08:00
// if(this.monthdui != this.yeartime.month){
// this.timelists = this.timelist
// this.totalRecharge = res.totalRecharge
this.chartData = this.timelist.map(item => item.value);
this.chartday = this.timelist.map(item => item.key.slice(-2) + '日');
// }else{
// this.timelists = this.timelist.slice(0,this.dateday)
// this.timelists.reverse()
// this.totalRecharge = res.totalRecharge
// this.chartData = this.timelist.slice(0, this.dateday).map(item => item.recharge)
// this.chartday = this.timelist.slice(0, this.dateday).map(item => item.createDay + '日');
// }
this.timelists = this.timelist
this.totalRecharge = res.total
2024-05-10 21:35:42 +08:00
this.loging = true
2024-03-25 19:46:07 +08:00
for (let i = 0; i < this.timelist.length; i++) {
2024-12-03 14:40:32 +08:00
this.recharge += this.timelist[i].value
2024-03-25 19:46:07 +08:00
}
2024-05-10 17:37:36 +08:00
return this.recharge
2024-05-10 21:35:42 +08:00
this.$refs.canvas.init(this.initChart)
2024-12-03 14:40:32 +08:00
}else{
uni.showToast({
title:res.msg,
icon: 'none',
duration:2000
})
2024-03-25 19:46:07 +08:00
}
})
},
2024-05-10 17:37:36 +08:00
gettimes() {
let data = {
2024-05-10 21:35:42 +08:00
deviceId: this.deviceId,
2024-05-10 17:37:36 +08:00
year: this.yeartime.year,
month: this.yeartime.month,
groupBy: 'create_date'
}
2024-05-10 21:35:42 +08:00
this.loging = false
2024-05-10 17:37:36 +08:00
this.$u.get('/app/device/electric/count', data).then((res) => {
if (res.code == 200) {
this.timelist = res.data
this.chartData = this.timelist.map(item => item.usedElectriQuantity);
2024-05-10 21:35:42 +08:00
this.chartday = this.timelist.map(item => item.createDay + '日');
this.loging = true
2024-05-10 17:37:36 +08:00
}
})
},
2024-01-24 11:55:35 +08:00
generateWaveData(length) {
2024-03-25 19:46:07 +08:00
const data = []
2024-01-27 16:37:52 +08:00
for (let i = 0; i < length; i++) {
2024-03-25 19:46:07 +08:00
const y = Math.sin((i / (length - 1)) * Math.PI * 2) // 正弦函数生成波浪形状的y值
data.push((y + 1) * 50) // 映射到0-100的范围
2024-01-27 16:37:52 +08:00
}
2024-03-25 19:46:07 +08:00
return data
2024-01-27 16:37:52 +08:00
},
2024-05-10 21:35:42 +08:00
initChart(canvas, width, height, canvasDpr) {
let that = this
console.log(canvas, width, height, canvasDpr)
2024-03-25 19:46:07 +08:00
const option = {
grid: {
left: 60,
right: 10,
top: 10,
bottom: 30,
},
xAxis: {
type: 'category',
boundaryGap: false,
axisLine: {
show: false,
},
axisTick: {
show: false,
},
axisLabel: {
show: true,
color: '#fff',
fontSize: 11,
rotate: 0,
},
splitLine: {
show: false,
},
2024-05-10 21:35:42 +08:00
data: that.chartday,
2024-03-25 19:46:07 +08:00
},
yAxis: {
show: true,
axisLine: {
show: false,
},
axisTick: {
show: false,
},
axisLabel: {
show: true,
color: '#fff',
fontSize: 11,
formatter: function(value) {
// 保留两位小数没有小数时显示00
2024-06-11 18:03:16 +08:00
return value + '元'
2024-03-25 19:46:07 +08:00
},
},
splitLine: {
show: false,
},
},
series: [{
type: 'line',
smooth: 0.6,
symbol: 'none',
lineStyle: {
color: '#E0DBFF',
width: 4,
},
areaStyle: {
normal: {
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
offset: 0,
color: '#B4B0F7'
}, ]),
2024-08-12 21:49:12 +08:00
},
2024-03-25 19:46:07 +08:00
},
2024-05-10 21:35:42 +08:00
data: that.chartData,
2024-03-25 19:46:07 +08:00
}],
};
2024-05-10 21:35:42 +08:00
chart = echarts.init(canvas, null, {
width: width,
height: height,
devicePixelRatio: canvasDpr
})
2024-05-11 13:33:17 +08:00
2024-05-10 21:35:42 +08:00
option.series[0].data = that.chartData
canvas.setChart(chart)
2024-05-10 17:37:36 +08:00
chart.setOption(option)
2024-05-10 21:35:42 +08:00
return chart
},
2024-01-23 19:15:52 +08:00
}
}
2023-12-05 16:45:28 +08:00
</script>
2024-01-24 11:55:35 +08:00
<style lang="scss">
2024-05-24 16:48:42 +08:00
/deep/ .u-title{
padding-bottom: 20rpx;
}
/deep/ .u-icon__icon{
padding-bottom: 20rpx;
}
2024-05-10 21:35:42 +08:00
.uni-ec-canvas {
width: 100%;
height: 320rpx;
display: block;
margin-top: 30rpx;
}
2024-03-25 19:46:07 +08:00
.btnxz {
padding: 0 20rpx;
box-sizing: border-box;
font-size: 28rpx;
font-family: Source Han Sans, Source Han Sans;
font-weight: 400;
color: #FFFFFF;
}
2024-01-24 11:55:35 +08:00
page {
background-color: #F7FAFE;
}
.page {
padding: 0 59rpx;
2024-12-03 14:40:32 +08:00
.name{
font-size: 36rpx;
color: #3D3D3D;
margin-top: 20rpx;
}
.gongneng{
margin-top: 40rpx;
width: 632rpx;
height: 150rpx;
background: #FFFFFF;
box-shadow: 0rpx 16rpx 40rpx 0rpx rgba(42,130,228,0.1);
border-radius: 24rpx 24rpx 24rpx 24rpx;
display: flex;
justify-content: space-between;
padding: 26rpx 50rpx;
box-sizing: border-box;
image{
width: 96rpx;
height: 102rpx;
}
}
2024-01-24 11:55:35 +08:00
.title {
2024-03-25 19:46:07 +08:00
margin-top: 120rpx;
2024-01-24 11:55:35 +08:00
font-size: 48rpx;
font-weight: 400;
letter-spacing: 0rpx;
color: rgba(38, 43, 55, 1);
}
2024-01-23 19:15:52 +08:00
2024-01-24 11:55:35 +08:00
.card {
padding-top: 32rpx;
2024-05-24 16:48:42 +08:00
margin-top: 10rpx;
2024-01-24 11:55:35 +08:00
width: 632rpx;
2024-06-08 18:04:47 +08:00
height: 540rpx;
2024-01-24 11:55:35 +08:00
background: #8883F0;
box-shadow: 0rpx 16rpx 40rpx 0rpx rgba(42, 130, 228, 0.1);
opacity: 1;
border-radius: 40rpx;
.month {
2024-01-27 16:37:52 +08:00
2024-01-24 11:55:35 +08:00
margin-left: 22rpx;
font-size: 28rpx;
font-family: Source Han Sans, Source Han Sans;
font-weight: 400;
color: #FFFFFF;
}
.tit {
margin-top: 18rpx;
margin-left: 22rpx;
font-size: 20rpx;
font-family: HarmonyOS Sans SC, HarmonyOS Sans SC;
font-weight: 400;
color: #FFFFFF;
}
.txt {
margin-top: 2rpx;
margin-left: 22rpx;
font-size: 36rpx;
font-family: HarmonyOS Sans SC, HarmonyOS Sans SC;
font-weight: 700;
color: #FFFFFF;
}
2024-01-27 16:37:52 +08:00
2024-01-24 11:55:35 +08:00
.echarts {
margin-left: 22rpx;
margin-top: 60rpx;
width: 588rpx;
height: 320rpx;
}
}
2024-01-27 16:37:52 +08:00
.list {
margin-top: 16rpx;
2024-12-03 14:40:32 +08:00
height: 630rpx;
2024-06-08 18:04:47 +08:00
overflow: auto;
2024-01-27 16:37:52 +08:00
.card_list {
width: 632rpx;
height: 88rpx;
background: #FFFFFF;
opacity: 1;
border-radius: 30rpx;
display: flex;
flex-wrap: nowrap;
justify-content: space-between;
margin-top: 16rpx;
align-items: center;
.left {
margin-left: 52rpx;
font-size: 28rpx;
font-family: HarmonyOS Sans SC, HarmonyOS Sans SC;
font-weight: 400;
color: #808080;
}
.right {
margin-right: 20rpx;
font-size: 28rpx;
font-family: HarmonyOS Sans SC, HarmonyOS Sans SC;
font-weight: 400;
color: #808080;
}
}
}
2024-01-24 11:55:35 +08:00
}
</style>