<template>
	<el-dialog title="审核" :visible.sync="dialogVisible" @close="dialogFormVisible" :close-on-click-modal="false"
		:close-on-press-escape="false">
		<el-form size="small" :model="form" ref="form">
			<el-form-item label="名称" :label-width="formLabelWidth">
				<el-input v-model="form.name" autocomplete="off" disabled></el-input>
			</el-form-item>

			<el-form-item label="手机号" prop="mobile" :label-width="formLabelWidth">
				<el-input v-model="form.mobile" autocomplete="off" disabled></el-input>
			</el-form-item>		
			
			<el-form-item label="身份证" prop="card" :label-width="formLabelWidth">
				<el-input v-model="form.card" autocomplete="off" disabled></el-input>
			</el-form-item>

			<el-form-item label="出生日期" prop="both" :label-width="formLabelWidth">
				<el-input v-model="form.both" autocomplete="off" disabled></el-input>
			</el-form-item>

			<el-form-item label="套餐" prop="group_name" :label-width="formLabelWidth">
				<el-input v-model="form.group_name" autocomplete="off" disabled></el-input>
			</el-form-item>

			<el-form-item label="审核" prop="status" :label-width="formLabelWidth">
				<el-select v-model="form.status" placeholder="请选择">
					<el-option label="通过"   :value="1"></el-option>
					<el-option label="不通过" :value="2"></el-option>
				</el-select>
			</el-form-item>
		
		</el-form>
		<div slot="footer" class="dialog-footer">
			<el-button @click="dialogFormVisible">取 消</el-button>
			<el-button type="primary" @click="review" :loading="loading">确 定</el-button>
		</div>
		<!--上传图片组件-->
		<Upload v-if="isupload" :isupload="isupload" :type="type" @returnImgs="returnImgsFunc">上传图片</Upload>
	</el-dialog>

</template>

<script>
import Upload from '@/components/file/Upload';
import Uediter from '@/components/UE.vue';
import VenueApi from '@/api/venue.js';
import ComboApi from '@/api/combo.js';

export default {
	components: {
		Upload,
		Uediter,
	},
	data() {
		return {
			/*富文本框配置*/
			ueditor: {
				text: '',
				config: {
					initialFrameWidth: 400,
					initialFrameHeight: 500,
                    toolbars: [
						[
							'fullscreen', 'source', '|', 'undo', 'redo', '|',
							'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc', '|',
							'rowspacingtop', 'rowspacingbottom', 'lineheight', '|',
							'customstyle', 'paragraph', 'fontfamily', 'fontsize', '|',
							'directionalityltr', 'directionalityrtl', 'indent', '|',
							'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|', 'touppercase', 'tolowercase', '|',
							'link', 'unlink', 'anchor', '|',
							'emotion', 'map', 'insertframe', 'insertcode', 'pagebreak', 'template', 'background', '|',
							'horizontal', 'date', 'time', 'spechars', 'wordimage', '|',
							'inserttable', 'deletetable', 'insertparagraphbeforetable', 'insertrow', 'deleterow', 'insertcol', 'deletecol', 'mergecells', 'mergeright', 'mergedown', 'splittocells', 'splittorows', 'splittocols', 'charts', '|',
							'print', 'preview', 'searchreplace', 'drafts', 'help'
						]
					]
				},
			},
			form: {
				id: 0,
				mobile: '',
				name: '',
				card: '',
				both: '',
				status: ''
			},
        	file_path: '',
			formRules: {
				name: [{
					required: true,
					message: '请输入套餐名称',
					trigger: 'blur'
				}],		
                
                eg_name: [{
					required: true,
					message: '请输入套餐英文名称',
					trigger: 'blur'
				}],

                image: [{
                    required: true,
                    message: '请上传套餐图片',
                    trigger: 'blur'
                }],

                price: [{
                    required: true,
                    message: '请输入套餐价格',
                    trigger: 'blur'
                }],
                
                month_price: [{
                    required: true,
                    message: '请输入指导价',
                    trigger: 'blur'
                }],

                content: [{
                    required: true,
                    message: '请输入权益说明',
                    trigger: 'blur'
                }],
			},
			/*左边长度*/
			formLabelWidth: '120px',
			/*是否显示*/
			dialogVisible: false,
			loading: false,
			/*是否上传图片*/
			isupload: false,
		};
	},
    props: ['open_edit', 'editform'],
	created() {
		this.dialogVisible = this.open_edit;
		console.log(this.editform);
		this.form.id = this.editform.id;
		this.form.name = this.editform.name;
		this.form.mobile = this.editform.mobile;
		this.form.card = this.editform.card;
		this.form.both = this.editform.both;
		this.form.group_name = this.editform.group_name;
		this.form.status = this.editform.status == 0 ? '' : this.editform.status;
	},
	methods: {
		/*添加场馆*/
		addUser() {
			let self = this;
			let params = self.form;
	
			self.$refs.form.validate((valid) => {
				if (valid) {
					self.loading = true;
					ComboApi.editGround(params).then(data => {
						self.loading = false;
						self.$message({
							message: '修改成功',
							type: 'success'
						});
						self.dialogFormVisible(true);
					}).catch(error => {
						self.loading = false;
					});
				}
			});
		},

		/*获取富文本内容*/
		contentChangeFunc(e){
			this.form.content = e;
		},

		/*关闭弹窗*/
		dialogFormVisible(e) {
			if (e) {
				this.$emit('closeDialog', {
					type: 'success',
					openDialog: false
				})
			} else {
				this.$emit('closeDialog', {
					type: 'error',
					openDialog: false
				})
			}
		},
		/*上传*/
		openUpload(e) {
			this.type = e;
			this.isupload = true;
		},
		/*获取图片*/
		returnImgsFunc(e) {
			console.log("🚀 ~ e:", e)
			if (e != null && e.length > 0) {
				this.file_path = e[0].file_path;
				this.form.image = e[0].file_id;
			}
			this.isupload = false;
		},

		review() {
			let self = this;
			let params = {
				id: self.form.id,
				status: self.form.status
			};
	
			self.$refs.form.validate((valid) => {
				if (valid) {
					self.loading = true;
					ComboApi.reviewEdit(params).then(data => {
						self.loading = false;
						self.$message({
							message: '操作成功',
							type: 'success'
						});
						self.dialogFormVisible(true);
					}).catch(error => {
						self.loading = false;
					});
				}
			});
		}

	}
};
</script>

<style>
.img {
	margin-top: 10px;
}
</style>
