<template>
    <footer class="upload-footer">
        <a v-show="value === 0" :href="templateHref">下载模板</a>
        <div v-show="value===1" style="display: flex; align-items: center; text-align: left; flex:1">
            <nobr v-if="canSelectMethod">
                <span style="width: 90px;">导入方式</span>
            </nobr>
            <Select v-if="canSelectMethod" v-model="method" style="width:80px;margin:0 10px;">
                <Option value="APPEND">追加</Option>
                <Option value="OVERRIDE">覆盖</Option>
            </Select>
            <nobr  v-if="canSelectMethod" style="flex:1">
                <span style="color:#D81B60" v-if="method==='OVERRIDE'">!!!请注意:覆盖导入会清除所有数据!</span>
            </nobr>
        </div>
        <span v-show="value===2"></span>
        <div>
            <Button @click="onCancel">{{ btnName[value].close }}</Button>
            <Button
                :type="value === 2 ? 'error': 'primary'"
                @click="add"
                v-if="currIndex !== 2"
                :disabled="disabled"
            >{{ btnName[value].next }}</Button>
        </div>
    </footer>
</template>
<script>
export default {
    name: 'Footer',
    data() {
        return {
            /**
             * 模板下载地址
             */
            templateHref: '',
            btnName: {
                0: {
                    close: '取消',
                    next: '下一步'
                },
                1: {
                    close: '取消',
                    next: '下一步'
                },
                2: {
                    close: '取消',
                    next: '中止'
                }
            },
            method: 'APPEND'
        }
    },
    props: {
        value: Number,
        currIndex: Number,
        guid: String,
        canSelectMethod: Boolean
    },

    watch: {
        currIndex(val) {
            if (val === 2) this.btnName[2].close = '关闭'
        },
        method(val) {
            this.$emit('on-change-method', val)
        }
    },

    computed: {
        disabled() {
            if (this.value === 0 || this.value === 1) {
                if (this.currIndex !== this.value) return true
            }
            return false
        }
    },
    methods: {
        add() {
            if (this.value === 2) {
                this.$emit('on-change-index', 2)
                return
            }
            let value = this.value + 1
            this.$emit('input', value)
        },

        onCancel() {
            this.$emit('on-cancel')
        }
    },
    mounted() {
        this.templateHref = `/data-service/import-excel/download-template?guid=${this.guid}&access=876BEAC1F5437D21E050840A06393DE0`
    }
}
</script>
<style lang="less" scoped>
.upload-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
}
</style>
