Browse Source

联调 添加虫害

master
邓宏 2 years ago
parent
commit
bee8c6d4f4
  1. 2
      pages/massif/add_farming.vue
  2. 19
      pages/massif/pestRecord.vue
  3. 107
      pages/massif/pestType.vue
  4. 21
      uni_modules/d-form/components/d-form/d-form.vue

2
pages/massif/add_farming.vue

@ -208,7 +208,7 @@
<text class="title">操作</text> <text class="record">病虫害记录</text><text class="plant-youbian"/>
</view>
<view class="value" v-if="formData.farmPests">
过程:{{formData.farmPests.growthProcessLabel}}病虫害部位:{{formData.farmPests.pestSite}}症状{{formData.farmPests.symptomLabel}}({{formData.farmPests.pestName.map(v=>v.name).join(',')}})
过程:{{formData.farmPests.growthProcess}}病虫害部位:{{formData.farmPests.pestSite}}症状{{formData.farmPests.symptom}}({{formData.farmPests.pestName.map(v=>v.name).join(',')}})
</view>
</view>
<u-form class="inline" errorType="toast" :model="formData" :rules="rules" ref="form" labelWidth="auto">

19
pages/massif/pestRecord.vue

@ -14,10 +14,10 @@
:field="k"
v-bind="v"
:required="!!rules[k]"
:value="/^checkBox$|^navigate$/.test(v.type)?fields[k].value:formData[k]"
:value="/^select$|^checkBox$|^navigate$/.test(v.type)?fields[k].value:formData[k]"
@input="formData[k]=$event"
@checkBox="fields[k].value=$event;formData[k]=$event.join(',')"
@select="formData[k]=$event[0].value;fields[k].value=$event[0].label"
@select="formData[k]=$event[0].value;fields[k].value=[formData[k]]"
@imgs="fields[k].value=$event"/>
</u-form>
<button class="cu-btn round bg-green shadow submit" @click="sumbit">保存</button>
@ -32,8 +32,9 @@ export default {
pestSite:{label:"病虫害部位",type:"checkBox",value:[],columns:[{label:"根",value:"根"},{label:"茎",value:"茎"},{label:"叶",value:"叶"}]},
growthProcess:{label:"作物生长过程",type:"select-tab",dictCode:"growth_process"},
symptom:{label:"显著症状",type:"select-tab",dictCode:"symptom"},
pestName:{label:"害虫名称",type:"navigate",value:"",btnFun:()=>uni.navigateTo({
url:"/pages/massif/pestType",
pestType:{label:"病虫害类型",type:"select",columns:[[{label:"病害",value:"病害"},{label:"虫害",value:"虫害"}]],value:['虫害']},
pestName:{label:()=>`${this.formData.pestType}名称`,type:"navigate",value:"",btnFun:()=>uni.navigateTo({
url:`/pages/massif/pestType?type=${({"病害":"disease","虫害":"pestis"})[this.formData.pestType]}`,
events:{type:e=>{
this.formData.pestName=e
this.fields.pestName.value=e.map(v=>v.name).join(",")
@ -50,6 +51,7 @@ export default {
growthProcess:'',
pestSite:'',
symptom:"",
pestType:"虫害",
pestName:[],
medicationArea:"",
pic:[],
@ -59,6 +61,7 @@ export default {
growthProcess:{required:true,message:"请选择作物生长过程!",trigger:['blur','change']},
pestSite:{required:true,message:"请选择病虫害部位!",trigger:['blur','change']},
symptom:{required:true,message:"请选择显著症状!",trigger:['blur','change']},
pestType:{required:true,message:"请选择病虫害类型!",trigger:['blur','change']},
pestName:{required:true,message:"请选择害虫!",type:"array",trigger:['blur','change']},
medicationArea:{required:true,message:"请输入农资作用面积!",type:"number",trigger:['blur','change']},
pic:{required:true,validator:(rule,val,call)=>{
@ -74,8 +77,8 @@ export default {
this.eventChannel.on("detail",e=>{
this.fields.pic.value=e.pic||''
this.fields.pestSite.value=e?.pestSite?.split?.(",")?.filter?.(v=>v)||[]
this.fields.growthProcess.value=e?.growthProcessLabel||""
this.fields.symptom.value=e?.symptomLabel||""
// this.fields.growthProcess.value=e?.growthProcessLabel||""
// this.fields.symptom.value=e?.symptomLabel||""
this.fields.pestName.value=e?.pestName?.map(v=>v.name).join(',')
this.formData=Object.assign(this.formData,{
...e,
@ -90,8 +93,8 @@ export default {
this.eventChannel.emit("addPest",{
...this.formData,
pic:this.fields.pic.value,
growthProcessLabel:this.fields.growthProcess.value,
symptomLabel:this.fields.symptom.value,
// growthProcessLabel:this.fields.growthProcess.value,
// symptomLabel:this.fields.symptom.value,
})
uni.navigateBack()
}

107
pages/massif/pestType.vue

@ -91,25 +91,27 @@
</style>
<template>
<view class="container flex">
<d-navbar style="--bg:#10C176;--c:#fff;" isBack text="选择害虫">
<d-navbar style="--bg:#10C176;--c:#fff;" isBack :text="({pestis:'选择虫害',disease:'选择病害'})[type]">
<button slot="right" class="cu-btn round" @click="submit">提交</button>
</d-navbar>
<d-search background="#eee" v-model="searchVal.search" @search="inputSearch"/>
<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>
<view class="title">害虫种类 <button class="cu-btn round sm" v-if="searchVal.value" @click="show=true">自定义+</button></view>
<d-search background="#eee" v-model="searchVal.search" @search="type=='disease'?searchDisease():inputSearch()"/>
<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>
<view class="items">
<text :class="{active:select.some(i=>i.id==v.id)}" v-for="(v,k) in list" :key="k" @click="selectPest(v)">{{v.name}}</text>
@ -137,6 +139,7 @@ export default {
select:[],
eventChannel:null,
show:false,
type:"", //:disease :pestis
}
},
computed:{
@ -144,10 +147,15 @@ export default {
return this.cropList?.[this.cropCurrent]?.children||[]
},
},
onLoad(){
onLoad(options){
this.type=options.type
this.eventChannel=this.getOpenerEventChannel()
this.eventChannel.on("ids",e=>this.select=e)
this.init()
if(this.type=='pestis'){
this.init()
}else{
this.searchDisease()
}
},
methods:{
async init(){
@ -182,7 +190,7 @@ export default {
this.list=[]
uni.showModal({
title:"提示",
content:res.msg||"获取种植计划选项失败!",
content:res.msg||"获取虫害失败!",
showCancel:false,
})
}
@ -204,7 +212,7 @@ export default {
this.list=[]
uni.showModal({
title:"提示",
content:res.msg||"获取种植计划选项失败!",
content:res.msg||"获取虫害失败!",
showCancel:false,
})
}
@ -213,6 +221,21 @@ export default {
}
}
},
async searchDisease(){
var res=await request("/api/plantFarming/getDiseaseByLike",{
params:{search: this.searchVal.search}
})
if(res.statu){
this.list=res.data.map(v=>({id:v.id,name:v.dictName}))
}else{
uni.showModal({
title:"提示",
content:res.msg||"获取病害失败!",
showCancel:false,
})
}
},
submit(){
if(this.select.length>0){
this.eventChannel.emit("type", this.select)
@ -226,21 +249,39 @@ export default {
}
},
async addPest(e){
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(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:"添加虫害失败!",
showCancel:false,
})
}
})
if(res.statu){
this.list.push(e)
}else{
uni.showModal({
title:"提示",
content:"添加害虫失败!",
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:"添加病害失败!",
showCancel:false,
})
}
}
},
selectPest(e){

21
uni_modules/d-form/components/d-form/d-form.vue

@ -280,16 +280,16 @@
</style>
<template>
<view class="d-form" :class="{parallel:styleType=='parallel'}">
<u-form-item :class="{tip:!!tip}" :label="label" :prop="field" :required="required">
<u-form-item :class="{tip:!!tip}" :label="labelName" :prop="field" :required="required">
<view v-if="/^text$|^number$|^digit$|^password$/.test(type)" class="textinput">
<u-input :placeholder="placeholder||`请输入${label}`" :type="type" :disabled="disabled" :value="value" @input="$emit('input',$event)" @blur="/^number$|^digit$/.test(type) && $emit('input', parseFloat($event)||'')">
<u-input :placeholder="placeholder||`请输入${labelName}`" :type="type" :disabled="disabled" :value="value" @input="$emit('input',$event)" @blur="/^number$|^digit$/.test(type) && $emit('input', parseFloat($event)||'')">
<text v-if="suffix" slot="suffix" style="color:#999;">{{suffix}}</text>
</u-input>
<button v-if="btnText || btnIcon" @click="btnFun" class="cu-btn bg-green shadow" :class="btnIcon">{{btnText}}</button>
</view>
<view v-else-if="type=='map'" class="map plant-dingweixiao" :class="{noData:value.length<=0}" @click="openMap">{{value.length>0?Object.values(value[0]).join():"选择经纬度"}}</view>
<view v-else-if="type=='select'" class="plant-youbian" :class="{noData: !value[0]}" @click="show=true">{{pickerContent}}</view>
<view v-else-if="type=='navigate'" class="navigate plant-youbian" :class="{noData:!value}" @click="btnFun">{{value||placeholder||`请选择${label}`}}</view>
<view v-else-if="type=='navigate'" class="navigate plant-youbian" :class="{noData:!value}" @click="btnFun">{{value||placeholder||`请选择${labelName}`}}</view>
<view v-else-if="type=='select-tab'" class="select-tab">
<text :class="{active:value==v.value}" v-for="(v,k) in dictCodeList" :key="k" @click="$emit('select',[v])">{{v.label}}</text>
<text @click="show=true">自定义+</text>
@ -299,7 +299,7 @@
<text class="plant-paizhao">添加照片</text>
</view>
</u-upload>
<textarea v-else-if="type=='textarea'" auto-height :value="value" :placeholder="placeholder||`请输入${label}`" @input="$emit('input',$event.detail.value)"/>
<textarea v-else-if="type=='textarea'" auto-height :value="value" :placeholder="placeholder||`请输入${labelName}`" @input="$emit('input',$event.detail.value)"/>
<view v-else-if="type=='dateRange'" class="dateRange">
<text style="margin-right:20rpx;" :class="{noData:!value[0]}" @click="dateType='start';show=true">{{value[0]||startPlaceholder||'开始时间'}}</text>
-
@ -315,7 +315,7 @@
<u-checkbox :customStyle="{marginRight: '30rpx'}" v-for="(v, k) in columns" :key="k" activeColor="#D9F6E9" iconColor="#10C176" :label="v.label" :name="v.value" />
</u-checkbox-group>
</view>
<view v-else-if="type=='calendar'" class="calendar" @click="$refs.calendar.open()" :class="{noData:!value}">{{value||placeholder||`请选择${label}`}} <text class="plant-rili"/></view>
<view v-else-if="type=='calendar'" class="calendar" @click="$refs.calendar.open()" :class="{noData:!value}">{{value||placeholder||`请选择${labelName}`}} <text class="plant-rili"/></view>
<view class="tip" v-if="tip">{{tip}}</view>
</u-form-item>
@ -409,7 +409,7 @@ import {computeArea} from '@/common/utils'
export default{
props:{
label:{
type:String,
type:[String,Function],
default:"",
},
suffix:{
@ -518,6 +518,9 @@ import {computeArea} from '@/common/utils'
}
},
computed:{
labelName(){
return typeof this.label=='string'?this.label:this.label()
},
date(){
if(this.dateType=='start')return this.value[0]||new Date().format('yyyy-MM-dd');
else return this.value[1]||new Date().format('yyyy-MM-dd');
@ -534,7 +537,7 @@ import {computeArea} from '@/common/utils'
},
pickerContent(){//
if(this.type=='select'){
return this.$defineArray(setPickerVal(this.columns[0], this.value).filter(v=>v)).at(-1)?.label||this.placeholder||`请选择${this.label}`
return this.$defineArray(setPickerVal(this.columns[0], this.value).filter(v=>v)).at(-1)?.label||this.placeholder||`请选择${this.labelName}`
}
return ''
},
@ -565,7 +568,7 @@ import {computeArea} from '@/common/utils'
}else{
uni.showModal({
title:"提示",
content:res.msg||`获取${this.label}选项失败!`,
content:res.msg||`获取${this.labelName}选项失败!`,
showCancel:false,
})
}
@ -584,7 +587,7 @@ import {computeArea} from '@/common/utils'
}else{
uni.showModal({
title:"提示",
content:res.msg||`添加${this.label}失败!`,
content:res.msg||`添加${this.labelName}失败!`,
showCancel:false,
})
}

Loading…
Cancel
Save