<template>
    <div style="display:inline-block;margin-left:10px;">
       <Upload style="display:inline-block"
            ref="upload"
            :action="action"
            name="excel-file"
            :headers="headers"
            :show-upload-list="false"
            :on-format-error="handleFormatError"
            :before-upload="handleBeforeUpload"
            :on-success="handleSuccess"
            :on-error="handleError"
            :format ="['xlsx']">
                <Button type="primary" icon="md-cloud-upload">{{$t('1006')}}</Button>
        </Upload>
    </div>
</template>
<script>
export default {
    data () {
        return {
            addmodal: false,
            headers: {
                token: localStorage.getItem('token'),
                timestamp: localStorage.getItem('timestamp'),
                nonce: localStorage.getItem('nonce'),
                sign: localStorage.getItem('sign')
            },
            action: this.axios.publicPath + this.uploadSrc

        }
    },
    props: {
        uploadSrc: {
            type: String
        }
    },
    methods: {
        handleBeforeUpload () {
            this.upload_btn = false
        },
        handleFormatError (file) {
            this.$Notice.warning({
                title: this.$t('950395'), // 文件格式不正确
                desc: this.$t('950396') + file.name + this.$t('950397') // 文件 xxx 格式不正确，请上传.xlsx文件。
            })
        },
        handleSuccess (res, file) {
            if (res.ret === 1) {
                this.$Message.success(this.$t('950398'))
                this.upload_btn = true
                this.$emit('upload_success', this.upload_btn)
            } else {
                if (res.msg.indexOf(',' != -1)) {
                    inittip(res.msg)
                } else {
                    window_warning(this.$t(res.msg))
                }
            }
        },
        handleError () {
            this.$Message.error(this.$t('950399'))
        }
    }
}
</script>
<style lang="less" scoped>

</style>
