| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- <script setup>
- import { ref, computed } from 'vue'
- import { onLoad } from '@dcloudio/uni-app'
- import { getPlan, arrangeTransport, listVehicles, listPersonnel } from '@/api/pl'
- import { dash, planCardSub } from '@/utils/plLabels'
- import { PAGE_PATHS } from '@/config/api'
- const id = ref('')
- const detail = ref(null)
- const vehicles = ref([])
- const drivers = ref([])
- const vehicleIndex = ref(-1)
- const driverIndex = ref(-1)
- const freightTypeIndex = ref(0)
- const freightPrice = ref('')
- const freightAmount = ref('')
- const distanceKm = ref('')
- const acting = ref(false)
- const freightTypes = [
- { value: 'by_weight', label: '按重量' },
- { value: 'by_trip', label: '按趟次' }
- ]
- const vehicleLabels = computed(() =>
- vehicles.value.map((v) => v.licensePlate || v.plateNo || v.id)
- )
- const driverLabels = computed(() =>
- drivers.value.map((d) => `${d.personnelName || d.name || ''}${d.phoneNo ? ` ${d.phoneNo}` : ''}`)
- )
- const freightTypeLabels = computed(() => freightTypes.map((t) => t.label))
- const goBack = () => {
- uni.navigateBack({
- fail: () => uni.navigateTo({ url: `${PAGE_PATHS.plPlanDetail}?id=${id.value}` })
- })
- }
- const loadOptions = async () => {
- try {
- const [vRes, pRes] = await Promise.all([
- listVehicles({ page: 1, pageSize: 100, vehicleStatus: 'active' }),
- listPersonnel({ page: 1, pageSize: 100, personnelType: 'driver' })
- ])
- vehicles.value = vRes.rows || []
- drivers.value = pRes.rows || []
- // 若无 driver 类型,再拉全量人员
- if (!drivers.value.length) {
- const all = await listPersonnel({ page: 1, pageSize: 100 })
- drivers.value = all.rows || []
- }
- } catch (e) {
- uni.showToast({ title: e.message || '加载车辆/司机失败', icon: 'none' })
- }
- }
- const load = async () => {
- if (!id.value) return
- try {
- detail.value = await getPlan(id.value)
- await loadOptions()
- } catch (e) {
- uni.showToast({ title: e.message || '加载失败', icon: 'none' })
- }
- }
- const onVehicleChange = (e) => {
- vehicleIndex.value = Number(e.detail.value)
- }
- const onDriverChange = (e) => {
- driverIndex.value = Number(e.detail.value)
- }
- const onFreightTypeChange = (e) => {
- freightTypeIndex.value = Number(e.detail.value)
- }
- const submit = async () => {
- if (vehicleIndex.value < 0 || !vehicles.value[vehicleIndex.value]) {
- uni.showToast({ title: '请选择车辆', icon: 'none' })
- return
- }
- if (driverIndex.value < 0 || !drivers.value[driverIndex.value]) {
- uni.showToast({ title: '请选择司机', icon: 'none' })
- return
- }
- const vehicle = vehicles.value[vehicleIndex.value]
- const driver = drivers.value[driverIndex.value]
- const body = {
- vehicleId: String(vehicle.id),
- driverId: String(driver.id),
- carrierId: vehicle.carrierId || undefined,
- freightType: freightTypes[freightTypeIndex.value].value,
- pickupAddress: detail.value?.pickupAddress || undefined,
- destinationAddress: detail.value?.destinationAddress || undefined
- }
- if (freightPrice.value !== '') body.freightPrice = Number(freightPrice.value)
- if (freightAmount.value !== '') body.freightAmount = Number(freightAmount.value)
- if (distanceKm.value !== '') body.distanceKm = Number(distanceKm.value)
- acting.value = true
- try {
- await arrangeTransport(id.value, body)
- uni.showToast({ title: '已安排运输', icon: 'success' })
- setTimeout(() => {
- uni.redirectTo({ url: `${PAGE_PATHS.plPlanDetail}?id=${id.value}` })
- }, 500)
- } catch (e) {
- uni.showToast({ title: e.message || '安排失败', icon: 'none' })
- } finally {
- acting.value = false
- }
- }
- onLoad((q) => {
- id.value = q?.id || ''
- load()
- })
- </script>
- <template>
- <view class="mp-page mp-page--sub mp-page--with-bottom">
- <view class="mp-header mp-header--pl">
- <text class="mp-subpage-back" @click="goBack">← 返回</text>
- <text class="mp-header__title" style="margin-top: 16rpx">安排运输</text>
- <text v-if="detail" class="mp-header__meta">{{ dash(detail.planNo) }} · {{ planCardSub(detail) }}</text>
- </view>
- <view class="mp-block">
- <text class="mp-block__title">选择资源</text>
- <view class="mp-form">
- <view class="mp-form-item">
- <text class="mp-form-label">车辆</text>
- <picker :range="vehicleLabels" @change="onVehicleChange">
- <view class="mp-form-picker">
- {{ vehicleIndex >= 0 ? vehicleLabels[vehicleIndex] : '请选择车辆' }}
- </view>
- </picker>
- </view>
- <view class="mp-form-item">
- <text class="mp-form-label">司机</text>
- <picker :range="driverLabels" @change="onDriverChange">
- <view class="mp-form-picker">
- {{ driverIndex >= 0 ? driverLabels[driverIndex] : '请选择司机' }}
- </view>
- </picker>
- </view>
- <view class="mp-form-item">
- <text class="mp-form-label">运费方式</text>
- <picker :range="freightTypeLabels" :value="freightTypeIndex" @change="onFreightTypeChange">
- <view class="mp-form-picker">{{ freightTypeLabels[freightTypeIndex] }}</view>
- </picker>
- </view>
- <view class="mp-form-item">
- <text class="mp-form-label">运费单价</text>
- <input v-model="freightPrice" class="mp-form-input" type="digit" placeholder="可选" />
- </view>
- <view class="mp-form-item">
- <text class="mp-form-label">运费金额</text>
- <input v-model="freightAmount" class="mp-form-input" type="digit" placeholder="可选" />
- </view>
- <view class="mp-form-item">
- <text class="mp-form-label">公里数</text>
- <input v-model="distanceKm" class="mp-form-input" type="digit" placeholder="可选" />
- </view>
- </view>
- </view>
- <view class="mp-bottom-bar">
- <button class="mp-btn mp-btn--primary mp-btn--block" :disabled="acting" @click="submit">
- {{ acting ? '提交中…' : '确认安排' }}
- </button>
- </view>
- </view>
- </template>
|