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.
 
 
 
 
 

166 lines
4.7 KiB

<style lang="scss">
.container{
min-height:100%;
background:#f6f6f6;
padding:30rpx 0;
.info{
margin-top:0;
.name{
display:flex;
align-items: center;
text{
&:first-child{
color:#fff;
background:#10C176;
border-radius: 0 20rpx 0 20rpx;
padding:0 6rpx;
font-size:20rpx;
height:40rpx;
line-height: 40rpx;
margin-right: 20rpx;
}
}
}
.tip{
display:flex;
align-items: center;
margin-top:6rpx;
text{
&:first-child{
color:#FBA83C;
font-size:24rpx;
margin-right:auto;
}
&:nth-child(2){
color:#999;
font-size:20rpx;
}
}
}
}
}
</style>
<template>
<view class="container">
<view class="card info">
<view class="name">
<text>{{detail.plantTypeName}}</text> <text>{{detail.plantName}}</text>
</view>
<view class="tip">
<text>提示当前可交易重量{{detail.harvestNum||0}}kg</text> <text>采收日期{{detail.harvestTime}}</text>
</view>
</view>
<view class="card">
<u-form class="inline" errorType="toast" :model="formData" ref="form" :rules="rules" labelWidth="auto">
<d-form label="交易重量" required field="tradeWeight" type="digit" suffix="kg" :value="formData.tradeWeight" @input="formData.tradeWeight=$event"/>
<view style="display:flex;align-items: center;">
<d-form label="规格" required field="specification" type="digit" suffix="kg" :value="formData.specification" @input="formData.specification=$event"/>
<text style="margin:45rpx 20rpx 0 20rpx;">/</text>
<d-form style="width:max-content;margin-top:40rpx;" type="select" placeholder=" " @select="formData.packUnit=$event.value[0].value" :columns="[packWeightList]" :value="[formData.packUnit]"/>
</view>
<d-form label="交易数量" type="digit" suffix="袋" required field="tradeNum" :value="formData.tradeNum" @input="formData.tradeNum=$event"/>
<d-form label="买方名称" required field="buyerName" :value="formData.buyerName" @input="formData.buyerName=$event"/>
<d-form label="买方类型" required field="buyerType" type="select" :columns="[buyerType.list]" :value="buyerType.value" @select="buyerType.value=$event.value.map(v=>v.value);formData.buyerType=buyerType.value[1]"/>
<d-form label="收货地址" required field="buyerAddress" type="textarea" :value="formData.buyerAddress" @input="formData.buyerAddress=$event"/>
</u-form>
</view>
<button class="cu-btn round bg-green shadow submit" @click="sumbit">保存</button>
</view>
</template>
<script>
import request from '@/common/request'
export default {
data(){
return{
buyerType:{list:[],value:[]},
packWeightList:[],
detail:{},
formData:{
harvestId:"",
tradeWeight:"",
specification:"",
packUnit:"",
tradeNum:"",
buyerName:"",
buyerType:"",
buyerAddress:"",
},
rules:{
tradeWeight:{required:true,validator:(rule,val,call)=>{
if(!(val>0))call(new Error('交易重量必填!'));
else if(val>this.detail.harvestNum)call(new Error(`交易重量不能大于可交易重量${this.detail.harvestNum}`));
else call()
}},
specification:{required:true,message:"规格必填!"},
tradeNum:{required:true,message:"交易数量必填!",type:"number"},
buyerName:{required:true,message:"买方名称必填!"},
buyerType:{required:true,message:"交易类型必选!"},
buyerAddress:{required:true,message:"收货地址必填!"},
},
}
},
onLoad(options){
var eventChannel=this.getOpenerEventChannel()
eventChannel.on("detail", e=>{
this.detail=e
this.formData.harvestId=e.id
})
this.init()
},
methods:{
async init(){
//规格
var res = await request("/common/api/dict/queryDictItemByDictCode",{
method:"post",
params:{dictCode:"dressing_unit"}
})
if(res.statu){
this.packWeightList=res.data
this.formData.packUnit=res.data[0].value
}else{
uni.showModal({
title:"提示",
content:res.msg||"获取规格选项失败!",
showCancel:false,
})
}
//买方类型
var res = await request("/common/api/dict/categoryValue",{
method:"post",
params:{code:"B08"}
})
if(res.statu){
this.buyerType.list=res.data
}else{
uni.showModal({
title:"提示",
content:res.msg||"获取买方类型选项失败!",
showCancel:false,
})
}
},
sumbit(){
this.$refs.form.validate().then(async valid=>{
if(valid){
var res=await request("/api/plantTrade/add",{
method:"post",
body: this.formData
})
if(res.statu){
uni.navigateBack()
}else{
uni.showModal({
title:"提示",
content:res.msg||"保存失败!",
showCancel:false,
})
}
}
})
},
}
}
</script>