index.vue
13 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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
<template>
<view class="page-container">
<!-- 顶部固定区域 -->
<up-sticky>
<view class="header-wrap">
<!-- 第一行:u-tabs 待办/已办切换 :scrollable="false"-->
<up-tabs
v-model="activeTab"
:list="tabList"
active-color="#1989fa"
inactive-color="#666"
font-size="30rpx"
@click="handleTabChange"
/>
<!-- 第二行:下拉框 + 搜索框 -->
<view class="search-header">
<!-- 左侧下拉框 -->
<view class="select-wrap common-text-color">
<up-select
v-model:current="selectedSortValue"
:options="sortOptions"
:showOptionsLabel="true"
@select="handleSortChange"
border="surround"
:style="{ flex: 1 }"
/>
</view>
<!-- 右侧搜索框 -->
<view class="search-input-wrap">
<up-search
v-model="searchValue"
placeholder="请输入关键字"
@search="handleSearch"
bg-color="#f5f5f5"
:clearabled="false"
:show-action="true"
actionText="搜索"
:animation="true"
@custom="handleSearch"
/>
</view>
</view>
</view>
</up-sticky>
<!-- 列表容器 -->
<z-paging
ref="paging"
v-model="orderList"
@query="queryList"
:auto-show-system-loading="true"
>
<template #empty>
<empty-view />
</template>
<view class="common-card-list" style="padding-top: 200rpx;padding-bottom: 30rpx">
<!-- 待办工单卡片 -->
<up-card
v-if="activeTab == 1"
:border="false"
:foot-border-top="false"
v-for="(item, index) in orderList"
:key="`todo_${item.orderNo}_${index}`"
:show-head="false"
class="order-card"
>
<template #body>
<view class="card-body">
<view class="u-body-item u-flex">
<view class="u-body-item-title">工单编号:</view>
<view class="u-line-1 u-body-value">{{ item.orderNo || '-' }}</view>
</view>
<view class="u-body-item u-flex">
<view class="u-body-item-title">工单位置:</view>
<view class="u-line-1 u-body-value">{{ item.roadName || '-' }}</view>
</view>
<view class="u-body-item u-flex">
<view class="u-body-item-title">工单名称:</view>
<view class="u-line-1 u-body-value">{{ item.orderName || '未填写' }}</view>
</view>
<view class="u-body-item u-flex">
<view class="u-body-item-title">情况描述:</view>
<view class="u-line-1 u-body-value">{{ item.remark || '无' }}</view>
</view>
<view class="u-body-item u-flex common-item-center common-justify-between">
<view class="u-body-item-title">紧急程度:</view>
<view class="u-line-1 u-body-value">
{{uni.$dict.getDictLabel('workorder_pressing_type',item.pressingType)}}
</view>
</view>
<view class="u-body-item u-flex">
<view class="u-body-item-title">提交时间:</view>
<view class="u-line-1 u-body-value">{{ timeFormat(item.createTime, 'yyyy-mm-dd hh:MM:ss') }}</view>
</view>
<!-- 操作按钮行 -->
<view class="u-body-item u-flex common-justify-between common-item-center mt-20">
<up-button type="warning" size="mini" @click="handleReject(item)">回退</up-button>
<up-button type="primary" size="mini" @click="handleProcess(item)">处理</up-button>
<up-button type="info" size="mini" @click="handleDetail(item)">详情</up-button>
</view>
</view>
</template>
</up-card>
<!-- 已办工单卡片和我发起的 -->
<up-card
v-if="activeTab == 2||activeTab == 0"
:border="false"
:foot-border-top="false"
v-for="(item, index) in orderList"
:key="`done_${item.orderNo}_${index}`"
:show-head="false"
class="order-card"
>
<template #body>
<view class="card-body">
<view class="u-body-item u-flex">
<view class="u-body-item-title">工单编号:</view>
<view class="u-line-1 u-body-value">{{ item.orderNo || '-' }}</view>
</view>
<view class="u-body-item u-flex">
<view class="u-body-item-title">工单位置:</view>
<view class="u-line-1 u-body-value">{{ item.roadName || '-' }}</view>
</view>
<view class="u-body-item u-flex">
<view class="u-body-item-title">工单名称:</view>
<view class="u-line-1 u-body-value">{{ item.orderName || '未填写' }}</view>
</view>
<view class="u-body-item u-flex">
<view class="u-body-item-title">情况描述:</view>
<view class="u-line-1 u-body-value">{{ item.remark || '无' }}</view>
</view>
<view class="u-body-item u-flex common-justify-between common-item-center">
<view class="u-body-item-title">紧急程度: {{uni.$dict.getDictLabel('workorder_pressing_type',item.pressingType)}}</view>
<view class=" ">
<up-button type="primary" size="mini" @click="handleDetail(item)">工单详情</up-button>
</view>
</view>
<view class="u-body-item u-flex">
<view class="u-body-item-title">提交时间:</view>
<view class="u-line-1 u-body-value">{{ timeFormat(item.createTime, 'yyyy-mm-dd hh:MM:ss') }}</view>
</view>
</view>
</template>
</up-card>
</view>
</z-paging>
<!-- 底部新增工单按钮(仅巡查员显示) -->
<view v-if="isInspector" class="fixed-bottom-btn-wrap">
<up-button type="primary" size="large" @click="handleAddOrder">
新增工单
</up-button>
</view>
<!-- 回退原因弹窗 -->
<up-popup v-model="rejectPopupShow" mode="center" :close-on-click-overlay="false">
<view class="reject-popup">
<view class="popup-title">回退原因</view>
<up-textarea
v-model="rejectReason"
placeholder="请输入回退原因(必填)"
:required="true"
maxlength="-1"
rows="4"
class="mt-20"
/>
<view class="upload-wrap mt-20">
<view class="upload-title">上传图片(选填)</view>
<up-upload
:action="uploadUrl"
:file-list="rejectFileList"
@after-read="handleAfterRead"
@delete="handleDeleteFile"
multiple
max-count="3"
/>
</view>
<view class="popup-btn-wrap mt-40">
<up-button type="default" size="medium" @click="rejectPopupShow = false" class="mr-20">取消</up-button>
<up-button type="primary" size="medium" @click="confirmReject">确认提交</up-button>
</view>
</view>
</up-popup>
</view>
</template>
<script setup>
import { ref, computed } from 'vue';
import { onReady, onShow } from '@dcloudio/uni-app';
import { timeFormat } from '@/uni_modules/uview-plus';
import { myBuzSimplePage, todoBuzSimplePage, doneBuzSimplePage } from '@/api/work-order-manage/work-order-manage'
// 假设从用户store获取角色信息
import { useUserStore } from '@/pinia/user';
import { getDictLabel } from "../../../common/utils/dict";
import EmptyView from "../../../components/empty-view/empty-view.vue";
// ========== 状态管理 ==========
const userStore = useUserStore();
// 标签页切换
const activeTab = ref(0); // 0-我发起的 1-待办 2-已办
const tabList = ref([
{ name: '我发起的任务' },
{ name: '待办' },
{ name: '已办' }
]);
// 排序下拉框
const selectedSortValue = ref(1);
const sortOptions = ref([
{ name: '位置', id: 1 },
{ name: '名称', id: 2 },
{ name: '描述', id: 3 },
{ name: '编号', id: 4 },
]);
// 搜索
const searchValue = ref('');
// 分页
const paging = ref(null);
const orderList = ref([]);
// 角色控制(巡查员显示新增按钮)
const isInspector = computed(() => {
// 假设用户角色字段为role,巡查员标识为inspector
return userStore.userInfo.roles.includes('yl_inspector')
});
// 回退弹窗相关
const rejectPopupShow = ref(false);
const rejectReason = ref('');
const rejectFileList = ref([]);
const currentRejectItem = ref(null);
// 上传地址(根据实际接口配置)
const uploadUrl = ref('https://xxx.com/upload');
// 分页查询列表
const queryList = async (pageNo, pageSize) => {
try {
const apiParams = {
searchContent: searchValue.value.trim() || '',
pageNo,
pageSize,
type: selectedSortValue.value // 1-位置 2-工单名称 3-情况描述 4-工单编号
};
let res;
if (activeTab.value == 0) {
// 我发起的任务
res = await myBuzSimplePage(apiParams);
} else if(activeTab.value == 1) {
// 待办工单
res = await todoBuzSimplePage(apiParams);
}else {
// 已办工单
res = await doneBuzSimplePage(apiParams);
}
// 适配z-paging分页
paging.value.complete(res.list, res.total);
} catch (error) {
console.error('加载工单失败:', error);
paging.value?.complete(false);
uni.showToast({ title: '加载失败,请重试', icon: 'none' });
}
};
// ========== 事件处理 ==========
// 标签页切换
const handleTabChange = (item) => {
console.log(item)
activeTab.value = item.index;
paging.value?.reload(); // 切换标签页刷新列表
};
// 排序变更
const handleSortChange = (val) => {
selectedSortValue.value = val.id;
searchValue.value = '';
paging.value?.reload(); // 排序变更刷新列表
};
// 搜索
const handleSearch = (val) => {
searchValue.value = val;
paging.value?.reload(); // 搜索刷新列表
};
// 工单详情
const handleDetail = (item) => {
// 0-我发起的 1-待办 2-已办
uni.navigateTo({
url: `/pages-sub/problem/work-order-manage/order-detail?taskId=${item.taskId}&activeTab=${activeTab.value}`
});
};
// 待办-处理工单
const handleProcess = async (item) => {
try {
// 调用处理工单接口,获取跳转标识
const res = await uni.request({
url: '/api/order/process',
method: 'POST',
data: { orderId: item.id }
});
const { jumpType, jumpUrl } = res.data;
// 根据返回标识跳转不同页面
if (jumpType === 1) {
uni.navigateTo({ url: jumpUrl });
} else if (jumpType === 2) {
uni.redirectTo({ url: jumpUrl });
} else if (jumpType === 3) {
uni.switchTab({ url: jumpUrl });
}
} catch (error) {
console.error('处理工单失败:', error);
uni.showToast({ title: '处理失败,请重试', icon: 'none' });
}
};
// 待办-回退工单
const handleReject = (item) => {
currentRejectItem.value = item;
rejectReason.value = '';
rejectFileList.value = [];
rejectPopupShow.value = true;
};
// 确认回退工单
const confirmReject = async () => {
if (!rejectReason.value.trim()) {
uni.showToast({ title: '请填写回退原因', icon: 'none' });
return;
}
try {
// 调用回退工单接口
await uni.request({
url: '/api/order/reject',
method: 'POST',
data: {
orderId: currentRejectItem.value.id,
reason: rejectReason.value,
fileUrls: rejectFileList.value.map(file => file.url)
}
});
uni.showToast({ title: '回退成功', icon: 'success' });
rejectPopupShow.value = false;
paging.value?.reload(); // 刷新列表
} catch (error) {
console.error('回退工单失败:', error);
uni.showToast({ title: '回退失败,请重试', icon: 'none' });
}
};
// 新增工单
const handleAddOrder = () => {
uni.navigateTo({
url: '/pages-sub/problem/work-order-manage/add-order'
});
};
// 上传图片-读取后
const handleAfterRead = (file) => {
rejectFileList.value.push(file);
};
// 上传图片-删除
const handleDeleteFile = (index) => {
rejectFileList.value.splice(index, 1);
};
// 页面初始化
onShow(() => {
// 初始化加载列表
paging.value?.reload();
});
</script>
<style scoped lang="scss">
.page-container {
min-height: 100vh;
}
// 顶部固定区域
.header-wrap {
background-color: #fff;
//box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);
}
// 搜索栏样式
.search-header {
display: flex;
align-items: center;
padding: 20rpx;
box-sizing: border-box;
.select-wrap {
width: 120rpx;
margin-right: 20rpx;
:deep(.u-select) {
width: 100%;
font-size: 28rpx;
}
:deep(.u-input__placeholder) {
font-size: 28rpx;
}
}
.search-input-wrap {
flex: 1;
}
}
</style>