gasBottleImportDialog.vue
5.5 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
176
177
178
179
<template>
<div class="dialogSty">
<el-dialog
:title="upload.title"
:visible.sync="upload.open"
width="400px"
append-to-body
>
<el-row>
<el-form label-width="90px" :model="queryForm" :rules="queryFormRules" ref="queryForm" >
<el-form-item label="所属企业:" prop="qyId">
<el-select v-model="queryForm.qyId" style="width: 100%;" @change="handleQyChange" placeholder="请选择">
<el-option v-for="item in qyOption" :key="item.qyId" :label="item.qymc" :value="item.qyId">
</el-option>
</el-select>
</el-form-item>
<el-form-item label="所属气站:" prop="qzId">
<el-select v-model="queryForm.qzId" style="width: 100%;" placeholder="请选择">
<el-option v-for="item in qzOption" :key="item.qzId" :label="item.qzmc" :value="item.qzId">
</el-option>
</el-select>
</el-form-item>
</el-form>
</el-row>
<el-upload
ref="upload"
accept=".xlsx, .xls"
multiple
:action="upload.action"
drag
:data="uploadObj"
:on-success="handleFileSuccess"
:auto-upload="false"
:headers="upload.headers"
:on-error="handleFileError"
>
<!-- :disabled="upload.isUploading" -->
<!-- :on-progress="handleFileUploadProgress" -->
<i class="el-icon-upload"></i>
<div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
<div class="el-upload__tip" slot="tip">
<el-link type="info" style="font-size:12px" @click="importTemplate">下载模板</el-link>
</div>
<div class="el-upload__tip" style="color: red;" slot="tip">
提示:仅允许导入“xls”或“xlsx”格式文件!
</div>
</el-upload>
<div slot="footer" class="dialog-footer">
<el-button @click="upload.open = false">取 消</el-button>
<el-button type="primary" @click="submitDeliveryForm('queryForm')"
>确 定</el-button
>
</div>
</el-dialog>
</div>
</template>
<script>
import {getGasBottleTemplate } from '@/api/gasRecord'
import download from "@/mixins/download";
import {getCurrentEnterpriseAndStation} from "@/api/common";
export default {
name: "gasBottleImportDialog",
mixins: [ download ],
data(){
return{
queryFormRules:{
qyId:[
{required:true,message:'请选择所属企业',trigger:'change'}
],
qzId:[
{required:true,message:'请选择所属气站',trigger:'change'}
],
},
qyOption:[],
qzOption:[],
allOption:[],
//上传文件携带的参数
uploadObj: {
czId:"",
},
queryForm:{
qyId:'',
qzId:''
},
// 发货导入参数
upload: {
// 是否显示弹出层(会员导入)
open: false,
action:'',
// 弹出层标题(会员导入)
title: "",
// 是否禁用上传
// isUploading: false,
// 设置上传的请求头部
headers: {
Authorization: "Bearer " + this.$store.state.user.accessToken,
},
// 上传的地址
// url: process.env.VUE_APP_BASE_API + "/fm/importUser/importData"
},
}
},
async created() {
await this.getEnterpriseAndStationList();
console.log('打印this.$store.getters',this.$store);
this.upload.action = `${window.context.portal}/manage/qpxx/v1/bottleBatchImport`;
},
methods:{
open(row){
console.log('打印row',row);
this.upload.open = true;
this.queryForm.qzId = '';
this.queryForm.qyId = '';
this.upload.title ='导入气瓶信息';
},
//获取企业和气站数据
async getEnterpriseAndStationList(){
await getCurrentEnterpriseAndStation().then((res)=>{
console.log('打印当前气站和企业信息数据====',res);
const { value } = res;
if(value.length>0){
this.allOption = value;
this.qyOption = value?value.map((item)=>{
return {
qyId:item.qyId,
qymc:item.qymc
}
}):[];
console.log('打印 this.qyOption ', this.qyOption );
console.log('打印 this.allOption ', this.allOption );
}
})
},
//选择企业的数据
handleQyChange(val){
this.qzOption =[];
this.queryForm.qzId ='';
this.qzOption = this.allOption.filter((item)=>item.qyId == val)[0].qzxxList;
},
submitDeliveryForm(formName) {
this.$refs[formName].validate((valid) => {
if (valid) {
this.uploadObj.czId = this.queryForm.qzId;
this.$refs.upload.submit();
} else {
console.log('error submit!!');
return false;
}
});
},
//文件上传失败处理
handleFileError(err, file, fileList) {
this.$message.error("上传失败,请重新上传!");
},
// 文件上传成功处理
handleFileSuccess(response, file, fileList) {
this.upload.open = false;
this.$refs.upload.clearFiles();
this.$message.success("导入成功");
this.$emit('handleRefresh');
},
/** 下载模板操作 */
async importTemplate() {
await getGasBottleTemplate().then((response) => {
console.log("response", response);
this.handleDownload(response, "气瓶信息导入模板");
});
},
}
}
</script>
<style lang="scss" scoped>
.dialogSty{
}
</style>