2023-12-20 18:13:01 +08:00
|
|
|
|
<template>
|
|
|
|
|
<view class="content">
|
|
|
|
|
|
|
|
|
|
<view class="cards">
|
|
|
|
|
<up-form labelWidth='130' :model="data.formData" ref="form1">
|
|
|
|
|
<view class="c-title">养殖信息</view>
|
|
|
|
|
<view class="c-box">
|
|
|
|
|
<up-form-item label="耳号" prop="title" borderBottom required>
|
|
|
|
|
<up-input input-align="right" placeholder="请输入耳号" border="none" v-model="data.formData.title"></up-input>
|
|
|
|
|
</up-form-item>
|
|
|
|
|
<up-form-item label="品类" prop="title" borderBottom required>
|
|
|
|
|
<up-input input-align="right" placeholder="请输入品类名称" border="none" v-model="data.formData.title"></up-input>
|
|
|
|
|
</up-form-item>
|
|
|
|
|
<up-form-item label="品种" prop="area" borderBottom required>
|
|
|
|
|
<up-input input-align="right" placeholder="请输入品种名称" border="none" v-model="data.formData.area"></up-input>
|
|
|
|
|
</up-form-item>
|
|
|
|
|
<up-form-item label="性别" prop="master_name" borderBottom required @click="showSex=true">
|
|
|
|
|
<up-input input-align="right" placeholder="请选择性别" border="none" suffixIcon="arrow-down"
|
|
|
|
|
suffix-icon-style="color: #b6b6b6;" v-model="data.formData.sex" readonly></up-input>
|
|
|
|
|
</up-form-item>
|
|
|
|
|
<up-form-item label="生理阶段" prop="master_phone" borderBottom required>
|
|
|
|
|
<up-input input-align="right" placeholder="请输入生理阶段" border="none"
|
|
|
|
|
v-model="data.formData.master_phone"></up-input>
|
|
|
|
|
</up-form-item>
|
|
|
|
|
<up-form-item label="血统纯度" prop="master_phone" borderBottom required>
|
|
|
|
|
<up-input input-align="right" placeholder="请输入血统纯度" border="none"
|
|
|
|
|
v-model="data.formData.master_phone"></up-input>
|
|
|
|
|
</up-form-item>
|
|
|
|
|
<block v-if="data.formData.type==1">
|
|
|
|
|
<up-form-item label="来源" borderBottom>
|
|
|
|
|
<up-input input-align="right" border="none" v-model="data.formData.type_name" readonly></up-input>
|
|
|
|
|
</up-form-item>
|
|
|
|
|
<up-form-item label="栏舍" prop="master_phone" borderBottom required>
|
|
|
|
|
<up-input input-align="right" placeholder="请输入栏舍" border="none"
|
|
|
|
|
v-model="data.formData.master_phone"></up-input>
|
|
|
|
|
</up-form-item>
|
|
|
|
|
<up-form-item label="现估重(kg)" prop="master_phone" borderBottom required>
|
|
|
|
|
<up-input input-align="right" placeholder="请输入现估重" type="number" border="none"
|
|
|
|
|
v-model="data.formData.master_phone"></up-input>
|
|
|
|
|
</up-form-item>
|
|
|
|
|
<up-form-item label="入场日期" prop="master_phone" borderBottom required @click="showDate=true">
|
|
|
|
|
<up-input input-align="right" placeholder="请选择入场日期" border="none" suffixIcon="arrow-down"
|
|
|
|
|
suffix-icon-style="color: #b6b6b6;" v-model="data.formData.join_date"></up-input>
|
|
|
|
|
</up-form-item>
|
|
|
|
|
</block>
|
|
|
|
|
<block v-else>
|
|
|
|
|
<up-form-item label="来源" borderBottom>
|
|
|
|
|
<up-input input-align="right" border="none" v-model="data.formData.type_name" readonly></up-input>
|
|
|
|
|
</up-form-item>
|
|
|
|
|
<up-form-item label="栏舍" prop="master_phone" borderBottom required>
|
|
|
|
|
<up-input input-align="right" placeholder="请输入栏舍" border="none"
|
|
|
|
|
v-model="data.formData.master_phone"></up-input>
|
|
|
|
|
</up-form-item>
|
|
|
|
|
<up-form-item label="代数" prop="" borderBottom required>
|
|
|
|
|
<up-input input-align="right" placeholder="请输入代数" type="number" border="none"
|
|
|
|
|
v-model="data.formData.master_phone"></up-input>
|
|
|
|
|
</up-form-item>
|
|
|
|
|
<up-form-item label="现估重(kg)" prop="master_phone" borderBottom required>
|
|
|
|
|
<up-input input-align="right" placeholder="请输入现估重" type="number" border="none"
|
|
|
|
|
v-model="data.formData.master_phone"></up-input>
|
|
|
|
|
</up-form-item>
|
|
|
|
|
<up-form-item label="出生体重(kg)" prop="master_phone" borderBottom required>
|
|
|
|
|
<up-input input-align="right" placeholder="请输入出生体重" type="number" border="none"
|
|
|
|
|
v-model="data.formData.master_phone"></up-input>
|
|
|
|
|
</up-form-item>
|
|
|
|
|
<up-form-item label="出生日期" borderBottom required @click="showDate=true">
|
|
|
|
|
<up-input input-align="right" placeholder="请选择出生日期" border="none" suffixIcon="arrow-down"
|
|
|
|
|
suffix-icon-style="color: #b6b6b6;" v-model="data.formData.brith_date"></up-input>
|
|
|
|
|
</up-form-item>
|
|
|
|
|
</block>
|
|
|
|
|
</view>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<view class="card-li">
|
2024-01-23 19:52:15 +08:00
|
|
|
|
<view class="c-title">养殖基地图片</view>
|
2023-12-20 18:13:01 +08:00
|
|
|
|
<view class="c-box c-box-p">
|
|
|
|
|
<view class="code-img1">
|
|
|
|
|
<view class="" v-if="pic.length>0"
|
|
|
|
|
style="display: flex;flex-direction: row;flex-wrap: wrap;margin-bottom: 30rpx;">
|
|
|
|
|
<view class="" v-for="(item,i) in pic" style="margin-right: 30rpx;">
|
|
|
|
|
<view class="">
|
|
|
|
|
<u-icon name="close" size="15" style="margin-left:120.85rpx;" @click="delimg(i)"></u-icon>
|
|
|
|
|
<u-image :src="item" width="150.85rpx" height="150.85rpx"></u-image>
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
|
|
|
|
|
</view>
|
|
|
|
|
<view class="code-img">
|
|
|
|
|
<view class="" @click="updateImgFn">
|
|
|
|
|
<view class="carime-icon">
|
|
|
|
|
<u-image src="/static/img/DJSC.png" width="91.12rpx" height="91.12rpx"></u-image>
|
|
|
|
|
<view class="">
|
|
|
|
|
点击上传图片
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
|
|
|
|
|
</view>
|
|
|
|
|
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
</up-form>
|
|
|
|
|
<u-action-sheet :show="showSex" keyName="name" closeOnClickOverlay :actions="[{name:'公'}, {name:'母'}]" title="请选择"
|
|
|
|
|
@close="showSex = false" @select="selectSex"></u-action-sheet>
|
|
|
|
|
<u-datetime-picker :show="showDate" :max-date="Date.now()" mode="date" v-model="changeTime"
|
|
|
|
|
@confirm="selectDate" :formatter="formatter" @cancel="showDate=false"></u-datetime-picker>
|
|
|
|
|
<u-button class="btn" @click="submit">提交</u-button>
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script setup>
|
|
|
|
|
import {
|
|
|
|
|
ref,
|
|
|
|
|
reactive,
|
|
|
|
|
onMounted,
|
|
|
|
|
unref,
|
|
|
|
|
computed,
|
|
|
|
|
watch
|
|
|
|
|
} from 'vue';
|
|
|
|
|
import {
|
|
|
|
|
onLoad,
|
|
|
|
|
onReady
|
|
|
|
|
} from '@dcloudio/uni-app';
|
|
|
|
|
import {
|
|
|
|
|
Uploads
|
|
|
|
|
} from "@/api/upload.js"
|
|
|
|
|
|
|
|
|
|
const form1 = ref(null);
|
|
|
|
|
const data = reactive({
|
|
|
|
|
formData: {
|
|
|
|
|
title: '',
|
|
|
|
|
sex: '',
|
|
|
|
|
type: 1,
|
|
|
|
|
brith_date: '', //出生日期
|
|
|
|
|
join_date: '', //入场日期
|
|
|
|
|
type_name: '购买', // 来源
|
|
|
|
|
master_name: '',
|
|
|
|
|
master_phone: '',
|
|
|
|
|
pic: ['https://img0.baidu.com/it/u=1717510975,3258230326&fm=253&fmt=auto?w=120&h=80',
|
|
|
|
|
'https://img0.baidu.com/it/u=1717510975,3258230326&fm=253&fmt=auto?w=120&h=80'
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
rules: {
|
|
|
|
|
title: [{
|
|
|
|
|
type: 'string',
|
|
|
|
|
required: true,
|
2024-01-23 19:52:15 +08:00
|
|
|
|
message: '请填写养殖基地名称',
|
2023-12-20 18:13:01 +08:00
|
|
|
|
trigger: ['blur', 'change']
|
|
|
|
|
}],
|
|
|
|
|
area: [{
|
|
|
|
|
type: 'string',
|
|
|
|
|
required: true,
|
2024-01-23 19:52:15 +08:00
|
|
|
|
message: '请填写养殖基地面积',
|
2023-12-20 18:13:01 +08:00
|
|
|
|
trigger: ['blur', 'change']
|
|
|
|
|
}],
|
|
|
|
|
master_name: [{
|
|
|
|
|
type: 'string',
|
|
|
|
|
required: true,
|
2024-01-23 19:52:15 +08:00
|
|
|
|
message: '请输入养殖基地负责人名称',
|
2023-12-20 18:13:01 +08:00
|
|
|
|
trigger: ['blur', 'change']
|
|
|
|
|
}],
|
|
|
|
|
master_phone: [{
|
|
|
|
|
required: true,
|
|
|
|
|
message: '请输入手机号',
|
|
|
|
|
trigger: ['change', 'blur'],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
validator: (rule, value, callback) => {
|
|
|
|
|
// 上面有说,返回true表示校验通过,返回false表示不通过
|
|
|
|
|
// uni.$u.test.mobile()就是返回true或者false的
|
|
|
|
|
return uni.$u.test.mobile(value);
|
|
|
|
|
},
|
|
|
|
|
message: '手机号码不正确',
|
|
|
|
|
// 触发器可以同时用blur和change
|
|
|
|
|
trigger: ['change', 'blur'],
|
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
const pic = reactive([]);
|
|
|
|
|
|
|
|
|
|
const showSex = ref(false);
|
|
|
|
|
const showDate = ref(false);
|
|
|
|
|
|
|
|
|
|
//图片删除
|
|
|
|
|
const delimg = (i) => {
|
|
|
|
|
pic.splice(i, 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//图片上传
|
|
|
|
|
const updateImgFn = async () => {
|
|
|
|
|
|
|
|
|
|
uni.chooseImage({
|
|
|
|
|
count: 1,
|
|
|
|
|
sizeType: ['original', 'compressed'],
|
|
|
|
|
sourceType: ['album', 'camera'],
|
|
|
|
|
success: (res) => {
|
|
|
|
|
Uploads(res.tempFilePaths[0], 'img').then(res => {
|
|
|
|
|
// console.log(res)
|
|
|
|
|
if (res.code == 1) {
|
|
|
|
|
pic.push(res.data.url)
|
|
|
|
|
console.log(data.formData)
|
|
|
|
|
|
|
|
|
|
uni.$u.toast('上传成功')
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}).catch(err => {
|
|
|
|
|
//console.log('err', err);
|
|
|
|
|
// uni.$u.toast('上传失败')
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
fail: function(err) {
|
|
|
|
|
//console.log('choose失败');
|
|
|
|
|
uni.$u.toast('添加失败')
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
// let res = await Uploads()
|
|
|
|
|
// data.formData.pic = res.data.image
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const selectSex = (e)=>{
|
|
|
|
|
data.formData.sex = e.name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const changeTime = ref(Date.now())
|
|
|
|
|
const selectDate = (e)=>{
|
|
|
|
|
let date = new Date(e.value);
|
2023-12-21 16:29:58 +08:00
|
|
|
|
if(data.formData.type>1) data.formData.brith_date = uni.$u.timeFormat(e.value, 'yyyy-mm-dd');
|
|
|
|
|
else data.formData.join_date = uni.$u.timeFormat(e.value, 'yyyy-mm-dd');
|
2023-12-20 18:13:01 +08:00
|
|
|
|
showDate.value = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onReady(() => {
|
|
|
|
|
form1.value.setRules(data.rules);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const formatter = (type, value) => {
|
|
|
|
|
if (type === 'year') {
|
|
|
|
|
return `${value}年`;
|
|
|
|
|
}
|
|
|
|
|
if (type === 'month') {
|
|
|
|
|
return `${value}月`;
|
|
|
|
|
}
|
|
|
|
|
if (type === 'day') {
|
|
|
|
|
return `${value}日`;
|
|
|
|
|
}
|
|
|
|
|
return value;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const submit = async () => {
|
|
|
|
|
try {
|
|
|
|
|
const valid = await form1.value.validate();
|
|
|
|
|
if (valid) {
|
|
|
|
|
// console.log('表单通过', data.formData);
|
|
|
|
|
if (pic.length == 0) {
|
|
|
|
|
|
|
|
|
|
uni.$u.toast('请上传图片')
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
data.formData.pic = JSON.stringify(pic)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 表单验证通过,执行提交操作
|
|
|
|
|
addland(data.formData).then((res) => {
|
|
|
|
|
console.log(res)
|
|
|
|
|
if (res.code == 1) {
|
|
|
|
|
uni.navigateBack({
|
|
|
|
|
delta: 1
|
|
|
|
|
})
|
|
|
|
|
uni.$u.toast(res.msg)
|
|
|
|
|
// console.log('提交通过');
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
} else {
|
|
|
|
|
// 表单验证不通过
|
|
|
|
|
console.log('表单验证未通过');
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
// 捕获验证过程中的错误
|
|
|
|
|
console.error(error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onLoad((options) => {
|
|
|
|
|
if (options.type > 1) {
|
|
|
|
|
data.formData.type = +options.type;
|
|
|
|
|
data.formData.type_name = options.name;
|
|
|
|
|
} else {
|
|
|
|
|
data.formData.type = 1;
|
|
|
|
|
data.formData.type_name = '购买';
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style lang="scss">
|
|
|
|
|
page {
|
|
|
|
|
background-color: #fffcf5;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.cards {
|
|
|
|
|
background-color: #fffcf5;
|
|
|
|
|
padding: 0;
|
|
|
|
|
padding-bottom: 80rpx;
|
|
|
|
|
|
|
|
|
|
.c-title {
|
|
|
|
|
font-weight: bold;
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
padding: 30rpx;
|
|
|
|
|
padding-bottom: 15rpx;
|
|
|
|
|
|
|
|
|
|
&:before {
|
|
|
|
|
content: '';
|
|
|
|
|
display: inline-block;
|
|
|
|
|
height: 0.8rem;
|
|
|
|
|
width: 6rpx;
|
|
|
|
|
margin-top: 0.2rem;
|
|
|
|
|
margin-right: 10rpx;
|
|
|
|
|
background-color: #feb048;
|
|
|
|
|
border-radius: 6rpx;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.c-box {
|
|
|
|
|
background-color: #fff;
|
|
|
|
|
padding-left: 30rpx;
|
|
|
|
|
padding-right: 20rpx;
|
|
|
|
|
padding-bottom: 20rpx;
|
|
|
|
|
box-shadow: 0px 2px 8px rgba(0, 0, 0, 0.1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.c-box-p {
|
|
|
|
|
padding: 20rpx;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.btn {
|
|
|
|
|
margin: 20rpx auto;
|
|
|
|
|
width: 694rpx;
|
|
|
|
|
height: 80rpx;
|
|
|
|
|
border-radius: 80rpx;
|
|
|
|
|
background-color: #ffb049;
|
|
|
|
|
color: #fff;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.card-li-tit {
|
|
|
|
|
position: relative;
|
|
|
|
|
|
|
|
|
|
span {
|
|
|
|
|
position: absolute;
|
|
|
|
|
left: -9px;
|
|
|
|
|
color: #f56c6c;
|
|
|
|
|
line-height: 20px;
|
|
|
|
|
font-size: 20px;
|
|
|
|
|
top: 3px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
margin-bottom: 20rpx;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.confim-btn {
|
|
|
|
|
margin: 0 auto;
|
|
|
|
|
width: 196.26rpx;
|
|
|
|
|
height: 66.59rpx;
|
|
|
|
|
/* border: ; */
|
|
|
|
|
border: #00A15E 1px solid;
|
|
|
|
|
color: #00A15E;
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
justify-content: center;
|
|
|
|
|
border-radius: 42.06rpx 42.06rpx 42.06rpx 42.06rpx;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.up-img {
|
|
|
|
|
width: 341.71rpx
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.today-btn {
|
|
|
|
|
width: 588.79rpx;
|
|
|
|
|
background-color: #00A15E;
|
|
|
|
|
color: white;
|
|
|
|
|
position: fixed;
|
|
|
|
|
bottom: 40rpx;
|
|
|
|
|
/* transform: ; */
|
|
|
|
|
left: 50%;
|
|
|
|
|
transform: translateX(-50%);
|
|
|
|
|
background: linear-gradient(to right, #00A15E, #4CC593);
|
|
|
|
|
/* margin: 0 auto; */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.code-img {
|
|
|
|
|
background-color: #F4F4F4;
|
|
|
|
|
height: 350.47rpx;
|
|
|
|
|
position: relative;
|
|
|
|
|
|
|
|
|
|
.carime-icon {
|
|
|
|
|
position: absolute;
|
|
|
|
|
top: 50%;
|
|
|
|
|
left: 50%;
|
|
|
|
|
transform: translate(-50%, -50%);
|
|
|
|
|
display: flex;
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
align-items: center;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
</style>
|