hookehuyr

feat(车辆): 添加价格输入校验并优化认证车接口

添加价格输入校验逻辑,限制只能输入数字和小数点
将我的认证车页面接口从getVehicleListAPI更换为getMyListingVehicleAPI
发布成功后跳转至首页而非返回上一页
1 /* 1 /*
2 * @Date: 2025-07-09 14:58:51 2 * @Date: 2025-07-09 14:58:51
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2025-07-11 10:18:35 4 + * @LastEditTime: 2025-07-15 11:55:43
5 * @FilePath: /jgdl/src/api/car.js 5 * @FilePath: /jgdl/src/api/car.js
6 * @Description: 车辆相关API接口 6 * @Description: 车辆相关API接口
7 */ 7 */
...@@ -93,7 +93,7 @@ export const getRecommendVehicleAPI = (params) => fn(fetch.get(Api.RECOMMEND_VEH ...@@ -93,7 +93,7 @@ export const getRecommendVehicleAPI = (params) => fn(fetch.get(Api.RECOMMEND_VEH
93 export const getVehicleListAPI = (params) => fn(fetch.get(Api.LIST_VEHICLE, params)); 93 export const getVehicleListAPI = (params) => fn(fetch.get(Api.LIST_VEHICLE, params));
94 94
95 /** 95 /**
96 - * @description: 获取我卖的车 96 + * @description: 获取我卖的车/我的认证
97 * @param page 页码 97 * @param page 页码
98 * @param limit 每页数量 98 * @param limit 每页数量
99 * @returns data[{ id, seller_id, school_id, school_name, title, brand, model, manufacture_year, new_level, range_km, total_mileage_km, max_speed_kmh, battery_capacity_ah, brake_wear_level, tire_wear_level, price, market_price, verification_status, rejection_reason, note, photos, is_favorite }] 99 * @returns data[{ id, seller_id, school_id, school_name, title, brand, model, manufacture_year, new_level, range_km, total_mileage_km, max_speed_kmh, battery_capacity_ah, brake_wear_level, tire_wear_level, price, market_price, verification_status, rejection_reason, note, photos, is_favorite }]
......
1 <!-- 1 <!--
2 * @Date: 2022-09-19 14:11:06 2 * @Date: 2022-09-19 14:11:06
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2025-07-11 17:14:08 4 + * @LastEditTime: 2025-07-15 11:56:17
5 * @FilePath: /jgdl/src/pages/myAuthCar/index.vue 5 * @FilePath: /jgdl/src/pages/myAuthCar/index.vue
6 * @Description: 我的认证车页面 6 * @Description: 我的认证车页面
7 --> 7 -->
...@@ -88,7 +88,7 @@ import { ref, computed, onMounted } from 'vue' ...@@ -88,7 +88,7 @@ import { ref, computed, onMounted } from 'vue'
88 import Taro from '@tarojs/taro' 88 import Taro from '@tarojs/taro'
89 import './index.less' 89 import './index.less'
90 // 导入接口 90 // 导入接口
91 -import { getVehicleListAPI } from '@/api/car' 91 +import { getMyListingVehicleAPI } from '@/api/car'
92 import { DEFAULT_COVER_IMG } from '@/utils/config' 92 import { DEFAULT_COVER_IMG } from '@/utils/config'
93 93
94 // ==================== API相关 ==================== 94 // ==================== API相关 ====================
...@@ -126,7 +126,7 @@ const scrollStyle = computed(() => { ...@@ -126,7 +126,7 @@ const scrollStyle = computed(() => {
126 const initData = async () => { 126 const initData = async () => {
127 loading.value = true 127 loading.value = true
128 try { 128 try {
129 - const response = await getVehicleListAPI({ 129 + const response = await getMyListingVehicleAPI({
130 verification_status: 5, // 已认证状态 130 verification_status: 5, // 已认证状态
131 page: 0, 131 page: 0,
132 limit: pageSize.value 132 limit: pageSize.value
...@@ -157,7 +157,7 @@ const loadMore = async () => { ...@@ -157,7 +157,7 @@ const loadMore = async () => {
157 loading.value = true 157 loading.value = true
158 try { 158 try {
159 const nextPage = currentPage.value + 1 159 const nextPage = currentPage.value + 1
160 - const response = await getVehicleListAPI({ 160 + const response = await getMyListingVehicleAPI({
161 verification_status: 5, // 已认证状态 161 verification_status: 5, // 已认证状态
162 page: nextPage, 162 page: nextPage,
163 limit: pageSize.value 163 limit: pageSize.value
......
...@@ -219,7 +219,7 @@ ...@@ -219,7 +219,7 @@
219 </view> 219 </view>
220 <view class="form-item-right"> 220 <view class="form-item-right">
221 <text class="price-symbol">¥</text> 221 <text class="price-symbol">¥</text>
222 - <input v-model="formData.price" placeholder="请输入" type="digit" class="price-input" /> 222 + <input v-model="formData.price" placeholder="请输入" type="digit" class="price-input" @onInput="validatePriceInput" />
223 </view> 223 </view>
224 </view> 224 </view>
225 225
...@@ -231,7 +231,7 @@ ...@@ -231,7 +231,7 @@
231 <view class="form-item-right"> 231 <view class="form-item-right">
232 <text class="market-price-symbol">¥</text> 232 <text class="market-price-symbol">¥</text>
233 <input v-model="formData.market_price" placeholder="请输入" type="digit" 233 <input v-model="formData.market_price" placeholder="请输入" type="digit"
234 - class="market-price-input" /> 234 + class="market-price-input" @onInput="validateMarketPriceInput" />
235 </view> 235 </view>
236 </view> 236 </view>
237 </view> 237 </view>
...@@ -605,6 +605,42 @@ const showTireWearPicker = () => { ...@@ -605,6 +605,42 @@ const showTireWearPicker = () => {
605 } 605 }
606 606
607 /** 607 /**
608 + * 校验价格输入,只允许数字和小数点
609 + * @param {Object} event - 输入事件对象
610 + */
611 +const validatePriceInput = (event) => {
612 + const value = event.detail.value
613 + const validValue = value.replace(/[^0-9.]/g, '')
614 +
615 + // 防止多个小数点
616 + const parts = validValue.split('.')
617 + if (parts.length > 2) {
618 + const newValue = parts[0] + '.' + parts.slice(1).join('')
619 + formData.price = newValue
620 + } else {
621 + formData.price = validValue
622 + }
623 +}
624 +
625 +/**
626 + * 校验市场价格输入,只允许数字和小数点
627 + * @param {Object} event - 输入事件对象
628 + */
629 +const validateMarketPriceInput = (event) => {
630 + const value = event.detail.value
631 + const validValue = value.replace(/[^0-9.]/g, '')
632 +
633 + // 防止多个小数点
634 + const parts = validValue.split('.')
635 + if (parts.length > 2) {
636 + const newValue = parts[0] + '.' + parts.slice(1).join('')
637 + formData.market_price = newValue
638 + } else {
639 + formData.market_price = validValue
640 + }
641 +}
642 +
643 +/**
608 * 学校选择确认 644 * 学校选择确认
609 */ 645 */
610 const onSchoolConfirm = ({ selectedValue, selectedOptions }) => { 646 const onSchoolConfirm = ({ selectedValue, selectedOptions }) => {
...@@ -759,11 +795,11 @@ const createCar = async (data) => { ...@@ -759,11 +795,11 @@ const createCar = async (data) => {
759 Taro.showToast({ 795 Taro.showToast({
760 title: '发布成功', 796 title: '发布成功',
761 icon: 'success', 797 icon: 'success',
762 - duration: 2000, 798 + duration: 2000
763 - complete: () => {
764 - Taro.navigateBack()
765 - }
766 }) 799 })
800 + setTimeout(() => {
801 + Taro.reLaunch({ url: '/pages/index/index' })
802 + }, 1000);
767 } 803 }
768 } 804 }
769 805
...@@ -799,8 +835,6 @@ const onPublish = async () => { ...@@ -799,8 +835,6 @@ const onPublish = async () => {
799 tire_wear_level: convertTextToScore(formData.tire_wear_level, 'wear') 835 tire_wear_level: convertTextToScore(formData.tire_wear_level, 'wear')
800 } 836 }
801 837
802 - console.warn(submitData);
803 -
804 if (isEditMode.value) { 838 if (isEditMode.value) {
805 submitData.id = carId.value 839 submitData.id = carId.value
806 } 840 }
...@@ -814,6 +848,18 @@ const onPublish = async () => { ...@@ -814,6 +848,18 @@ const onPublish = async () => {
814 } 848 }
815 849
816 /** 850 /**
851 + * 价格格式校验
852 + * @param {string} price 价格字符串
853 + * @returns {boolean} 是否为有效的价格格式
854 + */
855 +const isValidPrice = (price) => {
856 + if (!price || price.trim() === '') return false
857 + // 正则表达式:匹配数字和小数点,允许小数
858 + const priceRegex = /^\d+(\.\d+)?$/
859 + return priceRegex.test(price.toString().trim())
860 +}
861 +
862 +/**
817 * 表单验证 863 * 表单验证
818 * @returns {boolean} 验证结果 864 * @returns {boolean} 验证结果
819 */ 865 */
...@@ -842,11 +888,23 @@ const validateForm = () => { ...@@ -842,11 +888,23 @@ const validateForm = () => {
842 return false 888 return false
843 } 889 }
844 890
891 + // 校验出让价格(必填)
845 if (!formData.price) { 892 if (!formData.price) {
846 Taro.showToast({ title: '请输入出让价格', icon: 'none' }) 893 Taro.showToast({ title: '请输入出让价格', icon: 'none' })
847 return false 894 return false
848 } 895 }
849 896
897 + if (!isValidPrice(formData.price)) {
898 + Taro.showToast({ title: '出让价格格式不正确,请输入有效数字', icon: 'none' })
899 + return false
900 + }
901 +
902 + // 校验市场价格(选填,但如果填写了必须格式正确)
903 + if (formData.market_price && !isValidPrice(formData.market_price)) {
904 + Taro.showToast({ title: '市场价格格式不正确,请输入有效数字', icon: 'none' })
905 + return false
906 + }
907 +
850 return true 908 return true
851 } 909 }
852 910
......