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.
170 lines
5.9 KiB
170 lines
5.9 KiB
import XLSX from 'xlsx'
|
|
import common from '@/utils/common'
|
|
import qs from 'qs'
|
|
import preview from '@/utils/preview'
|
|
import router from '@/router'
|
|
import store from '@/store'
|
|
import { Notification } from 'element-ui'
|
|
|
|
export default {
|
|
/**
|
|
* 导入报检设备信息
|
|
* @param self this对象
|
|
* @param file 当前xlsx文件
|
|
* @param importField 文字和字段的对应关系:[{ label: '文字', value: '字段名' }]
|
|
* @param sbzldm 设备种类代码
|
|
* @param bjType 报检类型(车用气瓶:cyqp)
|
|
* @returns {boolean}
|
|
*/
|
|
beforeUpload(self, file, importField, sbzldm, bjType) {
|
|
if (!/\.(xlsx)$/.test(file.name)) {
|
|
self.$message({
|
|
message: '请使用指定模板上传数据.',
|
|
type: 'warning'
|
|
})
|
|
}
|
|
if (!importField || !importField.length) {
|
|
self.$message({
|
|
message: '暂未提供当前导入模板.',
|
|
type: 'warning'
|
|
})
|
|
}
|
|
const loading = self.$loading({
|
|
lock: true,
|
|
text: 'Loading',
|
|
spinner: 'el-icon-loading',
|
|
background: 'rgba(0, 0, 0, 0.7)'
|
|
})
|
|
// 读取数据
|
|
const reader = new FileReader()
|
|
reader.onload = e => {
|
|
const data = e.target.result
|
|
const workbook = XLSX.read(data, { type: 'array' })
|
|
for (let index = 0; index < importField.length; index++) {
|
|
const firstSheetName = workbook.SheetNames[index]
|
|
const worksheet = workbook.Sheets[firstSheetName]
|
|
// 从表格中读取数据,以第一行为key,其余行为数据,组成数据进行返回
|
|
const importData = XLSX.utils.sheet_to_json(worksheet, { range: 1, raw: false, header: importField[index].map(field => field.value) })
|
|
if (index === 0 && importField.length > 1) {
|
|
const bjd = importData[0]
|
|
Object.keys(bjd).forEach(key => {
|
|
if (key === 'quhuamingcheng') {
|
|
const area = self.areas.filter(area => area.label === bjd[key])[0]
|
|
self.bjd.quhuadaima = area ? area.value : self.bjd.quhuadaima
|
|
} else {
|
|
self.bjd[key] = bjd[key]
|
|
}
|
|
})
|
|
} else {
|
|
importData.forEach(tableObj => {
|
|
// 遍历字段名修改其对应关系
|
|
// 设置默认值
|
|
if (sbzldm === 'F000') {
|
|
tableObj.neibuleibie = 'DQ'
|
|
tableObj.shebeizhonglei = '安全附件'
|
|
tableObj.shebeizhongleidaima = 'F000'
|
|
tableObj.shebeileibie = '压力管道阀门'
|
|
tableObj.shebeileibiedaima = '7300'
|
|
tableObj.shebeipinzhong = '安全阀'
|
|
tableObj.shebeipinzhongdaima = '7310'
|
|
tableObj.s18 = 'TSGZF001-2006'
|
|
} else if (bjType === 'cyqp') {
|
|
tableObj.neibuleibie = 'JD'
|
|
tableObj.shebeizhonglei = '压力容器'
|
|
tableObj.shebeizhongleidaima = '2000'
|
|
tableObj.shebeileibie = '气瓶'
|
|
tableObj.shebeileibiedaima = '2300'
|
|
tableObj.shebeipinzhong = '特种气瓶'
|
|
tableObj.shebeipinzhongdaima = '23T0'
|
|
} else if (bjType === 'ZJ') {
|
|
tableObj.neibuleibie = 'ZZ'
|
|
if (sbzldm === '1000') {
|
|
tableObj.shebeizhonglei = '锅炉'
|
|
tableObj.shebeizhongleidaima = '1000'
|
|
// 根据设备类别获取对应数据,数据如下:
|
|
// {"value":"1100","label":"承压蒸汽锅炉","children":[{"value":"1110","label":"电站锅炉","children":null},{"value":"1120","label":"工业锅炉","children":null}]}
|
|
const sblb = self.sblbList.filter(row => row.label === tableObj.shebeileibie)[0]
|
|
tableObj.shebeileibiedaima = sblb.value
|
|
tableObj.shebeipinzhong = sblb.children[0].label
|
|
tableObj.shebeipinzhongdaima = sblb.children[0].value
|
|
} else if (sbzldm === '2000') {
|
|
tableObj.shebeizhonglei = '压力容器'
|
|
tableObj.shebeizhongleidaima = '2000'
|
|
tableObj.ss1 = common.accMul(tableObj.s54, tableObj.ss7)
|
|
tableObj.xitongheding = common.accMul(tableObj.ss1, tableObj.ss2 / 100)
|
|
if (tableObj.xitongheding < 50) {
|
|
tableObj.xitongheding = 50
|
|
}
|
|
}
|
|
}
|
|
self.$set(tableObj, 'sblbpz', [String(tableObj.shebeileibiedaima), String(tableObj.shebeipinzhongdaima)])
|
|
})
|
|
self.tableData = self.tableData.concat(importData)
|
|
self.$forceUpdate()
|
|
}
|
|
}
|
|
}
|
|
reader.readAsArrayBuffer(file)
|
|
loading.close()
|
|
},
|
|
/**
|
|
* 批量打印回执单
|
|
*
|
|
* @param bjdIds 报检单主键数组
|
|
* @return {Promise<AxiosResponse<any>>}
|
|
*/
|
|
batchPrintHzd(bjdIds) {
|
|
return new Promise(resolve => {
|
|
preview({
|
|
url: '/print/batchGeneratePdfHzd',
|
|
method: 'get',
|
|
params: {
|
|
bjdIds: bjdIds
|
|
},
|
|
paramsSerializer: function(params) {
|
|
return qs.stringify(params, { indices: false })
|
|
}
|
|
}).then((data) => {
|
|
preview({
|
|
url: '/print/createXmlOther',
|
|
method: 'post',
|
|
params: {
|
|
ids: bjdIds,
|
|
type: 'HZD'
|
|
},
|
|
paramsSerializer: function(params) {
|
|
return qs.stringify(params, { indices: false })
|
|
}
|
|
}).then((data) => {
|
|
resolve(data)
|
|
})
|
|
})
|
|
})
|
|
},
|
|
viewHzd(bjdId) {
|
|
preview({
|
|
url: '/print/generatePdfHzd',
|
|
method: 'get',
|
|
params: {
|
|
bjdId: bjdId
|
|
}
|
|
}).then((data) => {
|
|
data = data.replace(/\\/g, '/')
|
|
if (data) {
|
|
router.push({
|
|
path:
|
|
'/preview/hzd?src=' +
|
|
store.getters.prodName +
|
|
'/static/web/viewer.html?file=' +
|
|
encodeURIComponent(data)
|
|
})
|
|
} else {
|
|
Notification({
|
|
message: 'PDF预览错误!',
|
|
type: 'error',
|
|
duration: 3 * 1000
|
|
})
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|