m0_70156489 17 годин тому
батько
коміт
05404d41a7

+ 113 - 2
application/admin/controller/Procuremen.php

@@ -8170,6 +8170,85 @@ class Procuremen extends Backend
         }
     }
 
+    /**
+     * 月度导出:按列表搜索条件过滤 purchase_order 行(与 procuremenexport 列表一致)
+     *
+     * @param array<int, mixed> $dbRows
+     * @return array<int, array<string, mixed>>
+     */
+    protected function filterMonthOutwardExportDbRowsBySearch(array $dbRows): array
+    {
+        $keyword = trim((string)$this->request->get('search', ''));
+        if ($keyword === '') {
+            $keyword = trim((string)$this->request->request('search', ''));
+        }
+
+        $filter = $this->request->get('filter', '');
+        $op = $this->request->get('op', '');
+        if (is_string($filter) && $filter !== '') {
+            $filterArr = (array)json_decode($filter, true);
+        } else {
+            $filterArr = is_array($filter) ? $filter : [];
+        }
+        if (is_string($op) && $op !== '') {
+            $opArr = (array)json_decode($op, true);
+        } else {
+            $opArr = is_array($op) ? $op : [];
+        }
+
+        if ($keyword === '' && $filterArr === []) {
+            return array_values(array_filter($dbRows, 'is_array'));
+        }
+
+        $searchFields = ['CCYDH', 'CYJMC', 'CGYMC'];
+        $out = [];
+        foreach ($dbRows as $row) {
+            if (!is_array($row)) {
+                continue;
+            }
+            if ($keyword !== '') {
+                $hit = false;
+                foreach ($searchFields as $f) {
+                    if (mb_stripos((string)($row[$f] ?? ''), $keyword) !== false) {
+                        $hit = true;
+                        break;
+                    }
+                }
+                if (!$hit) {
+                    continue;
+                }
+            }
+            $passFilter = true;
+            foreach ($filterArr as $field => $val) {
+                $field = (string)$field;
+                $val = trim((string)$val);
+                if ($field === '' || $val === '') {
+                    continue;
+                }
+                if (!array_key_exists($field, $row) && !in_array($field, $searchFields, true)) {
+                    continue;
+                }
+                $cell = (string)($row[$field] ?? '');
+                $mode = strtoupper((string)($opArr[$field] ?? 'LIKE'));
+                if ($mode === '=' || $mode === 'EQUAL') {
+                    if (strcasecmp($cell, $val) !== 0) {
+                        $passFilter = false;
+                        break;
+                    }
+                } elseif (mb_stripos($cell, $val) === false) {
+                    $passFilter = false;
+                    break;
+                }
+            }
+            if (!$passFilter) {
+                continue;
+            }
+            $out[] = $row;
+        }
+
+        return $out;
+    }
+
     /**
      * 按月份导出:已完结订单(与历史存证、月度列表一致),按完结月份筛选。
      * 表头固定 8 列(与历史「协助明细」模板一致):序号、传票号、传票名称、外加工单位、订法、客户名称、工序、加工金额。
@@ -8210,15 +8289,47 @@ class Procuremen extends Backend
         if ($sidList !== []) {
             $completeTsMap = ProcuremenTime::loadOperLogTimestampMap(array_keys($sidList), ['purchase_confirm', 'mark_complete']);
         }
-        $dbRows = array_values(array_filter($dbRows, function ($dbRow) use ($ym, $completeTsMap) {
+
+        $searchKw = trim((string)$this->request->get('search', ''));
+        if ($searchKw === '') {
+            $searchKw = trim((string)$this->request->request('search', ''));
+        }
+        $filterRaw = $this->request->get('filter', '');
+        $filterArrTmp = [];
+        if (is_string($filterRaw) && $filterRaw !== '') {
+            $filterArrTmp = (array)json_decode($filterRaw, true);
+        } elseif (is_array($filterRaw)) {
+            $filterArrTmp = $filterRaw;
+        }
+        $hasSearch = ($searchKw !== '');
+        if (!$hasSearch) {
+            foreach ($filterArrTmp as $fv) {
+                if (trim((string)$fv) !== '') {
+                    $hasSearch = true;
+                    break;
+                }
+            }
+        }
+
+        // 有搜索时跨月份导出(与列表一致);无搜索时仍按查看月份
+        $dbRows = array_values(array_filter($dbRows, function ($dbRow) use ($ym, $completeTsMap, $hasSearch) {
             if (!is_array($dbRow)) {
                 return false;
             }
             $done = ProcuremenTime::resolveCompletedDone($dbRow, $completeTsMap);
+            if ($done['ts'] <= 0) {
+                return false;
+            }
+            if ($hasSearch) {
+                return true;
+            }
 
-            return $done['ts'] > 0 && date('Y-m', $done['ts']) === $ym;
+            return date('Y-m', $done['ts']) === $ym;
         }));
 
+        // 与列表页一致:按搜索关键字 / 通用搜索过滤
+        $dbRows = $this->filterMonthOutwardExportDbRowsBySearch($dbRows);
+
         $pool = $this->procuremenPoolFromPurchaseOrderDbRows($dbRows);
         $filtered = $pool;
 

+ 50 - 4
application/admin/controller/Procuremenexport.php

@@ -86,10 +86,24 @@ class Procuremenexport extends Backend
                 $ym = date('Y-m');
             }
             try {
-                $rows = $this->buildExportableOrderRows($ym);
+                // 有搜索条件时跨月份查询(用户常不知完结月份)
+                $hasSearch = $this->exportListHasActiveSearch();
+                $rows = $this->buildExportableOrderRows($hasSearch ? '' : $ym);
                 $rows = $this->filterExportableRowsBySearch($rows);
 
-                return json(['total' => count($rows), 'rows' => $rows, 'ym' => $ym]);
+                $total = count($rows);
+                $offset = max(0, (int)$this->request->get('offset', 0));
+                $limit = (int)$this->request->get('limit', 0);
+                if ($limit > 0) {
+                    $rows = array_slice($rows, $offset, $limit);
+                }
+
+                return json([
+                    'total'      => $total,
+                    'rows'       => $rows,
+                    'ym'         => $ym,
+                    'cross_month'=> $hasSearch ? 1 : 0,
+                ]);
             } catch (\Throwable $e) {
                 return json(['total' => 0, 'rows' => [], 'ym' => $ym, 'msg' => $e->getMessage()]);
             }
@@ -98,6 +112,34 @@ class Procuremenexport extends Backend
         return $this->view->fetch();
     }
 
+    /**
+     * 列表是否带有有效搜索(快速搜索或通用搜索)
+     */
+    protected function exportListHasActiveSearch(): bool
+    {
+        $keyword = trim((string)$this->request->request('search', ''));
+        if ($keyword === '') {
+            $keyword = trim((string)$this->request->get('search', ''));
+        }
+        if ($keyword !== '') {
+            return true;
+        }
+
+        $filter = $this->request->get('filter', '');
+        if (is_string($filter) && $filter !== '') {
+            $filterArr = (array)json_decode($filter, true);
+        } else {
+            $filterArr = is_array($filter) ? $filter : [];
+        }
+        foreach ($filterArr as $val) {
+            if (trim((string)$val) !== '') {
+                return true;
+            }
+        }
+
+        return false;
+    }
+
     /**
      * 已完结、可按月份导出的订单(合并为一单一行)
      */
@@ -198,6 +240,7 @@ class Procuremenexport extends Backend
     /**
      * 已完结订单(与历史存证一致),按完结月份筛选后合并为一单一行
      *
+     * @param string $ym 完结月份 Y-m;空字符串表示不限月份(用于跨月搜索)
      * @return array<int, array<string, mixed>>
      */
     protected function buildExportableOrderRows(string $ym): array
@@ -236,8 +279,11 @@ class Procuremenexport extends Backend
                 continue;
             }
             $done = ProcuremenTime::resolveCompletedDone($r, $completeTsMap);
-            $rowYm = $done['ts'] > 0 ? date('Y-m', $done['ts']) : '';
-            if ($rowYm !== $ym) {
+            if ($done['ts'] <= 0) {
+                continue;
+            }
+            $rowYm = date('Y-m', $done['ts']);
+            if ($ym !== '' && $rowYm !== $ym) {
                 continue;
             }
             $sid = (int)($r['scydgy_id'] ?? 0);

+ 1 - 1
application/admin/view/procuremenexport/index.html

@@ -6,7 +6,7 @@
             <div id="toolbar" class="toolbar">
                 <a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}"><i class="fa fa-refresh"></i> 刷新</a>
                 {if $canExportMonthOutward}
-                <a href="javascript:;" class="btn btn-success" id="btn-export-month-outward" title="导出当前所选月份的协助明细 Excel"><i class="fa fa-download"></i> 导出 Excel</a>
+                <a href="javascript:;" class="btn btn-success" id="btn-export-month-outward" title="导出当前列表筛选结果(含搜索)的协助明细 Excel"><i class="fa fa-download"></i> 导出 Excel</a>
                 {/if}
                 <span class="procuremen-export-ym-wrap" style="display:inline-block;margin-left:12px;vertical-align:middle;">
                     <label style="margin:0 6px 0 0;font-weight:normal;">查看月份</label>

+ 1 - 1
application/extra/site.php

@@ -5,7 +5,7 @@ return array (
   'brand_logo' => 'https://a-7in6-com.oss-cn-hangzhou.aliyuncs.com/xinhua/img/logo1.png',
   'beian' => '',
   'cdnurl' => '',
-  'version' => '1.10.10',
+  'version' => '1.10.12',
   'timezone' => 'Asia/Shanghai',
   'forbiddenip' => '',
   'languages' => 

+ 51 - 0
public/assets/js/backend/procuremenexport.js

@@ -46,12 +46,21 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                 pk: 'id',
                 sortName: 'id',
                 sortOrder: 'desc',
+                sidePagination: 'server',
                 pagination: true,
                 pageSize: Config.pagesize || localStorage.getItem('pagesize') || 20,
                 pageList: [10, 15, 20, 25, 50],
                 showJumpto: true,
                 commonSearch: true,
                 search: true,
+                queryParams: function (params) {
+                    var ym = ($('#export-preview-ym').val() || '').trim();
+                    if (!/^\d{4}-\d{2}$/.test(ym)) {
+                        ym = Controller.api.currentYm();
+                    }
+                    params.ym = ym;
+                    return params;
+                },
                 columns: [
                     [
                         {field: 'ym', title: '月份', width: 88, operate: false},
@@ -106,7 +115,49 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                     Toastr.warning('请选择有效月份');
                     return;
                 }
+                var opts = table.bootstrapTable('getOptions') || {};
+                var search = $.trim(opts.searchText || '');
+                if (!search) {
+                    search = $.trim(table.closest('.bootstrap-table').find('.fixed-table-toolbar .search input').val() || '');
+                }
+                var filter = '';
+                var op = '';
+                try {
+                    var $cs = table.closest('.panel-intro').find('form.form-commonsearch');
+                    if ($cs.length) {
+                        var filterObj = {};
+                        var opObj = {};
+                        $cs.find('input[name], select[name]').each(function () {
+                            var $el = $(this);
+                            var name = ($el.attr('name') || '').trim();
+                            if (!name || name === 'search' || name.indexOf('[') >= 0) {
+                                return;
+                            }
+                            var val = $.trim($el.val() || '');
+                            if (val === '') {
+                                return;
+                            }
+                            filterObj[name] = val;
+                            var operate = $el.data('operate') || $el.attr('data-operate') || 'LIKE';
+                            opObj[name] = operate;
+                        });
+                        if (Object.keys(filterObj).length) {
+                            filter = JSON.stringify(filterObj);
+                            op = JSON.stringify(opObj);
+                        }
+                    }
+                } catch (eFilter) {
+                }
                 var url = Fast.api.fixurl('procuremen/export_month_outward?ym=' + encodeURIComponent(ym));
+                if (search) {
+                    url += '&search=' + encodeURIComponent(search);
+                }
+                if (filter) {
+                    url += '&filter=' + encodeURIComponent(filter);
+                }
+                if (op) {
+                    url += '&op=' + encodeURIComponent(op);
+                }
                 window.open(url, '_blank');
             });