command-record.vue
6.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
<template>
<view class="command-record">
<!-- 命令记录筛选-->
<view class="filter-button" @click="openSearchDialog">
<text>筛选</text>
<image src="/static/shaixuan.png" />
</view>
<!-- 命令记录分页 -->
<mescroll-uni ref="mescrollRef" @init="mescrollInit" :down="downOption" @down="downCallback" @up="upCallback"
height="700px">
<view @click="openCommandDetail(item)" class="list-item" v-for="(item, index) in list" :key="index">
<view class="item">
<view class="item-first">
<text>{{ item.deviceName }}</text>
<!-- 业务 单向是没有响应状态 -->
<view v-if="!item.request.oneway">
<view class="item-right item-success" v-if="item.response">响应成功</view>
<view class="item-right item-fail" v-else>响应失败</view>
</view>
</view>
<view>
命令类型:
<text class="ml-16">{{ item.additionalInfo.cmdType===1?'服务':'自定义' }}</text>
</view>
<view v-if="item.statusName">
命令状态:
<text :style="{color:formatCommandStatus(item.status)}" class="ml-16">
{{ item.statusName }}
</text>
</view>
<view class="item-first">
<view>
响应类型:
<text class="ml-16">{{ !item.request.oneway?'双向':'单向' }}</text>
</view>
<view class="time">{{ format(item.createTime) }}</view>
</view>
</view>
</view>
</mescroll-uni>
<!-- 命令记录弹窗筛选 -->
<u-popup @close="close" closeable bgColor="#fff" :show="show" mode="bottom" :round="20">
<view class="filter" @touchmove.stop.prevent="disabledScroll">
<view class="filter-title"><text>筛选条件</text></view>
<query-item :filterList="issueStatus" title="下发状态"
@clickTag="currentIndex => handleClickTag(currentIndex, issueStatus)"></query-item>
<view class="flex-column">
<view class="mt-3 command-time-text">命令下发时间</view>
<view class="mt-3">
<uni-datetime-picker return-type="timestamp" v-model="range" type="datetimerange"
rangeSeparator="至" />
</view>
</view>
<view class="h-30"></view>
<view class="button-group">
<view>
<u-button :customStyle="{ color: '#333' }" color="#e3e3e5" shape="circle" text="重置"
@click="resetFilter"></u-button>
</view>
<view>
<u-button color="#3388ff" shape="circle" text="确认" @click="confirmFilter"></u-button>
</view>
</view>
</view>
</u-popup>
</view>
</template>
<script>
import queryItem from '@/pages/device/components/query-item.vue';
import MescrollMixin from '@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js';
import {
formatToDate
} from '@/plugins/utils.js';
import {
debounce
} from '@/plugins/throttle.js';
import {
issueStatus
} from '../config/data.js'
import api from '@/api/index.js'
import {
useNavigateTo
} from '@/plugins/utils.js'
export default {
mixins: [MescrollMixin],
components: {
queryItem
},
props: {
tbDeviceId: {
type: String,
default: ''
}
},
data() {
return {
show: false,
list: [],
total: 0,
range: [],
formTime: {
status: '',
startTime: '',
endTime: ''
},
status: '',
issueStatus,
downOption: {
auto: false //是否在初始化后,自动执行downCallback; 默认true
},
page: {
num: 0,
size: 10
}
};
},
methods: {
formatCommandStatus(status) {
return status == 'EXPIRED' ?
'red' :
status == 'DELIVERED' ?
'blue' :
status == 'QUEUED' ?
'#00C9A7' :
status == 'TIMEOUT' ?
'red' :
status == 'SENT' ?
'#00C9A7' : ''
},
downCallback() {
for (let i in this.formTime) Reflect.set(this.formTime, i, '')
this.list = [];
this.page.num = 1;
this.loadData(this.page.num, {
tbDeviceId: this.tbDeviceId
});
},
format(date) {
return formatToDate(date, 'YYYY-MM-DD HH:mm:ss');
},
disabledScroll() {
return;
},
upCallback() {
const tbDeviceId = {
tbDeviceId: this.tbDeviceId
}
const condition = Object.values(this.formTime)
if (condition.length === 0) {
this.page.num += 1;
this.loadData(this.page.num, {
...tbDeviceId
});
} else if (condition.filter(Boolean).length > 0) {
this.page.num += 1;
this.loadData(this.page.num, {
...this.formTime,
...tbDeviceId
});
} else {
this.page.num += 1;
this.loadData(this.page.num, {
...tbDeviceId
});
}
},
async loadData(pageNo, params = {}) {
let httpData = {
...params,
page: pageNo,
pageSize: 10
};
const res = await api.deviceApi.getRpcRecord({
params: httpData,
custom: {
load: false
}
})
if (!res) return
this.total = res.total;
uni.stopPullDownRefresh();
this.mescroll.endByPage(res.items.length, res.total);
if (pageNo == 1) {
this.list = res.items;
} else {
this.list = this.list.concat(res.items);
}
},
handleClickTag(currentIndex, list) {
list.map((item, index) => {
item.checked = index === currentIndex;
});
},
resetFilter() {
const {
issueStatus
} = this;
issueStatus.forEach(item => item.checked = false)
issueStatus[0].checked = true
},
close() {
this.show = false;
},
openSearchDialog() {
this.show = true;
this.resetFilter()
this.range = []
for (let i in this.formTime) Reflect.set(this.formTime, i, '')
},
hideKeyboard() {
uni.hideKeyboard();
},
confirmFilter() {
this.formTime.startTime = this.range[0]
this.formTime.endTime = this.range[1]
const issueStatus = this.issueStatus.find(item => item.checked);
this.formTime.status = issueStatus.type ? issueStatus.type : undefined,
this.loadData(1, {
tbDeviceId: this.tbDeviceId,
...this.formTime
});
this.show = false;
},
openCommandDetail(item) {
useNavigateTo('/device-subpackage/device-detail/components/command-detail?data=', item)
}
}
};
</script>
<style lang="scss" scoped>
@import "../static/command-record.scss";
</style>