feat(表单): 添加品牌型号选择器组件并集成到销售表单
- 新增 BrandModelPicker 组件用于统一选择品牌和型号 - 替换原表单中分开的品牌和型号选择字段 - 添加表单验证逻辑和组合字段显示
Showing
3 changed files
with
61 additions
and
5 deletions
| ... | @@ -7,6 +7,7 @@ export {} | ... | @@ -7,6 +7,7 @@ export {} |
| 7 | 7 | ||
| 8 | declare module 'vue' { | 8 | declare module 'vue' { |
| 9 | export interface GlobalComponents { | 9 | export interface GlobalComponents { |
| 10 | + BrandModelPicker: typeof import('./src/components/BrandModelPicker.vue')['default'] | ||
| 10 | NavBar: typeof import('./src/components/navBar.vue')['default'] | 11 | NavBar: typeof import('./src/components/navBar.vue')['default'] |
| 11 | NutActionSheet: typeof import('@nutui/nutui-taro')['ActionSheet'] | 12 | NutActionSheet: typeof import('@nutui/nutui-taro')['ActionSheet'] |
| 12 | NutButton: typeof import('@nutui/nutui-taro')['Button'] | 13 | NutButton: typeof import('@nutui/nutui-taro')['Button'] | ... | ... |
src/components/BrandModelPicker.vue
0 → 100644
This diff is collapsed. Click to expand it.
| ... | @@ -103,20 +103,32 @@ | ... | @@ -103,20 +103,32 @@ |
| 103 | <!-- 车辆详情表单 --> | 103 | <!-- 车辆详情表单 --> |
| 104 | <nut-form ref="formRef" :model-value="formData"> | 104 | <nut-form ref="formRef" :model-value="formData"> |
| 105 | <view class="form-section"> | 105 | <view class="form-section"> |
| 106 | - <!-- 车型品牌 --> | 106 | + <!--<!~~ 车型品牌 ~~> |
| 107 | - <nut-form-item label-position="top" label="车型品牌" prop="brand" required :rules="[{ required: true, message: '请选择车型品牌' }]"> | 107 | + <nut-form-item label-position="top" label="车型品牌" prop="brand" required |
| 108 | + :rules="[{ required: true, message: '请选择车型品牌' }]"> | ||
| 108 | <view class="form-item-content" @click="showBrandPicker"> | 109 | <view class="form-item-content" @click="showBrandPicker"> |
| 109 | <text class="form-value">{{ formData.brand || '请选择' }}</text> | 110 | <text class="form-value">{{ formData.brand || '请选择' }}</text> |
| 110 | <Right class="arrow-icon" /> | 111 | <Right class="arrow-icon" /> |
| 111 | </view> | 112 | </view> |
| 112 | </nut-form-item> | 113 | </nut-form-item> |
| 113 | 114 | ||
| 114 | - <!-- 车辆型号 --> | 115 | + <!~~ 车辆型号 ~~> |
| 115 | <nut-form-item label-position="top" label="车辆型号" prop="model"> | 116 | <nut-form-item label-position="top" label="车辆型号" prop="model"> |
| 116 | <view class="form-item-content" @click="showModelPicker"> | 117 | <view class="form-item-content" @click="showModelPicker"> |
| 117 | <text class="form-value">{{ formData.model || '请选择' }}</text> | 118 | <text class="form-value">{{ formData.model || '请选择' }}</text> |
| 118 | <Right class="arrow-icon" /> | 119 | <Right class="arrow-icon" /> |
| 119 | </view> | 120 | </view> |
| 121 | + </nut-form-item>--> | ||
| 122 | + | ||
| 123 | + <!-- 品牌型号选择(新版) --> | ||
| 124 | + <nut-form-item label-position="top" label="品牌型号选择" prop="brandModel" required | ||
| 125 | + :rules="[{ required: true, message: '请选择品牌型号' }]"> | ||
| 126 | + <view class="form-item-content" @click="showBrandModelPicker"> | ||
| 127 | + <text class="form-value"> | ||
| 128 | + {{ formData.brand && formData.model ? `${formData.brand} ${formData.model}` : '请选择品牌型号' }} | ||
| 129 | + </text> | ||
| 130 | + <Right class="arrow-icon" /> | ||
| 131 | + </view> | ||
| 120 | </nut-form-item> | 132 | </nut-form-item> |
| 121 | 133 | ||
| 122 | <!-- 车辆出厂年份 --> | 134 | <!-- 车辆出厂年份 --> |
| ... | @@ -243,12 +255,14 @@ | ... | @@ -243,12 +255,14 @@ |
| 243 | </view> | 255 | </view> |
| 244 | 256 | ||
| 245 | <!-- 选择器弹窗 --> | 257 | <!-- 选择器弹窗 --> |
| 246 | - <!-- 学校选择 --> | 258 | + <!-- 学校选择器 --> |
| 247 | <nut-popup v-model:visible="schoolPickerVisible" position="bottom"> | 259 | <nut-popup v-model:visible="schoolPickerVisible" position="bottom"> |
| 248 | <nut-picker v-model="schoolValue" :columns="schoolOptions" title="选择学校" @confirm="onSchoolConfirm" | 260 | <nut-picker v-model="schoolValue" :columns="schoolOptions" title="选择学校" @confirm="onSchoolConfirm" |
| 249 | @cancel="schoolPickerVisible = false" /> | 261 | @cancel="schoolPickerVisible = false" /> |
| 250 | </nut-popup> | 262 | </nut-popup> |
| 251 | 263 | ||
| 264 | + <!-- TODO: 如果车型品牌选择其他,车辆型号选择其他型号,允许用户自己填写自定义的内容, 需要等待真实数据后再考虑 --> | ||
| 265 | + | ||
| 252 | <!-- 品牌选择 --> | 266 | <!-- 品牌选择 --> |
| 253 | <nut-popup v-model:visible="brandPickerVisible" position="bottom"> | 267 | <nut-popup v-model:visible="brandPickerVisible" position="bottom"> |
| 254 | <nut-picker v-model="brandValue" :columns="brandOptions" title="选择车型品牌" @confirm="onBrandConfirm" | 268 | <nut-picker v-model="brandValue" :columns="brandOptions" title="选择车型品牌" @confirm="onBrandConfirm" |
| ... | @@ -261,6 +275,9 @@ | ... | @@ -261,6 +275,9 @@ |
| 261 | @cancel="modelPickerVisible = false" /> | 275 | @cancel="modelPickerVisible = false" /> |
| 262 | </nut-popup> | 276 | </nut-popup> |
| 263 | 277 | ||
| 278 | + <!-- 品牌型号选择器组件 --> | ||
| 279 | + <BrandModelPicker ref="brandModelPickerRef" @confirm="onBrandModelConfirm" @cancel="onBrandModelCancel" /> | ||
| 280 | + | ||
| 264 | <!-- 年份选择 --> | 281 | <!-- 年份选择 --> |
| 265 | <nut-popup v-model:visible="yearPickerVisible" position="bottom"> | 282 | <nut-popup v-model:visible="yearPickerVisible" position="bottom"> |
| 266 | <nut-picker v-model="yearValue" :columns="yearOptions" title="选择出厂年份" @confirm="onYearConfirm" | 283 | <nut-picker v-model="yearValue" :columns="yearOptions" title="选择出厂年份" @confirm="onYearConfirm" |
| ... | @@ -298,6 +315,7 @@ import { ref, reactive, onMounted } from 'vue' | ... | @@ -298,6 +315,7 @@ import { ref, reactive, onMounted } from 'vue' |
| 298 | import { Plus, Right, Location, Close, RectLeft } from '@nutui/icons-vue-taro' | 315 | import { Plus, Right, Location, Close, RectLeft } from '@nutui/icons-vue-taro' |
| 299 | import Taro from '@tarojs/taro' | 316 | import Taro from '@tarojs/taro' |
| 300 | import BASE_URL from '@/utils/config'; | 317 | import BASE_URL from '@/utils/config'; |
| 318 | +import BrandModelPicker from '@/components/BrandModelPicker.vue' | ||
| 301 | import './index.less' | 319 | import './index.less' |
| 302 | 320 | ||
| 303 | const themeVars = ref({ | 321 | const themeVars = ref({ |
| ... | @@ -350,6 +368,7 @@ const formData = reactive({ | ... | @@ -350,6 +368,7 @@ const formData = reactive({ |
| 350 | school: '', | 368 | school: '', |
| 351 | brand: '', | 369 | brand: '', |
| 352 | model: '', | 370 | model: '', |
| 371 | + brandModel: '', // 品牌型号组合字段,用于表单验证 | ||
| 353 | year: '', | 372 | year: '', |
| 354 | condition: '', | 373 | condition: '', |
| 355 | mileage: '1200', | 374 | mileage: '1200', |
| ... | @@ -374,6 +393,10 @@ const batteryWearPickerVisible = ref(false) | ... | @@ -374,6 +393,10 @@ const batteryWearPickerVisible = ref(false) |
| 374 | const brakeWearPickerVisible = ref(false) | 393 | const brakeWearPickerVisible = ref(false) |
| 375 | const tireWearPickerVisible = ref(false) | 394 | const tireWearPickerVisible = ref(false) |
| 376 | 395 | ||
| 396 | +// 新的品牌型号选择器状态 | ||
| 397 | +// 品牌型号选择器组件引用 | ||
| 398 | +const brandModelPickerRef = ref(null) | ||
| 399 | + | ||
| 377 | // 选择器值 | 400 | // 选择器值 |
| 378 | const schoolValue = ref([]) | 401 | const schoolValue = ref([]) |
| 379 | const brandValue = ref([]) | 402 | const brandValue = ref([]) |
| ... | @@ -444,6 +467,8 @@ const wearLevelOptions = ref([ | ... | @@ -444,6 +467,8 @@ const wearLevelOptions = ref([ |
| 444 | { text: '需要更换', value: '需要更换' } | 467 | { text: '需要更换', value: '需要更换' } |
| 445 | ]) | 468 | ]) |
| 446 | 469 | ||
| 470 | +// 品牌型号数据已移至 BrandModelPicker 组件中 | ||
| 471 | + | ||
| 447 | 472 | ||
| 448 | 473 | ||
| 449 | /** | 474 | /** |
| ... | @@ -508,7 +533,7 @@ const uploadImage = (filePath, type) => { | ... | @@ -508,7 +533,7 @@ const uploadImage = (filePath, type) => { |
| 508 | } | 533 | } |
| 509 | }); | 534 | }); |
| 510 | }, | 535 | }, |
| 511 | - fail: function (res) { | 536 | + fail: function () { |
| 512 | Taro.hideLoading({ | 537 | Taro.hideLoading({ |
| 513 | success: () => { | 538 | success: () => { |
| 514 | Taro.showToast({ | 539 | Taro.showToast({ |
| ... | @@ -682,6 +707,36 @@ const onTireWearConfirm = ({ selectedValue }) => { | ... | @@ -682,6 +707,36 @@ const onTireWearConfirm = ({ selectedValue }) => { |
| 682 | } | 707 | } |
| 683 | 708 | ||
| 684 | /** | 709 | /** |
| 710 | + * 显示品牌型号选择器 | ||
| 711 | + */ | ||
| 712 | +const showBrandModelPicker = () => { | ||
| 713 | + brandModelPickerRef.value?.show() | ||
| 714 | +} | ||
| 715 | + | ||
| 716 | +/** | ||
| 717 | + * 品牌型号选择确认回调 | ||
| 718 | + */ | ||
| 719 | +const onBrandModelConfirm = (result) => { | ||
| 720 | + formData.brand = result.brand | ||
| 721 | + formData.model = result.model | ||
| 722 | + // 设置组合字段用于表单验证 | ||
| 723 | + formData.brandModel = `${result.brand} ${result.model}` | ||
| 724 | + | ||
| 725 | + Taro.showToast({ | ||
| 726 | + title: `已选择 ${result.brand} ${result.model}`, | ||
| 727 | + icon: 'success', | ||
| 728 | + duration: 2000 | ||
| 729 | + }) | ||
| 730 | +} | ||
| 731 | + | ||
| 732 | +/** | ||
| 733 | + * 品牌型号选择取消回调 | ||
| 734 | + */ | ||
| 735 | +const onBrandModelCancel = () => { | ||
| 736 | + // 可以在这里处理取消逻辑 | ||
| 737 | +} | ||
| 738 | + | ||
| 739 | +/** | ||
| 685 | * 发布/保存车辆 | 740 | * 发布/保存车辆 |
| 686 | */ | 741 | */ |
| 687 | const onPublish = () => { | 742 | const onPublish = () => { | ... | ... |
-
Please register or login to post a comment