feat: 创建订单时先选客户种类再选客户,默认顾客
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Agent
2026-03-29 05:35:01 +00:00
parent ac29a24199
commit f90152f010

View File

@@ -6,11 +6,25 @@
<text class="section-icon">👤</text> <text class="section-icon">👤</text>
<text class="section-title">客户信息</text> <text class="section-title">客户信息</text>
</view> </view>
<view class="form-item">
<text class="label">客户种类</text>
<picker
mode="selector"
:range="typeOptions"
range-key="label"
@change="selectType"
>
<view class="picker-value">
{{ selectedTypeLabel || '请选择客户种类' }}
<text class="arrow"></text>
</view>
</picker>
</view>
<view class="form-item"> <view class="form-item">
<text class="label">客户</text> <text class="label">客户</text>
<picker <picker
mode="selector" mode="selector"
:range="customers" :range="filteredCustomers"
range-key="name" range-key="name"
@change="selectCustomer" @change="selectCustomer"
> >
@@ -166,6 +180,15 @@ import customerApi from '@/api/customer'
export default { export default {
data() { data() {
return { return {
// 客户种类
typeOptions: [
{ label: '顾客', value: 'customer' },
{ label: '木匠', value: 'carpenter' },
{ label: '装修公司', value: 'company' }
],
selectedType: 'customer',
selectedTypeLabel: '顾客',
// 客户相关 // 客户相关
customers: [], customers: [],
selectedCustomer: null, selectedCustomer: null,
@@ -188,7 +211,8 @@ export default {
// 编辑模式 // 编辑模式
editingOrderId: null, editingOrderId: null,
tempCustomerId: null // 临时保存编辑时的客户ID tempCustomerId: null, // 临时保存编辑时的客户ID
tempCustomerType: null // 临时保存编辑时的客户种类
} }
}, },
onLoad(options) { onLoad(options) {
@@ -204,14 +228,20 @@ export default {
}, 500) }, 500)
} }
}, },
computed: {
filteredCustomers() {
return this.customers.filter(c => c.type === this.selectedType)
}
},
methods: { methods: {
async loadOrder(orderId) { async loadOrder(orderId) {
try { try {
const detail = await orderApi.getOrderDetail(orderId) const detail = await orderApi.getOrderDetail(orderId)
const order = detail.order const order = detail.order
// 先保存 customerId customers 加载完成后匹配 // 先保存 customerId客户列表加载完成后匹配
this.tempCustomerId = order.customerId this.tempCustomerId = order.customerId
this.tempCustomerType = order.customerType
this.orderItems = (detail.items || []).map(item => ({ this.orderItems = (detail.items || []).map(item => ({
productId: item.productId, productId: item.productId,
@@ -238,6 +268,13 @@ export default {
matchCustomer() { matchCustomer() {
if (this.tempCustomerId && this.customers.length > 0) { if (this.tempCustomerId && this.customers.length > 0) {
this.selectedCustomer = this.customers.find(c => c.customerId === this.tempCustomerId) this.selectedCustomer = this.customers.find(c => c.customerId === this.tempCustomerId)
if (this.tempCustomerType) {
this.selectedType = this.tempCustomerType
const typeOption = this.typeOptions.find(t => t.value === this.tempCustomerType)
if (typeOption) {
this.selectedTypeLabel = typeOption.label
}
}
} }
}, },
async loadCustomers() { async loadCustomers() {
@@ -259,7 +296,14 @@ export default {
} }
}, },
selectCustomer(e) { selectCustomer(e) {
this.selectedCustomer = this.customers[e.detail.value] this.selectedCustomer = this.filteredCustomers[e.detail.value]
},
selectType(e) {
const idx = e.detail.value
this.selectedType = this.typeOptions[idx].value
this.selectedTypeLabel = this.typeOptions[idx].label
// 切换种类后清除已选客户
this.selectedCustomer = null
}, },
goToSelectProduct() { goToSelectProduct() {
uni.navigateTo({ url: '/pages/product/select' }) uni.navigateTo({ url: '/pages/product/select' })