385 lines
11 KiB
Vue
385 lines
11 KiB
Vue
|
|
<template>
|
|||
|
|
<view class="page-detail">
|
|||
|
|
<!-- 信息表单 -->
|
|||
|
|
<view class="info-group">
|
|||
|
|
<!-- 车次 -->
|
|||
|
|
<view class="info-item">
|
|||
|
|
<text class="info-label" v-if="isEdit"><text class="required">*</text>车次</text>
|
|||
|
|
<text class="info-label" v-else>车次</text>
|
|||
|
|
<u-input v-if="isEdit" v-model="form.TrainNumber" placeholder="请输入车次" />
|
|||
|
|
<text class="info-value" v-else>{{ form.TrainNumber || '--' }}</text>
|
|||
|
|
</view>
|
|||
|
|
|
|||
|
|
<!-- 单位名称 -->
|
|||
|
|
<view class="info-item">
|
|||
|
|
<text class="info-label" v-if="isEdit"><text class="required">*</text>单位名称</text>
|
|||
|
|
<text class="info-label" v-else>单位名称</text>
|
|||
|
|
<u-input v-if="isEdit" v-model="form.UnitName" :clearable="false" type="select" placeholder="请选择单位" @click="handleShowUnit" />
|
|||
|
|
<text class="info-value" v-else>{{ form.UnitName || '--' }}</text>
|
|||
|
|
</view>
|
|||
|
|
|
|||
|
|
<!-- 驾驶员姓名 -->
|
|||
|
|
<view class="info-item">
|
|||
|
|
<text class="info-label" v-if="isEdit"><text class="required">*</text>驾驶员姓名</text>
|
|||
|
|
<text class="info-label" v-else>驾驶员姓名</text>
|
|||
|
|
<u-input v-if="isEdit" v-model="form.DriverName" placeholder="请输入驾驶员姓名" />
|
|||
|
|
<text class="info-value" v-else>{{ form.DriverName || '--' }}</text>
|
|||
|
|
</view>
|
|||
|
|
|
|||
|
|
<!-- 驾驶员电话 -->
|
|||
|
|
<view class="info-item">
|
|||
|
|
<text class="info-label" v-if="isEdit"><text class="required">*</text>驾驶员电话</text>
|
|||
|
|
<text class="info-label" v-else>驾驶员电话</text>
|
|||
|
|
<u-input v-if="isEdit" v-model="form.DriverPhone" placeholder="请输入驾驶员电话" type="number" />
|
|||
|
|
<text class="info-value" v-else>{{ form.DriverPhone || '--' }}</text>
|
|||
|
|
</view>
|
|||
|
|
|
|||
|
|
<!-- 车牌号 -->
|
|||
|
|
<view class="info-item">
|
|||
|
|
<text class="info-label" v-if="isEdit"><text class="required">*</text>车牌号</text>
|
|||
|
|
<text class="info-label" v-else>车牌号</text>
|
|||
|
|
<u-input v-if="isEdit" v-model="form.LicensePlateNumber" placeholder="请输入车牌号" />
|
|||
|
|
<text class="info-value" v-else>{{ form.LicensePlateNumber || '--' }}</text>
|
|||
|
|
</view>
|
|||
|
|
|
|||
|
|
<!-- 联系人姓名 -->
|
|||
|
|
<view class="info-item">
|
|||
|
|
<text class="info-label" v-if="isEdit"><text class="required">*</text>联系人姓名</text>
|
|||
|
|
<text class="info-label" v-else>联系人姓名</text>
|
|||
|
|
<u-input v-if="isEdit" v-model="form.ContactName" placeholder="请输入联系人姓名" />
|
|||
|
|
<text class="info-value" v-else>{{ form.ContactName || '--' }}</text>
|
|||
|
|
</view>
|
|||
|
|
|
|||
|
|
<!-- 联系人电话 -->
|
|||
|
|
<view class="info-item">
|
|||
|
|
<text class="info-label" v-if="isEdit"><text class="required">*</text>联系人电话</text>
|
|||
|
|
<text class="info-label" v-else>联系人电话</text>
|
|||
|
|
<u-input v-if="isEdit" v-model="form.ContactPhone" placeholder="请输入联系人电话" type="number" />
|
|||
|
|
<text class="info-value" v-else>{{ form.ContactPhone || '--' }}</text>
|
|||
|
|
</view>
|
|||
|
|
|
|||
|
|
<!-- 备注 -->
|
|||
|
|
<view class="info-item">
|
|||
|
|
<text class="info-label">备注</text>
|
|||
|
|
<u-input v-if="isEdit" v-model="form.Remark" placeholder="请输入备注" type="textarea" />
|
|||
|
|
<text class="info-value" v-else>{{ form.Remark || '--' }}</text>
|
|||
|
|
</view>
|
|||
|
|
|
|||
|
|
<!-- 状态 -->
|
|||
|
|
<view class="info-item">
|
|||
|
|
<text class="info-label">状态</text>
|
|||
|
|
<text class="info-value">{{ form.StateName || '--' }}</text>
|
|||
|
|
</view>
|
|||
|
|
|
|||
|
|
<!-- 扫码添加(编辑状态有Id且未发货) -->
|
|||
|
|
<view class="scan-row" v-if="form.TrainNumberId && isEdit">
|
|||
|
|
<text class="scan-text">扫码添加</text>
|
|||
|
|
<view class="scan-btn" @click="handleScan">
|
|||
|
|
<u-icon name="scan" :size="40" color="#2979ff"></u-icon>
|
|||
|
|
</view>
|
|||
|
|
</view>
|
|||
|
|
|
|||
|
|
<!-- 包装列表 -->
|
|||
|
|
<view class="package-section" v-if="form.TrainNumberId">
|
|||
|
|
<text class="section-title">包装列表</text>
|
|||
|
|
<view class="package-table">
|
|||
|
|
<view class="table-hd">
|
|||
|
|
<text class="table-td">包装编号</text>
|
|||
|
|
<text class="table-td">预制工作包</text>
|
|||
|
|
<text class="table-td td-operate" v-if="isEdit">操作</text>
|
|||
|
|
</view>
|
|||
|
|
<view v-for="(item, index) in BZList" :key="index" class="table-tr">
|
|||
|
|
<text class="table-td">{{ item.PackagingCode }}</text>
|
|||
|
|
<text class="table-td">{{ item.StackingPosition || '--' }}</text>
|
|||
|
|
<text class="table-td td-operate" v-if="isEdit" @click="handleDeletePackage(item)">
|
|||
|
|
<u-icon name="trash" :size="20" color="#fa3534"></u-icon>
|
|||
|
|
</text>
|
|||
|
|
</view>
|
|||
|
|
<view v-if="BZList.length === 0" class="table-empty">
|
|||
|
|
<u-empty text="暂无数据" mode="list"></u-empty>
|
|||
|
|
</view>
|
|||
|
|
</view>
|
|||
|
|
</view>
|
|||
|
|
</view>
|
|||
|
|
|
|||
|
|
<!-- 底部按钮 -->
|
|||
|
|
<view class="bottom-btns" v-if="isEdit">
|
|||
|
|
<u-button size="medium" type="primary" :disabled="disabledBtn" @click="handleSave(0)">保存</u-button>
|
|||
|
|
<u-button size="medium" type="success" :disabled="disabledBtn" @click="handleSave(1)">发货</u-button>
|
|||
|
|
</view>
|
|||
|
|
<view class="bottom-btns" v-if="form.State === 1">
|
|||
|
|
<u-button size="medium" type="warning" :disabled="disabledBtn" @click="handleSign">签收</u-button>
|
|||
|
|
</view>
|
|||
|
|
|
|||
|
|
<!-- 单位选择弹窗 -->
|
|||
|
|
<nbd-select v-model="showUnitSelect" v-model:model="selectedUnit" :show-search="true" title="选择单位"
|
|||
|
|
:list="unitList" label-key="UnitName" value-key="UnitId" @confirm="handleUnitConfirm" />
|
|||
|
|
</view>
|
|||
|
|
</template>
|
|||
|
|
|
|||
|
|
<script setup>
|
|||
|
|
import { ref, computed } from 'vue'
|
|||
|
|
import { onLoad, onShow } from '@dcloudio/uni-app'
|
|||
|
|
import { useUserStore } from '@/store'
|
|||
|
|
import { storeToRefs } from 'pinia'
|
|||
|
|
import { reqUnitByProjectIdUnitType } from '@/api/base'
|
|||
|
|
import { reqTrainNumberById, reqSaveTrainNumber, reqSignTrainNumber, reqDeletePackagingFromTrain, reqPackagingListByTrain } from '@/api/hj'
|
|||
|
|
|
|||
|
|
// 是否编辑状态
|
|||
|
|
const isEdit = computed(() => !form.value.State || form.value.State === 0)
|
|||
|
|
|
|||
|
|
const userStore = useUserStore()
|
|||
|
|
const { currentProject } = storeToRefs(userStore)
|
|||
|
|
|
|||
|
|
// ===== 页面状态 =====
|
|||
|
|
const trainNumberId = ref('')
|
|||
|
|
const disabledBtn = ref(false)
|
|||
|
|
|
|||
|
|
// ===== 表单数据 =====
|
|||
|
|
const form = ref({
|
|||
|
|
TrainNumberId: '',
|
|||
|
|
TrainNumber: '',
|
|||
|
|
UnitId: '',
|
|||
|
|
UnitName: '',
|
|||
|
|
DriverName: '',
|
|||
|
|
DriverPhone: '',
|
|||
|
|
LicensePlateNumber: '',
|
|||
|
|
ContactName: '',
|
|||
|
|
ContactPhone: '',
|
|||
|
|
Remark: '',
|
|||
|
|
State: 0,
|
|||
|
|
StateName: ''
|
|||
|
|
})
|
|||
|
|
|
|||
|
|
// ===== 单位选择 =====
|
|||
|
|
const showUnitSelect = ref(false)
|
|||
|
|
const unitList = ref([{ UnitId: '', UnitName: '全部单位' }])
|
|||
|
|
const selectedUnit = ref({ UnitId: '', UnitName: '全部单位' })
|
|||
|
|
|
|||
|
|
// ===== 包装列表 =====
|
|||
|
|
const BZList = ref([])
|
|||
|
|
|
|||
|
|
// ===== 获取单位列表 =====
|
|||
|
|
const getUnitList = async () => {
|
|||
|
|
try {
|
|||
|
|
const res = await reqUnitByProjectIdUnitType(currentProject.value?.ProjectId || '')
|
|||
|
|
unitList.value = [{ UnitId: '', UnitName: '全部单位' }, ...(res.data || [])]
|
|||
|
|
} catch (error) {
|
|||
|
|
console.error('获取单位列表失败:', error)
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// ===== 显示单位选择 =====
|
|||
|
|
const handleShowUnit = () => {
|
|||
|
|
if (form.value.UnitId) {
|
|||
|
|
selectedUnit.value = {
|
|||
|
|
UnitId: form.value.UnitId,
|
|||
|
|
UnitName: form.value.UnitName
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
showUnitSelect.value = true
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// ===== 单位选择确认 =====
|
|||
|
|
const handleUnitConfirm = (item) => {
|
|||
|
|
form.value.UnitId = item.UnitId
|
|||
|
|
form.value.UnitName = item.UnitName
|
|||
|
|
selectedUnit.value = item
|
|||
|
|
showUnitSelect.value = false
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// ===== 获取车次详情 =====
|
|||
|
|
const getTrainNumberDetail = async () => {
|
|||
|
|
if (!trainNumberId.value) return
|
|||
|
|
|
|||
|
|
try {
|
|||
|
|
const res = await reqTrainNumberById(trainNumberId.value)
|
|||
|
|
if (res.data) {
|
|||
|
|
form.value = { ...form.value, ...res.data }
|
|||
|
|
selectedUnit.value = {
|
|||
|
|
UnitId: res.data.UnitId,
|
|||
|
|
UnitName: res.data.UnitName
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
// 获取包装列表
|
|||
|
|
getPackagingList()
|
|||
|
|
} catch (error) {
|
|||
|
|
console.error('获取车次详情失败:', error)
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// ===== 获取包装列表 =====
|
|||
|
|
const getPackagingList = async () => {
|
|||
|
|
if (!trainNumberId.value) return
|
|||
|
|
|
|||
|
|
try {
|
|||
|
|
const res = await reqPackagingListByTrain(trainNumberId.value)
|
|||
|
|
BZList.value = res.data || []
|
|||
|
|
} catch (error) {
|
|||
|
|
console.error('获取包装列表失败:', error)
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// ===== 删除包装 =====
|
|||
|
|
const handleDeletePackage = async (item) => {
|
|||
|
|
try {
|
|||
|
|
await reqDeletePackagingFromTrain({
|
|||
|
|
trainNumberId: trainNumberId.value,
|
|||
|
|
packagingManageId: item.PackagingManageId || item.PackagingId
|
|||
|
|
})
|
|||
|
|
uni.showToast({
|
|||
|
|
title: '删除成功',
|
|||
|
|
icon: 'success'
|
|||
|
|
})
|
|||
|
|
getPackagingList()
|
|||
|
|
} catch (error) {
|
|||
|
|
console.error('删除包装失败:', error)
|
|||
|
|
uni.showToast({
|
|||
|
|
title: '删除失败',
|
|||
|
|
icon: 'none'
|
|||
|
|
})
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// ===== 扫码 =====
|
|||
|
|
const handleScan = () => {
|
|||
|
|
// #ifdef MP-WEIXIN
|
|||
|
|
wx.scanCode({
|
|||
|
|
success: (res) => {
|
|||
|
|
console.log('扫码结果:', res)
|
|||
|
|
uni.showToast({
|
|||
|
|
title: '扫码成功',
|
|||
|
|
icon: 'success'
|
|||
|
|
})
|
|||
|
|
// TODO: 根据扫码结果处理
|
|||
|
|
},
|
|||
|
|
fail: (err) => {
|
|||
|
|
console.error('扫码失败:', err)
|
|||
|
|
uni.showToast({
|
|||
|
|
title: '扫码失败',
|
|||
|
|
icon: 'none'
|
|||
|
|
})
|
|||
|
|
}
|
|||
|
|
})
|
|||
|
|
// #endif
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// ===== 保存/发货 =====
|
|||
|
|
const handleSave = async (state) => {
|
|||
|
|
// 验证必填项
|
|||
|
|
if (!form.value.TrainNumber) {
|
|||
|
|
uni.showToast({ title: '请输入车次', icon: 'none' })
|
|||
|
|
return
|
|||
|
|
}
|
|||
|
|
if (!form.value.UnitId) {
|
|||
|
|
uni.showToast({ title: '请选择单位', icon: 'none' })
|
|||
|
|
return
|
|||
|
|
}
|
|||
|
|
if (!form.value.DriverName) {
|
|||
|
|
uni.showToast({ title: '请输入驾驶员姓名', icon: 'none' })
|
|||
|
|
return
|
|||
|
|
}
|
|||
|
|
if (!form.value.DriverPhone) {
|
|||
|
|
uni.showToast({ title: '请输入驾驶员电话', icon: 'none' })
|
|||
|
|
return
|
|||
|
|
}
|
|||
|
|
if (!form.value.LicensePlateNumber) {
|
|||
|
|
uni.showToast({ title: '请输入车牌号', icon: 'none' })
|
|||
|
|
return
|
|||
|
|
}
|
|||
|
|
if (!form.value.ContactName) {
|
|||
|
|
uni.showToast({ title: '请输入联系人姓名', icon: 'none' })
|
|||
|
|
return
|
|||
|
|
}
|
|||
|
|
if (!form.value.ContactPhone) {
|
|||
|
|
uni.showToast({ title: '请输入联系人电话', icon: 'none' })
|
|||
|
|
return
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
disabledBtn.value = true
|
|||
|
|
|
|||
|
|
try {
|
|||
|
|
const res = await reqSaveTrainNumber({
|
|||
|
|
trainNumberId: trainNumberId.value || '',
|
|||
|
|
projectId: currentProject.value?.ProjectId || '',
|
|||
|
|
unitId: form.value.UnitId,
|
|||
|
|
trainNumber: form.value.TrainNumber,
|
|||
|
|
driverName: form.value.DriverName,
|
|||
|
|
driverPhone: form.value.DriverPhone,
|
|||
|
|
licensePlateNumber: form.value.LicensePlateNumber,
|
|||
|
|
contactName: form.value.ContactName,
|
|||
|
|
contactPhone: form.value.ContactPhone,
|
|||
|
|
remark: form.value.Remark,
|
|||
|
|
state: state
|
|||
|
|
})
|
|||
|
|
|
|||
|
|
if (res.code === 1 || res.data) {
|
|||
|
|
uni.showToast({
|
|||
|
|
title: state === 1 ? '发货成功' : '保存成功',
|
|||
|
|
icon: 'success'
|
|||
|
|
})
|
|||
|
|
|
|||
|
|
setTimeout(() => {
|
|||
|
|
const newId = res.data?.trainNumberId || trainNumberId.value
|
|||
|
|
uni.redirectTo({
|
|||
|
|
url: `/pipe/deliver/add?id=${newId}&from=1`
|
|||
|
|
})
|
|||
|
|
}, 1500)
|
|||
|
|
}
|
|||
|
|
} catch (error) {
|
|||
|
|
console.error('保存失败:', error)
|
|||
|
|
uni.showToast({
|
|||
|
|
title: '保存失败,请重试',
|
|||
|
|
icon: 'none'
|
|||
|
|
})
|
|||
|
|
} finally {
|
|||
|
|
disabledBtn.value = false
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// ===== 签收 =====
|
|||
|
|
const handleSign = async () => {
|
|||
|
|
disabledBtn.value = true
|
|||
|
|
|
|||
|
|
try {
|
|||
|
|
const res = await reqSignTrainNumber({
|
|||
|
|
trainNumberId: trainNumberId.value,
|
|||
|
|
personId: currentProject.value?.PersonId || ''
|
|||
|
|
})
|
|||
|
|
|
|||
|
|
if (res.code === 1) {
|
|||
|
|
uni.showToast({
|
|||
|
|
title: '签收成功',
|
|||
|
|
icon: 'success'
|
|||
|
|
})
|
|||
|
|
|
|||
|
|
setTimeout(() => {
|
|||
|
|
uni.navigateBack()
|
|||
|
|
}, 1500)
|
|||
|
|
}
|
|||
|
|
} catch (error) {
|
|||
|
|
console.error('签收失败:', error)
|
|||
|
|
uni.showToast({
|
|||
|
|
title: '签收失败,请重试',
|
|||
|
|
icon: 'none'
|
|||
|
|
})
|
|||
|
|
} finally {
|
|||
|
|
disabledBtn.value = false
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// ===== 生命周期 =====
|
|||
|
|
onLoad((options) => {
|
|||
|
|
if (options.id) {
|
|||
|
|
trainNumberId.value = options.id
|
|||
|
|
}
|
|||
|
|
})
|
|||
|
|
|
|||
|
|
onShow(() => {
|
|||
|
|
getUnitList()
|
|||
|
|
if (trainNumberId.value) {
|
|||
|
|
getTrainNumberDetail()
|
|||
|
|
}
|
|||
|
|
})
|
|||
|
|
</script>
|