<template>
	<div class="container" style="margin: 10px;">
		<!-- 当前费率展示   -->
		<el-form ref="model" :model="model" label-width="120px" :rules="rules">
			<el-form-item label="专员提成金额" prop="CommissionMoney">
				<el-input v-model="model.CommissionMoney" placeholder="请输入专员提成金额" ref="CommissionMoney" maxlength="10" @blur="ChangeMoney">
					<template slot="append">元</template>
				</el-input>
			</el-form-item>
			<el-form-item label="经理提成金额" prop="ManagerMoney">
				<el-input v-model="model.ManagerMoney" placeholder="请输入经理提成金额" ref="ManagerMoney" maxlength="10" @blur="ChangeMoney">
					<template slot="append">元</template>
				</el-input>
			</el-form-item>
			<el-form-item label="独享金额" >
				<el-input v-model="Dmoney" placeholder="独享金额" maxlength="10" disabled>
					<template slot="append">元</template>
				</el-input>
			</el-form-item>
		</el-form>
		<el-button type="success" @click="Submit" style="margin-left: 40px;">确认更改</el-button>
	</div>
</template>

<script>
	import {
		UpdateCalculation,
		GetModelCalculation
	} from '../../api/calculation.js'
	export default {
		data() {
			return {
				size: '',
				rules: {
					ManagerMoney: [{
							required: true,
							message: '请输入经理提成',
							trigger: 'blur'
						},
						{
							pattern: /^\d+(\.\d+)?$/,
							message: '请输入金额'
						}
					],
					CommissionMoney: [{
							required: true,
							message: '请输入专员提成',
							trigger: 'blur'
						},
						{
							pattern: /^\d+(\.\d+)?$/,
							message: '请输入金额'
						}
					]
				},
				model: {
					"id": 0,
					"CommissionMoney": 0,
					"ManagerMoney": 0,
					"add_time": "2022-01-08T21:37:09.691Z",
					"update_time": "2022-01-08T21:37:09.691Z",
					"status": 0
				},
				Dmoney:0,
				form: {
					"KeyWord": "",
					"TotalCount": 0,
					"PageIndex": 1,
					"PageSize": 1,
					"Sort": [{
						"Field": "",
						"Type": 0
					}]
				}
			}
		},
		created() {
			this.GetMoney()
		},
		methods: {
			ChangeMoney(){
				this.Dmoney=parseInt(this.model.CommissionMoney)+parseInt(this.model.ManagerMoney)
			},
			// 查询当前费率标准
			GetMoney() {
				GetModelCalculation(this.form).then(res=>{
					this.model.CommissionMoney=res.data.data.rows[0].CommissionMoney
					this.model.ManagerMoney=res.data.data.rows[0].ManagerMoney
					this.Dmoney=this.model.CommissionMoney+this.model.ManagerMoney
				})
			},
			// 确认更改提成费用
			Submit() {
				this.$refs.model.validate((valid) => {
					if (valid) {
						UpdateCalculation(this.model).then(res => {
							console.log('修改数据', res)
							if (res.data.code == 200) {
								this.$message.success('更改提成费率成功')
							} else {
								this.$message.error('更改失败,请重试')
							}
						})
					}
				})
			}
		}
	}
</script>

<style>
	.container {
		width: 100%;
	}
</style>
