|
|
@@ -0,0 +1,193 @@
|
|
|
+$(".batchu9jm").click(function() {
|
|
|
+ var dr = $(this);
|
|
|
+ $("#upload-file").click();
|
|
|
+ $("#upload-file").unbind("change");
|
|
|
+ $("#upload-file").bind("change",function(){
|
|
|
+ excel_parsing(dr);
|
|
|
+ layx.load('loadId','导入中,请稍后',{shadable:0.6});
|
|
|
+ });
|
|
|
+});
|
|
|
+function excel_parsing(dr){
|
|
|
+ var file = document.getElementById("upload-file").files[0];
|
|
|
+ if (!file) return;
|
|
|
+
|
|
|
+ // 显示加载提示
|
|
|
+ //layx.load('loadId', '解析 Excel 中,请稍后', { shadable: 0.6 });
|
|
|
+
|
|
|
+ // 使用 FileReader 读取文件
|
|
|
+ var reader = new FileReader();
|
|
|
+ reader.onload = function(e) {
|
|
|
+ var data = e.target.result;
|
|
|
+ try {
|
|
|
+ // 使用 SheetJS 解析 Excel 为 JSON
|
|
|
+ var workbook = XLSX.read(data, { type: 'array' });
|
|
|
+ var sheetName = workbook.SheetNames[0]; // 取第一个工作表
|
|
|
+ var worksheet = workbook.Sheets[sheetName];
|
|
|
+ var jsonData = XLSX.utils.sheet_to_json(worksheet, { header:1,defval: "" });
|
|
|
+ jsonData.shift(); // 去掉第一行表头
|
|
|
+
|
|
|
+ // 构建要上传的数据(可以包含文件名、sheet名等)
|
|
|
+ // var uploadData = {
|
|
|
+ // fileName: file.name,
|
|
|
+ // sheetName: sheetName,
|
|
|
+ // data: jsonData // 解析后的 JSON 数组
|
|
|
+ // };
|
|
|
+ // 通过 AJAX 上传 JSON 数据
|
|
|
+ document.getElementById("upload-file").files[0] = '';
|
|
|
+ //return console.log(jsonData); // 输出解析后的 JSON 数据
|
|
|
+
|
|
|
+ $.ajax({
|
|
|
+ url: '/fullorderabf/batchhetgood' , // 注意:后端接口可能需要改为接收 JSON
|
|
|
+ type: "POST",
|
|
|
+ contentType: "application/json", // 发送 JSON 格式
|
|
|
+ data:JSON.stringify({
|
|
|
+ list:jsonData
|
|
|
+ }),
|
|
|
+ dataType: "json",
|
|
|
+ success: function(a) {
|
|
|
+ layx.destroy('loadId');
|
|
|
+
|
|
|
+ if(a.hasOwnProperty('list')){
|
|
|
+ addGoodList(a.list)
|
|
|
+ }
|
|
|
+
|
|
|
+ if(a.hasOwnProperty('error_list')){
|
|
|
+ layx.confirm(a.msg,'是否下载错误列表?',null,{
|
|
|
+ buttons:[
|
|
|
+ {
|
|
|
+ label:'确定',
|
|
|
+ callback:function(id, button, event){
|
|
|
+ layx.destroy(id);
|
|
|
+ downloadErrorList(a.error_list)
|
|
|
+ $(".search span").click();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ {
|
|
|
+ label:'取消',
|
|
|
+ callback:function(id, button, event){
|
|
|
+ layx.destroy(id);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ],dialogIcon:'success',shadable:0.6
|
|
|
+ });
|
|
|
+ }else{
|
|
|
+ if(a.success){
|
|
|
+ layx.confirm('消息提示',a.msg,null,{
|
|
|
+ buttons:[
|
|
|
+ {
|
|
|
+ label:'确定',
|
|
|
+ callback:function(id, button, event){
|
|
|
+ layx.destroy(id);
|
|
|
+ $(".search span").click();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ],dialogIcon:'success',shadable:0.6
|
|
|
+ });
|
|
|
+ }else{
|
|
|
+ layx.confirm('错误提示',a.msg,null,{
|
|
|
+ buttons:[
|
|
|
+ {
|
|
|
+ label:'确定',
|
|
|
+ callback:function(id, button, event){
|
|
|
+ layx.destroy(id);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ],dialogIcon:'error',shadable:0.6
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ error: function(xhr, status, error) {
|
|
|
+ layx.destroy('loadId');
|
|
|
+ console.error("上传失败:", error);
|
|
|
+ errorc({ success: false, message: "上传失败" });
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ } catch (err) {
|
|
|
+ layx.destroy('loadId');
|
|
|
+ console.error("解析 Excel 失败:", err);
|
|
|
+ errorc({ success: false, message: "解析 Excel 文件失败" });
|
|
|
+ }
|
|
|
+ };
|
|
|
+ reader.onerror = function() {
|
|
|
+ layx.destroy('loadId');
|
|
|
+ errorc({ success: false, message: "文件读取失败" });
|
|
|
+ };
|
|
|
+ reader.readAsArrayBuffer(file); // 以 ArrayBuffer 读取
|
|
|
+}
|
|
|
+function downloadErrorList(error_list){
|
|
|
+ let sheet = XLSX.utils.json_to_sheet(error_list)
|
|
|
+
|
|
|
+
|
|
|
+ sheet['!cols'] = [
|
|
|
+ //订单号
|
|
|
+ {
|
|
|
+ wch:80,
|
|
|
+ },
|
|
|
+
|
|
|
+ ];
|
|
|
+
|
|
|
+
|
|
|
+ let workbook = XLSX.utils.book_new();
|
|
|
+
|
|
|
+ XLSX.utils.book_append_sheet(workbook, sheet, "Sheet1");
|
|
|
+ XLSX.writeFile(workbook, "错误列表.xlsx");
|
|
|
+}
|
|
|
+
|
|
|
+function addGoodList(list){
|
|
|
+ let str = ''
|
|
|
+ for(let i=0;i<list.length;i++){
|
|
|
+ doAddGoodList(list[i].fpdata,list[i].title,list[i].num,0);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //$(".datatext",window.parent.document).append("<tr data-list='"+f+"'><td>"+e+"</td><td>"+ts+"</td><td class='none'>"+(dj).toFixed(2)+"</td><td class='none'>"+(ts*dj).toFixed(2)+"</td><td class='none'>CNY</td><td class='none'>"+inch.replace("inch","")+"</td><td class='none'>"+(ts*purchasemy).toFixed(2)+"</td><td class='none'>"+(ts*costmy).toFixed(2)+"</td><td class='none'>"+(ts*weight)+"</td><td class='none val9'>0</td><td></td><td><font class='jzzd'>禁止占单</font></td></tr>");
|
|
|
+}
|
|
|
+function doAddGoodList(f,title,ts,weight = 0){
|
|
|
+ var x = 0
|
|
|
+ $(".datatext tr", window.parent.document).each(function() {
|
|
|
+ if ($(this).data("list") == f) {
|
|
|
+ x++;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if (x > 0) {
|
|
|
+ $(".ts p").text("已有相同信息!");
|
|
|
+ $(".ts").show();
|
|
|
+ setTimeout('$(".ts").fadeOut()', 1700);
|
|
|
+ return false;
|
|
|
+ } else {
|
|
|
+ var dj = $(".exp input[name='money']").val() * 1;
|
|
|
+ var purchasemy = $(".exp .purchase").text() * 1;
|
|
|
+ var costmy = $(".exp .cost").text() * 1;
|
|
|
+ var index = $(".cike select").find("option:selected").index();
|
|
|
+ var inch = $(".datalist .checkbox .ckrows input:checked").next("font").text(); //针对单选尺寸,多选需要修改
|
|
|
+
|
|
|
+ //xyxg 删除这个
|
|
|
+
|
|
|
+ if ($("input[name='mdedit']").length > 0) //线下单操作界面
|
|
|
+ {
|
|
|
+ $(".datatext").append("<tr data-list='" + f + "'><td>" + title + "</td><td>" + ts +
|
|
|
+ "</td><td class='none'>" + (dj).toFixed(2) + "</td><td class='none'>" + (ts * dj).toFixed(2) +
|
|
|
+ "</td><td class='none'>CNY</td><td class='none'>" + inch.replace("inch", "") +
|
|
|
+ "</td><td class='none'>" + (ts * purchasemy).toFixed(2) + "</td><td class='none'>" + (ts * costmy)
|
|
|
+ .toFixed(2) + "</td><td class='none'>" + (ts * weight) +
|
|
|
+ "</td><td class='none val9'>0</td><td><font class='jzzd'>禁止占单</font></td></tr>");
|
|
|
+ } else {
|
|
|
+ $(".datatext").append("<tr data-list='" + f + "'><td>" + title + "</td><td>" + ts +
|
|
|
+ "</td><td class='none'>" + (dj).toFixed(2) + "</td><td class='none'>" + (ts * dj).toFixed(2) +
|
|
|
+ "</td><td class='none'>CNY</td><td class='none'>" + inch.replace("inch", "") +
|
|
|
+ "</td><td class='none'>" + (ts * purchasemy).toFixed(2) + "</td><td class='none'>" + (ts * costmy)
|
|
|
+ .toFixed(2) + "</td><td class='none'>" + (ts * weight) +
|
|
|
+ "</td><td class='none val9'>0</td><td></td><td><font class='jzzd'>禁止占单</font></td></tr>");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ //$("input[name='shouldmoney']").val(($("input[name='shouldmoney']").val()*1+(sl*dj)).toFixed(2));//应收价格加上新增价格
|
|
|
+ //et();
|
|
|
+ cost(); //计算成本价
|
|
|
+ window.parent.custom();
|
|
|
+ choicegb();
|
|
|
+ pptskc("a"); //匹配特殊库存
|
|
|
+}
|