mattersHandle.js
3.1 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
import api from '~/api/api'
import { getMatterDetailFields, normalizeMatterItem } from '~/utils/matterItem'
Page({
data: {
navBarHeight: 0,
task: null,
reply: '',
detailFields: [],
submitting: false,
isReadonly: false,
loading: true,
},
onLoad(options) {
const id = options?.id
if (!id) {
wx.showToast({ title: '缺少任务信息', icon: 'none' })
setTimeout(() => wx.navigateBack(), 1500)
return
}
this.taskId = id
this.loadDetail()
},
async loadDetail() {
this.setData({ loading: true })
wx.showLoading({ title: '加载中', mask: true })
try {
const res = await api.getTaskCenterDetail({ id: this.taskId })
if (res?.code !== '0' && res?.code !== 0) {
wx.showToast({
title: res?.message || '加载失败',
icon: 'none',
})
setTimeout(() => wx.navigateBack(), 1500)
return
}
const task = normalizeMatterItem(res.data || {}, 0)
this.setData({
task,
detailFields: getMatterDetailFields(task.taskType),
isReadonly: task.completed,
reply: task.replyText || '',
loading: false,
})
} catch (e) {
wx.showToast({ title: '加载失败', icon: 'none' })
setTimeout(() => wx.navigateBack(), 1500)
} finally {
wx.hideLoading()
this.setData({ loading: false })
}
},
navbarReady(e) {
this.setData({ navBarHeight: e.detail.height })
},
onBack() {
wx.navigateBack()
},
onReplyInput(e) {
this.setData({ reply: e.detail.value || '' })
},
async submit() {
const { reply, task, submitting } = this.data
if (submitting || !task) return
const content = (reply || '').trim()
if (!content) {
wx.showToast({ title: '请输入专项任务回复', icon: 'none' })
return
}
if (content.length > 800) {
wx.showToast({ title: '回复内容不能超过800字', icon: 'none' })
return
}
this.setData({ submitting: true })
wx.showLoading({ title: '提交中', mask: true })
try {
const res = await api.submitTaskCenter({
id: task.id,
replyContent: content,
})
if (res?.code === '0' || res?.code === 0) {
this.onSubmitSuccess()
} else {
wx.showToast({
title: res?.message || res?.msg || '提交失败',
icon: 'none',
})
}
} catch (e) {
wx.showToast({ title: '提交失败', icon: 'none' })
} finally {
wx.hideLoading()
this.setData({ submitting: false })
}
},
onSubmitSuccess() {
const { task } = this.data
wx.hideLoading()
this.setData({ submitting: false })
wx.showToast({ title: '提交成功', icon: 'success' })
this.notifyRefresh()
setTimeout(() => {
if (task?.taskType === 'staff-replace-access') {
wx.redirectTo({
url: '/pages/mattersSubmitResult/mattersSubmitResult',
})
return
}
wx.navigateBack()
}, 1000)
},
notifyRefresh() {
const eventChannel = this.getOpenerEventChannel()
eventChannel?.emit?.('refreshList')
},
})