<template>
    <el-dialog id="tableBody" title="导入客户" :visible.sync="dialogVisible" width="60%" :before-close="handleClose">

        <div style="margin-left:30%">
               <el-form label-position="left" label-width="120px"   :model="formLabelAlign">
                    <el-form-item label="请填写批次号：">
                         <el-col :span="12">
                            <el-input v-model="formLabelAlign.batchNo" ></el-input>
                         </el-col>
                    </el-form-item>
                    <el-form-item label="备注信息：" >
                        <el-col :span="12">
                            <el-input v-model="formLabelAlign.remark"></el-input>
                        </el-col>
                    </el-form-item>
                    <el-form-item label="选择文件："  > 
                        <div  style="width:240px;">
                            <el-upload
                                class="upload-demo"
                                ref="upload"
                                action=""
                                :on-preview="handlePreview"
                                :on-remove="handleRemove"
                                :file-list="fileList"
                                :auto-upload="false">
                                <el-button slot="trigger" size="small" type="primary">选取文件</el-button>
                                <div slot="tip" class="el-upload__tip">只能上传excel文件!</div>
                            </el-upload>
                        </div>
                    </el-form-item>
                </el-form>
        </div>

        <div slot="footer" style="margin-right:30%;">
            <el-button type="info" plain @click="handleClose">取 消</el-button>
            <el-button type="primary" @click="submitMarket">确 定</el-button>
        </div>
    </el-dialog>
</template>

<script>
    export default {
        name: "byhRegainMarket",
        props: {
            dialogVisible: {
                type: Boolean
            },
            certNo: {
                type: String
            },
        },
        data () {
            return {
                client: {},
                records: [],
                fileList: [],
                formLabelAlign: {
                    batchNo: '',
                    remark: '',
                },
            }
        },
        methods: {

            /** 关闭处理 */
            handleClose () {
                this.visible = false
                setTimeout(() => {
                    this.$emit('update:dialogVisible', false)
                }, 100)
            },

            submitMarket() {
                this.$$post('/market/importMarket/', this.buildParam()).then(res => {
                    if (res.data.code != 1) {
                        this.$message.error(res.data.msg);
                        return
                    }
                    this.$message({message: '操作成功', type: 'success'});
                    this.handleClose();
                    window.location.reload();
                }).catch(error => {
                    this.$Message.error(error || '系统异常');
                });
            },
            // 文件上传
            handleRemove(file, fileList) {
                //console.log(file, fileList);
            },
            handlePreview(file) {
                //console.log(file);
            },
            handleExceed(files, fileList) {
                this.$message.warning(`当前限制选择 1 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`);
            },
            beforeRemove(file, fileList) {
                return this.$confirm(`确定移除 ${ file.name }？`);
            },
              //参数
            buildParam() {
                var return_hash = new FormData();

                if (this.formLabelAlign.batchNo != '') {
                     return_hash.append('batchNo',this.formLabelAlign.batchNo)
                }

                if (this.formLabelAlign.remark != '') {
                     return_hash.append('remark',this.formLabelAlign.remark)
                }
                 
                if (this.$refs.upload != '') {
                    return_hash.append('file',this.$refs.upload.uploadFiles[0].raw)
                }
                return return_hash;
            },

        }
    }
</script>

<style scoped lang="stylus" rel="stylesheet/stylus">

#tableBody{
    text-align:center;
}
</style>