You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

149 lines
4.9 KiB

2 years ago
<style lang="scss" scoped>
2 years ago
.container{
2 years ago
background:#F6F6F6;
padding:28rpx 0;
2 years ago
}
</style>
<template>
2 years ago
<view class="container">
2 years ago
<u-form class="card inline" errorType="toast" :model="formData" ref="form" :rules="rules" labelWidth="auto">
<d-form
v-for="(v,k) in fields"
:key="k"
v-bind="v"
:required="!!rules[k]"
:field="k"
:value="/^select$/.test(v.type)?fields[k].value:formData[k]"
@input="formData[k]=$event"
@select="fields[k].value=$event.value.map(v=>v.value);formData[k]=$event.value[0].value"
@imgs="fields[k].value=$event"/>
2 years ago
</u-form>
2 years ago
<button class="cu-btn round bg-green shadow submit" @click="submit">确认提交</button>
2 years ago
</view>
</template>
<script>
2 years ago
import request from '@/common/request.js'
2 years ago
export default{
data(){
return{
fields:{
2 years ago
warehouseName:{label:"仓库名称"},
warehouseNo:{label:"仓库编号"},
2 years ago
warehouseAddress:{label:"仓库位置",type:"textarea"},
2 years ago
warehouseVolume:{label:"仓库容量(㎡)", type:"digit",placeholder:"请输入仓库容量"},
goodsType:{label:"存储物品类型",type:"select",columns:[],value:[]},
warehouseType:{label:"仓库类型",type:"select",columns:[],value:[]},
contactPeople:{label:"基地管理员", disabled:this.$store.getters['userInfo'].roleCode=="baseAdmin"},
contactNumber:{label:"管理员联系方式", disabled:this.$store.getters['userInfo'].roleCode=="baseAdmin"},
2 years ago
warehousePic:{label:"仓库图片",type:"upImg",num:3},
2 years ago
},
formData:{
2 years ago
warehouseName:"",
warehouseNo:'',
2 years ago
warehouseAddress:"",
warehouseVolume:"",
goodsType:'',
2 years ago
warehouseType:"",
2 years ago
contactPeople:"",
contactNumber:"",
2 years ago
warehousePic:[],
baseId: this.$store.state.plantBaseInfoId,
2 years ago
},
rules:{
2 years ago
warehouseName:{required:true, message:"仓库名称必填!", trigger:["blur","change"]},
warehouseNo: {required:true, message:"种植编号必填!", trigger:"blur"},
2 years ago
warehouseAddress:{required:true, message:"仓库位置必填!", trigger:["blur","change"]},
warehouseVolume:{required:true, message:"仓库容量必填!", type:"number", trigger:["blur","change"]},
goodsType:{required:true, message:"存储物品类型必填!", trigger:["blur","change"]},
2 years ago
warehouseType:{required:true, message:"仓库类型必选!", trigger:["blur","change"]},
contactPeople:{required:true, message:"基地管理员必填!", trigger:["blur","change"]},
contactNumber:{required:true, validator(rule,val,call){
if(!val)call(new Error("管理员联系方式必填!"));
else if(!/^1(3\d|4[5-9]|5[0-35-9]|6[567]|7[0-8]|8\d|9[0-35-9])\d{8}$/.test(val))call(new Error("请输入正确联系方式格式!"))
else call();
}, trigger:["blur","change"]},
warehousePic:{required:true, validator(rule,val,call){
if(!this.fields.warehousePic)call(new Error("仓库图片必选!"))
else call()
}, trigger:["blur","change"]},
2 years ago
},
eventChannel:null,
2 years ago
}
},
onLoad(options){
this.eventChannel=this.getOpenerEventChannel()
2 years ago
this.init()
this.eventChannel.on("detail", e=>{
if(e){
this.formData=e
this.fields.warehousePic.value=e.warehousePic.join(',')
this.fields.warehouseType.value=[e.warehouseType]
this.fields.goodsType.value=[e.goodsType]
}else if(this.$store.getters['userInfo'].roleCode=="baseAdmin"){
this.formData.contactPeople=this.$store.getters['userInfo'].realname
this.formData.contactNumber=this.$store.getters['userInfo'].phone
}
})
2 years ago
},
2 years ago
methods:{
2 years ago
async init(){
2 years ago
//仓库类型
2 years ago
var res=await request("/common/api/dict/queryDictItemByDictCode",{
method:"post",
params:{dictCode: "warehouse_type"}
})
2 years ago
if(res.statu){
2 years ago
this.fields.warehouseType.columns=[res.data]
2 years ago
}else{
uni.showModal({
title:"提示",
content:res.msg||"获取仓库类型选项失败!",
showCancel:false,
})
}
2 years ago
//存储物品类型
var res=await request("/common/api/dict/queryDictItemByDictCode",{
method:"post",
params:{dictCode: "goods_type"}
})
if(res.statu){
this.fields.goodsType.columns=[res.data]
2 years ago
}else{
uni.showModal({
title:"提示",
content:res.msg||"获取仓库类型选项失败!",
showCancel:false,
})
}
2 years ago
},
submit(){
this.$refs.form.validate().then(async valid=>{
if(valid){
var res=await request("/api/WarehouseManageApi/addOrUpdate",{
2 years ago
method:"post",
body:{
...this.formData,
warehousePic: this.fields.warehousePic.value
}
})
if(res.statu){
this.eventChannel.emit("update")
uni.navigateBack()
//新增仓库,首页刷新
if(!this.formData.id){
this.$provise.emit("updateStock")
}
2 years ago
}else{
uni.showModal({
title:"提示",
content:res.msg||"保存失败!",
showCancel:false,
})
}
}
})
},
2 years ago
},
}
</script>