给所有单据都增加扫码功能

This commit is contained in:
季圣华 2021-10-09 00:35:51 +08:00
parent d5bb4616a3
commit d958c07341
14 changed files with 343 additions and 14 deletions

View File

@ -110,4 +110,67 @@ export function validateTables(cases, deleteTempId) {
})
})()
})
}
/**
* 一次性验证主表单和所有的次表单-只校验单号
* @param form 主表单 form 对象
* @param cases 接收一个数组每项都是一个JEditableTable实例
* @returns {Promise<any>}
* @author sunjianlei
*/
export function getListData(form, cases) {
let options = {}
return new Promise((resolve, reject) => {
// 验证主表表单
form.validateFields(['number'],(err, values) => {
err ? reject({ error: VALIDATE_NO_PASSED }) : resolve(values)
})
}).then(values => {
Object.assign(options, { formValue: values })
// 验证所有子表的表单
return getListTables(cases)
}).then(all => {
Object.assign(options, { tablesValue: all })
return Promise.resolve(options)
}).catch(error => {
return Promise.reject(error)
})
}
/**
* 不验证直接获取一个或多个表格的所有值
* @param cases 接收一个数组每项都是一个JEditableTable实例
* @param deleteTempId 是否删除临时ID如果设为true行编辑就不返回新增行的IDID需要后台生成
* @author sunjianlei
*/
export function getListTables(cases, deleteTempId) {
if (!(cases instanceof Array)) {
throw `'validateTables'函数的'cases'参数需要的是一个数组而传入的却是${typeof cases}`
}
return new Promise((resolve, reject) => {
let tables = []
let index = 0;
if(!cases || cases.length==0){
resolve()
}
(function next() {
let vm = cases[index]
vm.getAll(false, deleteTempId).then(all => {
tables[index] = all
// 判断校验是否全部完成完成返回成功否则继续进行下一步校验
if (++index === cases.length) {
resolve(tables)
} else (
next()
)
}, error => {
// 出现未验证通过的表单不再进行下一步校验直接返回失败并跳转到该表格
if (error === VALIDATE_NO_PASSED) {
reject({ error: VALIDATE_NO_PASSED, index })
}
reject(error)
})
})()
})
}

View File

@ -1,4 +1,4 @@
import { FormTypes } from '@/utils/JEditableTableUtil'
import { FormTypes, getListData } from '@/utils/JEditableTableUtil'
import {findBySelectSup,findBySelectCus,findBySelectRetail,getMaterialByBarCode,findStockByDepotAndBarCode,getAccount,
getPersonByNumType, getBatchNumberList} from '@/api/api'
import { getAction,putAction } from '@/api/manage'
@ -511,8 +511,106 @@ export const BillModalMixin = {
scanEnter() {
this.scanStatus = false
},
//扫码之后回车
scanPressEnter() {
console.log(this.scanBarCode)
if(this.scanBarCode) {
this.getAllTable().then(tables => {
return getListData(this.form, tables)
}).then(allValues => {
let param = {
barCode: this.scanBarCode,
mpList: getMpListShort(Vue.ls.get('materialPropertyList')), //扩展属性
prefixNo: this.prefixNo
}
getMaterialByBarCode(param).then((res) => {
if (res && res.code === 200) {
let hasFinished = false
let allTaxLastMoney = 0
//获取单据明细列表信息
let detailArr = allValues.tablesValue[0].values
//构造新的列表数组用于存放单据明细信息
let newDetailArr = []
for(let detail of detailArr){
if(detail.barCode) {
//如果条码重复就在给原来的数量加1
if(detail.barCode === this.scanBarCode) {
detail.operNumber = (detail.operNumber-0)+1
//由于改变了商品数量需要同时更新相关金额和价税合计
let taxRate = detail.taxRate-0 //税率
let unitPrice = detail.unitPrice-0 //单价
detail.allPrice = (unitPrice*detail.operNumber).toFixed(2)-0
detail.taxMoney = ((taxRate*0.01)*detail.allPrice).toFixed(2)-0
detail.taxLastMoney = (detail.allPrice + detail.taxMoney).toFixed(2)-0
hasFinished = true
}
newDetailArr.push(detail)
}
}
if(!hasFinished) {
//将扫码的条码对应的商品加入列表
let item = {}
item.barCode = this.scanBarCode
let mList = res.data
if(mList && mList.length>0) {
let mInfo = mList[0]
if(mInfo.sku) {
this.changeFormTypes(this.materialTable.columns, 'sku', 1)
}
if(mInfo.enableSerialNumber === "1") {
this.changeFormTypes(this.materialTable.columns, 'snList', 1)
}
if(mInfo.enableBatchNumber === "1") {
this.changeFormTypes(this.materialTable.columns, 'batchNumber', 1)
this.changeFormTypes(this.materialTable.columns, 'expirationDate', 1)
}
item.depotId = mInfo.depotId
item.name = mInfo.name
item.standard = mInfo.standard
item.model = mInfo.model
item.materialOther = mInfo.materialOther
item.stock = mInfo.stock
item.unit = mInfo.commodityUnit
item.sku = mInfo.sku
item.operNumber = 1
item.unitPrice = mInfo.billPrice
item.taxUnitPrice = mInfo.billPrice
item.allPrice = mInfo.billPrice
item.taxRate = 0
item.taxMoney = 0
item.taxLastMoney = mInfo.billPrice
newDetailArr.push(item)
} else {
this.$message.warning('抱歉此条码不存在商品信息');
}
}
//组合和拆分单据给商品类型进行重新赋值
for(let i=0; i< newDetailArr.length; i++) {
if(i===0) {
newDetailArr[0].mType = '组合件'
} else {
newDetailArr[i].mType = '普通子件'
}
}
this.materialTable.dataSource = newDetailArr
//更新优惠后金额本次付款等信息
for(let newDetail of newDetailArr){
allTaxLastMoney = allTaxLastMoney + (newDetail.taxLastMoney-0)
}
let discount = this.form.getFieldValue('discount')-0
let otherMoney = this.form.getFieldValue('otherMoney')-0
let discountMoney = (discount*0.01*allTaxLastMoney).toFixed(2)-0
let discountLastMoney = (allTaxLastMoney-discountMoney).toFixed(2)-0
let changeAmountNew = (discountLastMoney + otherMoney).toFixed(2)-0
this.$nextTick(() => {
this.form.setFieldsValue({'discount':discount,'discountMoney':discountMoney,'discountLastMoney':discountLastMoney,
'changeAmount':changeAmountNew,'debt':0})
});
//置空扫码的内容
this.scanBarCode = ''
}
})
})
}
},
stopScan() {
this.scanStatus = true

View File

@ -39,7 +39,21 @@
:actionButton="true"
@valueChange="onValueChange"
@added="onAdded"
@deleted="onDeleted" />
@deleted="onDeleted">
<template #buttonAfter>
<a-row :gutter="24">
<a-col v-if="scanStatus" :md="6" :sm="24">
<a-button @click="scanEnter">扫码录入</a-button>
</a-col>
<a-col v-if="!scanStatus" :md="16" :sm="24" style="padding: 0 6px 0 12px">
<a-input placeholder="请扫码商品条码并回车" v-model="scanBarCode" @pressEnter="scanPressEnter" />
</a-col>
<a-col v-if="!scanStatus" :md="6" :sm="24" style="padding: 0px">
<a-button @click="stopScan">收起扫码</a-button>
</a-col>
</a-row>
</template>
</j-editable-table>
<a-row class="form-row" :gutter="24">
<a-col :lg="24" :md="24" :sm="24">
<a-form-item :labelCol="labelCol" :wrapperCol="{xs: { span: 24 },sm: { span: 24 }}" label="">

View File

@ -39,7 +39,21 @@
:actionButton="true"
@valueChange="onValueChange"
@added="onAdded"
@deleted="onDeleted" />
@deleted="onDeleted">
<template #buttonAfter>
<a-row :gutter="24">
<a-col v-if="scanStatus" :md="6" :sm="24">
<a-button @click="scanEnter">扫码录入</a-button>
</a-col>
<a-col v-if="!scanStatus" :md="16" :sm="24" style="padding: 0 6px 0 12px">
<a-input placeholder="请扫码商品条码并回车" v-model="scanBarCode" @pressEnter="scanPressEnter" />
</a-col>
<a-col v-if="!scanStatus" :md="6" :sm="24" style="padding: 0px">
<a-button @click="stopScan">收起扫码</a-button>
</a-col>
</a-row>
</template>
</j-editable-table>
<a-row class="form-row" :gutter="24">
<a-col :lg="24" :md="24" :sm="24">
<a-form-item :labelCol="labelCol" :wrapperCol="{xs: { span: 24 },sm: { span: 24 }}" label="">

View File

@ -39,7 +39,21 @@
:actionButton="true"
@valueChange="onValueChange"
@added="onAdded"
@deleted="onDeleted" />
@deleted="onDeleted">
<template #buttonAfter>
<a-row :gutter="24">
<a-col v-if="scanStatus" :md="6" :sm="24">
<a-button @click="scanEnter">扫码录入</a-button>
</a-col>
<a-col v-if="!scanStatus" :md="16" :sm="24" style="padding: 0 6px 0 12px">
<a-input placeholder="请扫码商品条码并回车" v-model="scanBarCode" @pressEnter="scanPressEnter" />
</a-col>
<a-col v-if="!scanStatus" :md="6" :sm="24" style="padding: 0px">
<a-button @click="stopScan">收起扫码</a-button>
</a-col>
</a-row>
</template>
</j-editable-table>
<a-row class="form-row" :gutter="24">
<a-col :lg="24" :md="24" :sm="24">
<a-form-item :labelCol="labelCol" :wrapperCol="{xs: { span: 24 },sm: { span: 24 }}" label="">

View File

@ -48,7 +48,21 @@
:actionButton="true"
@valueChange="onValueChange"
@added="onAdded"
@deleted="onDeleted" />
@deleted="onDeleted">
<template #buttonAfter>
<a-row :gutter="24">
<a-col v-if="scanStatus" :md="6" :sm="24">
<a-button @click="scanEnter">扫码录入</a-button>
</a-col>
<a-col v-if="!scanStatus" :md="16" :sm="24" style="padding: 0 6px 0 12px">
<a-input placeholder="请扫码商品条码并回车" v-model="scanBarCode" @pressEnter="scanPressEnter" />
</a-col>
<a-col v-if="!scanStatus" :md="6" :sm="24" style="padding: 0px">
<a-button @click="stopScan">收起扫码</a-button>
</a-col>
</a-row>
</template>
</j-editable-table>
<a-row class="form-row" :gutter="24">
<a-col :lg="24" :md="24" :sm="24">
<a-form-item :labelCol="labelCol" :wrapperCol="{xs: { span: 24 },sm: { span: 24 }}" label="">

View File

@ -48,7 +48,21 @@
:actionButton="true"
@valueChange="onValueChange"
@added="onAdded"
@deleted="onDeleted" />
@deleted="onDeleted">
<template #buttonAfter>
<a-row :gutter="24">
<a-col v-if="scanStatus" :md="6" :sm="24">
<a-button @click="scanEnter">扫码录入</a-button>
</a-col>
<a-col v-if="!scanStatus" :md="16" :sm="24" style="padding: 0 6px 0 12px">
<a-input placeholder="请扫码商品条码并回车" v-model="scanBarCode" @pressEnter="scanPressEnter" />
</a-col>
<a-col v-if="!scanStatus" :md="6" :sm="24" style="padding: 0px">
<a-button @click="stopScan">收起扫码</a-button>
</a-col>
</a-row>
</template>
</j-editable-table>
<a-row class="form-row" :gutter="24">
<a-col :lg="24" :md="24" :sm="24">
<a-form-item :labelCol="labelCol" :wrapperCol="{xs: { span: 24 },sm: { span: 24 }}" label="">

View File

@ -52,7 +52,21 @@
:actionButton="true"
@valueChange="onValueChange"
@added="onAdded"
@deleted="onDeleted" />
@deleted="onDeleted">
<template #buttonAfter>
<a-row :gutter="24">
<a-col v-if="scanStatus" :md="6" :sm="24">
<a-button @click="scanEnter">扫码录入</a-button>
</a-col>
<a-col v-if="!scanStatus" :md="16" :sm="24" style="padding: 0 6px 0 12px">
<a-input placeholder="请扫码商品条码并回车" v-model="scanBarCode" @pressEnter="scanPressEnter" />
</a-col>
<a-col v-if="!scanStatus" :md="6" :sm="24" style="padding: 0px">
<a-button @click="stopScan">收起扫码</a-button>
</a-col>
</a-row>
</template>
</j-editable-table>
<a-row class="form-row" :gutter="24">
<a-col :lg="24" :md="24" :sm="24">
<a-form-item :labelCol="labelCol" :wrapperCol="{xs: { span: 24 },sm: { span: 24 }}" label="">

View File

@ -47,7 +47,21 @@
:rowSelection="true"
:actionButton="true"
@valueChange="onValueChange"
@deleted="onDeleted" />
@deleted="onDeleted">
<template #buttonAfter>
<a-row :gutter="24">
<a-col v-if="scanStatus" :md="6" :sm="24">
<a-button @click="scanEnter">扫码录入</a-button>
</a-col>
<a-col v-if="!scanStatus" :md="16" :sm="24" style="padding: 0 6px 0 12px">
<a-input placeholder="请扫码商品条码并回车" v-model="scanBarCode" @pressEnter="scanPressEnter" />
</a-col>
<a-col v-if="!scanStatus" :md="6" :sm="24" style="padding: 0px">
<a-button @click="stopScan">收起扫码</a-button>
</a-col>
</a-row>
</template>
</j-editable-table>
<a-row class="form-row" :gutter="24">
<a-col :lg="24" :md="24" :sm="24">
<a-form-item :labelCol="labelCol" :wrapperCol="{xs: { span: 24 },sm: { span: 24 }}" label="">

View File

@ -55,7 +55,21 @@
:actionButton="true"
@valueChange="onValueChange"
@added="onAdded"
@deleted="onDeleted" />
@deleted="onDeleted">
<template #buttonAfter>
<a-row :gutter="24">
<a-col v-if="scanStatus" :md="6" :sm="24">
<a-button @click="scanEnter">扫码录入</a-button>
</a-col>
<a-col v-if="!scanStatus" :md="16" :sm="24" style="padding: 0 6px 0 12px">
<a-input placeholder="请扫码商品条码并回车" v-model="scanBarCode" @pressEnter="scanPressEnter" />
</a-col>
<a-col v-if="!scanStatus" :md="6" :sm="24" style="padding: 0px">
<a-button @click="stopScan">收起扫码</a-button>
</a-col>
</a-row>
</template>
</j-editable-table>
</a-col>
<a-col :lg="6" :md="12" :sm="24">
<a-row class="form-row" :gutter="24">

View File

@ -59,7 +59,21 @@
:actionButton="true"
@valueChange="onValueChange"
@added="onAdded"
@deleted="onDeleted" />
@deleted="onDeleted">
<template #buttonAfter>
<a-row :gutter="24">
<a-col v-if="scanStatus" :md="6" :sm="24">
<a-button @click="scanEnter">扫码录入</a-button>
</a-col>
<a-col v-if="!scanStatus" :md="16" :sm="24" style="padding: 0 6px 0 12px">
<a-input placeholder="请扫码商品条码并回车" v-model="scanBarCode" @pressEnter="scanPressEnter" />
</a-col>
<a-col v-if="!scanStatus" :md="6" :sm="24" style="padding: 0px">
<a-button @click="stopScan">收起扫码</a-button>
</a-col>
</a-row>
</template>
</j-editable-table>
</a-col>
<a-col :lg="6" :md="12" :sm="24">
<a-row class="form-row" :gutter="24">

View File

@ -52,7 +52,21 @@
:actionButton="true"
@valueChange="onValueChange"
@added="onAdded"
@deleted="onDeleted" />
@deleted="onDeleted">
<template #buttonAfter>
<a-row :gutter="24">
<a-col v-if="scanStatus" :md="6" :sm="24">
<a-button @click="scanEnter">扫码录入</a-button>
</a-col>
<a-col v-if="!scanStatus" :md="16" :sm="24" style="padding: 0 6px 0 12px">
<a-input placeholder="请扫码商品条码并回车" v-model="scanBarCode" @pressEnter="scanPressEnter" />
</a-col>
<a-col v-if="!scanStatus" :md="6" :sm="24" style="padding: 0px">
<a-button @click="stopScan">收起扫码</a-button>
</a-col>
</a-row>
</template>
</j-editable-table>
<a-row class="form-row" :gutter="24">
<a-col :lg="24" :md="24" :sm="24">
<a-form-item :labelCol="labelCol" :wrapperCol="{xs: { span: 24 },sm: { span: 24 }}" label="">

View File

@ -51,7 +51,21 @@
:rowSelection="true"
:actionButton="true"
@valueChange="onValueChange"
@deleted="onDeleted" />
@deleted="onDeleted">
<template #buttonAfter>
<a-row :gutter="24">
<a-col v-if="scanStatus" :md="6" :sm="24">
<a-button @click="scanEnter">扫码录入</a-button>
</a-col>
<a-col v-if="!scanStatus" :md="16" :sm="24" style="padding: 0 6px 0 12px">
<a-input placeholder="请扫码商品条码并回车" v-model="scanBarCode" @pressEnter="scanPressEnter" />
</a-col>
<a-col v-if="!scanStatus" :md="6" :sm="24" style="padding: 0px">
<a-button @click="stopScan">收起扫码</a-button>
</a-col>
</a-row>
</template>
</j-editable-table>
<a-row class="form-row" :gutter="24">
<a-col :lg="24" :md="24" :sm="24">
<a-form-item :labelCol="labelCol" :wrapperCol="{xs: { span: 24 },sm: { span: 24 }}" label="">

View File

@ -52,7 +52,21 @@
:actionButton="true"
@valueChange="onValueChange"
@added="onAdded"
@deleted="onDeleted" />
@deleted="onDeleted">
<template #buttonAfter>
<a-row :gutter="24">
<a-col v-if="scanStatus" :md="6" :sm="24">
<a-button @click="scanEnter">扫码录入</a-button>
</a-col>
<a-col v-if="!scanStatus" :md="16" :sm="24" style="padding: 0 6px 0 12px">
<a-input placeholder="请扫码商品条码并回车" v-model="scanBarCode" @pressEnter="scanPressEnter" />
</a-col>
<a-col v-if="!scanStatus" :md="6" :sm="24" style="padding: 0px">
<a-button @click="stopScan">收起扫码</a-button>
</a-col>
</a-row>
</template>
</j-editable-table>
<a-row class="form-row" :gutter="24">
<a-col :lg="24" :md="24" :sm="24">
<a-form-item :labelCol="labelCol" :wrapperCol="{xs: { span: 24 },sm: { span: 24 }}" label="">