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.

132 lines
3.7 KiB

2 years ago
<style lang="scss">
2 years ago
.container{
min-height:100%;
background:#f6f6f6;
padding:30rpx 0;
2 years ago
}
</style>
<template>
2 years ago
<view class="container">
2 years ago
<d-navbar text="采收信息" style="--bg:#10C176;--c:#fff;" isBack>
<button slot="right" class="cu-btn round" @click="submit">提交</button>
2 years ago
</d-navbar>
2 years ago
<u-form class="card inline" errorType="toast" :model="formData" :rules="rules" ref="form" labelWidth="auto">
2 years ago
<d-form
v-for="(v,k) in fields"
:key="k"
v-bind="v"
:field="k"
:required="!!rules[k]"
2 years ago
:value="/^select$/.test(v.type)?fields[k].value:formData[k]"
@select="fields[k].value=$event.map(v=>v.value);formData[k]=fields[k].value[0]"
2 years ago
@input="formData[k]=$event"/>
2 years ago
</u-form>
</view>
</template>
<script>
import request from '@/common/request'
2 years ago
export default {
data(){
return{
fields:{
2 years ago
harvestNum:{label:"采收数量",suffix:'kg',type:"digit"},
harvestBatch:{label:"收获批次号",btnText:"生成", btnFun:()=>this.formData.harvestBatch=`CS${new Date().format('yyyyMMdd')}${new Date().getTime()}`},
2 years ago
principal:{label:"负责人",type:"select",columns:[],value:[]},
harvestTime:{label:"采收时间",type:"calendar"},
status:{label:"采收状态",type:"select",columns:[],value:[]},
2 years ago
warehouseId:{label:"仓库",type:"select",columns:[],value:[]},
2 years ago
},
formData:{
harvestNum:"",
harvestBatch:"",
principal:"",
harvestTime:"",
status:"",
2 years ago
warehouseId:"",
plantSchedulId:"",//种植计划id
2 years ago
plotId:"",//地块id
2 years ago
},
rules:{
2 years ago
harvestNum: {required:true, type:"number", message:"采收数量必填!", trigger:"blur"},
harvestBatch:{required:true, message:"收获批次号必填!", trigger:"blur"},
principal:{required:true, message:"负责人必填!", trigger:"blur"},
harvestTime:{required:true, message:"采收时间必填!", trigger:"blur"},
status:{required:true, message:"采收状态必填!", trigger:"blur"},
warehouseId:{required:true, message:"仓库必选!"},
2 years ago
},
eventChannel:null,
2 years ago
}
},
onLoad(options){
2 years ago
this.eventChannel=this.getOpenerEventChannel()
this.formData.plantSchedulId=options.plantId
this.formData.plotId=options.plotId
2 years ago
this.init()
},
methods:{
2 years ago
async init(){
var res=await request("/api/plantHarvest/getUser")
if(res.statu){
this.fields.principal.columns=[res.data.map(v=>({label:v,value:v}))]
}else{
uni.showModal({
title:"提示",
content:res.msg||"获取负责人选项失败!",
showCancel:false,
})
}
2 years ago
//仓库 下拉选
var res=await request("/api/plantHarvest/getWarehouse",{
2 years ago
params:{
plantBaseId:this.$store.state.baseInfo.id,
2 years ago
type:2,//1 农资,2 农产品
}
2 years ago
})
if(res.statu){
this.fields.warehouseId.columns=[res.data.map(v=>({label:v.warehouseName,value:v.id}))]
}else{
uni.showModal({
title:"提示",
content:res.msg||"获取仓库选项失败!",
showCancel:false,
})
}
// 采收状态
var res=await request("/common/api/dict/queryDictItemByDictCode",{
method:"post",
params:{dictCode:"harvest_status"}
})
if(res.statu){
this.fields.status.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("/api/plantHarvest/add",{
method:"post",
body: this.formData
})
if(res.statu){
2 years ago
uni.navigateBack()
2 years ago
this.eventChannel.emit('toRecovery')
2 years ago
}else{
uni.showModal({
title:"提示",
content:res.msg||"保存失败失败!",
showCancel:false,
})
}
}
})
},
},
2 years ago
}
</script>