//获取上传表格的sheet索引,如果一个Excel表格含有多个工作表,用索引获取对应的工作表,位置从1开始
var sheet = dataOper.getSheetAt(0);
//获取工作表的最后一行
var maxRow = helper.getSheetLastRowNumber(sheet);
maxRow = maxRow - 1;
function setDtls() {
//根据属性返回一行新的订单明细行
function getNewDtl(prdId, prdName, prdSpc, wth, hgt, thk, qty, ut, matId, matName, clr, barCode, rem, kw, wl) {
//针对wth,hgt,thk,qty,四色五入
wth = wth == null || wth == "" ? 0 : Math.round(wth);
hgt = hgt == null || hgt == "" ? 0 : Math.round(hgt);
thk = thk == null || thk == "" ? 0 : Math.round(thk);
var res = {
prdId: prdId,
prdName: prdName,
prdSpc: prdSpc,
wth: wth,
hgt: hgt,
thk: thk,
ut: ut,
qty_q: qty,
matId: matId,
matName: matName,
clr: clr,
barCode: barCode,
rem: rem,
kw: kw,
wl: wl
};
return res;
}
//判断是否数字
function isNumber(val) {
var regPos = /^\d+(\.\d+)?$/; //非负浮点数
var regNeg = /^(-(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*)))$/; //负浮点数
if (regPos.test(val) || regNeg.test(val)) {
return true;
} else {
return false;
}
}
//根据颜色返回材质对象
function getMatClr(matclr) {
var mat = helper.getMatByClr(matclr);
if (mat == null) {
throw "颜色:[" + matclr + "]在系统中尚未建档"
}
return {
matId: mat.matId,
matName: mat.matName,
clr: matclr
}
}
function getMatInfo(matName) {
var mat = helper.getMatInfo(matName);
if (mat == null) {
throw "材质:[" + matName + "]在系统中尚未建档"
}
}
//根据造型返回产品对象
function getPrdtBySpc(prdSpc) {
var prdt = helper.getPrdInfoByPrdSpc(prdSpc);
if (prdt == null) {
throw "产品型号:[" + prdSpc + "]在系统中不存在";
}
return prdt;
}
//设置门板的其他属性
function setMbOtherProps(dtl, prdt, mpBean, zh, kongpost) {
dtl.mpId = mpBean.mpId;
dtl.bxName = prdt.dxRem;
//中横位置或拆解比例,判断zh是数字类型,还是字符类型
if (isNumber(zh)) {
zh = 60 + parseInt(zh);
helper.setDtlBeanParam(dtl, "中横位置", zh);
} else if (zh != "" && zh != null) {
helper.setDtlBeanParam(dtl, "拆解比例", zh);
}
//孔位参数的设置;
if (kongpost != null && kongpost != "") {
var konglist = kongpost.split("/");
if (konglist.length != 5) {
throw "孔位" + kongpost + "应该有5个值";
}
if (konglist[0] != null && konglist[0] != "" && konglist[0] != 0) {
helper.setDtlBeanParam(dtl, "V1", konglist[0]);
}
if (konglist[1] != null && konglist[1] != "" && konglist[1] != 0) {
helper.setDtlBeanParam(dtl, "V2", konglist[1]);
}
if (konglist[2] != null && konglist[2] != "" && konglist[2] != 0) {
helper.setDtlBeanParam(dtl, "V3", konglist[2]);
}
if (konglist[3] != null && konglist[3] != "" && konglist[3] != 0) {
helper.setDtlBeanParam(dtl, "V4", konglist[3]);
}
if (konglist[4] != null && konglist[4] != "" && konglist[4] != 0) {
helper.setDtlBeanParam(dtl, "V5", konglist[4]);
}
}
}
//根据行号返回读取excel行的数据,并返回订单明细行对象
function getDtlBean(i) {
//产品名称
var ePrdName = helper.getSheetVal(sheet, i, 2);
//产品型号
var ePrdSpc = helper.getSheetVal(sheet, i, 4);
//宽
var wth = helper.getSheetVal(sheet, i, 5);
//高
var hgt = helper.getSheetVal(sheet, i, 6);
//厚
var thk = helper.getSheetVal(sheet, i, 7);
//块
var qty = helper.getSheetVal(sheet, i, 8);
//材质颜色纹理
var matName = helper.getSheetVal(sheet, i, 9);
var clrName = helper.getSheetVal(sheet, i, 10);
var wl = helper.getSheetVal(sheet, i, 12);
var 基材 = helper.getSheetVal(sheet, i, 13);
//条码号
var barCode = helper.getSheetVal(sheet, i, 14);
//特殊说明
var rem = helper.getSheetVal(sheet, i, 15);
//特殊工艺
var gyNames= helper.getSheetVal(sheet, i, 16);
//开门方向
var kw = helper.getSheetVal(sheet, i, 17);
//孔位
var kwpost = helper.getSheetVal(sheet, i, 18);
//中横位置
var zh = helper.getSheetVal(sheet, i, 19);
//产品对象
var 产品对象 = null;
//门片对象
var 门片对象 = null;
//如果型号中含有下划线_
if (ePrdSpc.indexOf("_") > -1) {
var 产品型号 = ePrdSpc.split("_")[0];
产品对象 = getPrdtBySpc(产品型号);
//设置门片的对象
var 门片型号 = ePrdSpc.split("_")[1];
门片对象 = helper.getMpInfoBySpc(门片型号);
} else {
产品对象 = getPrdtBySpc(ePrdSpc);
}
//根据面材获取材质对象
var 材质对象 = getMatInfo(matName);
//传入属性值,返回一个订单行对象
var dtl = getNewDtl(产品对象.prdId, prdName, 产品对象.prdSpc, wth, hgt, thk, qty, 产品对象.prdUt, 材质对象.matId, 材质对象.matName, clrName, barCode, rem, kw, wl);
//门板的其他属性设置
if (产品对象.prdType == 0) {
setMbOtherProps(dtl, 产品对象, 门片对象, zh, kwpost,gyNames);
//对主门型进行计数,分类定义为0,用于最后写订单表头信息的主门型
helper.setObjectCount(0, 产品对象);
}
//特殊工艺的设置
if(gyNames!=null && gyNames!=""){
gyNames=gyNames.replace(/;/,"/");
var gybean=helper.getGyObject(产品对象.prdId,gyNames);
dtl.gyId=gybean.gyId;
helper.setDtlGyName(dtl,gybean.gyName);
}
//产品基材参数
helper.setDtlBeanParam(dtl, "板材", 基材);
//为材质使用进行计数,分类定义为1,以设定表头的材质
helper.setObjectCount(1, 材质对象);
//表头的颜色计数
helper.setObjectCount(2, clrName);
//表头参数,板材的计数
helper.setObjectCount(3, 基材);
return dtl;
}
//过程的入口;从表格的第5行开始循环
for (var i = 5; i <= maxRow; i++) {
try {
//传入行数,返回一个订单明细行对象;
var bean = getDtlBean(i);
//将这个对象插入到系统内置结果数组"订单明细中"
订单明细.push(bean);
} catch (e) {
throw "在导入行:[" + (i) + "]是发生错误," + e;
}
}
}
//execl订单明细行的处理
setDtls();
function setMainInfo() {
var cusName = "成都伊恋";
//根据客户名称,返回客户信息对象;
var cust = helper.getCustByName(cusName);
if (cust == null) {
throw "客户名称:[" + cusName + "]在系统中未建档";
}
//订单主表为系统内置结果对象,需要对其赋值;
//客户的Id
订单主表.cusId = cust.cusId;
var cusrName = helper.getSheetVal(sheet, 2, 8);
var cusrF = helper.getSheetVal(sheet, 2, 3);
cusrName = cusrName + " [" + (cusrF == null ? "" : cusrF) + "]";
var cusrOrderNo = helper.getSheetVal(sheet, 2, 11);
var cusrGtName = helper.getSheetVal(sheet, 3, 3);
var cusrPrd = (cusrOrderNo == null ? "" : cusrOrderNo) + " " + (cusrGtName == null ? "" : cusrGtName);
//终端用户;
订单主表.cusrName = cusrName;
//空间区域
订单主表.cusrPrd = cusrPrd;
//终端客户+空间区域需要连接后给"cusrRem";
订单主表.cusrRem = cusrName + " " + cusrPrd;
//获取主门型的最大计数项;
var prdt = helper.getMaxObjectCount(0);
if (prdt != null) {
//主门型的ID
订单主表.mxId = prdt.prdId;
//主门型的原始型号
订单主表.mxfName = prdt.prdSpc;
//主门型的最后呈现型号;
订单主表.mxName = prdt.prdSpc;
//订单主表的边型
订单主表.bxName = prdt.dxRem;
}
//获取材质的最大计数项;
var mat = helper.getMaxObjectCount(1);
if (mat != null) {
//材质的ID;
订单主表.matId = mat.matId;
//材质名称
订单主表.maName = mat.maName;
//材质颜色;
订单主表.clrName = mat.clr;
}
//设定订单主表的附加参数;客户编号;
helper.setMainBeanParam(订单主表, "客户编号", cusrOrderNo);
}
//订单表头的处理
setMainInfo();
console