lhl 1 рік тому
батько
коміт
b0cc695b7d
1 змінених файлів з 103 додано та 63 видалено
  1. 103 63
      src/pages/erp/purchase/addPurchase.vue

+ 103 - 63
src/pages/erp/purchase/addPurchase.vue

@@ -28,11 +28,12 @@
 				</Tabs>
 			</div>
 			<Form v-if="currentTab == 0" class="formValidate mt20" ref="formValidate_0" :rules="ruleValidate"
-				:model="formValidate_0" :label-width="labelWidth" :label-position="labelPosition" @submit.native.prevent>
+				:model="formValidate_0" :label-width="labelWidth" :label-position="labelPosition"
+				@submit.native.prevent>
 				<Row :gutter="24" type="flex">
 					<Col span="24">
 					<FormItem label="采购对象:" prop="control">
-						<RadioGroup v-model="formValidate_0.who"  @on-change="changeWho">
+						<RadioGroup v-model="formValidate_0.who" @on-change="changeWho">
 							<Radio :label="0" :disabled="formValidate_0.id != 0">
 								<Icon type="social-apple"></Icon>
 								<span>仓库采购</span>
@@ -70,7 +71,8 @@
 					</FormItem>
 					</Col>
 					<Col span="24">
-					<FormItem label="创建人:" prop="create_uid" v-if="formValidate_0.wid != 0 || formValidate_0.store_id != 0">
+					<FormItem label="创建人:" prop="create_uid"
+						v-if="formValidate_0.wid != 0 || formValidate_0.store_id != 0">
 						<el-cascader placeholder="请选择创建人" class="input-add" size="mini"
 							v-model="formValidate_0.create_uid" :options="authList" :props="propsss" @change="checkAuth"
 							filterable clearable v-width="'400'">
@@ -155,13 +157,13 @@
 					</Col>
 					<Col span="24">
 					<FormItem label="商品:" prop="goods">
-						<Table :columns="formValidate_1.id == 0 ?columns_1:columnss" :data="goods" ref="table"
+						<Table :columns="formValidate_1.id == 0 ?columns_1_1:columnss" :data="goods" ref="table"
 							:loading="loading" no-userFrom-text="暂无数据" no-filtered-userFrom-text="暂无筛选结果"
 							@on-selection-change="change">
 							<template slot-scope="{ row,index }" slot="product_num">
 								<!-- <Input v-model="goods[index].want_product_num" placeholder="请输入要货数量" v-width="'150'"
 									type="number" /> -->
-									{{row.want_product_num}}
+								{{row.want_product_num}}
 							</template>
 							<template slot-scope="{ row,index }" slot="unit_type">
 								<Select v-model="goods[index].unit_type" style="width:200px">
@@ -173,6 +175,12 @@
 							<template slot-scope="{ row,index }" slot="unit_types">
 								{{row.unit_name}}
 							</template>
+							<template slot-scope="{ row,index }" slot="unit">
+								{{row.stock['unit_' +  row.unit_type + '_num']}} {{row.unit_name}}
+							</template>
+							<template slot-scope="{ row,index }" slot="want_unit">
+								{{row.want_product_num -row.stock['unit_' +  row.unit_type + '_num'] > 0?row.want_product_num -row.stock['unit_' +  row.unit_type + '_num']:'库存充足,无需采购'}}
+							</template>
 							<template slot-scope="{ row,index }" slot="store_num">
 								<span> {{ row.my.stock }}{{row.my.unit_name}}</span>
 							</template>
@@ -198,8 +206,8 @@
 				<Row :gutter="24" type="flex">
 					<Col span="24">
 					<FormItem label="要货单号:" prop="want_order_id" label-for="want_order_id">
-						<Input v-model="formValidate_2.want_order_id" placeholder="请输入要货单号" v-width="'250'"/>
-						<span class="addClass" @click="addClass" >确认</span>
+						<Input v-model="formValidate_2.want_order_id" placeholder="请输入要货单号" v-width="'250'" />
+						<span class="addClass" @click="addClass">确认</span>
 					</FormItem>
 					</Col>
 					<Col span="24">
@@ -236,7 +244,7 @@
 							<template slot-scope="{ row,index }" slot="product_num">
 								<!-- <Input v-model="goods[index].want_product_num" placeholder="请输入要货数量" v-width="'150'"
 									type="number" /> -->
-									{{row.want_product_num}}
+								{{row.want_product_num}}
 							</template>
 							<template slot-scope="{ row,index }" slot="unit_type">
 								<Select v-model="goods[index].unit_type" style="width:200px">
@@ -273,7 +281,8 @@
 			:style="{ left: `${!menuCollapse ? '200px' : isMobile ? '0' : '80px'}` }">
 			<Form>
 				<FormItem>
-					<Button type="primary" class="submission" @click="handleSubmit('formValidate_' + currentTab)">保存</Button>
+					<Button type="primary" class="submission"
+						@click="handleSubmit('formValidate_' + currentTab)">保存</Button>
 				</FormItem>
 			</Form>
 		</Card>
@@ -391,17 +400,46 @@
 						minWidth: 90
 					},
 					{
-						title: '单位',
+						title: '采购单位',
 						slot: 'unit_types',
 						minWidth: 150
 					},
-
 				],
-				columns_2: [ {
-					title: "ID",
-					key: "product_id",
-					minWidth: 90
-				},{
+				columns_1_1: [{
+						type: 'selection',
+						width: 60,
+						align: 'center'
+					}, {
+						title: '商品名称',
+						key: 'product_name',
+						minWidth: 160
+					},
+					{
+						title: '数量',
+						slot: 'product_num',
+						minWidth: 90
+					},
+					{
+						title: '采购单位',
+						slot: 'unit_types',
+						minWidth: 150
+					},
+					{
+						title: '仓库库存',
+						slot: 'unit',
+						minWidth: 150
+					},
+					{
+						title: '需采购数量',
+						slot: 'want_unit',
+						minWidth: 150
+					},
+				],
+				columns_2: [{
+						title: "ID",
+						key: "product_id",
+						minWidth: 90
+					}, {
 						title: '商品名称',
 						key: 'product_name',
 						minWidth: 160
@@ -416,7 +454,7 @@
 						slot: 'unit_types',
 						minWidth: 150
 					},
-				
+
 				],
 				chooseGoods: [],
 				staffData: [],
@@ -453,7 +491,7 @@
 				},
 				formValidate_0: {
 					store_id: 0,
-					who: 0,//0-仓库采购、1-门店采购
+					who: 0, //0-仓库采购、1-门店采购
 					id: 0,
 					wid: 0,
 					goods: [],
@@ -466,7 +504,7 @@
 					wid: 0,
 					goods: [],
 					supplier_id: 0,
-					create_admin_id:0,
+					create_admin_id: 0,
 					create_uid: 0,
 					purchasing_person_uid: 0
 				},
@@ -474,7 +512,7 @@
 					id: 0,
 					wid: 0,
 					supplier_id: 0,
-					create_admin_id:0,
+					create_admin_id: 0,
 					create_uid: 0,
 					purchasing_person_uid: 0,
 					want_order_id: '',
@@ -541,19 +579,19 @@
 		methods: {
 			...mapMutations("admin/layout", ["setCopyrightShow"]),
 			addClass() {
-				if(this.formValidate_2.want_order_id) {
+				if (this.formValidate_2.want_order_id) {
 					getWantInfo(this.formValidate_2.want_order_id).then(res => {
-						if(res.data && res.data.id) {
-							if(res.data.status == 0) {
+						if (res.data && res.data.id) {
+							if (res.data.status == 0) {
 								return this.$Message.error('当前要货单审核中,请审核后再试');
-							}else if(res.data.status == 3 ) {
+							} else if (res.data.status == 3) {
 								return this.$Message.error('当前要货单已完成');
 							}
 							let data = res.data
 							this.formValidate_2.wid = data.wid
 							this.goodss = data.info
 							this.getUserList(data.wid)
-						}else {
+						} else {
 							return this.$Message.error(res.msg);
 						}
 						// console.log(res);
@@ -563,10 +601,10 @@
 						// 	 return this.$Message.error('请输入正确的要货单号');
 						// }
 					})
-				}else {
-					 return this.$Message.error('请输入要货单号');
+				} else {
+					return this.$Message.error('请输入要货单号');
 				}
-				
+
 			},
 			change(e) {
 				console.log(e);
@@ -575,8 +613,8 @@
 			checkAuth(e) {
 				if (e) {
 					let obj = this.authList.find(item => item.id == e)
-					console.log(e,'check',obj);
-					this['formValidate_' +this.currentTab].create_admin_id = obj.admin_id
+					console.log(e, 'check', obj);
+					this['formValidate_' + this.currentTab].create_admin_id = obj.admin_id
 				}
 
 			},
@@ -648,7 +686,7 @@
 				return arr
 			},
 			setGoods(e) {
-				console.log(e,'选择商品');
+				console.log(e, '选择商品');
 				this.chooseGoods = this.chooseGoods.concat(this.resetGoods(e, 're'))
 			},
 			getGoods() {
@@ -666,11 +704,11 @@
 				// this.$refs.goodDetail.getList()
 			},
 			getUserList(id) {
-				if(this.currentTab == 0) {
+				if (this.currentTab == 0) {
 					let qdata = {}
-					if(this.formValidate_0.who == 0) {
+					if (this.formValidate_0.who == 0) {
 						qdata.wid = this.formValidate_0.wid
-					}else {
+					} else {
 						qdata.store_id = this.formValidate_0.store_id
 					}
 					getUserList(qdata).then(res => {
@@ -681,8 +719,8 @@
 						// 		return item
 						// 	});
 					})
-					
-				}else {
+
+				} else {
 					getUserList({
 						wid: id
 					}).then(res => {
@@ -694,7 +732,7 @@
 						// 	});
 					})
 				}
-				
+
 			},
 			staffList() {
 				staffListInfo()
@@ -747,7 +785,7 @@
 				this.chooseGoods.splice(index, 1);
 			},
 			userSearchs(e) {
-this.formValidate_0.create_uid = "";
+				this.formValidate_0.create_uid = "";
 				this.authList = []
 				this.goods = []
 				this.getUserList(this.formValidate_0.store_id)
@@ -787,8 +825,8 @@ this.formValidate_0.create_uid = "";
 					item.product_num = want
 					return item
 				})
-				try{
-					console.log(arr,'arr');
+				try {
+					console.log(arr, 'arr');
 					return arr.map(item => {
 						let obj = {
 							bar_code: item.bar_code,
@@ -808,35 +846,35 @@ this.formValidate_0.create_uid = "";
 					}).filter(item => {
 						return item.product_num != 0
 					})
-				}catch(e){
+				} catch (e) {
 					//TODO handle the exception
-					console.log('err',e);
+					console.log('err', e);
 				}
-				
+
 			},
 			handleSubmit(name) {
 				console.log('开始');
 				if (this.currentTab == 0) {
 					if (this.formValidate_0.id == 0) {
 						this.formValidate_0.goods = this.handleGoods(this.chooseGoods)
-						if(this.formValidate_0.goods.length == 0) {
+						if (this.formValidate_0.goods.length == 0) {
 							return this.$Message.error('请选择商品并填写采购数量');
 						}
 					} else {
 						this.formValidate_0.goods = this.chooseGoods
 					}
-				} else if(this.currentTab == 1) {
+				} else if (this.currentTab == 1) {
 					console.log('汇总采购商品');
-					this.formValidate_1.goods = this.chooseGoods_1.filter(item => item.want_product_num != 0).map(item=>{
+					this.formValidate_1.goods = this.chooseGoods_1.filter(item => item.want_product_num != 0).map(item => {
 						item.product_num = item.want_product_num
 						return item
 					})
-					if(this.formValidate_1.goods.length == 0) {
+					if (this.formValidate_1.goods.length == 0) {
 						return this.$Message.error('请选择商品并填写采购数量');
 					}
 				}
-				console.log(this.formValidate_0.goods,'this.formValidate_0.goods');
-				try{
+				console.log(this.formValidate_0.goods, 'this.formValidate_0.goods');
+				try {
 					this.$refs[name].validate((valid) => {
 						if (valid) {
 							console.log('校验结束');
@@ -846,9 +884,10 @@ this.formValidate_0.create_uid = "";
 								try {
 									pdata = {
 										id: this.$route.query.id,
-										store_id: this.formValidate_0.who == 1?this.formValidate_0.store_id:'',
-										wid: this.formValidate_0.who == 0?this.formValidate_0.wid: '',
-										type: this.formValidate_0.who==0?0:1,
+										store_id: this.formValidate_0.who == 1 ? this.formValidate_0.store_id :
+											'',
+										wid: this.formValidate_0.who == 0 ? this.formValidate_0.wid : '',
+										type: this.formValidate_0.who == 0 ? 0 : 1,
 										products: this.formValidate_0.goods,
 										supplier_id: this.formValidate_0.supplier_id,
 										create_uid: this.formValidate_0.create_uid,
@@ -857,25 +896,26 @@ this.formValidate_0.create_uid = "";
 								} catch (e) {
 									console.log(e, '错误');
 								}
-							}else if(this.currentTab == 1) {
+							} else if (this.currentTab == 1) {
 								console.log('汇总采购');
 								pdata = {
 									id: this.$route.query.id,
 									wid: this.formValidate_1.wid,
-									goods_ids: this.formValidate_1.goods.map(item => item.product_id).join(','),
+									goods_ids: this.formValidate_1.goods.map(item => item.product_id).join(
+										','),
 									supplier_id: this.formValidate_1.supplier_id,
 									create_uid: this.formValidate_1.create_uid,
 									create_admin_id: this.formValidate_1.create_admin_id,
 									purchasing_person_uid: this.formValidate_1.purchasing_person_uid,
 								}
-								console.log('pdata',pdata);
-							}else if(this.currentTab == 2) {
+								console.log('pdata', pdata);
+							} else if (this.currentTab == 2) {
 								console.log('要货单审核');
-								if(this.formValidate_2.wid == 0) {
+								if (this.formValidate_2.wid == 0) {
 									return this.$Message.error('请确认要货单');
 								}
 								pdata = {
-									id: this.$route.query.id, 
+									id: this.$route.query.id,
 									supplier_id: this.formValidate_2.supplier_id,
 									create_uid: this.formValidate_2.create_uid,
 									create_admin_id: this.formValidate_2.create_admin_id,
@@ -892,13 +932,12 @@ this.formValidate_0.create_uid = "";
 							}).catch(err => {
 								this.$Message.error(err.msg);
 							})
-						} else {
-						}
+						} else {}
 					});
-				}catch(e){
-					console.log('err',e);
+				} catch (e) {
+					console.log('err', e);
 				}
-				
+
 			},
 		},
 	};
@@ -976,6 +1015,7 @@ this.formValidate_0.create_uid = "";
 	.ml16 {
 		margin-left: 16px;
 	}
+
 	.addClass {
 		color: #1890FF;
 		margin-left 14px;