Browse Source

产品配置搜索优化, 分页优化

曹鹤洋 1 year ago
parent
commit
d4f8e91b45

+ 3 - 12
application/admin/controller/QcodeBach.php

@@ -88,10 +88,7 @@ class QcodeBach extends Backend
                 $where[$k] = new \MongoDB\BSON\Regex($v);
             }
 
-            $total = $this->model->name($company_id.'_'."qcode_bach")->where($where)
-                ->order($sort,$order)
-                ->skip($offset)
-                ->select();
+            $total = $this->model->name($company_id.'_'."qcode_bach")->where($where)->select();
             $list = $this->model->name($company_id.'_'."qcode_bach")->where($where)
                 ->order($sort,$order)
                 ->limit($limit)
@@ -150,10 +147,7 @@ class QcodeBach extends Backend
             }
 
             $db = new QcodeLarge();
-            $total = $db->name($company_id.'_'."qcode_large")->where($where)
-                ->order($sort,$order)
-                ->skip($offset)
-                ->select();
+            $total = $db->name($company_id.'_'."qcode_large")->where($where)->select();
             $list = $db->name($company_id.'_'."qcode_large")->where($where)
                 ->order($sort,$order)
                 ->limit($limit)
@@ -216,10 +210,7 @@ class QcodeBach extends Backend
             }
 
             $qcodeSmall = new QcodeSmall();
-            $total = $qcodeSmall->name($company_id.'_'."qcode_small")->where($where)
-                ->order($sort,$order)
-                ->skip($offset)
-                ->select();
+            $total = $qcodeSmall->name($company_id.'_'."qcode_small")->where($where)->select();
             $list = $qcodeSmall->name($company_id.'_'."qcode_small")->where($where)
                 ->order($sort,$order)
                 ->limit($limit)

+ 9 - 9
application/admin/controller/QcodeProduct.php

@@ -2,6 +2,7 @@
 
 namespace app\admin\controller;
 
+use app\admin\model\QcodeClassification;
 use app\admin\model\QcodeCompany;
 use app\common\controller\Backend;
 use \think\Session;
@@ -24,6 +25,10 @@ class QcodeProduct extends Backend
     {
         parent::_initialize();
         $this->model = new \app\admin\model\QcodeProduct();
+        $qcodeClassification = new QcodeClassification();
+        $codeList = $qcodeClassification->where(['status'=>1,'delete_time'=>''])->select();
+        $this->view->assign("codeList", $codeList);
+
     }
 
 
@@ -114,13 +119,11 @@ class QcodeProduct extends Backend
 //            $filter = ['field' => $regex];
 
             $filter = json_decode($req['filter'], true);
+
             foreach ($filter as $k => $v){
                 $where[$k] = new \MongoDB\BSON\Regex($v);
             }
-            $total = $this->model->where($where)
-                ->order($sort,$order)
-                ->skip($offset)
-                ->select();
+            $total = $this->model->where($where)->select();
             $list = $this->model->where($where)
                 ->order($sort,$order)
                 ->limit($limit)
@@ -131,6 +134,7 @@ class QcodeProduct extends Backend
                 $list[$k]['id'] = $oid['$oid'];
             }
 
+
             $result = array("total" => count($total), "rows" => $list);
 
             return json($result);
@@ -180,11 +184,7 @@ class QcodeProduct extends Backend
                 ->column('product_id');
             $rows = array_values($rows);
 
-            $total = $this->model->where($where)
-                ->where('_id','in',$rows)
-                ->order($sort,$order)
-                ->skip($offset)
-                ->select();
+            $total = $this->model->where($where)->where('_id','in',$rows)->select();
 
             $list = $this->model->where($where)
                 ->where('_id','in',$rows)

+ 45 - 0
application/admin/model/QcodeClassification.php

@@ -0,0 +1,45 @@
+<?php
+namespace app\admin\model;
+
+use think\Model;
+use think\Log;
+use traits\model\SoftDelete;
+class QcodeClassification extends Model
+{
+    protected $connection = 'mongodb';
+    protected $table = 'qcode_classification';
+    protected $deleteTime = 'delete_time';
+
+    use SoftDelete;
+
+    public function createIndex()
+    {
+        $this->connection->command([
+            'createIndexes' => $this->table,
+            'indexes' => [
+                [
+                    'key' => ['pid' => 1],
+                    'name' => 'pid_index'
+                ]
+            ]
+        ]);
+    }
+    protected static function init()
+    {
+
+        //把当前表加入到监听队列
+        Redis_sAdd('watch_tables', "qcode_classification");
+        self::beforeWrite(function ($model) {
+            if (!isset($model->delete_time)){
+                $model->delete_time="";
+            }
+
+            $model->sync_flag=0;
+        });
+
+//        $model->sync_flag=1;
+
+
+    }
+
+}

+ 62 - 2
application/admin/view/qcode_product/index.html

@@ -1,4 +1,4 @@
-<div class="row">
+
     <div class="panel panel-default panel-intro">
         <div class="panel-body">
             <div id="1" class="tab-content">
@@ -23,6 +23,66 @@
             </div>
         </div>
     </div>
+    <script id="customformtpl" type="text/html">
+        <!--form表单必须添加form-commsearch这个类-->
+        <form action="" class="form-commonsearch">
+            <div style="border-radius:2px;margin-bottom:10px;background:#f5f5f5;padding:15px 20px;">
+                <div class="row">
+                    <div class="col-xs-12 col-sm-6 col-md-3">
+                        <div class="form-group">
+                            <label class="control-label">编号</label>
+                            <!--隐式的operate操作符,必须携带一个class为operate隐藏的文本框,且它的data-name="字段",值为操作符-->
+                            <input class="operate" type="hidden" data-name="product_code" value="LIKE"/>
+                            <div>
+                                <input class="form-control" type="text" name="product_code" placeholder="请输入查找的编号" value=""/>
+                            </div>
+                        </div>
+                    </div>
+                    <div class="col-xs-12 col-sm-6 col-md-3">
+                        <div class="form-group">
+                            <label class="control-label">名称</label>
+                            <!--隐式的operate操作符,必须携带一个class为operate隐藏的文本框,且它的data-name="字段",值为操作符-->
+                            <input class="operate" type="hidden" data-name="product_name" value="LIKE"/>
+                            <div>
+                                <input class="form-control" type="text" name="product_name" placeholder="请输入查找的名称" value=""/>
+                            </div>
+                        </div>
+                    </div>
+                    <div class="col-xs-12 col-sm-6 col-md-3" style="min-height:68px;">
+                        <!--这里添加68px是为了避免刷新时出现元素错位闪屏-->
+                        <div class="form-group">
+                            <label class="control-label">存货分类编码</label>
+                            <input type="hidden" class="operate" data-name="code" value="LIKE"/>
+                            <div>
+                                <!--给select一个固定的高度-->
+                                <!--@formatter:off-->
+                                <select id="c-flag" class="form-control selectpicker" name="code" style="height:31px;">
+                                    <option value="" >请选择</option>
+                                    {foreach name="codeList" item="vo"}
+                                    <option value="{$vo.code}" >{$vo.code}-{$vo.name}</option>
+                                    {/foreach}
+                                </select>
+                                <!--@formatter:on-->
+                            </div>
+                        </div>
+                    </div>
+                    <div class="col-xs-12 col-sm-6 col-md-3">
+                        <div class="form-group">
+                            <label class="control-label"></label>
+                            <div class="row">
+                                <div class="col-xs-6">
+                                    <input type="submit" class="btn btn-success btn-block" value="提交"/>
+                                </div>
+                                <div class="col-xs-6">
+                                    <input type="reset" class="btn btn-primary btn-block" value="重置"/>
+                                </div>
+                            </div>
+                        </div>
+                    </div>
+                </div>
+            </div>
+        </form>
+    </script>
     <div class="panel panel-default panel-intro">
         <div class="panel-body">
             <div id="myTabContent2" class="tab-content">
@@ -46,4 +106,4 @@
             </div>
         </div>
     </div>
-</div>
+

+ 13 - 8
public/assets/js/backend/qcode_product.js

@@ -79,19 +79,23 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                     toolbar: '#toolbar1',
                     pk: 'id',
                     sortName: 'id',
+                    sortOrder: 'asc',
                     pageSize: 8,
                     pageList: [8, 20, 50, 'All'],
                     search: false,
                     singleSelect: true,
+                    searchFormVisible: true,
+                    searchFormTemplate: 'customformtpl',
                     columns: [
                         [
                             {checkbox: true},
                             {field: 'product_code', title: __('Product_code'), operate: 'LIKE'},
                             {field: 'product_name', title: __('Product_name'), operate: 'LIKE'},
-                            {field: 'temple', title: __('Temple'), operate: 'LIKE'},
-                            {field: 'main_unit', title: __('Main_unit'), operate: 'LIKE'},
-                            {field: 'sec_unit', title: __('Sec_unit'), operate: 'LIKE'},
-                            {field: 'proportion', title: __('Proportion'), operate: 'LIKE'},
+                            {field: 'temple', title: __('Temple')},
+                            {field: 'main_unit', title: __('Main_unit')},
+                            {field: 'sec_unit', title: __('Sec_unit')},
+                            {field: 'proportion', title: __('Proportion')},
+                            {field: 'code', title: __('存货分类编码'), visible:false},
                             // {field: 'notes', title: __('Notes')},
                             // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                         ]
@@ -117,6 +121,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                     toolbar: '#toolbar2',
                     pk: 'id',
                     sortName: 'id',
+                    sortOrder: 'asc',
                     pageSize: 8,
                     pageList: [8, 20, 50, 'All'],
                     search: false,
@@ -126,10 +131,10 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                             {checkbox: true},
                             {field: 'product_code', title: __('Product_code'), operate: 'LIKE'},
                             {field: 'product_name', title: __('Product_name'), operate: 'LIKE'},
-                            {field: 'temple', title: __('Temple'), operate: 'LIKE'},
-                            {field: 'main_unit', title: __('Main_unit'), operate: 'LIKE'},
-                            {field: 'sec_unit', title: __('Sec_unit'), operate: 'LIKE'},
-                            {field: 'proportion', title: __('Proportion'), operate: 'LIKE'},
+                            {field: 'temple', title: __('Temple'), operate: false},
+                            {field: 'main_unit', title: __('Main_unit'), operate: false},
+                            {field: 'sec_unit', title: __('Sec_unit'), operate: false},
+                            {field: 'proportion', title: __('Proportion'), operate: false},
                             // {field: 'notes', title: __('Notes')},
                             // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                         ]