| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- <script setup>
- import { ref, computed } from 'vue'
- import { onLoad, onShow } from '@dcloudio/uni-app'
- import { getWeighing, updateWeighing, voidWeighing } from '@/api/db'
- import { weighingPhase, dash, formatWeight, nowYmdHms, todayYmd } from '@/utils/dbLabels'
- import { PAGE_PATHS } from '@/config/api'
- const id = ref('')
- const detail = ref(null)
- const showSecond = ref(false)
- const tareWeight = ref('')
- const acting = ref(false)
- const phase = computed(() => weighingPhase(detail.value))
- const canSecond = computed(() => phase.value.text === '一次过磅')
- const canVoid = computed(() => {
- if (!detail.value || Number(detail.value.isVoided) === 1) return false
- const t = String(detail.value.grossWeightTime || detail.value.createdAt || '')
- return t.startsWith(todayYmd())
- })
- const goBack = () => {
- uni.navigateBack({
- fail: () => uni.navigateTo({ url: PAGE_PATHS.dbWeighingList })
- })
- }
- const load = async () => {
- if (!id.value) return
- try {
- detail.value = await getWeighing(id.value)
- } catch (e) {
- uni.showToast({ title: e.message || '加载失败', icon: 'none' })
- }
- }
- const openSecond = () => {
- tareWeight.value = ''
- showSecond.value = true
- }
- const submitSecond = async () => {
- const tare = Number(tareWeight.value)
- if (!tare || tare <= 0) {
- uni.showToast({ title: '请填写皮重', icon: 'none' })
- return
- }
- const gross = Number(detail.value?.grossWeight) || 0
- const deduction = Number(detail.value?.deduction) || 0
- const net = Math.max(gross - tare - deduction, 0)
- acting.value = true
- try {
- await updateWeighing(id.value, {
- tareWeight: tare,
- tareWeightTime: nowYmdHms(),
- netWeight: net
- })
- uni.showToast({ title: '二次过磅已保存', icon: 'success' })
- showSecond.value = false
- load()
- } catch (e) {
- uni.showToast({ title: e.message || '保存失败', icon: 'none' })
- } finally {
- acting.value = false
- }
- }
- const onVoid = () => {
- uni.showModal({
- title: '作废地磅单',
- content: '仅支持作废当天单据,确认作废?',
- success: async (r) => {
- if (!r.confirm) return
- acting.value = true
- try {
- await voidWeighing(id.value)
- uni.showToast({ title: '已作废', icon: 'success' })
- load()
- } catch (e) {
- uni.showToast({ title: e.message || '作废失败', icon: 'none' })
- } finally {
- acting.value = false
- }
- }
- })
- }
- onLoad((q) => {
- id.value = q?.id || ''
- })
- onShow(() => load())
- </script>
- <template>
- <view class="mp-page mp-page--sub mp-page--with-bottom">
- <view class="mp-header mp-header--db">
- <text class="mp-subpage-back" @click="goBack">← 返回</text>
- <text class="mp-header__title" style="margin-top: 16rpx">地磅单详情</text>
- </view>
- <view v-if="detail" class="mp-detail-hero">
- <view class="mp-detail-hero__top">
- <view>
- <text class="mp-detail-hero__title">{{ dash(detail.vehicleNo) }}</text>
- <text class="mp-detail-hero__sub">{{ dash(detail.cargoName) }} · {{ dash(detail.businessType) }}</text>
- </view>
- <text class="mp-tag" :class="'mp-tag--' + phase.tag">{{ phase.text }}</text>
- </view>
- <view class="mp-detail-hero__meta">
- <text class="mp-detail-hero__chip">净重 {{ formatWeight(detail.netWeight) }}</text>
- <text class="mp-detail-hero__chip">{{ dash(detail.batchNo) }}</text>
- </view>
- </view>
- <view class="mp-block">
- <text class="mp-block__title">过磅数据</text>
- <view class="mp-block__panel">
- <view class="mp-kv"><text class="mp-kv__label">毛重</text><text class="mp-kv__value">{{ formatWeight(detail?.grossWeight) }}</text></view>
- <view class="mp-kv"><text class="mp-kv__label">毛重时间</text><text class="mp-kv__value">{{ dash(detail?.grossWeightTime) }}</text></view>
- <view class="mp-kv"><text class="mp-kv__label">皮重</text><text class="mp-kv__value">{{ formatWeight(detail?.tareWeight) }}</text></view>
- <view class="mp-kv"><text class="mp-kv__label">皮重时间</text><text class="mp-kv__value">{{ dash(detail?.tareWeightTime) }}</text></view>
- <view class="mp-kv"><text class="mp-kv__label">扣重</text><text class="mp-kv__value">{{ formatWeight(detail?.deduction) }}</text></view>
- <view class="mp-kv"><text class="mp-kv__label">净重</text><text class="mp-kv__value">{{ formatWeight(detail?.netWeight) }}</text></view>
- </view>
- </view>
- <view class="mp-block">
- <text class="mp-block__title">业务信息</text>
- <view class="mp-block__panel">
- <view class="mp-kv"><text class="mp-kv__label">计划号</text><text class="mp-kv__value">{{ dash(detail?.planNo) }}</text></view>
- <view class="mp-kv"><text class="mp-kv__label">规格</text><text class="mp-kv__value">{{ dash(detail?.specification) }}</text></view>
- <view class="mp-kv"><text class="mp-kv__label">供货单位</text><text class="mp-kv__value">{{ dash(detail?.supplier) }}</text></view>
- <view class="mp-kv"><text class="mp-kv__label">收货单位</text><text class="mp-kv__value">{{ dash(detail?.consignee) }}</text></view>
- <view class="mp-kv"><text class="mp-kv__label">过磅点</text><text class="mp-kv__value">{{ dash(detail?.weighingPoint) }}</text></view>
- <view class="mp-kv"><text class="mp-kv__label">备注</text><text class="mp-kv__value">{{ dash(detail?.remarks) }}</text></view>
- </view>
- </view>
- <view v-if="showSecond" class="mp-form-panel">
- <view class="mp-form-row">
- <text class="mp-form-label mp-form-label--req">皮重(kg)</text>
- <input v-model="tareWeight" class="mp-form-input" type="digit" placeholder="二次过磅皮重" />
- </view>
- <view class="mp-form-row" style="display: flex; gap: 16rpx">
- <view class="mp-btn mp-btn--ghost" style="flex: 1" @click="showSecond = false">取消</view>
- <view class="mp-btn mp-btn--primary" style="flex: 1" @click="submitSecond">
- {{ acting ? '…' : '确认保存' }}
- </view>
- </view>
- </view>
- <view class="mp-bottom-bar">
- <view v-if="canSecond" class="mp-btn mp-btn--primary" @click="openSecond">二次过磅</view>
- <view v-if="canVoid" class="mp-btn mp-btn--danger" @click="onVoid">作废</view>
- </view>
- </view>
- </template>
|