|
@@ -48,13 +48,13 @@
|
|
|
<span>{{ props.row.weight }}千克</span>
|
|
|
</el-form-item>
|
|
|
<el-form-item label="品种">
|
|
|
- <span>{{ props.row.variety }}</span>
|
|
|
+ <span>{{ props.row.breed }}</span>
|
|
|
</el-form-item>
|
|
|
<el-form-item label="去向">
|
|
|
<span>{{ props.row.whereDidYouGo }}</span>
|
|
|
</el-form-item>
|
|
|
<el-form-item label="所属单元">
|
|
|
- <span>{{ props.row.number }}</span>
|
|
|
+ <span>{{ props.row.unitNumber }}</span>
|
|
|
</el-form-item>
|
|
|
<el-form-item label="所属猪舍">
|
|
|
<span>{{ props.row.phNumber }}</span>
|
|
@@ -132,7 +132,7 @@
|
|
|
</el-option>
|
|
|
</el-select>
|
|
|
</el-form-item>
|
|
|
- <el-form-item label="单元序号">
|
|
|
+ <el-form-item label="单元编号">
|
|
|
<el-select v-model="form.unitId" placeholder="请选择所属单元" @change="getUnit">
|
|
|
<el-option
|
|
|
v-for="item in unSelectedList"
|
|
@@ -142,14 +142,44 @@
|
|
|
</el-option>
|
|
|
</el-select>
|
|
|
</el-form-item>
|
|
|
+ <el-form-item label="栏期编号">
|
|
|
+ <el-select v-model="form.periodId" placeholder="请选择所属栏期" @change="getPeriod">
|
|
|
+ <el-option
|
|
|
+ v-for="item in peSelectedList"
|
|
|
+ :key="item.id"
|
|
|
+ :label="item.number"
|
|
|
+ :value="item.id">
|
|
|
+ </el-option>
|
|
|
+ </el-select>
|
|
|
+ </el-form-item>
|
|
|
<el-form-item label="耳标">
|
|
|
<el-input v-model="form.eartag" placeholder="请输入耳标"></el-input>
|
|
|
</el-form-item>
|
|
|
+ <el-form-item label="性别">
|
|
|
+ <el-select v-model="form.sex" placeholder="请选择性别">
|
|
|
+ <el-option
|
|
|
+ v-for="item in sex"
|
|
|
+ :key="item.label"
|
|
|
+ :label="item.label"
|
|
|
+ :value="item.value">
|
|
|
+ </el-option>
|
|
|
+ </el-select>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="出生日期">
|
|
|
+ <el-date-picker
|
|
|
+ v-model="form.birthday"
|
|
|
+ type="date"
|
|
|
+ value-format="yyyy-MM-dd"
|
|
|
+ placeholder="请选择出生日期"
|
|
|
+ @change="changeBirth">
|
|
|
+ </el-date-picker>
|
|
|
+ </el-form-item>
|
|
|
<el-form-item label="年龄">
|
|
|
- <el-input v-model="form.dayAge" placeholder="请输入年龄(天)"></el-input>
|
|
|
+ <!-- <el-input v-model="form.dayAge" placeholder="请输入年龄(天)"></el-input> -->
|
|
|
+ <el-input-number v-model="form.dayAge" :step="1" :max="10000000000" :min="0" @change="changeDay"></el-input-number> 天
|
|
|
</el-form-item>
|
|
|
<el-form-item label="健康状况">
|
|
|
- <el-select v-model="form.healthStatus" placeholder="请输入健康状况">
|
|
|
+ <el-select v-model="form.healthStatus" placeholder="请选择健康状况">
|
|
|
<el-option
|
|
|
v-for="item in health"
|
|
|
:key="item.label"
|
|
@@ -159,10 +189,11 @@
|
|
|
</el-select>
|
|
|
</el-form-item>
|
|
|
<el-form-item label="体重">
|
|
|
- <el-input v-model="form.weight" placeholder="请输入体重(千克)"></el-input>
|
|
|
+ <el-input-number v-model="form.weight" :step="0.01" :max="1000000" :min="0"></el-input-number> 千克
|
|
|
+ <!-- <el-input v-model="form.weight" placeholder="请输入体重(千克)"></el-input> -->
|
|
|
</el-form-item>
|
|
|
<el-form-item label="品种">
|
|
|
- <el-input v-model="form.variety" placeholder="请输入品种"></el-input>
|
|
|
+ <el-input v-model="form.breed" placeholder="请输入品种"></el-input>
|
|
|
</el-form-item>
|
|
|
<el-form-item label="去向">
|
|
|
<el-input v-model="form.whereDidYouGo" placeholder="请输入去向"></el-input>
|
|
@@ -200,7 +231,9 @@ export default {
|
|
|
breed: '',
|
|
|
birthday: '',
|
|
|
sex: '',
|
|
|
- pigstyId: ''
|
|
|
+ pigstyId: '',
|
|
|
+ periodId: '',
|
|
|
+ pastureId: ''
|
|
|
},
|
|
|
pastureList: [], // 牧场list
|
|
|
pighouseList: [], // 猪舍list
|
|
@@ -270,6 +303,7 @@ export default {
|
|
|
url: this.$http.adornUrl('/management/period/findAll'),
|
|
|
method: 'post'
|
|
|
})
|
|
|
+ periodResult.data.all && (this.periodList = periodResult.data.all)
|
|
|
if (data && data.code === 0) {
|
|
|
this.dataList = data.page.list
|
|
|
this.totalPage = data.page.totalCount
|
|
@@ -277,13 +311,13 @@ export default {
|
|
|
this.dataList.forEach(item => {
|
|
|
for (let unit of this.unitList) {
|
|
|
if (item.unitId === unit.id) {
|
|
|
- item.number = unit.number
|
|
|
+ item.unitNumber = unit.number
|
|
|
item.pastureId = unit.pastureId
|
|
|
item.pigstyId = unit.pigstyId
|
|
|
break
|
|
|
}
|
|
|
}
|
|
|
- });
|
|
|
+ })
|
|
|
// 牧场对应
|
|
|
this.dataList.forEach(item => {
|
|
|
for (let pasture of this.pastureList) {
|
|
@@ -292,7 +326,7 @@ export default {
|
|
|
break
|
|
|
}
|
|
|
}
|
|
|
- });
|
|
|
+ })
|
|
|
// 猪舍对应
|
|
|
this.dataList.forEach(item => {
|
|
|
for (let pighouse of this.pighouseList) {
|
|
@@ -301,10 +335,20 @@ export default {
|
|
|
break
|
|
|
}
|
|
|
}
|
|
|
- });
|
|
|
+ })
|
|
|
+ // 栏期对应
|
|
|
+ this.dataList.forEach(item => {
|
|
|
+ for (let period of this.periodList) {
|
|
|
+ if (item.periodId === period.id) {
|
|
|
+ item.periodNumber = period.number
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
// 初始化时,选择后的与未选择的list相同
|
|
|
this.phSelectedList = this.pighouseList
|
|
|
this.unSelectedList = this.unitList
|
|
|
+ this.peSelectedList = this.periodList
|
|
|
} else {
|
|
|
this.dataList = []
|
|
|
this.totalPage = 0
|
|
@@ -323,7 +367,31 @@ export default {
|
|
|
this.pageIndex = val
|
|
|
this.getDataList()
|
|
|
},
|
|
|
- // 获取到了牧场 → 猪舍 + 单元处理
|
|
|
+ // 获取出生日期
|
|
|
+ changeBirth (val) {
|
|
|
+ let birth = new Date(val)
|
|
|
+ let now = new Date()
|
|
|
+ let days = now.getTime() - birth.getTime()
|
|
|
+ if (days < 0) {
|
|
|
+ this.$confirm(`出生日期有误`, '提示', {
|
|
|
+ confirmButtonText: '确定',
|
|
|
+ cancelButtonText: '取消',
|
|
|
+ type: 'warning'
|
|
|
+ }).then(() => {
|
|
|
+ console.log('还没出生呢...');
|
|
|
+ }).catch(() => {})
|
|
|
+ }
|
|
|
+ this.form.dayAge = parseInt(days / (1000 * 60 * 60 * 24))
|
|
|
+ },
|
|
|
+ // 获取dayAge
|
|
|
+ changeDay (val) {
|
|
|
+ let now = new Date()
|
|
|
+ let birth = new Date(now.setDate(now.getDate() - val))
|
|
|
+ let month = birth.getMonth() < 9? '0' + (birth.getMonth() + 1): (birth.getMonth() + 1)
|
|
|
+ let date = birth.getDate() < 10? '0' + birth.getDate(): birth.getDate()
|
|
|
+ this.form.birthday = `${birth.getFullYear()}-${month}-${date}`
|
|
|
+ },
|
|
|
+ // 获取到了牧场 → 猪舍 + 单元 + 栏期处理
|
|
|
getPasture (val) {
|
|
|
/** 关于猪舍 */
|
|
|
// → 限制猪舍
|
|
@@ -332,16 +400,10 @@ export default {
|
|
|
if (item.pastureId === val) {
|
|
|
this.phSelectedList.push(item)
|
|
|
}
|
|
|
- });
|
|
|
- // 如果已有选中的猪舍,且该猪舍不属于该牧场,则清空猪舍选择
|
|
|
- let i;
|
|
|
- for (i = 0; i < this.phSelectedList.length; i++) {
|
|
|
- let item = this.phSelectedList[i];
|
|
|
- if (item.id === this.form.pigstyId) {
|
|
|
- break
|
|
|
- }
|
|
|
- }
|
|
|
- if (i === this.phSelectedList.length) {
|
|
|
+ })
|
|
|
+ // 判断当前 猪舍 是否需要清除
|
|
|
+ let pigsty = this.pigstyByYid(this.form.pigstyId)
|
|
|
+ if (pigsty && pigsty.pastureId !== val) {
|
|
|
this.form.pigstyId = ''
|
|
|
}
|
|
|
/** 关于单元 */
|
|
@@ -352,34 +414,32 @@ export default {
|
|
|
this.unSelectedList.push(item)
|
|
|
}
|
|
|
});
|
|
|
- // 如果已有选中的单元,且该猪舍不属于该牧场,则清空单元选择
|
|
|
- let j;
|
|
|
- for (j = 0; j < this.unSelectedList.length; j++) {
|
|
|
- let item = this.unSelectedList[j];
|
|
|
- if (item.id === this.form.pastureId) {
|
|
|
- break
|
|
|
- }
|
|
|
- }
|
|
|
- if (j === this.unSelectedList.length) {
|
|
|
+ // 判断当前 单元 是否需要清除
|
|
|
+ let unit = this.UnitByIid(this.form.unitId)
|
|
|
+ if (unit && unit.pastureId !== val) {
|
|
|
this.form.unitId = ''
|
|
|
}
|
|
|
+ /** 关于栏期 */
|
|
|
+ // → 限制栏期
|
|
|
+ this.peSelectedList = []
|
|
|
+ this.periodList.forEach(item => {
|
|
|
+ if (item.pastureId === val) {
|
|
|
+ this.peSelectedList.push(item)
|
|
|
+ }
|
|
|
+ });
|
|
|
+ // 判断当前 栏期 是否需要清除
|
|
|
+ let period = this.periodByJid(this.form.periodId)
|
|
|
+ if (period && period.pastureId !== val) {
|
|
|
+ this.form.periodId = ''
|
|
|
+ }
|
|
|
},
|
|
|
- // 获取到猪舍 → 牧场 + 猪舍自身 + 单元处理
|
|
|
+ // 获取到猪舍 → 牧场 + 猪舍自身 + 单元 + 栏期处理
|
|
|
getPigsty (val) {
|
|
|
// → 反向确定牧场
|
|
|
- for (let item of this.pighouseList) {
|
|
|
- if (item.id === val) {
|
|
|
- this.form.pastureId = item.pastureId
|
|
|
- break
|
|
|
- }
|
|
|
- }
|
|
|
+ let pigsty = this.pigstyByYid(this.form.pigstyId)
|
|
|
+ this.form.pastureId = pigsty.pastureId
|
|
|
// → 先获取猪舍,没有确定牧场的情况下,限制猪舍自身
|
|
|
- this.phSelectedList = []
|
|
|
- this.pighouseList.forEach(item => {
|
|
|
- if (item.pastureId === this.form.pastureId) {
|
|
|
- this.phSelectedList.push(item)
|
|
|
- }
|
|
|
- });
|
|
|
+ this.phSelectedList = this.xidYlist(pigsty.pastureId)
|
|
|
/** 关于单元 */
|
|
|
// → 限制单元
|
|
|
this.unSelectedList = []
|
|
@@ -388,41 +448,113 @@ export default {
|
|
|
this.unSelectedList.push(item)
|
|
|
}
|
|
|
});
|
|
|
- // 如果已有选中的单元,且该猪舍不属于该牧场,则清空单元选择
|
|
|
- let j;
|
|
|
- for (j = 0; j < this.unSelectedList.length; j++) {
|
|
|
- let item = this.unSelectedList[j];
|
|
|
- if (item.id === this.form.pastureId) {
|
|
|
- break
|
|
|
- }
|
|
|
- }
|
|
|
- if (j === this.unSelectedList.length) {
|
|
|
+ // 判断当前 单元 是否需要清除
|
|
|
+ let unit = this.UnitByIid(this.form.unitId)
|
|
|
+ if (unit && unit.pigstyId !== val) {
|
|
|
this.form.unitId = ''
|
|
|
}
|
|
|
+ /** 关于栏期 */
|
|
|
+ // → 限制栏期
|
|
|
+ this.peSelectedList = []
|
|
|
+ this.periodList.forEach(item => {
|
|
|
+ if (item.pigstyId === val) {
|
|
|
+ this.peSelectedList.push(item)
|
|
|
+ }
|
|
|
+ });
|
|
|
+ // 判断当前 栏期 是否需要清除
|
|
|
+ let period = this.periodByJid(this.form.periodId)
|
|
|
+ if (period && period.pigstyId !== val) {
|
|
|
+ this.form.periodId = ''
|
|
|
+ }
|
|
|
},
|
|
|
// 获取到了单元 → 牧场 + 猪舍 + 单元自身处理
|
|
|
getUnit (val) {
|
|
|
- // → 反向确定牧场 + 牧场
|
|
|
- for (let item of this.unSelectedList) {
|
|
|
- if (item.id === val) {
|
|
|
- this.form.pastureId = item.pastureId
|
|
|
- this.form.pigstyId = item.pigstyId
|
|
|
- }
|
|
|
+ let unit = this.UnitByIid(val)
|
|
|
+ // 反向确定 牧场 + 猪舍
|
|
|
+ this.form.pastureId = unit.pastureId
|
|
|
+ this.form.pigstyId = unit.pigstyId
|
|
|
+ // 反向确定 猪舍selectedList + 单元selectedList + 栏期selectedList
|
|
|
+ this.phSelectedList = this.xidYlist(unit.pastureId)
|
|
|
+ this.unSelectedList = this.yidIlist (unit.pigstyId)
|
|
|
+ this.peSelectedList = this.yidJlist (unit.pigstyId)
|
|
|
+ // 判断当前栏期是否需要清除
|
|
|
+ let period = this.periodByJid(this.form.periodId)
|
|
|
+ if (period && period.pigstyId !== unit.pigstyId) {
|
|
|
+ this.form.periodId = ''
|
|
|
}
|
|
|
- // → 先获取单元,在没有确定牧场+猪舍的情况下,限制猪舍
|
|
|
- this.phSelectedList = []
|
|
|
+ },
|
|
|
+ // 根据牧场id → 限制猪舍selectedList
|
|
|
+ xidYlist (pastureId) {
|
|
|
+ let phSelectedList = []
|
|
|
this.pighouseList.forEach(item => {
|
|
|
- if (item.pastureId === this.form.pastureId) {
|
|
|
- this.phSelectedList.push(item)
|
|
|
+ if (item.pastureId === pastureId) {
|
|
|
+ phSelectedList.push(item)
|
|
|
}
|
|
|
- });
|
|
|
- // → 先获取单元,在没有确定牧场+猪舍的情况下,限制单元自身
|
|
|
- this.unSelectedList = []
|
|
|
+ })
|
|
|
+ return phSelectedList
|
|
|
+ },
|
|
|
+ // 根据猪舍id → 限制栏期selectedList
|
|
|
+ yidJlist (pigstyId) {
|
|
|
+ let peSelectedList = []
|
|
|
+ this.periodList.forEach(item => {
|
|
|
+ if (item.pigstyId === pigstyId) {
|
|
|
+ peSelectedList.push(item)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ return peSelectedList
|
|
|
+ },
|
|
|
+ // 根据猪舍id → 限制单元selectedList
|
|
|
+ yidIlist (pigstyId) {
|
|
|
+ let unSelectedList = []
|
|
|
this.unitList.forEach(item => {
|
|
|
- if (item.pigstyId === this.form.pigstyId) {
|
|
|
- this.unSelectedList.push(item)
|
|
|
+ if (item.pigstyId === pigstyId) {
|
|
|
+ unSelectedList.push(item)
|
|
|
}
|
|
|
- });
|
|
|
+ })
|
|
|
+ return unSelectedList
|
|
|
+ },
|
|
|
+ // 根据猪舍id → 返回猪舍信息
|
|
|
+ pigstyByYid (pigstyId) {
|
|
|
+ for (let item of this.pighouseList) {
|
|
|
+ if (item.id === pigstyId) {
|
|
|
+ return item
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null
|
|
|
+ },
|
|
|
+ // 根据栏期id → 返回栏期信息
|
|
|
+ periodByJid (periodId) {
|
|
|
+ for (let item of this.periodList) {
|
|
|
+ if (item.id === periodId) {
|
|
|
+ return item
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null
|
|
|
+ },
|
|
|
+ // 根据单元id → 返回单元信息
|
|
|
+ UnitByIid (unitId) {
|
|
|
+ for (let item of this.unitList) {
|
|
|
+ if (item.id === unitId) {
|
|
|
+ return item
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null
|
|
|
+ },
|
|
|
+ // 获取到栏期 → 牧场 + 猪舍 + 单元自身处理
|
|
|
+ getPeriod (val) {
|
|
|
+ let period = this.periodByJid(val)
|
|
|
+ // 反向确定牧场 + 猪舍
|
|
|
+ this.form.pastureId = period.pastureId
|
|
|
+ this.form.pigstyId = period.pigstyId
|
|
|
+ // 反向确定 猪舍selectedList + 单元selectedList + 栏期selectedList
|
|
|
+ this.phSelectedList = this.xidYlist(period.pastureId)
|
|
|
+ this.unSelectedList = this.yidIlist (period.pigstyId)
|
|
|
+ this.peSelectedList = this.yidJlist (period.pigstyId)
|
|
|
+ // 判断当前 单元 是否需要清除
|
|
|
+ let unit = this.UnitByIid(this.form.unitId)
|
|
|
+ if (unit && unit.pigstyId !== period.pigstyId) {
|
|
|
+ this.form.unitId = ''
|
|
|
+ }
|
|
|
},
|
|
|
// 新增 or 修改单元
|
|
|
addOrUpdateHandle (row) {
|
|
@@ -430,7 +562,6 @@ export default {
|
|
|
this.visible = true
|
|
|
if (row) {
|
|
|
this.form = row
|
|
|
- console.log(row);
|
|
|
}
|
|
|
},
|
|
|
// 选择n个牧场
|
|
@@ -477,96 +608,95 @@ export default {
|
|
|
formSubmit () {
|
|
|
if (this.form.id) {
|
|
|
// 修改
|
|
|
- if (this.confirmInput()) {
|
|
|
- // 进行修改操作
|
|
|
- this.$http({
|
|
|
- url: this.$http.adornUrl('/management/yearpigbase/update'),
|
|
|
- method: 'post',
|
|
|
- data: this.$http.adornData({
|
|
|
- id: this.form.id,
|
|
|
- unitId: this.form.unitId,
|
|
|
- dayAge: parseInt(this.form.dayAge),
|
|
|
- eartag: this.form.eartag,
|
|
|
- healthStatus: this.form.healthStatus,
|
|
|
- weight: parseInt(this.form.weight),
|
|
|
- whereDidYouGo: this.form.whereDidYouGo,
|
|
|
- variety: this.form.variety
|
|
|
- })
|
|
|
- }).then(result => {
|
|
|
- if (result.data.code === 0) {
|
|
|
- this.resetForm();
|
|
|
- this.visible = false;
|
|
|
- this.$message({
|
|
|
- message: '成功修改年猪信息',
|
|
|
- type: 'success',
|
|
|
- duration: 1000
|
|
|
- })
|
|
|
- } else {
|
|
|
- this.$message.error('修改年猪信息失败');
|
|
|
- }
|
|
|
- })
|
|
|
- } else {
|
|
|
- // 请输入完整
|
|
|
- this.$confirm(`请输入完整`, '提示', {
|
|
|
- confirmButtonText: '确定',
|
|
|
- cancelButtonText: '取消',
|
|
|
- type: 'warning'
|
|
|
- }).then(() => {
|
|
|
- return
|
|
|
- }).catch(() => {})
|
|
|
+ // 输入是否完整
|
|
|
+ if (!this.confirmComplete()) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 输入是否合法
|
|
|
+ if (!this.confirmInput()) {
|
|
|
+ return
|
|
|
}
|
|
|
+ // 进行修改操作
|
|
|
+ this.$http({
|
|
|
+ url: this.$http.adornUrl('/management/yearpigbase/update'),
|
|
|
+ method: 'post',
|
|
|
+ data: this.$http.adornData({
|
|
|
+ id: this.form.id,
|
|
|
+ unitId: this.form.unitId,
|
|
|
+ dayAge: parseInt(this.form.dayAge),
|
|
|
+ eartag: this.form.eartag,
|
|
|
+ healthStatus: this.form.healthStatus,
|
|
|
+ weight: parseFloat(this.form.weight),
|
|
|
+ whereDidYouGo: this.form.whereDidYouGo,
|
|
|
+ breed: this.form.breed,
|
|
|
+ pigstyId: this.form.phNumber,
|
|
|
+ birthday: this.form.birthday,
|
|
|
+ sex: this.form.sex,
|
|
|
+ periodId: this.form.periodId,
|
|
|
+ pigstyId: this.form.pigstyId
|
|
|
+ })
|
|
|
+ }).then(result => {
|
|
|
+ if (result.data.code === 0) {
|
|
|
+ this.resetForm();
|
|
|
+ console.log(result);
|
|
|
+ console.log(this.form);
|
|
|
+ this.visible = false;
|
|
|
+ this.$message({
|
|
|
+ message: '成功修改年猪信息',
|
|
|
+ type: 'success',
|
|
|
+ duration: 1000
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ this.$message.error('修改年猪信息失败');
|
|
|
+ }
|
|
|
+ })
|
|
|
} else {
|
|
|
// 新增
|
|
|
- if (this.confirmInput(1)) {
|
|
|
- // 进行新增操作
|
|
|
- console.log('进行新增操作');
|
|
|
- this.$http({
|
|
|
- url: this.$http.adornUrl('/management/yearpigbase/save'),
|
|
|
- method: 'post',
|
|
|
- data: this.$http.adornData({
|
|
|
- unitId: this.form.unitId,
|
|
|
- dayAge: parseInt(this.form.dayAge),
|
|
|
- eartag: this.form.eartag,
|
|
|
- healthStatus: this.form.healthStatus,
|
|
|
- weight: parseInt(this.form.weight),
|
|
|
- whereDidYouGo: this.form.whereDidYouGo,
|
|
|
- breed: this.form.variety,
|
|
|
- pigstyId: this.form.phNumber,
|
|
|
- birthday: this.form.birthday,
|
|
|
- sex: this.form.sex
|
|
|
- })
|
|
|
- }).then(result => {
|
|
|
- console.log(result);
|
|
|
- if (result.data.code === 0) {
|
|
|
- this.resetForm();
|
|
|
- this.visible = false;
|
|
|
- this.$message({
|
|
|
- message: '成功添加年猪',
|
|
|
- type: 'success',
|
|
|
- duration: 1000
|
|
|
- })
|
|
|
- } else {
|
|
|
- this.$message.error('添加年猪失败');
|
|
|
- }
|
|
|
- })
|
|
|
- } else {
|
|
|
- // 请输入完整
|
|
|
- this.$confirm(`请输入完整`, '提示', {
|
|
|
- confirmButtonText: '确定',
|
|
|
- cancelButtonText: '取消',
|
|
|
- type: 'warning'
|
|
|
- }).then(() => {
|
|
|
- return
|
|
|
- }).catch(() => {})
|
|
|
+ // 输入是否完整
|
|
|
+ if (!this.confirmComplete(1)) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 输入是否合法
|
|
|
+ if (!this.confirmInput()) {
|
|
|
+ return
|
|
|
}
|
|
|
+ // 进行新增操作
|
|
|
+ console.log('进行新增操作');
|
|
|
+ this.$http({
|
|
|
+ url: this.$http.adornUrl('/management/yearpigbase/save'),
|
|
|
+ method: 'post',
|
|
|
+ data: this.$http.adornData({
|
|
|
+ unitId: this.form.unitId,
|
|
|
+ dayAge: parseInt(this.form.dayAge),
|
|
|
+ eartag: this.form.eartag,
|
|
|
+ healthStatus: this.form.healthStatus,
|
|
|
+ weight: parseInt(this.form.weight),
|
|
|
+ whereDidYouGo: this.form.whereDidYouGo,
|
|
|
+ breed: this.form.breed,
|
|
|
+ pigstyId: this.form.phNumber,
|
|
|
+ birthday: this.form.birthday,
|
|
|
+ sex: this.form.sex,
|
|
|
+ periodId: this.form.periodId,
|
|
|
+ pigstyId: this.form.pigstyId
|
|
|
+ })
|
|
|
+ }).then(result => {
|
|
|
+ if (result.data.code === 0) {
|
|
|
+ this.resetForm()
|
|
|
+ this.visible = false;
|
|
|
+ this.$message({
|
|
|
+ message: '成功添加年猪',
|
|
|
+ type: 'success',
|
|
|
+ duration: 1000
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ this.$message.error('添加年猪失败');
|
|
|
+ }
|
|
|
+ })
|
|
|
}
|
|
|
},
|
|
|
- // 判断新增/修改时是否输入完整
|
|
|
- confirmInput (val) {
|
|
|
- console.log('判断是否输入完整');
|
|
|
- console.log(val);
|
|
|
- val && (delete this.form.id, delete this.form.deleted, delete this.form.fosterStatus, delete this.form.gmtCreate, delete this.form.gmtModified, delete this.form.name, delete this.form.number)
|
|
|
- console.log(this.form);
|
|
|
+ // 校验输入是否完整
|
|
|
+ validComplete (val) {
|
|
|
+ val && (delete this.form.id, delete this.form.deleted, delete this.form.fosterStatus, delete this.form.gmtCreate, delete this.form.gmtModified, delete this.form.periodNumber, delete this.form.phNumber, delete this.form.unitNumber, delete this.form.name)
|
|
|
for (let i in this.form) {
|
|
|
if (!this.form[i].toString()) {
|
|
|
return false
|
|
@@ -574,6 +704,59 @@ export default {
|
|
|
}
|
|
|
return true
|
|
|
},
|
|
|
+ // 如不完整,则提示
|
|
|
+ confirmComplete (val) {
|
|
|
+ if (this.validComplete(val)) {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ this.$confirm(`请输入完整`, '提示', {
|
|
|
+ confirmButtonText: '确定',
|
|
|
+ cancelButtonText: '取消',
|
|
|
+ type: 'warning'
|
|
|
+ }).then(() => {
|
|
|
+ console.log('输入不完整');
|
|
|
+ }).catch(() => {})
|
|
|
+ return false
|
|
|
+ },
|
|
|
+ // 校验输入是否合法
|
|
|
+ validInput () {
|
|
|
+ // 出生日期是否有误
|
|
|
+ let birth = new Date(this.form.birthday)
|
|
|
+ let now = new Date()
|
|
|
+ let days = now.getTime() - birth.getTime()
|
|
|
+ if (days < 0) {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ if (this.form.weight <= 0) {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ // 只允许中文、英文、数字、-、_的输入,取反
|
|
|
+ const reg = /[^\a-\z\A-\Z0-9\u4E00-\u9FA5\_\-]/g
|
|
|
+ if (reg.test(this.form.eartag)) {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ if (reg.test(this.form.breed)) {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ if (reg.test(this.form.whereDidYouGo)) {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ return true
|
|
|
+ },
|
|
|
+ // 如不合法,则提示
|
|
|
+ confirmInput () {
|
|
|
+ if (this.validInput()) {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ this.$confirm(`请检查输入项是否合法`, '提示', {
|
|
|
+ confirmButtonText: '确定',
|
|
|
+ cancelButtonText: '取消',
|
|
|
+ type: 'warning'
|
|
|
+ }).then(() => {
|
|
|
+ console.log('输入不合法');
|
|
|
+ }).catch(() => {})
|
|
|
+ return false
|
|
|
+ },
|
|
|
// 清空form
|
|
|
resetForm () {
|
|
|
for (let i in this.form) {
|