index.vue
4.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<template>
<v-layout>
<template slot="breadcrumb">
<el-breadcrumb-item>工具</el-breadcrumb-item>
</template>
<template slot="main">
<div class="ibox">
<div class="ibox-title">
<h3 class="pull-left">设备信息导入</h3>
</div>
<div class="ibox-content">
<div class="import-panel">
<el-form ref="form" :model="form" :rules="rules" :inline="false" size="mini" v-show="!showResult">
<el-form-item label="" prop="filename">
<el-upload ref="upload" class="upload-wrap"
action="customstat/exportDeviceGprsGps"
:data="data"
:on-change="changeFile"
:before-upload="beforeUpload"
:multiple="false"
:show-file-list="false"
:on-success="successUpload"
:on-error="errorUpload"
:auto-upload="false">
<el-input v-model="filename" 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>
<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>
<el-row>
<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" class="pull-right" :disabled="disabled">确认</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" class="pull-right">完成</el-button>
</div>
</el-row>
</div>
</div>
</div>
</template>
</v-layout>
</template>
<script>
import {exportExcel} from 'utils'
export default{
data(){
let checkId = (rule, vaule, cb)=>{
if(this.form.deviceHardwareId === ''){
cb('')
}
cb()
}
let checkFilename = (rule, vaule, cb)=>{
if(this.filename === ''){
cb('')
}
cb()
}
return {
form: {
deviceHardwareId: ''
},
showResult: false,
successNum: '',
errorNum: '',
seqNo: '',
importing: false,
filename: '',
data:{
},
rules: {
filename: [{validator: checkFilename, trigger: 'change'}],
}
}
},
computed:{
'disabled'(){
return this.filename === ''
}
},
methods: {
doneResult(){
this.showResult = false;
this.successNum = '';
this.errorNum = '';
this.seqNo = '';
this.importing = false;
this.filename = '';
//this.form.deviceHardwareId = ''
},
exportErrorResult(){
exportExcel('device/deviceManage/exportFailDeviceManage', {seqNo: this.seqNo})
},
successUpload(res){
this.importing = false;
if(typeof res === 'object'){
if(res.returnCode == 0){
const data = res.data;
this.$refs.upload.clearFiles();
this.filename = ''
window.open(data.fileUrl)
}
}else{
window.location.href = '../ots/login';
}
},
submitUpload() {
this.$refs.form.validate((valid) => {
if(valid){
this.$refs.upload.submit();
}
})
},
changeFile(file, filelist) {
this.filename = file.name;
},
beforeUpload(file){
if(file.name == this.filename){
this.importing = true;
return true
}
return false
},
downloadTpl(){
exportExcel('device/deviceManage/downLoadDeviceManage')
},
errorUpload(err){
window.location.href = '../ots/login';
}
},
components: {
}
}
</script>
<style>
.import-panel {
max-width: 400px;
}
.import-panel .upload-wrap .el-upload{
width: 400px;
}
.import-panel .el-icon-success, .import-panel .el-icon-error{
font-size: 30px;
}
.import-panel .result-row .el-col+.el-col{
border-left: 1px solid #eee;
}
</style>