Commit 749744fb by zhuxiaomei

app扫码bug处理

parent 11456cb3
...@@ -1072,17 +1072,46 @@ ...@@ -1072,17 +1072,46 @@
} }
}, },
mounted() { mounted() {
mui.init({
beforeback: function () {
localStorage.removeItem('summary')
localStorage.removeItem('sample')
return true
}
})
this._open() this._open()
}, },
beforeDestroy(){
localStorage.removeItem('summary')
localStorage.removeItem('sample')
},
methods: { methods: {
_open() { _open() {
if (this.$route.query.id) {//编辑 if (this.$route.query.id) {//编辑
this.id = this.$route.query.id this.id = this.$route.query.id
this._getData() //localStorage.getItem('summary')有值 是扫码进来的
console.log(localStorage.getItem('summary'), 'localStorage.getItem(\'summary\')')
if (localStorage.getItem('summary')) {
this._initData(JSON.parse(localStorage.getItem('summary')))
if (localStorage.getItem('sample')) {
this._scanResult(JSON.parse(localStorage.getItem('sample')))
}
} else {
this._getData()
}
} else {//添加 } else {//添加
this.id = '' this.id = ''
this.formObj.testMembers = this.$global.getUserInfo().realname //localStorage.getItem('summary')有值 是扫码进来的
this._getLastTester() console.log(localStorage.getItem('summary'), 'localStorage.getItem(\'summary\')')
if (localStorage.getItem('summary')) {
this._initData(JSON.parse(localStorage.getItem('summary')))
if (localStorage.getItem('sample')) {
this._scanResult(JSON.parse(localStorage.getItem('sample')))
}
} else {
this.formObj.testMembers = this.$global.getUserInfo().realname
this._getLastTester()
}
} }
}, },
_companySelect(type) { _companySelect(type) {
...@@ -1127,7 +1156,10 @@ ...@@ -1127,7 +1156,10 @@
this.nonNetTested.tel = res.tel ? res.tel : '' this.nonNetTested.tel = res.tel ? res.tel : ''
}, },
_scan() { _scan() {
this.$refs.scan._open() //将已经填写过的存起来
localStorage.setItem('summary', JSON.stringify(this._getSaveObj()))
// this.$refs.scan._open()
this.$router.push('/sampling_list/scan_bar')
}, },
_scanResult(result) { _scanResult(result) {
for (let key in this.sample) { for (let key in this.sample) {
...@@ -1208,50 +1240,53 @@ ...@@ -1208,50 +1240,53 @@
_getData: async function () { _getData: async function () {
let result = await samplingSummary.getById(this.id) let result = await samplingSummary.getById(this.id)
if (result) { if (result) {
for (let key in this.formObj) { this._initData(result)
if (result[key] !== '') { }
if (key === 'samplingDate') { },
this.formObj[key] = result[key] ? this.$dateformat(result[key], 'yyyy-mm-dd') : '' _initData(result) {
} else { for (let key in this.formObj) {
this.formObj[key] = result[key] if (result[key] !== '') {
} if (key === 'samplingDate') {
this.formObj[key] = result[key] ? this.$dateformat(result[key], 'yyyy-mm-dd') : ''
} else {
this.formObj[key] = result[key]
} }
} }
for (let key in this.nonNetTested) { }
if (result.nonNetTested[key] !== '') { for (let key in this.nonNetTested) {
if (key === 'placeLink') { if (result.nonNetTested[key] !== '') {
this.place = result.nonNetTested.placeLink + ',' + result.nonNetTested.place if (key === 'placeLink') {
switch (result.nonNetTested.placeLink) { this.place = result.nonNetTested.placeLink + ',' + result.nonNetTested.place
case '1': switch (result.nonNetTested.placeLink) {
this.placeRemark1 = result.nonNetTested.placeRemark ? result.nonNetTested.placeRemark : '' case '1':
break this.placeRemark1 = result.nonNetTested.placeRemark ? result.nonNetTested.placeRemark : ''
case '2': break
this.placeRemark2 = result.nonNetTested.placeRemark ? result.nonNetTested.placeRemark : '' case '2':
break this.placeRemark2 = result.nonNetTested.placeRemark ? result.nonNetTested.placeRemark : ''
case '3': break
this.placeRemark3 = result.nonNetTested.placeRemark ? result.nonNetTested.placeRemark : '' case '3':
break this.placeRemark3 = result.nonNetTested.placeRemark ? result.nonNetTested.placeRemark : ''
} break
} else {
this.nonNetTested[key] = result.nonNetTested[key]
} }
} else {
this.nonNetTested[key] = result.nonNetTested[key]
} }
} }
for (let key in this.sample) { }
if (result.sample[key] !== '') { for (let key in this.sample) {
if (key === 'sampleDate') { if (result.sample[key] !== '') {
this.sample[key] = result.sample[key] ? this.$dateformat(result.sample[key], 'yyyy-mm-dd') : '' if (key === 'sampleDate') {
} else if (key === 'storageCondition') { this.sample[key] = result.sample[key] ? this.$dateformat(result.sample[key], 'yyyy-mm-dd') : ''
this.storageCondition = result.sample[key].split(',') } else if (key === 'storageCondition') {
this.sample[key] = result.sample[key] this.storageCondition = result.sample[key].split(',')
} else { this.sample[key] = result.sample[key]
this.sample[key] = result.sample[key] } else {
} this.sample[key] = result.sample[key]
} }
} }
this.testedType = result.testedType
this.shelfId = result.shelfId
} }
this.testedType = result.testedType
this.shelfId = result.shelfId
}, },
_valParams() { _valParams() {
if (this.formObj.samplingNum === '') { if (this.formObj.samplingNum === '') {
...@@ -1280,6 +1315,14 @@ ...@@ -1280,6 +1315,14 @@
if (this._valParams()) { if (this._valParams()) {
return return
} }
let data = this._getSaveObj()
if (this.id) {
this._editSave(data)
} else {
this._addSave(data)
}
},
_getSaveObj() {
let data = Object.assign({}, this.formObj, {nonNetTested: this.nonNetTested}, {sample: this.sample}) let data = Object.assign({}, this.formObj, {nonNetTested: this.nonNetTested}, {sample: this.sample})
data.sample.storageCondition = this.storageCondition.join(',') data.sample.storageCondition = this.storageCondition.join(',')
if (this.place) { if (this.place) {
...@@ -1299,16 +1342,14 @@ ...@@ -1299,16 +1342,14 @@
} }
data.shelfId = this.shelfId data.shelfId = this.shelfId
data.testedType = this.testedType data.testedType = this.testedType
if (this.id) { return data
this._editSave(data)
} else {
this._addSave(data)
}
}, },
_addSave: async function (data) { _addSave: async function (data) {
let result = await samplingSummary.add(data) let result = await samplingSummary.add(data)
if (result) { if (result) {
this.$toast('添加成功!') this.$toast('添加成功!')
localStorage.removeItem('summary')
localStorage.removeItem('sample')
this.$router.go(-1) this.$router.go(-1)
} }
}, },
...@@ -1317,6 +1358,8 @@ ...@@ -1317,6 +1358,8 @@
let result = await samplingSummary.edit(data) let result = await samplingSummary.edit(data)
if (result) { if (result) {
this.$toast('编辑成功!') this.$toast('编辑成功!')
localStorage.removeItem('summary')
localStorage.removeItem('sample')
this.$router.go(-1) this.$router.go(-1)
} }
}, },
......
<template>
<customer-navBar-layout>
<template #navBar>
<van-nav-bar title="扫码"
left-arrow
@click-left="_cancelScan"></van-nav-bar>
</template>
<template #content>
<div id="bcid">
<div style="height:40%"></div>
</div>
<div class="bottom-btn">
<van-button block type="default" @click="_cancelScan">取消</van-button>
</div>
</template>
</customer-navBar-layout>
</template>
<style scoped>
#bcid {
width: 100%;
height: calc(100% - 42px);
text-align: center;
}
</style>
<script>
import {samplingSample} from '../../api'
var barcode = null;//扫码对象
export default {
data() {
return {
num: '',
}
},
mounted() {
this._open()
//返回键操作
mui.init({
beforeback: function () {
barcode.close();
return true;
}
});
},
methods: {
_open() {
barcode = null;
let that = this;
if (!barcode) {
barcode = new plus.barcode.Barcode('bcid', [plus.barcode.EAN13, plus.barcode.EAN8], {
frameColor: '#00FF00',
scanbarColor: '#00FF00'
});
barcode.onmarked = function (type, result) {
if (type === plus.barcode.EAN13 || type === plus.barcode.EAN8) {
that._getSample(result)
} else {
that.$toast('扫描失败!')
barcode.close();
that.$router.go(-1);
}
};
plus.webview.currentWebview().append(barcode);
}
barcode.start();
},
_getSample: async function (qrcode) {
let res = await samplingSample.scanSample({qrcode: qrcode})
if (res) {
localStorage.setItem('sample', JSON.stringify(res))
barcode.close();
this.$router.go(-1)
} else {
localStorage.setItem('sample', JSON.stringify({qrcode: qrcode}))
barcode.close();
this.$router.go(-1)
}
},
_cancelScan() {
barcode.close();
this.$router.go(-1)
},
// _scanPicture() {
// let that = this;
// plus.gallery.pick(function (path) {
// plus.barcode.scan(path, function (type, result) {
// var text = '未知: ';
// switch (type) {
// case plus.barcode.CODE128:
// text = 'CODE128: ';
// break;
// }
// that.$store.dispatch('EnvSample/scanReceive', {num: result}).then(() => {
// if (that.$store.state.EnvSample.success) {
// barcode.close();
// that.$router.go(-1);
// }
// });
// }, function (error) {
// plus.nativeUI.alert('无法识别此图片');
// }, [plus.barcode.CODE128]);
// }, function (err) {
// console.log('Failed: ' + err.message);
// });
// },
}
}
</script>
...@@ -7,6 +7,7 @@ import SamplingListDetailNet from '@/page/sampling-list/SamplingListDetailNet.vu ...@@ -7,6 +7,7 @@ import SamplingListDetailNet from '@/page/sampling-list/SamplingListDetailNet.vu
import File from '@/page/sampling-list/file/File.vue' import File from '@/page/sampling-list/file/File.vue'
import FileUpload from '@/page/sampling-list/file/FileUpload.vue' import FileUpload from '@/page/sampling-list/file/FileUpload.vue'
import FileDownLoad from '@/page/sampling-list/file/FileDownLoad.vue' import FileDownLoad from '@/page/sampling-list/file/FileDownLoad.vue'
import ScanBar from '@/page/sampling-list/ScanBar.vue'
export default [ export default [
{path: 'sampling_task', component: SamplingTask, meta: {title: '抽样任务'}}, {path: 'sampling_task', component: SamplingTask, meta: {title: '抽样任务'}},
...@@ -18,4 +19,5 @@ export default [ ...@@ -18,4 +19,5 @@ export default [
{path: 'file', component: File, meta: {title: '附件'}}, {path: 'file', component: File, meta: {title: '附件'}},
{path: 'file_upload', component: FileUpload, meta: {title: '添加附件'}}, {path: 'file_upload', component: FileUpload, meta: {title: '添加附件'}},
{path: 'file_download', component: FileDownLoad, meta: {title: '预览附件'}}, {path: 'file_download', component: FileDownLoad, meta: {title: '预览附件'}},
{path: 'scan_bar', component: ScanBar, meta: {title: '扫码',hideNavBar:true}},
] ]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment