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

18
components/form.vue

@ -141,25 +141,25 @@
<view class="d-form"> <view class="d-form">
<u-form-item :class="{tip:!!tip}" :label="label" :prop="field" :required="required"> <u-form-item :class="{tip:!!tip}" :label="label" :prop="field" :required="required">
<view v-if="/^text$|^number$|^digit$/.test(type)" class="textinput"> <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> <text v-if="suffix" slot="suffix">{{suffix}}</text>
</u-input> </u-input>
<button v-if="btnText" @click="btnFun" class="cu-btn bg-green shadow">{{btnText}}</button> <button v-if="btnText" @click="btnFun" class="cu-btn bg-green shadow">{{btnText}}</button>
</view> </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"> <u-upload v-if="type=='upImg'" :fileList="imgs" previewFullImage multiple :maxCount="num" @delete="delImg" @afterRead="afterRead">
<view class="album"> <view class="album">
<text class="plant-paizhao">添加照片</text> <text class="plant-paizhao">添加照片</text>
</view> </view>
</u-upload> </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"> <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-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> <text style="margin-left:20rpx;" :class="{noData:!value[1]}" @click="dateType='end';show=true">{{value[1]||endPlaceholder||'结束时间'}}</text>
</view> </view>
<view v-if="type=='checkBox'" class="checkBox"> <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 :customStyle="{marginRight: '30rpx'}" v-for="(v, k) in columns" :key="k" activeColor="#D9F6E9" iconColor="#10C176" :label="v.label" :name="v.value" />
</u-checkbox-group> </u-checkbox-group>
</view> </view>
@ -171,7 +171,7 @@
v-if="type=='select'" v-if="type=='select'"
:columns="columns" :columns="columns"
:show="show" :show="show"
:keyName="keyName" keyName="label"
:defaultIndex="[value||0]" :defaultIndex="[value||0]"
closeOnClickOverlay closeOnClickOverlay
@close="show=false" @close="show=false"
@ -225,10 +225,6 @@ import request,{host} from '@/common/request'
type:String, type:String,
default:"", default:"",
}, },
keyName:{
type:String,
default:"label",
},
type:{ type:{
type:String, type:String,
default:"text" default:"text"
@ -288,14 +284,14 @@ import request,{host} from '@/common/request'
}))) })))
for(var i=0; i<e.file.length;i++){ for(var i=0; i<e.file.length;i++){
var res=await request('/sys/common/upload',{ var res=await request('/sys/common/upload',{
file:e.file[i] filePath:e.file[i].url
}) })
if(res.statu ||true){ if(res.statu ||true){
this.imgList.some((v,k)=>{ this.imgList.some((v,k)=>{
if(v==e.file[i]){ if(v==e.file[i]){
v.status='success' v.status='success'
v.message='' v.message=''
v.tempUrl=res.data.data v.tempUrl=res.data
this.$set(this.imgList,k,this.imgList[k]) this.$set(this.imgList,k,this.imgList[k])
return true return true
} }

57
pages/massif/info.vue

@ -14,27 +14,29 @@
v-bind="v" v-bind="v"
:required="!!rules[k]" :required="!!rules[k]"
:field="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" @input="formData[k]=$event"
@selectRDate="selectDate" @selectRDate="selectDate"
@select="fields[k].value=$event;formData[k]=fields[k].columns[0][$event].value"
@imgs="fields[k].value=$event"/> @imgs="fields[k].value=$event"/>
</u-form> </u-form>
<button class="cu-btn round bg-green shadow submit" @click="sumbit">保存</button> <button class="cu-btn round bg-green shadow submit" @click="sumbit">保存</button>
</view> </view>
</template> </template>
<script> <script>
import request from '@/common/request'
import dForm from '@/components/form.vue' import dForm from '@/components/form.vue'
export default{ export default{
components:{dForm}, components:{dForm},
data(){ data(){
return{ return{
fields:{ fields:{
plantBaseName:{label:"基地名称"}, plantBaseName:{label:"基地名称",type:"select",columns:[],value:''},
plotNumber:{label:"地块编号"}, plotNumber:{label:"地块编号"},
plotName:{label:"地块名称"}, plotName:{label:"地块名称"},
drawArea:{label:"地块面积(亩)",type:'digit'}, drawArea:{label:"地块面积(亩)",type:'digit'},
realityArea:{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:[]}, date:{label:"使用日期",type:"dateRange",value:[]},
jw:{label:"经/纬度"}, jw:{label:"经/纬度"},
address:{label:"详细地址",type:"textarea"}, address:{label:"详细地址",type:"textarea"},
@ -43,8 +45,8 @@ import dForm from '@/components/form.vue'
plantBaseName:"", plantBaseName:"",
plotNumber:"", plotNumber:"",
plotName:"", plotName:"",
drawArea:0, drawArea:'',
realityArea:0, realityArea:'',
image:[], image:[],
beginTime:"", beginTime:"",
endTime:"", endTime:"",
@ -53,21 +55,41 @@ import dForm from '@/components/form.vue'
address:"", address:"",
}, },
rules:{ rules:{
plantBaseName:{required:true, message:"基地名称必填!", trigger:"blue"}, plantBaseName:{required:true, message:"基地名称必填!", trigger:"change"},
plotNumber:{required:true, message:"地块编号必填!", trigger:"blue"}, plotNumber:{required:true, message:"地块编号必填!", trigger:"blur"},
plotName:{required:true, message:"地块名称必填!", trigger:"blue"}, plotName:{required:true, message:"地块名称必填!", trigger:"blur"},
drawArea:{required:true, message:"地块面积必填!", trigger:"blue"}, drawArea:{required:true, type:'number', message:"地块面积必填!", trigger:"blur"},
realityArea:{required:true, message:"实际面积必填!", trigger:"blue"}, realityArea:{required:true, type:'number', message:"实际面积必填!", trigger:"blur"},
image:{required:true, type:"array",min:1, message:"地块图片必填!", trigger:"blue"}, 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)=>{ date:{required:true,validator:(rule,val,call)=>{
if(!this.fields.date.value[0])call(new Error('请选择开始时间!')); if(!this.fields.date.value[0])call(new Error('请选择开始时间!'));
else if(!this.fields.date.value[1])call(new Error('请选择结束时间!')); else if(!this.fields.date.value[1])call(new Error('请选择结束时间!'));
else call() else call()
}, trigger:"blue"} }, trigger:"change"}
}, },
} }
}, },
onLoad(){
this.init()
},
methods:{ 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){ selectDate(e){
switch(e.type){ switch(e.type){
case "start":this.fields.date.value[0]=e.value;break; case "start":this.fields.date.value[0]=e.value;break;
@ -77,7 +99,16 @@ import dForm from '@/components/form.vue'
sumbit(){ sumbit(){
this.$refs.form.validate().then(async valid=>{ this.$refs.form.validate().then(async valid=>{
if(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