<template>
    <div class="box-dialog">
        <BaseForm v-bind="form" :schemas="formConfig" label-width="110px" @cancel="onCancel" @submit="onSubmit" />
    </div>
</template>

<script>
import BaseForm from '@/components/McForm/index.vue'
import { BaseFormMixin } from '@/mixins/BaseForm'
import API from '@/server/api'
export default {
    name: "CreateDownload",
    components: {
        BaseForm
    },
    props: {
        callback: Function
    },
    mixins: [BaseFormMixin()],
    data() {
        return {
            formConfig: [
                {
                    component: 'MUpload',
                    label: '文件',
                    prop: 'excelUrl',
                    limit: 3,
                    showFileList: false,
                    accept: '.xltx,.xltm,.xlsx,.xlsm,.xls',
                    value: '',
                    rules: [
                        { required: true, message: '请上传文件', trigger: 'change' },
                    ],
                    helpMessage: '请上传借款编号:loan_no'
                },
                {
                    component: 'input',
                    label: '案件批次',
                    prop: 'batchName',
                    value: '',
                    rules: [
                        { required: true, message: '请填写案件批次', trigger: 'blur' },
                    ],
                },
                {
                    component: 'input',
                    type: "textarea",
                    label: '备注',
                    prop: 'memo',
                    value: '',
                    rules: [
                        { required: true, message: '请填写备注', trigger: 'blur' },
                    ],
                }
            ]
        }
    },
    methods: {
        async onSubmit(val) {
            try {
                const params = Object.assign({}, val)
                params.excelUrl = params.excelUrl[0]['url']
                params.creator = window.localStorage.getItem('userName')
                const { data: { success, message } } = await API.CreateCollectionDownLoad(params)
                if (success) {
                    this.$message.success(message)
                    this.$emit('callback')
                } else {
                    this.$message.error(message)
                }
                setTimeout(() => {
                    this.onCancel();
                }, 500)
            } catch (err) {
                this.$message({
                    message: '操作失败'
                })
            }
        },
        onCancel() {
            this.$children[0].reset()
            this.$parent.$parent.handleCancel();
        }
    }

}
</script>

<style lang="less" scoped></style>