diff --git a/TradeManage/HuoWu/HW_GoodsAddForTM.aspx b/TradeManage/HuoWu/HW_GoodsAddForTM.aspx index 451872a..258aede 100644 --- a/TradeManage/HuoWu/HW_GoodsAddForTM.aspx +++ b/TradeManage/HuoWu/HW_GoodsAddForTM.aspx @@ -4852,22 +4852,21 @@ function selectE(p,c) { type="button" value="计算" /> - - - temu成本预估: - - - 进价: - +运费: - +货物税费: - +头程: - =预计价格:0$   - - - + + + temu成本预估: + + 进价: + +运费: + +货物税费: + +头程: + =预计价格:0$   + + + 最大物流数量: + + + + @@ -50,520 +58,89 @@ WindowLoadModel.Load(); ajaxInit(WindowLoadModel); CreateDataGrid(); - $("#txt_trackcode").focus(); - GetShopList(); ReadData(); $(document).keyup(function (event) { - if ($("#txt_trackcode").is(":focus") == true && event.keyCode == 13) { - if ($("#txt_trackcode").val() != "") + if ($("#txt_SKU").is(":focus") == true && event.keyCode == 13) { + if ($("#txt_SKU").val() != "") ReadData(); - - } - }); - //货物详情 - //#region 货物详情 - $(`#${datagrid1.TableID} input[CommandName='showDetail']`).live("click", function () { - $("#img_1").attr("src", $(this).attr("src")); - $("#div_img").empty(); - var RowIndex = $(this).parentsUntil("tr").parent().attr("index"); - showDetailModel = datagrid1.Get_Model(RowIndex); - OpenGoodsMsg(showDetailModel) - - }); - //#endregion - //上架状态选择 - //#region 上架状态选择 - $(`#${datagrid1.TableID} input[CommandName='StartPutaway']`).live("click", function () { - var RowIndex = $(this).parentsUntil("tr").parent().attr("index"); - var model = datagrid1.Get_Model(RowIndex); - id = model.id; - if (model.SecondHandSalePrice == null || model.SecondHandSalePrice == 0) { - $("#txt_SecondHandSalePrice").val((model.order_amount * 0.7).toFixed(2)); - } else { - $("#txt_SecondHandSalePrice").val(model.SecondHandSalePrice); - } - - $("#select_offerup").val(model.IsOfferUp); - $("#select_maketplace").val(model.IsMaketPlace); - - OpenStartPutaway(); - - }); - //#endregion - - //上架状态选择 - //#region 提货信息选择 - $(`#${datagrid1.TableID} input[CommandName='CreateSecongHandBuyerMsg']`).live("click", function () { - var RowIndex = $(this).parentsUntil("tr").parent().attr("index"); - var model = datagrid1.Get_Model(RowIndex); - id = model.id; - $("#txt_buyer_name").val(model.SecondHandBuyerName); - $("#txt_buyer_phone").val(model.SecondHandBuyerPhone); - $("#txt_buyer_time").val(model.SecondHandBuyerTime); - $("#btn_CreateSecongHandBuyerMsg").show(); - OpenSecongHandBuyerMsg(); - }); - $(`#${datagrid1.TableID} input[CommandName='LookSecongHandBuyerMsg']`).live("click", function () { - var RowIndex = $(this).parentsUntil("tr").parent().attr("index"); - var model = datagrid1.Get_Model(RowIndex); - id = model.id; - $("#txt_buyer_name").val(model.SecondHandBuyerName); - $("#txt_buyer_phone").val(model.SecondHandBuyerPhone); - $("#txt_buyer_time").val(model.SecondHandBuyerTime); - $("#btn_CreateSecongHandBuyerMsg").hide(); - OpenSecongHandBuyerMsg(); - }); - $(`#${datagrid1.TableID} input[CommandName='CancelSecongHandBuyerMsg']`).live("click", function () { - var RowIndex = $(this).parentsUntil("tr").parent().attr("index"); - var model = datagrid1.Get_Model(RowIndex); - id = model.id; - - if (window.confirm('确定要撤销吗?') == false) return; - - CancelSecongHandBuyerMsg(); - }); - - //#endregion - $(`#${datagrid1.TableID} input[CommandName='EndBuy']`).live("click", function () { - var RowIndex = $(this).parentsUntil("tr").parent().attr("index"); - var model = datagrid1.Get_Model(RowIndex); - id = model.id; - - if (window.confirm('确定已卖出吗?') == false) return; - UpdateSecondHandType(id, 3) - }); - //生成取件码图片 - $(`#${datagrid1.TableID} input[CommandName='CreateImage']`).live("click", function () { - var RowIndex = $(this).parentsUntil("tr").parent().attr("index"); - var model = datagrid1.Get_Model(RowIndex); - id = model.id; - var product = ''; - var param = new Object(); - param.OrderId = model.orderid; - //获取货物信息 - $.ajax({ - url: "../DD_OrderServiceNew.asmx/GetOrderGoodsListForTMSecond", - data: Sys.Serialization.JavaScriptSerializer.serialize(param), - async: false, - success: function (data) { - GoodsList = data.d; - if (GoodsList != null) { - product = GoodsList[0].GoodsEnglisgName; - } - } - }); - - - let obj = { - trackCode: model.tracking_id, - product: product, - price: model.SecondHandSalePrice == null ? (model.order_amount * 0.7).toFixed(2) : model.SecondHandSalePrice, - date: model.SecondHandBuyerTime, - contactName: model.SecondHandBuyerName, - contactPhone: model.SecondHandBuyerPhone, - address: model.StoreName == 'E' ? '2615 Port Industrial Dr Suite 408, Jacksonville, FL, 32218' :'11190 White Birch Dr Suite 100, Rancho Cucamonga, CA 91730', - } - debugger - downloadQRCodeImg(obj); - }); - - - }); - - //货物详情 - //#region 货物详情 - function OpenGoodsMsg(showDetailModel) { - - var param = new Object(); - param.OrderId = showDetailModel.orderid; - $.fancybox({ - 'width': '70%', - 'height': '100%', - 'autoScale': false, - 'transitionIn': 'elastic', - 'transitionOut': 'elastic', - 'href': '#OrderReturnDetail', - 'afterLoad': function () { - //获取货物信息 - $.ajax({ - url: "../DD_OrderServiceNew.asmx/GetOrderGoodsListForTMSecond", - data: Sys.Serialization.JavaScriptSerializer.serialize(param), - async: false, - success: function (data) { - //WindowLoadModel.Hide(); - GoodsList = data.d; - if (GoodsList != null) { - debugger - var GoodsName = GoodsList[0].GoodsName; - var GoodsSKU = GoodsList[0].GoodsSKU; - var GoodsInfo = GoodsList[0].GoodsInfo; - var shopName = showDetailModel.ShopName; - var productImgUrl = GoodsList[0].LinkUrl; - var GoodsEnglisgName = GoodsList[0].GoodsEnglisgName; - - //$("#txt_Merchantsku").val(showDetailModel.merchant_sku);//txt_GoodsUrl - $("#txt_GoodsCode").val(GoodsSKU); - $("#txt_GoodsName").val(GoodsName); - $("#txt_GoodsDeatil").val(GoodsInfo); - $("#txt_GoodsEnglisgName").val(GoodsEnglisgName); - //$("#txt_GoodsUrl").val(showDetailModel.productImgUrl); - - var link = document.getElementById("txt_GoodsUrl"); - link.href = productImgUrl; - link.text = shopName; - - var newLinkUrlList = GoodsList[0].LinkUrlList; - debugger - var divElement = document.getElementById('div_LinkList'); - divElement.innerHTML = ''; - $(newLinkUrlList).each(t => { - if (t != null) { - $("#div_LinkList").append(`${newLinkUrlList[t].LinkDesc}`); - } - }); - // div_LinkList - } - - - - - } - }); - //图片信息 - //先用列表的 - var imgList = []; - imgList.push(showDetailModel.Img_Url); - imgList.push(showDetailModel.ImgUrl); - showDetailModel.ImgUrl2 != null ? imgList.push(showDetailModel.ImgUrl2) : ''; - showDetailModel.ImgUrl3 != null ? imgList.push(showDetailModel.ImgUrl3) : ''; - showDetailModel.ImgUrl4 != null ? imgList.push(showDetailModel.ImgUrl4) : ''; - showDetailModel.ImgUrl5 != null ? imgList.push(showDetailModel.ImgUrl5) : ''; - - $("#img_1").attr("src",imgList[0]); - $(imgList).each(t => { - if (t != null) { - $("#div_img").append(``); - } - }); - - }, - 'onClosed': function () { - - } - - - - }); - - } - //#endregion - //上架操作 - //#region 上架操作 - //打开上架信息页面 - //#region 打开上架信息页面 - function OpenStartPutaway() { - - $.fancybox({ - 'width': '40%', - 'height': '40%', - 'autoScale': false, - 'transitionIn': 'elastic', - 'transitionOut': 'elastic', - 'href': '#StartPutaway', - 'onComplete': function () { - - } - }); - - } - //#endregion - //保存上架信息 - //#region 保存上架信息 - function SavePutawayMsg() { - if ($("#txt_SecondHandSalePrice").val() == "") { - alert("SecondHandSalePrice is empty"); - return; - } - var param = new Object(); - - param.id = id; - param.SecondHandSalePrice = $("#txt_SecondHandSalePrice").val(); - param.IsOfferUp = $("#select_offerup").val(); - param.IsMaketPlace = $("#select_maketplace").val(); - - $.ajax({ - url: "../DD_OrderServiceNew.asmx/UpdatePutawayMsg", - data: Sys.Serialization.JavaScriptSerializer.serialize(param), - dataType: "json", - success: function (data) { - alert("保存成功"); - $.fancybox.close(); - } - }); - - var secondHandType = 0; - if (param.IsOfferUp == 1 || param.IsMaketPlace == 1) { - secondHandType = 1; - } - UpdateSecondHandType(id, secondHandType) - ReadData(); - } - //#endregion - //#endregion - //提货信息 - //#region 提货信息 - //#region 提货页面 - function OpenSecongHandBuyerMsg() { - - $.fancybox({ - 'width': '40%', - 'height': '40%', - 'autoScale': false, - 'transitionIn': 'elastic', - 'transitionOut': 'elastic', - 'href': '#SecongHandBuyerMsg', - 'onComplete': function () { - - } - }); - - } - //#endregion - //保存提货信息 - //#region 保存提货信息 - function SaveSecongHandBuyerMsg() { - var param = new Object(); - param.id = id; - param.SecondHandBuyerName = $("#txt_buyer_name").val(); - param.SecondHandBuyerPhone = $("#txt_buyer_phone").val(); - param.SecondHandBuyerTime = $("#txt_buyer_time").val(); - param.isSecondHandBuyer = true; - - $.ajax({ - url: "../DD_OrderServiceNew.asmx/UpdateSecondHandBuyer", - data: Sys.Serialization.JavaScriptSerializer.serialize(param), - dataType: "json", - success: function (data) { - alert("保存成功"); - $.fancybox.close(); - UpdateSecondHandType(id, 2); + if ($("#txt_BarCode").is(":focus") == true && event.keyCode == 13) { + if ($("#txt_BarCode").val() != "") + ReadData(); } - }); - - ReadData(); - } - //#endregion - //撤销提货信息 - //#region 撤销提货信息 - function CancelSecongHandBuyerMsg() { - var param = new Object(); - param.id = id; - param.SecondHandBuyerName = ""; - param.SecondHandBuyerPhone = ""; - param.SecondHandBuyerTime = ""; - param.isSecondHandBuyer = false; - - $.ajax({ - url: "../DD_OrderServiceNew.asmx/UpdateSecondHandBuyer", - data: Sys.Serialization.JavaScriptSerializer.serialize(param), - dataType: "json", - success: function (data) { - alert("撤销成功"); - $.fancybox.close(); - UpdateSecondHandType(id, 1); + if ($("#txt_PositionCode").is(":focus") == true && event.keyCode == 13) { + if ($("#txt_PositionCode").val() != "") + ReadData(); } }); - - ReadData(); - } - //#endregion - //#endregion - //通用 更新二手状态 - //#region 更新二手状态 - function UpdateSecondHandType(newId,secondHandType) { - var param = new Object(); - param.id = newId; - param.SecondHandType = secondHandType; - - $.ajax({ - url: "../DD_OrderServiceNew.asmx/UpdateSecondHandType", - data: Sys.Serialization.JavaScriptSerializer.serialize(param), - dataType: "json", - success: function (data) { - - - } + $("#" + datagrid1.TableID + " input[type='checkbox']").live("click", function () { + var num = $("#" + datagrid1.TableID + " input[type='checkbox']:checked").length; + if ($("#" + datagrid1.TableID + "_SelectAll").is(":checked") == true) + num = num - 1; + $("#a_select").html("已选中" + num + "条"); }); + }); - ReadData(); - } - //#endregion // 初始化DataGrid //#region 初始化DataGrid function CreateDataGrid() { - var col = new nblf.ui.DataGridColumn(); - col.HeaderText = "Shop"; - col.CellTemplate = "{Bind ShopName}"; - col.SortExpression = "c.ShopName"; - Array.add(datagrid1.Columns, col); - - col = new nblf.ui.DataGridColumn(); - col.HeaderText = "OrderCode"; - col.CellTemplate = "{Bind ordercode}"; - col.SortExpression = "ordercode"; - Array.add(datagrid1.Columns, col); - col = new nblf.ui.DataGridColumn(); - col.HeaderText = "order_date"; - col.CellTemplate = "{Bind order_date,yyyy-MM-dd HH:mm}"; - col.SortExpression = "order_date"; + col.HeaderText = "Image"; + col.CellTemplate = ""; Array.add(datagrid1.Columns, col); - col = new nblf.ui.DataGridColumn(); + var col = new nblf.ui.DataGridColumn(); col.HeaderText = "SKU"; - col.CellTemplate = "{Bind merchant_sku}"; - Array.add(datagrid1.Columns, col); - - col = new nblf.ui.DataGridColumn(); - col.HeaderText = "return_quantity"; - col.CellTemplate = "{Bind return_quantity}"; - Array.add(datagrid1.Columns, col); - - col = new nblf.ui.DataGridColumn(); - col.HeaderText = "order_amount"; - col.CellTemplate = "{Bind order_amount}"; - Array.add(datagrid1.Columns, col); - - col = new nblf.ui.DataGridColumn(); - col.HeaderText = "refund_amount"; - col.CellTemplate = "{Bind refund_amount}"; - Array.add(datagrid1.Columns, col); - - col = new nblf.ui.DataGridColumn(); - col.HeaderText = "label_cost"; - col.CellTemplate = "{Bind label_cost}"; - Array.add(datagrid1.Columns, col); - - col = new nblf.ui.DataGridColumn(); - col.HeaderText = "tracking_id"; - col.CellTemplate = "{Bind tracking_id} 【{Bind return_carrier}】"; - Array.add(datagrid1.Columns, col); - - col = new nblf.ui.DataGridColumn(); - col.HeaderText = "return_reason_code"; - col.CellTemplate = "
{Bind return_reason_code}
"; - Array.add(datagrid1.Columns, col); - - col = new nblf.ui.DataGridColumn(); - col.HeaderText = "Scan Status"; - col.SortExpression = "ScanState"; - col.CellTemplate = "{Bind ScanState}"; - col.CellFormatter = function (value) { - switch (value) { - case "2": return "First Scan"; - case "1": return "Final Scan"; - default: return "No Scan"; - } - }; - Array.add(datagrid1.Columns, col); - - col = new nblf.ui.DataGridColumn(); - col.HeaderText = "ScanDate"; - col.SortExpression = "ScanDate"; - col.CellTemplate = "{Bind ScanDate,yyyy-MM-dd HH:mm}"; + col.CellTemplate = "{Bind SkuCode}"; + col.SortExpression = "c.SkuCode"; Array.add(datagrid1.Columns, col); - col = new nblf.ui.DataGridColumn(); - col.HeaderText = "Scan Name"; - col.CellTemplate = "{Bind Name}"; - Array.add(datagrid1.Columns, col); - - col = new nblf.ui.DataGridColumn(); - col.HeaderText = "WareHouse"; - col.CellTemplate = "{Bind StoreName}"; - Array.add(datagrid1.Columns, col); - - col = new nblf.ui.DataGridColumn(); - col.HeaderText = "InType"; - col.SortExpression = "InType"; - col.CellTemplate = "{Bind InType}"; - col.CellFormatter = function (value) { - switch (value) { - case "1": return "Restock"; - case "4": return "Sale"; - case "2": return "CTN change"; - case "3": return "Scrap"; - case "5": return "Claim"; - default: return ""; - } - }; - Array.add(datagrid1.Columns, col); - - col = new nblf.ui.DataGridColumn(); - col.HeaderText = "Return PostionCode"; - col.CellTemplate = "{Bind PostionCode}"; - col.SortExpression = "PostionCode"; - Array.add(datagrid1.Columns, col); - - col = new nblf.ui.DataGridColumn(); - col.HeaderText = "Return BarCode"; - col.CellTemplate = "{Bind barcode}"; - col.SortExpression = "barcode"; + var col = new nblf.ui.DataGridColumn(); + col.HeaderText = "BarCode"; + col.CellTemplate = "{Bind BarCode}"; + col.SortExpression = "c.BarCode"; Array.add(datagrid1.Columns, col); - col = new nblf.ui.DataGridColumn(); - col.HeaderText = "Photos"; - col.CellTemplate = ""; + var col = new nblf.ui.DataGridColumn(); + col.HeaderText = "PositionCode"; + col.CellTemplate = "{Bind WarehousePositionCode}"; + col.SortExpression = "c.WarehousePositionCode"; Array.add(datagrid1.Columns, col); col = new nblf.ui.DataGridColumn(); - col.HeaderText = "OfferUp"; - col.CellTemplate = "{Bind IsOfferUp}"; - col.CellFormatter = function (value) { - switch (value) { - case 0: return "No"; - case 1: return "Yes"; - default: return "No"; - } - }; + col.HeaderText = "CreationTime"; + col.CellTemplate = "{Bind CreationTime,yyyy-MM-dd HH:mm}"; + col.SortExpression = "CreationTime"; Array.add(datagrid1.Columns, col); - col = new nblf.ui.DataGridColumn(); - col.HeaderText = "MaketPlace"; - col.CellTemplate = "{Bind IsMaketPlace}"; + var col = new nblf.ui.DataGridColumn(); + col.HeaderText = "IsPrinted"; + col.CellTemplate = "{Bind IsPrinted}"; col.CellFormatter = function (value) { - switch (value) { - case 0: return "No"; - case 1: return "Yes"; - default: return "No"; + if(value){ + return 'Printed' + }else{ + return 'Not Printed' } }; Array.add(datagrid1.Columns, col); - //是否有客户预约信息 - col = new nblf.ui.DataGridColumn(); - col.HeaderText = "SecondHandSalePrice"; - col.CellTemplate = "{Bind SecondHandSalePrice}"; - Array.add(datagrid1.Columns, col); - //操作语句 - var OptionStr = ""; - //是否售卖完毕 - col = new nblf.ui.DataGridColumn(); - col.HeaderText = "SecondHandType"; - col.CellTemplate = "{Bind SecondHandType}"; + var col = new nblf.ui.DataGridColumn(); + col.HeaderText = "Status"; + col.CellTemplate = "{Bind Status}"; col.CellFormatter = function (value) { switch (value) { - case 0: - return "未上架"; case 1: - return "上架中"; + return "未上架"; case 2: + return "已上架"; + case 3: return "等待客户取货"; - case 3: return "完成售卖"; + case 4: + return "完成售卖"; default: - return "未上架"; + return "-"; } }; Array.add(datagrid1.Columns, col); @@ -571,41 +148,32 @@ //操作 col = new nblf.ui.DataGridColumn(); col.HeaderText = "操作"; - col.Width = "300px"; - //col.CellTemplate = " "; - col.CellTemplate = "{Bind SecondHandType}"; - col.CellFormatter = function (value) { - var OptionStr = " "; - switch (value) { - case 0: - OptionStr += " "; - OptionStr += " "; - return OptionStr; - case 1: - OptionStr += " "; - OptionStr += " "; - OptionStr += " "; - return OptionStr; - case 2: - OptionStr += " "; - OptionStr += " "; - OptionStr += " "; - OptionStr += " "; - return OptionStr; - case 3: return OptionStr; - default: - OptionStr += " "; - OptionStr += " "; - return OptionStr; - } - }; - //col.CellTemplate = OptionStr; - //col.CellTemplate += " "; - //col.CellTemplate += " "; - //col.CellTemplate += " "; - //col.CellTemplate += " "; - //col.CellTemplate += " "; - //col.CellTemplate += " "; + col.Width = "200px"; + // col.CellFormatter = function (value) { + // var OptionStr = " "; + // switch (value) { + // case 0: + // OptionStr += " "; + // OptionStr += " "; + // return OptionStr; + // case 1: + // OptionStr += " "; + // OptionStr += " "; + // OptionStr += " "; + // return OptionStr; + // case 2: + // OptionStr += " "; + // OptionStr += " "; + // OptionStr += " "; + // OptionStr += " "; + // return OptionStr; + // case 3: return OptionStr; + // default: + // OptionStr += " "; + // OptionStr += " "; + // return OptionStr; + // } + // }; @@ -621,7 +189,7 @@ datagrid1.AllowPaging2 = true; datagrid1.ShowIndexColumn = true; datagrid1.Width = "100%"; - datagrid1.SelectMode = nblf.ui.SelectMode.None; + datagrid1.SelectMode = nblf.ui.SelectMode.CheckBox; datagrid1.Init(); datagrid1.Sorting(function () { @@ -641,8 +209,8 @@ var Status = $('#select_Status').val() == "-1" ? null : $('#select_Status').val() var param = { - PageIndex: datagrid1.Get_PageSize(), - PageSize: datagrid1.Get_PageIndex(), + PageIndex: datagrid1.Get_PageIndex(), + PageSize: datagrid1.Get_PageSize(), Code: $('#txt_SKU').val() || '', //SKU编码 BarCode: $('#txt_BarCode').val() || '', //条码 WarehousePositionCode: $('#txt_PositionCode').val() || '', //库位编码 @@ -656,8 +224,13 @@ data: Sys.Serialization.JavaScriptSerializer.serialize(param), success: function (data) { WindowLoadModel.Hide(); + data.d.DataSource.forEach(it=>{ + it.ImageUrls = JSON.parse(it.ImageUrls) + it.firstImg = it.ImageUrls && it.ImageUrls.length ? it.ImageUrls[0] : "" + }) datagrid1.Set_RowCount(data.d.RowCount); datagrid1.DataBind(data.d.DataSource); + $("#a_select").html(""); $("a[iul]").each(function () { var iul = $(this).attr("iul"); if (iul == "") @@ -742,35 +315,145 @@ } //#endregion - //选择商店 - //#region 选择商店 - function GetShopList() { - $("#select_shop").empty(); - //if (AllShop == "1") - $("#select_shop").append(""); - var param = new Object(); - param.DeptId = "0"; - param.PlatType = "0"; + //#region 日期格式转换 + function formatDate(date) { + const year = date.getFullYear(); + const month = String(date.getMonth() + 1).padStart(2, '0'); + const day = String(date.getDate()).padStart(2, '0'); + return `${year}-${month}-${day}`; + } + //#endregion + + //#region 批量下载条码图片 + function BatDownloadBarcode() { + var SelectListModels = datagrid1.GetSelectListModel(); + if (SelectListModels == null || $(SelectListModels).length == 0) { + alert("Please check the data first"); + return; + } + var SelectList = SelectListModels.map(it=>{ + return { + ...it, + date: formatDate(it.CreationTime) + } + }) + var printedIds = SelectList.map(it=>it.Id) + var uploadIds = SelectList.filter(it=>it.Status == 1).map(it=>it.Id) + BatChangeIsPrinted(printedIds); + generateAndDownload(SelectList) + BatUploadGoods(uploadIds); + } + //#endregion + + //#region 批量修改打印状态 + function BatChangeIsPrinted(Ids) { + var param = { + Ids: Ids, + } WindowLoadModel.Show(); $.ajax({ - url: "../BaseDataNew.asmx/GetShopListForTM", + url: "../DD_OrderServiceNew.asmx/OrderUsedSalePlatformPrint", data: Sys.Serialization.JavaScriptSerializer.serialize(param), - async: false, + dataType: "json", success: function (data) { WindowLoadModel.Hide(); - - if (data.d != null) { - $(data.d).each(function (i) { - $("#select_shop").append(""); - }); - + if(data.Code==1){ + ReadData(); + }else{ + alert(data.Message); } + } + }); + } + //#endregion + //#region 批量上架产品 + function BatUploadGoods(Ids) { + var param = { + Ids: Ids, + } + $.ajax({ + url: "../DD_OrderServiceNew.asmx/OrderUsedSalePlatformPublish", + data: Sys.Serialization.JavaScriptSerializer.serialize(param), + dataType: "json", + }); + } + //#endregion - } + //#region 生成条码图片并下载ZIP + async function generateAndDownload(data) { + const zip = new JSZip(); + + for (let i = 0; i < data.length; i++) { + const canvas = await generateImage(data[i]); + const imageData = canvas.toDataURL('image/png').split(',')[1]; + zip.file(`image_${i + 1}.png`, imageData, {base64: true}); + + // 显示预览 + const container = document.createElement('div'); + container.className = 'image-container'; + container.appendChild(canvas); + // document.getElementById('preview').appendChild(container); + } + + // 生成并下载ZIP文件 + zip.generateAsync({type: 'blob'}).then(function(content) { + saveAs(content, 'images.zip'); + }); + } + // 生成条码图片 + async function generateImage(item) { + // 创建画布 + const canvas = document.createElement('canvas'); + canvas.width = 900; + canvas.height = 660; + const ctx = canvas.getContext('2d'); + + // 填充白色背景 + ctx.fillStyle = 'white'; + ctx.fillRect(0, 0, canvas.width, canvas.height); + + // 添加SKU + ctx.fillStyle = 'black'; + ctx.font = '48px SimHei'; + ctx.fillText(item.SkuCode, 30, 60); + + // 添加日期,右对齐 + ctx.font = '40px SimHei'; + const dateWidth = ctx.measureText(item.date).width; // 测量文本宽度 + ctx.fillText(item.date, canvas.width - 30 - dateWidth, 60); // 从右边缘减去文本宽度和边距 + + // 生成条形码 + const barcodeCanvas = document.createElement('canvas'); + JsBarcode(barcodeCanvas, item.BarCode, { + format: "CODE128", + width: 6, + height: 300, + displayValue: true, + fontSize: 48, + fontOptions: "bold", + textMargin: 10, + font: "SimHei" }); + + // 将条形码绘制到主画布 + ctx.drawImage(barcodeCanvas, 150, 120); + + // 添加分割线 + ctx.beginPath(); + ctx.moveTo(30, 570); + ctx.lineTo(870, 570); + ctx.strokeStyle = 'black'; + ctx.lineWidth = 3; + ctx.stroke(); + + // 添加提示文字 + ctx.font = '35px Arial'; + ctx.fillText('Notice: This product cannot be returned or exchanged', 30, 630); + + return canvas; } //#endregion @@ -819,6 +502,13 @@ + + + +
+ + +