正在服务中的记录,可以上传音频文件
This commit is contained in:
@@ -55,6 +55,9 @@
|
|||||||
<view class="service-action-btn service-action-btn--supplement" @click.stop="showSupplementDialog(item)">
|
<view class="service-action-btn service-action-btn--supplement" @click.stop="showSupplementDialog(item)">
|
||||||
<text>补录</text>
|
<text>补录</text>
|
||||||
</view>
|
</view>
|
||||||
|
<view class="service-action-btn service-action-btn--upload" @click.stop="chooseAndUploadFile(item)">
|
||||||
|
<text>{{ isUploading(item.id) ? '上传中' : '上传' }}</text>
|
||||||
|
</view>
|
||||||
<view class="service-action-btn service-action-btn--finish" @click.stop="finishService(item)">
|
<view class="service-action-btn service-action-btn--finish" @click.stop="finishService(item)">
|
||||||
<text>结束</text>
|
<text>结束</text>
|
||||||
</view>
|
</view>
|
||||||
@@ -203,6 +206,7 @@ export default {
|
|||||||
// 补录相关
|
// 补录相关
|
||||||
showSupplementModal: false,
|
showSupplementModal: false,
|
||||||
currentSupplementItem: null,
|
currentSupplementItem: null,
|
||||||
|
uploadingIds: [],
|
||||||
supplementForm: {
|
supplementForm: {
|
||||||
customerName: "",
|
customerName: "",
|
||||||
contact: "",
|
contact: "",
|
||||||
@@ -459,6 +463,158 @@ export default {
|
|||||||
// 查看服务详情
|
// 查看服务详情
|
||||||
console.log('查看服务详情', item);
|
console.log('查看服务详情', item);
|
||||||
},
|
},
|
||||||
|
isUploading(recordId) {
|
||||||
|
if (!recordId) return false;
|
||||||
|
return this.uploadingIds.includes(String(recordId));
|
||||||
|
},
|
||||||
|
async chooseAndUploadFile(item) {
|
||||||
|
if (!item || !item.id) {
|
||||||
|
uni.showToast({
|
||||||
|
title: '无法获取服务记录ID',
|
||||||
|
icon: 'none'
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (this.isUploading(item.id)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const selectedFile = await this.selectUploadFile();
|
||||||
|
if (!selectedFile || !selectedFile.path) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await this.uploadFileForRecord(item, selectedFile);
|
||||||
|
},
|
||||||
|
selectUploadFile() {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
const normalizeSelected = (res) => {
|
||||||
|
const tempFiles = Array.isArray(res?.tempFiles) ? res.tempFiles : [];
|
||||||
|
if (!tempFiles.length) return null;
|
||||||
|
const file = tempFiles[0] || {};
|
||||||
|
const filePath = file.path || file.tempFilePath || file.url || '';
|
||||||
|
const fileName = file.name || filePath.split('/').pop() || `service_file_${Date.now()}`;
|
||||||
|
if (!filePath) return null;
|
||||||
|
return {
|
||||||
|
path: filePath,
|
||||||
|
name: fileName
|
||||||
|
};
|
||||||
|
};
|
||||||
|
const onSuccess = (res) => {
|
||||||
|
const selected = normalizeSelected(res);
|
||||||
|
if (!selected) {
|
||||||
|
uni.showToast({
|
||||||
|
title: '未选择有效文件',
|
||||||
|
icon: 'none'
|
||||||
|
});
|
||||||
|
resolve(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
resolve(selected);
|
||||||
|
};
|
||||||
|
const onFail = (err) => {
|
||||||
|
const errMsg = err?.errMsg || '';
|
||||||
|
if (errMsg.includes('cancel')) {
|
||||||
|
resolve(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
console.error('选择文件失败:', err);
|
||||||
|
uni.showToast({
|
||||||
|
title: '选择文件失败',
|
||||||
|
icon: 'none'
|
||||||
|
});
|
||||||
|
resolve(null);
|
||||||
|
};
|
||||||
|
if (typeof uni.chooseMessageFile === 'function') {
|
||||||
|
uni.chooseMessageFile({
|
||||||
|
count: 1,
|
||||||
|
type: 'file',
|
||||||
|
success: onSuccess,
|
||||||
|
fail: onFail
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (typeof uni.chooseFile === 'function') {
|
||||||
|
uni.chooseFile({
|
||||||
|
count: 1,
|
||||||
|
success: onSuccess,
|
||||||
|
fail: onFail
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
uni.chooseImage({
|
||||||
|
count: 1,
|
||||||
|
success: onSuccess,
|
||||||
|
fail: onFail
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
getAuthHeaders() {
|
||||||
|
let tenantId = '';
|
||||||
|
let token = '';
|
||||||
|
try {
|
||||||
|
tenantId = uni.getStorageSync('backend-tenant-id') || '';
|
||||||
|
token = uni.getStorageSync('backend-token') || '';
|
||||||
|
} catch (e) {
|
||||||
|
console.error('获取认证信息失败:', e);
|
||||||
|
}
|
||||||
|
const headers = {};
|
||||||
|
if (token) {
|
||||||
|
headers['Authorization'] = `Bearer ${token}`;
|
||||||
|
}
|
||||||
|
if (tenantId) {
|
||||||
|
headers['X-Tenant-Id'] = tenantId;
|
||||||
|
}
|
||||||
|
return headers;
|
||||||
|
},
|
||||||
|
async uploadFileForRecord(item, selectedFile) {
|
||||||
|
const recordId = String(item.id);
|
||||||
|
this.uploadingIds = [...this.uploadingIds, recordId];
|
||||||
|
try {
|
||||||
|
uni.showLoading({
|
||||||
|
title: '上传中...'
|
||||||
|
});
|
||||||
|
const uploadRes = await uni.uploadFile({
|
||||||
|
url: getApiUrl('/api/audioManagement/uploadBluetoothAudio'),
|
||||||
|
filePath: selectedFile.path,
|
||||||
|
name: 'file',
|
||||||
|
formData: {
|
||||||
|
id: item.id,
|
||||||
|
customerId: item.customerId || '',
|
||||||
|
customerName: item.customerName || '',
|
||||||
|
fileName: selectedFile.name || `service_file_${Date.now()}`
|
||||||
|
},
|
||||||
|
header: this.getAuthHeaders(),
|
||||||
|
timeout: 60000
|
||||||
|
});
|
||||||
|
let result = {};
|
||||||
|
try {
|
||||||
|
result = typeof uploadRes?.data === 'string' ? JSON.parse(uploadRes.data) : (uploadRes?.data || {});
|
||||||
|
} catch (e) {
|
||||||
|
result = uploadRes?.data || {};
|
||||||
|
}
|
||||||
|
if (uploadRes?.statusCode === 200 && result?.success !== false) {
|
||||||
|
uni.showToast({
|
||||||
|
title: '上传成功',
|
||||||
|
icon: 'success'
|
||||||
|
});
|
||||||
|
this.serviceStatusPage.current = 1;
|
||||||
|
this.fetchServiceStatusList({ force: true });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
uni.showToast({
|
||||||
|
title: result?.message || '上传失败',
|
||||||
|
icon: 'none'
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error('上传文件失败:', error);
|
||||||
|
uni.showToast({
|
||||||
|
title: error?.errMsg || error?.message || '上传失败',
|
||||||
|
icon: 'none'
|
||||||
|
});
|
||||||
|
} finally {
|
||||||
|
uni.hideLoading();
|
||||||
|
this.uploadingIds = this.uploadingIds.filter(id => id !== recordId);
|
||||||
|
}
|
||||||
|
},
|
||||||
async finishService(item) {
|
async finishService(item) {
|
||||||
if (!item || !item.id) {
|
if (!item || !item.id) {
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
@@ -1045,6 +1201,15 @@ export default {
|
|||||||
opacity: 0.7;
|
opacity: 0.7;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.service-action-btn--upload {
|
||||||
|
color: #7C3AED;
|
||||||
|
background-color: transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
.service-action-btn--upload:active {
|
||||||
|
opacity: 0.7;
|
||||||
|
}
|
||||||
|
|
||||||
.service-status-empty {
|
.service-status-empty {
|
||||||
padding: 48rpx 0;
|
padding: 48rpx 0;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
|
|||||||
Reference in New Issue
Block a user