From bf4d2cf9eeea8ebc24952d522910296a9aeefd65 Mon Sep 17 00:00:00 2001 From: hant Date: Fri, 14 Mar 2025 18:22:34 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B4=BE=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/controller/orders/Dispatch.php | 30 ++++--- .../admin/controller/workers/Worker.php | 25 +++++- application/admin/model/Item.php | 26 +++++++ .../admin/view/orders/dispatch/add.html | 78 ++++++++++++++----- public/assets/js/backend/orders/dispatch.js | 52 ++++++++++--- public/assets/js/require-table.js | 3 +- .../dist/css/city-picker.css | 10 +++ .../dist/js/city-picker.js | 2 +- .../fastadmin-citypicker/src/city-picker.js | 2 +- 9 files changed, 183 insertions(+), 45 deletions(-) diff --git a/application/admin/controller/orders/Dispatch.php b/application/admin/controller/orders/Dispatch.php index c1a6bb6..5ae710e 100644 --- a/application/admin/controller/orders/Dispatch.php +++ b/application/admin/controller/orders/Dispatch.php @@ -100,19 +100,31 @@ class Dispatch extends Backend if (!$order) { $this->error(__('No results were found')); } - $code = $this->getSelectAreaCode(substr_replace($order->area_id, '00', -2)); - $workers = model('worker') - ->where('area_id','like', $code.'%') - ->where('status',1) - ->field(['id','name','tel','area_id','lng','lat']) - ->select(); + $items = Db::name('item') + ->where('status',1) + ->field(['id','title','key_word','pid']) + ->order('pid','asc') + ->order('sort','desc') + ->select(); + $filtered = array_filter($items, function($item) { + return $item['pid'] == 0; + }); + + $pid_map = array_column($filtered,null,'id'); + $res_items = []; + foreach ($items as $item){ + if ($item['pid'] != 0 && isset($pid_map[$item['pid']])){ + $res_items [] = [ + ...$item,'ptitle' => $pid_map[$item['pid']]['title'] + ]; + } + } + $area_name = model('area')->getNameByCode($order->area_id); $order->area_name = str_replace(',','/',$area_name); - - $workers = $this->getWorkers($workers); - $this->view->assign('workers', $workers); + $this->view->assign('items', $res_items); $this->view->assign('row', $order); return $this->view->fetch(); diff --git a/application/admin/controller/workers/Worker.php b/application/admin/controller/workers/Worker.php index 6805edc..01986c3 100644 --- a/application/admin/controller/workers/Worker.php +++ b/application/admin/controller/workers/Worker.php @@ -190,7 +190,7 @@ class Worker extends Backend ]; } model('WorkerItem')->where('worker_id',$ids)->delete(); - model('WorkerItem')->batchInsert($insert); + model('WorkerItem')->insertAll($insert); } } unset($params['rules']); @@ -220,4 +220,27 @@ class Worker extends Backend return $this->fetch(); } + public function dispatchList(){ + + $area_id = request()->get('area_id'); + list($where, $sort, $order, $offset, $limit) = $this->buildparams(); + + $build = model('worker') + ->where('status',1) + ->with(['area']) + ->field(['id','name','tel','area_id','lng','lat']); + + if ($area_id){ + $code = $this->getSelectAreaCode(substr_replace($area_id, '00', -2)); + $build->where('area_id','like', $code.'%'); + } + $list = $build + ->paginate($limit); + + $result = array("total" => $list->total(), "rows" => $list->items()); + + return json($result); + + } + } diff --git a/application/admin/model/Item.php b/application/admin/model/Item.php index 351e58c..f46706f 100644 --- a/application/admin/model/Item.php +++ b/application/admin/model/Item.php @@ -2,6 +2,7 @@ namespace app\admin\model; +use think\Db; use think\Model; @@ -50,6 +51,31 @@ class Item extends Model } + public function getList(){ + $items = $this + ->where('status',1) + ->field(['id','title','key_word','pid']) + ->order('pid','asc') + ->order('sort','desc') + ->select(); + + + $this->items = $items; + $filtered = array_filter($items, function($item) { + return $item['pid'] == 0; + }); + + $pid_map = array_column($filtered,null,'id'); + $res_items = []; + foreach ($items as $item){ + if ($item['pid'] != 0 && isset($pid_map[$item['pid']])){ + $res_items [] = [ + ...$item,'ptitle' => $pid_map[$item['pid']]['title'] + ]; + } + } + return $res_items; + } } diff --git a/application/admin/view/orders/dispatch/add.html b/application/admin/view/orders/dispatch/add.html index 1a87ae1..f1d8efd 100644 --- a/application/admin/view/orders/dispatch/add.html +++ b/application/admin/view/orders/dispatch/add.html @@ -24,10 +24,15 @@
- + +
+
+
+ +
+
-
@@ -45,20 +50,14 @@
- +
-
- +
- + +
@@ -84,18 +83,37 @@
-
+

师傅选择

-
-
- -
- + + +
+ +
+ +
-

重置

+
+ +
+ +
+
+
+ +
+ +
+
+

搜索

+

清空

-
@@ -106,4 +124,22 @@
-
\ No newline at end of file +
+ \ No newline at end of file diff --git a/public/assets/js/backend/orders/dispatch.js b/public/assets/js/backend/orders/dispatch.js index 0aa2486..4c3fb48 100644 --- a/public/assets/js/backend/orders/dispatch.js +++ b/public/assets/js/backend/orders/dispatch.js @@ -168,7 +168,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form','layer'], function ($, // 初始化表格参数配置 Table.api.init({ extend: { - index_url: 'workers/worker/index' + location.search, + index_url: 'workers/worker/dispatchList', table: 'worker', } }); @@ -177,7 +177,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form','layer'], function ($, // 初始化表格 table.bootstrapTable({ - url: $.fn.bootstrapTable.defaults.extend.index_url, + url: $.fn.bootstrapTable.defaults.extend.index_url +'?' + getQueryData(), pk: 'id', sortName: 'id', fixedColumns: true, @@ -185,7 +185,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form','layer'], function ($, columns: [ [ // {checkbox: true}, - // {field: 'id', title: __('Id')}, + {field: 'id', title: __('Id')}, {field: 'name', title: __('Name'), operate: 'LIKE'}, {field: 'tel', title: __('Tel'), operate: 'LIKE'}, // {field: 'status', title: __('Status'), searchList: {"1":__('Status 1'),"0":__('Status 0')}, formatter: Table.api.formatter.status}, @@ -194,23 +194,49 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form','layer'], function ($, //{field: 'lat', title: __('Lat'), operate:'BETWEEN'}, {field: 'area.short_merge_name', title: __('Area.short_merge_name'), operate: 'LIKE'}, // {field: 'deposit_amount', title: __('Deposit_amount'), operate:'BETWEEN'}, - {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate} + {field: 'id', title: '操作',formatter:function (id) { + return `

选择

`; + }}, ] - ] + ], + search:false, + commonSearch:false, }); + function getQueryData(){ + return $('#select-form').serialize(); + } $("#c-city-search").on("cp:updated", function() { var citypicker = $(this).data("citypicker"); var code = citypicker.getCode("district") || citypicker.getCode("city") || citypicker.getCode("province"); - table.bootstrapTable('refresh',{query: {area_code: code}}); + // table.bootstrapTable('refresh',{query: {area_code: code}}); + $('#area_id').val(code); }); - $("#reset").on("click", function() { - $("#c-city").citypicker('reset'); - table.bootstrapTable('refresh'); + $("#search_btn").on("click", function() { + table.bootstrapTable('refresh',{ + url:$.fn.bootstrapTable.defaults.extend.index_url +'?' + getQueryData(), + }); + }); + $("#reset_btn").on("click", function() { + $("#c-city-search").citypicker('reset'); + $("#area_id").val(''); + $("#citem").val('').selectpicker('refresh'); + $("#keyword").val(''); + console.log(1); + table.bootstrapTable('refresh',{ + url:$.fn.bootstrapTable.defaults.extend.index_url +'?' + getQueryData(), + }); + }); + Form.events.citypicker($("#select-form")); + + $(document).on('click', '.tab_chose', function() { + var dataId = $(this).data('id'); // 获取 data-id 的值 + const worker = Table.api.getrowbyid(table ,dataId); + $('#c-worker_name').val(worker.name + '--' + worker.tel).trigger('input').trigger('change'); + $('#worker_id').val(worker.id).trigger('input').trigger('change'); }); // 为表格绑定事件 Table.api.bindevent(table); - Form.events.citypicker($("#select-form")); Controller.api.bindevent(); }, @@ -219,7 +245,11 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form','layer'], function ($, }, api: { bindevent: function () { - Form.api.bindevent($("form[role=form]")); + Form.api.bindevent($("#add-form"),null,null,function (data) { + Form.api.submit($("#add-form")); + return false; + }); + Form.api.bindevent($("#select-form")); } } }; diff --git a/public/assets/js/require-table.js b/public/assets/js/require-table.js index fbeff7c..3dedb86 100755 --- a/public/assets/js/require-table.js +++ b/public/assets/js/require-table.js @@ -1068,7 +1068,8 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table getrowbyid: function (table, id) { var row = {}; var options = table.bootstrapTable("getOptions"); - $.each(Table.api.selecteddata(table), function (i, j) { + var data = table.bootstrapTable('getData'); + $.each(data, function (i, j) { if (j[options.pk] == id) { row = j; return false; diff --git a/public/assets/libs/fastadmin-citypicker/dist/css/city-picker.css b/public/assets/libs/fastadmin-citypicker/dist/css/city-picker.css index 686e668..51d375f 100755 --- a/public/assets/libs/fastadmin-citypicker/dist/css/city-picker.css +++ b/public/assets/libs/fastadmin-citypicker/dist/css/city-picker.css @@ -30,6 +30,16 @@ background: url(../images/drop-arrow.png) -10px -25px no-repeat; } +.city-picker-span > .close { + position: absolute; + top: 50%; + right: 24px; + width: 10px; + margin-top: -12px; + font-size: 20px; + height: 5px; +} + .city-picker-span.focus, .city-picker-span.open { border-bottom-color: #46A4FF; diff --git a/public/assets/libs/fastadmin-citypicker/dist/js/city-picker.js b/public/assets/libs/fastadmin-citypicker/dist/js/city-picker.js index 07c031f..6e6ccd5 100755 --- a/public/assets/libs/fastadmin-citypicker/dist/js/city-picker.js +++ b/public/assets/libs/fastadmin-citypicker/dist/js/city-picker.js @@ -73,7 +73,7 @@ this.getWidthStyle(p.width) + 'height:' + p.height + 'px;line-height:' + (p.height - 1) + 'px;">' + (placeholder ? '' + placeholder + '' : '') + - '
' + '', + '
X
' + '', dropdown = '
' + diff --git a/public/assets/libs/fastadmin-citypicker/src/city-picker.js b/public/assets/libs/fastadmin-citypicker/src/city-picker.js index 51b9fe2..d17a8c5 100755 --- a/public/assets/libs/fastadmin-citypicker/src/city-picker.js +++ b/public/assets/libs/fastadmin-citypicker/src/city-picker.js @@ -73,7 +73,7 @@ this.getWidthStyle(p.width) + 'height:' + p.height + 'px;line-height:' + (p.height - 1) + 'px;">' + (placeholder ? '' + placeholder + '' : '') + - '
' + '', + '
X
' + '', dropdown = '
' +