front/src/views/h5/customer-center/components/H5PickupOrderSheet.vue
zzh 33f696bc42
All checks were successful
Build and Deploy Front / deploy (push) Successful in 7m24s
feat: 抽取 PublishDiff 公共组件,完善发布/订单/渠道与多模块体验
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-13 23:34:54 +08:00

366 lines
9.8 KiB
Vue

<template>
<a-drawer
:visible="visible"
placement="bottom"
height="auto"
:footer="false"
:header="false"
unmount-on-close
:mask-closable="!submitting"
:drawer-style="drawerStyle"
popup-container="body"
class="h5-pk-create-drawer"
@cancel="close"
>
<div class="h5-pkc">
<div class="h5-pkc__handle" aria-hidden="true" />
<header class="h5-pkc__head">
<h3>{{ t('h5.pickupCreate.title') }}</h3>
<button type="button" class="h5-pkc__close" :disabled="submitting" @click="close">
<icon-close />
</button>
</header>
<a-spin :loading="loading" class="h5-pkc__body">
<label class="h5-pkc__label">{{ t('h5.journey.ship.pickSender') }}</label>
<a-select
v-model="form.senderAddressId"
allow-clear
:placeholder="t('h5.placeOrder.senderPh')"
>
<a-option v-for="s in senders" :key="s.id" :value="s.id">
{{ s.senderName }} · {{ s.phone }}
</a-option>
</a-select>
<label class="h5-pkc__label">{{ t('h5.journey.ship.warehouse') }}</label>
<a-select v-model="form.warehouseId" allow-clear>
<a-option v-for="w in warehouses" :key="w.id" :value="w.id">{{ w.name }}</a-option>
</a-select>
<label class="h5-pkc__label">{{ t('h5.journey.ship.product') }}</label>
<a-select v-model="form.productCode" allow-search allow-clear>
<a-option v-for="p in products" :key="p.value" :value="p.value">{{ p.label }}</a-option>
</a-select>
<label class="h5-pkc__label">{{ t('h5.journey.ship.cargoName') }}</label>
<a-input v-model="form.cargoName" allow-clear />
<label class="h5-pkc__label">{{ t('h5.journey.ship.weight') }}</label>
<a-input v-model="form.actualWeight" allow-clear />
<label class="h5-pkc__label">{{ t('h5.journey.ship.pickupTime') }}</label>
<a-input
v-model="form.pickupTime"
allow-clear
:placeholder="t('h5.journey.ship.pickupTimePh')"
/>
<button
type="button"
class="h5-pkc__submit"
:disabled="submitting"
@click="submit"
>
<span v-if="submitting" class="h5-pkc__loading" aria-hidden="true" />
{{
submitting
? t('h5.placeOrder.submitting')
: t('h5.journey.ship.createPickup')
}}
</button>
</a-spin>
</div>
</a-drawer>
</template>
<script lang="ts" setup>
import { reactive, ref, watch } from 'vue';
import { useI18n } from 'vue-i18n';
import { Message } from '@arco-design/web-vue';
import { IconClose } from '@arco-design/web-vue/es/icon';
import { getWarehouseList } from '@/api/system/warehouse';
import { getSalesProductList } from '@/api/channel/salesProduct';
import { getDictListAll } from '@/api/system/dict';
import { createPickupOrder, getSenderAddressList } from '@/api/order/senderAddress';
import { pickField } from '@/utils/warehouseListMapper';
import { isCustomerContactRequiredError } from '@/utils/customerContactGate';
defineOptions({ name: 'H5PickupOrderSheet' });
const props = defineProps<{ visible: boolean }>();
const emit = defineEmits<{
'update:visible': [boolean];
success: [];
}>();
const { t } = useI18n();
const loading = ref(false);
const submitting = ref(false);
const senders = ref<{ id: number; senderName: string; phone: string }[]>([]);
const warehouses = ref<{ id: number; name: string }[]>([]);
const products = ref<{ value: string; label: string }[]>([]);
const form = reactive({
senderAddressId: undefined as number | undefined,
warehouseId: undefined as number | undefined,
productCode: '',
cargoName: '',
actualWeight: '',
pickupTime: '',
});
const drawerStyle = {
borderRadius: '20px 20px 0 0',
overflow: 'hidden',
maxHeight: 'min(92vh, 780px)',
};
function close() {
if (submitting.value) return;
emit('update:visible', false);
}
function defaultPickupTime() {
const d = new Date();
d.setDate(d.getDate() + 1);
d.setHours(10, 0, 0, 0);
const p = (n: number) => String(n).padStart(2, '0');
return `${d.getFullYear()}-${p(d.getMonth() + 1)}-${p(d.getDate())} ${p(d.getHours())}:${p(d.getMinutes())}:00`;
}
function resetForm() {
form.senderAddressId = undefined;
form.warehouseId = undefined;
form.productCode = '';
form.cargoName = '';
form.actualWeight = '';
form.pickupTime = defaultPickupTime();
}
async function loadRefs() {
loading.value = true;
try {
const [senderRes, whRes, productRes, salesProductGroupDictRows] = await Promise.all([
getSenderAddressList({ page: 1, pageSize: 100, addressType: 'pickup' }),
getWarehouseList({ page: 1, pageSize: 100 }),
getSalesProductList({ page: 1, pageSize: 200, isActive: 2 }),
getDictListAll({ dictType: 'sales_product_group' }),
]);
senders.value = (senderRes.items || [])
.map((row: any) => {
const id = Number(pickField(row, 'id', 'Id'));
if (!Number.isFinite(id) || id <= 0) return null;
return {
id,
senderName: String(pickField(row, 'senderName', 'SenderName') || `#${id}`),
phone: String(pickField(row, 'phone', 'Phone') || '-'),
};
})
.filter(Boolean) as typeof senders.value;
warehouses.value = (whRes.items || [])
.map((row: any) => {
const id = Number(row?.id ?? row?.Id);
if (!Number.isFinite(id)) return null;
return {
id,
name: String(row?.warehouseName ?? row?.WarehouseName ?? id),
};
})
.filter(Boolean) as typeof warehouses.value;
const domesticPickupGroupCodes = new Set(
(salesProductGroupDictRows ?? [])
.filter((d: any) => String(d?.dictName ?? d?.DictName ?? '').includes('国内揽收'))
.map((d: any) => String(d?.dictCode ?? d?.DictCode ?? '').trim())
.filter((code: string) => Boolean(code)),
);
products.value = (productRes.items || [])
.filter((row: any) => {
const groupCode = String(row?.productGroup ?? row?.ProductGroup ?? '').trim();
return domesticPickupGroupCodes.size ? domesticPickupGroupCodes.has(groupCode) : true;
})
.map((row: any) => {
const code = String(row?.productCode ?? row?.ProductCode ?? '').trim();
const name = String(row?.productName ?? row?.ProductName ?? '').trim();
return code ? { value: code, label: name ? `${name} ${code}` : code } : null;
})
.filter(Boolean) as typeof products.value;
if (senders.value.length) form.senderAddressId = senders.value[0].id;
if (warehouses.value.length) form.warehouseId = warehouses.value[0].id;
if (!form.pickupTime) form.pickupTime = defaultPickupTime();
} finally {
loading.value = false;
}
}
async function submit() {
if (!form.senderAddressId) {
Message.warning(t('h5.journey.ship.pickSender'));
return;
}
if (!form.warehouseId) {
Message.warning(t('h5.journey.ship.pickWarehouse'));
return;
}
if (!form.productCode) {
Message.warning(t('h5.journey.ship.pickProduct'));
return;
}
if (!form.cargoName.trim()) {
Message.warning(t('h5.journey.ship.pickCargo'));
return;
}
const weight = Number(form.actualWeight);
if (!Number.isFinite(weight) || weight <= 0) {
Message.warning(t('h5.journey.ship.pickWeight'));
return;
}
submitting.value = true;
try {
await createPickupOrder({
senderAddressId: form.senderAddressId,
warehouseId: form.warehouseId,
productCode: form.productCode,
pickupTime: form.pickupTime || defaultPickupTime(),
cargoName: form.cargoName.trim(),
actualWeight: weight,
});
Message.success(t('h5.journey.ship.pickupOk'));
emit('success');
emit('update:visible', false);
} catch (e: any) {
if (isCustomerContactRequiredError(e)) {
Message.warning(t('h5.contact.requiredToast'));
} else {
Message.error(e?.message || t('h5.journey.ship.pickupFailed'));
}
} finally {
submitting.value = false;
}
}
watch(
() => props.visible,
(v) => {
if (!v) return;
resetForm();
void loadRefs();
},
);
</script>
<style lang="less">
.h5-pk-create-drawer {
.arco-drawer-content {
border-radius: 20px 20px 0 0;
overflow: hidden;
max-height: min(92vh, 780px);
}
}
</style>
<style lang="less" scoped>
.h5-pkc {
padding: 8px 16px calc(16px + env(safe-area-inset-bottom, 0px));
max-height: min(88vh, 740px);
overflow: auto;
-webkit-overflow-scrolling: touch;
}
.h5-pkc__handle {
width: 36px;
height: 4px;
margin: 4px auto 12px;
border-radius: 2px;
background: #e5e6eb;
}
.h5-pkc__head {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 12px;
h3 {
margin: 0;
font-size: 17px;
font-weight: 700;
color: #1d2129;
}
}
.h5-pkc__close {
width: 32px;
height: 32px;
border: none;
border-radius: 16px;
background: #f2f3f5;
color: #86909c;
display: inline-flex;
align-items: center;
justify-content: center;
cursor: pointer;
}
.h5-pkc__body {
display: block;
width: 100%;
}
.h5-pkc__label {
display: block;
margin: 12px 0 6px;
font-size: 13px;
font-weight: 600;
color: #4e5969;
&:first-child {
margin-top: 0;
}
}
.h5-pkc__submit {
width: 100%;
height: 44px;
margin-top: 20px;
border: none;
border-radius: 12px;
background: var(--app-primary-color);
color: #fff;
font-size: 15px;
font-weight: 600;
display: inline-flex;
align-items: center;
justify-content: center;
gap: 8px;
cursor: pointer;
&:disabled {
opacity: 0.7;
cursor: default;
}
}
.h5-pkc__loading {
width: 16px;
height: 16px;
border: 2px solid rgba(255, 255, 255, 0.35);
border-top-color: #fff;
border-radius: 50%;
animation: h5-pkc-spin 0.7s linear infinite;
}
@keyframes h5-pkc-spin {
to {
transform: rotate(360deg);
}
}
</style>