<template>
	<div>
		<div class="crumbs">
			<el-breadcrumb separator="/">
				<el-breadcrumb-item><i class="el-icon-lx-punch"></i> 员工系统</el-breadcrumb-item>
				<el-breadcrumb-item>工资管理</el-breadcrumb-item>
				<el-breadcrumb-item>工资管理 - 员工</el-breadcrumb-item>
			</el-breadcrumb>
		</div>
		<div class="container">
			<div class="form-box">
				<el-form :model="wageForm" :rules="rules" ref="wage_Form" label-width="80px">
					<el-form-item label="员工">
						<span style="padding-left: 15px;">{{this.$route.query.wages_num}}</span>
					</el-form-item>
					<el-form-item label="基本工资">
						<span style="padding-left: 15px;">{{wageForm.baseprice}}</span>
					</el-form-item>
					<el-form-item label="绩效">
						<span style="padding-left: 15px;">{{wageForm.journalprice}}</span>
					</el-form-item>
					<el-form-item label="增加工资" prop="add_price">
						<el-input type="text" v-model="wageForm.add_price"></el-input>
					</el-form-item>
					<el-form-item label="增加原因" prop="add_reason">
						<el-input type="textarea" v-model="wageForm.add_reason" rows="3"></el-input>
					</el-form-item>
					<el-form-item label="减少工资" prop="sub_price">
						<el-input type="text" v-model="wageForm.sub_price"></el-input>
					</el-form-item>
					<el-form-item label="减少原因" prop="sub_reason">
						<el-input type="textarea" v-model="wageForm.sub_reason" rows="3"></el-input>
					</el-form-item>
					<el-form-item>
						<el-button type="primary" @click="onSubmit(wageForm)">确定保存</el-button>
					</el-form-item>
				</el-form>
			</div>

		</div>


	</div>
</template>

<script>
	export default {
		data() {
			return {
				Uw_url: 'special',
				// Uw_url: 'api',
				wageForm: {},
				rules: {
					add_price: [{
						required: true,
						message: '请输入增加工资',
						trigger: 'blur'
					}],
					add_reason: [{
						required: true,
						message: '请输入增加原因',
						trigger: 'blur'
					}],
					sub_price: [{
						required: true,
						message: '请输入减少工资',
						trigger: 'blur'
					}],
					sub_reason: [{
						required: true,
						message: '请输入减少原因',
						trigger: 'blur'
					}]
				}
			};
		},
		created() {
			this.getData();
		},
		methods: {
			// 获取员工个人详情
			getData() {
				this.$api
					.post(this.Uw_url+'/Staff/getStaffRealtime', {
						'name': this.$route.query.wages_num
					})
					.then(res => {
						if (res.code == 0) {
							this.wageForm = res.data;
						} else {
							this.$message.error(res.msg);
						}
					})
					.catch(err => {
						this.$message.error(err);
					});
			},

			// 提交员工信息
			onSubmit(wageForm) {
				if (this.wageForm.add_price == '0') {
					this.$message.error("工资未出单，请每月25日后修改！");
				} else {
					this.$refs.wage_Form.validate((valid) => {
						if (valid) {
							this.$api
								.post(this.Uw_url+'/Staff/editStaffLog', this.wageForm)
								.then(res => {
									if (res.code == 0) {
										this.$message.success('修改员工信息成功！');
										this.getData();
									} else {
										this.$message.error(res.msg);
									}
								})
								.catch(err => {
									this.$message.error(err);
								});
						} else {
							this.$message.error('error submit!!');
							return false;
						}
					});
				}

			}
		}
	};
</script>

<style>
	.title_header {
		margin-bottom: 20px;
	}
</style>
