lvhao 2 месяцев назад
Родитель
Сommit
7f98d7836e
2 измененных файлов с 132 добавлено и 13 удалено
  1. 70 0
      core/CoreApp/controllers/Whlabel.php
  2. 62 13
      template/erp/whlabel_error.html

+ 70 - 0
core/CoreApp/controllers/Whlabel.php

@@ -202,6 +202,8 @@ class Whlabel extends Start_Controller
 			$this->_whlabelexcelzhjs();
 		}else if($arg == 'dccrtypejs'){
 			$this->_dccrtypejs();
+		}else if($arg == 'errorexceljs'){
+			$this->_errorexceljs();
 		}else if($arg == "w_t_cs"){
 			$this->_w_t_cs(); //首页
 		}else {
@@ -9081,4 +9083,72 @@ class Whlabel extends Start_Controller
 		}
 	}
 
+	public function _errorexceljs()
+	{
+		$post = $this->input->post(NULL, TRUE);
+		if (isset($_GET['page'])) {
+			$page = $this->input->get('page', true);
+			$perpage = $this->input->get('perpage', true);
+			$sku = $this->input->get('sku', true);
+			$warehouse = $this->input->get('warehouse', true);
+			$ktime = $this->input->get('ktime', true);
+			$jtime = $this->input->get('jtime', true);
+			$ktime = strtotime($ktime);
+			$jtime = strtotime($jtime);
+			$where = "sku != 'Preset'";
+			$gj = '';
+			if ($sku) {
+				$where  .= " and sku like '%$sku%'";
+			} else {
+				if ($ktime && $jtime) {
+					$gj  = " and time > '$ktime' and time < '$jtime'";
+				}
+			}
+			if ($warehouse) {
+				$where  .= " and warehouse = '$warehouse'";
+			}
+			//数据排序
+			$order_str = "id desc";
+			if (empty($page)) {
+				$start = 0;
+				$perpage = 1;
+			} else {
+				$start = ($page - 1) * $perpage;
+			}
+			//取得信息列表
+			$rows = array();
+			$list = array();
+			$info_list = $this->whlabel->find_pc($where, 'warehouse,features,sku', '*');
+			foreach ($info_list as $value) {
+				$warehouse = $this->warehouse->read($value['warehouse']);
+				$c = $this->whlabel->find_count('sku = "' . $value['sku'] . '" and state = "0" and warehouse = "' . $value['warehouse'] . '"');
+				$number = $value['number'];
+				$ftime = time() - 15 * 24 * 3600;
+				if ($c < 1) {
+					$list[] = array('warehouse' => $warehouse['title'], 'sku' => $value['sku'], 'title' => $value['title'], 'c' => $c);
+				}
+			}
+
+
+			$title = "0库存汇总";
+
+			$first_row = ["仓库","SKU","产品","当前库存"];
+
+			$cols = [
+				["wch"=>"15"],["wch"=>"30"],["wch"=>"30"],["wch"=>"15"],
+			];
+			$final_list= [];
+			foreach($list as $key => $value){
+				$final_list[] = array_values($value) ;
+			}
+			if(empty($final_list)){
+				exit(json_encode(array('code' => 0, 'msg' => '无符合条件数据')));
+			}
+			array_unshift($final_list, $first_row);
+			
+			$merges = [];
+			exit(json_encode(array('code' => 1,'msg'=>"获取成功",'data'=>['merges'=>$merges, 'data' => $final_list,'title'=>$title,'cols' => $cols])));
+		}
+	}
+
 }

+ 62 - 13
template/erp/whlabel_error.html

@@ -35,19 +35,7 @@ function custom(){
 $(".data tr").each(function() {
 $(this).find('td:eq(3)').css("width","25%");
 });}
-$(".whlabelerror").click(function() {
-	 var f = "";
-    $(".select").each(function() {
-        f = f + $(this).attr("name") + "=" + $(this).children("option:selected").val() + "&";
-    });
-    $("input:text").each(function() {
-        f = f + $(this).attr("name") + "=" + encodeURIComponent($(this).val()) + "&";
-    });
-	$("input:hidden").each(function() {
-        f = f + $(this).attr("name") + "=" + $(this).val() + "&";
-    });
-window.location.href = "/whlabel/errorexcel?excel=1&"+f;
-});
+
 
 $(".whlabeldr0kc").click(function() {
 var dr = $(this);
@@ -91,6 +79,67 @@ success: function(a) {
 </script>
 <script type="text/javascript" src="{$theme}js/time.js"></script>
 <script type="text/javascript" src="{$theme}js/laydate.js"></script>
+<script src="{$theme}js/excel/xlxs.js"></script>
+<script>
+$(".whlabelerror").click(function() {
+	 var f = "";
+    $(".select").each(function() {
+        f = f + $(this).attr("name") + "=" + $(this).children("option:selected").val() + "&";
+    });
+    $("input:text").each(function() {
+        f = f + $(this).attr("name") + "=" + encodeURIComponent($(this).val()) + "&";
+    });
+	$("input:hidden").each(function() {
+        f = f + $(this).attr("name") + "=" + $(this).val() + "&";
+    });
+	let url = "/whlabel/errorexceljs?excel=1&"+f;
+
+	layx.load('loadId','导出中,请稍后',{shadable:0.6});
+    $.get(url,{},function(res){
+        layx.destroy('loadId');
+        if(res.code == 1){
+            importDataNoCol(res.data)
+        }else{
+            layx.alert('错误',res.msg,function(id,button){
+            },{dialogIcon:'error'});
+        }
+    },'json')
+
+});
+
+//导出第一行不含合并单元格的
+function importDataNoCol(data){
+    const fileName = data.title+'.xlsx' ;
+    // 将数据转换为工作表
+
+    // 创建工作表
+    const worksheet = XLSX.utils.aoa_to_sheet(data.data);
+
+    // 定义合并区域
+    const merges = data.merges;
+    worksheet['!cols'] = data.cols;
+
+    // 应用合并
+    worksheet["!merges"] = merges;
+
+    // 设置标题样式(仅在Excel中可见)
+    worksheet.A1.s = {
+            font: { sz: 20, name: "微软雅黑", bold: true },
+            alignment: { horizontal: "center" }
+    };
+    // 创建工作簿
+    const workbook = XLSX.utils.book_new();
+    XLSX.utils.book_append_sheet(workbook, worksheet, data.title);
+    
+    // 导出文件
+    XLSX.writeFile(workbook, fileName);
+    
+    alert('EXCEL已导出为 :'+fileName)
+
+
+    return ;
+}
+</script>
 <div style="display:none;">
 <input id="upload-file" name="files" accept="image/xls,image/xlsx" type="file">
 </div>