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)
} }
}, },
......
...@@ -353,10 +353,10 @@ ...@@ -353,10 +353,10 @@
</van-radio-group> </van-radio-group>
<div style="border-bottom: 1px solid #000"> <div style="border-bottom: 1px solid #000">
<van-field :readonly="sample.type!=='其他'" <van-field :readonly="sample.type!=='其他'"
label-class="cus-field-class" label-class="cus-field-class"
label-width="50%" label-width="50%"
label-align="center" label-align="center"
v-model="sample.typeRemark" v-model="sample.typeRemark"
></van-field> ></van-field>
</div> </div>
</template> </template>
...@@ -377,10 +377,10 @@ ...@@ -377,10 +377,10 @@
</van-radio-group> </van-radio-group>
<div style="border-bottom: 1px solid #000"> <div style="border-bottom: 1px solid #000">
<van-field :readonly="sample.source!=='其他'" <van-field :readonly="sample.source!=='其他'"
label-class="cus-field-class" label-class="cus-field-class"
label-width="50%" label-width="50%"
label-align="center" label-align="center"
v-model="sample.sourceRemark" v-model="sample.sourceRemark"
></van-field> ></van-field>
</div> </div>
</template> </template>
...@@ -400,10 +400,10 @@ ...@@ -400,10 +400,10 @@
</van-radio-group> </van-radio-group>
<div style="border-bottom: 1px solid #000"> <div style="border-bottom: 1px solid #000">
<van-field :readonly="sample.properties!=='其他'" <van-field :readonly="sample.properties!=='其他'"
label-class="cus-field-class" label-class="cus-field-class"
label-width="50%" label-width="50%"
label-align="center" label-align="center"
v-model="sample.propertiesRemark" v-model="sample.propertiesRemark"
></van-field> ></van-field>
</div> </div>
</template> </template>
...@@ -699,10 +699,10 @@ ...@@ -699,10 +699,10 @@
</van-radio-group> </van-radio-group>
<div style="border-bottom: 1px solid #000"> <div style="border-bottom: 1px solid #000">
<van-field :readonly="formObj.thirdPartyNature!=='其他'" <van-field :readonly="formObj.thirdPartyNature!=='其他'"
label-class="cus-field-class" label-class="cus-field-class"
label-width="50%" label-width="50%"
label-align="center" label-align="center"
v-model="formObj.thirdPartyNatureRemark" v-model="formObj.thirdPartyNatureRemark"
></van-field> ></van-field>
</div> </div>
</template> </template>
...@@ -872,7 +872,7 @@ ...@@ -872,7 +872,7 @@
selectDateType: '', selectDateType: '',
showCityPicker: false, showCityPicker: false,
areaList:areaList, areaList: areaList,
formObj: { formObj: {
samplingNum: '', samplingNum: '',
...@@ -980,49 +980,69 @@ ...@@ -980,49 +980,69 @@
shelfId: this.$route.query.shelfId shelfId: this.$route.query.shelfId
} }
}, },
watch:{ watch: {
//除储存条件 选其他以外的选项备注清空 //除储存条件 选其他以外的选项备注清空
'sample.type':function (val) { 'sample.type': function (val) {
if(val!=='其他'){ if (val !== '其他') {
this.sample.typeRemark ='' this.sample.typeRemark = ''
} }
}, },
'sample.source':function (val) { 'sample.source': function (val) {
if(val!=='其他'){ if (val !== '其他') {
this.sample.sourceRemark ='' this.sample.sourceRemark = ''
} }
}, },
'sample.properties':function (val) { 'sample.properties': function (val) {
if(val!=='其他'){ if (val !== '其他') {
this.sample.propertiesRemark ='' this.sample.propertiesRemark = ''
} }
}, },
'formObj.thirdPartyNature':function (val) { 'formObj.thirdPartyNature': function (val) {
if(val!=='其他'){ if (val !== '其他') {
this.formObj.thirdPartyNatureRemark ='' this.formObj.thirdPartyNatureRemark = ''
} }
} }
}, },
computed: { computed: {
areaObj:function(){ areaObj: function () {
return this.netTested.testedProvince+this.netTested.testedCity+this.netTested.testedCountry return this.netTested.testedProvince + this.netTested.testedCity + this.netTested.testedCountry
} }
}, },
mounted() { mounted() {
this._open() this._open()
localStorage.removeItem('summary')
localStorage.removeItem('sample')
},
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() 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 if (localStorage.getItem('summary')) {
this._getLastTester() 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) {
switch (type) { switch (type) {
case 'netTested.name': case 'netTested.name':
this.$refs.tested._open() this.$refs.tested._open()
...@@ -1035,7 +1055,7 @@ ...@@ -1035,7 +1055,7 @@
break break
} }
}, },
_testerResult(res){ _testerResult(res) {
this.formObj.testName = res.testName ? res.testName : '' this.formObj.testName = res.testName ? res.testName : ''
this.formObj.testAddress = res.testAddress ? res.testAddress : '' this.formObj.testAddress = res.testAddress ? res.testAddress : ''
this.formObj.testLinkman = res.testLinkman ? res.testLinkman : '' this.formObj.testLinkman = res.testLinkman ? res.testLinkman : ''
...@@ -1043,13 +1063,13 @@ ...@@ -1043,13 +1063,13 @@
this.formObj.testEmail = res.testEmail ? res.testEmail : '' this.formObj.testEmail = res.testEmail ? res.testEmail : ''
this.formObj.testFax = res.testFax ? res.testFax : '' this.formObj.testFax = res.testFax ? res.testFax : ''
}, },
_producterResult(res){ _producterResult(res) {
this.formObj.proName = res.proName ? res.proName : '' this.formObj.proName = res.proName ? res.proName : ''
this.formObj.proAddress = res.proAddress ? res.proAddress : '' this.formObj.proAddress = res.proAddress ? res.proAddress : ''
this.formObj.proLicense = res.proLicense ? res.proLicense : '' this.formObj.proLicense = res.proLicense ? res.proLicense : ''
this.formObj.proTel = res.proTel ? res.proTel : '' this.formObj.proTel = res.proTel ? res.proTel : ''
}, },
_testedResult(res){ _testedResult(res) {
this.netTested.name = res.name ? res.name : '' this.netTested.name = res.name ? res.name : ''
this.netTested.testedProvince = res.testedProvince ? res.testedProvince : '' this.netTested.testedProvince = res.testedProvince ? res.testedProvince : ''
this.netTested.testedCity = res.testedCity ? res.testedCity : '' this.netTested.testedCity = res.testedCity ? res.testedCity : ''
...@@ -1064,11 +1084,14 @@ ...@@ -1064,11 +1084,14 @@
this.netTested.tel = res.tel ? res.tel : '' this.netTested.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) {
if (result[key]!=='') { if (result[key] !== '') {
if (key === 'sampleDate') { if (key === 'sampleDate') {
this.sample[key] = result[key] ? this.$dateformat(result[key], 'yyyy-mm-dd') : '' this.sample[key] = result[key] ? this.$dateformat(result[key], 'yyyy-mm-dd') : ''
} else if (key === 'storageCondition') { } else if (key === 'storageCondition') {
...@@ -1146,39 +1169,42 @@ ...@@ -1146,39 +1169,42 @@
_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.netTested) { }
if (result.netTested[key]!=='') { for (let key in this.netTested) {
if (key === 'placeLink') { if (result.netTested[key] !== '') {
this.place = result.netTested.placeLink + ',' + result.netTested.place if (key === 'placeLink') {
} else { this.place = result.netTested.placeLink + ',' + result.netTested.place
this.netTested[key] = result.netTested[key] } else {
} this.netTested[key] = result.netTested[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 === '') {
...@@ -1207,6 +1233,14 @@ ...@@ -1207,6 +1233,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, {netTested: this.netTested}, {sample: this.sample}) let data = Object.assign({}, this.formObj, {netTested: this.netTested}, {sample: this.sample})
data.sample.storageCondition = this.storageCondition.join(',') data.sample.storageCondition = this.storageCondition.join(',')
if (this.place) { if (this.place) {
...@@ -1215,25 +1249,23 @@ ...@@ -1215,25 +1249,23 @@
} }
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)
}
}, },
_editSave: async function (data) { _editSave: async function (data) {
data.id = this.id data.id = this.id
let result = await samplingSummary.edit(data) let result = await samplingSummary.edit(data)
if (result) { if (result) {
this.$toast('编辑成功!') this.$toast('编辑成功!')
this.$router.go(-1) localStorage.removeItem('summary')
localStorage.removeItem('sample')this.$router.go(-1)
} }
}, },
_selectDate(type) { _selectDate(type) {
......
<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