From 77b8624957ea9afafc81af72e52212c15b5f091e Mon Sep 17 00:00:00 2001
From: wlzboy <66905212@qq.com>
Date: 星期四, 25 十二月 2025 01:34:32 +0800
Subject: [PATCH] feat: 优化新建 保存同步
---
app/pages/index.vue | 220 +++++++++++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 205 insertions(+), 15 deletions(-)
diff --git a/app/pages/index.vue b/app/pages/index.vue
index 46ca76b..7b2aeb4 100644
--- a/app/pages/index.vue
+++ b/app/pages/index.vue
@@ -232,15 +232,36 @@
</view>
</view>
</scroll-view>
+
+ <!-- 鍙栨秷鍘熷洜閫夋嫨瀵硅瘽妗� -->
+ <uni-popup ref="cancelPopup" type="center" :is-mask-click="false">
+ <view class="cancel-dialog">
+ <view class="dialog-title">璇烽�夋嫨鍙栨秷鍘熷洜</view>
+ <picker mode="selector" :range="cancelReasonList" range-key="label" @change="selectCancelReason">
+ <view class="reason-picker">
+ <view class="picker-label">鍙栨秷鍘熷洜</view>
+ <view class="picker-value">
+ {{ selectedCancelReasonLabel }}
+ </view>
+ <uni-icons type="arrowright" size="16"></uni-icons>
+ </view>
+ </picker>
+ <view class="dialog-buttons">
+ <button class="cancel-btn" @click="closeCancelDialog">鍙栨秷</button>
+ <button class="confirm-btn" @click="confirmCancelTask">纭畾</button>
+ </view>
+ </view>
+ </uni-popup>
</view>
</template>
<script>
import { mapState } from "vuex";
-import { getMyTasks, changeTaskStatus } from "@/api/task";
+import { getMyTasks, changeTaskStatus, checkTaskConsentAttachment } from "@/api/task";
import { getUserProfile } from "@/api/system/user";
import { getUserBoundVehicle } from "@/api/vehicle";
import { getUnreadCount } from "@/api/message";
+import { getDicts } from "@/api/dict";
import { formatDateTime } from "@/utils/common";
import subscribeManager from "@/utils/subscribe";
import { checkTaskCanDepart } from "@/utils/taskValidator";
@@ -268,6 +289,12 @@
currentPage: 1,
pageSize: 10,
hasMore: true,
+
+ // 鍙栨秷鍘熷洜鐩稿叧
+ cancelReasonList: [], // 鍙栨秷鍘熷洜鍒楄〃
+ showCancelDialog: false, // 鏄剧ず鍙栨秷鍘熷洜瀵硅瘽妗�
+ selectedCancelReason: '', // 閫変腑鐨勫彇娑堝師鍥�
+ currentCancelTask: null // 褰撳墠瑕佸彇娑堢殑浠诲姟
};
},
computed: {
@@ -288,6 +315,15 @@
"IN_PROGRESS",
].includes(task.taskStatus);
});
+ },
+
+ // 鑾峰彇閫変腑鐨勫彇娑堝師鍥犳爣绛撅紙鐢ㄤ簬寮圭獥鏄剧ず锛�
+ selectedCancelReasonLabel() {
+ if (!this.selectedCancelReason || !this.cancelReasonList.length) {
+ return '璇烽�夋嫨'
+ }
+ const reason = this.cancelReasonList.find(r => r.value === this.selectedCancelReason)
+ return reason ? reason.label : '璇烽�夋嫨'
},
},
onLoad() {
@@ -310,6 +346,8 @@
this.loadRunningTasks();
// 鍔犺浇鏈娑堟伅鏁伴噺
this.loadUnreadMessageCount();
+ // 鍔犺浇鍙栨秷鍘熷洜瀛楀吀
+ this.loadCancelReasonDict();
},
onShow() {
// 妫�鏌ョ敤鎴锋槸鍚﹀凡鐧诲綍
@@ -707,13 +745,9 @@
break;
case "cancel":
- // 鍙栨秷 -> 浜屾纭鍚庣姸鎬佸彉涓哄凡鍙栨秷
- this.$modal
- .confirm("纭畾瑕佸彇娑堟浠诲姟鍚楋紵")
- .then(() => {
- this.updateTaskStatus(task.taskId, "CANCELLED", "浠诲姟宸插彇娑�");
- })
- .catch(() => {});
+ // 鍙栨秷 -> 鏄剧ず鍙栨秷鍘熷洜閫夋嫨瀵硅瘽妗�
+ this.currentCancelTask = task;
+ this.showCancelReasonDialog();
break;
case "arrive":
@@ -748,12 +782,8 @@
case "complete":
// 宸插畬鎴� -> 鐘舵�佸彉涓哄凡瀹屾垚
- this.$modal
- .confirm("纭浠诲姟宸插畬鎴愶紵")
- .then(() => {
- this.updateTaskStatus(task.taskId, "COMPLETED", "浠诲姟宸插畬鎴�");
- })
- .catch(() => {});
+ // 闇�瑕佹鏌ユ槸鍚︿笂浼犱簡鐭ユ儏鍚屾剰涔�
+ this.checkConsentAttachmentAndThen(task.taskId, "COMPLETED", "浠诲姟宸插畬鎴�");
break;
}
},
@@ -763,9 +793,96 @@
// 鑾峰彇GPS浣嶇疆淇℃伅
this.getLocationAndUpdateStatus(taskId, status, remark);
},
+
+ // 鍔犺浇鍙栨秷鍘熷洜瀛楀吀
+ loadCancelReasonDict() {
+ getDicts('task_cancel_reason').then(response => {
+ if (response.code === 200 && response.data) {
+ this.cancelReasonList = response.data.map(item => ({
+ value: item.dictValue,
+ label: item.dictLabel
+ }))
+ }
+ }).catch(error => {
+ console.error('鍔犺浇鍙栨秷鍘熷洜瀛楀吀澶辫触:', error)
+ })
+ },
+
+ // 鏄剧ず鍙栨秷鍘熷洜瀵硅瘽妗�
+ showCancelReasonDialog() {
+ this.selectedCancelReason = ''
+ this.$refs.cancelPopup.open()
+ },
+
+ // 纭鍙栨秷浠诲姟
+ confirmCancelTask() {
+ if (!this.selectedCancelReason) {
+ this.$modal.showToast('璇烽�夋嫨鍙栨秷鍘熷洜')
+ return
+ }
+
+ this.$refs.cancelPopup.close()
+
+ // 璋冪敤鏇存柊鐘舵�佹柟娉曪紝浼犻�掑彇娑堝師鍥�
+ this.updateTaskStatusWithCancelReason(this.currentCancelTask.taskId, 'CANCELLED', '浠诲姟宸插彇娑�', this.selectedCancelReason)
+ },
+
+ // 鍙栨秷瀵硅瘽妗嗗叧闂�
+ closeCancelDialog() {
+ this.$refs.cancelPopup.close()
+ this.selectedCancelReason = ''
+ this.currentCancelTask = null
+ },
+
+ // 閫夋嫨鍙栨秷鍘熷洜
+ selectCancelReason(e) {
+ this.selectedCancelReason = this.cancelReasonList[e.detail.value].value
+ },
+
+ // 甯﹀彇娑堝師鍥犵殑鐘舵�佹洿鏂�
+ updateTaskStatusWithCancelReason(taskId, status, remark, cancelReason) {
+ this.getLocationAndUpdateStatus(taskId, status, remark, cancelReason)
+ },
+
+ // 妫�鏌ョ煡鎯呭悓鎰忎功闄勪欢骞舵洿鏂扮姸鎬�
+ async checkConsentAttachmentAndThen(taskId, status, remark) {
+ try {
+ uni.showLoading({
+ title: '妫�鏌ラ檮浠�...'
+ });
+
+ const response = await checkTaskConsentAttachment(taskId);
+
+ uni.hideLoading();
+
+ if (response.code === 200) {
+ // 宸蹭笂浼犵煡鎯呭悓鎰忎功锛岀户缁洿鏂扮姸鎬�
+ this.$modal
+ .confirm("纭浠诲姟宸插畬鎴愶紵")
+ .then(() => {
+ this.updateTaskStatus(taskId, status, remark);
+ })
+ .catch(() => {});
+ } else {
+ // 鏈笂浼犵煡鎯呭悓鎰忎功锛屾樉绀烘彁绀�
+ this.$modal.confirm('浠诲姟鏈笂浼犵煡鎯呭悓鎰忎功锛屾棤娉曞畬鎴愪换鍔°�傛槸鍚︾幇鍦ㄥ幓涓婁紶锛�').then(() => {
+ // 璺宠浆鍒颁换鍔¤鎯呴〉涓婁紶闄勪欢
+ this.$tab.navigateTo(`/pagesTask/detail?id=${taskId}`);
+ }).catch(() => {});
+ }
+ } catch (error) {
+ uni.hideLoading();
+ console.error('妫�鏌ラ檮浠跺け璐�:', error);
+
+ // 濡傛灉妫�鏌ュけ璐ワ紝璇㈤棶鐢ㄦ埛鏄惁缁х画
+ this.$modal.confirm('妫�鏌ラ檮浠剁姸鎬佸け璐ワ紝鏄惁缁х画瀹屾垚浠诲姟锛�').then(() => {
+ this.updateTaskStatus(taskId, status, remark);
+ }).catch(() => {});
+ }
+ },
// 鑾峰彇浣嶇疆淇℃伅骞舵洿鏂扮姸鎬�
- getLocationAndUpdateStatus(taskId, status, remark) {
+ getLocationAndUpdateStatus(taskId, status, remark, cancelReason) {
const that = this;
// 浣跨敤uni.getLocation鑾峰彇GPS浣嶇疆
@@ -792,6 +909,11 @@
speed: res.speed,
heading: res.direction || res.heading,
};
+
+ // 濡傛灉鏈夊彇娑堝師鍥狅紝娣诲姞鍒拌姹傛暟鎹腑
+ if (cancelReason) {
+ statusData.cancelReason = cancelReason
+ }
changeTaskStatus(taskId, statusData)
.then((response) => {
@@ -813,6 +935,11 @@
taskStatus: status,
remark: remark,
};
+
+ // 濡傛灉鏈夊彇娑堝師鍥狅紝娣诲姞鍒拌姹傛暟鎹腑
+ if (cancelReason) {
+ statusData.cancelReason = cancelReason
+ }
changeTaskStatus(taskId, statusData)
.then((response) => {
@@ -1350,4 +1477,67 @@
}
}
}
+
+// 鍙栨秷鍘熷洜瀵硅瘽妗嗘牱寮�
+.cancel-dialog {
+ width: 600rpx;
+ background-color: white;
+ border-radius: 20rpx;
+ padding: 40rpx;
+
+ .dialog-title {
+ font-size: 32rpx;
+ font-weight: bold;
+ text-align: center;
+ margin-bottom: 30rpx;
+ color: #333;
+ }
+
+ .reason-picker {
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ padding: 20rpx 30rpx;
+ background-color: #f5f5f5;
+ border-radius: 10rpx;
+ margin-bottom: 30rpx;
+
+ .picker-label {
+ font-size: 28rpx;
+ color: #666;
+ }
+
+ .picker-value {
+ flex: 1;
+ text-align: right;
+ margin: 0 20rpx;
+ font-size: 28rpx;
+ color: #333;
+ }
+ }
+
+ .dialog-buttons {
+ display: flex;
+ gap: 20rpx;
+
+ button {
+ flex: 1;
+ height: 80rpx;
+ line-height: 80rpx;
+ border-radius: 10rpx;
+ font-size: 28rpx;
+ border: none;
+ }
+
+ .cancel-btn {
+ background-color: #f5f5f5;
+ color: #666;
+ }
+
+ .confirm-btn {
+ background-color: #007AFF;
+ color: white;
+ }
+ }
+}
</style>
\ No newline at end of file
--
Gitblit v1.9.1