Browse Source

地块基本信息 联调保存接口

master
邓宏 2 years ago
parent
commit
e3bdcf4bb7
  1. 7
      common/request.js
  2. 18
      components/form.vue
  3. 57
      pages/massif/info.vue

7
common/request.js

@ -3,7 +3,7 @@ import store from "@/store"
export function host(host='default',suffix='/plant_manage'){
return(
process.env.NODE_ENV === 'development'?{
default:`http://qv6mj8.natappfree.cc${suffix}`
default:`http://m3df6f.natappfree.cc${suffix}`
}:{
default:`http://qv6mj8.natappfree.cc${suffix}`
}
@ -29,10 +29,11 @@ const request=async function(url,param={}){
"X-Access-Token":store.getters.token,
}
if(param.file){
if(param.file||param.filePath){
var res=await uni.uploadFile({
url:`${param.host||host()}${('/'+url).replace(/\/{2}/,'/').replace(/\?.+/,"")}?${pathData}`,
file:param.file,
file:param.file||{},
filePath:param.filePath||"",
name:"file",
formData:param.body||{},
timeout:param.timeout||60*1000,

18
components/form.vue

@ -141,25 +141,25 @@
<view class="d-form">
<u-form-item :class="{tip:!!tip}" :label="label" :prop="field" :required="required">
<view v-if="/^text$|^number$|^digit$/.test(type)" class="textinput">
<u-input :placeholder="placeholder||`请输入${label}`" :type="type" :value="value" @input="$emit('input',e)">
<u-input :placeholder="placeholder||`请输入${label}`" :type="type" :value="value" @input="$emit('input',$event)" @blur="/^number$|^digit$/.test(type) && $emit('input',parseFloat(value)||'')">
<text v-if="suffix" slot="suffix">{{suffix}}</text>
</u-input>
<button v-if="btnText" @click="btnFun" class="cu-btn bg-green shadow">{{btnText}}</button>
</view>
<view v-if="type=='select'" class="plant-youbian" :class="{noData:!/^\d+$/.test(value)}" @click="show=true">{{/^\d+$/.test(value)&&columns[0][value][keyName]||placeholder||`请选择${label}`}}</view>
<view v-if="type=='select'" class="plant-youbian" :class="{noData:!/^\d+$/.test(value)}" @click="show=true">{{/^\d+$/.test(value)&&columns[0][value].label||placeholder||`请选择${label}`}}</view>
<u-upload v-if="type=='upImg'" :fileList="imgs" previewFullImage multiple :maxCount="num" @delete="delImg" @afterRead="afterRead">
<view class="album">
<text class="plant-paizhao">添加照片</text>
</view>
</u-upload>
<textarea v-if="type=='textarea'" auto-height :value="value" :placeholder="placeholder||`请输入${label}`" @input="$emit('input',e)"/>
<textarea v-if="type=='textarea'" auto-height :value="value" :placeholder="placeholder||`请输入${label}`" @input="$emit('input',$event.detail.value)"/>
<view v-if="type=='dateRange'" class="dateRange">
<text style="margin-right:20rpx;" :class="{noData:!value[0]}" @click="dateType='start';show=true">{{value[0]||startPlaceholder||'开始时间'}}</text>
-
<text style="margin-left:20rpx;" :class="{noData:!value[1]}" @click="dateType='end';show=true">{{value[1]||endPlaceholder||'结束时间'}}</text>
</view>
<view v-if="type=='checkBox'" class="checkBox">
<u-checkbox-group :value="[]" @change="$emit('select',e)" >
<u-checkbox-group :value="[]" @change="$emit('select',$event)" >
<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>
@ -171,7 +171,7 @@
v-if="type=='select'"
:columns="columns"
:show="show"
:keyName="keyName"
keyName="label"
:defaultIndex="[value||0]"
closeOnClickOverlay
@close="show=false"
@ -225,10 +225,6 @@ import request,{host} from '@/common/request'
type:String,
default:"",
},
keyName:{
type:String,
default:"label",
},
type:{
type:String,
default:"text"
@ -288,14 +284,14 @@ import request,{host} from '@/common/request'
})))
for(var i=0; i<e.file.length;i++){
var res=await request('/sys/common/upload',{
file:e.file[i]
filePath:e.file[i].url
})
if(res.statu ||true){
this.imgList.some((v,k)=>{
if(v==e.file[i]){
v.status='success'
v.message=''
v.tempUrl=res.data.data
v.tempUrl=res.data
this.$set(this.imgList,k,this.imgList[k])
return true
}

57
pages/massif/info.vue

@ -14,27 +14,29 @@
v-bind="v"
:required="!!rules[k]"
:field="k"
:value="({dateRange:fields.date.value})[v.type||'text']||formData[k]"
:value="(/^dateRange$|^select$/.test(v.type)?fields[k].value:formData[k])"
@input="formData[k]=$event"
@selectRDate="selectDate"
@select="fields[k].value=$event;formData[k]=fields[k].columns[0][$event].value"
@imgs="fields[k].value=$event"/>
</u-form>
<button class="cu-btn round bg-green shadow submit" @click="sumbit">保存</button>
</view>
</template>
<script>
import request from '@/common/request'
import dForm from '@/components/form.vue'
export default{
components:{dForm},
data(){
return{
fields:{
plantBaseName:{label:"基地名称"},
plantBaseName:{label:"基地名称",type:"select",columns:[],value:''},
plotNumber:{label:"地块编号"},
plotName:{label:"地块名称"},
drawArea:{label:"地块面积(亩)",type:'digit'},
realityArea:{label:"实际面积",type:'digit'},
image:{label:"地块图片",type:"upImg",num:3},
image:{label:"地块图片",type:"upImg",num:3,value:[]},
date:{label:"使用日期",type:"dateRange",value:[]},
jw:{label:"经/纬度"},
address:{label:"详细地址",type:"textarea"},
@ -43,8 +45,8 @@ import dForm from '@/components/form.vue'
plantBaseName:"",
plotNumber:"",
plotName:"",
drawArea:0,
realityArea:0,
drawArea:'',
realityArea:'',
image:[],
beginTime:"",
endTime:"",
@ -53,21 +55,41 @@ import dForm from '@/components/form.vue'
address:"",
},
rules:{
plantBaseName:{required:true, message:"基地名称必填!", trigger:"blue"},
plotNumber:{required:true, message:"地块编号必填!", trigger:"blue"},
plotName:{required:true, message:"地块名称必填!", trigger:"blue"},
drawArea:{required:true, message:"地块面积必填!", trigger:"blue"},
realityArea:{required:true, message:"实际面积必填!", trigger:"blue"},
image:{required:true, type:"array",min:1, message:"地块图片必填!", trigger:"blue"},
plantBaseName:{required:true, message:"基地名称必填!", trigger:"change"},
plotNumber:{required:true, message:"地块编号必填!", trigger:"blur"},
plotName:{required:true, message:"地块名称必填!", trigger:"blur"},
drawArea:{required:true, type:'number', message:"地块面积必填!", trigger:"blur"},
realityArea:{required:true, type:'number', message:"实际面积必填!", trigger:"blur"},
image:{required:true, type:"array", min:1, validator:(rule,val,call)=>{
if(this.fields.image.value.length<=0)call(new Error('地块图片必选!'));
else call()
}, trigger:"change"},
date:{required:true,validator:(rule,val,call)=>{
if(!this.fields.date.value[0])call(new Error('请选择开始时间!'));
else if(!this.fields.date.value[1])call(new Error('请选择结束时间!'));
else call()
}, trigger:"blue"}
}, trigger:"change"}
},
}
},
onLoad(){
this.init()
},
methods:{
async init(){
var res=await request("/api/plantPlot/getAllPlantBaseInfo",{
params:{companyId:this.$store.getters.userInfo.companyId}
})
if(res.statu){
this.$set(this.fields.plantBaseName, "columns", [res.data.map(v=>({label:v,value:v}))])
}else{
uni.showModal({
title:"提示",
content:res.msg||"获取基地名称下拉选项失败!",
showCancel:false,
})
}
},
selectDate(e){
switch(e.type){
case "start":this.fields.date.value[0]=e.value;break;
@ -77,7 +99,16 @@ import dForm from '@/components/form.vue'
sumbit(){
this.$refs.form.validate().then(async valid=>{
if(valid){
var res=await request("/api/plantPlot/addOrUpdate",{
method:"post",
body:{
...this.formData,
image:this.fields.image.value,
beginTime:this.fields.date.value[0],
endTime:this.fields.date.value[1],
}
})
console.log(res,'----------res------------')
}
})
}

Loading…
Cancel
Save