You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
378 lines
14 KiB
378 lines
14 KiB
2 years ago
|
import {
|
||
|
PrintServices,
|
||
|
postImportDown,
|
||
|
postImport,
|
||
|
fileStorage,
|
||
|
fileStorageCreate
|
||
|
} from '@/api/wms-api'
|
||
|
|
||
|
export const mixins = {
|
||
|
data() {
|
||
|
return {
|
||
|
//Dialog标题
|
||
|
formTitle: "",
|
||
|
editOptions: {
|
||
|
options: [], //autoComplete显示数据|| select显示数据(拉取)
|
||
|
// whetherOrNot: this.$staticOptions.WhetherOrNot(),
|
||
|
// openToClose: this.$staticOptions.OpenToClose(),
|
||
|
// week: this.$staticOptions.Week(),
|
||
|
// inspectType: this.$staticOptions.InspectType(),
|
||
|
// whetherOrNot: this.$staticOptions.WhetherOrNot(),
|
||
|
// storeRelationType: this.$staticOptions.storeRelationType(),
|
||
|
// QtyUom: this.$staticOptions.QtyUom(),
|
||
|
},
|
||
|
//表头 从本地缓存获取字段设置,如果没有,从js中获取 todo:优化数据
|
||
|
tableColumns: this.initTableColumns(),
|
||
|
//明细表头数据
|
||
|
detailsTableColumns: this.$isDetailsTableColumns[this.$route.name],
|
||
|
//明细表头数据——汇总
|
||
|
summaryTableColumns: this.$isSummaryTableColumns[this.$route.name],
|
||
|
|
||
|
//详情数据
|
||
|
tabsDesTions: this.$isTabsDesTions[this.$route.name],
|
||
|
|
||
|
// 主表查询-快速搜索数据配置
|
||
|
quicklySearchOption: this.$isQuicklySearchOption[this.$route.name],
|
||
|
|
||
|
// 主表查询-初级搜索数据配置
|
||
|
primarySearchOption: this.$isPrimarySearchOption[this.$route.name],
|
||
|
|
||
|
//当前操作
|
||
|
theEvent: "",
|
||
|
editHandle: [{
|
||
|
label: "取消",
|
||
|
name: "cancel"
|
||
|
},
|
||
|
{
|
||
|
label: "确定",
|
||
|
type: "primary",
|
||
|
name: "determine"
|
||
|
},
|
||
|
],
|
||
|
}
|
||
|
},
|
||
|
methods: {
|
||
|
initTableColumns(){
|
||
|
let _local = localStorage.getItem(this.$store.getters.name.userName + '_' + this.$route.name)
|
||
|
let _list_local = JSON.parse(localStorage.getItem(this.$store.getters.name.userName + '_' + this.$route.name))
|
||
|
let _list_defalut = this.$isTableColumns[this.$route.name]
|
||
|
let _new_list = [] //格式化后的数据
|
||
|
if(!_local){
|
||
|
_new_list = _list_defalut
|
||
|
}else{
|
||
|
// 如果默认中已经删除掉的,本地中缓存中也不显示,新增字段,缓存中也显示(默认为眼睛关闭)
|
||
|
_list_defalut.forEach((defalutItem,index) => {
|
||
|
defalutItem.isture = false
|
||
|
_new_list.push(defalutItem)
|
||
|
_list_local.forEach(localItem => {
|
||
|
if(!defalutItem.showProp && defalutItem.prop == localItem.prop){
|
||
|
_new_list[index].isture = localItem.isture
|
||
|
}else if(defalutItem.showProp && defalutItem.showProp == localItem.showProp){
|
||
|
_new_list[index].isture = localItem.isture
|
||
|
}
|
||
|
});
|
||
|
});
|
||
|
}
|
||
|
return _new_list
|
||
|
},
|
||
|
//添加子表
|
||
|
openAddNew() {
|
||
|
let data = JSON.parse(JSON.stringify(...this.childTableData))
|
||
|
if (data.number != undefined) { //判断是否有number字段
|
||
|
data.number = this.CreateFormData.number
|
||
|
}
|
||
|
if (this.formReveal) {
|
||
|
this.CreateFormData.details.push(data)
|
||
|
} else {
|
||
|
// data.poLine = Number(this.editFormData.details[this.editFormData.details.length - 1].poLine) + 1
|
||
|
this.editFormData.details.push(data)
|
||
|
}
|
||
|
// this.displayDialog.AddNewDialog = true
|
||
|
},
|
||
|
//子表操作
|
||
|
childTable(e, val) {
|
||
|
let UrlData = {
|
||
|
detailId: val.row.id
|
||
|
}
|
||
|
switch (e.target.innerHTML) {
|
||
|
case "删除":
|
||
|
this.$confirm('您确定删除吗, 是否继续?', '提示', {
|
||
|
confirmButtonText: '确定',
|
||
|
cancelButtonText: '取消',
|
||
|
type: 'warning'
|
||
|
}).then(() => {
|
||
|
if (this.formReveal) {
|
||
|
this.CreateFormData.details.splice(val.$index, 1)
|
||
|
} else {
|
||
|
// postDetailDelete(this.propsData.id, UrlData, this.URL).then(res => {
|
||
|
// this.editFormData.details.splice(val.$index, 1)
|
||
|
// })
|
||
|
this.editFormData.details.splice(val.$index, 1)
|
||
|
}
|
||
|
}).catch(() => {
|
||
|
|
||
|
});
|
||
|
break;
|
||
|
case "确定":
|
||
|
postDetailUpdate(val.row, this.propsData.id, UrlData, this.URL).then(res => {})
|
||
|
}
|
||
|
},
|
||
|
//步骤新增OR编辑结束退出
|
||
|
stepsClose(val) {
|
||
|
// this.FormRemove(val[0]);
|
||
|
this.CreateFormData = val[0]
|
||
|
if (val[1] == 1) {
|
||
|
this.oldSkipCount = 1;
|
||
|
this.paging();
|
||
|
}
|
||
|
this.displayDialog.newDialog = false;
|
||
|
},
|
||
|
//步骤新增OR编辑第一步
|
||
|
stepsHandelOne() {
|
||
|
return new Promise((resolve, reject) => {
|
||
|
resolve()
|
||
|
})
|
||
|
},
|
||
|
//打印标签
|
||
|
Print(val) {
|
||
|
const loading = this.$loading({
|
||
|
lock: true,
|
||
|
text: 'Loading',
|
||
|
});
|
||
|
return new Promise((resolve, reject) => {
|
||
|
PrintServices(val).then(res => {
|
||
|
// console.log(process.env.VUE_APP_PRINT_API + '/' + res)
|
||
|
// window.open(process.env.VUE_APP_PRINT_API + '/' + res)
|
||
|
// window.open('http://10.74.150.81:9082' + '/' + res)
|
||
|
//杭州
|
||
|
const BaseURL = localStorage.getItem('base') + '/' + res
|
||
|
window.open(BaseURL)
|
||
|
loading.close()
|
||
|
resolve()
|
||
|
}).catch(err => {
|
||
|
loading.close()
|
||
|
reject()
|
||
|
})
|
||
|
})
|
||
|
},
|
||
|
//导出存储
|
||
|
// blob(res) {
|
||
|
// // const name = decodeURIComponent (res.disposition.slice(res.disposition.indexOf('=') + 1))
|
||
|
// const name = filters.Roles(this.$route.name)
|
||
|
// // delete res.disposition
|
||
|
// let blob = new Blob([res], {
|
||
|
// type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
||
|
// })
|
||
|
// const href = URL.createObjectURL(blob) //创建新的URL表示指定的blob对象
|
||
|
// const a = document.createElement('a') //创建a标签
|
||
|
// a.style.display = 'none'
|
||
|
// a.href = href // 指定下载链接
|
||
|
// a.download = name //指定下载文件名
|
||
|
// a.click() //触发下载
|
||
|
// URL.revokeObjectURL(a.href) //释放URL对象
|
||
|
// },
|
||
|
downloadFile(data, fileName) {
|
||
|
var byteString = atob(data)
|
||
|
var arrayBuffer = new ArrayBuffer(byteString.length) // 创建缓冲数组
|
||
|
var intArray = new Uint8Array(arrayBuffer) // 创建视图
|
||
|
for (var i = 0; i < byteString.length; i++) {
|
||
|
intArray[i] = byteString.charCodeAt(i)
|
||
|
}
|
||
|
const blob = new Blob([intArray], { type: '' })
|
||
|
// 获取heads中的filename文件名
|
||
|
const downloadElement = document.createElement('a')
|
||
|
// 创建下载的链接
|
||
|
const href = window.URL.createObjectURL(blob)
|
||
|
downloadElement.href = href
|
||
|
// 下载后文件名
|
||
|
downloadElement.download = fileName
|
||
|
document.body.appendChild(downloadElement)
|
||
|
// 点击下载
|
||
|
downloadElement.click()
|
||
|
// 下载完成移除元素
|
||
|
document.body.removeChild(downloadElement)
|
||
|
// 释放掉blob对象
|
||
|
window.URL.revokeObjectURL(href)
|
||
|
},
|
||
|
//导出存储-新
|
||
|
blob(res, fileName) {
|
||
|
let blob = new Blob([res], {
|
||
|
type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
||
|
})
|
||
|
const href = URL.createObjectURL(blob) //创建新的URL表示指定的blob对象
|
||
|
const a = document.createElement('a') //创建a标签
|
||
|
a.style.display = 'none'
|
||
|
a.href = href // 指定下载链接
|
||
|
a.download = fileName //指定下载文件名
|
||
|
a.click() //触发下载
|
||
|
URL.revokeObjectURL(a.href) //释放URL对象
|
||
|
},
|
||
|
//导入文件-新
|
||
|
postImportMergeClick(val) {
|
||
|
let that = this
|
||
|
let menuName = this.$route.meta.title
|
||
|
if (val[0][0] == 0) {
|
||
|
that.FormRemove(val[0]);
|
||
|
that.displayDialog.importDialog = false;
|
||
|
} else {
|
||
|
val[0][1].validate((valid) => {
|
||
|
if (valid) {
|
||
|
that.Loading.importLoading = true;
|
||
|
let {
|
||
|
formFile
|
||
|
} = val[1]
|
||
|
let fd = new FormData();
|
||
|
let fileName = ''
|
||
|
let rd = new FileReader(); // 创建文件读取对象
|
||
|
// formFile.forEach((item) => {
|
||
|
// fd.append("formFile", item)
|
||
|
// fd.append("method", val[1].method)
|
||
|
// fd.append("isAllowPartImport", val[1].isAllowPartImport=='0'?true:false)
|
||
|
// })
|
||
|
|
||
|
// 目前只有单文件上传,写法只适用于单文件上传
|
||
|
fileName = formFile[0].name
|
||
|
rd.readAsDataURL(formFile[0])
|
||
|
rd.onloadend = function(){
|
||
|
var arrayBuffer = rd.result
|
||
|
let params = {
|
||
|
fileName: fileName,
|
||
|
bytes: arrayBuffer.substring(arrayBuffer.indexOf(',') + 1, arrayBuffer.length)
|
||
|
}
|
||
|
// 特殊导入接口判断
|
||
|
let _uploadURL = that.importUploadURL || that.URL
|
||
|
let _isSpecial = that.importUploadURL ? true : false
|
||
|
fileStorageCreate(params).then( createRes => {
|
||
|
let importParams = {
|
||
|
fileType: 1, //文件类型 固定1
|
||
|
method: val[1].method, //导入方式 0 更新 1 追加 2 覆盖
|
||
|
isAllowPartImport: val[1].isAllowPartImport=='0'?true:false, //是否部分错误导入
|
||
|
route: _isSpecial ? _uploadURL : _uploadURL + '/import', //路由
|
||
|
function: menuName, //菜单名
|
||
|
blobName: createRes,
|
||
|
company: window.SITE_CONFIG['company']
|
||
|
}
|
||
|
postImport(importParams, _uploadURL, _isSpecial).then(res => {
|
||
|
// 判断是否有错误记录
|
||
|
if (res.errorNum > 0) {
|
||
|
that.$alert('发现导入错误数据共:' + res.errorNum + '条', '错误报告', {
|
||
|
confirmButtonText: '下载错误报告',
|
||
|
callback: action => {
|
||
|
if (action == 'confirm') {
|
||
|
fileStorage({blobName: res.fileCode}).then( fileStorageRes => {
|
||
|
that.downloadFile(fileStorageRes.bytes, fileStorageRes.fileName)
|
||
|
}).catch( err => {
|
||
|
console.log(err)
|
||
|
})
|
||
|
}
|
||
|
}
|
||
|
})
|
||
|
} else if (res.exceptionMessage != null) {
|
||
|
that.$alert('错误信息:' + res.exceptionMessage, '错误', {
|
||
|
confirmButtonText: '确定',
|
||
|
callback: action => {
|
||
|
}
|
||
|
})
|
||
|
// that.$alert('导入模板错误,请导入正确的模板文件!', '模板错误', {
|
||
|
// confirmButtonText: '确定',
|
||
|
// callback: action => {
|
||
|
// }
|
||
|
// })
|
||
|
} else {
|
||
|
// that.$successMsg('全部导入成功')
|
||
|
that.$alert('全部导入成功,是否下载导入报告', '导入报告', {
|
||
|
confirmButtonText: '下载导入报告',
|
||
|
cancelButtonText: '取消',
|
||
|
callback: action => {
|
||
|
if (action == 'confirm') {
|
||
|
fileStorage({blobName: res.fileCode}).then( fileStorageRes => {
|
||
|
that.downloadFile(fileStorageRes.bytes, fileStorageRes.fileName)
|
||
|
}).catch( err => {
|
||
|
console.log(err)
|
||
|
})
|
||
|
}
|
||
|
}
|
||
|
})
|
||
|
|
||
|
}
|
||
|
that.Loading.importLoading = false
|
||
|
that.FormRemove(val[0]);
|
||
|
that.displayDialog.importDialog = false;
|
||
|
that.paging()
|
||
|
}).catch(err => {
|
||
|
that.Loading.importLoading = false
|
||
|
that.FormRemove(val[0]);
|
||
|
that.displayDialog.importDialog = false;
|
||
|
that.paging()
|
||
|
})
|
||
|
}).catch(err => {
|
||
|
console.log(err)
|
||
|
})
|
||
|
}
|
||
|
} else {
|
||
|
that.$errorMsg('请按照提示继续操作')
|
||
|
that.displayDialog.importDialog = false;
|
||
|
return false;
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
},
|
||
|
//导入文件 应该暂无使用
|
||
|
// importClick(val) {
|
||
|
// if (val[0][0] == 0) {
|
||
|
// this.FormRemove(val[0]);
|
||
|
// this.displayDialog.importDialog = false;
|
||
|
// } else {
|
||
|
// val[0][1].validate((valid) => {
|
||
|
// if (valid) {
|
||
|
// this.Loading.importLoading = true;
|
||
|
// let {
|
||
|
// formFile
|
||
|
// } = val[1]
|
||
|
// let fd = new FormData();
|
||
|
// formFile.forEach((item) => {
|
||
|
// fd.append("formFile", item)
|
||
|
// })
|
||
|
// postImport(fd, this.URL).then(res => {
|
||
|
// if (res.failList.length === 0) {
|
||
|
// this.$successMsg('全部导入成功')
|
||
|
// } else {
|
||
|
// let failListCode = ''
|
||
|
// res.failList.forEach(key => {
|
||
|
// failListCode = failListCode.concat(key.code + ';')
|
||
|
// })
|
||
|
// this.$errorMsg('部分导入失败,失败代码为:' + failListCode)
|
||
|
// }
|
||
|
// this.Loading.importLoading = false
|
||
|
// this.FormRemove(val[0]);
|
||
|
// this.displayDialog.importDialog = false;
|
||
|
// this.paging()
|
||
|
// }).catch(err => {
|
||
|
// this.Loading.importLoading = false
|
||
|
// this.FormRemove(val[0]);
|
||
|
// this.displayDialog.importDialog = false;
|
||
|
// this.paging()
|
||
|
// })
|
||
|
// } else {
|
||
|
// this.$errorMsg('请按照提示继续操作')
|
||
|
// this.displayDialog.importDialog = false;
|
||
|
// return false;
|
||
|
// }
|
||
|
// });
|
||
|
// }
|
||
|
// },
|
||
|
//导入模板下载
|
||
|
importDown(url) {
|
||
|
let _url = url ? url : this.URL
|
||
|
postImportDown(_url).then(res => {
|
||
|
let menuName = this.$route.meta.title
|
||
|
this.blob(res,menuName + '导入模板')
|
||
|
})
|
||
|
},
|
||
|
//重置表单
|
||
|
FormRemove(val) {
|
||
|
val[1].resetFields();
|
||
|
},
|
||
|
}
|
||
|
}
|