2023-11-22 14:08:24 +08:00
|
|
|
<template>
|
|
|
|
<!-- 播种 -->
|
|
|
|
<view class="content">
|
|
|
|
<view class="card">
|
2023-12-07 09:34:25 +08:00
|
|
|
<u--form labelPosition="top" labelWidth='130' :model="formData" :rules="rules" ref="form">
|
2023-11-25 16:18:54 +08:00
|
|
|
<u-form-item label="杀虫剂种类" prop="kind" borderBottom ref='item1' required>
|
|
|
|
<up-input placeholder="请输入杀虫剂种类" :disabled="mode=='detail'" border="surround"
|
|
|
|
v-model="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>
|
|
|
|
<up-input placeholder="请输入杀虫剂品牌" :disabled="mode=='detail'" border="surround"
|
2023-11-22 14:08:24 +08:00
|
|
|
v-model="formData.breed"></up-input>
|
|
|
|
</u-form-item>
|
2023-12-07 09:34:25 +08:00
|
|
|
<u-form-item label="杀虫剂用量(升)" prop="dosage" borderBottom required>
|
|
|
|
<up-input placeholder="请输入杀虫剂用量" type='number' border="surround" :disabled="mode=='detail'"
|
2023-11-25 16:18:54 +08:00
|
|
|
v-model="formData.dosage"></up-input>
|
2023-11-22 14:08:24 +08:00
|
|
|
</u-form-item>
|
2023-11-25 16:18:54 +08:00
|
|
|
|
|
|
|
<view class="" v-if="mode=='add'">
|
|
|
|
<u-form-item label="开始日期" @click="openDate" prop="start_date" borderBottom required>
|
2023-11-29 18:11:21 +08:00
|
|
|
<up-input placeholder="请选择日期" readonly border="surround"
|
|
|
|
v-model="formData.start_date" style="pointer-events: none;"></up-input>
|
2023-11-25 16:18:54 +08:00
|
|
|
</u-form-item>
|
|
|
|
<u-form-item label="结束日期" prop="end_date" @click="openDate1" borderBottom required>
|
2023-11-29 18:11:21 +08:00
|
|
|
<up-input placeholder="请选择日期" readonly border="surround"
|
|
|
|
v-model="formData.end_date" style="pointer-events: none;"></up-input>
|
2023-11-25 16:18:54 +08:00
|
|
|
</u-form-item>
|
|
|
|
</view>
|
|
|
|
<view class="" v-else>
|
|
|
|
<u-form-item label="开始日期" prop="start_date" borderBottom required>
|
2023-11-29 18:11:21 +08:00
|
|
|
<up-input placeholder="请选择日期" readonly border="surround"
|
|
|
|
v-model="formData.start_date" style="pointer-events: none;"></up-input>
|
2023-11-25 16:18:54 +08:00
|
|
|
</u-form-item>
|
|
|
|
<u-form-item label="结束日期" prop="end_date" borderBottom required>
|
2023-11-29 18:11:21 +08:00
|
|
|
<up-input placeholder="请选择日期" readonly border="surround"
|
|
|
|
v-model="formData.end_date" style="pointer-events: none;"></up-input>
|
2023-11-25 16:18:54 +08:00
|
|
|
</u-form-item>
|
|
|
|
</view>
|
2023-12-07 09:34:25 +08:00
|
|
|
<u-form-item label="作业面积(亩)" prop="area" borderBottom required>
|
2023-11-25 16:18:54 +08:00
|
|
|
<up-input placeholder="请输入作业面积" :disabled="mode=='detail'" type="number" border="surround"
|
|
|
|
v-model="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="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-12-07 09:34:25 +08:00
|
|
|
<span>*</span>
|
2023-11-25 16:18:54 +08:00
|
|
|
杀虫图片
|
2023-11-22 14:08:24 +08:00
|
|
|
</view>
|
2023-11-25 16:18:54 +08:00
|
|
|
<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>
|
2023-11-28 18:08:39 +08:00
|
|
|
<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-22 14:08:24 +08:00
|
|
|
</view>
|
2023-11-25 16:18:54 +08:00
|
|
|
</view>
|
|
|
|
|
|
|
|
</view>
|
|
|
|
<view class="code-img" v-if="mode=='add'">
|
|
|
|
<view class="" @click="updateImgFn">
|
|
|
|
<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-12-07 09:34:25 +08:00
|
|
|
<u-form-item label="备注" prop="remark" borderBottom >
|
2023-11-25 16:18:54 +08:00
|
|
|
<u--textarea v-model="formData.remark" :disabled="mode=='detail'" placeholder="请输入内容"></u--textarea>
|
2023-11-22 14:08:24 +08:00
|
|
|
</u-form-item>
|
|
|
|
|
|
|
|
</u--form>
|
|
|
|
<view>
|
2023-12-02 18:37:08 +08:00
|
|
|
<!-- <uni-calendar ref="calendar" :showMonth="true" :lunar="true" :insert="false" @confirm="dateConfirmfn" />
|
2023-11-25 16:18:54 +08:00
|
|
|
<uni-calendar ref="calendar1" :showMonth="true" :lunar="true" :insert="false"
|
2023-12-02 18:37:08 +08:00
|
|
|
@confirm="dateConfirmfn1" /> -->
|
|
|
|
<u-datetime-picker :show="show1" v-model="value1" mode="datetime" @confirm="dateConfirmfn"
|
|
|
|
:formatter="formatter" @cancel="show1=false"></u-datetime-picker>
|
|
|
|
<u-datetime-picker :show="show2" v-model="value1" mode="datetime" @confirm="dateConfirmfn1"
|
|
|
|
:formatter="formatter" @cancel="show2=false"></u-datetime-picker>
|
2023-11-22 14:08:24 +08:00
|
|
|
</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
|
|
|
|
} from '@dcloudio/uni-app';
|
|
|
|
import {
|
|
|
|
addaction
|
2023-11-28 18:08:39 +08:00
|
|
|
} from '@/api/api.js'
|
2023-11-22 14:08:24 +08:00
|
|
|
|
2023-11-25 16:18:54 +08:00
|
|
|
const pic = reactive([]);
|
2023-11-22 14:08:24 +08:00
|
|
|
const calendar = ref(null)
|
2023-11-25 16:18:54 +08:00
|
|
|
const calendar1 = ref(null)
|
2023-11-22 14:08:24 +08:00
|
|
|
const form = ref(null)
|
2023-11-25 16:18:54 +08:00
|
|
|
const task_id = ref('');
|
2023-12-02 18:37:08 +08:00
|
|
|
const value1 = ref(Date.now());
|
|
|
|
const show1 = ref(false);
|
|
|
|
const show2 = ref(false);
|
2023-11-22 14:08:24 +08:00
|
|
|
const openDate = () => {
|
2023-12-02 18:37:08 +08:00
|
|
|
// calendar.value.open()
|
|
|
|
show1.value = true
|
2023-11-22 14:08:24 +08:00
|
|
|
}
|
2023-11-25 16:18:54 +08:00
|
|
|
const openDate1 = () => {
|
2023-12-02 18:37:08 +08:00
|
|
|
// calendar1.value.open()
|
|
|
|
show2.value = true
|
2023-11-25 16:18:54 +08:00
|
|
|
}
|
2023-11-22 14:08:24 +08:00
|
|
|
// console.log()
|
|
|
|
const formData = reactive({
|
2023-11-25 16:18:54 +08:00
|
|
|
kind: "",
|
|
|
|
breed: "",
|
|
|
|
dosage: "",
|
|
|
|
start_date: "",
|
|
|
|
dosage: "",
|
|
|
|
end_date: "",
|
|
|
|
})
|
2023-11-22 14:08:24 +08:00
|
|
|
|
2023-12-02 18:37:08 +08:00
|
|
|
const formatter = (type, value) => {
|
|
|
|
if (type === 'year') {
|
|
|
|
return `${value}年`;
|
|
|
|
}
|
|
|
|
if (type === 'month') {
|
|
|
|
return `${value}月`;
|
|
|
|
}
|
|
|
|
if (type === 'day') {
|
|
|
|
return `${value}日`;
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
};
|
|
|
|
//获取时间
|
2023-11-22 14:08:24 +08:00
|
|
|
const dateConfirmfn = (e) => {
|
2023-12-02 18:37:08 +08:00
|
|
|
formData.start_date = uni.$u.timeFormat(e.value, 'yyyy-mm-dd hh:MM ')
|
|
|
|
show1.value = false
|
2023-11-22 14:08:24 +08:00
|
|
|
}
|
2023-11-25 16:18:54 +08:00
|
|
|
const dateConfirmfn1 = (e) => {
|
2023-12-02 18:37:08 +08:00
|
|
|
formData.end_date = uni.$u.timeFormat(e.value, 'yyyy-mm-dd hh:MM ')
|
|
|
|
show2.value = false
|
2023-11-25 16:18:54 +08:00
|
|
|
}
|
|
|
|
const rules = ref({
|
|
|
|
'kind': {
|
|
|
|
type: 'string',
|
|
|
|
required: true,
|
2023-11-27 18:23:17 +08:00
|
|
|
message: '请填写杀虫剂品牌',
|
2023-11-25 16:18:54 +08:00
|
|
|
trigger: ['blur', 'change']
|
|
|
|
},
|
|
|
|
'breed': {
|
|
|
|
type: 'string',
|
|
|
|
required: true,
|
|
|
|
message: '请填写杀虫剂品牌',
|
|
|
|
trigger: ['blur', 'change']
|
|
|
|
},
|
|
|
|
'dosage': {
|
|
|
|
type: 'string',
|
|
|
|
required: true,
|
|
|
|
message: '请填写杀虫剂用量',
|
|
|
|
trigger: ['blur', 'change']
|
|
|
|
},
|
|
|
|
'start_date': {
|
|
|
|
type: 'string',
|
|
|
|
required: true,
|
|
|
|
message: '请填写开始日期',
|
|
|
|
trigger: ['blur', 'change']
|
|
|
|
},
|
|
|
|
'end_date': {
|
|
|
|
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']
|
2023-12-07 09:34:25 +08:00
|
|
|
}
|
|
|
|
// ,
|
|
|
|
// 'remark': {
|
|
|
|
// type: 'string',
|
|
|
|
// required: true,
|
|
|
|
// message: '请填写备注',
|
|
|
|
// trigger: ['blur', 'change']
|
|
|
|
// },
|
2023-11-25 16:18:54 +08:00
|
|
|
})
|
|
|
|
onReady(() => {
|
|
|
|
form.value.setRules(rules);
|
|
|
|
|
|
|
|
});
|
2023-11-28 18:08:39 +08:00
|
|
|
//查看图片
|
|
|
|
const perviewFn = (url) => {
|
|
|
|
console.log(url)
|
|
|
|
uni.previewImage({
|
|
|
|
urls: [url]
|
|
|
|
})
|
|
|
|
}
|
2023-11-27 18:23:17 +08:00
|
|
|
//图片删除
|
|
|
|
const delimg = (i) => {
|
|
|
|
pic.splice(i, 1);
|
|
|
|
}
|
2023-11-25 16:18:54 +08:00
|
|
|
//图片上传
|
|
|
|
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
|
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 navgo = (url) => {
|
|
|
|
uni.navigateTo({
|
|
|
|
url
|
|
|
|
})
|
|
|
|
}
|
2023-11-25 16:18:54 +08:00
|
|
|
|
2023-11-22 14:08:24 +08:00
|
|
|
const addFn = () => {
|
|
|
|
form.value.validate().then(res => {
|
2023-11-25 16:18:54 +08:00
|
|
|
console.log(res)
|
|
|
|
if (res) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
formData.pic = pic
|
|
|
|
let data1 = {
|
|
|
|
plant_id: task_id.value,
|
|
|
|
type: 4,
|
|
|
|
detail: JSON.stringify(formData)
|
|
|
|
};
|
|
|
|
if (formData.pic.length == 0) {
|
|
|
|
|
|
|
|
uni.$u.toast('请上传图片')
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log('表单通过');
|
|
|
|
|
|
|
|
// 表单验证通过,执行提交操作
|
|
|
|
|
|
|
|
addaction(data1).then((res) => {
|
|
|
|
console.log(res)
|
|
|
|
if (res.code == 1) {
|
|
|
|
uni.$u.toast(res.msg)
|
|
|
|
uni.navigateBack({
|
|
|
|
delta: 1
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
// uni.$u.toast('校验成功')
|
|
|
|
}
|
|
|
|
|
2023-12-02 18:37:08 +08:00
|
|
|
}).catch((err)=>{
|
|
|
|
uni.$u.toast(err[0].message)
|
|
|
|
console.log(err)
|
2023-11-22 14:08:24 +08:00
|
|
|
})
|
|
|
|
|
2023-11-25 16:18:54 +08:00
|
|
|
|
2023-12-02 18:37:08 +08:00
|
|
|
|
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
|
|
|
if (options.task) {
|
|
|
|
let data = options.task ? JSON.parse(decodeURIComponent(options.task)) : null;
|
|
|
|
console.log(data, data.detail)
|
|
|
|
Object.assign(formData, data.detail);
|
2023-11-28 18:08:39 +08:00
|
|
|
pic.splice(0, pic.length, ...data.detail.pic);
|
2023-11-25 16:18:54 +08:00
|
|
|
|
|
|
|
mode.value = 'detail'
|
|
|
|
uni.setNavigationBarTitle({
|
|
|
|
title: '虫害防治信息详情'
|
|
|
|
})
|
|
|
|
|
|
|
|
// formData=data.detail
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
task_id.value = options.id
|
2023-11-22 14:08:24 +08:00
|
|
|
}
|
|
|
|
|
2023-11-25 16:18:54 +08:00
|
|
|
|
|
|
|
|
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 {
|
2023-12-07 09:34:25 +08:00
|
|
|
position: relative;
|
|
|
|
|
|
|
|
span {
|
|
|
|
position: absolute;
|
|
|
|
left: -9px;
|
|
|
|
color: #f56c6c;
|
|
|
|
line-height: 20px;
|
|
|
|
font-size: 20px;
|
|
|
|
top: 3px;
|
|
|
|
}
|
|
|
|
|
2023-11-22 14:08:24 +08:00
|
|
|
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>
|