shish 5 лет назад
Родитель
Сommit
492cd44679
2 измененных файлов с 157 добавлено и 115 удалено
  1. 19 10
      pt/src/service/item/index.js
  2. 138 105
      pt/src/views/item/list.vue

+ 19 - 10
pt/src/service/item/index.js

@@ -2,26 +2,35 @@ import { BaseService, Service } from '@/cool';
 
 @Service('item')
 export class ItemService extends BaseService {
-    /**
-	 * 新增花材 b
-	 */
+	//新增花材
 	itemAdd(data) {
 		return this.request({
 			url: '/add',
 			method: 'POST',
 			data: data
 		});
-  }
-    /**
-	 * 批量新增花材 b
-	 */
-    batchAdd(data) {
+	}
+	//批量新增花材
+	batchAdd(data) {
 		return this.request({
 			url: '/batch-add',
 			method: 'POST',
 			data: data
 		});
-  }
-  
+	}
+	//批量新增花材
+	update(data) {
+		return this.request({
+			url: '/update',
+			method: 'POST',
+			data: data
+		});
+	}
+	getDetail(data) {
+		return this.request({
+			url: '/detail',
+			params: data
+		});
+	}
 }
 export default new ItemService();

+ 138 - 105
pt/src/views/item/list.vue

@@ -46,7 +46,7 @@
 			<template #slot-modify="{ scope }">
 				<el-button
 					type="text"
-					@click.native.stop="replaceBtnFn(scope.row.id, scope.row.name)"
+					@click.native.stop="replaceBtnFn(scope.row.id)"
 					>修改</el-button
 				>
 			</template>
@@ -69,29 +69,34 @@
 					>
 				</div>
 			</template>
+
+			<template #slot-sync-btn>
+				<el-button type="primary" size="mini" @click="syncBtnFn({})">同步图片</el-button>
+			</template>
+
 			<template #slot-add-goods-btn>
-				<el-button type="primary" size="mini" @click="addBtn">添加</el-button>
+				<el-button type="primary" size="mini" @click="replaceBtnFn(0)">添加</el-button>
 			</template>
 		</x-crud>
 
 		<!-- 新增弹窗 -->
 		<el-dialog
-			:title="`${addOrModify == 1 ? '添加' : '修改'}花材`"
+			:title="`${currentItemId == 0 ? '添加' : '修改'}花材`"
 			:visible.sync="addDialog"
 			:close-on-click-modal="false"
 			width="600px"
 		>
 			<div class="ad-modal-content">
 				<el-form
-					:model="adForm"
-					:rules="adFormRules"
-					ref="adForm"
+					:model="replaceForm"
+					:rules="replaceFormRules"
+					ref="replaceForm"
 					label-width="100px"
 					class="demo-form"
 				>
 					<el-form-item label="名称" prop="name">
 						<el-input
-							v-model="adForm.name"
+							v-model="replaceForm.name"
 							placeholder="请输入名称"
 							size="small"
 						></el-input>
@@ -99,20 +104,20 @@
 
 					<el-form-item label="别名" prop="alias">
 						<el-input
-							v-model="adForm.alias"
+							v-model="replaceForm.alias"
 							placeholder="请输入别名"
 							size="small"
 						></el-input>
 					</el-form-item>
 
-					<el-form-item label="图片" prop="adImg">
-						<cl-upload v-model="adForm.adImg" :success="uploadSuccess"></cl-upload>
+					<el-form-item label="图片" prop="cover">
+						<cl-upload v-model="replaceForm.cover" :success="uploadSuccess"></cl-upload>
 						<p style="font-size: 14px; color: #cccccc">建议上传图片比例 400X400</p>
 					</el-form-item>
 
 					<el-form-item label="分类" prop="classId">
 						<el-select
-							v-model="adForm.className"
+							v-model="replaceForm.className"
 							size="small"
 							placeholder="请选择分类"
 							@change="selClassFn"
@@ -128,7 +133,7 @@
 
 					<el-form-item label="大单位" prop="bigUnitId">
 						<el-select
-							v-model="adForm.bigUnitName"
+							v-model="replaceForm.bigUnit"
 							size="small"
 							placeholder="请选择单位"
 							@change="selBigUnitFn"
@@ -142,9 +147,9 @@
 						</el-select>
 					</el-form-item>
 
-					<el-form-item label="小单位" prop="samllUnitId">
+					<el-form-item label="小单位" prop="smallUnitId">
 						<el-select
-							v-model="adForm.samllUnitName"
+							v-model="replaceForm.smallUnit"
 							size="small"
 							placeholder="请选择单位"
 							@change="selSmallUnitFn"
@@ -160,7 +165,7 @@
 
 					<el-form-item label="单位比" prop="ratio">
 						<el-input
-							v-model="adForm.ratio"
+							v-model="replaceForm.ratio"
 							placeholder="1扎=20支,请输入20"
 							size="small"
 						></el-input>
@@ -168,36 +173,41 @@
 
 					<el-form-item label="库存预警" prop="stockWarning">
 						<el-input
-							v-model="adForm.stockWarning"
-							placeholder="请输入别名"
+							v-model="replaceForm.stockWarning"
+							placeholder="请输入数值"
 							size="small"
 						></el-input>
 					</el-form-item>
 
+					<el-form-item label="每扎重量" prop="weight">
+						<el-input
+							v-model="replaceForm.weight"
+							placeholder="请输入斤数"
+							size="small"
+						></el-input>
+					</el-form-item>
 
 					<el-form-item label="每扎成本价" prop="cost">
 						<el-input
-							v-model="adForm.cost"
-							placeholder="请输入别名"
+							v-model="replaceForm.cost"
+							placeholder="请输入成本价"
 							size="small"
 						></el-input>
 					</el-form-item>
 
-
 					<el-form-item label="每扎加价" prop="addPrice">
 						<el-input
-							v-model="adForm.addPrice"
-							placeholder="请输入价"
+							v-model="replaceForm.addPrice"
+							placeholder="请输入价"
 							size="small"
 						></el-input>
 					</el-form-item>
 
-
 				</el-form>
 			</div>
 			<div slot="footer" class="dialog-footer">
 				<el-button size="small" @click="resetForm">取 消</el-button>
-				<el-button type="primary" size="small" @click="addFn">确认</el-button>
+				<el-button type="primary" size="small" @click="replaceConfirmFn">确认</el-button>
 			</div>
 		</el-dialog>
 	</div>
@@ -226,65 +236,84 @@ export default {
 			},
 			classId: 0,
 			addDialog: false,
-			adForm: {
+			replaceForm: {
 				name: '',
 				alias: '',
 				classId: '',
 				className: '',
-				adImg: '',
-				bigUnitName: '',
+				cover: '',
 				bigUnitId: '',
-				smallUnitName: '',
+				bigUnit: '',
 				smallUnitId: '',
-        stockWarning:'',
-        cost:'',
-        addPrice:''
+				smallUnit: '',
+				stockWarning:'',
+				cost:'',
+				addPrice:'',
+				weight:'',
+				ratio:''
 			},
 			addOrModify: 1,
-			adFormRules: {
+			replaceFormRules: {
 				name: {
 					required: true,
-					message: '广告图名称不能为空',
+					message: '名称不能为空',
 				},
-				adImg: {
+				cover: {
 					required: true,
-					message: '广告图片不能为空',
+					message: '图片不能为空',
 				},
-				style: {
-					validator: (rule, value, callback) => {
-						const { url, style } = this.adForm;
-						if (style == '0') {
-							if (!url) {
-								//return callback(new Error('链接不能为空'));
-							}
-						} else {
-							if (!this.goodsData.id) {
-								return callback(new Error('请选择商品'));
-							}
-						}
-
-						callback();
-					},
+				classId: {
+					required: true,
+					message: '请选择分类',
+				},
+				bigUnit: {
+					required: true,
+					message: '请选择大单位',
+				},
+				smallUnit: {
+					required: true,
+					message: '请选择小单位',
+				},
+				ratio: {
+					required: true,
+					message: '比例不能为空',
+				},
+				stockWarning: {
+					required: true,
+					message: '最低库存不能为空',
+				},
+				cost: {
+					required: true,
+					message: '运费不能为空',
+				},
+				addPrice: {
+					required: true,
+					message: '加价不能为空',
 				},
+				weight: {
+					required: true,
+					message: '重量不能为空',
+				}
 			},
 			//分类列表
 			itemClassList: [],
 			unitList: [],
+			currentItemId: 0
 		};
 	},
 	computed: {},
 	methods: {
 		selClassFn(val) {
 			let index = this.itemClassList.findIndex((e) => e.name == val);
-			this.adForm.classId = this.itemClassList[index].id;
+			this.replaceForm.classId = this.itemClassList[index].id;
 		},
 		selBigUnitFn(val) {
 			let index = this.unitList.findIndex((e) => e.name == val);
-			this.adForm.bigUnitId = this.unitList[index].id;
+			this.replaceForm.bigUnit = this.unitList[index].id;
 		},
 		selSmallUnitFn(val) {
 			let index = this.unitList.findIndex((e) => e.name == val);
-			this.adForm.smallUnitId = this.unitList[index].id;
+			this.replaceForm.smallUnit = this.unitList[index].id;
 		},
 		getAllClass() {
 			if (!this.$util.isEmpty(this.itemClassList)) {
@@ -303,47 +332,33 @@ export default {
 			});
 		},
 		uploadSuccess() {
-			this.$refs['adForm'].validateField('adImg');
+			this.$refs['replaceForm'].validateField('cover');
 		},
-		addBtn() {
+		replaceBtnFn(id) {
 			this.getAllClass()
 			this.getAllUnit()
 			this.addDialog = true
-			this.adForm = {
-				name: '',
-				alias: '',
-				adImg: '',
-				bigUnitName: '',
-				bigUnitId: '',
-				smallUnitName: '',
-				smallUnitId: '',
-        stockWarning:'',
-        cost:'',
-        addPrice:''
-			}
-		},
-		selGoodsConfirmFn(item) {
-			let param = [];
-			item.forEach((value) => {
-				let newObj = {};
-				newObj.itemId = value.id;
-				newObj.classId = this.classId;
-				newObj.cost = value.cost;
-				newObj.addPrice = value.addPrice;
-				newObj.stockWarning = value.stockWarning;
-				param.push(newObj);
-			});
-			param = JSON.stringify(param);
-			console.log(param);
-			this.$service.item
-				.batchAdd({ data: param })
-				.then((res) => {
-					this.$message.success('操作成功!');
-					this.$router.go(0);
-				})
-				.catch((err) => {
-					console.log(err);
+			this.currentItemId = id
+			if(id == 0){
+				this.replaceForm = {
+					name: '',
+					alias: '',
+					cover: '',
+					bigUnitId: '',
+					bigUnit: '',
+					smallUnitId: '',
+					smallUnit: '',
+					stockWarning:'',
+					cost:'',
+					addPrice:'',
+					weight:'',
+					ratio:''
+				}
+			}else{
+				this.$service.item.getDetail({id:id}).then(async res => {
+					this.replaceForm = res
 				});
+			}
 		},
 		tabClick(tab, e) {
 			this.app.refresh({ classId: this.classId });
@@ -394,6 +409,24 @@ export default {
 							align: 'center',
 							'min-width': 100,
 						},
+						{
+							prop: 'weight',
+							label: '重量',
+							align: 'center',
+							'min-width': 100,
+						},
+						{
+							prop: 'bigUnit',
+							label: '大单位',
+							align: 'center',
+							minWidth: 100,
+						},
+						{
+							prop: 'smallUnit',
+							label: '小单位',
+							align: 'center',
+							minWidth: 100,
+						},
 						{
 							prop: 'inTurn',
 							label: '排序',
@@ -410,7 +443,7 @@ export default {
 					op: {
 						visible: true,
 						props: {
-							width: 300,
+							width: 250,
 							align: 'center',
 							fixed: 'right',
 							label: '操作',
@@ -430,7 +463,7 @@ export default {
 				})
 				.set('layout', [
 					['slot-tabs'],
-					['flex1', 'slot-add-goods-btn', 'refresh-btn'],
+					['slot-sync-btn', 'flex1', 'slot-add-goods-btn',  'refresh-btn'],
 					['data-table'],
 					['flex1', 'pagination'],
 				])
@@ -466,30 +499,30 @@ export default {
 		},
 		resetForm() {
 			this.goodsData = {};
-			this.$refs['adForm'].resetFields();
+			this.$refs['replaceForm'].resetFields();
 			this.addDialog = false;
 		},
-		addFn() {
-			this.$refs.adForm.validate((valid) => {
+		replaceConfirmFn() {
+			this.$refs.replaceForm.validate((valid) => {
 				if (valid) {
-					let form = JSON.parse(JSON.stringify(this.adForm));
-					let host = null;
-					if (this.addOrModify == 1) {
+					let form = JSON.parse(JSON.stringify(this.replaceForm))
+					let host = null
+					if (this.currentItemId == 0) {
 						host = () => {
-							return this.$service.ad.add(form);
-						};
+							return this.$service.item.itemAdd(form)
+						}
 					} else {
 						host = () => {
-							return this.$service.ad.update({
+							return this.$service.item.update({
 								id: this.modifyData.id,
 								...form,
-							});
-						};
+							})
+						}
 					}
 					host().then((res) => {
-						this.$message.success('操作成功!');
-						this.resetForm();
-						this.app.refresh({ type: this.tabIndex });
+						this.$message.success('操作成功!')
+						this.resetForm()
+						this.app.refresh({ classId: this.classId })
 					});
 				}
 			});