Просмотр исходного кода

1.供货商增加一个新增花材功能 2、点修改再点添加会触发错误提示

jf 5 лет назад
Родитель
Сommit
cc3e55a736

+ 2 - 0
ghs/src/cool/request/index.js

@@ -28,6 +28,7 @@ import shop from '@/service/shop/index';
 import chat from '@/service/chat/index';
 import itemClass from '@/service/item-class/index';
 import item from '@/service/item/index';
+import unit from '@/service/unit/index';
 import ptItem from '@/service/pt-item/index';
 import custom from '@/service/custom/index';
 import product from '@/service/product/index';
@@ -65,6 +66,7 @@ export function SET_SERVICE({ store }) {
 		chat,
 		itemClass,
 		item,
+		unit,
 		ptItem,
 		custom,
 		product

+ 6 - 0
ghs/src/service/item/index.js

@@ -22,6 +22,12 @@ export class ItemService extends BaseService {
 			data: data
 		});
   }
+	getDetail(data) {
+		return this.request({
+			url: '/detail',
+			params: data
+		});
+	}
   
 }
 export default new ItemService();

+ 10 - 0
ghs/src/service/product/index.js

@@ -20,6 +20,16 @@ export class ProductService extends BaseService {
     data: data
   });
   }
+    /** *
+     * 新增花材  姜枫2021.06.22
+     */
+    addProduct(data) {
+        return this.request({
+            url: '/add',
+            method: 'POST',
+            data: data
+        });
+    }
   
 }
   

+ 13 - 0
ghs/src/service/unit/index.js

@@ -0,0 +1,13 @@
+import { BaseService, Service } from '@/cool';
+@Service('unit')
+export class UnitService extends BaseService {
+
+	getAllUnit(data) {
+		return this.request({
+			url: '/get-all-unit',
+			params: data
+		});
+	}
+
+}
+export default new UnitService();

+ 154 - 37
ghs/src/views/item/list.vue

@@ -90,7 +90,7 @@
         <el-button type="primary" size="mini" @click="addFn()">添加</el-button>
       </template>
 		<template #slot-addNew-goods-btn>
-        <el-button type="primary" size="mini" @click="addFn()">新增</el-button>
+        <el-button type="primary" size="mini" @click="replaceBtnFn(0)">新增</el-button>
       </template>
 
     </x-crud>
@@ -118,7 +118,13 @@
 							size="small"
 						></el-input>
 					</el-form-item>
-
+			<el-form-item label="拼音缩写" prop="py">
+				<el-input
+						v-model="replaceForm.py"
+						placeholder="拼音缩写"
+						size="small"
+				></el-input>
+			</el-form-item>
           <el-form-item label="别名" prop="alias">
 						<el-input
 							v-model="replaceForm.alias"
@@ -147,7 +153,25 @@
 							>
 						</el-select>
 					</el-form-item>
+			<el-form-item label="大单位" prop="bigUnitId">
+				<el-select v-model="replaceForm.bigUnit" size="small" placeholder="请选择单位" @change="selBigUnitFn">
+					<el-option v-for="(item, index) in unitList" :key="index" :value="item.name" >{{ item.name }}</el-option>
+				</el-select>
+			</el-form-item>
+
+			<el-form-item label="小单位" prop="smallUnitId">
+				<el-select v-model="replaceForm.smallUnit" size="small" placeholder="请选择单位" @change="selSmallUnitFn">
+					<el-option v-for="(item, index) in unitList" :key="index" :value="item.name" >{{ item.name }}</el-option>
+				</el-select>
+			</el-form-item>
 
+			<el-form-item label="单位比" prop="ratio">
+				<el-input
+						v-model="replaceForm.ratio"
+						placeholder="1扎=20支,请输入20"
+						size="small"
+				></el-input>
+			</el-form-item>
           <el-form-item label="库存预警" prop="stockWarning">
 						<el-input
 							v-model="replaceForm.stockWarning"
@@ -230,6 +254,7 @@ export default {
       addDialog: false,
       replaceForm: {
 				name: '',
+				py: '',
 				alias: '',
 				classId: '',
 				className: '',
@@ -254,6 +279,18 @@ export default {
 					required: true,
 					message: '请选择分类',
 				},
+		  bigUnitId: {
+			  required: true,
+			  message: '请选择大单位',
+		  },
+		  smallUnitId: {
+			  required: true,
+			  message: '请选择小单位',
+		  },
+		  ratio: {
+			  required: true,
+			  message: '比例不能为空',
+		  },
 				stockWarning: {
 					required: true,
 					message: '最低库存不能为空',
@@ -271,7 +308,9 @@ export default {
 					message: '重量不能为空',
 				}
 			},
-      itemClassList: []
+      itemClassList: [],
+	  unitList: [],
+	  currentItemId: 0
     };
   },
   computed: {
@@ -319,6 +358,14 @@ export default {
 				this.itemClassList = res.list;
 			});
 		},
+	  getAllUnit() {
+		  if (!this.$util.isEmpty(this.unitList)) {
+			  return this.unitList;
+		  }
+		  this.$service.unit.getAllUnit().then((res) => {
+			  this.unitList = res.list;
+		  });
+	  },
     addFn () {
       this.showItemModal = true
     },
@@ -326,6 +373,14 @@ export default {
 			let index = this.itemClassList.findIndex((e) => e.name == val);
 			this.replaceForm.classId = this.itemClassList[index].id;
 		},
+	  selBigUnitFn(val) {
+		  let index = this.unitList.findIndex((e) => e.name == val);
+		  this.replaceForm.bigUnitId = this.unitList[index].id;
+	  },
+	  selSmallUnitFn(val) {
+		  let index = this.unitList.findIndex((e) => e.name == val);
+		  this.replaceForm.smallUnitId = this.unitList[index].id;
+	  },
     resetForm() {
 			this.goodsData = {};
 			this.$refs['replaceForm'].resetFields();
@@ -336,16 +391,26 @@ export default {
 		if(this.replaceForm.cover.substr(0,4).toLowerCase() == "http"){
 			replaceForm.cover = this.replaceForm.shortCover;
 		}
-      this.$refs.replaceForm.validate((valid) => {
-        if(valid) {
-          this.$service.product.update(replaceForm).then(res => {
-            console.log('res1111', res)
-            this.$message.success('操作成功!');
-            this.addDialog = false
-            this.app.refresh()
-          }).catch(err => {})
-        }
-      })
+		this.$refs.replaceForm.validate((valid) => {
+			if(valid) {
+				if (this.currentItemId == 0) {
+					this.$service.product.addProduct(JSON.parse(JSON.stringify(this.replaceForm))).then(res => {
+						this.$message.success('操作成功!');
+						this.addDialog = false
+						this.app.refresh()
+					})
+				}else{
+					this.$service.product.update(replaceForm).then(res => {
+						console.log('res1111', res)
+						this.$message.success('操作成功!');
+						this.addDialog = false
+						this.app.refresh()
+					}).catch(err => {})
+				}
+			}
+		})
+
+
     },
     tabClick (tab, e) {
       this.app.refresh({ classId: this.classId });
@@ -504,31 +569,83 @@ export default {
       this.costWeight = false
     },
     replaceBtnFn(id) {
+		this.getAllClass()
+		this.getAllUnit()
       this.addDialog = true
-      this.getAllClass()
-      this.$service.product.info({id}).then(res => {
-        console.log(res)
-        // this.replaceForm.name = res.name
-				// this.replaceForm.alias = res.alias
-				// this.replaceForm.classId = res.classId
-				// this.replaceForm.className = res.classId
-				// this.replaceForm.cover = res.cover
-        // this.replaceForm.bigUnit = res.bigUnit
-				// this.replaceForm.smallUnit = res.smallUnit
-				// this.replaceForm.stockWarning = res.stockWarning
-				// this.replaceForm.cost = res.cost
-				// this.replaceForm.addPrice = res.addPrice
-				// this.replaceForm.weight = res.weight
-        let index = this.itemClassList.findIndex((e) => e.id == res.classId)
-        this.replaceForm = res
-        this.replaceForm.className = this.itemClassList[index].name
-        console.log(this.replaceForm.cover)
-        if(this.replaceForm.cover.indexOf('http') != -1 && this.replaceForm.cover.indexOf('/uploads') != -1) {
-          let str = this.replaceForm.cover
-          let str1 = str.substring(0, str.indexOf("/uploads"));
-          this.replaceForm.cover = str.substring(str1.length+1, str.length);
-        }
-      })
+		this.currentItemId = id;
+
+		if(id==0){
+			this.replaceFormRules = {};
+			this.replaceForm = {
+				name: '',
+				py: '',
+				alias: '',
+				classId: '',
+				className: '',
+				cover: '',
+				bigUnit: '',
+				smallUnit: '',
+				stockWarning:'',
+				cost:'',
+				addPrice:'',
+				weight:'',
+			};
+		}else{
+			this.replaceFormRules = {
+				name: {
+					required: true,
+							message: '名称不能为空',
+				},
+				cover: {
+					required: true,
+							message: '图片不能为空',
+				},
+				classId: {
+					required: true,
+							message: '请选择分类',
+				},
+				bigUnitId: {
+					required: true,
+					message: '请选择大单位',
+				},
+				smallUnitId: {
+					required: true,
+					message: '请选择小单位',
+				},
+				ratio: {
+					required: true,
+					message: '比例不能为空',
+				},
+				stockWarning: {
+					required: true,
+							message: '最低库存不能为空',
+				},
+				cost: {
+					required: true,
+							message: '运费不能为空',
+				},
+				addPrice: {
+					required: true,
+							message: '加价不能为空',
+				},
+				weight: {
+					required: true,
+							message: '重量不能为空',
+				}
+			};
+			this.$service.product.info({id}).then(res => {
+				let index = this.itemClassList.findIndex((e) => e.id == res.classId)
+				this.replaceForm = res
+				this.replaceForm.className = this.itemClassList[index].name
+				console.log(this.replaceForm.cover)
+				if(this.replaceForm.cover.indexOf('http') != -1 && this.replaceForm.cover.indexOf('/uploads') != -1) {
+					let str = this.replaceForm.cover
+					let str1 = str.substring(0, str.indexOf("/uploads"));
+					this.replaceForm.cover = str.substring(str1.length+1, str.length);
+				}
+			})
+		}
+
     },
 	  changeAllSort(e){
     	console.log(e,'1111');

+ 47 - 25
pt/src/views/item/list.vue

@@ -140,34 +140,14 @@
 					</el-form-item>
 
 					<el-form-item label="大单位" prop="bigUnitId">
-						<el-select
-							v-model="replaceForm.bigUnit"
-							size="small"
-							placeholder="请选择单位"
-							@change="selBigUnitFn"
-						>
-							<el-option
-								v-for="(item, index) in unitList"
-								:key="index"
-								:value="item.name"
-								>{{ item.name }}</el-option
-							>
+						<el-select v-model="replaceForm.bigUnit" size="small" placeholder="请选择单位" @change="selBigUnitFn">
+							<el-option v-for="(item, index) in unitList" :key="index" :value="item.name" >{{ item.name }}</el-option>
 						</el-select>
 					</el-form-item>
 
 					<el-form-item label="小单位" prop="smallUnitId">
-						<el-select
-							v-model="replaceForm.smallUnit"
-							size="small"
-							placeholder="请选择单位"
-							@change="selSmallUnitFn"
-						>
-							<el-option
-								v-for="(item, index) in unitList"
-								:key="index"
-								:value="item.name"
-								>{{ item.name }}</el-option
-							>
+						<el-select v-model="replaceForm.smallUnit" size="small" placeholder="请选择单位" @change="selSmallUnitFn">
+							<el-option v-for="(item, index) in unitList" :key="index" :value="item.name" >{{ item.name }}</el-option>
 						</el-select>
 					</el-form-item>
 
@@ -348,6 +328,7 @@ export default {
 			this.addDialog = true
 			this.currentItemId = id
 			if(id == 0){
+				this.replaceFormRules = {};
 				this.replaceForm = {
 					name: '',
 					alias: '',
@@ -367,7 +348,48 @@ export default {
 				}
 			}else{
 				this.$service.item.getDetail({id:id}).then(async res => {
-					
+					this.replaceFormRules = {
+						name: {
+							required: true,
+								message: '名称不能为空',
+						},
+						cover: {
+							required: true,
+								message: '图片不能为空',
+						},
+						classId: {
+							required: true,
+								message: '请选择分类',
+						},
+						bigUnitId: {
+							required: true,
+								message: '请选择大单位',
+						},
+						smallUnitId: {
+							required: true,
+								message: '请选择小单位',
+						},
+						ratio: {
+							required: true,
+								message: '比例不能为空',
+						},
+						stockWarning: {
+							required: true,
+								message: '最低库存不能为空',
+						},
+						cost: {
+							required: true,
+								message: '运费不能为空',
+						},
+						addPrice: {
+							required: true,
+								message: '加价不能为空',
+						},
+						weight: {
+							required: true,
+								message: '重量不能为空',
+						}
+					};
 					let index = this.itemClassList.findIndex((e) => e.id == res.classId)
 					this.replaceForm.name = res.name
 					this.replaceForm.alias = res.alias