You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
408 lines
11 KiB
408 lines
11 KiB
<template>
|
|
<view class="add">
|
|
<view class="add-bd">
|
|
<view class="item" v-if="info.id">
|
|
<view class="l">编号:</view>
|
|
<view class="r">
|
|
<input type="text" v-model="info.number" />
|
|
</view>
|
|
</view>
|
|
<view class="item" v-if="type == 3 || type == 4">
|
|
<view class="l">数量:</view>
|
|
<view class="r">
|
|
<input type="number" v-model="info.count" />
|
|
</view>
|
|
</view>
|
|
<view class="item" v-else>
|
|
<view class="l">性别:</view>
|
|
<view class="r">
|
|
<picker mode="selector" :range="sexList" :value="sexIndex" @change="bindDateChange">
|
|
{{sexIndex>= 0?sexList[sexIndex]:""}}
|
|
<image class="arrow" src="@/static/jiantouxia@2x.png"></image>
|
|
</picker>
|
|
</view>
|
|
</view>
|
|
<view class="item">
|
|
<view class="l">生日:</view>
|
|
<view class="r">
|
|
<picker mode="date" :value="info.birthday" :end="endDate" @change="bindDateChange1">
|
|
{{info.birthday?info.birthday:""}}
|
|
<image class="date" src="@/static/rili@2x.png"></image>
|
|
</picker>
|
|
</view>
|
|
</view>
|
|
<view class="item">
|
|
<view class="l">父亲:</view>
|
|
<view class="r">
|
|
<picker mode="selector" :range="fatherList" :value="fatherIndex" @change="bindDateChange4" range-key="number">
|
|
{{fatherIndex >=0 ? fatherList[fatherIndex].number:""}}
|
|
<image class="arrow" src="@/static/jiantouxia@2x.png"></image>
|
|
</picker>
|
|
</view>
|
|
</view>
|
|
<view class="item">
|
|
<view class="l">母亲:</view>
|
|
<view class="r">
|
|
<picker mode="selector" :range="motherList" :value="motherIndex" @change="bindDateChange5" range-key="number">
|
|
{{motherIndex >=0 ? motherList[motherIndex].number:""}}
|
|
<image class="arrow" src="@/static/jiantouxia@2x.png"></image>
|
|
</picker>
|
|
</view>
|
|
</view>
|
|
<view class="item">
|
|
<view class="l">品系:</view>
|
|
<view class="r">
|
|
<picker mode="selector" :range="strainsList" :value="strainsIndex" @change="bindDateChange2" range-key="title">
|
|
{{strainsIndex >= 0?strainsList[strainsIndex].title:""}}
|
|
<image class="arrow" src="@/static/jiantouxia@2x.png"></image>
|
|
</picker>
|
|
</view>
|
|
</view>
|
|
<view class="item">
|
|
<view class="l">基因:</view>
|
|
<view class="r">
|
|
<picker mode="selector" :range="geneList" :value="geneIndex" @change="bindDateChange3" range-key="title">
|
|
{{geneIndex >=0 ? geneList[geneIndex].title:""}}
|
|
<image class="arrow" src="@/static/jiantouxia@2x.png"></image>
|
|
</picker>
|
|
</view>
|
|
</view>
|
|
<view class="item" v-if="type == 1 || type == 2">
|
|
<view class="l">毛色:</view>
|
|
<view class="r">
|
|
<input type="text" v-model="info.hair_color" />
|
|
<image class="arrow" src="@/static/jiantouxia@2x.png"></image>
|
|
</view>
|
|
</view>
|
|
<view class="item">
|
|
<view class="l">备注:</view>
|
|
<view class="r">
|
|
<input type="text" v-model="info.remark" />
|
|
</view>
|
|
</view>
|
|
</view>
|
|
<view class="add-fd">
|
|
<view class="btn" @click="toCreate">完成</view>
|
|
</view>
|
|
</view>
|
|
</template>
|
|
|
|
<script>
|
|
export default {
|
|
data() {
|
|
return {
|
|
type: 4,
|
|
endDate: new Date().getFullYear()+"-"+((new Date().getMonth()+1)>10?new Date().getMonth()+1:"0"+(new Date().getMonth()+1))+"-"+((new Date().getDate())>10?new Date().getDate():"0"+(new Date().getDate())),
|
|
sexIndex: -1,
|
|
sexList: ['公','母'],
|
|
strainsList: [],
|
|
strainsIndex: -1,
|
|
geneList: [],
|
|
geneIndex: -1,
|
|
fatherList: [],
|
|
fatherIndex: -1,
|
|
motherList: [],
|
|
motherIndex: -1,
|
|
info: {},
|
|
id: "",
|
|
cid: "",
|
|
};
|
|
},
|
|
onLoad(o) {
|
|
this.cid = o.cid;
|
|
this.type = o.type;
|
|
this.id = o.id;
|
|
uni.setNavigationBarTitle({
|
|
title: o.type == 1?"新增小鼠":o.type == 2?"编辑小鼠":o.type == 3?"添加新生小鼠":"编辑新生小鼠"
|
|
})
|
|
if(this.cid){
|
|
this.get_api_squirrel_detail();
|
|
}
|
|
this.get_api_basicinfo_gene();
|
|
this.get_api_basicinfo_strains();
|
|
this.get_api_squirrel_getparents();
|
|
},
|
|
methods: {
|
|
async toCreate() {
|
|
if(this.type == 1 || this.type == 2){
|
|
if(this.sexIndex == -1){
|
|
uni.showToast({
|
|
title: "请选择性别",
|
|
icon: "none"
|
|
})
|
|
return ;
|
|
}
|
|
}else{
|
|
if(!this.info.count){
|
|
uni.showToast({
|
|
title: "数量不能为空",
|
|
icon: "none"
|
|
})
|
|
return ;
|
|
}
|
|
}
|
|
if(!this.info.birthday){
|
|
uni.showToast({
|
|
title: "请选择生日",
|
|
icon: "none"
|
|
})
|
|
return ;
|
|
}
|
|
if(this.fatherIndex == -1){
|
|
uni.showToast({
|
|
title: "请选择父亲",
|
|
icon: "none"
|
|
})
|
|
return ;
|
|
}
|
|
if(this.motherIndex == -1){
|
|
uni.showToast({
|
|
title: "请选择母亲",
|
|
icon: "none"
|
|
})
|
|
return ;
|
|
}
|
|
if(this.strainsIndex == -1){
|
|
uni.showToast({
|
|
title: "请选择品系",
|
|
icon: "none"
|
|
})
|
|
return ;
|
|
}
|
|
if(this.geneIndex == -1){
|
|
uni.showToast({
|
|
title: "请选择基因",
|
|
icon: "none"
|
|
})
|
|
return ;
|
|
}
|
|
if(this.type != 3){
|
|
if(!this.info.hair_color){
|
|
uni.showToast({
|
|
title: "请输入毛色",
|
|
icon: "none"
|
|
})
|
|
return ;
|
|
}
|
|
}
|
|
const { errorcode, message } = this.type == 1? await this.$api.api_squirrel_add({
|
|
sex: this.info.sex,
|
|
birthday: this.info.birthday,
|
|
strains_id: this.info.strains_id,
|
|
father: this.info.father,
|
|
mother: this.info.mother,
|
|
gene: this.info.gene,
|
|
hair_color: this.info.hair_color,
|
|
cage: this.id,
|
|
remark: this.info.remark?this.info.remark:'',
|
|
type: this.type,
|
|
uid: uni.getStorageSync("userInfo").uid,
|
|
}): this.type == 2? await this.$api.api_squirrel_edit({
|
|
id: this.info.id,
|
|
sex: this.info.sex,
|
|
birthday: this.info.birthday,
|
|
strains_id: this.info.strains_id,
|
|
father: this.info.father,
|
|
mother: this.info.mother,
|
|
gene: this.info.gene,
|
|
hair_color: this.info.hair_color,
|
|
cage: this.id,
|
|
remark: this.info.remark?this.info.remark:'',
|
|
uid: uni.getStorageSync("userInfo").uid,
|
|
}): await this.$api.api_squirrel_addNewSquirrel({
|
|
count: this.info.count,
|
|
birthday: this.info.birthday,
|
|
strains: this.info.strains_id,
|
|
father: this.info.father,
|
|
mother: this.info.mother,
|
|
gene: this.info.gene,
|
|
cage: this.id,
|
|
remark: this.info.remark?this.info.remark:'',
|
|
uid: uni.getStorageSync("userInfo").uid,
|
|
})
|
|
if( errorcode == 200 ){
|
|
uni.showToast({
|
|
title: this.type == 1?"新增成功":'修改成功'
|
|
})
|
|
setTimeout(()=>{
|
|
uni.navigateBack({
|
|
delta: 1
|
|
})
|
|
},2000)
|
|
}else{
|
|
uni.showToast({
|
|
icon: "none",
|
|
title: message
|
|
})
|
|
}
|
|
},
|
|
async get_api_squirrel_detail() {
|
|
const { errorcode, data } = await this.$api.api_squirrel_detail({id: this.cid});
|
|
if(errorcode == 200){
|
|
this.info = data
|
|
this.info.strains_id = data.strains
|
|
this.sexIndex = data.sex
|
|
this.info.sex = data.sex == 0?"公":"母"
|
|
}
|
|
},
|
|
async get_api_squirrel_getparents() {
|
|
const { errorcode, data } = await this.$api.api_squirrel_getparents({sex: ""});
|
|
if(errorcode == 200){
|
|
if(data && data.length> 0){
|
|
this.fatherList = data.filter(a=>a.sex == 1)
|
|
this.motherList = data.filter(a=>a.sex == 2)
|
|
if(this.type == 0){
|
|
let fatherIndex = 0, motherIndex = 0, father = this.info.father, mother = this.info.mother;
|
|
if(this.fatherList && this.fatherList.length >0){
|
|
this.fatherList.map((a,idx)=>{
|
|
if(a.number == father){
|
|
fatherIndex = idx
|
|
}
|
|
})
|
|
}
|
|
if(this.motherList && this.motherList.length >0){
|
|
this.motherList.map((a,idx)=>{
|
|
if(a.number == mother){
|
|
motherIndex = idx
|
|
}
|
|
})
|
|
}
|
|
this.fatherIndex= fatherIndex;
|
|
this.motherIndex = motherIndex
|
|
}
|
|
}
|
|
}
|
|
},
|
|
async get_api_basicinfo_strains() {
|
|
const { errorcode, data } = await this.$api.api_basicinfo_strains({});
|
|
if(errorcode == 200){
|
|
this.strainsList = data;
|
|
if(this.type == 0){
|
|
let strainsIndex = 0,strains = this.info.strains;
|
|
if(this.strainsList && this.strainsList.length >0){
|
|
this.strainsList.map((a,idx)=>{
|
|
if(a.title == strains){
|
|
strainsIndex = idx
|
|
}
|
|
})
|
|
this.strainsIndex = strainsIndex
|
|
}
|
|
}
|
|
}
|
|
},
|
|
async get_api_basicinfo_gene() {
|
|
const { errorcode, data } = await this.$api.api_basicinfo_gene({});
|
|
if(errorcode == 200){
|
|
this.geneList = data;
|
|
if(this.type == 0){
|
|
let geneIndex = 0,gene = this.info.gene;
|
|
if(this.geneList && this.geneList.length >0){
|
|
this.geneList.map((a,idx)=>{
|
|
if(a.title == gene){
|
|
geneIndex = idx
|
|
}
|
|
})
|
|
this.geneIndex = geneIndex
|
|
}
|
|
}
|
|
}
|
|
|
|
},
|
|
bindDateChange(e){
|
|
this.sexIndex = e.detail.value;
|
|
this.info.sex = Number(e.detail.value)+1
|
|
},
|
|
bindDateChange1(e){
|
|
this.info.birthday = e.detail.value
|
|
this.$forceUpdate();
|
|
},
|
|
bindDateChange2(e){
|
|
this.strainsIndex = e.detail.value
|
|
this.info.strains_id = this.strainsList[e.detail.value].title
|
|
},
|
|
bindDateChange3(e){
|
|
this.geneIndex = e.detail.value
|
|
this.info.gene = this.geneList[e.detail.value].title
|
|
},
|
|
bindDateChange4(e){
|
|
this.fatherIndex = e.detail.value
|
|
this.info.father = this.fatherList[e.detail.value].number
|
|
},
|
|
bindDateChange5(e){
|
|
this.motherIndex = e.detail.value
|
|
this.info.mother = this.motherList[e.detail.value].number
|
|
},
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style lang="scss" scoped>
|
|
.add{
|
|
padding-bottom: calc(env(safe-area-inset-bottom)+140rpx);
|
|
overflow: hidden;
|
|
&-bd{
|
|
padding: 0 35rpx;
|
|
overflow: hidden;
|
|
.item{
|
|
width: 100%;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
padding: 40rpx 0;
|
|
border-bottom: 1px solid #c0c2c2;
|
|
.l{
|
|
width: 100rpx;
|
|
font-size: 28rpx;
|
|
color: #000;
|
|
}
|
|
.r{
|
|
flex: 1;
|
|
display: flex;
|
|
align-items: center;
|
|
input,picker{
|
|
flex: 1;
|
|
font-size: 28rpx;
|
|
color: #000;
|
|
height: 50rpx;
|
|
line-height: 50rpx;
|
|
text-align: right;
|
|
}
|
|
.arrow{
|
|
width: 32rpx;
|
|
height: 19rpx;
|
|
margin-left: 20rpx;
|
|
vertical-align: middle;
|
|
}
|
|
|
|
.date{
|
|
width: 45rpx;
|
|
height: 45rpx;
|
|
margin-left: 20rpx;
|
|
vertical-align: middle;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
&-fd{
|
|
width: 100%;
|
|
padding: 20rpx 35rpx;
|
|
box-sizing: border-box;
|
|
background-color: #f3f5f6;
|
|
position: fixed;
|
|
left: 0;
|
|
bottom: 0;
|
|
z-index: 22;
|
|
padding-bottom: constant(safe-area-inset-bottom); /* 兼容 iOS < 11.2 */
|
|
padding-bottom: env(safe-area-inset-bottom); /* 兼容 iOS >= 11.2 */
|
|
.btn{
|
|
width: 100%;
|
|
line-height: 90rpx;
|
|
text-align: center;
|
|
background-color: #009944;
|
|
font-size: 32rpx;
|
|
color: #ffffff;
|
|
border-radius: 10rpx;
|
|
}
|
|
}
|
|
}
|
|
</style>
|
|
|