Commit e08062679968dbb31acb830cabe9df45482e7e9d
1 parent
c96859fc
业务线 小程序不用写死,从后端接口获取
Showing
5 changed files
with
68 additions
and
46 deletions
api/maintain-manage/maintain-manage.js
| ... | ... | @@ -100,10 +100,10 @@ export const maintainPlanList= (params) => { |
| 100 | 100 | * 直接结束 |
| 101 | 101 | * @returns {Promise} |
| 102 | 102 | */ |
| 103 | -export const finishPlan= (params) => { | |
| 104 | - // 后端 /finish 使用 @RequestParam("planNo"),必须放 query,不能放 JSON body | |
| 105 | - const planNo = params && params.planNo != null ? params.planNo : ''; | |
| 106 | - return post(`/app-api/app/garden/maintain-plan-commit/finish?planNo=${encodeURIComponent(planNo)}`, {}); | |
| 103 | +export const finishPlan= (params = {}) => { | |
| 104 | + // 后端 /finish 已改为 @RequestParam("commitId"),planNo 不再接收,必须放 query 且传本次养护ID | |
| 105 | + const commitId = params && params.commitId != null ? params.commitId : ''; | |
| 106 | + return post(`/app-api/app/garden/maintain-plan-commit/finish?commitId=${encodeURIComponent(commitId)}`, {}); | |
| 107 | 107 | }; |
| 108 | 108 | |
| 109 | 109 | /** | ... | ... |
pages-sub/daily/maintain-manage/add-record.vue
| ... | ... | @@ -130,7 +130,7 @@ |
| 130 | 130 | </view> |
| 131 | 131 | <view class="fixed-bottom-btn-wrap" v-if="dynamicFields.length > 0"> |
| 132 | 132 | <view class="btn-item btn-left" @click="submitInspect"> |
| 133 | - <text>提交</text> | |
| 133 | + <text>暂存</text> | |
| 134 | 134 | </view> |
| 135 | 135 | <view class="btn-item btn-right" @click="submitAndFinish"> |
| 136 | 136 | <text>提交并结束本次任务</text> |
| ... | ... | @@ -942,28 +942,35 @@ export default { |
| 942 | 942 | commonUserList: [], |
| 943 | 943 | remark: this.inspectForm.remark.trim(), |
| 944 | 944 | } |
| 945 | + // 子上报随结束一起提交:后端在同一事务里写 garden_work_record 并校验「至少一条子上报」。 | |
| 946 | + // clientSeq 幂等,重复点击不会重复计次。 | |
| 947 | + const workRecords = dynamicValues.length > 0 | |
| 948 | + ? [{ | |
| 949 | + clientSeq: this.clientSeq, | |
| 950 | + remark: this.inspectForm.remark.trim(), | |
| 951 | + fields: dynamicValues | |
| 952 | + }] | |
| 953 | + : [] | |
| 945 | 954 | |
| 946 | - // 只调一次 /create-and-finish:后端会新增一条带完成时间的上报记录并更新完成次数, | |
| 947 | - // 若先调 maintainCreate 会多出一条重复记录 | |
| 955 | + // ① /create-and-finish 必传 commitId:没有进行中的本次养护就先建一条草稿(/create 会复用已有草稿) | |
| 948 | 956 | if (!this.commitId) { |
| 949 | - const commitRes: any = await maintainCreateFinish(submitData) | |
| 957 | + const commitRes: any = await maintainCreate(submitData) | |
| 950 | 958 | // 兼容后端返回裸 id 或 {id:...} 两种形态 |
| 951 | 959 | this.commitId = commitRes && typeof commitRes === 'object' ? commitRes.id : commitRes |
| 952 | 960 | } |
| 953 | - | |
| 954 | - // 动态字段挂到本次完成记录上;重试时 commitId 已缓存,只补写字段 | |
| 955 | - if (dynamicValues.length > 0 && this.commitId) { | |
| 956 | - await workRecordSubmit({ | |
| 957 | - businessType: this.paramsOptins.businessType, | |
| 958 | - bizType: 3, | |
| 959 | - bizId: this.commitId, | |
| 960 | - workTypeId: Number(this.paramsOptins.planTypeId), | |
| 961 | - clientSeq: this.clientSeq, | |
| 962 | - remark: this.inspectForm.remark.trim(), | |
| 963 | - fields: dynamicValues | |
| 964 | - }) | |
| 961 | + if (!this.commitId) { | |
| 962 | + uni.hideLoading() | |
| 963 | + uni.showToast({ title: '创建本次养护失败,请重试', icon: 'none' }) | |
| 964 | + return | |
| 965 | 965 | } |
| 966 | 966 | |
| 967 | + // ② 子上报 + 结束本次养护(同一事务,不会出现字段已存但任务未结束的中间态) | |
| 968 | + await maintainCreateFinish({ | |
| 969 | + ...submitData, | |
| 970 | + commitId: this.commitId, | |
| 971 | + workRecords | |
| 972 | + }) | |
| 973 | + | |
| 967 | 974 | uni.hideLoading() |
| 968 | 975 | uni.showToast({ title: '提交并结束任务成功', icon: 'success', duration: 1000 }) |
| 969 | 976 | setTimeout(() => { |
| ... | ... | @@ -973,24 +980,19 @@ export default { |
| 973 | 980 | uni.hideLoading() |
| 974 | 981 | if (Array.isArray(error)) return |
| 975 | 982 | console.error('提交并结束失败', error) |
| 976 | - const backendMsg = error && error.msg | |
| 977 | - if (this.commitId) { | |
| 978 | - uni.showToast({ | |
| 979 | - title: backendMsg ? `养护记录已提交:${backendMsg}` : '养护记录已提交,结束任务接口失败', | |
| 980 | - icon: 'none', duration: 2500 | |
| 981 | - }) | |
| 982 | - } else if (!backendMsg) { | |
| 983 | - uni.showToast({ title: '提交失败,请重试', icon: 'none', duration: 2000 }) | |
| 984 | - } | |
| 983 | + // 业务错误 request.js 已弹过后端 msg(如「当前养护计划状态不允许此操作」),这里不重复弹 | |
| 984 | + if (error && error.msg) return | |
| 985 | + uni.showToast({ title: '提交失败,请重试', icon: 'none', duration: 2000 }) | |
| 985 | 986 | } finally { |
| 986 | 987 | this.submitting = false |
| 987 | 988 | } |
| 988 | 989 | }, |
| 989 | 990 | |
| 990 | 991 | /** |
| 991 | - * 提交养护记录 —— 双写两条链路: | |
| 992 | - * ① maintain-plan-commit/create:养护计划本身(描述 + 图片 + 人员),返回 commit.id | |
| 992 | + * 暂存养护记录(按钮文案「暂存」)—— 双写两条链路: | |
| 993 | + * ① maintain-plan-commit/create:养护计划本身(描述 + 图片 + 人员),返回 commit.id;后端只建草稿,不计数 | |
| 993 | 994 | * ② work-record/submit:动态字段值,bizId 用 ① 的 commit.id(旧接口的 VO 没有动态字段,会被 Jackson 静默丢弃) |
| 995 | + * 计数只在「提交并结束」或列表「结束任务」时推进,见 submitAndFinish | |
| 994 | 996 | * 重试安全:commitId 一旦取到就缓存住,重试只补写 ②(② 自身按 clientSeq 幂等),避免重复创建养护记录 |
| 995 | 997 | */ |
| 996 | 998 | async submitInspect() { |
| ... | ... | @@ -1039,10 +1041,11 @@ export default { |
| 1039 | 1041 | } |
| 1040 | 1042 | } |
| 1041 | 1043 | uni.hideLoading() |
| 1042 | - uni.showToast({ title: '提交成功', icon: 'success', duration: 1000 }) | |
| 1044 | + // 后端 /create 只建草稿、不推进完成次数,必须再点「提交并结束」或在列表点「结束任务」才计数 | |
| 1045 | + uni.showToast({ title: '已暂存,请记得结束本次养护', icon: 'none', duration: 1500 }) | |
| 1043 | 1046 | setTimeout(() => { |
| 1044 | 1047 | uni.reLaunch({ url: '/pages-sub/daily/maintain-manage/index' }) |
| 1045 | - }, 1000) | |
| 1048 | + }, 1500) | |
| 1046 | 1049 | } catch (error) { |
| 1047 | 1050 | uni.hideLoading() |
| 1048 | 1051 | // 表单校验失败时 error 是字段数组(uview-plus 已提示),不重复弹 | ... | ... |
pages-sub/daily/maintain-manage/finish-plan-detail.vue
| ... | ... | @@ -199,14 +199,18 @@ const previewImage = (currentUrl, allUrls) => { |
| 199 | 199 | /** |
| 200 | 200 | * 获取工单详情 |
| 201 | 201 | */ |
| 202 | -const getOrderDetail = async (planNo: string) => { | |
| 202 | +const getOrderDetail = async (planNo: string, commitId?: string) => { | |
| 203 | 203 | try { |
| 204 | 204 | loading.value = true; |
| 205 | - let queryData = { | |
| 205 | + // 后端 page 接口支持 commitId 精确过滤:从上报记录列表点「查看」时只展示这一条 | |
| 206 | + let queryData: any = { | |
| 206 | 207 | planNo: planNo, |
| 207 | - pageSize: 100, | |
| 208 | + pageSize: commitId ? 1 : 100, | |
| 208 | 209 | pageNo: 1, |
| 209 | 210 | }; |
| 211 | + if (commitId) { | |
| 212 | + queryData.commitId = commitId; | |
| 213 | + } | |
| 210 | 214 | const res = await detailList(queryData); |
| 211 | 215 | console.log('接口返回:', res); |
| 212 | 216 | |
| ... | ... | @@ -527,9 +531,9 @@ const openGeo = (geo) => { |
| 527 | 531 | |
| 528 | 532 | // 页面加载 |
| 529 | 533 | onLoad((options) => { |
| 530 | - const {planNo} = options; | |
| 534 | + const {planNo, commitId} = options; | |
| 531 | 535 | if (planNo) { |
| 532 | - getOrderDetail(planNo); | |
| 536 | + getOrderDetail(planNo, commitId); | |
| 533 | 537 | } else { |
| 534 | 538 | loading.value = false; |
| 535 | 539 | uni.showToast({title: '缺少工单ID', icon: 'none'}); | ... | ... |
pages-sub/daily/maintain-manage/now-list-page.vue
| ... | ... | @@ -7,7 +7,7 @@ |
| 7 | 7 | <!-- 上报记录列表 --> |
| 8 | 8 | <view class="list-wrap" v-if="reportList.length > 0"> |
| 9 | 9 | <view class="report-item" v-for="(item, index) in reportList" :key="index"> |
| 10 | - <view class="item-title">【第{{ index+1 }}次上报】{{ item.planName }}{{ item.planName }}</view> | |
| 10 | + <view class="item-title">【第{{ item.sortNum || (index + 1) }}次上报】{{ item.planName }}</view> | |
| 11 | 11 | <view class="item-row item-row-bottom"> |
| 12 | 12 | <view class="item-time">提交时间:{{ timeFormat(item.createTime,'yyyy-mm-dd')}}</view> |
| 13 | 13 | <view class="look-btn" @click="handleView(item)">查看</view> |
| ... | ... | @@ -73,7 +73,8 @@ const getReportList = async () => { |
| 73 | 73 | const handleView = (item) => { |
| 74 | 74 | console.log('查看详情', item) |
| 75 | 75 | uni.navigateTo({ |
| 76 | - url: `/pages-sub/daily/maintain-manage/finish-plan-detail?planNo=${item.planNo}` | |
| 76 | + // 后端 page 接口支持 commitId 精确过滤,必须带上,否则会把该计划全部上报都展示出来 | |
| 77 | + url: `/pages-sub/daily/maintain-manage/finish-plan-detail?planNo=${item.planNo}&commitId=${item.commitId}` | |
| 77 | 78 | }) |
| 78 | 79 | } |
| 79 | 80 | // 新增上报记录,把planNo带到新增页面 | ... | ... |
pages-sub/daily/maintain-manage/type-list-page.vue
| ... | ... | @@ -23,7 +23,7 @@ |
| 23 | 23 | </view> |
| 24 | 24 | <!-- 第二行:任务次数 + 去作业按钮 --> |
| 25 | 25 | <view class="row row-2"> |
| 26 | - <view class="info-text">任务次数:第{{ item.plannum || 1 }}次</view> | |
| 26 | + <view class="info-text">任务次数:第{{ item.planNum || 1 }}次</view> | |
| 27 | 27 | <!-- 仅待完成才显示去作业 --> |
| 28 | 28 | <view v-if="activeStatus === '1'" class="mini-btn" @click.stop="handleGoWork(item)">去作业</view> |
| 29 | 29 | </view> |
| ... | ... | @@ -70,7 +70,7 @@ |
| 70 | 70 | import { ref, computed } from 'vue' |
| 71 | 71 | import { onShow, onUnload, onLoad } from '@dcloudio/uni-app' |
| 72 | 72 | import { useUserStore } from '@/pinia/user'; |
| 73 | -import { maintainPlanNum, finishPlan, invalidatePlan } from "@/api/maintain-manage/maintain-manage"; | |
| 73 | +import { maintainPlanNum, maintainPlanList, finishPlan, invalidatePlan } from "@/api/maintain-manage/maintain-manage"; | |
| 74 | 74 | import { timeFormat } from '@/uni_modules/uview-plus'; |
| 75 | 75 | import { useUploadImgs } from '@/common/utils/useUploadImgs' |
| 76 | 76 | const userStore = useUserStore(); |
| ... | ... | @@ -259,19 +259,33 @@ const confirmEndTask = async () => { |
| 259 | 259 | |
| 260 | 260 | uni.showLoading({ title: '提交中...', mask: true }) |
| 261 | 261 | try { |
| 262 | - // 接口 finishPlan,传 planNo | |
| 263 | - await finishPlan({ | |
| 264 | - planNo: item.planNo | |
| 262 | + // ① 后端 /finish 只认 commitId:先找该计划编码下进行中的本次养护(commitState=1) | |
| 263 | + const page = await maintainPlanList({ | |
| 264 | + planNo: item.planNo, | |
| 265 | + pageNo: 1, | |
| 266 | + pageSize: 50 | |
| 265 | 267 | }) |
| 268 | + const draft = (page && page.list ? page.list : []).find((r: any) => Number(r.commitState) === 1) | |
| 269 | + if (!draft || !draft.commitId) { | |
| 270 | + uni.hideLoading() | |
| 271 | + uni.showToast({ title: '还没有上报记录,请先去作业提交', icon: 'none' }) | |
| 272 | + return | |
| 273 | + } | |
| 274 | + // ② 按 commitId 结束本次养护(后端要求本次养护至少有一条有效子上报) | |
| 275 | + await finishPlan({ commitId: draft.commitId }) | |
| 276 | + // 先关 loading 再弹提示:微信端 showLoading/showToast 共用同一个 toast,顺序反了会把成功提示顶掉 | |
| 277 | + uni.hideLoading() | |
| 266 | 278 | uni.showToast({ title: '结束任务成功', icon: 'success' }) |
| 267 | 279 | // 操作成功,重新加载数据,刷新列表 |
| 268 | 280 | await loadData() |
| 269 | 281 | pagingRef.value?.reload() |
| 270 | 282 | } catch (err) { |
| 271 | 283 | console.error('结束任务失败', err) |
| 284 | + uni.hideLoading() | |
| 285 | + // 业务错误 request.js 已弹过后端 msg,这里不重复弹 | |
| 286 | + if (err && err.msg) return | |
| 272 | 287 | uni.showToast({ title: '结束任务失败,请重试', icon: 'none' }) |
| 273 | 288 | } finally { |
| 274 | - uni.hideLoading() | |
| 275 | 289 | currentEndTaskItem.value = null |
| 276 | 290 | } |
| 277 | 291 | } | ... | ... |