<template>
	<el-dialog title="特惠" :visible.sync="open" width="600px" append-to-body>
		<!-- 添加或修改店铺对话框 -->
		<el-form ref="form" :model="form" :rules="rules" label-width="120px">
			<el-form-item label="商品名称">
				{{ form.goodsName }}
			</el-form-item>
			<el-form-item label="原售价">
				{{ form.price }}
			</el-form-item>
			<el-form-item label="折扣价">
				{{ form.discount }}
			</el-form-item>
		</el-form>
		<div class="dialog-footer">
			<el-button type="primary" @click="submitForm">确 定</el-button>
			<el-button @click="cancel">取 消</el-button>
		</div>
	</el-dialog>
</template>

<script>
import { addRecommend } from "@/api/system/shop";
export default {
	props: ['shopId'],
	data() {
		return {
			form: {},
			open: false,
			rules: {
				name: [
					{ required: true, message: "不能为空", trigger: "change" },
				],
				desc: [
					{ required: true, message: "不能为空", trigger: "change" },
				],
				pic: [
					{ required: true, message: "不能为空", trigger: "change" },
				],

			},
		}
	},
	methods: {
		/** 提交按钮 */
		submitForm() {
			this.$refs["form"].validate((valid) => {
				if (valid) {
					addRecommend(this.form).then((res) => {
						this.$modal.msgSuccess("成功");
						this.open = false;
					});
				}
			});
		},
		// 取消按钮
		cancel() {
			this.open = false;
			this.reset();
		},
		// 表单重置
		reset() {
			this.form = {};
			this.resetForm("form");
		},
		openModal(data) {
			this.form.goodsName = data.name
			this.form.shopId = this.shopId
			this.form.goodsId = data.id
			this.form.price = data.price
			this.form.discount = data.discount
			this.form.type = 2
			this.open = true
		}

	}
}
</script>

<style lang="scss" scoped>
.row_input {
	display: flex;
	justify-content: space-between;
}

.col12 {
	width: 48%;

}
</style>