123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330 |
- <template>
- <view class="data">
- <view class="data-screen" @click="openScreen" style="padding-right:40rpx">
- <image class="screen-img" src="@/static/image/sx.png" alt="">
- <text>筛选</text>
- </view>
- <view class="echarts">
- <!-- <dataQuery v-if="service.length" :service="service" :serviceTime="serviceTime" /> -->
- <web-view :src="src" style="top:5vh;width:100%;height:1000rpx;"></web-view>
- <view v-if="monthQuery" class="query-screen">
- <view>
- 数据项选择
- </view>
- <div style="margin: 20px 0;">
- <uni-data-select v-model="dataValue" :localdata="datasList" @change="dataValueChange"
- placeholder="选择数据组"></uni-data-select>
- </div>
- <uni-data-select v-model="queryParams.id" :localdata="dataItem" placeholder="选择数据项"
- @change="itemChange"></uni-data-select>
- <view class="month">
- <view :class="monthCurrent===item.current?'month-select':'month-item'" v-for="item in monthList"
- :key="item.current" @click="monthChange(item.current)">
- {{item.name}}
- </view>
- </view>
- <uni-datetime-picker v-model="range" type="datetimerange" start-placeholder="起始时间"
- end-placeholder="终止时间" @change="handelDate" return-type="timestamp" />
- <view class="month-btn">
- <u-button class="reset" style="width:200rpx" @click="reset">重置</u-button>
- <u-button type="primary" style="width:200rpx" @click="handelQuery">确认</u-button>
- </view>
- </view>
- <view class="modal" v-if="monthQuery"></view>
- <u-empty v-if="!service.length" class="empty" icon="../../static/data.png" text="暂无数据">
- </u-empty>
- </view>
- </view>
- </template>
- <script>
- import dataQuery from '../../components/ecahrts/dataQuery.vue'
- import {
- getLastWeek,
- getLastMonth,
- getLast3Month,
- getLast6Month
- } from '@/utils/date.js'
- export default {
- components: {
- dataQuery
- },
- data() {
- return {
- // 查询参数
- queryParams: {
- id: null,
- startTime: null,
- endTime: null,
- valueType: 0,
- },
- // 日期选择
- range: [],
- // 时间选择
- monthList: [{
- name: '近一周',
- current: 0
- },
- {
- name: '近1个月',
- current: 1
- },
- {
- name: '近3个月',
- current: 2
- },
- {
- name: '近6个月',
- current: 3
- }
- ],
- monthCurrent: 0,
- monthQuery: false,
- // 图表数据
- service: [],
- serviceTime: [],
- // 数据组数据
- datasList: [],
- dataValue: null,
- // 数据项数据
- dataItem: [],
- itemReadName: null,
- src: ''
- }
- },
- watch: {
- monthCurrent: {
- handler(val) {
- switch (val) {
- case 1:
- this.range = getLastMonth()
- break;
- case 2:
- this.range = getLast3Month()
- break;
- case 3:
- this.range = getLast6Month()
- break;
- default:
- this.range = getLastWeek()
- break;
- }
- this.handelDate(this.range)
- },
- immediate: true
- }
- },
- mounted() {
- this.getUserData()
- this.range = getLastWeek()
- },
- methods: {
- // 打开筛选
- openScreen() {
- this.monthQuery = !this.monthQuery
- },
- // 切换时间
- monthChange(current) {
- this.monthCurrent = current
- },
- //获取当前登录人所有数据组
- getUserData() {
- uni.$http.get('/itemGroup/getAllItemGroup', {
- readMode: 0
- }).then(res => {
- const data = res.data
- if (data.code === 200) {
- this.datasList = data.data.map(item => {
- return {
- text: item.groupName,
- value: item.id
- }
- })
- } else {
- }
- })
- },
- //通过id获取数据组
- getDataListById(id) {
- uni.$http.get('/itemGroup/getItemGroupById', {
- id: id,
- itemType: 1
- }).then(res => {
- const data = res.data
- if (data.code === 200) {
- this.dataItem = data.data.itemList.map(item => {
- return {
- text: item.itemReadName,
- value: item.id
- }
- })
- }
- })
- },
- //确认按钮查询
- handelQuery() {
- // 临时当前时间,需要改成选择时间----开始
- var date = new Date()
- var timestr = date.getHours() < 10 ? ('0' + date.getHours()) : date.getHours()
- timestr += ':'
- timestr += date.getMinutes() < 10 ? ('0' + date.getMinutes()) : date.getMinutes()
- timestr += ':'
- timestr += date.getSeconds() < 10 ? ('0' + date.getSeconds()) : date.getSeconds()
- // 临时当前时间,需要改成选择时间----结束
- uni.$http.get('/itemGroup/itemDataQuery', this.queryParams).then(res => {
- const data = res.data
- if (data.code === 200) {
- const {
- id,
- startTime,
- endTime,
- valueType
- } = this.queryParams
- this.src =
- `/static/webview/dataItem-wv.html?id=${id}&startTime=${startTime}&endTime=${endTime}&valueType=${valueType}&itemReadName=${this.itemReadName}`
- if (data.data) {
- const {
- valueList,
- valueTimeList
- } = data.data
- const service = [{
- // name: this.itemName,
- name: this.itemReadName,
- data: valueList
- }]
- this.service = service
- this.serviceTime = valueTimeList
- } else {
- this.service = []
- this.serviceTime = []
- }
- } else {
- uni.showToast({
- title: data.msg,
- duration: 2000,
- icon: "error"
- });
- }
- })
- this.monthQuery = false
- },
- //选择日期
- handelDate(date) {
- this.queryParams.startTime = this.resolvingDate(date[0])
- this.queryParams.endTime = this.resolvingDate(date[1])
- },
- resolvingDate(date) {
- if (!date) {
- return;
- }
- //date是传入的时间
- let d = new Date(date);
- let month = (d.getMonth() + 1) < 10 ? '0' + (d.getMonth() + 1) : (d.getMonth() + 1);
- let day = d.getDate() < 10 ? '0' + d.getDate() : d.getDate();
- let hours = d.getHours() < 10 ? '0' + d.getHours() : d.getHours();
- let min = d.getMinutes() < 10 ? '0' + d.getMinutes() : d.getMinutes();
- let sec = d.getSeconds() < 10 ? '0' + d.getSeconds() : d.getSeconds();
- let times;
- times = d.getFullYear() + '-' + month + '-' + day + ' ' + hours + ':' + min + ':' + sec;
- return times
- },
- //重置按钮
- reset() {
- this.queryParams = {
- id: null,
- startTime: null,
- endTime: null,
- valueType: 0
- }
- this.dataValue = null
- this.monthCurrent = 0
- this.monthQuery = false
- },
- //选择数据组
- dataValueChange(val) {
- this.getDataListById(val)
- },
- itemChange(val) {
- const item = this.dataItem.find(item => {
- return item.value === val
- })
- this.itemReadName = item.text
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- .data {
- margin-top: 40rpx;
- height: 50vh;
- .data-screen {
- text-align: right;
- .screen-img {
- width: 40rpx;
- height: 40rpx;
- }
- }
- }
- .echarts {
- position: relative;
- .query-screen {
- width: 96vw;
- padding: 0 20rpx;
- background: #ffffff;
- position: absolute;
- top: 0;
- z-index: 999;
- .month {
- display: flex;
- justify-content: space-between;
- align-items: center;
- font-size: 28rpx;
- margin: 40rpx 0;
- .month-item {
- padding: 10rpx 20rpx;
- background: #ECECEC;
- color: #000000;
- border-radius: 12rpx;
- }
- .month-select {
- padding: 10rpx 20rpx;
- border-radius: 12rpx;
- background: #289BFF;
- color: #ffffff;
- }
- }
- .month-btn {
- display: flex;
- justify-content: space-around;
- margin-top: 40rpx;
- margin-bottom: 40rpx;
- .reset {
- background: #EAF4FF;
- color: #469DED;
- border: 1px solid #A3B8CB;
- }
- }
- }
- }
- .modal {
- width: 100%;
- height: 76vh;
- background: rgba(0, 0, 0, 0.5);
- position: absolute;
- top: 0;
- }
- </style>
|