<template>
    <el-form ref="form" :model="formData" :rules="formRules" label-width="120px">
        <el-form-item label="押金类型" prop="depositType">
            <el-select placeholder="请选择押金类型" v-model="formData.depositType" clearable>
                <el-option label="装修押金" :value="1"></el-option>
                <el-option label="租赁押金" :value="2"></el-option>
                <el-option label="出入证押金" :value="3"></el-option>
                <el-option label="门禁卡押金" :value="4"></el-option>
            </el-select>
        </el-form-item>
        <el-form-item label="金额" prop="amount">
            <el-input v-model="formData.amount" placeholder="请输入金额"></el-input>
        </el-form-item>
        <el-form-item label="应收时间" prop="receivableDate" class="chargeStartTime">
            <el-date-picker v-model="formData.receivableDate" type="datetime" placeholder="选择应收时间"> </el-date-picker>
        </el-form-item>
    </el-form>
</template>
<script >
export default {
    props: ['params'],
    data() {
        return {
            formData: {
                depositType: '',
                receivableDate: '',
                amount: '',
                communityId: '',
                buildingId: '',
                houseId: '',
                roomNumber: ''
            },
            formRules: {
                depositType: [this.$valid.selectRequired('押金类型')],
                amount: [this.$valid.inputRequired('金额')],
                receivableDate: [this.$valid.selectRequired('应收时间')]
            }
        };
    },

    methods: {
        submit() {
            this.$refs.form.validate((valid) => {
                if (valid) {
                    var loading = this.$loading();
                    this.$http
                        .post('/sc-charge/deposit/add', this.formData)
                        .then(({ status, msg }) => {
                            if (status == 0) {
                                this.$message.success(msg);
                                this.params.callback();
                                this.$emit('close');
                            } else {
                                this.$message.error(msg);
                            }
                            loading.close();
                        })
                        .catch(() => {
                            loading.close();
                        });
                }
            });
        }
    },
    created() {
        let { communityId, buildingId, houseId, houseName } = this.params.thisCommObj;
        this.formData.communityId = communityId;
        this.formData.buildingId = buildingId;
        this.formData.houseId = houseId;
        this.formData.roomNumber = houseName;
    }
};
</script>
<style lang="scss" scoped>
.chargeStartTime {
    /deep/ .el-date-editor {
        width: 100%;
    }
}
</style>