Commit 749744fb by zhuxiaomei

app扫码bug处理

parent 11456cb3
......@@ -1072,17 +1072,46 @@
}
},
mounted() {
mui.init({
beforeback: function () {
localStorage.removeItem('summary')
localStorage.removeItem('sample')
return true
}
})
this._open()
},
beforeDestroy(){
localStorage.removeItem('summary')
localStorage.removeItem('sample')
},
methods: {
_open() {
if (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 {//添加
this.id = ''
this.formObj.testMembers = this.$global.getUserInfo().realname
this._getLastTester()
//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.formObj.testMembers = this.$global.getUserInfo().realname
this._getLastTester()
}
}
},
_companySelect(type) {
......@@ -1127,7 +1156,10 @@
this.nonNetTested.tel = res.tel ? res.tel : ''
},
_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) {
for (let key in this.sample) {
......@@ -1208,50 +1240,53 @@
_getData: async function () {
let result = await samplingSummary.getById(this.id)
if (result) {
for (let key in this.formObj) {
if (result[key] !== '') {
if (key === 'samplingDate') {
this.formObj[key] = result[key] ? this.$dateformat(result[key], 'yyyy-mm-dd') : ''
} else {
this.formObj[key] = result[key]
}
this._initData(result)
}
},
_initData(result) {
for (let key in this.formObj) {
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] !== '') {
if (key === 'placeLink') {
this.place = result.nonNetTested.placeLink + ',' + result.nonNetTested.place
switch (result.nonNetTested.placeLink) {
case '1':
this.placeRemark1 = result.nonNetTested.placeRemark ? result.nonNetTested.placeRemark : ''
break
case '2':
this.placeRemark2 = result.nonNetTested.placeRemark ? result.nonNetTested.placeRemark : ''
break
case '3':
this.placeRemark3 = result.nonNetTested.placeRemark ? result.nonNetTested.placeRemark : ''
break
}
} else {
this.nonNetTested[key] = result.nonNetTested[key]
}
for (let key in this.nonNetTested) {
if (result.nonNetTested[key] !== '') {
if (key === 'placeLink') {
this.place = result.nonNetTested.placeLink + ',' + result.nonNetTested.place
switch (result.nonNetTested.placeLink) {
case '1':
this.placeRemark1 = result.nonNetTested.placeRemark ? result.nonNetTested.placeRemark : ''
break
case '2':
this.placeRemark2 = result.nonNetTested.placeRemark ? result.nonNetTested.placeRemark : ''
break
case '3':
this.placeRemark3 = result.nonNetTested.placeRemark ? result.nonNetTested.placeRemark : ''
break
}
} else {
this.nonNetTested[key] = result.nonNetTested[key]
}
}
for (let key in this.sample) {
if (result.sample[key] !== '') {
if (key === 'sampleDate') {
this.sample[key] = result.sample[key] ? this.$dateformat(result.sample[key], 'yyyy-mm-dd') : ''
} else if (key === 'storageCondition') {
this.storageCondition = result.sample[key].split(',')
this.sample[key] = result.sample[key]
} else {
this.sample[key] = result.sample[key]
}
}
for (let key in this.sample) {
if (result.sample[key] !== '') {
if (key === 'sampleDate') {
this.sample[key] = result.sample[key] ? this.$dateformat(result.sample[key], 'yyyy-mm-dd') : ''
} else if (key === 'storageCondition') {
this.storageCondition = result.sample[key].split(',')
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() {
if (this.formObj.samplingNum === '') {
......@@ -1280,6 +1315,14 @@
if (this._valParams()) {
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})
data.sample.storageCondition = this.storageCondition.join(',')
if (this.place) {
......@@ -1299,16 +1342,14 @@
}
data.shelfId = this.shelfId
data.testedType = this.testedType
if (this.id) {
this._editSave(data)
} else {
this._addSave(data)
}
return data
},
_addSave: async function (data) {
let result = await samplingSummary.add(data)
if (result) {
this.$toast('添加成功!')
localStorage.removeItem('summary')
localStorage.removeItem('sample')
this.$router.go(-1)
}
},
......@@ -1317,6 +1358,8 @@
let result = await samplingSummary.edit(data)
if (result) {
this.$toast('编辑成功!')
localStorage.removeItem('summary')
localStorage.removeItem('sample')
this.$router.go(-1)
}
},
......
......@@ -353,10 +353,10 @@
</van-radio-group>
<div style="border-bottom: 1px solid #000">
<van-field :readonly="sample.type!=='其他'"
label-class="cus-field-class"
label-width="50%"
label-align="center"
v-model="sample.typeRemark"
label-class="cus-field-class"
label-width="50%"
label-align="center"
v-model="sample.typeRemark"
></van-field>
</div>
</template>
......@@ -377,10 +377,10 @@
</van-radio-group>
<div style="border-bottom: 1px solid #000">
<van-field :readonly="sample.source!=='其他'"
label-class="cus-field-class"
label-width="50%"
label-align="center"
v-model="sample.sourceRemark"
label-class="cus-field-class"
label-width="50%"
label-align="center"
v-model="sample.sourceRemark"
></van-field>
</div>
</template>
......@@ -400,10 +400,10 @@
</van-radio-group>
<div style="border-bottom: 1px solid #000">
<van-field :readonly="sample.properties!=='其他'"
label-class="cus-field-class"
label-width="50%"
label-align="center"
v-model="sample.propertiesRemark"
label-class="cus-field-class"
label-width="50%"
label-align="center"
v-model="sample.propertiesRemark"
></van-field>
</div>
</template>
......@@ -699,10 +699,10 @@
</van-radio-group>
<div style="border-bottom: 1px solid #000">
<van-field :readonly="formObj.thirdPartyNature!=='其他'"
label-class="cus-field-class"
label-width="50%"
label-align="center"
v-model="formObj.thirdPartyNatureRemark"
label-class="cus-field-class"
label-width="50%"
label-align="center"
v-model="formObj.thirdPartyNatureRemark"
></van-field>
</div>
</template>
......@@ -872,7 +872,7 @@
selectDateType: '',
showCityPicker: false,
areaList:areaList,
areaList: areaList,
formObj: {
samplingNum: '',
......@@ -980,49 +980,69 @@
shelfId: this.$route.query.shelfId
}
},
watch:{
watch: {
//除储存条件 选其他以外的选项备注清空
'sample.type':function (val) {
if(val!=='其他'){
this.sample.typeRemark =''
'sample.type': function (val) {
if (val !== '其他') {
this.sample.typeRemark = ''
}
},
'sample.source':function (val) {
if(val!=='其他'){
this.sample.sourceRemark =''
'sample.source': function (val) {
if (val !== '其他') {
this.sample.sourceRemark = ''
}
},
'sample.properties':function (val) {
if(val!=='其他'){
this.sample.propertiesRemark =''
'sample.properties': function (val) {
if (val !== '其他') {
this.sample.propertiesRemark = ''
}
},
'formObj.thirdPartyNature':function (val) {
if(val!=='其他'){
this.formObj.thirdPartyNatureRemark =''
'formObj.thirdPartyNature': function (val) {
if (val !== '其他') {
this.formObj.thirdPartyNatureRemark = ''
}
}
},
computed: {
areaObj:function(){
return this.netTested.testedProvince+this.netTested.testedCity+this.netTested.testedCountry
}
areaObj: function () {
return this.netTested.testedProvince + this.netTested.testedCity + this.netTested.testedCountry
}
},
mounted() {
this._open()
localStorage.removeItem('summary')
localStorage.removeItem('sample')
},
beforeDestroy(){
localStorage.removeItem('summary')
localStorage.removeItem('sample')
},
methods: {
_open() {
if (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 {//添加
this.id = ''
this.formObj.testMembers = this.$global.getUserInfo().realname
this._getLastTester()
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) {
switch (type) {
case 'netTested.name':
this.$refs.tested._open()
......@@ -1035,7 +1055,7 @@
break
}
},
_testerResult(res){
_testerResult(res) {
this.formObj.testName = res.testName ? res.testName : ''
this.formObj.testAddress = res.testAddress ? res.testAddress : ''
this.formObj.testLinkman = res.testLinkman ? res.testLinkman : ''
......@@ -1043,13 +1063,13 @@
this.formObj.testEmail = res.testEmail ? res.testEmail : ''
this.formObj.testFax = res.testFax ? res.testFax : ''
},
_producterResult(res){
_producterResult(res) {
this.formObj.proName = res.proName ? res.proName : ''
this.formObj.proAddress = res.proAddress ? res.proAddress : ''
this.formObj.proLicense = res.proLicense ? res.proLicense : ''
this.formObj.proTel = res.proTel ? res.proTel : ''
},
_testedResult(res){
_testedResult(res) {
this.netTested.name = res.name ? res.name : ''
this.netTested.testedProvince = res.testedProvince ? res.testedProvince : ''
this.netTested.testedCity = res.testedCity ? res.testedCity : ''
......@@ -1064,11 +1084,14 @@
this.netTested.tel = res.tel ? res.tel : ''
},
_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) {
for (let key in this.sample) {
if (result[key]!=='') {
if (result[key] !== '') {
if (key === 'sampleDate') {
this.sample[key] = result[key] ? this.$dateformat(result[key], 'yyyy-mm-dd') : ''
} else if (key === 'storageCondition') {
......@@ -1146,39 +1169,42 @@
_getData: async function () {
let result = await samplingSummary.getById(this.id)
if (result) {
for (let key in this.formObj) {
if (result[key]!=='') {
if (key === 'samplingDate') {
this.formObj[key] = result[key] ? this.$dateformat(result[key], 'yyyy-mm-dd') : ''
} else {
this.formObj[key] = result[key]
}
this._initData(result)
}
},
_initData(result) {
for (let key in this.formObj) {
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]!=='') {
if (key === 'placeLink') {
this.place = result.netTested.placeLink + ',' + result.netTested.place
} else {
this.netTested[key] = result.netTested[key]
}
}
for (let key in this.netTested) {
if (result.netTested[key] !== '') {
if (key === 'placeLink') {
this.place = result.netTested.placeLink + ',' + result.netTested.place
} else {
this.netTested[key] = result.netTested[key]
}
}
for (let key in this.sample) {
if (result.sample[key]!=='') {
if (key === 'sampleDate') {
this.sample[key] = result.sample[key] ? this.$dateformat(result.sample[key], 'yyyy-mm-dd') : ''
} else if (key === 'storageCondition') {
this.storageCondition = result.sample[key].split(',')
this.sample[key] = result.sample[key]
} else {
this.sample[key] = result.sample[key]
}
}
for (let key in this.sample) {
if (result.sample[key] !== '') {
if (key === 'sampleDate') {
this.sample[key] = result.sample[key] ? this.$dateformat(result.sample[key], 'yyyy-mm-dd') : ''
} else if (key === 'storageCondition') {
this.storageCondition = result.sample[key].split(',')
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() {
if (this.formObj.samplingNum === '') {
......@@ -1207,6 +1233,14 @@
if (this._valParams()) {
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})
data.sample.storageCondition = this.storageCondition.join(',')
if (this.place) {
......@@ -1215,25 +1249,23 @@
}
data.shelfId = this.shelfId
data.testedType = this.testedType
if (this.id) {
this._editSave(data)
} else {
this._addSave(data)
}
return data
},
_addSave: async function (data) {
let result = await samplingSummary.add(data)
if (result) {
this.$toast('添加成功!')
localStorage.removeItem('summary')
localStorage.removeItem('sample') }
this.$router.go(-1)
}
},
_editSave: async function (data) {
data.id = this.id
let result = await samplingSummary.edit(data)
if (result) {
this.$toast('编辑成功!')
this.$router.go(-1)
localStorage.removeItem('summary')
localStorage.removeItem('sample')this.$router.go(-1)
}
},
_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
import File from '@/page/sampling-list/file/File.vue'
import FileUpload from '@/page/sampling-list/file/FileUpload.vue'
import FileDownLoad from '@/page/sampling-list/file/FileDownLoad.vue'
import ScanBar from '@/page/sampling-list/ScanBar.vue'
export default [
{path: 'sampling_task', component: SamplingTask, meta: {title: '抽样任务'}},
......@@ -18,4 +19,5 @@ export default [
{path: 'file', component: File, meta: {title: '附件'}},
{path: 'file_upload', component: FileUpload, 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