<template>
	<div>
		<div class="crumbs">
			<el-breadcrumb separator="/">
				<el-breadcrumb-item>
					<i class="el-icon-lx-global"></i> 网站设置
				</el-breadcrumb-item>
			</el-breadcrumb>
		</div>
		<div class="container">
			<div class="form-box">
				<el-form :model="webForm" :rules="rules" ref="web_Form" label-width="80px">
					<el-form-item label="网站地址" prop="website">
						<el-input prop="website" type="text" v-model="webForm.website"></el-input>
					</el-form-item>
					<el-form-item label="邮箱" prop="email">
						<el-input prop="email" type="email" v-model="webForm.email"></el-input>
					</el-form-item>
					<el-form-item label="版权信息" prop="copyright">
						<el-input prop="copyright" type="text" v-model="webForm.copyright"></el-input>
					</el-form-item>
					<el-form-item>
						<el-button type="primary" @click="save_web(webForm)">确定保存</el-button>
						<!-- <el-button>取消</el-button> -->
					</el-form-item>
				</el-form>
			</div>
		</div>
	</div>
</template>

<script>
	export default {
		data() {
			return {
				ABase: {
					account: localStorage.getItem('admin_username'),
				},
				webForm: {},
				rules: {
					website: [{
						required: true,
						message: '请输入网站地址',
						trigger: 'blur'
					}],
					email: [{
							required: true,
							message: '请输入邮箱',
							trigger: 'blur'
						},
						{
							validator: function(rule, value, callback) {
								if (/^[A-Za-z0-9\u4e00-\u9fa5]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/.test(value) == false) {
									callback(new Error("请输入正确的邮箱格式"));
								} else {
									callback();
								}
							},
							trigger: "blur"
						}
					],
					
					
					copyright: [{
						required: true,
						message: '请输入版权信息',
						trigger: 'blur'
					}],
				}
			};
		},
		created() {
			this.getData();
		},
		methods: {
			// 获取网站信息
			getData() {
				this.$api
					.post('master/Mysystem/getSysBase')
					.then(res => {
						if (res.code == 0) {
							this.webForm = res.data;
						} else {
							this.$message.error(res.msg);
						}
					})
					.catch(err => {
						this.$message.error(err);
					});
			},
			// 更改网站设置
			save_web(webForm) {
				this.$refs.web_Form.validate((valid) => {
					if (valid) {
						this.$api
							.post('master/Mysystem/editSysBase', this.webForm)
							.then(res => {
								if (res.code == 0) {
									this.getData();
									this.$message.success('修改网站信息成功！');
								} else {
									this.$message.error(res.msg);
								}
							})
							.catch(err => {
								this.$message.error(err);
							});
					} else {
						this.$message.error('error submit!!');
						return false;
					}
				});
			}
		}
	};
</script>
