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.

135 lines
3.5 KiB

2 years ago
<style lang="scss">
2 years ago
.container{
2 years ago
background:#F6F6F6;
min-height: 100%;
padding:30rpx 0;
.card{
min-height:1000rpx;
}
}
</style>
<template>
2 years ago
<view class="container">
<u-form class="card inline" errorType="toast" labelWidth="auto" :model="formData" :rules="rules" ref="form">
2 years ago
<d-form
v-for="(v,k) in fields"
:key="k"
v-bind="v"
:field="k"
:required="!!rules[k]"
:value="/^select$/.test(v.type)?fields[k].value:formData[k]"
2 years ago
@input="formData[k]=$event"
@select="fields[k].value=$event.map(v=>v.value);formData[k]=fields[k].value.slice(-1)[0]"/>
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'
2 years ago
export default {
data(){
return{
fields:{
2 years ago
goodsName:{label:"物品名称"},
massUnits:{label:"物品单位",type:"select",columns:[],value:[]},
goodsType:{label:"物品类型",type:"select",columns:[],value:['1'],disabled:true},
supplier:{label:"供应商",btnIcon:"plant-sousuo", btnFun:()=>{
uni.navigateTo({
url:`/pages/purchase/search?data=${this.formData.supplier}`,
events:{update:e=>this.formData.supplier=e||this.formData.supplier}
})
}},
2 years ago
detailedType:{label:"详情类型",type:"select",columns:[],value:[]},
2 years ago
remarks:{label:"备注",type:"textarea"},
},
2 years ago
formData:{
goodsName:"",
massUnits:"",
goodsType:"1",
2 years ago
supplier:"",
detailedType:"",
remark:"",
},
2 years ago
rules:{
2 years ago
goodsName:{required:true, message:"物品名称必填!", trigger:"blur"},
massUnits:{required:true, message:"物品单位必选!", trigger:"blur"},
goodsType:{required:true, message:"物品类型必选!", trigger:"blur"},
2 years ago
supplier:{required:true, message:"供应商必填!", trigger:"blur"},
2 years ago
detailedType:{required:true, message:"详情类型必选!", trigger:"blur"},
},
eventChannel:null,
}
},
onLoad(options){
this.eventChannel=this.getOpenerEventChannel()
this.init()
},
methods:{
async init(){
var res=await request("/common/api/dict/queryDictItemByDictCode",{
2 years ago
method:"post",
params:{dictCode:'mass_units'}
2 years ago
})
if(res.statu){
this.fields.massUnits.columns=[res.data.map(v=>({label:v.text,value:v.value}))]
}else{
uni.showModal({
title:"提示",
content:res.msg||"获取物品单位下拉选项失败!",
showCancel:false,
})
}
var res=await request("/common/api/dict/queryDictItemByDictCode",{
2 years ago
method:"post",
params:{dictCode:'goods_type'}
2 years ago
})
if(res.statu){
this.fields.goodsType.columns=[res.data.map(v=>({label:v.text,value:v.value}))]
}else{
uni.showModal({
title:"提示",
content:res.msg||"获取物品类型下拉选项失败!",
showCancel:false,
})
}
var res=await request("/common/api/dict/categoryValue",{
2 years ago
method:"post",
params:{code:'B07'}
2 years ago
})
if(res.statu){
this.fields.detailedType.columns=[res.data]
}else{
uni.showModal({
title:"提示",
content:res.msg||"获取物品类型下拉选项失败!",
showCancel:false,
})
2 years ago
}
2 years ago
},
submit(){
this.$refs.form.validate().then(async valid=>{
if(valid){
var res=await request("/goods/goods/add",{
method:"post",
body: this.formData
})
if(res.statu){
this.eventChannel.emit("update")
uni.navigateBack()
}else{
uni.showModal({
title:"提示",
content:res.msg||"保存失败!",
showCancel:false,
})
}
}
})
2 years ago
}
}
}
</script>