TraceabilityAPP/pages/husbandryForm/sow.vue

362 lines
7.5 KiB
Vue
Raw Normal View History

2023-11-22 14:08:24 +08:00
<template>
<!-- 播种 -->
<view class="content">
<view class="card">
2023-11-25 16:18:54 +08:00
<u-form labelPosition="top" labelWidth='100' :model="data.formData" ref="form1">
<u-form-item label="种植种类" prop="kind" borderBottom ref='item1' required>
2023-11-22 14:08:24 +08:00
<up-input placeholder="请输入种植种类" :disabled="mode=='detail'" border="surround"
2023-11-25 16:18:54 +08:00
v-model="data.formData.kind"></up-input>
2023-11-22 14:08:24 +08:00
</u-form-item>
2023-11-25 16:18:54 +08:00
<u-form-item label="种植品种" prop="breed" borderBottom required>
2023-11-22 14:08:24 +08:00
<up-input placeholder="请输入品种" :disabled="mode=='detail'" border="surround"
2023-11-25 16:18:54 +08:00
v-model="data.formData.breed"></up-input>
2023-11-22 14:08:24 +08:00
</u-form-item>
2023-11-29 18:11:21 +08:00
<u-form-item label="开始日期" prop="date" borderBottom required @click="openDate">
<up-input placeholder="请选择日期" readonly border="surround"
v-model="data.formData.date" style="pointer-events: none;"></up-input>
2023-11-22 14:08:24 +08:00
</u-form-item>
2023-11-25 16:18:54 +08:00
<u-form-item label="种植面积" prop="area" borderBottom required>
2023-11-22 14:08:24 +08:00
<up-input placeholder="请输入种植面积" :disabled="mode=='detail'" type="number" border="surround"
2023-11-25 16:18:54 +08:00
v-model="data.formData.area"></up-input>
2023-11-22 14:08:24 +08:00
</u-form-item>
2023-11-25 16:18:54 +08:00
<u-form-item label="参与人" prop="user" borderBottom required>
<up-input placeholder="请输入参与人" :disabled="mode=='detail'" type="txt" border="surround"
v-model="data.formData.user"></up-input>
2023-11-22 14:08:24 +08:00
</u-form-item>
<view class="card-li">
<view class="card-li-tit">
2023-11-27 18:23:17 +08:00
种植图片
2023-11-25 16:18:54 +08:00
</view>
<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;">
2023-11-27 18:23:17 +08:00
<view class="">
<u-icon name="close" size="15" style="margin-left:120.85rpx;"
@click="delimg(i)" v-show="mode=='add'"></u-icon>
<u-image :src="item" width="150.85rpx" height="150.85rpx" @click="perviewFn(item)"></u-image>
2023-11-27 18:23:17 +08:00
</view>
2023-11-25 16:18:54 +08:00
</view>
</view>
2023-11-22 14:08:24 +08:00
</view>
<view class="code-img">
<view class="" @click="updateImgFn">
2023-11-25 16:18:54 +08:00
<view class="carime-icon">
<u-image src="/static/img/DJSC.png" width="91.12rpx" height="91.12rpx"></u-image>
2023-11-22 14:08:24 +08:00
<view class="">
点击上传图片
</view>
</view>
</view>
2023-11-25 16:18:54 +08:00
2023-11-22 14:08:24 +08:00
</view>
</view>
2023-11-25 16:18:54 +08:00
<u-form-item label="备注" prop="remark" borderBottom required>
<u--textarea v-model="data.formData.remark" :disabled="mode=='detail'"
placeholder="请输入内容"></u--textarea>
2023-11-22 14:08:24 +08:00
</u-form-item>
2023-11-25 16:18:54 +08:00
</u-form>
2023-11-22 14:08:24 +08:00
<view>
<uni-calendar ref="calendar" :showMonth="true" :lunar="true" :insert="false" @confirm="dateConfirmfn" />
</view>
</view>
<view class="confirm" v-if="mode=='add'">
<view class="confirm-btn" style="color: white;background-color: #0AA565;" @click="addFn">
完成添加
</view>
</view>
</view>
</template>
<script setup>
2023-11-25 16:18:54 +08:00
import {
Uploads
} from "@/api/upload.js"
2023-11-22 14:08:24 +08:00
import {
reactive,
ref
} from "vue";
import {
2023-11-25 16:18:54 +08:00
onLoad,
onReady
2023-11-22 14:08:24 +08:00
} from "@dcloudio/uni-app"
2023-11-25 16:18:54 +08:00
import {
addplant
} from '@/api/api.js'
2023-11-25 16:18:54 +08:00
2023-11-22 14:08:24 +08:00
const calendar = ref(null)
2023-11-25 16:18:54 +08:00
const form1 = ref(null);
const task_id = ref('');
const pic = reactive([]);
const data = reactive({
formData: {
kind: '',
breed: '',
area: '',
user: '',
date: '',
remark: '',
pic: []
},
rules: {
kind: [{
type: 'string',
required: true,
message: '请填写种植种类',
trigger: ['blur', 'change']
}],
breed: [{
type: 'string',
required: true,
message: '请填写种植品种',
trigger: ['blur', 'change']
}],
area: [{
type: 'string',
required: true,
message: '请填写种植面积',
trigger: ['blur', 'change']
}],
user: [{
type: 'string',
required: true,
message: '请填写参与人员',
trigger: ['blur', 'change']
}],
date: [{
type: 'string',
required: true,
message: '请填写开始日期',
trigger: ['blur', 'change']
}],
remark: [{
type: 'string',
required: true,
message: '请填写备注信息',
trigger: ['blur', 'change']
}]
}
})
onReady(() => {
form1.value.setRules(data.rules);
});
2023-11-22 14:08:24 +08:00
const openDate = () => {
calendar.value.open()
}
const dateConfirmfn = (e) => {
2023-11-25 16:18:54 +08:00
data.formData.date = e.fulldate
2023-11-22 14:08:24 +08:00
}
2023-11-25 16:18:54 +08:00
2023-11-27 18:23:17 +08:00
//图片删除
const delimg = (i) => {
pic.splice(i, 1);
}
2023-11-25 16:18:54 +08:00
2023-11-22 14:08:24 +08:00
const navgo = (url) => {
uni.navigateTo({
url
})
}
//查看图片
const perviewFn = (url) => {
console.log(url)
uni.previewImage({
urls: [url]
})
}
2023-11-25 16:18:54 +08:00
const addFn = async () => {
console.log(form1.value)
try {
const valid = await form1.value.validate();
if (valid) {
data.formData.land_id = task_id.value
console.log('表单通过');
data.formData.pic = JSON.stringify(pic)
if (data.formData.pic.length == 0) {
uni.$u.toast('请上传图片')
return
}
// 表单验证通过,执行提交操作
addplant(data.formData).then((res) => {
2023-11-27 18:23:17 +08:00
2023-11-25 16:18:54 +08:00
if (res.code == 1) {
2023-11-27 18:23:17 +08:00
2023-11-25 16:18:54 +08:00
uni.navigateBack({
delta:1
})
2023-11-27 18:23:17 +08:00
uni.$u.toast(res.msg)
2023-11-25 16:18:54 +08:00
}
})
} else {
// 表单验证不通过
console.log('表单验证未通过');
}
} catch (error) {
// 捕获验证过程中的错误
console.error(error);
}
2023-11-22 14:08:24 +08:00
2023-11-25 16:18:54 +08:00
// form.value.validate().then(res => {
// console.log(6)
// }).catch(errors => {
// uni.$u.toast('校验失败')
// })
// console.log()
}
//图片上传
2023-11-22 14:08:24 +08:00
const updateImgFn = async () => {
2023-11-25 16:18:54 +08:00
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(pic)
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
2023-11-22 14:08:24 +08:00
}
2023-11-25 16:18:54 +08:00
2023-11-22 14:08:24 +08:00
const mode = ref('add')
onLoad((options) => {
2023-11-25 16:18:54 +08:00
task_id.value = options.id
// if (options.task_id) {
// mode.value = "detail"
// }
2023-11-22 14:08:24 +08:00
})
</script>
<style lang='scss' scoped>
.content {
padding-bottom: 100rpx;
}
.tit {
display: flex;
justify-content: space-between;
}
.card-li-tit {
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;
/* margin-bottom: 100rpx; */
.carime-icon {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
display: flex;
flex-direction: column;
align-items: center;
}
}
.confirm {
position: fixed;
height: 84.11rpx;
display: flex;
bottom: 30rpx;
width: 750rpx;
.confirm-btn {
width: 315.42rpx;
height: 84.11rpx;
border: #00A15E 1px solid;
margin: 0 auto;
border-radius: 80rpx;
text-align: center;
line-height: 84rpx;
}
}
</style>