AlarmHandlePop.vue
5.4 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
<template>
<uv-popup ref="alarmHandlePop" round="24rpx">
<view class="pop_header">
<view style="width: 22px; visibility: hidden"></view>
<text class="pop_header_text">{{ statusText }}</text>
<uv-icon name="close" size="22" class="pop_header_icon" @tap="handleCloseI18nPop"></uv-icon>
</view>
<view class="upload-block">
<view class="upload-title">
<view class="u-t-title">{{ t('format.picture') }}</view>
<text>{{ fileList.length }}/1</text>
</view>
<uv-upload :fileList="fileList" :maxSize="10485760" :maxCount="1" @afterRead="handleUploadImg"
@delete="handleDeleteImg" @oversize="handleOverSize"></uv-upload>
<view class="note-title">
<!-- 确定不需要必填 -->
<!-- <text>*</text> -->
<view class="u-t-title">
{{ t('maintenance.common.remark') }}
</view>
</view>
<uv-textarea maxlength="300" count v-model="comment" :placeholder="t('maintenance.common.input')"></uv-textarea>
</view>
<view class="uni-date-changed uni-date-btn--ok">
<view class="uni-datetime-picker--btn" @tap="handleConfirmAlarm">
<text class="confirm-btn">{{ t("message.confirm") }}</text>
</view>
</view>
</uv-popup>
</template>
<script setup>
import {
ref,
computed,
onMounted
} from "vue";
import {
t
} from "@/plugins/index.js";
import {
setTaskStatusApi
} from "@/api/message.js";
import host from "../utils/ip-config.js";
import {
timeFormat
} from '@/uni_modules/uv-ui-tools/libs/function/index.js';
const emit = defineEmits(["success"]);
/******** 文件处理相关 **********/
const fileList = ref([]);
const handleUploadImg = async (event) => {
const result = await uploadFilePromise(event.file.url);
fileList.value = [{
status: "success",
uploadUrl: result,
url: `${host.assetsIp}/${result}`,
}, ];
};
const handleOverSize = () => {
uni.showToast({
icon: "none",
title: t("message.imgSize") + "10M",
});
};
const handleDeleteImg = () => {
fileList.value = [];
};
const uploadFilePromise = (url) => {
return new Promise((resolve, reject) => {
uni.showLoading({
title: t('button.uploaing')
})
uni.uploadFile({
url: `${host.ip}/report/common/upload`,
filePath: url,
name: "file",
formData: {
pathType: "task",
},
header: {
Authorization: uni.getStorageSync('Authorization') || '',
},
success: (res) => {
console.log(res);
const data = JSON.parse(res.data);
if (data.code === 200) {
resolve(data.msg);
}
},
complete: () => {
uni.hideLoading()
}
});
});
};
/******** 数据提交相关 **********/
const comment = ref("");
const handleConfirmAlarm = async () => {
try {
uni.showLoading({
title: t('button.uploaing')
})
comment.value = comment.value.trim();
// if (!comment.value) {
// uni.showToast({
// icon: 'none',
// title: t('pholder.enterNote')
// })
// return false
// }
const time = timeFormat(new Date().getTime(), 'yyyy-mm-dd hh:MM:ss');
const params = {
taskId: taskId.value,
comment: comment.value,
status: status.value,
id: idValue.value,
counttime: time, //当前设备的时间
};
console.log(params, 'params');
if (fileList.value.length > 0) {
params.photo = fileList.value[0].uploadUrl;
}
const res = await setTaskStatusApi(params);
if (res.code === 200) {
alarmHandlePop.value?.close();
emit("success", params);
}
} catch (err) {
console.log(err);
} finally {
uni.hideLoading()
}
};
/******** 弹窗数据相关 **********/
const alarmHandlePop = ref(null);
const taskId = ref("");
const status = ref("");
const idValue = ref();
const statusText = computed(() => {
return status.value === "RESOLVE" ? t('button.confirm') : t('TaskNotice.falseAlarm');
});
const handleOpen = (id, type, idValueParam) => {
taskId.value = id;
status.value = type;
idValue.value = idValueParam;
alarmHandlePop.value?.open("bottom");
};
const handleClose = () => {
alarmHandlePop.value?.close();
};
const handleCloseI18nPop = () => {
alarmHandlePop.value?.close();
};
defineExpose({
handleOpen,
});
</script>
<style lang="scss" scoped>
.upload-block {
width: 100%;
padding: 32rpx;
.u-t-title {
font-size: 28rpx;
font-family: Inter, Inter;
font-weight: 500;
color: #000000;
}
.upload-title {
display: flex;
justify-content: space-between;
align-items: center;
font-size: 28rpx;
margin-bottom: 20rpx;
text {
color: #90949d;
}
}
.note-title {
display: flex;
align-items: center;
margin: 8rpx 0 24rpx 0;
display: flex;
gap: 2rpx;
text {
color: #ff3838;
font-size: 24rpx;
}
}
}
// uv-upload__success 改这个样式 不要显示
:deep(.uv-upload__success) {
display: none;
}
:deep(.uv-upload__deletable) {
width: 18px;
height: 18px;
.uv-upload__deletable__icon {
transform: scale(1.2);
top: 4rpx;
right: 4rpx;
}
}
</style>