Browse Source

农资规格 修改选择规格判断

master
邓宏 2 years ago
parent
commit
6368f5c888
  1. 12
      pages/massif/add_farming.vue
  2. 196
      pages/massif/agrSpecs.vue
  3. 2
      pages/massif/collectList.vue
  4. 1
      uni_modules/d-form/components/d-form/d-form.vue
  5. 79
      uni_modules/d-picker/components/d-picker/d-picker.vue

12
pages/massif/add_farming.vue

@ -173,9 +173,6 @@
</view> </view>
</u-swipe-action-item> </u-swipe-action-item>
</u-swipe-action> </u-swipe-action>
<!-- <view class="info" v-for="(v,k) in formData.inputList" :key="k">
<text>{{v.parentName}}</text> <text>{{v.name}}</text> <text>{{v.total}}</text>
</view> -->
<button class="cu-btn round bg-green shadow submit" v-if="formData.inputList.length>0" @click="toCollectList">+继续添加农资</button> <button class="cu-btn round bg-green shadow submit" v-if="formData.inputList.length>0" @click="toCollectList">+继续添加农资</button>
</view> </view>
@ -226,10 +223,6 @@ export default {
rules:{ rules:{
farmingTime:{required:true,message:"操作日期必填!",trigger:'blur'}, farmingTime:{required:true,message:"操作日期必填!",trigger:'blur'},
farmingPlanId:{required:true,message:"种植计划必选!",trigger:'blur'}, farmingPlanId:{required:true,message:"种植计划必选!",trigger:'blur'},
images:{required:true,validator(rule,val,call){
if(!this.fields.images.value)call(new Error("请上传农事图片!"));
else call()
},trigger:'blur'},
}, },
massif:{}, massif:{},
tempType:"", tempType:"",
@ -242,6 +235,8 @@ export default {
this.formData.plotId=options.plotId this.formData.plotId=options.plotId
this.init() this.init()
this.getMassifDetail() this.getMassifDetail()
//
this.$provise.on("forming_agr",e=>e(this.formData.inputList))
}, },
methods:{ methods:{
async init(){ async init(){
@ -348,5 +343,8 @@ export default {
} }
}, },
}, },
onUnload(){
this.$provise.off('forming_agr')
},
} }
</script> </script>

196
pages/massif/agrSpecs.vue

@ -52,66 +52,44 @@
} }
} }
} }
.u-form{
&>.u-form-item{
&/deep/ {
.u-form-item__body__left{
.u-form-item__body__left__content{
.u-form-item__body__left__content__required{
position:initial;
margin-right:4rpx;
}
}
}
.u-form-item__body__right__message{
margin-left:0!important;
}
}
}
.plant-youbian{
padding:18rpx 18rpx;
border-radius: 24rpx;
width:100%;
display:flex;
align-items: center;
flex-direction: row-reverse;
justify-content: space-between;
background:#F7F7F7;
margin-top:14rpx;
color:rgb(48,49,51);
&.noData{
color:rgb(192, 196, 204);
}
&:before{
transform: rotate(90deg);
color:rgb(48,49,51);
}
}
}
} }
// .u-popup{
// .u-popup__content{
// &>.btns{
// display:flex;
// justify-content: space-between;
// padding:10rpx;
// }
// picker-view{
// height:500rpx;
// picker-view-column{
// view.item{
// padding:0 30rpx;
// display:flex;
// flex-direction: column;
// justify-content: space-evenly;
// .name{
// display:flex;
// align-items: center;
// text{
// font-size:16rpx;
// &:first-child{
// color:#fff;
// background:#10C176;
// border-radius:0 20rpx 0 20rpx;
// width:80rpx;
// height:34rpx;
// text-align: center;
// line-height: 34rpx;
// margin-right:16rpx;
// }
// &:nth-child(2){
// font-weight: bold;
// font-size:20rpx;
// }
// &:nth-child(3){
// color:#999;
// margin-left:6rpx;
// }
// }
// }
// .company{
// font-size:16rpx;
// &:before{
// content:attr(data-name);
// color:#FBA83C;
// margin-right:20rpx;
// }
// &:after{
// content:attr(data-company);
// color:#999999;
// }
// }
// }
// }
// }
// }
// }
.agr-picker{ .agr-picker{
padding:0 30rpx; padding:0 30rpx;
display:flex; display:flex;
@ -173,17 +151,15 @@
</view> </view>
<view class="card"> <view class="card">
<u-form class="inline" labelWidth="auto" ref="form" errorType="toast" :model="formData" :rules="rules"> <u-form class="inline" labelWidth="auto">
<d-form <u-form-item label="规格" prop="specificationId" :required="true">
v-for="(v,k) in fields" <view class="plant-youbian" :class="{noData: !formData.specDescribe}" @click="$refs.Dpicker.show=true">{{formData.specDescribe||"请选择规格"}}</view>
:key="k" </u-form-item>
v-bind="v" <d-form v-bind="inputQuantity" :value="formData.inputQuantity" @input="formData.inputQuantity=$event"/>
:field="k"
:required="!!rules[k]"
@input="formData[k]=$event"
@select="fields[k].value=$event.value.map(v=>v.value);formData[k]=$event.value[0].value"/>
</u-form> </u-form>
</view> </view>
<d-picker ref="Dpicker" :list="specs.list" @select="select"/>
</view> </view>
</template> </template>
<script> <script>
@ -191,39 +167,46 @@ import request from '@/common/request.js'
export default { export default {
data(){ data(){
return{ return{
fields:{ specs:{
specificationId:{label:"规格",tip:"",type:"select",columns:[[]],value:[]}, tip:"",
inputQuantity:{label:"投入数量",type:"digit",suffix:""}, list:[]
},
inputQuantity:{
label:"投入数量",
required:true,
type:"digit",
field:"inputQuantity",
suffix:"",
tip:"",
}, },
formData:{ formData:{
specificationId:"", specificationId:"",
number:'',//
specDescribe:"",//
inputQuantity:"", inputQuantity:"",
inventoryId:"", inventoryId:"",
}, },
rules:{
specificationId:{required:true,message:"规格必选!"},
inputQuantity:{required:true,type:"number",message:"投入数量必填!"},
},
agrDetail:{}, agrDetail:{},
eventChannel:null, eventChannel:null,
} }
}, },
computed:{ computed:{
specsVal(){ specsVal(){
var specs=(this.fields.specificationId.columns[0]?.find?.(v=>v.value==this.formData.specificationId)||{}).label||""
return{ return{
specs:(specs.match(/(\d+)(.+?)\/(.+?)/)||[]).slice(1,4), specs:(this.formData.specDescribe.match(/(\d+)(.+?)\/(.+?)/)||[]).slice(1,4),
num:this.formData.inputQuantity num:this.formData.inputQuantity
} }
}, },
}, },
watch:{ watch:{
specsVal(n){ specsVal(n){
this.fields.inputQuantity.suffix=n.specs[2] this.inputQuantity.suffix=n.specs[2]
if(n.num>0 && n.specs[0]>0){ if(n.num>0 && n.specs[0]>0){
this.$set(this.fields.inputQuantity, "tip", `${parseFloat(n.num)*parseFloat(n.specs[0])}${n.specs[1]}`) this.$set(this.inputQuantity, "tip", `${parseFloat(n.num)*parseFloat(n.specs[0])}${n.specs[1]}`)
}else{ }else{
this.$set(this.fields.inputQuantity, "tip", "") this.$set(this.inputQuantity, "tip", "")
} }
} }
}, },
@ -233,16 +216,23 @@ export default {
this.agrDetail=e this.agrDetail=e
this.init() this.init()
}) })
this.formData.inventoryId=options.id
}, },
methods:{ methods:{
async init(){ async init(){
var res=await request("/api/plantFarming/getSpecification",{ var res=await request("/api/plantFarming/getSpecification",{
params:{goodsId: this.agrDetail.goodsId} params:{
goodsId: this.agrDetail.goodsId,
baseId: this.$store.state.plantBaseInfoId,
}
}) })
if(res.statu){ if(res.statu){
this.fields.specificationId.columns=[res.data.listSpec.map(v=>({label:v.goodsSpecification,value:v.id}))] this.$provise.emit("forming_agr", list=>{
this.fields.specificationId.tip=res.data.inventory this.specs.list=res.data.listSpec.map(v=>{
v.number-=list.reduce((a,b)=>a+(b.inventoryId==v.id?b.inputQuantity:0),0)
return v
}).filter(v=>v.number>0)
})
this.specs.tip=res.data.inventory
}else{ }else{
uni.showModal({ uni.showModal({
title:"提示", title:"提示",
@ -251,18 +241,36 @@ export default {
}) })
} }
}, },
select(e){
this.formData.specificationId=e.specId
this.formData.inventoryId=e.id
this.formData.number=e.number
this.formData.specDescribe=e.specDescribe
},
check(){
if(!this.formData.specificationId){
uni.showToast({title:"规格必选!",icon:"none"})
return false
}else if(!(this.formData.inputQuantity>0)){
uni.showToast({title:"投入数量必填!",icon:"none"})
return false
}else if(this.formData.inputQuantity>this.formData.number){
uni.showToast({title:`投入数量不能大于剩余数量${this.formData.number}`,icon:"none"})
return false
}
return true
},
submit(){ submit(){
this.$refs.form.validate().then(async valid=>{ if(this.check()){
if(valid){ this.eventChannel.emit("update", {
this.eventChannel.emit("update", { ...this.formData,
...this.formData, total: `${parseFloat(this.specsVal.num)*parseFloat(this.specsVal.specs[0])}${this.specsVal.specs[1]}`,
total: `${parseFloat(this.specsVal.num)*parseFloat(this.specsVal.specs[0])}${this.specsVal.specs[1]}`, goodsType: this.agrDetail.goodsType,
goodsType: this.agrDetail.goodsType, substanceName: this.agrDetail.substanceName,
substanceName: this.agrDetail.substanceName, })
}) uni.navigateBack()
uni.navigateBack() }
}
})
}, },
} }
} }

2
pages/massif/collectList.vue

@ -74,8 +74,6 @@ export default {
return{ return{
searchVal:{ searchVal:{
baseId: this.$store.state.plantBaseInfoId, baseId: this.$store.state.plantBaseInfoId,
userId: this.$store.getters['userInfo'].id,
enterpriseId: this.$store.getters['userInfo'].companyId,
pageNo:1, pageNo:1,
flagGroupBy:'y', flagGroupBy:'y',
pageSize:6, pageSize:6,

1
uni_modules/d-form/components/d-form/d-form.vue

@ -436,6 +436,7 @@ import {computeArea} from '@/common/utils'
}, },
}, },
created(){ created(){
window.the=this
if(this.type=='select' && this.columns?.length>0){ if(this.type=='select' && this.columns?.length>0){
this.$nextTick(()=>{ this.$nextTick(()=>{
setPickerCol.bind(this.$refs.picker)(this.columns[0]||[],this.value,1) setPickerCol.bind(this.$refs.picker)(this.columns[0]||[],this.value,1)

79
uni_modules/d-picker/components/d-picker/d-picker.vue

@ -6,23 +6,6 @@
justify-content: space-between; justify-content: space-between;
padding:10rpx; padding:10rpx;
align-items: center; align-items: center;
&>.search{
flex-grow: 1;
margin:6rpx 20rpx;
border:1rpx solid rgba(221, 221, 221, 0.5);
border-radius: 40rpx;
display:flex;
align-items: center;
input{
flex-grow: 1;
height:50rpx;
}
.plant-zengjia{
flex-shrink: 0;
color:#999;
transform: rotate(45deg);
}
}
&>button{ &>button{
flex-shrink: 0; flex-shrink: 0;
} }
@ -36,7 +19,12 @@
&/deep/ .item{ &/deep/ .item{
height:60rpx; height:60rpx;
line-height: 60rpx; line-height: 60rpx;
text-align: center; display:flex;
align-items: center;
padding:0 20rpx;
text{
}
} }
} }
} }
@ -46,34 +34,41 @@
<u-popup class="dPicker" :show="show" @close="show=false"> <u-popup class="dPicker" :show="show" @close="show=false">
<view class="btns"> <view class="btns">
<button class="cu-btn sm" @click="show=false">取消</button> <button class="cu-btn sm" @click="show=false">取消</button>
<view class="search"> <button class="cu-btn sm bg-green" @click="$emit('select',list[sureVal]);show=false">确定</button>
<u-icon name="search" color="#999" size="20"/>
<input auto-blur placeholder="搜索内容" v-model="searchVal"/>
<text class="plant-zengjia" v-if="!!searchVal" @click="searchVal=''"/>
</view>
<button class="cu-btn sm bg-green" @click="$emit('select',list[changeVal]);show=false">确定</button>
</view> </view>
<picker-view :value="[value]" indicator-class="mask" @change="changeVal=$event.detail.value[0]"> <picker-view :value="[value]" indicator-class="mask" @change="changeVal=$event.detail.value[0]">
<picker-view-column> <picker-view-column>
<template v-for="(v,k) in list"> <view class="item" v-for="(v,k) in list" :key="k">
<view class="item" :key="k" v-if="!searchVal || (new RegExp(searchVal,'i')).test(v)">{{v}}</view> <text style="margin-left:10rpx;font-weight:bold;">剩余{{v.number}}{{v.packgeUnit}}</text>
</template> <text style="font-size:24rpx;color:#999;">({{v.specDescribe}})</text>
<text style="margin-left:auto;color:#999;">{{new Date(v.operateTime).format('yyyy-MM-dd')}}</text>
</view>
</picker-view-column> </picker-view-column>
</picker-view> </picker-view>
</u-popup> </u-popup>
</template> </template>
<script> <script>
import request from '@/common/request' import {dataType} from 'black-knight/lib/config/tools'
export default{ export default{
props:{ props:{
value:{
type:Number,
default:0
},
list:{
type:Array,
default:()=>[]
},
}, },
data(){ data(){
return{ return{
show:false, show:false,
changeVal:0, changeVal:0,
searchVal:"", }
list:[], },
computed:{
sureVal(){
return dataType(this.changeVal,'number')?this.changeVal:this.value
} }
}, },
watch:{ watch:{
@ -84,27 +79,7 @@ import request from '@/common/request'
}, },
}, },
methods:{ methods:{
open(e){
this.searchVal=e
this.show=true
this.list=[]
this.search()
},
async search(){
var res=await request("/api/goods/supplierShow",{
params:{supplier: ''}
})
if(res.statu){
this.changeVal=0
this.list=res.data
}else{
uni.showModal({
title:"提示",
content:res.msg||"获取供应商列表失败!",
showCancel:false,
})
}
},
}, },
} }
</script> </script>

Loading…
Cancel
Save