Commit 40ba5f9a42931871104e124bb44becbd6ef979e4

Authored by 刘淇
1 parent 073562dd

结束二次确定

pages-sub/daily/maintain-manage/type-list-page.vue
@@ -29,8 +29,9 @@ @@ -29,8 +29,9 @@
29 </view> 29 </view>
30 <!-- 第三行:有效期 + 结束任务按钮 --> 30 <!-- 第三行:有效期 + 结束任务按钮 -->
31 <view class="row row-3"> 31 <view class="row row-3">
32 - <!-- timeFormat(start, 'yyyy-mm-dd'), -->  
33 - <view class="info-text u-line-1">有效期:{{ timeFormat(item.beginTime, 'yyyy-mm-dd') }}—{{ timeFormat(item.endTime, 'yyyy-mm-dd') }} 32 + <!-- timeFormat(start, 'yyyy-mm-dd'), -->
  33 + <view class="info-text u-line-1">有效期:{{ timeFormat(item.beginTime, 'yyyy-mm-dd') }}—{{
  34 + timeFormat(item.endTime, 'yyyy-mm-dd') }}
34 </view> 35 </view>
35 <!-- 仅待完成才显示结束任务 --> 36 <!-- 仅待完成才显示结束任务 -->
36 <view v-if="activeStatus === '1'" class="mini-btn" @click.stop="handleEndTask(item)">结束任务</view> 37 <view v-if="activeStatus === '1'" class="mini-btn" @click.stop="handleEndTask(item)">结束任务</view>
@@ -54,11 +55,20 @@ @@ -54,11 +55,20 @@
54 </view> 55 </view>
55 </view> 56 </view>
56 </up-modal> 57 </up-modal>
  58 +
  59 + <!-- ========== 结束任务二次确认弹窗【新增】 ========== -->
  60 + <up-modal :show="endTaskModalShow" title="提示" :closeOnClickOverlay="false" :showConfirmButton="true"
  61 + :showCancelButton="true" @cancel="handleEndTaskModalCancel" @confirm="confirmEndTask">
  62 + <view class="end-task-modal-content">
  63 + <text>确定要结束该任务吗?结束后将不可再去作业。</text>
  64 + </view>
  65 + </up-modal>
  66 +
57 </view> 67 </view>
58 </template> 68 </template>
59 <script setup lang="ts"> 69 <script setup lang="ts">
60 import { ref, computed } from 'vue' 70 import { ref, computed } from 'vue'
61 -import { onShow, onUnload,onLoad } from '@dcloudio/uni-app' 71 +import { onShow, onUnload, onLoad } from '@dcloudio/uni-app'
62 import { useUserStore } from '@/pinia/user'; 72 import { useUserStore } from '@/pinia/user';
63 import { maintainPlanNum, finishPlan, invalidatePlan } from "@/api/maintain-manage/maintain-manage"; 73 import { maintainPlanNum, finishPlan, invalidatePlan } from "@/api/maintain-manage/maintain-manage";
64 import { timeFormat } from '@/uni_modules/uview-plus'; 74 import { timeFormat } from '@/uni_modules/uview-plus';
@@ -89,6 +99,9 @@ const allTotalData = ref&lt;any[]&gt;([]) @@ -89,6 +99,9 @@ const allTotalData = ref&lt;any[]&gt;([])
89 const invalidModalShow = ref(false) 99 const invalidModalShow = ref(false)
90 const invalidReason = ref('') 100 const invalidReason = ref('')
91 const currentInvalidItem = ref(null) 101 const currentInvalidItem = ref(null)
  102 +// ===================== 结束任务确认弹窗【新增】 =====================
  103 +const endTaskModalShow = ref(false)
  104 +const currentEndTaskItem = ref<any>(null)
92 // 图片上传实例,和回退保持一致,最多3张 105 // 图片上传实例,和回退保持一致,最多3张
93 const invalidImgs = useUploadImgs({ 106 const invalidImgs = useUploadImgs({
94 maxCount: 3, 107 maxCount: 3,
@@ -147,7 +160,7 @@ const loadData = async () =&gt; { @@ -147,7 +160,7 @@ const loadData = async () =&gt; {
147 const planTypeId = ref('') 160 const planTypeId = ref('')
148 onLoad((options) => { 161 onLoad((options) => {
149 planTypeId.value = options.planTypeId 162 planTypeId.value = options.planTypeId
150 - 163 +
151 }); 164 });
152 // onShow 只保留一处,读取storage,只第一次读取storage 165 // onShow 只保留一处,读取storage,只第一次读取storage
153 onShow(async () => { 166 onShow(async () => {
@@ -185,40 +198,40 @@ const handleInvalidModalCancel = () =&gt; { @@ -185,40 +198,40 @@ const handleInvalidModalCancel = () =&gt; {
185 198
186 // 确认提交置为失效 199 // 确认提交置为失效
187 const confirmSetInvalid = async () => { 200 const confirmSetInvalid = async () => {
188 - const reason = invalidReason.value.trim()  
189 - if (!reason) {  
190 - uni.showToast({ title: '请填写失效原因', icon: 'none' })  
191 - return  
192 - }  
193 - const item = currentInvalidItem.value  
194 - if (!item || !item.id) return 201 + const reason = invalidReason.value.trim()
  202 + if (!reason) {
  203 + uni.showToast({ title: '请填写失效原因', icon: 'none' })
  204 + return
  205 + }
  206 + const item = currentInvalidItem.value
  207 + if (!item || !item.id) return
195 208
196 - uni.showLoading({ title: '提交中...', mask: true })  
197 - try {  
198 - // 获取上传成功图片url数组,拼接逗号  
199 - const imgUrlArr = invalidImgs.getSuccessImgUrls()  
200 - const invalidFiles = imgUrlArr.join(',') 209 + uni.showLoading({ title: '提交中...', mask: true })
  210 + try {
  211 + // 获取上传成功图片url数组,拼接逗号
  212 + const imgUrlArr = invalidImgs.getSuccessImgUrls()
  213 + const invalidFiles = imgUrlArr.join(',')
201 214
202 - const params = {  
203 - id: item.id,  
204 - invalidReason: reason,  
205 - invalidFiles: invalidFiles  
206 - }  
207 - console.log('置为失效提交参数:', params)  
208 - // 调用接口 invalidatePlan  
209 - await invalidatePlan(params) 215 + const params = {
  216 + id: item.id,
  217 + invalidReason: reason,
  218 + invalidFiles: invalidFiles
  219 + }
  220 + console.log('置为失效提交参数:', params)
  221 + // 调用接口 invalidatePlan
  222 + await invalidatePlan(params)
210 223
211 - uni.showToast({ title: '操作成功', icon: 'success' })  
212 - handleInvalidModalCancel()  
213 - // 重新加载数据刷新列表  
214 - await loadData()  
215 - pagingRef.value?.reload()  
216 - } catch (err) {  
217 - console.error(err)  
218 - uni.showToast({ title: '提交失败,请重试', icon: 'none' })  
219 - } finally {  
220 - uni.hideLoading()  
221 - } 224 + uni.showToast({ title: '操作成功', icon: 'success' })
  225 + handleInvalidModalCancel()
  226 + // 重新加载数据刷新列表
  227 + await loadData()
  228 + pagingRef.value?.reload()
  229 + } catch (err) {
  230 + console.error(err)
  231 + uni.showToast({ title: '提交失败,请重试', icon: 'none' })
  232 + } finally {
  233 + uni.hideLoading()
  234 + }
222 } 235 }
223 236
224 const handleGoWork = (item) => { 237 const handleGoWork = (item) => {
@@ -228,23 +241,39 @@ const handleGoWork = (item) =&gt; { @@ -228,23 +241,39 @@ const handleGoWork = (item) =&gt; {
228 }) 241 })
229 } 242 }
230 const handleEndTask = async (item) => { 243 const handleEndTask = async (item) => {
231 - console.log(item)  
232 - uni.showLoading({ title: '提交中...', mask: true })  
233 - try {  
234 - // 接口 finishPlan,传 planNo  
235 - await finishPlan({  
236 - planNo: item.planNo  
237 - })  
238 - uni.showToast({ title: '结束任务成功', icon: 'success' })  
239 - // 操作成功,重新加载数据,刷新列表  
240 - await loadData()  
241 - pagingRef.value?.reload()  
242 - } catch (err) {  
243 - console.error('结束任务失败', err)  
244 - uni.showToast({ title: '结束任务失败,请重试', icon: 'none' })  
245 - } finally {  
246 - uni.hideLoading()  
247 - } 244 + currentEndTaskItem.value = item
  245 + endTaskModalShow.value = true
  246 +}
  247 +
  248 +// 关闭结束任务弹窗
  249 +const handleEndTaskModalCancel = () => {
  250 + endTaskModalShow.value = false
  251 + currentEndTaskItem.value = null
  252 +}
  253 +
  254 +// 确认结束任务,真正调用接口【新增】
  255 +const confirmEndTask = async () => {
  256 + const item = currentEndTaskItem.value
  257 + if (!item || !item.planNo) return
  258 + endTaskModalShow.value = false
  259 +
  260 + uni.showLoading({ title: '提交中...', mask: true })
  261 + try {
  262 + // 接口 finishPlan,传 planNo
  263 + await finishPlan({
  264 + planNo: item.planNo
  265 + })
  266 + uni.showToast({ title: '结束任务成功', icon: 'success' })
  267 + // 操作成功,重新加载数据,刷新列表
  268 + await loadData()
  269 + pagingRef.value?.reload()
  270 + } catch (err) {
  271 + console.error('结束任务失败', err)
  272 + uni.showToast({ title: '结束任务失败,请重试', icon: 'none' })
  273 + } finally {
  274 + uni.hideLoading()
  275 + currentEndTaskItem.value = null
  276 + }
248 } 277 }
249 278
250 // 页面卸载清空,防止内存残留 279 // 页面卸载清空,防止内存残留