<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-item label="推荐标题" >
				<el-input v-model="form.name" placeholder="请输入推荐标题" />
			</el-form-item>
			<el-form-item label="简述" >
				<el-input v-model="form.desc" placeholder="请输入简述" />
			</el-form-item>
			<el-form-item label="推荐图" prop="pic">
				<ImageUpload :value="form.pic" v-model="form.pic" :limit="1" />
			</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: {
        name:"",
        desc:"",
        pic:""
      },
			open: false,
			rules: {
				// name: [
				// 	{ required: true, message: "不能为空", trigger: "blur" },
				// ],
				// desc: [
				// 	{ required: true, message: "不能为空", trigger: "blur" },
				// ],
				pic: [
					{ required: true, message: "不能为空", trigger: "blur" },
				],

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

	}
}
</script>

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

.col12 {
	width: 48%;

}
</style>