<template>
	<uni-row class="main" v-bind:style="{ height: client.win_height + 'px' }">
		<uni-col :span="24" class="one">
			<form @submit="onSubmit">
				<view class="content">
					<view class="title">简历信息：</view>
					<input :value="info.work_experience" name="work_experience" placeholder="此处输入简历信息" />
				</view>
				<view class="btn">
					<button type="primary" size="mini" form-type="submit">
						提交保存
					</button>
				</view>
			</form>
		</uni-col>
	</uni-row>
</template>

<script>
	import {
		mapState,
		mapGetters,
		createNamespacedHelpers
	} from "vuex";
	const {
		mapActions: securityGuardBase
	} = createNamespacedHelpers(
		"security_guard_base"
	);
	export default {
		data() {
			return {
				info: {},
			};
		},
		created() {
			this.search();
		},
		methods: {
			...securityGuardBase(["fetch", "update"]),
			async search() {
				const {
					id
				} = this.user;
				if (!id) return;
				const res = await this.fetch({
					id
				});
				if (this.$checkRes(res)) {
					const {
						work_experience
					} = res.data;
					this.$set(this, `info`, {
						work_experience
					});
				}
			},
			onSubmit: async function(e) {
				const {
					id
				} = this.user;
				if (!id) return;
				const res = await this.update({
					id,
					...e.detail.value
				});
				if (this.$checkRes(res)) {
					uni.showToast({
						title: "保存成功",
						icon: "success"
					});
					uni.redirectTo({
						url: "/pages/home/index"
					});
				} else {
					uni.showToast({
						title: "保存失败",
						icon: "error"
					});
				}
			},
		},
		computed: {
			...mapState(["user"]),
			...mapGetters(["client"]),
		},
	};
</script>

<style lang="scss" scoped>
	.main {
		background-color: #409eff;
		overflow-y: auto;

		.one {
			float: left;
			width: 100%;

			.content {
				padding: 0 10px;
				margin: 10px 0;

				.title {
					font-size: 16px;
					margin: 0 0 8px 0;
					color: #000000;
				}

				input {
					border: 1px solid #ccc;
					border-radius: 5px;
					padding: 10px;
				}
			}

			.btn {
				text-align: center;
				margin: 15rpx 0 0 0;

				button {
					margin: 0 10px;
				}
			}
		}
	}
</style>
