小程序需重进页面才提示错误问题

This commit is contained in:
Ledo 2025-07-07 14:54:48 +08:00
parent 391818d086
commit 4194f5e9ee

View File

@ -1,49 +1,49 @@
<script setup lang="ts"> <script setup lang="ts">
import { toRaw, ref, computed } from 'vue' import { toRaw, ref, computed } from 'vue'
import { formatDate } from '@/utils/index' import { formatDate } from '@/utils/index'
import { onLoad, onShow } from '@dcloudio/uni-app' import { onLoad, onShow } from '@dcloudio/uni-app'
import { useLoginStore } from '@/stores/modules/login' import { useLoginStore } from '@/stores/modules/login'
import { getTaskRepotPageAPI, getTaskDetailAPI, postOperateAPI } from '@/services/productionReport' import { getTaskRepotPageAPI, getTaskDetailAPI, postOperateAPI } from '@/services/productionReport'
const popup = ref<UniHelper.UniPopupInstance>() const popup = ref<UniHelper.UniPopupInstance>()
const userStore = useLoginStore() const userStore = useLoginStore()
const dictInfo = userStore?.dictInfo || [] const dictInfo = userStore?.dictInfo || []
const unitDictData = dictInfo.filter(e => e.dictType == 'heli_material_unit') || [] const unitDictData = dictInfo.filter(e => e.dictType == 'heli_material_unit') || []
const userId = userStore.userInfo.userId const userId = userStore.userInfo.userId
const isShowStart = ref(false) const isShowStart = ref(false)
const isShowEnd = ref(false) const isShowEnd = ref(false)
// const isShowStart = computed(() => { // const isShowStart = computed(() => {
// let flag = true // let flag = true
// if (historyList.value.length) { // if (historyList.value.length) {
// const obj = historyList.value[0] // const obj = historyList.value[0]
// if (!obj?.endTime) { // if (!obj?.endTime) {
// flag = false // flag = false
// } // }
// } // }
// return flag // return flag
// }) // })
// const isShowEnd = computed(() => { // const isShowEnd = computed(() => {
// let flag = true // let flag = true
// if (historyList.value.length) { // if (historyList.value.length) {
// const obj = historyList.value[0] // const obj = historyList.value[0]
// if (obj?.endTime) { // if (obj?.endTime) {
// flag = false // flag = false
// } // }
// } else { // } else {
// flag = false // flag = false
// } // }
// return flag // return flag
// }) // })
const amount = ref(null) const amount = ref(null)
const workTime = ref(null) const workTime = ref(null)
// //
const detailInfo = ref({}) const detailInfo = ref({})
let isLoading = ref(false) let isLoading = ref(false)
const historyList = ref([]) const historyList = ref([])
const formObj = ref({}) const formObj = ref({})
// //
const getData = async () => { const getData = async () => {
// //
// isLoading.value = true // isLoading.value = true
const params = { const params = {
@ -61,7 +61,7 @@ const getData = async () => {
if (data.list[0]) { if (data.list[0]) {
// Date // Date
formObj.value = data.list[0] formObj.value = data.list[0]
const endTime= new Date(formObj.value.endTimeStr); const endTime = new Date(formObj.value.endTimeStr);
const startTime = new Date(formObj.value.startTimeStr); const startTime = new Date(formObj.value.startTimeStr);
// //
const timeDifferenceInMs = endTime - startTime; const timeDifferenceInMs = endTime - startTime;
@ -69,9 +69,9 @@ const getData = async () => {
// //
const timeDifferenceInHours = timeDifferenceInMs / (3600 * 1000); const timeDifferenceInHours = timeDifferenceInMs / (3600 * 1000);
const roundedTimeDifference = parseFloat(timeDifferenceInHours.toFixed(2)); const roundedTimeDifference = parseFloat(timeDifferenceInHours.toFixed(2));
if ("Y"==detailInfo.value.isOutsourcing){ if ("Y" == detailInfo.value.isOutsourcing) {
}else { } else {
workTime.value = roundedTimeDifference; workTime.value = roundedTimeDifference;
} }
@ -83,7 +83,7 @@ const getData = async () => {
const obj = historyList.value[0] const obj = historyList.value[0]
console.log('s') console.log('s')
if (!obj?.amount) { if (!obj?.amount) {
isShowStart.value= false isShowStart.value = false
} }
} }
if (historyList.value.length) { if (historyList.value.length) {
@ -94,12 +94,12 @@ const getData = async () => {
} else { } else {
isShowEnd.value = false isShowEnd.value = false
} }
if(historyList.value!=null&&historyList.value.length>0){ if (historyList.value != null && historyList.value.length > 0) {
var totalAmount = detailInfo.value.amount; var totalAmount = detailInfo.value.amount;
var beforeAmount = detailInfo.value.totalReportAmount var beforeAmount = detailInfo.value.totalReportAmount
if(totalAmount >= beforeAmount){ if (totalAmount >= beforeAmount) {
amount.value = totalAmount - beforeAmount amount.value = totalAmount - beforeAmount
}else{ } else {
amount.value = 0 amount.value = 0
} }
@ -107,17 +107,17 @@ const getData = async () => {
isLoading.value = false isLoading.value = false
} }
// //
const isOverBeforeProcedure = ref(true) const isOverBeforeProcedure = ref(true)
const getDetailData = async (id) => { const getDetailData = async (id) => {
// //
// isLoading.value = true // isLoading.value = true
const params = { const params = {
id, id,
} }
const data = await getTaskDetailAPI(params) const data = await getTaskDetailAPI(params)
if(data.beforeProcedureStatus == 0){ if (data.beforeProcedureStatus == 0) {
// //
isOverBeforeProcedure.value = true; isOverBeforeProcedure.value = true;
} }
@ -137,9 +137,9 @@ const getDetailData = async (id) => {
data.unit = lineObj.label data.unit = lineObj.label
detailInfo.value = data || {} detailInfo.value = data || {}
isLoading.value = false isLoading.value = false
} }
const popupShow = ref(false) const popupShow = ref(false)
onLoad(async (options: any) => { onLoad(async (options : any) => {
await getDetailData(options.id) await getDetailData(options.id)
await getData() await getData()
const obj = historyList.value[0] const obj = historyList.value[0]
@ -147,10 +147,10 @@ onLoad(async (options: any) => {
if (obj && obj?.workTime == null && obj.endTime) { if (obj && obj?.workTime == null && obj.endTime) {
popupShow.value = true popupShow.value = true
} }
}) })
// //
const handleComplate = async () => { const handleComplate = async () => {
isLoading.value = true isLoading.value = true
const params = { const params = {
id: detailInfo.value?.id, id: detailInfo.value?.id,
@ -158,14 +158,17 @@ const handleComplate = async () => {
} }
try { try {
const data = await postOperateAPI(params); const data = await postOperateAPI(params);
console.log(data)
console.log('ai')
} catch (error) { } catch (error) {
console.log(error) console.log('meijinlai ')
uni.showToast({ uni.showToast({
icon: 'none', icon: 'none',
duration: 3000, duration: 3000,
title: error.data.msg, title: error.data.msg,
}) })
} finally { } finally {
console.log('jie')
await getDetailData(detailInfo.value.id) await getDetailData(detailInfo.value.id)
await getData() await getData()
const obj = historyList.value[0] const obj = historyList.value[0]
@ -179,9 +182,9 @@ const handleComplate = async () => {
// uni.redirectTo({ // uni.redirectTo({
// url, // url,
// }) // })
} }
// //
const handleOk = async (active) => { const handleOk = async (active) => {
const params = { const params = {
id: detailInfo.value?.id, id: detailInfo.value?.id,
active: 'SUBMIT', active: 'SUBMIT',
@ -189,37 +192,54 @@ const handleOk = async (active) => {
workTime: workTime.value, workTime: workTime.value,
} }
const data = await postOperateAPI(params) const data = await postOperateAPI(params)
const url = `/pages/productionReport/productionReport-detail?id=${detailInfo.value.id}` const pages = getCurrentPages(); //
uni.redirectTo({ const currentPage = pages[pages.length - 1]; //
url, const url = `/${currentPage.route}?${Object.entries(currentPage.options).map(([key, val]) => `${key}=${val}`).join('&')}`;
}) uni.reLaunch({ url }); //
}
// // const url = `/pages/productionReport/productionReport-detail?id=${detailInfo.value.id}`
const handleStart = async () => { // uni.redirectTo({
// url,
// })
}
//
const handleStart = async () => {
const params = { const params = {
id: detailInfo.value.id, id: detailInfo.value.id,
active: 'START', active: 'START',
} }
const data = await postOperateAPI(params) const data = await postOperateAPI(params)
const url = `/pages/productionReport/productionReport-detail?id=${detailInfo.value.id}` const pages = getCurrentPages(); //
uni.redirectTo({ const currentPage = pages[pages.length - 1]; //
url, const url = `/${currentPage.route}?${Object.entries(currentPage.options).map(([key, val]) => `${key}=${val}`).join('&')}`;
}) uni.reLaunch({ url }); //
}
// // const url = `/pages/productionReport/productionReport-detail?id=${detailInfo.value.id}`
const handleStop = async () => { // uni.redirectTo({
// url,
// })
}
//
const handleStop = async () => {
const params = { const params = {
id: detailInfo.value?.id, id: detailInfo.value?.id,
active: 'END', active: 'END',
} }
const data = await postOperateAPI(params) const data = await postOperateAPI(params)
await getDetailData(detailInfo.value.id)
await getData() await getData()
const obj = historyList.value[0]
//
if (obj && obj?.workTime == null && obj.endTime) {
popupShow.value = true
}
// const url = `/pages/productionReport/productionReport-detail?id=${detailInfo.value.id}` // const url = `/pages/productionReport/productionReport-detail?id=${detailInfo.value.id}`
// uni.redirectTo({ // uni.redirectTo({
// url, // url,
// }) // })
popup.value?.open() popup.value?.open()
} }
</script> </script>
<template> <template>
<view> <view>
@ -228,10 +248,12 @@ const handleStop = async () => {
<view class="module"> <view class="module">
<view class="module-info"> <view class="module-info">
<view class="product-item">项目{{ detailInfo.projectCode }} {{ detailInfo.projectName }}</view> <view class="product-item">项目{{ detailInfo.projectCode }} {{ detailInfo.projectName }}</view>
<image src="/static/images/productionReport-page.png" class="product-img" mode="scaleToFill"></image> <image src="/static/images/productionReport-page.png" class="product-img" mode="scaleToFill">
</image>
<view :class="[detailInfo.procedureStatus == 2 ? 'had' : 'unhad', 'product-status']">{{ <view :class="[detailInfo.procedureStatus == 2 ? 'had' : 'unhad', 'product-status']">{{
detailInfo.procedureStatus == 2 ? '已完成' : '未完成' }}</view> detailInfo.procedureStatus == 2 ? '已完成' : '未完成' }}</view>
<view class="product-item">子项目{{ detailInfo.projectSubCode || '' }} {{ ' ' + detailInfo.projectSubName }} <view class="product-item">子项目{{ detailInfo.projectSubCode || '' }}
{{ ' ' + detailInfo.projectSubName }}
</view> </view>
<view class="product-item">派工工序{{ detailInfo.procedureName }}</view> <view class="product-item">派工工序{{ detailInfo.procedureName }}</view>
<view class="product-row"> <view class="product-row">
@ -255,9 +277,11 @@ const handleStop = async () => {
</view> </view>
</view> </view>
<view class="product-item">预计生产日期{{ detailInfo.startTime }} {{ detailInfo.endTime }}</view> <view class="product-item">预计生产日期{{ detailInfo.startTime }} {{ detailInfo.endTime }}</view>
<view class="finish" v-if="isShowStart && detailInfo.procedureStatus !== 2 && detailInfo.totalWorkTime" <view class="finish"
v-if="isShowStart && detailInfo.procedureStatus !== 2 && detailInfo.totalWorkTime"
@click="handleComplate"> @click="handleComplate">
<image class="complate-img" src="/static/images/productionReport-detail-complate.png" mode="scaleToFill" /> <image class="complate-img" src="/static/images/productionReport-detail-complate.png"
mode="scaleToFill" />
生产完成 生产完成
</view> </view>
</view> </view>
@ -283,7 +307,8 @@ const handleStop = async () => {
</view> </view>
</view> </view>
<view class="tip-index"> <view class="tip-index">
<image src="/static/images/productionReport-detail-index.png" class="icon-status" mode="scaleToFit"> <image src="/static/images/productionReport-detail-index.png" class="icon-status"
mode="scaleToFit">
</image> </image>
<view class="text">{{ historyList.length - index }}</view> <view class="text">{{ historyList.length - index }}</view>
</view> </view>
@ -314,12 +339,14 @@ const handleStop = async () => {
</view> </view>
<view class="item"> <view class="item">
<view class="label"><span class="star">*</span>本次报工工时</view> <view class="label"><span class="star">*</span>本次报工工时</view>
<uni-easyinput class="val" type="digit" v-model="workTime" placeholder="请输入本次报工工时"></uni-easyinput> <uni-easyinput class="val" type="digit" v-model="workTime"
placeholder="请输入本次报工工时"></uni-easyinput>
<view class="unit"></view> <view class="unit"></view>
</view> </view>
<view class="item"> <view class="item">
<view class="label"><span class="star">*</span>本次报工数量</view> <view class="label"><span class="star">*</span>本次报工数量</view>
<uni-easyinput class="val" type="number" v-model="amount" placeholder="请输入本次报工数量"></uni-easyinput> <uni-easyinput class="val" type="number" v-model="amount"
placeholder="请输入本次报工数量"></uni-easyinput>
<view class="unit"> {{ detailInfo.unit }}</view> <view class="unit"> {{ detailInfo.unit }}</view>
</view> </view>
</view> </view>
@ -333,8 +360,8 @@ const handleStop = async () => {
</template> </template>
<style lang="scss"> <style lang="scss">
// //
.data-detail { .data-detail {
border-radius: 10rpx; border-radius: 10rpx;
padding-bottom: 200rpx; padding-bottom: 200rpx;
@ -409,6 +436,7 @@ const handleStop = async () => {
} }
} }
.finish { .finish {
position: absolute; position: absolute;
right: 40rpx; right: 40rpx;
@ -649,5 +677,5 @@ const handleStop = async () => {
color: #fff; color: #fff;
} }
} }
} }
</style> </style>