Browse Source

农事操作 修改病虫害防止对象表单赋值

master
邓宏 2 months ago
parent
commit
06516efb1d
  1. 22
      pages/massif/add_farming.vue
  2. 203
      pages/massif/pestType.vue

22
pages/massif/add_farming.vue

@ -431,15 +431,19 @@ export default {
}, },
// //
pestsFun(){ pestsFun(){
uni.navigateTo({ if(this.formData.pestsType){
url:`/pages/massif/pestType?type=${({"病害":"disease","虫害":"pestis"})[this.formData.pestsType]||''}&plantType=${this.massif.plantType}`, uni.navigateTo({
events:{type:e=>{ url:`/pages/massif/pestType?type=${this.formData.pestsType}&plantType=${this.massif.plantType}`,
this.formData.pests=e.map(v=>v).join(',') events:{type:e=>{
}}, this.formData.pests=e.map(v=>v).join(',')
success:res=>{ }},
res.eventChannel.emit('ids',this.formData?.pests?.split?.(',')?.filter(v=>v)||[]) success:res=>{
} res.eventChannel.emit('ids',this.formData?.pests?.split?.(',')?.filter(v=>v)||[])
}) }
})
}else{
uni.showToast({title:"请选择病虫害类型!"})
}
}, },
// //
toPestRecord(){ toPestRecord(){

203
pages/massif/pestType.vue

@ -1,52 +1,6 @@
<style lang="less" scoped> <style lang="less" scoped>
.container{ .container{
height:100%; height:100%;
&>.d-search{
&/deep/ .search{
margin-bottom:0;
}
}
&>.u-tabs{
margin:0 30rpx;
flex-shrink: 0;
&/deep/ .u-tabs__wrapper__nav__line{
box-shadow:0 4rpx 6rpx 2rpx rgba(16,193,118,0.1);
}
}
&>.tabs{
flex-shrink: 0;
margin:10rpx 30rpx 0;
background:#EEFBF5;
border-radius: 8rpx;
padding:0 15rpx;
display:flex;
flex-wrap: wrap;
text{
color:#999;
padding:15rpx;
&.active{
color:#10C176;
}
}
}
&>.title{
flex-shrink: 0;
color:#333;
margin:30rpx;
display:flex;
align-items: center;
&:before{
content:"*";
color:#EE263A;
}
button{
margin-left:auto;
background:#10C176;
color:#fff;
box-shadow: 4rpx 4rpx 6rpx rgba(0,0,0,0.1);
font-size:24rpx;
}
}
scroll-view{ scroll-view{
flex-grow: 1; flex-grow: 1;
height:1rpx; height:1rpx;
@ -77,52 +31,22 @@
} }
} }
.addPest{
position:absolute;
bottom:0;
left:0;
width:100%;
background:#fff;
color:#333;
height:60rpx;
padding:0 20rpx;
}
} }
</style> </style>
<template> <template>
<view class="container flex"> <view class="container flex">
<d-navbar style="--bg:#10C176;--c:#fff;" isBack :text="({pestis:'选择虫害',disease:'选择病害'})[type]||'选择病虫害'"> <d-navbar style="--bg:#10C176;--c:#fff;" isBack :text="`选择${searchVal.pestsType}害`">
<button slot="right" class="cu-btn round" @click="submit">提交</button> <button slot="right" class="cu-btn round" @click="submit">提交</button>
</d-navbar> </d-navbar>
<d-search background="#eee" v-model="searchVal.search" @search="type=='disease'?searchDisease():inputSearch()"/> <d-search background="#eee" v-model="searchVal.detailName" @search="search()"/>
<template v-if="type=='pestis'">
<u-tabs
:list="cropList"
:current="cropCurrent"
activeStyle="color:#10C176"
keyName="label"
lineWidth="60rpx"
lineHeight="8rpx"
inactiveStyle="color:#333"
lineColor="#10C176"
@change="cropCurrent=$event.index"/>
<view class="tabs">
<text v-for="(v,k) in agrProd" :class="{active:searchVal.value==v.value}" :key="k" @click="agrSearch(v.value)">{{v.label}}</text>
</view>
</template>
<view class="title">{{({pestis:'虫害',disease:'病害'})[type]}}种类 <button class="cu-btn round sm" v-if="searchVal.value||type=='disease'" @click="show=true">自定义+</button></view>
<scroll-view scroll-y> <scroll-view scroll-y>
<view class="items"> <view class="items">
<text :class="{active:select.some(i=>i==v.name)}" v-for="(v,k) in list" :key="k" @click="selectPest(v)">{{v.name}}</text> <text :class="{active:select.some(i=>i==v.label)}" v-for="(v,k) in list" :key="k" @click="selectPest(v)">{{v.label}}</text>
</view> </view>
<u-empty :show="list.length<=0" text="未查询到相关信息" width="70%" icon="/static/noData.png"/> <u-empty :show="list.length<=0" text="未查询到相关信息" width="70%" icon="/static/noData.png"/>
</scroll-view> </scroll-view>
</view>
<u-overlay :show="show" @click="show=false">
<input class="addPest" placeholder="请输入" @click.stop="" :focus="show" @blur="show=false" @confirm="addPest($event.detail.value)"/>
</u-overlay>
</view>
</template> </template>
<script> <script>
import request from '@/common/request' import request from '@/common/request'
@ -133,8 +57,9 @@ export default {
cropCurrent:0, cropCurrent:0,
list:[], list:[],
searchVal:{ searchVal:{
value:"",// pestsType: '',
search:"", plantType: '',
detailName:'',
}, },
select:[], select:[],
eventChannel:null, eventChannel:null,
@ -148,14 +73,12 @@ export default {
}, },
}, },
onLoad(options){ onLoad(options){
this.type=options.type this.searchVal.pestsType=options.type
this.searchVal.plantType=options.type=='病害'?options.plantType:''
this.eventChannel=this.getOpenerEventChannel() this.eventChannel=this.getOpenerEventChannel()
this.eventChannel.on("ids",e=>this.select=e) this.eventChannel.on("ids",e=>this.select=e)
if(this.type=='pestis'){
this.init() this.search()
}else{
this.searchDisease()
}
}, },
methods:{ methods:{
async init(){ async init(){
@ -174,64 +97,17 @@ export default {
}) })
} }
}, },
async inputSearch(){ async search(type){
if(this.searchVal.search){ var res=await request("/suyuan/farmingApi/queryPestDetail",{
this.searchVal.value="" method:"post",
body: this.searchVal,
var res=await request("/api/plantFarming/getPestByLike",{
params: {
value: '',//
search: this.searchVal.search,
}
})
if(res.statu){
this.list=res.data
}else{
this.list=[]
uni.showModal({
title:"提示",
content:res.msg||"获取虫害失败!",
showCancel:false,
})
}
}
},
async agrSearch(e){
if(e){
this.searchVal={ value:e, search:"" }
if(typeof e=='string'){
var res=await request("/api/plantFarming/getPestByLike",{
params: {
value: e,//
search:"",
}
})
if(res.statu){
this.list=res.data
}else{
this.list=[]
uni.showModal({
title:"提示",
content:res.msg||"获取虫害失败!",
showCancel:false,
})
}
}else{
this.list=e
}
}
},
async searchDisease(){
var res=await request("/api/plantFarming/getDiseaseByLike",{
params:{search: this.searchVal.search}
}) })
if(res.statu){ if(res.statu){
this.list=res.data.map(v=>({id:v.id,name:v.dictName})) this.list=res.data
}else{ }else{
uni.showModal({ uni.showModal({
title:"提示", title:"提示",
content:res.msg||"获取病害失败!", content:res.msg||`获取${this.searchVal.pestsType}失败!`,
showCancel:false, showCancel:false,
}) })
} }
@ -240,6 +116,9 @@ export default {
if(this.select.length>0){ if(this.select.length>0){
this.eventChannel.emit("type", this.select) this.eventChannel.emit("type", this.select)
uni.navigateBack() uni.navigateBack()
}else if(this.searchVal.detailName){
this.eventChannel.emit('type', [this.searchVal.detailName])
uni.navigateBack()
}else{ }else{
uni.showModal({ uni.showModal({
title:"提示", title:"提示",
@ -248,47 +127,11 @@ export default {
}) })
} }
}, },
async addPest(e){
if(this.type=='pestis'){//
var res=await request("/common/api/dict/AddCategory",{
method:"post",
body:{
pid: typeof this.searchVal.value=='string'?this.searchVal.value:this.cropList.find(v=>v.pest==this.searchVal.value).value,
name:e
}
})
if(res.statu){
this.list.push({id:res,name:e})
}else{
uni.showModal({
title:"提示",
content:res.msg||"添加虫害失败!",
showCancel:false,
})
}
}else{//
var res=await request("/common/api/dict/addDictItem",{
params:{
dictCode:"disease_type",
text:e,
}
})
if(res.statu){
this.list.push({id:res.data.id,name:e})
}else{
uni.showModal({
title:"提示",
content:res.msg||"添加病害失败!",
showCancel:false,
})
}
}
},
selectPest(e){ selectPest(e){
if(this.select.some(v=>v==e.name)){ if(this.select.some(v=>v==e.label)){
this.select=this.select.filter(v=>v!=e.name) this.select=this.select.filter(v=>v!=e.label)
}else{ }else{
this.select.push(e.name) this.select.push(e.label)
} }
}, },
} }

Loading…
Cancel
Save