【前端】智能库房综合管理系统前端项目
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.
 
 
 
 
 

240 lines
7.7 KiB

import { FetchInitBorrowRule, FetchBillBorrowConfirm, FetchArchivesReturnConfirm } from '@/api/archivesManage/lendManage'
import { FetchFindAllSubsetById } from '@/api/archivesConfig/dictDetail'
import RFID from '@/api/RFID/RFID'
export const lendingCrud = {
filters: {
borrowStatus(val) {
switch (val) {
case 1:
return '待登记'
case 2:
return '待借阅'
case 3:
return '待归还'
case 4:
return '已归还'
case 5:
return '逾期'
}
},
tidType(val) {
switch (val) {
case 1:
return '档案'
case 2:
return '档案盒'
case 3:
return '层架位'
}
}
},
// 组件共用属性
data() {
return {
lineStateVal: '',
lendQuery: {},
lendSelect: '',
options: [],
departOptions: [],
idTypeOptions: [
{ value: '身份证', label: '身份证' },
{ value: '军官证', label: '军官证' },
{ value: '士官证', label: '士官证' },
{ value: '文职人员证', label: '文职人员证' }
],
// epc
btnDisabled: false,
devId: 'D001',
timer: null,
flagNum: 0,
unbindWarnLoading: false,
tipIndex: 0,
ase: 0
}
},
// 组件挂载时的共用方法
mounted() {
if (this.queryOption) {
this.lendSelect = this.queryOption[0].value
}
},
// 组件共用方法
methods: {
borrowStyle(val) {
switch (val) {
case '逾期':
return 'cell-lend have-lend'
case '已归还':
return 'cell-lend has-return'
default:
return 'cell-lend no-lend '
}
},
// 获取部门list
getDepart() {
FetchFindAllSubsetById({ id: 'BA3910917510B181160A9A' }).then(data => {
this.departOptions = data
})
},
selectionChangeHandler(val) {
this.selections = val
},
// 档案详情
handleDbClick(row) {
this.$nextTick(() => {
const archiveDetailDom = this.$refs.archiveDetailDom
archiveDetailDom.detailVisible = true
archiveDetailDom.rowData = row
archiveDetailDom.getBillDetails()
})
},
// 判断当前借阅规则
getBorrowRule() {
FetchInitBorrowRule().then(data => {
if (data) {
this.lineStateVal = data === 'true' ? 'online' : 'offline'
}
})
},
// 借出确认 / 归还确认
confirmLendOrReturn(type, params, selections) {
if (type === 0) {
FetchBillBorrowConfirm(params).then(data => {
if (data === selections.length) {
this.$message.success('借阅成功 ' + data + ' 条数据' + ' ' + '借阅失败0条数据')
this.releaseAlarmVisible = false
this.crud.refresh()
}
})
} else {
FetchArchivesReturnConfirm(params).then(data => {
if (data === selections.length) {
this.$message.success('归还成功 ' + data + ' 条数据' + ' ' + '归还失败0条数据')
this.releaseAlarmVisible = false
this.crud.refresh()
}
})
}
},
// 解除/恢复中关闭icon不可操作
handleCancle() {
this.releaseAlarmVisible = !!this.btnDisabled
},
// 解除/恢复 状态style
cellWarn({ row, columnIndex }) {
if ((row.warnState === '未解除' || row.warnState === '未恢复') && columnIndex === 4) {
return 'no-clear'
} else if ((row.warnState === '已解除' || row.warnState === '已恢复') && columnIndex === 4) {
return 'have-clear'
} else if ((row.warnState === '解除失败' || row.warnState === '恢复失败') && columnIndex === 4) {
return 'fail-clear'
}
},
// 写epc
async writeEPC(ase) {
this.flagNum++
this.ase = ase
this.btnDisabled = true
this.unbindWarnLoading = true
return new Promise(async(resolve, reject) => {
const params = { op: 'RFID_WriteEPC', sDevID: this.devId, EAS: this.ase, Type: this.tipTable[this.tipIndex].tagType, Code: this.tipTable[this.tipIndex].archivesId, Tid: this.tipTable[this.tipIndex].tid }
let writeRes = await RFID.writeEPC(params)
writeRes = JSON.parse(writeRes)
if (writeRes.code === '0') {
if (this.ase === 0) {
this.tipTable[this.tipIndex].warnState = '已解除'
} else {
this.tipTable[this.tipIndex].warnState = '已恢复'
}
this.btnDisabled = false
this.unbindWarnLoading = false
this.tipIndex = this.tipIndex + 1
if (this.tipIndex !== this.tipTable.length) {
this.flagNum = 0
this.btnDisabled = true
this.unbindWarnLoading = true
clearTimeout(this.timer)
this.timer = setTimeout(() => {
if (this.ase === 0) {
resolve(this.writeEPC(0))
} else {
resolve(this.writeEPC(1))
}
}, 2000)
} else {
clearTimeout(this.timer)
setTimeout(() => {
const index = this.tipTable.findIndex((item) => item.warnState === '解除失败' || item.warnState === '恢复失败')
if (index === -1) {
let params
if (this.ase === 0) {
params = this.lendSelections.map(item => item.orderNo)
} else {
params = this.lendSelections.map(item => item.id)
}
this.confirmLendOrReturn(this.ase, params, this.lendSelections)
} else {
this.alarmErrorTip()
}
}, 2000)
}
// resolve()
} else if (writeRes.code === '-1') {
this.releaseAlarmErrorHandle(resolve, '标签损坏或丢失,需要用户自主去解除或恢复电子标签绑定')
// reject()
} else if (writeRes.code === '-1000') {
this.releaseAlarmErrorHandle(resolve, '读写器超时未响应')
// reject()
}
})
},
// 只要有一条未解除/恢复成功即errorTip
alarmErrorTip() {
if (this.ase === 0) {
this.$message.error('借阅成功0条数据' + ' ' + '借阅失败' + this.lendSelections.length + '条数据')
} else {
this.$message.error('归还成功0条数据' + ' ' + '归还失败' + this.lendSelections.length + '条数据')
}
this.releaseAlarmVisible = false
this.crud.refresh()
},
// 写epc不成功时的操作提示 -1 / -1000
releaseAlarmErrorHandle(resolve, message) {
if (this.flagNum >= 3) {
if (this.ase === 0) {
this.tipTable[this.tipIndex].warnState = '解除失败'
} else {
this.tipTable[this.tipIndex].warnState = '恢复失败'
}
this.btnDisabled = false
this.unbindWarnLoading = false
this.tipIndex = this.tipIndex + 1
this.flagNum = 0
this.$message({
message: message,
type: 'error'
})
}
if (this.tipIndex !== this.tipTable.length) {
this.btnDisabled = true
this.unbindWarnLoading = true
clearTimeout(this.timer)
this.timer = setTimeout(() => {
if (this.ase === 0) {
resolve(this.writeEPC(0))
} else {
resolve(this.writeEPC(1))
}
}, 2000)
} else {
clearTimeout(this.timer)
this.timer = setTimeout(() => {
const findErrorArray = this.tipTable.map((item) => item.warnState === '解除失败' || item.warnState === '恢复失败')
if (findErrorArray.length === this.tipTable.length) {
this.alarmErrorTip()
}
}, 2000)
}
}
}
}