importOrder.vue 5.99 KB
<template>
	<!-- 批量导入弹框 -->
	<el-dialog class="import-dialog"  :visible="importModalVisible" @open="openDialog" @close="closeDialog" append-to-body width="600px" :close-on-click-modal="false">
		<div slot="title" class="header-title">
            <span class="title-name">批量导入</span>
            <span v-show='isWoring' class="title-age">正在导入数据,请勿关闭窗口!</span>
        </div>

	  	<el-form ref="form" :model="form" :rules="rules" :inline="false" size="mini" v-show="!showResult">
  			<el-form-item label="" prop="file">
				<el-upload ref="upload" class="upload-wrap"
				  	action="workordmana/import"
				  	:on-change="changeFile"
				  	:before-upload="beforeUpload"
				  	:multiple="false"
				  	:show-file-list="false"
				  	:on-success="successUpload"
				  	:on-error="errorUpload"
				  	:data="data"
				  	:auto-upload="false">
				  	<el-input v-model="file" placeholder="未选取任何文件" class="input-with-select" size="small" >
						<el-button slot="append" >浏览</el-button>
	  				</el-input>
				  	<div slot="tip" class="el-upload__tip">请选择需要导入的工单表格</div>
				</el-upload>
			</el-form-item>
			<el-form-item label="导入类型" prop="importType">
				<el-radio-group v-model="form.importType">
			    	<el-radio  label='0'>安装单</el-radio>
			        <el-radio  label='1'>基础信息</el-radio>
			        <el-radio  label='2'>居住工作信息</el-radio>
			    </el-radio-group>
			</el-form-item>	
	  	</el-form>
		<el-row v-show="showResult" class="result-row">
			<el-col :span="12" class="text-center">
				<p><i class="el-icon-success el-alert--success"></i></p>
				<p><strong>{{successNum}}</strong><br>成功记录</p>
			</el-col>
			<el-col :span="12" class="text-center">
				<p><i class="el-icon-error el-alert--error"></i></p>
				<p><strong>{{errorNum}}</strong><br>失败记录</p>
			</el-col>
		</el-row>
		<div slot="footer" class="dialog-footer">
			<div v-show="!showResult" class="success">
				<el-button type="primary" @click="downloadTpl" size="small" class="pull-left">下载模板</el-button>
	  			<el-button type="primary" @click="submitUpload" size="small" :loading="importing" :disabled="disabled">确认</el-button>
	    		<el-button @click="canel()" size="small">关闭</el-button>
			</div>
			<div v-show="showResult">
				<el-button v-show="errorNum" type="primary" @click="exportErrorResult" size="small" class="pull-left">导出失败结果</el-button>
	    		<el-button @click="doneResult" size="small" type="primary">完成</el-button>
			</div>
	  	</div>
	</el-dialog>
</template>
<script>
	import {exportExcel} from 'utils'
	export default{
		props: ['importModalVisible'],
		data(){
			let checkFilename = (rule, vaule, cb)=>{
				if(this.file === ''){
					cb('')
				}
				cb()
			}
			return {
				form: {
				},
				type:'',
				isWoring:false,
				showResult: false,
				successNum: '',
				errorNum: '',
				seqNo: '',
				importing: false,
				file: '',
				flag:false,
				form:{
					importType:'',
				},
				data:{
					importType:''
				},
				rules: {
					file: [{validator: checkFilename, trigger: 'change'}],
					importType: [{ required: true, message: '请选择导入类型', trigger: 'change' }]
				}
			}
		},
		methods: {
			doneResult(){
				this.$emit('onImportModalChange', false);
				this.$emit('onRefreshList');
				this.showResult = false;
				this.successNum = '';
				this.errorNum = '';
				this.seqNo = '';
				this.importType = '';
				this.form.importing = false;
				this.file = '';
			},
			exportErrorResult(){
				exportExcel('workordmana/exportfail',{seqNo:this.seqNo})
			},
			successUpload(res){
				this.importing = false;
				if(typeof res === 'object'){
					if(res.returnCode == 0){
						this.isWoring = false;
						const data = res.data;
						this.successNum = data.success;
						this.errorNum = parseInt(data.fail);
						this.seqNo = data.seqNo;
						this.$refs.upload.clearFiles();
						this.showResult = true;
					}else{
						this.$message({
				          	message: res.message,
				          	type: 'error'
				        });
				        this.form.importType = '';
						this.flag = true;
						this.isWoring = false;
					}
				}else{
					
			        return false;
					//window.location.href = '../ots/login';
				}
			},
			errorUpload(err){
				//window.location.href = '../ots/login';
			},
			submitUpload() {
		        this.$refs.form.validate((valid) => {
					if(valid){
		        		this.$refs.upload.submit();
		        		this.isWoring = true;
		        	}else{
		        		return false;
		        	}
		        })
		    },
			changeFile(file, filelist) {
				if(this.flag){
					this.file = '';
					this.flag = false;
				}else{
					this.file = file.name;
				}
		    },
		    beforeUpload(file){
		    	if(file.name == this.file){
		    		this.data.importType = parseInt(this.form.importType)
		    		this.importing = true;
		    		return true
		    	}

		    	return false
		    },
			downloadTpl(){
				
					if(this.form.importType == ''){
						this.$message({
				          	message: '请选择导入类型',
				          	type: 'error'
				        });
		        		return false; 
		        	}else{
		        		let importType = parseInt(this.form.importType)
		        		exportExcel('workordmana/downtemp',{importType:importType})
		        		
		        	}
		        
				
			},
			openDialog(){
				this.$emit('onImportModalChange', true)
			},
			closeDialog(){
				this.$emit('onImportModalChange', false);
				
			},
			canel(){
				this.$emit('onImportModalChange', false);
				this.seqNo = '';
				this.form.importType = '';
				this.importing = false;
				this.file = '';
			}
		},
		components: {
			
		}
	}
</script>

<style>
	.import-dialog .upload-wrap .el-upload{
		width: 100%;
	}
	.import-dialog .el-icon-success, .import-dialog .el-icon-error{
		font-size: 30px;
	}
	.import-dialog .result-row .el-col+.el-col{
		border-left: 1px solid #eee;
	}
	.title-name{
		font-size: 18px;
		color: #606266;
	}
	.title-age{
		float: right;
		margin-right: 15px;
		color: red;
	}
</style>