增加商品条码功能

This commit is contained in:
季圣华
2020-02-17 00:59:25 +08:00
parent 301d053bd4
commit 4b61eb59ee
33 changed files with 3728 additions and 1995 deletions

View File

@@ -23,6 +23,31 @@
return o;
};
/**
* 扩展datagrid的editors方法支持combogrid
*/
$.extend($.fn.datagrid.defaults.editors, {
combogrid: {
init: function (container, options) {
var input = $('<input type="text" style="height: 22px;" class="datagrid-editable-input">').appendTo(container);
input.combogrid(options);
return input;
},
destroy: function (target) {
$(target).combogrid('destroy');
},
getValue: function (target) {
return $(target).combogrid('getValue');
},
setValue: function (target, value) {
$(target).combogrid('setValue', value);
},
resize: function (target, width) {
$(target).combogrid('resize', width);
}
}
});
$(function() {
domresize();
});

View File

@@ -533,23 +533,25 @@
dgResize();
}
//查找库存的方法
function findStockNumById(depotId, mId, monthTime, body, input, ratio, type){
function findStockNumById(depotId, meId, monthTime, body, input, ratio, type){
var thisRatio = 1; //比例
$.ajax({
url: "/material/findById",
url: "/material/findByIdWithBarCode",
type: "get",
dataType: "json",
data: {
id: mId
meId: meId
},
success: function (rec) {
if(rec && rec.code === 200 && rec.data && rec.data[0]) {
if(rec && rec.code === 200) {
var info = rec.data;
var commodityUnit = info.commodityUnit; //商品单位
var loadRatio = 1; //在单位输入框上面加载比例字段
if(rec.data[0].unit) { //如果存在计量单位信息
if(info.unit) { //如果存在计量单位信息
loadRatio = 1;
}
else{
var unitName = rec.data[0].unitName;
var unitName = info.unitName;
if(unitName) {
thisRatio = unitName.substring(unitName.indexOf(":")+1).replace(")","");
unitName = unitName.substring(0, unitName.indexOf("("));
@@ -557,24 +559,11 @@
var unitArr = unitName.split(",");
var basicUnit = unitArr[0]; //基础单位
var otherUnit = unitArr[1]; //副单位
var unitSetInput =""; //单位
if(listSubType === "采购订单" || listSubType === "采购" || listSubType === "采购退货"){
unitSetInput = rec.data[0].firstinunit;
if(basicUnit==unitSetInput){ //基础单位等于选择的单位
loadRatio = 1;
}
else if(otherUnit==unitSetInput){ //副单位等于选择的单位
loadRatio = thisRatio;
}
if(basicUnit==commodityUnit){ //基础单位等于选择的单位
loadRatio = 1;
}
else if(listSubType === "销售订单" || listSubType === "销售" || listSubType === "销售退货" || listSubType === "零售" || listSubType === "零售退货"){
unitSetInput = rec.data[0].firstoutunit;
if(basicUnit==unitSetInput){ //基础单位等于选择的单位
loadRatio = 1;
}
else if(otherUnit==unitSetInput){ //副单位等于选择的单位
loadRatio = thisRatio;
}
else if(otherUnit==commodityUnit){ //副单位等于选择的单位
loadRatio = thisRatio;
}
}
//查询库存
@@ -583,7 +572,7 @@
url: '/depotItem/findStockNumById',
data:{
depotId: depotId,
mId: mId
mId: info.id
},
dataType: "json",
success: function (res) {
@@ -721,7 +710,7 @@
body =$("#depotHeadFM .datagrid-body");
footer =$("#depotHeadFM .datagrid-footer");
input = ".datagrid-editable-input";
var mId = body.find("[field='MaterialId']").find(".combo-value").val();
var mId = body.find("[field='MaterialExtendId']").find(".combo-value").val();
if(mId){
var type = "select"; //type 类型:点击 click选择 select
findStockNumById(depotId, mId, monthTime, body, input, ratioDepot, type);
@@ -730,37 +719,71 @@
}
}
},
{ title: '品名(型号)(扩展信息)(单位)',field: 'MaterialId',width:230,
{ title: '条码_品名(规格)(型号)(扩展信息)(单位)',field: 'MaterialExtendId',width:270,
formatter:function(value,row,index){
return row.MaterialName;
},
editor:{
type:'combobox',
options:{
valueField:'Id',
textField:'MaterialName',
method:'get',
url: "/material/findBySelect",
panelWidth: 300, //下拉框的宽度
//全面模糊匹配,过滤字段
filter: function(q, row){
var opts = $(this).combobox('options');
return row[opts.textField].indexOf(q) >-1;
},
type:'combogrid',
options:{
url: "/material/findBySelect",
idField:'Id',
textField:'MaterialName',
method:'get',
pagination: true,
mode: 'remote',
hasDownArrow: false,
panelWidth: 630, //下拉框的宽度
panelHeight: 380,//下拉框的高度
columns:[[
{field:'mBarCode',title:'条码',width:120},
{field:'name',title:'品名',width:140},
{field:'standard',title:'规格',width:80},
{field:'model',title:'型号',width:80},
{field:'unit',title:'单位',width:60},
{field:'stock',title:'库存',width:50},
{field:'expand',title:'扩展信息',width:80}
]],
onBeforeLoad: function(param){
var edDepot = $('#materialData').datagrid('getEditor', {index:editIndex,field:'DepotId'});
if(edDepot) {
param.depotId = $(edDepot.target).combobox('getValue');
}
param.mpList = mPropertyList; //商品属性
},
onSelect:function(rec){
var materialId = $("#depotHeadFM .datagrid-body")
.find("[field='MaterialId']").find(".datagrid-editable-input").val();
if(materialId !=rec.Id) {
materialSelect(rec);
onLoadSuccess: function (rec) {
if(rec && rec.total==1) {
$(".datagrid-body [field='mBarCode']").click(); //在只有单个商品的时候自动选中
}
//分页后判断下是否有选中的数据行combogrid会依据上一次选中的值进行初始化选中datagrid数据行和设置显示值
var edMaterial = $('#materialData').datagrid('getEditor', {index:editIndex,field:'MaterialExtendId'});
var comboText = $(edMaterial.target).next().find('input.combo-text');
$.ajax({
type: "get",
url: '/material/getMaterialByMeId',
data: {
meId: comboText.val(),
mpList: mPropertyList
},
dataType: "json",
success: function (res) {
if (res && res.MaterialName) {
$(edMaterial.target).next().find('input.combo-text').val(res.MaterialName);
}
}
});
},
onSelect:function(index, rowData){
// var materialExtendId = $("#depotHeadFM .datagrid-body")
// .find("[field='MaterialExtendId']").find(".datagrid-editable-input").val();
// if(materialExtendId !=rowData.Id) {
materialSelect(rowData);
// }
}
}
}
}
},
{ title: '库存',field: 'Stock',editor:'validatebox',width:70},
{ title: '库存',field: 'Stock',editor:'validatebox',width:50},
{ title: anotherDepotHeadName, field: 'AnotherDepotId',editor:'validatebox',hidden:isShowAnotherDepot,width:90,
formatter: function (value, row, index) {
return row.AnotherDepotName;
@@ -783,12 +806,7 @@
{ title: '税率(%)',field: 'TaxRate',editor:'validatebox',hidden:isShowTaxColumn,width:75},
{ title: '税额',field: 'TaxMoney',editor:'validatebox',hidden:isShowTaxColumn,width:75},
{ title: '价税合计',field: 'TaxLastMoney',editor:'validatebox',hidden:isShowTaxColumn,width:75},
{ title: '备注',field: 'Remark',editor:'validatebox',width:120},
{ title: '品名-',field: 'OtherField1',editor:'validatebox',hidden:otherColumns,width:60},
{ title: '型号-',field: 'OtherField2',editor:'validatebox',hidden:otherColumns,width:60},
{ title: '颜色-',field: 'OtherField3',editor:'validatebox',hidden:otherColumns,width:60},
{ title: '备注1',field: 'OtherField4',editor:'validatebox',hidden:true,width:60},
{ title: '备注2',field: 'OtherField5',editor:'validatebox',hidden:true,width:60}
{ title: '备注',field: 'Remark',editor:'validatebox',width:100}
]],
toolbar:[
{
@@ -885,54 +903,33 @@
function materialSelect(rec) {
var body,footer,input; //定义表格和文本框
var ratio = 1; //比例-品名专用
var loadRatio = 1; //在单位输入框上面加载比例字段
if(rec) {
var mId = rec.Id;
var meId = rec.Id;
$.ajax({
url: "/material/findById",
url: "/material/findByIdWithBarCode",
type: "get",
dataType: "json",
data: {
id: mId
meId: meId
},
success: function (res) {
if(res && res.code === 200 && res.data && res.data[0]) {
var retailPrice = res.data[0].retailprice-0; //零售价格
var presetPriceOne = res.data[0].presetpriceone-0; //预计采购
var presetPriceTwo = res.data[0].presetpricetwo-0; //批发
var firstInUnit = res.data[0].firstinunit; //首选入库单位
var firstOutUnit = res.data[0].firstoutunit; //首选出库单位
var basicPresetPriceOne = ""; //多单位-入库-基础价格
var basicPresetPriceTwo = ""; //多单位-出库-基础价格
var retailPriceOne = ""; //多单位-入库-零售价格
var otherPresetPriceOne = ""; //多单位-入库-其他价格
var otherPresetPriceTwo = ""; //多单位-出库-其他价格
var retailPriceTwo = ""; //多单位-出库-零售价格
var basicUnit = ""; //基础单位
var otherUnit = ""; //其他单位
if(!res.data[0].unit){
var ps = res.data[0].pricestrategy;
var psObj = JSON.parse(ps);
basicPresetPriceOne = psObj[0].basic.PresetPriceOne-0;
basicPresetPriceTwo = psObj[0].basic.PresetPriceTwo-0;
retailPriceOne = psObj[0].basic.RetailPrice-0;
otherPresetPriceOne = psObj[1].other.PresetPriceOne-0;
otherPresetPriceTwo = psObj[1].other.PresetPriceTwo-0;
retailPriceTwo = psObj[1].other.RetailPrice-0;
basicUnit = psObj[0].basic.Unit;
otherUnit = psObj[1].other.Unit;
}
body =$("#depotHeadFM .datagrid-body");
footer =$("#depotHeadFM .datagrid-footer");
input = ".datagrid-editable-input";
if(res.data[0].unit){ //如果存在计量单位信息
ratio = 1; //重置比例为1
body.find("[field='Unit']").find(input).val(res.data[0].unit); //设置-计量单位信息
body.find("[field='Unit']").find(input).prop("readonly","readonly"); //设置计量单位为只读
body.find("[field='Unit']").find(input).off("click"); //移除点击事件
body.find("[field='Unit']").find(input).attr("data-ratio",ratio); //修改比例缓存信息
}
if(res && res.code === 200) {
var info = res.data;
var commodityDecimal = info.commodityDecimal-0; //零售
var purchaseDecimal = info.purchaseDecimal-0; //采购
var commodityUnit = info.commodityUnit; //商品单位
body =$("#depotHeadFM .datagrid-body");
footer =$("#depotHeadFM .datagrid-footer");
input = ".datagrid-editable-input";
body.find("[field='Unit']").find(input).prop("readonly","readonly"); //设置计量单位为只读
body.find("[field='Unit']").find(input).val(commodityUnit); //设置单位
if(info.unit){ //如果存在计量单位信息
ratio = 1; //重置比例为1
loadRatio = ratio;
}
else {
var unitName = res.data[0].unitName;
var unitName = info.unitName;
if(unitName) {
ratio = unitName.substring(unitName.indexOf(":")+1).replace(")",""); //给比例赋值
unitName = unitName.substring(0, unitName.indexOf("("));
@@ -940,146 +937,29 @@
var unitArr = unitName.split(",");
var basicUnit = unitArr[0]; //基础单位
var otherUnit = unitArr[1]; //副单位
var unitSetInput =""; //单位
body.find("[field='Unit']").find(input).prop("readonly","readonly"); //设置计量单位为只读
var loadRatio = 1; //在单位输入框上面加载比例字段
if(listSubType === "采购" || listSubType === "采购退货" || listSubType === "采购订单"){
unitSetInput = res.data[0].firstinunit; //给单位文本框赋值
if(basicUnit==unitSetInput){ //基础单位等于选择的单位
loadRatio = 1;
}
else if(otherUnit==unitSetInput){ //副单位等于选择的单位
loadRatio = ratio;
}
}
else if(listSubType === "销售" || listSubType === "销售退货" || listSubType === "销售订单" || listSubType === "零售" || listSubType === "零售退货"){
unitSetInput = res.data[0].firstoutunit; //给单位文本框赋值
if(basicUnit==unitSetInput){ //基础单位等于选择的单位
loadRatio = 1;
}
else if(otherUnit==unitSetInput){ //副单位等于选择的单位
loadRatio = ratio;
}
}
body.find("[field='Unit']").find(input).val(unitSetInput).attr("data-ratio", loadRatio); //设置-首选单位
body.find("[field='Unit']").find(input).off("click").on("click",function(){
if(basicUnit && otherUnit) {
var self = this;
//定义模版
var temp = "<div class='unit-list'>";
temp +="<ul>";
temp +="<li data-type='basic' data-ratio='1'>" + basicUnit + "</li>";
temp +="<li data-type='other' data-ratio='" + ratio + "'>" + otherUnit + "</li>";
temp +="</ul>";
temp +="</div>";
if($('.unit-list').length){
$('.unit-list').remove(); //如果存在计量单位列表先移除
}
else {
$(self).after(temp); //加载列表信息
}
//计量单位列表的单击事件
$('.unit-list ul li').off("click").on("click",function(){
var unit = $(this).text();
var thisRatio = $(this).attr("data-ratio"); //获取比例
$(self).val(unit).attr("data-ratio", thisRatio);
$(self).keyup(); //模拟键盘操作
$('.unit-list').remove(); //移除计量单位列表
var stock = body.find("[field='Stock']").find(input).attr("data-stock"); //从缓存中取值
var type = $(this).attr("data-type");
var UnitPrice = 0;
if(type === "basic"){
if(listTitle == "采购订单列表" || listTitle == "采购入库列表" || listTitle == "销售退货列表" || listTitle == "其它入库列表") {
UnitPrice = basicPresetPriceOne;
loadRatio = ratio;
}
else if(listTitle == "销售订单列表" || listTitle == "销售出库列表" || listTitle == "采购退货列表" || listTitle == "其它出库列表" || listTitle == "调拨出库列表") {
UnitPrice = basicPresetPriceTwo;
loadRatio = 1;
}
else if(listTitle == "零售出库列表" || listTitle == "零售退货列表"){
UnitPrice = retailPriceOne;
loadRatio = 1;
}
body.find("[field='Stock']").find(input).val(stock*loadRatio); //修改库存
}
else if(type === "other"){
if(listTitle == "采购订单列表" || listTitle == "采购入库列表" || listTitle == "销售退货列表" || listTitle == "其它入库列表") {
UnitPrice = otherPresetPriceOne;
loadRatio = 1;
}
else if(listTitle == "销售订单列表" || listTitle == "销售出库列表" || listTitle == "采购退货列表" || listTitle == "其它出库列表" || listTitle == "调拨出库列表") {
UnitPrice = otherPresetPriceTwo;
loadRatio = ratio;
}
else if(listTitle == "零售出库列表" || listTitle == "零售退货列表"){
UnitPrice = retailPriceTwo;
loadRatio = ratio;
}
body.find("[field='Stock']").find(input).val((stock/loadRatio).toFixed(2)); //修改库存
}
body.find("[field='UnitPrice']").find(input).val(UnitPrice); //单价
var OperNumber = body.find("[field='OperNumber']").find(input).val(); //获取数量
var taxRate = body.find("[field='TaxRate']").find(input).val(); //获取税率
body.find("[field='TaxUnitPrice']").find(input).val((UnitPrice*(1+taxRate/100)).toFixed(2)); //含税单价
body.find("[field='AllPrice']").find(input).val((UnitPrice*OperNumber).toFixed(2)); //金额
body.find("[field='TaxMoney']").find(input).val((UnitPrice*OperNumber*(taxRate/100)).toFixed(2)); //税额
body.find("[field='TaxLastMoney']").find(input).val((UnitPrice*OperNumber*(1+taxRate/100)).toFixed(2)); //价税合计
statisticsFun(body,UnitPrice,OperNumber,footer,taxRate);
});
//点击空白处移除计量单位列表
$(".datagrid-body").off("click").on("click",function(){
$('.unit-list').remove(); //移除计量单位列表
});
}
});
if(basicUnit==commodityUnit){ //基础单位等于选择的单位
loadRatio = 1;
}
else if(otherUnit==commodityUnit){ //副单位等于选择的单位
loadRatio = ratio;
}
}
var detailPrice = 0; //明细列表-单价
if(listSubType == "零售" || listSubType == "零售退货") {
if(res.data[0].unit) { //如果存在计量单位信息
detailPrice = retailPrice;
}
else {
if (firstOutUnit == basicUnit) {
detailPrice = retailPriceOne;
}
else if (firstOutUnit == otherUnit) {
detailPrice = retailPriceTwo;
}
}
detailPrice = commodityDecimal;
}
else if(listTitle == "采购订单列表" || listTitle == "采购入库列表" || listTitle == "销售退货列表" || listTitle == "其它入库列表") {
if(res.data[0].unit) { //如果存在计量单位信息
detailPrice = presetPriceOne;
}
else {
if (firstInUnit == basicUnit) {
detailPrice = basicPresetPriceOne;
}
else if (firstInUnit == otherUnit) {
detailPrice = otherPresetPriceOne;
}
}
detailPrice = purchaseDecimal;
}
else if(listTitle == "销售订单列表" || listTitle == "销售出库列表" || listTitle == "采购退货列表" || listTitle == "其它出库列表" || listTitle == "调拨出库列表") {
if(res.data[0].unit) { //如果存在计量单位信息
detailPrice = presetPriceTwo;
}
else {
if(firstOutUnit==basicUnit) {
detailPrice = basicPresetPriceTwo;
}
else if(firstOutUnit==otherUnit){
detailPrice = otherPresetPriceTwo;
}
}
}
body.find("[field='OperNumber']").find(input).val(1); //数量初始化为1
//单价和总价赋值
if(!detailPrice) {
detailPrice = 0;
detailPrice = commodityDecimal;
}
//单价和总价赋值
if(!detailPrice) {
detailPrice = 0;
}
var operNumber = 1;
body.find("[field='OperNumber']").find(input).val(operNumber); //数量初始化
body.find("[field='UnitPrice']").find(input).val(detailPrice);
body.find("[field='AllPrice']").find(input).val(detailPrice);
var taxRate = body.find("[field='TaxRate']").find(input).val()-0; //获取税率
@@ -1092,7 +972,7 @@
var depotId = body.find("[field='DepotId']").find(".textbox-value").val();
if(depotId) {
var type = "select"; //type 类型:点击 click选择 select
findStockNumById(depotId, mId, monthTime, body, input, loadRatio, type);
findStockNumById(depotId, meId, monthTime, body, input, loadRatio, type);
}
}
},
@@ -1142,8 +1022,8 @@
columns:[[
{ title: '商品类型',field: 'MType',width:80, hidden:isShowMaterialTypeColumn},
{ title: depotHeadName,field: 'DepotName',editor:'validatebox',width:90},
{ title: '品名(型号)(扩展信息)(单位)',field: 'MaterialName',width:230},
{ title: '库存',field: 'Stock',width:70},
{ title: '条码_品名(规格)(型号)(扩展信息)(单位)',field: 'MaterialName',width:270},
{ title: '库存',field: 'Stock',width:50},
{ title: anotherDepotHeadName,field: 'AnotherDepotName',hidden:isShowAnotherDepot,width:90},
{ title: '单位',field: 'Unit',editor:'validatebox',width:60},
{ title: '数量',field: 'OperNumber',editor:'validatebox',width:60},
@@ -1154,12 +1034,7 @@
{ title: '税率',field: 'TaxRate',editor:'validatebox',hidden:isShowTaxColumn,width:75},
{ title: '税额',field: 'TaxMoney',editor:'validatebox',hidden:isShowTaxColumn,width:75},
{ title: '价税合计',field: 'TaxLastMoney',editor:'validatebox',hidden:isShowTaxColumn,width:75},
{ title: '备注',field: 'Remark',editor:'validatebox',width:120},
{ title: '品名-',field: 'OtherField1',editor:'validatebox',hidden:otherColumns,width:60},
{ title: '型号-',field: 'OtherField2',editor:'validatebox',hidden:otherColumns,width:60},
{ title: '颜色-',field: 'OtherField3',editor:'validatebox',hidden:otherColumns,width:60},
{ title: '备注1',field: 'OtherField4',editor:'validatebox',hidden:true,width:60},
{ title: '备注2',field: 'OtherField5',editor:'validatebox',hidden:true,width:60}
{ title: '备注',field: 'Remark',editor:'validatebox',width:100}
]],
onLoadError:function() {
$.messager.alert('页面加载提示','页面加载异常请稍后再试','error');
@@ -2549,7 +2424,7 @@
var DepotName = $(edDepot.target).combobox('getText');
$('#materialData').datagrid('getRows')[editIndex]['DepotName'] = DepotName;
//商品信息
var edMaterial = $('#materialData').datagrid('getEditor', {index:editIndex,field:'MaterialId'});
var edMaterial = $('#materialData').datagrid('getEditor', {index:editIndex,field:'MaterialExtendId'});
var MaterialName = $(edMaterial.target).combobox('getText');
$('#materialData').datagrid('getRows')[editIndex]['MaterialName'] = MaterialName;
$('#materialData').datagrid('endEdit', editIndex);
@@ -2646,7 +2521,7 @@
}
var totalRowNum = "";
for (var i = 0; i < row.length; i++) {
if (row[i].DepotId == "" || row[i].MaterialId == "" || row[i].OperNumber == "" || row[i].UnitPrice === "" || row[i].AllPrice === "") {
if (row[i].DepotId == "" || row[i].MaterialExtendId == "" || row[i].OperNumber == "" || row[i].UnitPrice === "" || row[i].AllPrice === "") {
totalRowNum += (i + 1) + "";
}
}