<template>
	<ContainerTit>
		<div slot="headr">
			<el-button :loading="sub_load" type="primary" @click="submit">
				提交保存
			</el-button>
		</div>
		<div class="detail-tab-item">
			<div class="detail-tab-title">添加股东</div>
			<div class="detail-tab-main">
				<el-form ref="add_form" label-position="right" :model="add_form" :rules="form_rules" size="small"
					label-width="100px">
					<el-form-item label="股东名称" prop="name">
						<el-input v-model="add_form.name" style="width: 300px" size="small" placeholder="股东名称">
						</el-input>
					</el-form-item>
					<el-form-item label="联系方式" prop="number">
						<el-input v-model="add_form.number" style="width: 300px" size="small" placeholder="联系方式">
						</el-input>
					</el-form-item>

					<el-form-item label="联系地址" prop="address">
						<el-input v-model="add_form.address" style="width: 300px" size="small" placeholder="联系地址">
						</el-input>
					</el-form-item>
					<el-form-item label="备注" prop="remk">
						<el-input v-model="add_form.remk" style="width: 300px" size="small" placeholder="备注"></el-input>
					</el-form-item>
				</el-form>
			</div>
		</div>
	</ContainerTit>
</template>

<script>
	import {
		add,
		Getinfo,
	} from "@/api/Holders";
	export default {
		name: "AddReward",
		data() {
			return {
				sub_load:false,
				form_rules: {
					name: [{
						required: true,
						message: "请输入股东姓名",
						trigger: "blur"
					}, ],
					number: [{
						required: true,
						message: "请输入股东联系电话",
						trigger: "blur"
					}, ],
					address: [{
						required: true,
						message: "请输入股东联系地址",
						trigger: "blur"
					}, ],
				},
				add_form: {
					name: "",
					number: '',
					address: "",
					remk: "",
					id: 0
				},
			};
		},
		created() {
			if (this.$route.query.id) {
				this.rule_id = this.$route.query.id;
				this.Get();
			}
		},
		activated() {
			if (this.$_isInit()) return;
			if (this.$route.query.id) {
				this.rule_id = this.$route.query.id;
				this.Get();
			}
		},
		methods: {
			// 获取详情
			async Get() {
				const {
					data
				} = await Getinfo({
					id: this.rule_id
				});
				this.add_form = {
					name: data.name,
					number: data.number,
					address: data.address,
					remk: data.remk,
					id: data.id,
				};
			},
			async submit() {
				this.$refs["add_form"].validate(async (valid) => {
					if (valid) {
						if (this.add_form.name == "") {
							this.$message.warning("股东姓名不能为空");
							return;
						}
						if (this.add_form.number == '') {
							this.$message.warning("股东联系电话不能为空");
							return;
						}
						if (this.add_form.address == '') {
							this.$message.warning("股东联系地址不能为空");
							return;
						}
						this.sub_load = true;
						try {
							const data = await add(this.add_form);
							this.sub_load = false;
							this.$message.success(data.data);
							this.$closeCurrentGoEdit("/Shareholders/RewardList");
						} finally {
							this.sub_load = false;
						}
					}
				});
			},
		},
	};
</script>

<style scoped></style>
