@ -1,7 +1,9 @@
< script >
import {
downLoadObjectFile , getProvisionalDataList , provisionalDataAlterHandle ,
queryFileId ,
removeExternalPart ,
saveExternalPart ,
saveExternalPart , savePartInfoByExcel ,
selectExternalPartList , selectExternalPartPage ,
selectUnitList ,
updateExternalPart
@ -62,6 +64,14 @@ export default {
exportHeader : [ 'Part Info' ] ,
exportFooter : [ ] ,
resultList : [ ] ,
/ / 导 入
visible : false ,
fileList : [ ] ,
provisionalDataVisible : false ,
provisionalDataList : [ ] ,
isLoading : false ,
isLoading2 : false ,
isLoading3 : false ,
no : 1 ,
size : 50 ,
total : 0 ,
@ -851,6 +861,7 @@ export default {
let params = {
... this . part ,
site : this . $store . state . user . site ,
provisionalData : 'N' ,
}
selectExternalPartList ( params ) . then ( ( { data } ) => {
if ( data && data . code === 0 ) {
@ -1152,6 +1163,7 @@ export default {
site : this . $store . state . user . site ,
no : this . no ,
size : this . size ,
provisionalData : 'N' ,
}
selectExternalPartPage ( params ) . then ( ( { data } ) => {
if ( data && data . code === 0 ) {
@ -1231,6 +1243,144 @@ export default {
let s = eval ( '(' + json + ')' )
return s
} ,
partUpload ( ) {
this . visible = true
} ,
/ / 关 闭 m o d a l
closeUploadDialog ( ) {
this . fileList = [ ]
/ / 清 空 文 件 上 传 记 录
this . $refs . uploadFile . clearFiles ( )
/ / 关 闭 当 前 的 页 面
this . visible = false
} ,
/ / 保 修 当 前 的 数 据
saveUploadFile ( ) {
/ / 判 断 文 件 是 否 上 传
if ( null == this . fileList || 0 === this . fileList . length ) {
this . $message . error ( "请先上传文件!" )
return false
}
this . isLoading = true
const formData = new FormData ( )
formData . append ( "file" , this . fileList [ 0 ] . raw )
formData . append ( "createBy" , this . $store . state . user . name )
formData . append ( "site" , this . $store . state . user . site . toString ( ) )
savePartInfoByExcel ( formData ) . then ( ( { data } ) => {
if ( data . code === 0 ) {
/ / 关 闭 窗 口 并 刷 新 页 面
this . provisionalDataDialogHandle ( )
} else {
this . isLoading = false
this . $message . warning ( data . msg )
}
} )
} ,
provisionalDataDialogHandle ( ) {
getProvisionalDataList ( ) . then ( ( { data } ) => {
if ( data . code === 0 ) {
this . provisionalDataList = data . rows
this . isLoading = false
this . provisionalDataVisible = true
} else {
this . isLoading = false
this . $message . warning ( data . msg )
}
} )
} ,
/ / 上 传 之 前
beforeUploadHandle ( file ) {
let extName = file [ 0 ] . name . substring ( file [ 0 ] . name . lastIndexOf ( '.' ) ) . toLowerCase ( )
if ( ! ( extName === '.xlsx' || extName === '.xls' ) ) {
this . $message . error ( '数据导入失败,请选择正确的xlsx模板文件' )
return false
}
} ,
/ / 选 择 上 传 文 件 时
onChange ( file ) {
this . fileList . push ( file )
} ,
/ / 下 载
async downloadFile ( ) {
let file = {
id : 0 ,
fileName : ''
}
let tempData = {
orderRef1 : 'partInfo' ,
orderRef2 : 'partInfoFormat'
}
await queryFileId ( tempData ) . then ( ( { data } ) => {
if ( data && data . code === 0 ) {
file . id = data . data . id
file . fileName = data . data . fileName
} else {
this . $alert ( data . msg , '错误' , {
confirmButtonText : '确定'
} )
}
} )
await downLoadObjectFile ( file ) . then ( ( { data } ) => {
/ / 不 限 制 文 件 下 载 类 型
const blob = new Blob ( [ data ] , { type : "application/octet-stream" } )
/ / 下 载 文 件 名 称
const fileName = file . fileName
/ / a 标 签 下 载
const linkNode = document . createElement ( 'a' )
/ / a 标 签 的 d o w n l o a d 属 性 规 定 下 载 文 件 的 名 称
linkNode . download = fileName
linkNode . style . display = 'none'
/ / 生 成 一 个 B l o b U R L
linkNode . href = URL . createObjectURL ( blob )
document . body . appendChild ( linkNode )
/ / 模 拟 在 按 钮 上 的 一 次 鼠 标 单 击
linkNode . click ( )
/ / 释 放 U R L 对 象
URL . revokeObjectURL ( linkNode . href )
document . body . removeChild ( linkNode )
} )
} ,
provisionalDataAlterHandle ( type ) {
if ( type === 1 ) {
this . isLoading2 = true
} else if ( type === 2 ) {
this . isLoading3 = true
}
let inData = {
provisionalDataList : this . provisionalDataList ,
type : type
}
provisionalDataAlterHandle ( inData ) . then ( ( { data } ) => {
if ( data . code === 0 ) {
if ( type === 1 ) {
this . $message . success ( data . msg )
this . provisionalDataVisible = false
this . visible = false
this . handleSelectExternalPartPage ( )
this . isLoading2 = false
} else if ( type === 2 ) {
this . $message . warning ( 'Import cancelled!' )
this . provisionalDataVisible = false
this . isLoading3 = false
}
} else {
this . $message . warning ( data . msg )
if ( type === 1 ) {
this . isLoading2 = false
} else if ( type === 2 ) {
this . isLoading3 = false
}
}
} )
} ,
} ,
computed : { } ,
activated ( ) {
@ -1241,6 +1391,7 @@ export default {
}
} ,
created ( ) {
this . provisionalDataAlterHandle ( 3 )
this . selectUnitList ( )
this . getCategoryList ( )
/ / t h i s . g e t C o u n t r y L i s t ( ) ;
@ -1282,6 +1433,7 @@ export default {
< el -button type = "primary" @click ="handleSave" v-if ="!ofComponents" > New < / el -button >
<!-- < el -button type = "primary" @click ="selectExternalPartList" > Query < / el -button > -- >
< el -button type = "primary" @click ="handleSelectExternalPartPage" > Query < / el -button >
< el -button type = "primary" icon = "el-icon-upload" v-if ="this.$store.state.user.userType !== 'Common Users'" @click="partUpload()" > Import Part Info < / el -button >
< download -excel
: fields = "fields()"
: data = "exportData"
@ -1491,6 +1643,55 @@ export default {
< / div >
< / e l - d i a l o g >
< el -dialog title = "File Import" @close ="closeUploadDialog" :close-on-click-modal ="false" :visible.sync ="visible" width = "390px" style = "height: 520px;" class = "customer-dialog" >
< el -form :inline ="true" label -position = " top " label -width = " 80px " >
< el -form -item label = "Site" >
< el -input v -model = " this. $ store.state.user.site " disabled > < / e l - i n p u t >
< / e l - f o r m - i t e m >
< el -form -item label = " " >
< el -button type = "primary" @click ="downloadFile()" > Download file template < / el -button >
< / e l - f o r m - i t e m >
< el -row >
< el -col :span ="24" >
< el -upload class = "customer-upload" drag action = "javascript:void(0);" ref = "uploadFile" :limit ="1" accept = ".xlsx,.xls"
: before - upload = "beforeUploadHandle" : on - change = "onChange" : auto - upload = "false" style = "text-align: left;" >
< i class = "el-icon-upload" > < / i >
< div class = "el-upload__text" > Drag the file here , or < em > click to upload < / em > < / div >
< / e l - u p l o a d >
< / e l - c o l >
< / e l - r o w >
< / e l - f o r m >
< span slot = "footer" class = "dialog-footer" >
< el -button type = "primary" @click ="saveUploadFile" > {{ isLoading ? ' Saving... ' : ' Save ' }} < / el -button >
< el -button type = "primary" @click ="closeUploadDialog" > Cancel < / el -button >
< / span >
< / e l - d i a l o g >
< el -dialog title = "Import Info View" @close ="provisionalDataAlterHandle(3)" :close-on-click-modal ="false" :visible.sync ="provisionalDataVisible" width = "1100px" >
< el -table :data ="provisionalDataList" : height = "height + 200" border style = "width: 100%;margin-top: 5px" >
< el -table -column
v - for = "(item,index) in columnList" : key = "index"
: sortable = "item.columnSortable"
: prop = "item.columnProp"
: header - align = "item.headerAlign"
: show - overflow - tooltip = "item.showOverflowTooltip"
: align = "item.align"
: fixed = "item.fixed==''?false:item.fixed"
: min - width = "item.columnWidth"
: label = "item.columnLabel" >
< template slot -scope = " scope " >
< span v-if ="!item.columnHidden" > {{ scope.row [ item.columnProp ] }} < / span >
< span v-if ="item.columnImage" > < img :src ="scope.row[item.columnProp]"
style = "width: 100px; height: 80px" / > < / span >
< / template >
< / e l - t a b l e - c o l u m n >
< / e l - t a b l e >
< span slot = "footer" class = "dialog-footer" >
< el -button type = "primary" @click ="provisionalDataAlterHandle(1)" > {{ isLoading2 ? ' Saving... ' : ' Confirm Import ' }} < / el -button >
< el -button type = "primary" @click ="provisionalDataAlterHandle(2)" > {{ isLoading3 ? ' Canceling... ' : ' Cancel ' }} < / el -button >
< / span >
< / e l - d i a l o g >
< div v-show ="false" >
< img :src ="item" v-for ="(item,index) in base64List" :key="index" style="display: none" >
< / div >