<template>
	<div>
		<el-form ref="form" label-width="140px" style="margin-top: 20px;">
			<el-row v-for="(item,index) in settingList" :key="index">
				<el-col :span="24" v-if="item.level==1">
					<el-form-item label="股东分销提成">
						<el-input
							v-model="item.extract"
							placeholder="请输入股东分销提成"
							type="number"
							v-enterNumber
							style="width:200px"
						></el-input>
						<span style="color:#bfcbd9;">用户消费，其上线所得提成。提成为百分比，取值0到100之间，超出取值范围按0计算，无上线时无提成</span>
					</el-form-item>
				</el-col>

				<el-col :span="24" v-if="item.level==2">
					<el-form-item label="合伙人分销提成">
						<el-input
							v-model="item.extract"
							placeholder="请输入合伙人分销提成"
							type="number"
							v-enterNumber
							style="width:200px"
						></el-input>
						<span style="color:#bfcbd9;">用户消费，其上线所得提成。提成为百分比，取值0到100之间，超出取值范围按0计算，无上线时无提成</span>
					</el-form-item>
				</el-col>

				<el-col :span="24" v-if="item.level==3">
					<el-form-item label="代理人分销提成">
						<el-input
							v-model="item.extract"
							placeholder="请输入代理人分销提成"
							type="number"
							v-enterNumber
							style="width:200px"
						></el-input>
						<span style="color:#bfcbd9;">用户消费，其上线所得提成。提成为百分比，取值0到100之间，超出取值范围按0计算，无上线时无提成</span>
					</el-form-item>
				</el-col>

				<el-col :span="24" v-if="item.level==4">
					<el-form-item label="员工分销提成">
						<el-input
							v-model="item.extract"
							placeholder="请输入员工分销提成"
							type="number"
							v-enterNumber
							style="width:200px"
						></el-input>
						<span style="color:#bfcbd9;">用户消费，其上线所得提成。提成为百分比，取值0到100之间，超出取值范围按0计算，无上线时无提成</span>
					</el-form-item>
				</el-col>

				<el-col :span="24" v-if="item.level==0">
					<el-form-item label="普通用户分销提成">
						<el-input
							v-model="item.extract"
							placeholder="请输入普通用户分销提成"
							type="number"
							v-enterNumber
							style="width:200px"
						></el-input>
						<span style="color:#bfcbd9;">用户消费，其上线所得提成。提成为百分比，取值0到100之间，超出取值范围按0计算，无上线时无提成</span>
					</el-form-item>
				</el-col>
			</el-row>
		</el-form>
		<div slot="footer" class="dialog-footer">
			<el-button type="primary" @click="create()">立即提交</el-button>
			<el-button @click="cancel" style="width:88px">重置</el-button>
		</div>
	</div>
</template>

<script>
import { formatDate } from 'utils/dateFormattor'

import {
	toEast8Date,
	deepCopyDate,
	newEast8Date,
	convertDate2Str,
	timestamp2Date
} from 'utils/dateUtils'

import { mapGetters } from 'vuex'
import { getToken } from 'utils/auth'
import { getrewardSetting, rewardSetting } from 'api/purseManage'
import Element1 from '../admin/menu/components/element'
import ElRow from 'element-ui/packages/row/src/row'
import ElCol from 'element-ui/packages/col/src/col'

export default {
	name: 'tourManage',
	components: {
		ElCol,
		ElRow,
		Element1
	},
	data() {
		return {
			BASE_API: process.env.BASE_API,
			showLoadingBody: false,
			listLoading: true,
			form: {},
			inline: true,
			tableKey: 0,
			settingList: []
		}
	},
	created() {
		this.getSetting()
	},
	computed: {
		...mapGetters(['elements'])
	},
	methods: {
		getSetting: function() {
			this.listLoading = true
			getrewardSetting().then(response => {
				this.settingList = response.data
				this.listLoading = false
			})
		},
		create(formName) {
			var that = this
			var arr = []
			that.settingList.forEach(function(item) {
				if (item.extract == '') {
					this.$notify({
						title: '警告',
						message: '请输入' + item.name + '提成',
						type: 'warning'
					})
					return false
				}
				var obj = {}
				obj.id = item.id
				obj.extract = item.extract
				arr.push(obj)
			})
			// console.log(JSON.stringify(arr))
			// var Obj = JSON.stringify(arr)
			rewardSetting(arr).then(() => {
				this.$notify({
					title: '修改成功',
					message: '修改成功',
					type: 'success'
				})
				this.getSetting()
			})
		},
		cancel: function(formName) {
			var that = this
			that.settingList.forEach(function(item) {
				item.extract = ''
			})
		}
	}
}
</script>
