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.
 
 
 
 

567 lines
15 KiB

import { default as api } from './api'
import store from '../store'
import router from '../router'
import Utils from './contact.js'
import preview from './preview'
import Vue from 'vue'
import qs from 'qs'
export default {
// 原始记录预览
viewYsjl(id, viewType, generateType = false) {
preview({
url: '/print/generatePdf',
method: 'post',
data: {
ysjlId: id,
viewType: viewType,
generateType: generateType
}
}).then(data => {
data = data.replace(/\\/g, '/')
if (data) {
router.push({ path: '/preview/' + id + '/' + viewType + '/urlPath?src=' + store.getters.prodName + '/static/web/viewer.html?file=' + encodeURIComponent(data) + '&v=' + Math.random() })
} else {
Vue.prototype.$message({
message: 'PDF预览错误!',
type: 'error',
duration: 3 * 1000
})
}
})
},
/**
* 预览原始资料
* 如果给的是路径就直接预览,如果给的是任务ID,就先查询路径再预览
* @param id 任务ID
*/
viewRawRecords(id) {
preview({
url: '/download/pullRawRecordsPath',
method: 'get',
params: { renwuId: id }
}).then(data => {
if (data.path) {
data = data.path.replace(/\\/g, '/')
router.push({ path: '/preview/rawrecords?src=' + store.getters.prodName + '/static/web/viewer.html?file=' + encodeURIComponent(process.env.VUE_APP_PREVIEW_API + '/' + data) + '&v=' + Math.random() })
} else {
Vue.prototype.$message({
message: '数据未找到!',
type: 'error',
duration: 3 * 1000
})
}
})
},
/**
* 预览相关鉴证文件
* @param id 文件主键
*/
viewProve(id) {
preview.defaults.withCredentials = true
preview({
url: '/download/pullProvePath',
method: 'get',
params: { id: id }
}).then(data => {
data = data.replace(/\\/g, '/')
const fileType = data.substring(data.length - 3)
if (fileType === 'pdf' || fileType === 'PDF') {
router.push({ path: '/preview/' + id + '/PROVE/urlPath?src=' + (data) })
} else {
router.push({ name: 'ImagePreview', params: { src: data }})
}
})
},
/**
* 预览驳回附件
* @param id 驳回记录主键
* @param fileName 驳回附件名称
*/
viewReject(id, fileName) {
if (id && fileName && fileName !== '') {
const suffixName = fileName.substring(fileName.indexOf('.'))
const path = process.env.VUE_APP_BASE_API + 'reject/' + fileName
if (suffixName === 'pdf' || suffixName === 'PDF') {
router.push({ path: '/preview/' + id + '/REJECT/urlPath?src=' + (path) })
} else {
console.log(path)
router.push({ name: 'ImagePreview', params: { src: path }})
}
} else {
Vue.prototype.$message({
message: '暂无其他驳回附件!',
type: 'error',
duration: 3 * 1000
})
}
},
// 预览重启申请文件
viewRestartApply(ysjlId, type, generateType = false) {
preview({
url: '/print/generateRestartApplyPdf',
method: 'post',
params: {
ysjlId: ysjlId,
type: type,
generateType: generateType
}
}).then(data => {
data = data.replace(/\\/g, '/')
router.push({ path: '/preview/' + ysjlId + '/' + type + '/urlPath?src=' + store.getters.prodName + '/static/web/viewer.html?file=' + encodeURIComponent(data) + '&v=' + Math.random() })
})
},
switchInspection(list) {
let result = ''
for (let i = 0; i < list.length; i++) {
switch (list[i].jianyanxiangmu) {
case 'cfjc':
result = '磁粉'
break
case 'csjc':
result = '超声'
break
case 'sfsjc':
result = '声发射'
break
case 'stjc':
result = '渗透'
break
case 'sxjc':
result = '射线'
break
case 'tofd':
result = '衍射时差'
break
default:
result = '主报告'
break
}
list[i].inspectionItems = result
}
},
viewYsjlNoOpen(id, viewType) {
preview({
url: '/print/batchGeneratePDF',
method: 'post',
data: {
ids: [id],
generateType: viewType
},
paramsSerializer: function(data) {
return qs.stringify(data, { indices: false })
}
}).then(() => {
console.info('重新生成成功')
})
},
/**
* 检验员签名方法
* @param {*} id : 原始记录/报告主键
* @param {*} jyry :检验人员
*/
signName(id, jyry) {
if (!id) {
return
}
api({
url: '/ysjl/signName',
method: 'get',
params: {
ysjlId: id,
jianyanrenyuan: jyry
}
})
},
convertCnName(val) {
const length = store.getters.allUser.length
const idArray = val.replace('[', '').replace(']', '').replace(/\ +/g, '').split(',')
let chineseName = ''
if (length > 0 && !!val) {
for (let i = 0; i < length; i++) {
for (let j = 0; j < idArray.length; j++) {
if (idArray[j] === store.getters.allUser[i].id.toString()) {
if (chineseName === '') {
chineseName = store.getters.allUser[i].nickname
} else {
chineseName = chineseName + ',' + store.getters.allUser[i].nickname
}
}
}
}
}
return chineseName
},
/**
* 删除检验方案
* @param jyxm 检验项目简写。例如:bhcd
* @param jianyanxiangmu 检验项目。例如:壁厚测定
* @param bglx 报告类型。例如:[2, 3]
* @param ysjlId 无损或分项的原始记录Id
* @param mainYsjlId 主原始记录Id
* @param sblbdm 设备类别代码。例如:2100
* @param nblb 内部类别。例如:DQ
*/
delJyfa(jyxm, jianyanxiangmu, bglx, ysjlId, mainYsjlId, sblbdm, nblb) {
api({
url: '/ysjl/delJyfa',
method: 'get',
params: {
ysjlId: ysjlId,
bglx: bglx,
jianyanxiangmu: jianyanxiangmu
}
}).then(() => {
Utils.$emit('modifyMajorInspectionItemBySub' + mainYsjlId)
Utils.$emit('ysjl-list')
Utils.$emit('bggl-daiban-list')
Utils.$emit('JyfaInfo' + mainYsjlId)
Vue.prototype.$message({
message: '删除成功',
type: 'success'
})
}).catch(e => {})
},
/**
* 下载导入模板
* @param templateName 例如:模板名字.xlsx
*/
downloadTemplate(templateName) {
if (!templateName) {
Vue.prototype.$message({
message: '文件不存在',
type: 'error'
})
return false
}
api({
url: '/upload/downloadTemplate',
method: 'post',
params: {
templateName: templateName
}
}).then(data => {
window.open(data)
})
},
/**
* 上传数据
* @param file 上传的文件信息
* @param tableData 上传前的数据
* @returns {boolean}
* @constructor
*/
uploadTableData(file, tableData) {
const isExcel = file.type === 'application/vnd.ms-excel' || file.type === 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
const isExcel2 = file.name.endsWith('.xls') || file.name.endsWith('.xlsx')
if (!isExcel && !isExcel2) {
Vue.prototype.$message({
message: '只能上传xls/xlsx格式的文件',
type: 'error'
})
return false
}
const fd = new FormData()
fd.append('file', file)
fd.append('paramData', JSON.stringify(tableData))
api({
url: '/upload/uploadSchedule',
method: 'post',
data: fd
}).then(data => {
for (let i = tableData.length; i > 0; i--) {
tableData.pop()
}
data.forEach((v, i) => {
v.index = i
tableData.push(v)
})
Vue.prototype.$message({
message: '上传成功!',
type: 'success'
})
})
},
/**
* 深拷贝
* @param o
* @returns {Array|*}
*/
deepCopy(o) {
if (o instanceof Array) {
var n = []
for (var i = 0; i < o.length; ++i) {
n[i] = this.deepCopy(o[i])
}
return n
} else if (o instanceof Object) {
var nn = {}
for (var j in o) {
nn[j] = this.deepCopy(o[j])
}
return nn
} else {
return o
}
},
/**
* 根据报告ID查看驳回原因
* @param ysjlId
*/
viewRejection(ysjlId) {
api({
url: '/taskinfo/viewRejection',
method: 'get',
params: {
ysjlId: ysjlId
}
}).then(data => {
let tempRejection = '该信息无法查询!'
if (data != null) {
tempRejection = data.infoNotes
}
Vue.prototype.$alert(tempRejection, '驳回意见', {
confirmButtonText: '关闭'
})
})
},
/**
* 下载无损分项附件
* @param renwuId
*/
downloadWsFxFile(renwuId) {
preview({
url: '/download/pullWsFxFilePath',
method: 'get',
params: {
renwuId: renwuId
}
}).then(data => {
if (data) {
window.open(process.env.VUE_APP_PREVIEW_API + '/' + data.path)
}
})
},
/**
* 判断日期格式是否为yyyy-MM-dd
* */
checkDateFormat(checkDate) {
if (checkDate !== null) {
checkDate = checkDate.replace(/\s+/g, '').replace('00:00:00', '').replace('年', '-').replace('月', '-').replace('日', '')
const testDate = /^(\d{4})-(\d{2})-(\d{2})$/
if (!testDate.test(checkDate)) {
checkDate = null
}
}
return checkDate
},
/**
* 删除当前路由
*/
delCurrentViews() {
store.dispatch('delCurrentViews', {
view: router.history.current,
$router: router
})
},
/**
* 构建编辑原始记录页面路由参数
* @param ysjl
* @param obj 需要将特殊参数补充到路由的参数里面
* @returns {{modelId: null, departmentId: *, renwuId: null, sbzldm, sbpzdm, jyxm: null, jylb: *, sblbdm, id: null, state: null, neibuleibie, jianyanrenyuan: null}}
*/
buildEditYsjlRouterParam(ysjl, obj) {
const routerParam = {
id: ysjl.id,
jyxm: ysjl.jianyanxiangmu,
departmentId: ysjl.departmentId,
jianyanrenyuan: ysjl.jianyanrenyuan,
state: 'update',
renwuId: ysjl.renwuId,
templateId: ysjl.templateId,
jylb: ysjl.jianyanleibie,
neibuleibie: ysjl.neibuleibie,
sbzldm: ysjl.shebeizhongleidaima,
sblbdm: ysjl.shebeileibiedaima,
sbpzdm: ysjl.shebeipinzhongdaima
}
if (obj) {
obj.keys().beforeEach(objKey => {
routerParam[objKey] = obj[objKey]
})
}
return routerParam
},
/**
* 重新加载页面到更新报检单页面
* @param bjd
*/
reloadViewToUpdateBjd(bjd) {
this.delCurrentViews()
router.push({ path: '/bjd/bjd-' + bjd.jianyanleibie.toLowerCase() + '-input/' + bjd.id + '/' + bjd.shebeizhongleidaima + '/update' })
},
/**
* 重新加载页面到更新原始记录页面
* @param ysjl
* @param obj 需要将特殊参数补充到路由的参数里面
*/
reloadViewToUpdateYsjl(ysjl, obj) {
const path = router.history.current.path.replace('/null', '/' + ysjl.id)
this.delCurrentViews()
router.push({ path: path, query: this.buildEditYsjlRouterParam(ysjl, obj) })
},
/**
* 记录、报告编号判重
* @param bianhao
* @param id
* @returns {Promise<unknown>}
*/
judgeRepeat(bianhao, id) {
return new Promise(resolve => {
api({
url: '/ysjl/judgeRepeat',
method: 'get',
params: {
ysjlId: id,
bianhao: bianhao
}
}).then(data => {
resolve(data > 0)
})
})
},
initYsjl(query) {
return api({
url: '/ysjl/initYsjl',
method: 'post',
data: {
templateId: query.templateId,
renwuId: query.renwuId,
neibuleibie: query.neibuleibie,
sblbdm: query.sblbdm,
sblbmc: query.sblbmc,
sbpzdm: query.sbpzdm,
sbpzmc: query.sbpzmc
}
})
},
/**
* 根据原始记录id查询参数
* @param ysjlId
* @param sbzldm
* @returns {AxiosPromise}
*/
getParam(ysjlId, sbzldm) {
return api({
url: '/ysjl/getParamByYsjlId',
method: 'get',
params: {
ysjlId: ysjlId,
sbzldm: sbzldm
}
})
},
/**
* 获取检验项目
* @param modelId 模板主键(起草时使用)
* @param ysjlId 原始记录主键(更新时使用)
* @param sort 序号
* @returns {AxiosPromise}
*/
getJyxm(modelId, ysjlId, sort, state) {
let url = ''
let data = {}
if (state === 'create') {
url = '/jyxm/getCyJyxm'
data = {
templateId: modelId,
order: sort
}
} else {
url = '/jyxm/getCyJyxmByYsjl'
data = {
ysjlId: ysjlId,
isReport: false,
order: sort
}
}
return api({
url: url,
method: 'get',
params: data
})
},
/**
* 精确乘法
* @param arg1 乘数
* @param arg2 被乘数
* @param decimalPlaces 保留的小数位数
* @returns {number}
*/
accMul(arg1, arg2, decimalPlaces = 2) {
const percentage = Math.pow(10, decimalPlaces)
return Math.round(arg1 * arg2 * percentage) / percentage
},
/**
* 精确加法
* @param arg1
* @param arg2
* @returns {number}
*/
accAdd(arg1, arg2) {
let r1, r2, m, c
try {
r1 = arg1.toString().split('.')[1].length
} catch (e) {
r1 = 0
}
try {
r2 = arg2.toString().split('.')[1].length
} catch (e) {
r2 = 0
}
// eslint-disable-next-line prefer-const
c = Math.abs(r1 - r2)
// eslint-disable-next-line prefer-const
m = Math.pow(10, Math.max(r1, r2))
if (c > 0) {
var cm = Math.pow(10, c)
if (r1 > r2) {
arg1 = Number(arg1.toString().replace('.', ''))
arg2 = Number(arg2.toString().replace('.', '')) * cm
} else {
arg1 = Number(arg1.toString().replace('.', '')) * cm
arg2 = Number(arg2.toString().replace('.', ''))
}
} else {
arg1 = Number(arg1.toString().replace('.', ''))
arg2 = Number(arg2.toString().replace('.', ''))
}
return (arg1 + arg2) / m
},
/**
* 删除数组中指定元素
* @param arr 数据
* @param val 元素
*/
deleteElement(arr, val) {
for (var i = 0; i < arr.length; i++) {
if (arr[i] === val) {
arr.splice(i, 1)
break
}
}
return arr
},
/**
* 修复由于Vue的$on可能会多次绑定,导致多次调用$on的回调方法
* @param event
* @param callback
*/
$on(event, callback) {
Utils.$off(event)
Utils.$on(event, callback)
}
}
export let it