吉安感知网项目-前端
chenyao
yesterday 4c390d209b45d516fbe2f7552d26048687c83972
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
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
<template>
  <view class="handle-page">
    <u-navbar title="待办处置" :is-back="true" back-text="" :back-icon-size="40" @left-click="onBackClick"></u-navbar>
 
    <scroll-view class="form-scroll" scroll-y>
      <view class="form-section status-section">
        <view class="section-header">
          <text class="section-title">工单状态</text>
        </view>
        <picker
          mode="selector"
          :range="statusOptions"
          range-key="name"
          :value="statusPickerIndex"
          @change="onStatusChange"
          class="status-picker"
        >
          <div class="picker-value">
            {{ currentStatusLabel || '请选择' }}
            <text class="picker-arrow">▼</text>
          </div>
        </picker>
      </view>
      <view class="form-section description-section">
        <view class="section-header">
          <text class="section-title">处置描述</text>
        </view>
        <view class="description-wrapper">
                    <textarea
            v-model="formData.disposeContent"
            class="description-input"
            maxlength="140"
            placeholder="请输入"
            placeholder-class="description-placeholder"
            :show-confirm-bar="false"
          />
          <text class="word-count">{{ descriptionLength }}/140</text>
        </view>
      </view>
 
      <!--            <view class="form-section status-section">-->
      <!--                <text class="section-title">处置中</text>-->
      <!--                <switch class="status-switch" :checked="formData.isHandling" color="#00b578" @change="handleStatusChange" />-->
      <!--            </view>-->
 
      <view class="form-section upload-section">
        <view class="section-header upload-header">
          <text class="section-title">附件上传</text>
        </view>
        <!--                <button class="select-file-btn" @click="handleChooseFile">选择文件</button>-->
        <u-button color="#1D6FE9" class="select-file-btn" :disabled="uploading" @click="handleChooseFile">
          {{ uploading ? '上传中...' : '选择文件' }}
        </u-button>
 
        <view v-if="attachmentList.length" class="attachment-list">
          <view v-for="(file, index) in attachmentList" :key="`${file.path}-${index}`" class="attachment-item">
            <view class="file-info">
              <text class="file-name">{{ file.name }}</text>
              <text v-if="file.size" class="file-size">{{ formatFileSize(file.size) }}</text>
            </view>
            <text class="remove-file-btn" @click.stop="handleRemoveFile(index)">×</text>
          </view>
        </view>
      </view>
    </scroll-view>
 
    <view class="action-footer">
      <u-button color="#AEAEAE" class="custom-style" @click="handleCancel">取消</u-button>
      <u-button color="#1D6FE9" class="custom-style" :disabled="submitting || uploading" @click="handleSubmit">
        {{ submitting ? '提交中...' : '确定' }}
      </u-button>
    </view>
  </view>
</template>
 
<script setup>
import { computed, ref } from 'vue'
import { onLoad } from '@dcloudio/uni-app'
import { backGdApi, addDisposeRecord, uploadFileAPI } from '@/api/work/index.js'
 
const MAX_FILE_COUNT = 9
const eventId = ref('')
const eventStatus = ref(null)
const initialEventStatus = ref(null) // 进入页面时的原始工单状态
const submitting = ref(false)
const uploading = ref(false)
const attachmentList = ref([])
const formData = ref({
  disposeContent: '',
  isHandling: true,
})
const navbarTitleStyle = {
  color: '#ffffff',
  fontSize: '34rpx',
  fontWeight: '500',
}
 
// 计算处置描述字数
const descriptionLength = computed(() => formData.value.disposeContent.length)
 
// 读取当前工单标识
onLoad(options => {
  eventId.value = options?.id ?? ''
})
 
// 返回上一页
function handleBack() {
  uni.navigateBack()
}
 
// 状态选项列表
const statusOptions = [
    { name: '处置中', value: 1 },
    { name: '已处置', value: 3 },
    // { name: '已完成', value: 4 },
]
 
// 当前选中状态的索引
const statusPickerIndex = computed(() => {
    const status = eventStatus.value
    return statusOptions.findIndex(item => item.value === status)
})
 
// 当前状态文本
const currentStatusLabel = computed(() => {
    const option = statusOptions.find(item => item.value === eventStatus.value)
    return option?.name || ''
})
 
// 切换状态
const onStatusChange = e => {
    const index = e.detail.value
    const selectedOption = statusOptions[index]
    if (!selectedOption) return
    eventStatus.value = selectedOption.value
}
 
 
// 切换处置状态
// function handleStatusChange(event) {
//     formData.value.isHandling = event.detail.value
// }
 
// 提取文件名称
function getFileName(filePath = '') {
  const normalizedPath = filePath.replace(/\\/g, '/')
  return decodeURIComponent(normalizedPath.split('/').pop() || '未命名文件')
}
 
// 上传单个已选择文件
async function uploadSelectedFile(file) {
  const response = await uploadFileAPI(file.path)
  const link = response?.data?.link || response?.data?.url || response?.link
  if (!link) throw new Error('上传接口未返回文件地址')
  return { ...file, link }
}
 
// 处理已选择文件
async function handleChooseSuccess(result) {
  const selectedFiles = result.tempFiles?.length
    ? result.tempFiles
    : (result.tempFilePaths ?? []).map(path => ({ path }))
  const availableCount = MAX_FILE_COUNT - attachmentList.value.length
  const normalizedFiles = selectedFiles
    .slice(0, availableCount)
    .map(file => {
      const path = file.path || file.tempFilePath || ''
      return {
        name: file.name || getFileName(path),
        path,
        size: Number(file.size) || 0,
      }
    })
    .filter(file => file.path)
  if (!normalizedFiles.length) return
 
  uploading.value = true
  uni.showLoading({ title: '上传中...', mask: true })
  let failedCount = 0
  try {
    const uploadResults = await Promise.all(
      normalizedFiles.map(async file => {
        try {
          return { success: true, file: await uploadSelectedFile(file) }
        } catch {
          return { success: false, file }
        }
      })
    )
    const uploadedFiles = uploadResults.filter(item => item.success).map(item => item.file)
    failedCount = uploadResults.length - uploadedFiles.length
    attachmentList.value.push(...uploadedFiles)
  } finally {
    uni.hideLoading()
    uploading.value = false
  }
  uni.showToast({
    title: failedCount ? `${failedCount}个文件上传失败` : '上传成功',
    icon: failedCount ? 'none' : 'success',
  })
}
 
// 处理选择文件失败
function handleChooseFail(error) {
  if (error?.errMsg?.includes('cancel')) return
  uni.showToast({ title: '取消选择文件', icon: 'none' })
}
 
// 选择附件
function handleChooseFile() {
  if (uploading.value) return
  const availableCount = MAX_FILE_COUNT - attachmentList.value.length
  if (availableCount <= 0) {
    uni.showToast({ title: `最多选择${MAX_FILE_COUNT}个附件`, icon: 'none' })
    return
  }
  const options = {
    count: availableCount,
    type: 'all',
    success: handleChooseSuccess,
    fail: handleChooseFail,
  }
 
  // #ifdef H5
  uni.chooseFile(options)
  // #endif
 
  // #ifdef MP-WEIXIN
  uni.chooseMessageFile(options)
  // #endif
 
  // #ifdef APP-PLUS
  uni.chooseImage({ ...options, sourceType: ['album', 'camera'] })
  // #endif
}
 
// 移除附件
function handleRemoveFile(index) {
  attachmentList.value.splice(index, 1)
}
 
// 格式化文件大小
function formatFileSize(size) {
  if (size < 1024) return `${size} B`
  if (size < 1024 * 1024) return `${(size / 1024).toFixed(1)} KB`
  return `${(size / 1024 / 1024).toFixed(1)} MB`
}
 
// 取消处置
function handleCancel() {
  uni.navigateBack()
}
 
// 提交处置信息
async function handleSubmit() {
  if (uploading.value) {
    uni.showToast({ title: '请等待附件上传完成', icon: 'none' })
    return
  }
  const disposeContent = formData.value.disposeContent.trim()
  if (!disposeContent) {
    uni.showToast({ title: '请输入处置描述', icon: 'none' })
    return
  }
  if (!eventId.value) {
    uni.showToast({ title: '工单信息缺失', icon: 'none' })
    return
  }
 
  submitting.value = true
  try {
    await addDisposeRecord({
      eventId: eventId.value,
      recordType: 1,
      disposeContent: formData.value.disposeContent,
      // targetEventStatus: eventStatus.value == 1 ? 3 : eventStatus.value,
      // updateEventStatus: Number(eventStatus.value) == 1 ? true : false,
      // 初始状态为处置中时固定传3;初始状态为已处置时传当前选中的值
      targetEventStatus: Number(initialEventStatus.value) === 1 ? 3 : eventStatus.value,
      // 已处置状态进入且未切换成处置中时,不更新工单状态
      updateEventStatus: !(Number(initialEventStatus.value) === 3 && Number(eventStatus.value) === 3),
      attachUrl: attachmentList.value.map(file => file.link),
      // operateTime: '2026-07-30 14:00:00',
      // eventStatus: formData.value.isHandling ? '1' : '3',
      // handleDesc,
      // attachmentList: attachmentList.value.map(file => ({
      //     attachName: file.name,
      //     filePath: file.path,
      // })),
    })
    uni.showToast({ title: '提交成功', icon: 'success' })
    setTimeout(() => {
      submitting.value = false
      uni.navigateBack()
      // uni.navigateTo({
      //     url: `/subPackages/workDetail/HandleWork/index?id=${eventId.value}`,
      // })
    }, 1200)
  } catch {
    submitting.value = false
    uni.showToast({ title: '提交失败,请重试', icon: 'none' })
  }
}
 
// 返回按钮点击事件
const onBackClick = () => {
  uni.navigateBack()
}
 
onLoad(options => {
  eventId.value = options?.id || ''
  eventStatus.value = Number(options?.eventStatus) || null
  initialEventStatus.value = eventStatus.value
})
</script>
 
<style scoped lang="scss">
.handle-page {
  // #ifdef APP-PLUS
  padding-top: 188rpx;
  // #endif
  // #ifdef H5
    padding-top: 88rpx;
    // #endif
  :deep() {
    .u-navbar__content {
      background: url('https://wrj.shuixiongit.com/aiskyminio/cloud-bucket/ztzf_app_assets/images/user/bg.png')
      no-repeat !important;
      background-size: 100% !important;
      height: 88rpx !important;
    }
  }
 
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  height: calc(100vh);
  //padding-top: 88rpx;
  //background: #111827;
  //color: #f5f7fa;
 
  //:deep(.u-navbar__content) {
  //    height: 88rpx !important;
  //    background: #151c29 !important;
  //}
}
 
.form-scroll {
    // #ifdef APP-PLUS
    padding-top: 60rpx;
    // #endif
  box-sizing: border-box;
  height: 0;
  flex: 1;
  padding: 0 24rpx 24rpx;
}
 
.form-section {
  box-sizing: border-box;
  margin-bottom: 20rpx;
  background: #ffffff;
  border: 1rpx solid rgba(255, 255, 255, 0.03);
}
 
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 82rpx;
  padding: 0 22rpx;
  border-bottom: 1rpx solid #eeeeee;
}
 
.section-title {
  font-size: 30rpx;
  font-weight: 400;
  color: #222324;
}
 
.description-wrapper {
  position: relative;
}
 
.word-count {
  position: absolute;
  right: 22rpx;
  bottom: 16rpx;
  font-size: 24rpx;
  color: #999;
}
 
.description-input {
  display: block;
  box-sizing: border-box;
  width: 100%;
  height: 350rpx;
  padding: 24rpx 22rpx;
  font-size: 30rpx;
  line-height: 1.6;
  color: #222324;
  background: transparent;
}
 
:deep(.description-placeholder) {
  color: #999;
}
 
.status-section {
  // #ifdef APP-PLUS
    padding-top: 70rpx;
    // #endif
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 86rpx;
  padding: 0 20rpx 0 0rpx;
}
 
.status-switch {
  transform: scale(0.84);
  transform-origin: right center;
}
 
.upload-section {
  padding-bottom: 22rpx;
}
 
.upload-header {
  margin-bottom: 0;
}
 
.select-file-btn {
  width: 210rpx;
  height: 70rpx;
  margin: 0;
  font-size: 28rpx;
  line-height: 70rpx;
  //color: #ffffff;
  //background: #409eff;
  //border-radius: 4rpx;
}
 
.select-file-btn::after,
.action-btn::after {
  border: 0;
}
 
.custom-style {
  width: 276rpx;
  height: 76rpx;
  font-family: 'Source Han Sans CN';
  font-weight: 400;
  font-size: 28rpx;
}
 
.attachment-list {
  padding: 10rpx 22rpx 0;
}
 
.attachment-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 70rpx;
  border-bottom: 1rpx solid #eeeeee;
}
 
.file-info {
  display: flex;
  align-items: center;
  width: 0;
  flex: 1;
}
 
.file-name {
  overflow: hidden;
  font-size: 26rpx;
  color: #222324;
  text-overflow: ellipsis;
  white-space: nowrap;
}
 
.file-size {
  margin-left: 14rpx;
  font-size: 22rpx;
  color: #999;
  white-space: nowrap;
}
 
.remove-file-btn {
  width: 56rpx;
  font-size: 42rpx;
  line-height: 56rpx;
  color: #999;
  text-align: right;
}
 
.action-footer {
  display: flex;
  align-items: center;
  gap: 28rpx;
  box-sizing: border-box;
  padding: 22rpx 28rpx calc(22rpx + env(safe-area-inset-bottom));
  //background: #111827;
}
 
.action-btn {
  height: 82rpx;
  margin: 0;
  flex: 1;
  font-size: 30rpx;
  line-height: 80rpx;
  color: #ffffff;
  border-radius: 6rpx;
}
 
.cancel-btn {
  color: #00b578;
  background: transparent;
  border: 2rpx solid #00b578;
}
 
.confirm-btn {
  background: #00b578;
  border: 2rpx solid #00b578;
}
 
.confirm-btn[disabled] {
  color: rgba(255, 255, 255, 0.72);
  background: #087b58;
}
</style>