diff --git a/application/admin/command/Test.php b/application/admin/command/Test.php index df65a22..a9190af 100644 --- a/application/admin/command/Test.php +++ b/application/admin/command/Test.php @@ -35,9 +35,8 @@ class Test extends Command protected function execute(Input $input, Output $output) { - $key = 'ae0ab397a2febfa1ce0a2c780f3f23a3'; - $res = $this->getAddressByKeyword('重庆武隆区凤山街道锦江竹苑6幢31-4'); - dd($res); + $order = Order::where('id',221)->select()[0]; + AutoDispatchLogic::autoDispatch($order); } diff --git a/application/admin/controller/AutoDispatchLogic.php b/application/admin/controller/AutoDispatchLogic.php index 9bbf842..617cabe 100644 --- a/application/admin/controller/AutoDispatchLogic.php +++ b/application/admin/controller/AutoDispatchLogic.php @@ -22,6 +22,7 @@ class AutoDispatchLogic $worker_id = (new DispatchLogic())->getMaxScoreWorker($order); +// dd($worker_id); if (!$worker_id) { $order->dispatch_type = 1; $order->save(); diff --git a/application/admin/controller/Message.php b/application/admin/controller/Message.php index f3eb501..a96235f 100644 --- a/application/admin/controller/Message.php +++ b/application/admin/controller/Message.php @@ -148,4 +148,33 @@ class Message extends Backend } + public function markallread(){ + $list = $this->model + ->where('type',1) + ->where('to_id',$this->auth->id) + //->auth($this->auth) + //->whereRaw("FIND_IN_SET(?, read_uid) = 0 OR read_uid IS NULL OR read_uid = ''", [$this->auth->id]) + ->whereRaw("FIND_IN_SET({$this->auth->id}, read_uid) = 0 OR read_uid = '' or read_uid is null") + ->whereTime('create_time', '>=', '-3 days') + ->select(); + $update = []; + foreach ($list as &$item){ + $readUids = explode(',',$item->read_uid??''); + $item->status = 1; + if(!in_array($this->auth->id,$readUids)){ + $readUids[] = $this->auth->id; + $update[] = [ + 'id' => $item->id, + 'read_uid' => implode(',',$readUids), + 'update_time' => date('Y-m-d H:i:s') + ]; + $item->status = 0; + } + } + if($update){ + $this->batchUpdateByIdSimple('fa_message',$update); + } + $this->success("全部已读"); + } + } diff --git a/application/admin/controller/Order.php b/application/admin/controller/Order.php index fec957d..be2967e 100644 --- a/application/admin/controller/Order.php +++ b/application/admin/controller/Order.php @@ -13,6 +13,8 @@ use app\admin\model\Worker; use app\admin\model\WorkerItem; use app\common\controller\Backend; use app\common\Logic\OrderLogic; +use Carbon\Carbon; +use Carbon\Traits\Creator; use fast\Tree; use think\Db; use think\Exception; @@ -146,6 +148,7 @@ class Order extends Backend 'receive_type', 'plan_time', 'coupon_id', + 'create_time', 'total', 'online_amount', 'aftersale_id' @@ -153,18 +156,33 @@ class Order extends Backend ->where($where); $filter = (array)json_decode(input()['filter'] ?? '', true); $admin_filter = $filter['user.nickname'] ?? false; - + $is_timeout = $filter['is_timeout'] ?? null; +// dd($create_time,$filter); if ($admin_filter) { $admin_ids = Admin::where('nickname', 'like', '%' . $admin_filter . '%')->column('id'); $build->whereIn('admin_id', $admin_ids); } + if (!is_null($is_timeout)) { + if ($is_timeout == 1){ + $build->where('status', '>=', \app\admin\model\Order::STATUS_DISPATCHING) + ->where('create_time', '<=', (new Carbon())->subMinutes(20) + ->format('Y-m-d H:i:s')); + }else{ + $build->where('status', '>=', \app\admin\model\Order::STATUS_DISPATCHING) + ->where('create_time', '>', (new Carbon())->subMinutes(20) + ->format('Y-m-d H:i:s')); + } + + } if ($type == 1) { $build->where('status', '>=', 0); - } - - if ($type == 2) { + }elseif ($type == 2) { $build->where('status', '<', 0); + }elseif ($type == 3){ + $build->where('status', '>=', \app\admin\model\Order::STATUS_DISPATCHING) + ->where('create_time', '<=', (new Carbon())->subMinutes(20) + ->format('Y-m-d H:i:s')); } if ($group == 2 || $group == 6) { // 生成 SQL 语句 @@ -449,7 +467,7 @@ class Order extends Backend $insert [] = [ 'to_id' => $re, 'type' => 1, - 'title' => '订单报错通知', + 'title' => '催单通知', 'content' => '【催单通知】您有一条订单号为' . $order->order_no . '的订单被催单,请立即派单!' ]; } @@ -616,6 +634,9 @@ class Order extends Backend $op[] = ['id' => $option->id, 'title' => $option->title]; } $order = model('order')->get($ids); + if ($order){ + $this->error('订单未找到,请重试'); + } return $this->fetch('delete', ['row' => $order, 'options' => $op]); } $params = $this->request->post('row/a'); @@ -648,7 +669,7 @@ class Order extends Backend $hookparams['order'] = $order; $hookparams['role'] = 1; $hookparams['auth'] = null; - $hookparams['remark'] = $params['remark'] ?? ''; + $hookparams['remark'] = $params['remark'] ?? '取消订单'; Hook::listen('order_change', $hookparams); } Db::commit(); @@ -846,7 +867,7 @@ class Order extends Backend $index = 0; foreach ($filter as $k => $v) { - if ($k == 'user.nickname') continue; + if ($k == 'user.nickname' || $k =='is_timeout') continue; if (!preg_match('/^[a-zA-Z0-9_\-\.]+$/', $k)) { continue; } diff --git a/application/admin/controller/orders/DispatchLogic.php b/application/admin/controller/orders/DispatchLogic.php index 4f47a5c..30b00d8 100644 --- a/application/admin/controller/orders/DispatchLogic.php +++ b/application/admin/controller/orders/DispatchLogic.php @@ -29,11 +29,13 @@ FROM ( point(lng, lat), point(?, ?) ) AS distance - FROM fa_worker where deletetime is null + FROM fa_worker where deletetime is null and type = 1 and status = 1 ) AS t WHERE distance < 40000 ORDER BY distance;",[$order->lng,$order->lat]); + + $worker_ids = array_column($worker_info,'id'); @@ -47,7 +49,7 @@ ORDER BY distance;",[$order->lng,$order->lat]); $out_worker_ids = array_intersect($worker_ids, $worker_items_ids); $out_worker_ids = array_values(array_diff($out_worker_ids, $out_worker)); - +// dd($out_worker_ids); $worker_doings = (new OrderDispatch()) ->whereIn('worker_id', $out_worker_ids) ->group('worker_id') diff --git a/application/admin/controller/workers/Worker.php b/application/admin/controller/workers/Worker.php index ed455b1..619a9a4 100644 --- a/application/admin/controller/workers/Worker.php +++ b/application/admin/controller/workers/Worker.php @@ -6,6 +6,7 @@ use app\admin\model\Area; use app\admin\model\AuthGroup; use app\admin\model\Item; use app\admin\model\Order; +use app\admin\model\WorkerItem; use app\common\controller\Backend; use fast\Tree; use think\Db; @@ -160,7 +161,7 @@ class Worker extends Backend } $params['admin_id'] = $this->auth->id; - if(!empty($params['area_id'])){ + if((!empty($params['area_id'])) && isset($params['lng'])){ $area = Area::getByCode($params['area_id']); if($area){ @@ -171,7 +172,9 @@ class Worker extends Backend } } } +// dd($params); $result = $this->model->allowField(true)->save($params); +// dd($result); $item_map = model('item')->getAll(); $item_map = array_column($item_map, 'level', 'id'); if ($result) { @@ -275,6 +278,7 @@ class Worker extends Backend public function dispatchList() { $area_id = request()->get('area_id'); + $item_id = request()->get('item_id'); list($where, $sort, $order, $offset, $limit) = $this->buildparams(); $build = model('worker') @@ -297,6 +301,10 @@ class Worker extends Backend $code = $this->getSelectAreaCode(substr_replace($area_id, '00', -2)); $build->where('area_id', 'like', $code . '%'); } + if ($item_id) { + $worker_ids = WorkerItem::where('item_id',$item_id)->column('worker_id'); + $build->whereIn('id',$worker_ids); + } $list = $build ->paginate($limit); $result = array("total" => $list->total(), "rows" => $list->items()); diff --git a/application/admin/view/message/index.html b/application/admin/view/message/index.html index 3468ab4..02174ee 100644 --- a/application/admin/view/message/index.html +++ b/application/admin/view/message/index.html @@ -7,11 +7,13 @@
- + 全部标记已读 + +
diff --git a/application/admin/view/order/index.html b/application/admin/view/order/index.html index 825784b..7b56e16 100644 --- a/application/admin/view/order/index.html +++ b/application/admin/view/order/index.html @@ -6,6 +6,7 @@ diff --git a/application/admin/view/orders/dispatch/add.html b/application/admin/view/orders/dispatch/add.html index df88ac0..ceaef3b 100644 --- a/application/admin/view/orders/dispatch/add.html +++ b/application/admin/view/orders/dispatch/add.html @@ -97,7 +97,7 @@
- +
diff --git a/application/admin/view/orders/dispatch2/edit.html b/application/admin/view/orders/dispatch2/edit.html index e56a747..0f6e174 100644 --- a/application/admin/view/orders/dispatch2/edit.html +++ b/application/admin/view/orders/dispatch2/edit.html @@ -16,40 +16,40 @@ -
- -
- -
-
+ + + + + + -
- -
- -
-
+ + + + + + -
- -
- -
-
+ + + + + + -
- -
- -
-
+ + + + + + -
- -
- -
-
+ + + + + + {notempty name ='action'} @@ -69,12 +69,15 @@ -
- -
- -
-
+ + + + + + + + + @@ -135,7 +138,7 @@
- +
@@ -148,8 +151,29 @@ {/if} +
+ +
+ +
+
+
+ +
+
+ +
+ + +
+ +
+
    +
    +
    +
    @@ -166,12 +190,7 @@
    -
    - -
    - -
    -
    +
    @@ -193,31 +212,13 @@
    -
    - +
    - +
    - -
    - -
    -
    - -
    - - -
    - -
    -
      -
      -
      - -
      - - - - -
      @@ -108,4 +107,42 @@ \ No newline at end of file + + \ No newline at end of file diff --git a/application/admin/view/workers/worker/edit.html b/application/admin/view/workers/worker/edit.html index e01c404..18372fc 100644 --- a/application/admin/view/workers/worker/edit.html +++ b/application/admin/view/workers/worker/edit.html @@ -29,20 +29,21 @@
      -
      - -
      - - -
      -
      -
      - + +
        + +
        @@ -122,4 +123,42 @@ \ No newline at end of file + + \ No newline at end of file diff --git a/public/assets/js/backend/message.js b/public/assets/js/backend/message.js index babd5b8..1e57da3 100644 --- a/public/assets/js/backend/message.js +++ b/public/assets/js/backend/message.js @@ -54,6 +54,20 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin // 为表格绑定事件 Table.api.bindevent(table); + + + $(".btn-all-read").click(function () { + Layer.confirm("确定要将所有消息标记为已读吗?", function (index) { + Fast.api.ajax({ + url: 'message/markallread', + },function (){ + Layer.close(index); + table.bootstrapTable('refresh'); + }); + + }); + }); + }, add: function () { Controller.api.bindevent(); diff --git a/public/assets/js/backend/order.js b/public/assets/js/backend/order.js index 2a4d1c8..9286b0d 100644 --- a/public/assets/js/backend/order.js +++ b/public/assets/js/backend/order.js @@ -83,7 +83,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'cascader'], function fixed: true, searchList: { "0": __('Status 0'), - "10": __('Status 10'), + "10": __('Status 10'), "20": __('Status 20'), "30": __('Status 30'), "40": __('Status 40'), @@ -101,6 +101,33 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'cascader'], function "10": "my_dispatch" } }, + { + field: 'is_timeout', + title: '是否超时', + formatter: function (value, row) { + value = row.create_time; + + if (row.status !== 10 || !value) { + return ''; + } + // 解析 create_time 时间戳或字符串为时间对象 + var createTime = typeof value === 'string' ? new Date(value.replace(/-/g, '/')) : new Date(value * 1000); // 兼容时间戳和时间字符串 + var now = new Date(); + var diffMinutes = (now - createTime) / (1000 * 60); // 计算分钟差 + + return diffMinutes > 20 ? '超时' : '未超时';; + }, + searchList: { + "1": '超时', + "0": '未超时', + }, + searchable: true, + custom: { + '1': 'danger', + '0': 'success' + }, + operate: '=', + }, { field: 'dispatch_type', title: '派单方式', @@ -228,24 +255,6 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'cascader'], function }, dropdown: "更多" }, - { - name: "dispatch", - text: "派单", - title: "派单", - extend: 'data-toggle="tooltip" data-container="body"', - classname: 'btn btn-xs btn-info btn-dialog', - icon: 'fa fa-add', - url: function (row) { - return 'orders/dispatch/add?order_id=' + row.id; - }, - visible: function (row) { - if (row.status == 10) { - return true; - } - return false; - }, - refresh: true, - }, { name: "warning", @@ -284,6 +293,24 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'cascader'], function table.bootstrapTable('refresh'); } }, + { + name: "dispatch", + text: "派单", + title: "派单", + extend: 'data-toggle="tooltip" data-container="body"', + classname: 'btn btn-xs btn-info btn-dialog', + icon: 'fa fa-add', + url: function (row) { + return 'orders/dispatch/add?order_id=' + row.id; + }, + visible: function (row) { + if (row.status == 10) { + return true; + } + return false; + }, + refresh: true, + }, { name: "reminder", text: "催单", @@ -416,9 +443,22 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'cascader'], function table.bootstrapTable('refresh', {}); return false; }); - const timer = setInterval(function () { - table.bootstrapTable('refresh', {}); - }, 1000 * 120); + let idleTimer = null; + + function resetIdleTimer() { + clearTimeout(idleTimer); + idleTimer = setTimeout(function () { + // 30秒无操作后执行刷新 + table.bootstrapTable('refresh', {}); + }, 30 * 1000); // 30 秒 + } + + ['mousemove', 'keydown', 'click', 'scroll'].forEach(function (event) { + document.addEventListener(event, resetIdleTimer, false); + }); + + resetIdleTimer(); + }, add: function () { $("#mybuttom").on("click", function () { @@ -616,7 +656,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'cascader'], function $('#item_id_value').val(data.value); } }); - $('#item_id').val($('#item_id').data('value')).focus(); + $('#item_id').val($('#item_id').data('value')); const mainSelect = document.getElementById('receive_type'); const otherSelect = document.getElementById('coupon'); @@ -721,7 +761,6 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'cascader'], function } } - function handleInput(e) { selectedIndex = -1; addressSelected = false; @@ -759,7 +798,6 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'cascader'], function }; } - $('#suggestionList').on('mousedown', 'li', function (e) { const name = $(this).data('name'); const location = $(this).data('location'); // "经度,纬度" diff --git a/public/assets/js/backend/orders/dispatch.js b/public/assets/js/backend/orders/dispatch.js index b7c65b8..7747e2f 100644 --- a/public/assets/js/backend/orders/dispatch.js +++ b/public/assets/js/backend/orders/dispatch.js @@ -320,10 +320,8 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'layer', 'cascader'], $("#reset_btn").on("click", function () { $("#c-city-search").citypicker('reset'); $("#area_id").val(''); - $("#test").val(''); - $("#test").data('myvalue', ''); + $("#item_id").data('myvalue', ''); $("#keyword").val(''); - $('#item_id').zdCascader.reload(_data,true); table.bootstrapTable('refresh', { url: $.fn.bootstrapTable.defaults.extend.index_url + '?' + getQueryData(), }); @@ -336,27 +334,24 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'layer', 'cascader'], $('#c-worker_id').val(worker.id).trigger('input').trigger('change'); }); $('#add_worker').on('click',function (){ - console.log(1); Fast.api.open('workers/worker/add?type=2', '添加工人',{ callback: function (value) { - console.log(2222,value); + table.bootstrapTable('refresh', { + url: $.fn.bootstrapTable.defaults.extend.index_url + '?' + getQueryData(), + }); } }); }); - - $('#item_id').zdCascader({ data: _data, onChange: function ($this, data, allPathData) { - // console.log(data,allPathData); $('#item_id').data('myvalue', data.value); }, - defaultValue:$('#item_id_name').val(), - clear:true, - clickParent:true + // clear:true, + // clickParent:true }); - + $('#item_id').val($('#item_id').data('value')); // 为表格绑定事件 Table.api.bindevent(table); diff --git a/public/assets/js/backend/orders/dispatch2.js b/public/assets/js/backend/orders/dispatch2.js index fb871aa..e31d331 100644 --- a/public/assets/js/backend/orders/dispatch2.js +++ b/public/assets/js/backend/orders/dispatch2.js @@ -89,7 +89,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form','layer'], function ($, // {field: 'worker_id', title: __('Worker_id')}, {field: 'worker_name', title: __('Worker_name'), operate: 'LIKE'}, {field: 'worker_tel', title: __('Worker_tel'), operate: 'LIKE'}, - {field: 'type', title: __('Type'), searchList: {"1":__('Type 1'),"2":__('自动')}, formatter: Table.api.formatter.normal, + {field: 'type', title: __('Type'), searchList: {"1":__('Type 1'),"2":__('自动')}, formatter: Table.api.formatter.normal // defaultValue: '1' }, @@ -196,7 +196,24 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form','layer'], function ($, return true; } }, - + // { + // name: "dispatch", + // text: "派单", + // title: "派单", + // extend: 'data-toggle="tooltip" data-container="body"', + // classname: 'btn btn-xs btn-info btn-dialog', + // icon: 'fa fa-add', + // url: function (row) { + // return 'orders/dispatch/add?order_id=' + row.order_id; + // }, + // visible: function (row) { + // if (row.type == 2) { + // return true; + // } + // return false; + // }, + // refresh: true, + // }, { name: 'addrecord', text:"跟进", @@ -242,7 +259,8 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form','layer'], function ($, dropdown: "更多", visible: function (row) { - if (row.orderb.status >= 0 && row.orderb.status < 60 && row.status >0 && row.status < 60) { + return true; + if (row.orderb.status >= 0 && row.orderb.status < 60 && row.status >=0 && row.status < 60) { return true; } return false; @@ -261,7 +279,8 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form','layer'], function ($, refresh:true, dropdown: "更多", visible: function (row) { - if (row.orderb.status != 60 && row.status > 0 && row.status < 60) { + return true; + if (row.orderb.status != 60 && row.status >=0 && row.status < 60) { return true; } return false; @@ -279,7 +298,26 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form','layer'], function ($, dropdown: "更多", visible: function (row) { - if (row.orderb.status == 60 && row.status>0) { + return true; + if (row.orderb.status == 60 && row.status>=0) { + return true; + } + return false; + }, + }, + { + name: 'aftersale', + text: '申请售后', + title: '申请售后', + classname: 'btn btn-dialog', + icon: 'fa fa-phone-square', + url: function(row){ + return 'aftersales/aftersale/add/'+row.order_id; + }, + dropdown: "更多", + visible: function (row) { + return true; + if (row.orderb.status !== -10 && row.orderb.status !== 70) { return true; } return false; diff --git a/public/assets/js/backend/workers/worker.js b/public/assets/js/backend/workers/worker.js index b1727cf..6184ef1 100644 --- a/public/assets/js/backend/workers/worker.js +++ b/public/assets/js/backend/workers/worker.js @@ -218,11 +218,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'jstree'], Form.events.citypicker($("form")); }, add: function () { - $("#c-city").on("cp:updated", function () { - var citypicker = $(this).data("citypicker"); - var code = citypicker.getCode("district") || citypicker.getCode("city") || citypicker.getCode("province"); - $("#area_id").val(code); - }); + const urlParams = new URLSearchParams(window.location.search); const type = urlParams.get('type'); if (type) { @@ -232,14 +228,12 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'jstree'], } } Controller.api.bindevent(); + Controller.api.area(); }, edit: function () { - $("#c-city").on("cp:updated", function () { - var citypicker = $(this).data("citypicker"); - var code = citypicker.getCode("district") || citypicker.getCode("city") || citypicker.getCode("province"); - $("#area_id").val(code); - }); + Controller.api.bindevent(); + Controller.api.area(); }, api: { bindevent: function () { @@ -290,6 +284,152 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'jstree'], "data": content } }); + }, + + area: function (){ + const amapKey = 'c299da50c080dfccf9b1d00560ff9639'; + + let isComposing = false; + let addressSelected = false; + let selectedIndex = -1; + $('#c-address') + .on('compositionstart', () => { + isComposing = true; + }) + .on('compositionend', () => { + isComposing = false; + // 不执行 handleInput,由 input 触发 + }) + .on('input', debounce(function (e) { + if (!isComposing) handleInput(e); + }, 300)) + .on('blur', function () { + // 如果还没有选择地址,且列表中有内容,则默认选择第一个 + + // 如果还没有选择地址,且列表中有内容,则默认选择第一个 + if (!addressSelected && $('#suggestionList li').length > 0) { + choseFirst(); + } + + $('#suggestionList').hide(); + }) + .on('focus', function () { + // 如果还没有选择地址,且列表中有内容,则默认选择第一个 + $('#suggestionList').show(); + }) + .on('keydown', function (e) { + const $items = $('#suggestionList li'); + const len = $items.length; + + if (!len) return; + + if (e.key === 'ArrowDown') { + e.preventDefault(); + selectedIndex = (selectedIndex + 1) % len; + updateActiveItem($items); + } else if (e.key === 'ArrowUp') { + e.preventDefault(); + selectedIndex = (selectedIndex - 1 + len) % len; + updateActiveItem($items); + } else if (e.key === 'Enter') { + if (selectedIndex >= 0 && selectedIndex < len) { + e.preventDefault(); + $items.eq(selectedIndex).trigger('mousedown'); + } + } + }); + function updateActiveItem($items) { + $items.removeClass('active'); + if (selectedIndex >= 0) { + const $active = $items.eq(selectedIndex); + $active.addClass('active'); + + // 自动滚动使其可见 + const container = $('#suggestionList')[0]; + const item = $active[0]; + + if (item && container) { + const itemTop = item.offsetTop; + const itemBottom = itemTop + item.offsetHeight; + const containerTop = container.scrollTop; + const containerBottom = containerTop + container.clientHeight; + + if (itemTop < containerTop) { + container.scrollTop = itemTop; + } else if (itemBottom > containerBottom) { + container.scrollTop = itemBottom - container.clientHeight; + } + } + } + } + + function handleInput(e) { + selectedIndex = -1; + addressSelected = false; + const keyword = $(e.target).val(); + if (!keyword.trim() || /^[\s\p{P}]+$/u.test(keyword)) return; + if (!keyword) return $('#c-address').empty(); + + $.getJSON('https://restapi.amap.com/v3/assistant/inputtips', { + key: amapKey, + keywords: keyword, + datatype: 'all', + city: '全国', + }, function (res) { + if (res.tips) { + let html = ''; + res.tips.forEach(tip => { + if (tip.location) { + html += `
      • + ${tip.district} ${tip.name} +
      • `; + } + }); + $('#suggestionList').html(html).show(); + } + }); + } + + function debounce(fn, delay = 300) { + let timer = null; + return function (...args) { + clearTimeout(timer); + timer = setTimeout(() => { + fn.apply(this, args); + }, delay); + }; + } + + $('#suggestionList').on('mousedown', 'li', function (e) { + const name = $(this).data('name'); + const location = $(this).data('location'); // "经度,纬度" + const area_id = $(this).data('area_id'); // "经度,纬度" + const [lng, lat] = location.split(','); + $('#c-address').val(name); + $('#lng').val(lng); + $('#lat').val(lat); + $('#area_id').val(area_id); + // 隐藏提示列表 + $('#suggestionList').hide(); + selectedIndex = -1; + addressSelected = true; + }); + + function choseFirst(){ + const first = $('#suggestionList li').first(); + const name = first.data('name'); + const location = first.data('location'); // "经度,纬度" + const area_id = first.data('area_id'); // "经度,纬度" + const [lng, lat] = location.split(','); + console.log('chose'); + $('#lng').val(lng); + $('#lat').val(lat); + $('#area_id').val(area_id); + // 隐藏提示列表 + $('#suggestionList').hide(); + selectedIndex = -1; + addressSelected = true; + } } } };