|
|
@@ -31,7 +31,7 @@
|
|
|
:rules="rules.variety" />
|
|
|
<van-field v-model="state.form.levelName" label="饲养区域" placeholder="请选择" readonly is-link required :rules="rules.levelName"
|
|
|
@click="showLevelPicker = true" />
|
|
|
- <van-field label="周龄" required :rules="rules.age">
|
|
|
+ <van-field label="周龄(w)" :rules="rules.age">
|
|
|
<template #input>
|
|
|
<div class="range-input-wrapper">
|
|
|
<van-field v-model="state.form.age.min" placeholder="请输入" type="digit" class="range-input" />
|
|
|
@@ -40,7 +40,7 @@
|
|
|
</div>
|
|
|
</template>
|
|
|
</van-field>
|
|
|
- <van-field label="体重" required :rules="rules.weight">
|
|
|
+ <van-field label="体重(g)" :rules="rules.weight">
|
|
|
<template #input>
|
|
|
<div class="range-input-wrapper">
|
|
|
<van-field v-model="state.form.weight.min" placeholder="请输入" type="number" class="range-input" />
|
|
|
@@ -254,19 +254,31 @@ const rules = {
|
|
|
age: [
|
|
|
{
|
|
|
validator: () => {
|
|
|
- const value = state.form.age
|
|
|
- console.log('周龄范围:', value)
|
|
|
- const min = Number(value?.min)
|
|
|
- const max = Number(value?.max)
|
|
|
- if (
|
|
|
- !value ||
|
|
|
- value.min === null ||
|
|
|
- value.min === '' ||
|
|
|
- value.max === null ||
|
|
|
- value.max === '' ||
|
|
|
- isNaN(min) ||
|
|
|
- isNaN(max)
|
|
|
- ) {
|
|
|
+ const age = state.form.age
|
|
|
+ const weight = state.form.weight
|
|
|
+ const ageMin = age?.min
|
|
|
+ const ageMax = age?.max
|
|
|
+ const weightMin = weight?.min
|
|
|
+ const weightMax = weight?.max
|
|
|
+ const hasAgeMin = ageMin !== null && ageMin !== ''
|
|
|
+ const hasAgeMax = ageMax !== null && ageMax !== ''
|
|
|
+ const hasWeightMin = weightMin !== null && weightMin !== ''
|
|
|
+ const hasWeightMax = weightMax !== null && weightMax !== ''
|
|
|
+ const isAgeFilled = hasAgeMin && hasAgeMax
|
|
|
+ const isWeightFilled = hasWeightMin && hasWeightMax
|
|
|
+ const hasAgeAny = hasAgeMin || hasAgeMax
|
|
|
+ if (!hasAgeAny && !isWeightFilled) {
|
|
|
+ return '周龄或体重至少填写一个'
|
|
|
+ }
|
|
|
+ if (hasAgeAny && !isAgeFilled) {
|
|
|
+ return '周龄范围不能为空'
|
|
|
+ }
|
|
|
+ if (!isAgeFilled) {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ const min = Number(ageMin)
|
|
|
+ const max = Number(ageMax)
|
|
|
+ if (isNaN(min) || isNaN(max)) {
|
|
|
return '周龄范围不能为空'
|
|
|
}
|
|
|
if (max === 0) {
|
|
|
@@ -282,19 +294,31 @@ const rules = {
|
|
|
weight: [
|
|
|
{
|
|
|
validator: () => {
|
|
|
- const value = state.form.weight
|
|
|
- console.log('体重范围:', value)
|
|
|
- const min = Number(value?.min)
|
|
|
- const max = Number(value?.max)
|
|
|
- if (
|
|
|
- !value ||
|
|
|
- value.min === null ||
|
|
|
- value.min === '' ||
|
|
|
- value.max === null ||
|
|
|
- value.max === '' ||
|
|
|
- isNaN(min) ||
|
|
|
- isNaN(max)
|
|
|
- ) {
|
|
|
+ const age = state.form.age
|
|
|
+ const weight = state.form.weight
|
|
|
+ const ageMin = age?.min
|
|
|
+ const ageMax = age?.max
|
|
|
+ const weightMin = weight?.min
|
|
|
+ const weightMax = weight?.max
|
|
|
+ const hasAgeMin = ageMin !== null && ageMin !== ''
|
|
|
+ const hasAgeMax = ageMax !== null && ageMax !== ''
|
|
|
+ const hasWeightMin = weightMin !== null && weightMin !== ''
|
|
|
+ const hasWeightMax = weightMax !== null && weightMax !== ''
|
|
|
+ const isAgeFilled = hasAgeMin && hasAgeMax
|
|
|
+ const isWeightFilled = hasWeightMin && hasWeightMax
|
|
|
+ const hasWeightAny = hasWeightMin || hasWeightMax
|
|
|
+ if (!hasWeightAny && !isAgeFilled) {
|
|
|
+ return '周龄或体重至少填写一个'
|
|
|
+ }
|
|
|
+ if (hasWeightAny && !isWeightFilled) {
|
|
|
+ return '体重范围不能为空'
|
|
|
+ }
|
|
|
+ if (!isWeightFilled) {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ const min = Number(weightMin)
|
|
|
+ const max = Number(weightMax)
|
|
|
+ if (isNaN(min) || isNaN(max)) {
|
|
|
return '体重范围不能为空'
|
|
|
}
|
|
|
if (max === 0) {
|