<el-button v-if="dataModelFlag[3]" type="primary" @click="getImportDialog">维度数据导入</el-button>
<el-dialog title="维度数据导入" :visible.sync="dialogFormVisibleImport" width="50%">
<el-upload class="upload-demo upload-demo-auth" ref="upload" accept=".xls,.xlsx" ref="upLoadFile"
action="https://jsonplaceholder.typicode.com/posts/" :on-preview="handlePrev" :on-remove="handleRemove"
:on-change="perChange" :file-list="fileList" :auto-upload="false" :limit="1" :on-exceed="handleExceed">
<el-button slot="trigger" size="small" type="primary">选取文件</el-button>
</el-upload>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="getDimensionDataTemplate">下载模板</el-button>
<el-button type="primary" @click="upLoadDimensionData" :disabled="prImport">导 入</el-button>
<el-button type="primary" @click="dialogFormVisibleImport = false">取 消</el-button>
</div>
</el-dialog>
dimensionExcelTemplate({commit,state},data){
return new Promise((resolve, reject) => {
getExport({
url: urlConfig.dimensionMag.dimensionExcelTemplate,
data: data,
responseType: 'blob',
headers: {
Authorization: this.state.Login.token
}
}, function (res) {
resolve(res)
}, function (err) {
reject(err)
})
})
},
dimensionTreeUpload({commit,state},data){
return new Promise((resolve, reject) => {
post({
url: urlConfig.dimensionMag.dimensionTreeUpload,
data: data,
headers: {
Authorization: this.state.Login.token
}
}, function (res) {
resolve(res)
}, function (err) {
reject(err)
})
})
},
dialogFormVisibleImport: false,
param: '',
fileList: [],
prImport:false,
getImportDialog() {
this.fileList = []
this.param = ''
this.dialogFormVisibleImport = true
},
getDimensionDataTemplate() {
let that = this
let _data = {}
that.$store.dispatch('dimensionExcelTemplate', _data).then(function (res) {
console.log(res.data)
let file = res.data
let blob = new Blob([file])
let url = URL.createObjectURL(blob)
let fileName = decodeURIComponent("维度数据导入模板.xls")
if (navigator.msSaveBlob) {
that.$message({
type: 'success',
message: '下载成功'
})
return navigator.msSaveBlob(blob, fileName)
}
else {
let link = document.createElement('a')
link.download = fileName
link.href = url
link.style.display = 'none'
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
that.$message({
type: 'success',
message: '下载成功'
})
}
}, function (err) {
that.$message({
type: 'error',
message: '下载失败'
})
})
},
perChange(file) {
console.log(file);
this.param = new FormData();
this.param.append('file', file.raw);
this.param.append('applicationId', this.application_id)
console.log(this.param)
},
handleRemove(file, fileList) {
console.log(file, fileList);
this.param = ''
},
handlePrev(file) {
console.log(file);
},
handleExceed(files, fileList) {
this.$message.warning(`当前限制选择 1个文件,本次选择了 ${files.length} 个文件,共选择了 ${files.length + fileList.length} 个文件`);
},
upLoadDimensionData() {
let that = this
console.log(that.param)
if (that.param == ''){
that.$message({
message: '请选择导入文件',
type: "warning"
})
return;
}
that.prImport = true
that.$store.dispatch('dimensionTreeUpload', that.param).then(function (res) {
that.prImport = false
if (res.flag) {
that.$message({
message: '导入成功',
type: "success",
duration: 1000,
onClose: function () {
that.fileList = []
that.param = ''
that.dialogFormVisibleImport = false
}
})
that.getDimensionTypeList()
}
else {
that.$message({
message: res.message,
type: "warning"
})
}
}, function (err) {
that.prImport = false
that.$message({
message: err.message,
type: "error"
})
})
},