zilong 4 jaren geleden
bovenliggende
commit
bbb94c0775
2 gewijzigde bestanden met toevoegingen van 48 en 21 verwijderingen
  1. 25 7
      app/Community/Controllers/NoticeManageController.php
  2. 23 14
      resources/views/cdms/notice_list.blade.php

+ 25 - 7
app/Community/Controllers/NoticeManageController.php

xqd xqd xqd xqd
@@ -47,7 +47,7 @@ class NoticeManageController extends AdminController
         $list = $builder->paginate();
         $data['req'] = $req;
         $data['list'] = $list;
-        $data['ids']  = Cache::get('notice-'.$user['id'])[$req['page']??1] ?? [];
+        $data['ids']  = Cache::get('notice-'.$user['id']) ?? [];
 
         $content = new Content();
         Admin::disablePjax();
@@ -61,7 +61,14 @@ class NoticeManageController extends AdminController
         $user = Admin::user();
 
         $arr = Cache::get($req['type'].'-'.$user['id']) ?? [];
-        $arr[$req['page']] = $req['ids']??[];
+        foreach ($req['ids'] as $k => $v) {
+            if (isset($arr[$v])) {
+                unset($arr[$v]);
+            }
+            else {
+                $arr[$v] = $v;
+            }
+        }
         Cache::set($req['type'].'-'.$user['id'], $arr, 300);
 
         return out();
@@ -79,14 +86,11 @@ class NoticeManageController extends AdminController
         $user = Admin::user();
 
         $arr = Cache::get('notice-'.$user['id']) ?? [];
-        $ids = [];
-        foreach ($arr as $k => $v) {
-            $ids = array_merge($ids, $v);
-        }
-        $ids = array_values(array_unique($ids));
+        $ids = array_values(array_unique($arr));
         if (empty($ids)) {
             return out(null, 10001, '请勾选要发送通知的用户');
         }
+
         Cache::delete('notice-'.$user['id']);
         foreach ($ids as $id) {
             $user_id = Patient::where('id', $id)->value('user_id');
@@ -118,6 +122,20 @@ class NoticeManageController extends AdminController
         return out();
     }
 
+    public function getCacheUsers()
+    {
+        $req = request()->post();
+        $user = Admin::user();
+        $ids = Cache::get($req['type'].'-'.$user['id']) ?? [];
+        $nameText = '';
+        if (!empty($ids)) {
+            $nameArr = Patient::whereIn('id', $ids)->pluck('name')->toArray();
+            $nameText = implode(';', $nameArr);
+        }
+
+        return out($nameText);
+    }
+
     private function send($open_id, $tempId, $msg)
     {
         try {

+ 23 - 14
resources/views/cdms/notice_list.blade.php

xqd xqd xqd xqd xqd
@@ -24,7 +24,7 @@
                     <table class="table table-bordered table-hover table-striped">
                         <tbody>
                         <tr>
-                            <th><input id="batch_selected" type="checkbox" onclick="batch_selected()"></th>
+                            <th>{{--<input id="batch_selected" type="checkbox" onclick="batch_selected()">--}}</th>
                             <th>用户</th>
                             <th>监护人</th>
                             <th>患者</th>
@@ -35,7 +35,7 @@
                         </tr>
                         <?php foreach ($list as $k => $v){ ?>
                         <tr>
-                            <td><input class="box_ids" type="checkbox" value="{{$v['id']}}" name="ids" onclick="selected()" <?php if (in_array($v['id'], $ids)) { echo 'checked'; } ?>></td>
+                            <td><input class="box_ids" type="checkbox" value="{{$v['id']}}" name="ids" onclick="selected(this)" <?php if (in_array($v['id'], $ids)) { echo 'checked'; } ?>></td>
                             <td>{{$v['users']['nickname']}}</td>
                             <td>{{$v['guardian_name']}}</td>
                             <td>{{$v['name']}}</td>
@@ -58,6 +58,10 @@
     <div class="modal-content">
         <form id="commentForm">
             <div class="modal-body">
+                <div class="form-group">
+                    <label>发送用户</label>
+                    <div id="name_text"></div>
+                </div>
                 <div class="form-group">
                     <label>内容</label>
                     <textarea name="content" class="form-control content action" rows="4" placeholder="输入内容"></textarea>
@@ -100,12 +104,20 @@
 
     function showSendNotice()
     {
-        layer.open({
-            type: 1,
-            title: '群发通知',
-            area: ['50%', '95%'], //宽高
-            content: $('#show_send_notice')
-        });
+        $.post("{{ url('/cdms/community/noticeManage/getCacheUsers') }}", {type: "notice"}, function (res) {
+            if (res.status == 0) {
+                $('#name_text').text(res.data);
+                layer.open({
+                    type: 1,
+                    title: '群发通知',
+                    area: ['50%', '95%'], //宽高
+                    content: $('#show_send_notice')
+                });
+            }
+            else {
+                alert(res.message);
+            }
+        })
     }
 
     function batch_selected()
@@ -120,14 +132,11 @@
         selected();
     }
 
-    function selected()
+    function selected(obj)
     {
-        var checkID = [];
-        $("input[name='ids']:checked").each(function(i) {
-            checkID[i] = $(this).val();
-        });
+        var checkID = [$(obj).val()];
 
-        $.post("{{ url('/cdms/community/noticeManage/saveIds') }}", {ids: checkID, type:"notice", page:"{{$req['page']??1}}"}, function (res) {
+        $.post("{{ url('/cdms/community/noticeManage/saveIds') }}", {ids: checkID, type: "notice"}, function (res) {
             if (res.status != 0) {
                 alert(res.message);
             }