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.

440 lines
11 KiB

3 years ago
<template>
<view>
<u-navbar :is-back="false" title="资产扫码" title-color="#fff" :background="{'background':'#107fc9'}"></u-navbar>
<view class="content">
<u-swiper :list="list"></u-swiper>
<u-button :ripple="true" :type="flag ? 'error' : 'primary'" :custom-style="{'margin':'20rpx 30rpx 0 30rpx'}"
@click="scanClick">{{ flag ? "停止扫描" : "开始扫描" }}</u-button>
<u-card title="资产列表" v-show="info.length > 0">
3 years ago
<view slot="head" style="display: flex;justify-content: space-between;align-items: center;">
<view style="flex: 1;">资产列表</view>
<u-button size="medium" type="primary" @click="clear"></u-button>
</view>
3 years ago
<view class="card-body" slot="body">
<view v-for="(item,index) in info" :key="item.id"
style="display: flex;justify-content: space-between;padding: 10rpx 0;align-items: center;">
<view style="flex:1">{{ item.name }}</view>
<u-button :plain="true" size="medium" type="primary" @click="fund = item">选择
</u-button>
</view>
</view>
</u-card>
<u-card title="资产信息">
<view class="card-body" slot="body">
<view class="info">
<view class="info__name">名称</view>
<view class="info__value">{{fund.name || " "}}</view>
</view>
<view class="info">
<view class="info__name">编号</view>
<view class="info__value">{{fund.serial || " "}}</view>
</view>
<view class="info">
<view class="info__name">存放位置</view>
<view class="info__value">{{fund.position || " "}}</view>
</view>
<view class="info">
<view class="info__name">保管人</view>
<view class="info__value">{{fund.worker_name || " "}}</view>
</view>
<view class="info">
<view class="info__name">资产状态</view>
<view class="info__value">{{activeStatusFormat(fund.active_status) || " "}}</view>
</view>
<u-button type="primary" :ripple="true" :custom-style="btnStyle" @click="isShowPop = true">
盘点
</u-button>
</view>
<view class="card-footer" slot="foot">
<view class="footer-title">盘点记录</view>
<u-time-line>
<u-time-line-item v-for="(item,index) in logs" :key="index">
<!-- 此处没有自定义左边的内容会默认显示一个点 -->
<template v-slot:content>
<view>
<view class="u-order-desc" @click="fund = item">{{ item.remark }}</view>
<view class="u-order-time">
{{$moment(item.created_at).format('YYYY-MM-DD HH:mm:SS')}}
</view>
</view>
</template>
</u-time-line-item>
</u-time-line>
</view>
</u-card>
</view>
<u-popup width="76%" v-model="isShowPop" mode="center" :border-radius="10">
<view style="padding: 20rpx 40rpx;">
<u-form :model="fund" ref="form" label-position="top">
<u-form-item label="名称">
<u-input disabled v-model="fund.name" placeholder="资产名称"></u-input>
</u-form-item>
<u-form-item label="盘点时间">
<u-input disabled :value="$moment(new Date()).format('YYYY-MM-DD')" placeholder="盘点时间">
</u-input>
</u-form-item>
<u-form-item label="资产状态">
<u-input :value="activeStatusFormat(fund.active_status)" type="select"
@click="isShowSelect = true" placeholder="请选择资产状态"></u-input>
</u-form-item>
<u-form-item label="备注">
<u-input v-model="fund.remark" type="textarea" :auto-height="true" placeholder="请输入备注">
</u-input>
</u-form-item>
<u-form-item label="图片上传">
<u-upload :show-progress="false" :auto-upload="false" :max-count="1" ref="uUpload"
:file-list="fund.files ? [{url:fund.files}] : []">
</u-upload>
</u-form-item>
</u-form>
<view style="display: flex;margin-top: 20rpx;">
<u-button type="primary" size="medium" @click="confirm"></u-button>
<u-button size="medium" @click="isShowPop = false">
取消</u-button>
</view>
</view>
</u-popup>
<u-select :list="statusList" v-model="isShowSelect" @confirm="e => fund.active_status = e[0].value"></u-select>
</view>
</template>
<script>
// #ifdef APP-PLUS
let androidModule = uni.requireNativePlugin('uhfr')
let receiver;
3 years ago
let receiverQR;
3 years ago
let timerQR;
let main = plus.android.runtimeMainActivity();
let intent = plus.android.importClass('android.content.Intent');
// #endif
import {
openSqlite,
isOpenSqlite,
closeSqlite,
executeSql,
selectFromTable
} from '@/common/sqlite.js'
import {
byteToString
} from '@/common/util.js'
import {
ROOTPATH
} from '@/common/config.js'
export default {
data() {
return {
isShowPop: false,
isShowSelect: false,
action: `${ROOTPATH}/index.php?s=/Home/Worker/upload.html`,
statusList: [{
value: 0,
label: "正常未领用"
},
{
value: 1,
label: "已领用"
},
{
value: -1,
label: "报废"
},
{
value: -2,
label: "维修停用"
}
],
btnStyle: {
'margin': '60rpx 30rpx 0 30rpx'
},
list: [{
image: '/static/pic1.jpeg'
},
{
image: '/static/pic2.jpeg'
}
],
flag: 0, //当前扫码状态0未开始1进行中
fund: {
id: 0,
name: '',
serial: '',
position: '',
worker_name: '',
active_status: '',
files: '',
remark: ''
3 years ago
},
qrIdList: [],
3 years ago
info: [],
logs: []
}
},
methods: {
3 years ago
clear() {
this.info = []
this.fund = {
id: 0,
name: '',
serial: '',
position: '',
worker_name: '',
active_status: '',
files: '',
remark: ''
}
},
3 years ago
async getLogs() {
this.logs = await selectFromTable(`
select * from log where type = 1;
`)
},
async confirm() {
if (!this.fund.active_status && this.fund.active_status !== 0) {
uni.showToast({
icon: "none",
title: "请选择资产状态"
})
return
}
try {
if (this.$refs.uUpload.lists[0]?.url) {
const filePath = await uni.saveFile({
tempFilePath: this.$refs.uUpload.lists[0]?.url
})
console.log(filePath);
this.fund.files = filePath[1]?.savedFilePath
}
await executeSql(`
3 years ago
update property set active_status = "${this.fund.active_status}",remark = "${this.fund.remark}",is_check = 1${this.fund.files ? ',files = "' + this.fund.files + '"' : '' } where id = ${this.fund.id};
3 years ago
`)
uni.showToast({
icon: 'success',
title: '本地保存成功'
})
this.isShowPop = false
await executeSql(`
INSERT INTO log (remark,type) VALUES ('本地盘点:${this.fund.name}',1);
`)
await this.getLogs()
} catch (err) {
console.warn('sqlite-err', err)
androidModule.showToast(err)
}
},
listenRegist() {
receiver = plus.android.implements('io.dcloud.feature.internal.reflect.BroadcastReceiver', {
onReceive: (context, intent) => {
plus.android.importClass(intent)
3 years ago
let action = intent.getAction()
switch (action) {
case "com.rfid.SCAN":
let id = byteToString(intent.getExtra("data"))
this.qrIdList.push(id)
break;
case "android.rfid.FUN_KEY":
let keydown = intent.getBooleanExtra("keydown", false);
if (!keydown) {
this.scanClick()
}
break;
}
3 years ago
}
})
let intentFilter = plus.android.importClass('android.content.IntentFilter')
let filter = new intentFilter()
3 years ago
filter.addAction("android.rfid.FUN_KEY")
3 years ago
filter.addAction("com.rfid.SCAN")
main.registerReceiver(receiver, filter)
},
init() {
3 years ago
androidModule.initUhfrManage()
//二维码扫描初始化
let intentStart = new intent("com.rfid.SCAN_INIT")
main.sendBroadcast(intentStart)
let intentTime = new intent("com.rfid.SCAN_TIME")
intentTime.putExtra("time", 1000)
let intentBroad = new intent("com.rfid.SET_SCAN_MODE")
intentBroad.putExtra("mode", 0)
3 years ago
main.sendBroadcast(intentBroad)
},
async scanClick() {
if (!this.flag) {
this.flag = 1
3 years ago
//二维码扫描
this.qrIdList = []
let intentScan = new intent("com.rfid.SCAN_CMD")
timerQR = setInterval(() => {
main.sendBroadcast(intentScan)
}, 500)
3 years ago
//rfid扫描
androidModule.asyncStartReading()
try {
await executeSql(`
INSERT INTO log (remark) VALUES ('开始扫描');
`)
} catch (err) {
console.warn('sqlite-err', err)
androidModule.showToast(err)
}
} else {
3 years ago
this.flag = 0
clearInterval(timerQR)
3 years ago
//rfid标签盘点
androidModule.asyncStopReading()
androidModule.tagInventoryRealTime(async res => {
let dataList = JSON.parse(res)
const getSqlIn = () => {
3 years ago
return Array.from(new Set([...dataList, ...this.qrIdList])).map(item => {
3 years ago
return `"${item.replace(/^1(0+)/g,"")}"`
}).toString()
}
try {
let propertys = await selectFromTable(`
select * from property where id in (${getSqlIn()});
`)
androidModule.showToast(`扫描到:${propertys.length}件资产`)
3 years ago
this.info = propertys
3 years ago
this.fund = propertys[0]
3 years ago
} catch (e) {
console.warn('sqlite-err', e);
androidModule.showToast(err)
}
})
}
}
},
computed: {
activeStatusFormat() {
let map = new Map([
[0, '正常未领用'],
[1, '已领用'],
[-1, '报废'],
[-2, '维修停用']
])
return function(status) {
return map.get(status)
}
}
},
onLoad() {
// #ifdef APP-PLUS
this.init()
this.listenRegist()
// #endif
},
onUnload() {
3 years ago
// #ifdef APP-PLUS
//关闭二维码扫描
let intentClose = new intent("com.rfid.CLOSE_SCAN")
main.sendBroadcast(intentClose)
3 years ago
androidModule.stopTagInventory()
androidModule.close()
main.unregisterReceiver(receiver)
// #endif
},
mounted() {
// #ifdef APP-PLUS
try {
this.getLogs()
} catch (e) {
console.warn('sqlite-err', e);
androidModule.showToast(err)
}
3 years ago
// #endif
uni.$on('uploadSuccess',() => {
this.clear()
})
uni.$on('assetsSync',async () => {
try{
await executeSql(`
DELETE from log;
`)
await executeSql(`
UPDATE sqlite_sequence SET seq = 0 where name = 'log';
`)
}catch(err){
}
})
},
destroyed() {
uni.$off()
3 years ago
}
}
</script>
<style lang="scss" scoped>
::v-deep .u-drawer {
z-index: 999 !important;
}
.info {
display: flex;
padding-bottom: 30rpx;
&__name {
white-space: nowrap;
font-weight: bold;
}
&__value {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
padding-left: 10rpx;
}
&:nth-last-child() {
padding-bottom: 0;
}
}
.footer-title {
color: #303133;
padding-bottom: 32rpx;
}
.u-order-desc {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
</style>