<template>
    <div>
        <el-form :model="formData" :rules="rules" ref="form" label-width="80px" label-position="right" size="small" style="max-width: 500px;">
            <el-form-item prop="userId" label="用户">
                <el-select v-model="formData.userId" filterable placeholder="请选择" size="small">
                    <el-option v-for="item in userInfos" :key="item.id" :label="item.nickname" :value="item.id">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item prop="money" label="变动金额">
                <el-input v-model="formData.money"></el-input>
            </el-form-item>
            <el-button @click="onSave" :loading="$store.state.fetchingData" type="primary">保存</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>
<script>
import formValidator from '../formValidator'

export default {
    created() {

        this.$http.get({
            url: '/userInfo/all'
        }).then(res => {
            if (res.success) {
                this.userInfos = res.data;
            }
        });

    },
    data() {
        return {
            saving: false,
            formData: {},
            rules: {
            },
            subColumn: '',
            subValue: '',
            userInfos: [],
        }
    },
    methods: {
        onSave() {
            this.$refs.form.validate((valid) => {
                if (valid) {
                    this.submit();
                } else {
                    return false;
                }
            });
        },
        submit() {
            var data = JSON.parse(JSON.stringify(this.formData));
            this.$http.post({
                url: '/memberCoin/song',
                data: data
            }).then(res => {
                if (res.success) {
                    this.$message.success('成功');
                    this.$router.go(-1);
                } else {
                    this.$message.warning('失败')
                }
            });
        },
    }
}
</script>
<style lang="less" scoped>
</style>
