|
|
@@ -25,7 +25,7 @@
|
|
|
<div class="control">
|
|
|
<a href="javascript:void(0);" class="datalistwc">批量完成</a>
|
|
|
<a href="javascript:void(0);" class="whlabeltransportmb">导出模板</a>
|
|
|
-<a href="javascript:void(0);" class="whlabeldr">导入在途数据</a>
|
|
|
+<a href="javascript:void(0);" class="whlabeldr_erp">导入在途数据</a>
|
|
|
<a href="javascript:void(0);" class="whlabeltransportexcel">导出在途数据</a>
|
|
|
<a href="javascript:void(0);" class="whlabeltransportexcelzh">导出在途中及库存数据</a>
|
|
|
<a href="javascript:void(0);" class="check">删 除</a>
|
|
|
@@ -154,6 +154,106 @@ $(".datatext").on('click',"td .ztwc",function() {
|
|
|
|
|
|
});
|
|
|
</script>
|
|
|
+<script>
|
|
|
+ $(".whlabeldr_erp").on('click',function(){
|
|
|
+ var me = $(this);
|
|
|
+ $("#upload-file").click();
|
|
|
+ $("#upload-file").unbind("change");
|
|
|
+ $("#upload-file").bind("change",function(){
|
|
|
+ whlabeldr_two(me);
|
|
|
+ layx.load('loadId','导入中,请稍后',{shadable:0.6});
|
|
|
+ });
|
|
|
+ })
|
|
|
+
|
|
|
+ let excel_data = [];
|
|
|
+ function whlabeldr_two(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(); // 去掉第一行表头
|
|
|
+ // console.log(jsonData)
|
|
|
+ excel_data = jsonData;
|
|
|
+ // 构建要上传的数据(可以包含文件名、sheet名等)
|
|
|
+ // var uploadData = {
|
|
|
+ // fileName: file.name,
|
|
|
+ // sheetName: sheetName,
|
|
|
+ // data: jsonData // 解析后的 JSON 数组
|
|
|
+ // };
|
|
|
+ // 通过 AJAX 上传 JSON 数据
|
|
|
+ document.getElementById("upload-file").files[0] = '';
|
|
|
+ if(excel_data.length>100){
|
|
|
+ layx.destroy('loadId');
|
|
|
+ errorc({ success: false, msg: "一次最多只能上传100条数据" });
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ save_transfer_data();
|
|
|
+ } catch (err) {
|
|
|
+ layx.destroy('loadId');
|
|
|
+ console.error("解析 Excel 失败:", err);
|
|
|
+ errorc({ success: false, msg: "解析 Excel 文件失败" });
|
|
|
+ }
|
|
|
+ };
|
|
|
+ reader.onerror = function() {
|
|
|
+ layx.destroy('loadId');
|
|
|
+ errorc({ success: false, msg: "文件读取失败" });
|
|
|
+ };
|
|
|
+ reader.readAsArrayBuffer(file); // 以 ArrayBuffer 读取
|
|
|
+ }
|
|
|
+ function save_transfer_data(){
|
|
|
+ $.post("/whlabeltransport/add/", { data: JSON.stringify(excel_data) }, function(res) {
|
|
|
+ layx.destroy('loadId');
|
|
|
+ console.log(res)
|
|
|
+ if(res.code == 1){
|
|
|
+ errora({ success: true, msg: res.msg });
|
|
|
+ }else{
|
|
|
+
|
|
|
+ layx.confirm('错误提示',res.msg,null,{
|
|
|
+ buttons:[
|
|
|
+ {
|
|
|
+ label:'确定',
|
|
|
+ callback:function(id, button, event){
|
|
|
+ download_excel(res.data.error,res.data.filename);
|
|
|
+ layx.destroy(id);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ],dialogIcon:'warn',shadable:0.6
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ },'json');
|
|
|
+ }
|
|
|
+
|
|
|
+ function download_excel(data,filename){
|
|
|
+ let sheet = XLSX.utils.json_to_sheet(data)
|
|
|
+ sheet['!cols'] = [
|
|
|
+ //订单号
|
|
|
+ {
|
|
|
+ wch:60,
|
|
|
+ },
|
|
|
+ ];
|
|
|
+ let workbook = XLSX.utils.book_new();
|
|
|
+ XLSX.utils.book_append_sheet(workbook, sheet, "Sheet1");
|
|
|
+ XLSX.writeFile(workbook, filename);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+</script>
|
|
|
+<script type="text/javascript" src="{$theme}js/excel/xlxswidth.js" ></script>
|
|
|
<script type="text/javascript" src="{$theme}js/laydate.js"></script>
|
|
|
<div style="display:none;">
|
|
|
<input id="upload-file" name="files" accept="image/xls,image/xlsx" type="file">
|