<template>
    <el-dialog :title="title" :close-on-click-modal="false" :visible.sync="visible" :before-close="close" width="30%">
        <el-form :model="formData" :rules="rules" ref="formData" label-width="90px">
            <el-col>
                <el-form-item label="金额:" prop="amount">
                    <el-input placeholder="请输入充值金额" v-model="formData.amount"></el-input>
                </el-form-item>
            </el-col>
            <el-col>
                <el-form-item label="流水号:" prop="flowNum">
                    <el-input placeholder="请输入流水号" v-model.number="formData.flowNum"></el-input>
                </el-form-item>
            </el-col>
            <!-- <el-col>
                <el-form-item label="交易类型:" prop="type">
                    <el-select placeholder="收支类型" v-model="formData.type" clearable>
                        <el-option label="收入" :value="1"></el-option>
                        <el-option label="支付" :value="2"></el-option>
                    </el-select>
                </el-form-item>
            </el-col> -->
            <el-col>
                <el-form-item label="备注:" prop="descr">
                    <el-input type="textarea" autosize placeholder="请输入备注" v-model="formData.descr"> </el-input>
                </el-form-item>
            </el-col>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button @click="close()">取 消</el-button>
            <el-button type="primary" @click="submitForm()" :disabled="submitBtndisabled">确 定</el-button>
        </div>
    </el-dialog>
</template>
<script>
import { addTyBills } from '@/apps/mobile/api/payment/platformAccount/index';
import { validWithoutZero } from '@/apps/mobile/utils/validate';
export default {
    data() {
        // 价格校验
        var checkPrice = (rule, value, callback) => {
            if (value && !validWithoutZero(value)) {
                callback(new Error('格式不正确'));
            } else {
                callback();
            }
        };
        return {
            visible: false,
            title: '充值',
            formData: {},
            rules: {
                amount: [
                    { required: true, message: '请输入金额' },
                    { validator: checkPrice, message: '请输入正确的金额', trigger: 'blur' },
                ],
                flowNum: [
                    { required: true, message: '请输入流水号', trigger: 'blur' },
                    { type: 'number', message: '请输入数字类型', trigger: 'blur' },
                ],
                descr: [{ required: true, message: '请输入备注', trigger: 'blur' }],
            },
            submitBtndisabled: false,
            money: null,
        };
    },
    methods: {
        close() {
            this.$refs['formData'].resetFields();
            this.visible = false;
        },
        open(money) {
            this.money = money;
            this.visible = true;
        },
        submitForm() {
            this.$refs['formData'].validate(valid => {
                if (valid) {
                    // console.log(this.formData.balance + this.money);
                    this.formData.balance = this.formData.amount + this.money
                    this.formData.type = 1
                    console.log(this.formData,'this.formData');
                    addTyBills(this.formData).then(res=>{
                        this.$message.success('充值成功');
                        this.$emit('queryListData')
                        this.close()
                    }).catch(err=>err)
                    
                }
            });
        },
    },
};
</script>
<style scoped>
.el-input {
    width: auto;
}
::v-deep .el-dialog {
    height: auto;
}
::v-deep .el-dialog__footer {
    margin-top: 70px;
}
</style>
