Prechádzať zdrojové kódy

成员管理+设备管理

李浩杰 4 rokov pred
rodič
commit
417e89464c
56 zmenil súbory, kde vykonal 932 pridanie a 204 odobranie
  1. 1 1
      app/Http/Controllers/Admin/ProjectRoleController.php
  2. 64 0
      app/Http/Controllers/Admin/ProjectRoleRightController.php
  3. 1 1
      app/Http/Controllers/Admin/TestController.php
  4. 5 0
      app/Http/Controllers/Api/mini/InnerDeviceController.php
  5. 86 28
      app/Http/Controllers/Api/mini/OrderController.php
  6. 22 0
      app/Http/Controllers/Api/mini/OrderDeviceController.php
  7. 18 0
      app/Http/Controllers/Api/mini/ProjectRoleController.php
  8. 47 0
      app/Http/Controllers/Api/mini/RightController.php
  9. 4 0
      app/Http/Controllers/Api/mini/UserController.php
  10. 2 2
      app/Models/BaseModel.php
  11. 6 3
      app/Models/Notification.php
  12. 43 5
      app/Models/Order.php
  13. 10 0
      app/Models/OrderDevice.php
  14. 1 1
      app/Models/Project.php
  15. 57 12
      app/Models/ProjectRole.php
  16. 8 0
      app/Models/ProjectRoleRight.php
  17. 8 0
      app/Models/Right.php
  18. 16 3
      app/Models/User.php
  19. 34 0
      database/migrations/2020_12_30_170204_create_rights_table.php
  20. 33 0
      database/migrations/2020_12_30_174206_create_project_role_rights_table.php
  21. 30 0
      database/migrations/2021_01_01_105700_add_level_to_orders.php
  22. 30 0
      database/migrations/2021_01_03_230906_add_user_id_to_order_devices.php
  23. 42 0
      database/seeds/RightSeeder.php
  24. 28 0
      mini/components/inner-device-card/index.js
  25. 8 1
      mini/components/inner-device-card/index.wxml
  26. 5 1
      mini/components/inner-order-item/index.js
  27. 2 14
      mini/components/inner-order-item/index.wxml
  28. 5 2
      mini/components/out-order-item/index.js
  29. 1 1
      mini/components/out-order-item/index.wxml
  30. 4 2
      mini/custom-tab-bar/index.js
  31. 7 6
      mini/pages/account/index.js
  32. 2 1
      mini/pages/add-inner-device/index.js
  33. 58 10
      mini/pages/create-order-inner/index.js
  34. 13 35
      mini/pages/create-order-inner/index.wxml
  35. 3 0
      mini/pages/create-order-inner/index.wxss
  36. 50 12
      mini/pages/create-order/index.js
  37. 1 1
      mini/pages/create-order/index.wxml
  38. 1 1
      mini/pages/device-inner/index.wxml
  39. 2 2
      mini/pages/draft/index.wxml
  40. 0 7
      mini/pages/index/index.js
  41. 3 3
      mini/pages/index/index.wxml
  42. 3 0
      mini/pages/index/index.wxss
  43. 9 2
      mini/pages/note-detail/index.js
  44. 3 2
      mini/pages/note-detail/index.wxml
  45. 1 1
      mini/pages/order-detail-inner/index.js
  46. 16 12
      mini/pages/order-detail/index.js
  47. 7 7
      mini/pages/order-detail/index.wxml
  48. 1 0
      mini/pages/order/index.js
  49. 22 14
      mini/pages/project/index.js
  50. 3 3
      mini/pages/project/index.wxml
  51. 2 2
      mini/pages/use-record/index.js
  52. 3 3
      mini/pages/use-record/index.wxml
  53. 4 1
      mini/pages/use-record/index.wxss
  54. 1 1
      mini/utils/env.js
  55. 92 0
      resources/views/admin/project-role-rights/index.blade.php
  56. 4 1
      routes/api.php

+ 1 - 1
app/Http/Controllers/Admin/ProjectRoleController.php

xqd xqd
@@ -4,6 +4,7 @@ namespace App\Http\Controllers\Admin;
 
 use App\Models\ProjectRole;
 use Illuminate\Http\Request;
+use Illuminate\Support\Facades\Auth;
 
 class ProjectRoleController extends BaseController
 {
@@ -100,5 +101,4 @@ class ProjectRoleController extends BaseController
         if (!$res) return response()->json(['status' => 'fail', 'info' => '删除失败']);
         return response()->json(['status' => 'success', 'info' => '操作成功']);
     }
-
 }

+ 64 - 0
app/Http/Controllers/Admin/ProjectRoleRightController.php

xqd
@@ -0,0 +1,64 @@
+<?php
+
+namespace App\Http\Controllers\Admin;
+
+use App\Models\ProjectRole;
+use App\Models\ProjectRoleRight;
+use App\Models\Right;
+use Illuminate\Http\Request;
+
+class ProjectRoleRightController extends BaseController
+{
+    protected $model;
+
+    protected $department;
+
+    protected $model_name = '权限管理';
+
+    protected $pre_uri = '/admin/ProjectRoleRight/';
+
+    protected $view_path = 'admin.project-role-rights.';
+
+    protected $redirect_index = '/admin/ProjectRoleRight/index';
+
+    public function __construct()
+    {
+        $this->model = new ProjectRole();
+    }
+
+    public function index()
+    {
+        $rights = Right::all();
+        $project_roles = ProjectRole::all();
+        $project_role_rights = ProjectRoleRight::all();
+        $items = [];
+        foreach($rights as $right) {
+            $item = [$right];
+            foreach($project_roles as $project_role) {
+                $has_right = $project_role_rights->where('right_id', $right->id)->where('project_role_id', $project_role->id)->first() != null;
+                array_push($item, ['right_id' => $right->id, 'role_id' => $project_role->id, 'has' => $has_right]);
+            }
+            array_push($items, $item);
+        }
+        list($model, $model_name, $pre_uri) = array($this->model, $this->model_name, $this->pre_uri);
+        return view($this->view_path . 'index', compact('model', 'model_name','pre_uri', 'items', 'project_roles'));
+    }
+
+    public function change(Request $request)
+    {
+        // 赋予权力
+        if($request->input('has') == 2) {
+            ProjectRoleRight::updateOrCreate([
+                'project_role_id' => $request->input('role_id'),
+                'right_id' => $request->input('right_id')
+            ]);
+        } else {
+            // 取消权利
+            ProjectRoleRight::where([
+                ['project_role_id', $request->input('role_id')],
+                ['right_id', $request->input('right_id')]
+            ])->delete();
+        }
+        return response()->json(['status' => 'success', 'info' => '操作成功']);
+    }
+}

+ 1 - 1
app/Http/Controllers/Admin/TestController.php

xqd
@@ -20,7 +20,7 @@ class TestController extends Controller
 {
     public function index(Request $request)
     {
-        Project::first()->getShowLabel('test');
+        dd(ProjectRole::getCreateRole('apply', 2));
 //    	return view('admin.test.index');
     }
 }

+ 5 - 0
app/Http/Controllers/Api/mini/InnerDeviceController.php

xqd
@@ -63,6 +63,11 @@ class InnerDeviceController extends BaseController
             $stat_items = $this->getStat($items);
         }
 
+        if($request->input('free')) {
+            $free_id = Option::get('inner_devices', 'status', 'free', 'id');
+            $items = $items->where('status', $free_id);
+        }
+
         $items = $items->paginate();
         foreach($items as $item) {
             $item->status = Option::find($item->status);

+ 86 - 28
app/Http/Controllers/Api/mini/OrderController.php

xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd
@@ -33,7 +33,7 @@ class OrderController extends BaseController
         $project = Project::find($request->input('project_id'));
         if(!$project) return $this->error(['msg' => '找不到项目']);
         $user = Auth::guard('mini')->user();
-        $project_role_id = $request->input('is_draft') == 1 ? ProjectRole::getByKey('work', 'id') : ProjectRole::getByKey('machine', 'id');
+        $project_role = ProjectRole::getCreateRole('rent', $request->input('is_draft'));
         $option = Option::get('orders', 'status', 'checking');
 
         $order = Order::create([
@@ -44,7 +44,8 @@ class OrderController extends BaseController
             'order_number' => $this->model->createOrderNumber(),
             'project_id' => $project->id,
             'user_id' => $user->id,
-            'project_role_id' => $project_role_id,
+            'project_role_id' => $project_role ? $project_role['id'] : '',
+            'level' => $project_role ? $project_role['level'] : '',
             'type' => 1
         ]);
         if(!$order) return $this->error(['msg' => '订单创建失败']);
@@ -119,7 +120,7 @@ class OrderController extends BaseController
         }
 
         $user = Auth::guard('mini')->user();
-        $project_role_id = $request->input('is_draft') == 1 ? ProjectRole::getByKey('machine', 'id') : ProjectRole::getByKey('assist', 'id');
+        $project_role = ProjectRole::getCreateRole('apply', $request->input('is_draft'));
         $option = Option::get('orders', 'status', 'checking');
 
         $order = Order::create([
@@ -130,7 +131,8 @@ class OrderController extends BaseController
             'order_number' => $this->model->createOrderNumber(),
             'project_id' => $project->id,
             'user_id' => $user->id,
-            'project_role_id' => $project_role_id,
+            'project_role_id' => $project_role ? $project_role['id'] : '',
+            'level' => $project_role ? $project_role['level'] : '',
             'type' => 2,
             'is_change' => 2
         ]);
@@ -141,6 +143,7 @@ class OrderController extends BaseController
                 'name' => $device['name'],
                 'order_id' => $order->id,
                 'project_id' => $order->project_id,
+                'user_id' => $order->user_id,
                 'inner_device_id' => $device['id'],
                 'start_date' => $device['start_date'],
                 'end_date' => $device['end_date']
@@ -164,7 +167,7 @@ class OrderController extends BaseController
         $order = $this->model->find($request->input('id'));
         if(!$order) return $this->error(['msg' => '找不到订单']);
         $user = Auth::guard('mini')->user();
-        $project_role_id = $request->input('is_draft') == 1 ? ProjectRole::getByKey('work', 'id') : ProjectRole::getByKey('machine', 'id');
+        $project_role = ProjectRole::getCreateRole('rent', $request->input('is_draft'));
         $option = Option::get('orders', 'status', 'checking');
         $res = $order->update([
             'work_point_id' => $request->input('work_point_id'),
@@ -173,7 +176,8 @@ class OrderController extends BaseController
             'status' => $option,
             'order_number' => $this->model->createOrderNumber(),
             'user_id' => $user->id,
-            'project_role_id' => $project_role_id
+            'project_role_id' => $project_role ? $project_role['id'] : '',
+            'level' => $project_role ? $project_role['level'] : ''
         ]);
         if(!$res) return $this->error(['msg' => '订单修改失败']);
         $devices = $request->input('devices');
@@ -201,7 +205,7 @@ class OrderController extends BaseController
         $order = $this->model->find($request->input('id'));
         if(!$order) return $this->error(['msg' => '找不到订单']);
         $user = Auth::guard('mini')->user();
-        $project_role_id = $request->input('is_draft') == 1 ? ProjectRole::getByKey('work', 'id') : ProjectRole::getByKey('machine', 'id');
+        $project_role = ProjectRole::getCreateRole('apply', $request->input('is_draft'));
         $type = $request->input('type');
         $option = Option::get('orders', 'status', 'checking');
         if($type == 'back') {
@@ -214,7 +218,8 @@ class OrderController extends BaseController
             'is_draft' => $request->input('is_draft'),
             'status' => $option,
             'user_id' => $user->id,
-            'project_role_id' => $project_role_id
+            'project_role_id' => $project_role ? $project_role['id'] : '',
+            'level' => $project_role ? $project_role['level'] : '',
         ]);
         if(!$res) return $this->error(['msg' => '订单修改失败']);
         $devices = $request->input('devices');
@@ -255,9 +260,12 @@ class OrderController extends BaseController
 
     public function get(Request $request)
     {
+        $user = Auth::guard('mini')->user();
+        $level = $user->getLevel($request->input('project_id'));
         $items = $this->model->join('users', 'orders.user_id', '=', 'users.id')->select('orders.*', 'users.id as user_id', 'users.name');
         $search_items = [
-            ['project_id', $request->input('project_id')]
+            ['project_id', $request->input('project_id')],
+            ['level', '>=', $level]
         ];
         $is_draft = $request->input('is_draft');
         if($is_draft) {
@@ -302,27 +310,40 @@ class OrderController extends BaseController
 
     public function detail(Request $request)
     {
-        $order = $this->model->with('project', 'workPoint', 'devices', 'user', 'innerDevices')->find($request->input('id'));
+        $order = $this->model->with('project', 'workPoint', 'user', 'innerDevices', 'order_devices')->find($request->input('id'));
         if(!$order) return $this->error(['msg' => '找不到订单']);
         $this->formatOrder($order);
         foreach($order['innerDevices'] as $device) {
+            $device->device = Device::find($device->device_id);
+            $device->device_name = DeviceName::find($device->device_name_id);
             $device->status = Option::find($device->status);
             $device->spec = Spec::find($device->spec);
             $device->work_point = WorkPoint::find($device->work_point_id);
         }
+        foreach($order['order_devices'] as $order_device) {
+            $order_device->device_type = Device::find($order_device->device_id);
+            $order_device->device_name = DeviceName::find($order_device->device_name_id);
+            $order_device->spec = Spec::find($order_device->spec_id);
+            $order_device->rent_type = RentType::find($order_device->rent_type_id);
+        }
         return $this->success(['data' => $order]);
     }
 
     public function getRole(Request $request)
     {
         $user = Auth::guard('mini')->user();
-        $order = $this->model->find($request->input('id'));
-        if(!$order) return $this->error(['msg' => '找不到订单']);
         $project_user = ProjectUser::where([
-            ['project_id', '=', $order->project_id],
+            ['project_id', '=', $request->input('id')],
             ['user_id', '=', $user->id]
-        ])->with('projectRole')->first();
-        return $this->success(['data' => $project_user]);
+        ])->first();
+        $project_role = null;
+        if($project_user) {
+            $project_role = ProjectRole::find($project_user->project_role_id);
+            if($project_role) {
+                $project_role->rights = $project_role->getRights();
+            }
+        }
+        return $this->success(['data' => $project_role]);
     }
 
     public function check(Request $request)
@@ -338,37 +359,63 @@ class OrderController extends BaseController
         $project_role = ProjectRole::find($project_user->project_role_id);
         if(!$project_role) return $this->error(['msg' => '找不到角色']);
         $status = Option::get('orders', 'status', $request->input('type'));
-
+        $next_project_role = null;
         $is_inner = $order->type == 2;
+        $new_order = null;
         // 工区负责人确认通过
         if($request->input('type') == 'pass') {
             $status = Option::get('orders', 'status', 'pass');
-            $next_project_role_id = $project_role->id;
+            $next_project_role = $project_role;
         } else if($request->input('type') == 're-submit') {
             $status = Option::get('orders', 'status', 'checking');
-            $next_project_role_id = $project_role->getNext('id', $is_inner);
+            $next_project_role = $project_role->getNext(null, $is_inner);
         } else if($request->input('type') == 'reject') {
-            if($is_inner) {
-                $next_project_role_id = ProjectRole::getByKey('machine', 'id');
+            $next_project_role = ProjectRole::getFirstRole($order);
+        } else if($request->input('type') == 'back') {
+            $new_order = $order->backInnerDevices($request->input('devices'));
+            // 没有返回新订单,是全部归还
+            if(!$new_order) {
+                $status = Option::get('orders', 'status', 'pass');
+                // 全部归还,下一角色改为最高角色
+                $next_project_role = ProjectRole::getLastRole($order);
             } else {
-                $next_project_role_id = ProjectRole::getByKey('work', 'id');
+                // 部分归还,状态保持,下一角色保持,上一角色保持
+                $status = $order->status;
+                $next_project_role = ProjectRole::find($order->project_role_id);
+                $project_role = ProjectRole::find($order->last_project_role_id);
             }
-        } else if($request->input('type') == 'back') {
-            $next_project_role_id = $project_role->id;
-            $order->backInnerDevices();
         } else {
             // 审核
-            $next_project_role_id = $project_role->getNext('id', $is_inner);
+            $next_project_role = $project_role->getNext(null, $is_inner);
         }
         $is_change = $request->input('is_change');
 
+        $level = $next_project_role ? $next_project_role['level'] : '';
+        if($request->input('type') == 'pass') {
+            $last_role = ProjectRole::getLastRole($order);
+            $level = $last_role ? $last_role['level'] : '';
+        }
+
         $res = $order->update([
             'status' => $status,
             'last_project_role_id' => $project_role->id,
-            'project_role_id' => $next_project_role_id,
-            'is_change' => $is_change
+            'project_role_id' => $next_project_role ? $next_project_role['id'] : '',
+            'level' => $level,
+            'is_change' => $is_change,
+            'remark' => $request->input('remark')
         ]);
-        Notification::send($order->id);
+        if($request->input('type') == 'back') {
+            if($new_order) {
+                // 部分归还
+                Notification::send($new_order->id);
+            } else {
+                // 全部归还
+                Notification::send($order->id);
+            }
+        } else {
+            Notification::send($order->id);
+        }
+
         if($res) return $this->success();
         return $this->error(['msg' => '操作失败']);
     }
@@ -391,6 +438,17 @@ class OrderController extends BaseController
         if($request->input('id')) {
             $id = $request->input('id');
             $this->model->where('id', $id)->delete();
+            $inner_device_ids = OrderDevice::where('order_id', $id)->pluck('inner_device_id');
+            if($inner_device_ids) {
+                $free_id = Option::get('inner_devices', 'status', 'free');
+                InnerDevice::where('id', $inner_device_ids)->update([
+                    'status' => $free_id,
+                    'start_date' => null,
+                    'end_date' => null,
+                    'work_point_id' => ''
+                ]);
+            }
+            Notification::where('order_id', $id)->delete();
             OrderDevice::where('order_id', $id)->delete();
         }
         return $this->success();

+ 22 - 0
app/Http/Controllers/Api/mini/OrderDeviceController.php

xqd
@@ -0,0 +1,22 @@
+<?php
+
+namespace App\Http\Controllers\Api\mini;
+
+use App\Models\OrderDevice;
+use Illuminate\Http\Request;
+
+class OrderDeviceController extends BaseController
+{
+    protected $model;
+
+    public function __construct()
+    {
+        $this->model = new OrderDevice();
+    }
+
+    public function get(Request $request)
+    {
+        $items = $this->model->with('project', 'user')->where('inner_device_id', $request->input('id'))->orderBy('created_at', 'desc')->get();
+        return $this->success(['data' => $items]);
+    }
+}

+ 18 - 0
app/Http/Controllers/Api/mini/ProjectRoleController.php

xqd
@@ -63,4 +63,22 @@ class ProjectRoleController extends BaseController
 
         return $this->success(['msg' => '创建成功', 'data' => $items]);
     }
+
+    public function getRoleAndRights(Request $request)
+    {
+        $user = Auth::guard('mini')->user();
+        if (!$user || !$request->input('id')) return $this->success(['data' => null]);
+        $project_user = ProjectUser::where([
+            ['user_id', $user->id],
+            ['project_id', $request->input('id')]
+        ])->first();
+        if ($project_user) {
+            $project_role = ProjectRole::find($project_user->project_role_id);
+            if ($project_role) {
+                $project_role->rights = $project_role->getRights();
+                return $this->success(['msg' => '创建成功', 'data' => $project_role]);
+            }
+        }
+        return $this->success(['data' => null]);
+    }
 }

+ 47 - 0
app/Http/Controllers/Api/mini/RightController.php

xqd
@@ -0,0 +1,47 @@
+<?php
+
+namespace App\Http\Controllers\Api\mini;
+
+use App\Models\Order;
+use App\Models\ProjectRole;
+use App\Models\ProjectRoleRight;
+use App\Models\ProjectUser;
+use App\Models\Right;
+use Illuminate\Http\Request;
+use Illuminate\Support\Facades\Auth;
+
+class RightController extends BaseController
+{
+    protected $model;
+
+    public function __construct()
+    {
+        $this->model = new Right();
+    }
+
+    public function get(Request $request)
+    {
+        $rights = $this->model->all();
+        $user = Auth::guard('mini')->user();
+        $order = Order::find($request->input('order_id'));
+        $project_role = null;
+        if($user && $project_role) {
+            $order_user = ProjectUser::where('project_id', $order->project_id)->where('user_id', $user->id)->first();
+            if($order_user) {
+                $project_role = ProjectRole::find(ProjectRole::find($order_user->project_role_id));
+            }
+        }
+        $items = [];
+        foreach($rights as $right) {
+            $has_right = false;
+            if($project_role) {
+                $has_right = ProjectRoleRight::where([
+                    ['project_role_id', $project_role->id],
+                    ['right_id', $right->id]
+                ])->first() != null;
+            }
+            $items[$right->key] = $has_right;
+        }
+        return $this->success(['data' => $items]);
+    }
+}

+ 4 - 0
app/Http/Controllers/Api/mini/UserController.php

xqd
@@ -77,6 +77,10 @@ class UserController extends BaseController
         $user = Auth::guard('mini')->user();
 
         $project_role = $user->getTopRole();
+        if($project_role) {
+            $project_role->rights = $project_role->getRights();
+        }
+
         return $this->success(['data' => $project_role]);
     }
 

+ 2 - 2
app/Models/BaseModel.php

xqd
@@ -50,9 +50,9 @@ class BaseModel extends Model
     public function getValidator(Request $request, $type)
     {
         $validator = Validator::make($request->input('data'), [
-            'user_id' => 'required'
+            'name' => 'required'
         ], [
-            'user_id.required' => '用户必填'
+            'name.required' => '名称必填'
         ]);
         return $validator;
     }

+ 6 - 3
app/Models/Notification.php

xqd xqd xqd
@@ -17,7 +17,7 @@ class Notification extends BaseModel
         $role = ProjectRole::find($order['project_role_id']);
         $status = 1;
         $user_ids = [];
-        $project_role_ids = [$role['id']];
+        $project_role_ids = ProjectRole::where('level', $order['level'])->pluck('id');
         if($overdue) {
             // 调用时间到期
             $role = ProjectRole::getFirstRole($order);
@@ -25,10 +25,13 @@ class Notification extends BaseModel
         } else if($order['status'] == $pass_id) {
             // 租赁完成,调用完成
             if($order['type'] == 1) {
+                // 租赁完成
                 $project_role_ids = ProjectRole::whereIn('key', ['manager'])->pluck('id');
             } else if($order['is_change' == 2]) {
+                // 调用完成且未修改
                 $project_role_ids = ProjectRole::whereIn('key', ['machine', 'admin'])->pluck('id');
             } else {
+                // 调用完成且修改
                 $project_role_ids = ProjectRole::whereIn('key', ['machine'])->pluck('id');
             }
         } else if($order['status'] == $back_id) {
@@ -57,9 +60,9 @@ class Notification extends BaseModel
         } else {
             // 调用
             // 调用成功
-            if($order['status'] == $checked_id && $role && $last_role && $last_role['key'] == 'admin') {
+            if($order['status'] == $checked_id && $role && $last_role && in_array($last_role['key'], ['admin', 'sub'])) {
                 $status = $order['is_change'] == 1 ? 7 : 1;
-            } else if($role && in_array($role['key'], ['assist', 'manager', 'admin'])) {
+            } else if($role && in_array($role['key'], ['assist', 'manager', 'sub', 'admin'])) {
                 // 调用待处理
                 $status = 2;
             } else if($order['status'] == $reject_id) {

+ 43 - 5
app/Models/Order.php

xqd xqd
@@ -105,16 +105,49 @@ class Order extends BaseModel
         $item->date_time = substr($item->created_at, 0, 16);
     }
 
-    public function backInnerDevices()
+    public function backInnerDevices($devices)
     {
+        $back_devices = [];
+        $back_device_ids = [];
+        foreach ($devices as $device) {
+            if(isset($device['checked']) && $device['checked']) {
+                array_push($back_devices, $device);
+                array_push($back_device_ids, $device['id']);
+            }
+        }
+
+        $new_order = null;
+
+        if(count($back_devices) < count($devices)) {
+            $status = Option::get('orders', 'status', 'pass', 'id');
+            $last_role = ProjectRole::getLastRole($this);
+            $level = $last_role ? $last_role['level'] : '';
+            $new_order = Order::create([
+                'work_point_id' => $this['work_point_id'],
+                'remark' => $this['remark'],
+                'money' => $this['money'],
+                'is_draft' => $this['is_draft'],
+                'status' => $status,
+                'order_number' => self::createOrderNumber(),
+                'project_id' => $this['project_id'],
+                'user_id' => $this['user_id'],
+                'project_role_id' => $this['project_role_id'],
+                'level' => $level,
+                'last_project_role_id' => $this['last_project_role_id'],
+                'last_user_id' => $this['last_user_id'],
+                'is_change' => $this['is_change'],
+                'type' => $this['type']
+            ]);
+            OrderDevice::where('order_id', $this['id'])->whereIn('inner_device_id', $back_device_ids)->update(['order_id' => $new_order->id]);
+        }
         $free_id = Option::get('inner_devices', 'status', 'free');
-        $device_ids = $this['innerDevices']->pluck('id');
-        InnerDevice::whereIn('id', $device_ids)->update([
+        InnerDevice::whereIn('id', $back_device_ids)->update([
             'status' => $free_id,
-            'start_date' => '',
-            'end_date' => '',
+            'start_date' => null,
+            'end_date' => null,
             'work_point_id' => ''
         ]);
+        return $new_order;
     }
 
     /**
@@ -126,4 +159,9 @@ class Order extends BaseModel
         if($this['type'] == 1) return 2;
         $devices = $request->input('devices');
     }
+
+    public function order_devices()
+    {
+        return $this->hasMany('App\Models\OrderDevice', 'order_id');
+    }
 }

+ 10 - 0
app/Models/OrderDevice.php

xqd
@@ -8,4 +8,14 @@ class OrderDevice extends BaseModel
     {
         return $this->belongsTo('App\Models\Device', 'device_id');
     }
+
+    public function project()
+    {
+        return $this->belongsTo('App\Models\Project', 'project_id');
+    }
+
+    public function user()
+    {
+        return $this->belongsTo('App\Models\User', 'user_id');
+    }
 }

+ 1 - 1
app/Models/Project.php

xqd
@@ -9,7 +9,7 @@ class Project extends BaseModel
 
     public function getManager()
     {
-        $role = ProjectRole::where('name', '经理')->first();
+        $role = ProjectRole::getByKey('manager');
         if(!$role) return null;
         $res = ProjectUser::where([
             ['project_id', '=', $this['id']],

+ 57 - 12
app/Models/ProjectRole.php

xqd xqd xqd
@@ -2,6 +2,8 @@
 
 namespace App\Models;
 
+use Illuminate\Support\Facades\Auth;
+
 class ProjectRole extends BaseModel
 {
     /**
@@ -25,17 +27,16 @@ class ProjectRole extends BaseModel
 
     public function getNext($column = null, $inner = false)
     {
-        $need_check = $inner ? 'need_check_inner' : 'need_check';
-        $item = $this->where([
-            [$need_check, '=', 1],
-            ['id', '>', $this['id']]
-        ])->first();
-        if(!$inner && $this['key'] == 'manager') {
-            $item = self::getByKey('work');
-        } else if($inner && $this['key'] == 'admin') {
-            $item = self::getByKey('machine');
+        $right_key = $inner ? 'applyHandle' : 'rentHandle';
+        $right = Right::where('key', $right_key)->first();
+        $project_role = null;
+        if($right) {
+            $project_role_ids = ProjectRoleRight::where('right_id', $right->id)->pluck('project_role_id');
+            $project_role = ProjectRole::whereIn('id', $project_role_ids)->where('level', '>', $this['level'])->orderBy('level')->first();
+            if(!$project_role) $project_role = ProjectRole::whereIn('id', $project_role_ids)->orderBy('level')->first();
         }
-        return $column ? ($item ? $item[$column] : '') : $item;
+
+        return $column ? ($project_role ? $project_role[$column] : '') : $project_role;
     }
 
     public static function getOptions()
@@ -45,11 +46,55 @@ class ProjectRole extends BaseModel
 
     public static function getFirstRole(Order $order)
     {
-        return $order['type'] == 1 ? $role = self::getByKey('work') : self::getByKey('machine');
+        return self::getFirstOrLastRole($order, 'asc');
     }
 
     public static function getLastRole(Order $order)
     {
-        return $order['type'] == 1 ? $role = self::getByKey('manager') : self::getByKey('admin');
+        return self::getFirstOrLastRole($order, 'desc');
+    }
+
+    public static function getFirstOrLastRole(Order $order, $order_by)
+    {
+        $right_key = $order['type'] == 1 ? 'rentHandle' : 'applyHandle';
+        $right = Right::where('key', $right_key)->first();
+        $project_role = null;
+        if($right) {
+            $project_role_ids = ProjectRoleRight::where('right_id', $right->id)->pluck('project_role_id');
+            $project_role = ProjectRole::whereIn('id', $project_role_ids)->orderBy('level', $order_by)->first();
+        }
+        return $project_role;
+    }
+
+    public function getRights()
+    {
+        $rights = Right::all();
+        $items = [];
+        foreach($rights as $right) {
+            $has_right = ProjectRoleRight::where([
+                ['project_role_id', $this['id']],
+                ['right_id', $right->id]
+            ])->first() != null;
+            $items[$right->key] = $has_right;
+        }
+        return $items;
+    }
+
+    /**
+     * @param $type (rent外部租赁|apply内部调用)
+     * @param $is_draft (1是2否)
+     * @return ProjectRole
+     */
+    public static function getCreateRole($type, $is_draft)
+    {
+        $right_key = $type == 'rent' ? 'rentHandle' : 'applyHandle';
+        $right = Right::where('key', $right_key)->first();
+        if($right) {
+            $project_role_ids = ProjectRoleRight::where('right_id', $right->id)->pluck('project_role_id');
+            $project_role = ProjectRole::whereIn('id', $project_role_ids)->orderBy('level')->first();
+            if($is_draft == 1) return $project_role;
+            if($project_role && $is_draft == 2) return ProjectRole::whereIn('id', $project_role_ids)->where('level', '>', $project_role->level)->orderBy('level')->first();
+        }
+        return null;
     }
 }

+ 8 - 0
app/Models/ProjectRoleRight.php

xqd
@@ -0,0 +1,8 @@
+<?php
+
+namespace App\Models;
+
+class ProjectRoleRight extends BaseModel
+{
+    //
+}

+ 8 - 0
app/Models/Right.php

xqd
@@ -0,0 +1,8 @@
+<?php
+
+namespace App\Models;
+
+class Right extends BaseModel
+{
+    //
+}

+ 16 - 3
app/Models/User.php

xqd
@@ -97,8 +97,21 @@ class User extends Authenticatable
 
     public function getTopRole()
     {
-        $project_user = ProjectUser::where('user_id', $this['id'])->orderBy('project_role_id', 'desc')->first();
-        if(!$project_user) return null;
-        return ProjectRole::find($project_user->project_role_id);
+        $project_role_ids = ProjectUser::where('user_id', $this['id'])->pluck('project_role_id');
+        $project_role = ProjectRole::whereIn('id', $project_role_ids)->orderBy('level', 'desc')->first();
+        return $project_role;
+    }
+
+    public function getLevel($project_id)
+    {
+        $project_user = ProjectUser::where([
+            ['user_id', $this['id']],
+            ['project_id', $project_id]
+        ])->first();
+        if($project_user) {
+            $project_role = ProjectRole::find($project_user->project_role_id);
+            return $project_role ? $project_role['level'] : 0;
+        }
+        return 0;
     }
 }

+ 34 - 0
database/migrations/2020_12_30_170204_create_rights_table.php

xqd
@@ -0,0 +1,34 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class CreateRightsTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('rights', function (Blueprint $table) {
+            $table->increments('id');
+            $table->string('name', 200)->nullable();
+            $table->string('key', 200)->nullable();
+            $table->unsignedInteger('sort')->nullable();
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('rights');
+    }
+}

+ 33 - 0
database/migrations/2020_12_30_174206_create_project_role_rights_table.php

xqd
@@ -0,0 +1,33 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class CreateProjectRoleRightsTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('project_role_rights', function (Blueprint $table) {
+            $table->increments('id');
+            $table->unsignedInteger('right_id')->nullable();
+            $table->unsignedInteger('project_role_id')->nullable();
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('project_role_rights');
+    }
+}

+ 30 - 0
database/migrations/2021_01_01_105700_add_level_to_orders.php

xqd
@@ -0,0 +1,30 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class AddLevelToOrders extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('orders', function (Blueprint $table) {
+            $table->unsignedInteger('level')->after('project_role_id')->comment('审核级别')->nullable();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        //
+    }
+}

+ 30 - 0
database/migrations/2021_01_03_230906_add_user_id_to_order_devices.php

xqd
@@ -0,0 +1,30 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class AddUserIdToOrderDevices extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('order_devices', function (Blueprint $table) {
+            $table->unsignedInteger('user_id')->after('order_id')->nullable();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        //
+    }
+}

+ 42 - 0
database/seeds/RightSeeder.php

xqd
@@ -0,0 +1,42 @@
+<?php
+
+use Illuminate\Database\Seeder;
+
+class RightSeeder extends Seeder
+{
+    /**
+     * Run the database seeds.
+     *
+     * @return void
+     */
+    public function run()
+    {
+        $items = [
+            ['name' => '租赁订单申请权限', 'key' => 'rentCreate'],
+            ['name' => '租赁订单操作权限', 'key' => 'rentHandle'],
+            ['name' => '租赁订单审核权限', 'key' => 'rentCheck'],
+            ['name' => '租赁订单金额修改权限', 'key' => 'rentMoneyChange'],
+            ['name' => '租赁订单金额确认权限', 'key' => 'rentMoneyConfirm'],
+            ['name' => '租赁订单查看权限', 'key' => 'rentView'],
+            ['name' => '调用订单申请权限', 'key' => 'applyCreate'],
+            ['name' => '调用订单操作权限', 'key' => 'applyHandle'],
+            ['name' => '调用订单审核权限', 'key' => 'applyCheck'],
+            ['name' => '调用订单修订权限', 'key' => 'applyEdit'],
+            ['name' => '设备管理查看权限', 'key' => 'deviceView'],
+            ['name' => '维修上报权限', 'key' => 'repairReport'],
+            ['name' => '项目新建权限', 'key' => 'newProject'],
+            ['name' => '人员添加权限', 'key' => 'memberAdd'],
+            ['name' => '人员管理权限', 'key' => 'memberManage'],
+            ['name' => '数据中心查看权限', 'key' => 'dataView'],
+        ];
+        \App\Models\Right::truncate();
+        \App\Models\ProjectRoleRight::truncate();
+        foreach ($items as $key => $item) {
+            \App\Models\Right::create([
+                'name' => $item['name'],
+                'key' => $item['key'],
+                'sort' => ($key + 1)
+            ]);
+        }
+    }
+}

+ 28 - 0
mini/components/inner-device-card/index.js

xqd xqd
@@ -9,6 +9,22 @@ Component({
       type: String,
       // record
       value: ''
+    },
+    showStatus: {
+      type: Boolean,
+      value: true
+    },
+    showChecked: {
+      type: Boolean,
+      value: false
+    },
+    showDelete: {
+      type: Boolean,
+      value: false
+    },
+    index: {
+      type: String,
+      value: ''
     }
   },
 
@@ -29,5 +45,17 @@ Component({
         url: url,
       })
     },
+    switchChecked: function(e) {
+      var index = e.currentTarget.dataset.index
+      this.triggerEvent('checked', {
+        index
+      }, {})
+    },
+    delete: function(e) {
+      var index = e.currentTarget.dataset.index
+      this.triggerEvent('delete', {
+        index
+      }, {})
+    }
   }
 })

+ 8 - 1
mini/components/inner-device-card/index.wxml

xqd
@@ -3,10 +3,17 @@
   <view class="sg-top sg-flex sg-space-between sg-bottom-border sg-pad-bottom-sm sg-font-small sg-bold">
     <view class="sg-name">{{item.device ? item.device.name : ''}} - {{item.device_name ? item.device_name.name : ''}}
     </view>
-    <view class="sg-status sg-flex sg-align-center">
+    <view class="sg-status sg-flex sg-align-center" wx:if="{{showStatus}}">
       <view class="sg-dot" style="background: {{item.status ? item.status.color : ''}}"></view>
       <view class="sg-status-name">{{item.status ? item.status.name : ''}}</view>
     </view>
+    <view class="sg-status sg-flex sg-align-center sg-font-lg" wx:if="{{showChecked}}" bindtap="switchChecked" data-index="{{index}}">
+      <van-icon name="passed" wx:if="{{item.checked}}" class="sg-index-color" />
+      <van-icon name="circle" wx:else />
+    </view>
+    <view class="sg-status sg-flex sg-align-center sg-font-lg" wx:if="{{showDelete}}" bindtap="delete" data-index="{{index}}">
+      <van-icon name="clear" />
+    </view>
     <van-icon class="sg-action sg-index-color sg-icon" wx:if="{{action=='record'}}" name="notes-o" bindtap="navigate" data-url="/pages/use-record/index?id={{item.id}}"></van-icon>
   </view>
   <view class="sg-body sg-font-xs sg-bottom-border sg-pad-bottom-sm">

+ 5 - 1
mini/components/inner-order-item/index.js

xqd
@@ -7,7 +7,11 @@ Component({
    */
   properties: {
     item: Object,
-    role: Object
+    role: Object,
+    showDelete: {
+      type: Boolean,
+      value: true
+    }
   },
 
   /**

+ 2 - 14
mini/components/inner-order-item/index.wxml

xqd
@@ -29,26 +29,14 @@
     </view>
     <view>
       <block
-        wx:if="{{(item.status_key=='reject' || item.status_key=='checking') && (role && role.project_role.key == 'machine')}}">
+        wx:if="{{(item.status_key=='reject' || item.status_key=='checking' || item.is_draft == 1) && (role && role.key == 'machine') && showDelete}}">
         <view class="sg-right sg-red-bg sg-pad-sm sg-white sg-margin-bottom" catchtap="doAction" data-type="delete"
           data-order="{{item}}">删除订单</view>
       </block>
-      <block wx:if="{{item.status=='管理员 - 已审核' && role && role.project_role.key == 'machine'}}">
-        <view class="sg-right sg-green-bg sg-pad-sm sg-white" catchtap="doAction" data-type="confirm"
-          data-order="{{item}}">确认订单</view>
-      </block>
-      <block wx:elif="{{item.status_key=='reject'}}">
+      <block wx:if="{{item.status_key=='reject'}}">
         <view class="sg-right sg-red-bg sg-pad-sm sg-white" catchtap="doAction" data-type="edit"
           data-url="/pages/create-order-inner/index?id={{item.project_id}}&order_id={{item.id}}&type=edit">重新修订</view>
       </block>
-      <!-- <block wx:elif="{{item.status_key=='pass' && role && role.project_role && role.project_role.key=='machine'}}">
-            <view class="sg-right sg-index-bg sg-pad-sm sg-white" catchtap="doAction" data-type="edit"
-              data-url="/pages/create-order-inner/index?id={{item.project_id}}&order_id={{item.id}}&type=edit">查看详情</view>
-          </block>
-          <block wx:elif="{{item.status_key=='checked' && role && role.project_role && role.project_role.key=='admin'}}">
-            <view class="sg-right sg-index-bg sg-pad-sm sg-white" catchtap="doAction" data-type="edit"
-              data-url="/pages/create-order-inner/index?id={{item.project_id}}&order_id={{item.id}}&type=edit">查看详情</view>
-          </block> -->
       <block wx:else>
         <view class="sg-right sg-index-bg sg-pad-sm sg-white" catchtap="doAction" data-type="edit"
           data-url="/pages/create-order-inner/index?id={{item.project_id}}&order_id={{item.id}}&type=edit">查看详情</view>

+ 5 - 2
mini/components/out-order-item/index.js

xqd xqd
@@ -7,7 +7,11 @@ Component({
    */
   properties: {
     item: Object,
-    role: Object
+    role: Object,
+    showDelete: {
+      type: Boolean,
+      value: true
+    }
   },
 
   /**
@@ -31,7 +35,6 @@ Component({
       var type = e.currentTarget.dataset.type
       var that = this
       var order = e.currentTarget.dataset.order
-      console.log(type)
       if(type == 'edit' || type == 'detail') {
         this.navigate(e)
       } else if(type == 'confirm') {

+ 1 - 1
mini/components/out-order-item/index.wxml

xqd
@@ -25,7 +25,7 @@
     </view>
     <view>
       <block
-        wx:if="{{(item.status_key=='reject' || item.status_key=='checking') && (role && role.project_role.key == 'work')}}">
+        wx:if="{{(item.status_key=='reject' || item.status_key=='checking') && (role && role.key == 'work') && showDelete}}">
         <view class="sg-right sg-red-bg sg-pad-sm sg-white sg-font-xs sg-margin-bottom" catchtap="doAction"
           data-type="delete" data-order="{{item}}">
           删除订单</view>

+ 4 - 2
mini/custom-tab-bar/index.js

xqd
@@ -48,9 +48,11 @@ Component({
 				list: list
 			})
 			this.setData({
-				active: this.data.list.findIndex(item => item.url === `/${page.route}`),
-				role: role
+				active: this.data.list.findIndex(item => item.url === `/${page.route}`)
 			});
+			if(role) {
+				this.setData({role})
+			}
 		}
 	}
 });

+ 7 - 6
mini/pages/account/index.js

xqd xqd
@@ -15,12 +15,7 @@ Page({
    * 生命周期函数--监听页面加载
    */
   onLoad: function (options) {
-    if (app.globalData.userInfo) {
-      this.setData({
-        userInfo: app.globalData.userInfo,
-        hasUserInfo: true
-      })
-    }
+    
   },
 
   navigate: function (e) {
@@ -50,6 +45,12 @@ Page({
    */
   onShow: function () {
     this.getTabBar().init();
+    if (app.globalData.userInfo) {
+      this.setData({
+        userInfo: app.globalData.userInfo,
+        hasUserInfo: true
+      })
+    }
   },
 
   /**

+ 2 - 1
mini/pages/add-inner-device/index.js

xqd
@@ -160,7 +160,8 @@ Page({
         device_id: this.data.type,
         device_name_id: this.data.name,
         spec_id: this.data.spec,
-        page: this.data.page
+        page: this.data.page,
+        free: true
       },
       success: function (res) {
         if (res.code == 0) {

+ 58 - 10
mini/pages/create-order-inner/index.js

xqd xqd xqd xqd xqd xqd xqd xqd
@@ -26,7 +26,8 @@ Page({
     // 审核(check)|确认(pass)|重新提交(re-submit)|退回(back)
     actionType: null,
     order: null,
-    canEdit: true
+    canEdit: true,
+    showBack: false
   },
 
   /**
@@ -57,7 +58,7 @@ Page({
       var that = this
 
       api.getByName(this, 'orders/detail', 'order', { id: order_id }, function (res) {
-        api.getByName(that, 'orders/getRole', 'role', { id: order_id }, function (res) {
+        api.getByName(that, 'orders/getRole', 'role', { id: that.data.order ? that.data.order.project_id : '' }, function (res) {
           that.updateActionType()
           that.initData()
         });
@@ -72,13 +73,12 @@ Page({
     var actionType = ''
     var role = this.data.role
     var order = this.data.order
-    if (order.project_role_id == role.id) {
-      if (order.status_key == 'checking' && role.project_role.key == 'assist') actionType = 'check'
-      else if (order.status_key == 'checked' && ['manager', 'admin'].indexOf(role.project_role.key) != -1) actionType = 'check'
-      else if (order.status_key == 'reject' && role.project_role.key == 'machine') actionType = 're-submit'
-      else if (order.status_key == 'pass' && role.project_role.key == 'machine') actionType = 'back'
+    if (order.level == role.level) {
+      if(['checking', 'checked'].indexOf(order.status_key) != -1 && role && role.rights && role.rights.applyCheck) actionType = 'check';
+      else if (order.status_key == 'reject' && role.key == 'machine') actionType = 're-submit'
+      else if (order.status_key == 'checked' && role.key == 'machine') actionType = 'back'
     }
-    var canEdit = actionType == 'check' && role.project_role.key == 'admin' || (actionType == 're-submit');
+    var canEdit = (actionType == 're-submit');
     if (order.is_draft == 1) {
       canEdit = true
       actionType = 'edit'
@@ -95,13 +95,33 @@ Page({
     })
   },
 
+  switchChecked: function(e) {
+    var index = e.detail.index
+    var devices = this.data.devices
+    devices[index].checked = !devices[index].checked
+    this.setData({
+      devices
+    })
+  },
+
+  switchShow: function(e) {
+    var name = e.currentTarget.dataset.name
+    var val = this.data[name]
+    this.setData({
+      [name]: !val
+    })
+  },
+
   check: function (e) {
     var type = e.currentTarget.dataset.type
     var that = this
     var msg = '确认通过审核吗?'
     if (type == 'reject') msg = '确认驳回申请吗?'
     else if (type == 'pass' || type == 're-submit') msg = '确认提交吗?'
-    else if (type == 'back') msg = '确认归还吗?'
+    else if (type == 'back') {
+      this.switchShow(e)
+      return false
+    }
     Dialog.confirm({
       title: '提示',
       message: msg,
@@ -118,6 +138,21 @@ Page({
       util.error('请选择调用设备');
       return false;
     }
+    if(type == 'back') {
+      var devices = this.data.devices
+      var find = false;
+      for(var i = 0; i < devices.length; ++i) {
+        if(devices[i].checked) {
+          find = true;
+          break;
+        }
+      }
+      if(!find) {
+        util.error('归还设备不能为空');
+        return false;
+      }
+      this.switchShow(e)
+    }
     http({
       url: 'orders/check',
       data: {
@@ -172,6 +207,7 @@ Page({
     var work_point = this.data.work_points[this.data.pointIndex]
     var url = (submit_type == 'create' || type == 're-rent') ? 'orders/createInner' : 'orders/updateInner'
     wx.setStorageSync('sg-added-devices', [])
+    var that = this
     http({
       url: url,
       data: {
@@ -186,6 +222,18 @@ Page({
       success: function (res) {
         if (res.code == 0) {
           util.success('操作成功')
+          setTimeout(function() {
+            var url = '/pages/order-inner/index?id=' + that.data.id
+            if(is_draft == 1) {
+              wx.navigateBack({
+                delta: 0,
+              })
+            } else {
+              wx.redirectTo({
+                url: url,
+              })
+            }
+          }, 1000)
         }
       }
     })
@@ -236,7 +284,7 @@ Page({
       content: "是否确定删除",
       success: (res) => {
         if (res.confirm) {
-          var index = e.currentTarget.dataset.index
+          var index = e.detail.index
           var devices = this.data.devices
           devices.splice(index, 1)
           this.setData({

+ 13 - 35
mini/pages/create-order-inner/index.wxml

xqd xqd xqd
@@ -41,12 +41,21 @@
       </block>
       <view class="sg-form-item sg-pad sg-top-border">
         <view class="sg-label">备注</view>
-        <input value="{{remark}}" class="sg-input" bindinput="onChange" data-name="remark" placeholder="订单备注填写"
-          disabled="{{!canEdit}}"></input>
+        <input value="{{remark}}" class="sg-input" bindinput="onChange" data-name="remark" placeholder="订单备注填写"></input>
       </view>
     </view>
   </view>
   <van-dialog id="van-dialog" />
+  <van-popup show="{{ showBack }}" bind:close="onClose" custom-style="width: 90%">
+    <view class="sg-title sg-text-center sg-bold sg-font-lg sg-pad-tb sg-border-bottom">选择归还的设备</view>
+    <view class="sg-list">
+      <inner-device-card  wx:for="{{devices}}" wx:key="index" item="{{item}}"  data-index="{{index}}" showStatus="{{false}}" showChecked="{{true}}" bind:checked="switchChecked" index="{{index}}"></inner-device-card>
+    </view>
+    <view class="sg-btns sg-flex">
+      <van-button type="default" class="sg-btn" block bindtap="switchShow" data-name="showBack">取消</van-button>
+      <van-button type="danger" class="sg-btn" block bindtap="submitCheck" data-type="back" data-change="{{false}}" data-name="showBack">确认</van-button>
+    </view>
+  </van-popup>
   <view class="sg-device-box" wx:if="{{tabIndex == 1}}">
     <view class="sg-device-list sg-top-border">
       <block wx:if="{{devices.length <= 0}}">
@@ -68,38 +77,7 @@
           <view class="sg-right sg-red-bg sg-pad sg-flex sg-align-center" bindtap="deleteDevice" data-index="{{index}}">删除</view>
         </view> -->
         <view class="sg-list sg-pad">
-          <view class="sg-item sg-white-bg sg-pad sg-margin-bottom" wx:for="{{devices}}" wx:key="index" data-index="{{index}}" data-can="{{item.status && item.status.key == 'free'}}">
-            <view class="sg-top sg-flex sg-space-between sg-bottom-border sg-pad-bottom-sm sg-font-small sg-bold">
-              <view class="sg-name">{{item.device ? item.device.name : ''}} -
-                {{item.device_name ? item.device_name.name : ''}}
-              </view>
-              <van-icon name="clear" bindtap="deleteDevice" size="20px" />
-            </view>
-            <view class="sg-body sg-font-xs sg-bottom-border sg-pad-bottom-sm">
-              <view class="sg-item sg-margin-tb-sm sg-flex" style=" justify-content: space-between;">
-                <view class="sg-left-item">固定资产编号:{{item.number}}</view>
-                <view class="sg-right-item">出厂日期:{{item.produce_date}}</view>
-              </view>
-              <view class="sg-item sg-margin-tb-sm sg-flex" style=" justify-content: space-between;">
-                <view class="sg-left-item">外形尺寸:{{item.shape}}</view>
-                <view class="sg-right-item">采购原值:{{item.buy_origin}}</view>
-              </view>
-              <view class="sg-item sg-margin-tb-sm sg-flex" style=" justify-content: space-between;">
-                <view class="sg-left-item">规格型号:{{item.spec ? item.spec.name : ''}}</view>
-                <view class="sg-right-item">生产厂家:{{item.manufacturer}}</view>
-              </view>
-            </view>
-            <view class="sg-bottom sg-font-xs">
-              <view class="sg-left" style="display:block">
-                <view class="sg-item sg-margin-tb-sm">目前在用工点:{{item.work_point ? item.work_point.name : '无'}}</view>
-                <view class="sg-item sg-margin-tb-sm">
-                  借用时间:{{item.start_date ? item.start_date + '至' + item.end_date : '无'}}
-                </view>
-              </view>
-              <!-- <view class="sg-white sg-pad-sm {{item.status && item.status.key == 'free' ? 'sg-green-bg' : 'sg-gray-bg'}}">
-          借用设备</view> -->
-            </view>
-          </view>
+          <inner-device-card item="{{item}}" wx:for="{{devices}}" wx:key="index" data-index="{{index}}" showStatus="{{false}}" showDelete="{{canEdit}}" bind:delete="deleteDevice"></inner-device-card>
         </view>
       </block>
     </view>
@@ -140,7 +118,7 @@
     </block>
     <block wx:if="{{actionType == 'back'}}">
       <view class="sg-action sg-draft sg-pad sg-border-right sg-red-bg" bindtap="check" data-change="2"
-        data-type='back'>归还</view>
+        data-type='back' data-name="showBack">归还</view>
       <view class="sg-action sg-pad sg-index-bg sg-green-bg" bindtap="submit" data-change="2" data-type='re-rent'>续租
       </view>
     </block>

+ 3 - 0
mini/pages/create-order-inner/index.wxss

xqd
@@ -43,4 +43,7 @@
 }
 .sg-submit-box.sg-fix-bottom {
   z-index: 1;
+}
+.sg-btns .sg-btn {
+  width: 50%;
 }

+ 50 - 12
mini/pages/create-order/index.js

xqd xqd xqd xqd xqd
@@ -57,6 +57,7 @@ Page({
     var id = options.id ? options.id : 1
     var type = options.type ? options.type : 'create'
     var order_id = options.order_id ? options.order_id : ''
+    var that = this
     this.setData({
       id,
       type,
@@ -67,7 +68,6 @@ Page({
     api.getByName(this, 'devices/getThreeLevel', 'device_types');
     api.getByName(this, 'rent-types/get', 'rent_types');
     if(order_id) {
-      var that = this
       api.getByName(this, 'orders/detail', 'order', {id: order_id}, function(res) {
         that.initData()
       });
@@ -95,18 +95,20 @@ Page({
         break;
       }
     }
-    var devices = order.devices
+    var devices = order.order_devices
     var local_devices = []
     for(var i = 0; i < devices.length; ++i) {
       var device = devices[i]
       local_devices.push({
-        name: device.pivot.name,
-        type_name: device.name,
-        type_id: device.id,
-        quantity: device.pivot.quantity,
-        price: device.pivot.price / 100,
-        start_date: device.pivot.start_date,
-        end_date: device.pivot.end_date
+        type_name: device.device_type ? device.device_type.name : '',
+        type_id: device.device_type ? device.device_type.id : '',
+        name: device.device_name ? device.device_name.name : '',
+        spec: device.spec ? device.spec.name : '',
+        rent: device.rent_type ? device.rent_type.name : '',
+        quantity: device.quantity,
+        price: device.price / 100,
+        start_date: device.start_date,
+        end_date: device.end_date
       })
     }
     this.setData({
@@ -187,15 +189,49 @@ Page({
     var typeIndex = -1
     var device_types = this.data.device_types
     var default_dates = [device.start_date, device.end_date]
+    var names = null
+    var nameIndex = -1
     for(var i = 0; i < device_types.length; ++i) {
       if(device_types[i].id == device.type_id) {
         typeIndex = i;
+        names = device_types[i].names
+        break;
+      }
+    }
+
+    var specs = null
+    var specIndex = -1
+    if(names) {
+      for(var i = 0; i < names.length; ++i) {
+        if(names[i].name == device.name) {
+          specs = names[i].specs
+          nameIndex = i;
+          break;
+        }
+      }
+    }
+    if(specs) {
+      for(var i = 0; i < specs.length; ++i) {
+        if(specs[i].name == device.spec) {
+          specIndex = i;
+          break;
+        }
+      }
+    }
+    var rent_types = this.data.rent_types
+    var rentIndex = -1;
+    for(var i = 0; i < rent_types.length; ++i) {
+      if(rent_types[i].name == device.rent) {
+        rentIndex = i;
         break;
       }
     }
     this.setData({
       device_name: device.name,
       typeIndex,
+      nameIndex,
+      specIndex,
+      rentIndex,
       start_date: device.start_date,
       end_date: device.end_date,
       device_quantity: device.quantity,
@@ -281,13 +317,15 @@ Page({
       devices[this.data.selectIndex] = device
     }
     this.setData({
-      devices
+      devices,
+      typeIndex: -1,
+      nameIndex: -1,
+      specIndex: -1,
+      rentIndex: -1
     })
     this.updateDeviceStat()
   },
   onClose: function(e) {
-    console.log('----------')
-    console.log(e)
     if(e.detail == 'confirm') return false;
     return true
   },

+ 1 - 1
mini/pages/create-order/index.wxml

xqd
@@ -47,7 +47,7 @@
           bindtap="selectDevice" data-index="{{index}}">
           <view class=" sg-flex-grow sg-pad sg-flex-column">
             <view class="sg-left-top sg-flex sg-justify-center sg-space-between">
-              <view class="sg-name">{{item.type_name}}-{{item.name}}</view>
+              <view class="sg-name">{{item.type_name}}-{{item.name}}-{{item.spec}}</view>
               <view class="sg-left-right sg-quantity-price sg-red-color" style="color:red">
                 ¥<text>{{item.price*item.quantity}}</text>
               </view>

+ 1 - 1
mini/pages/device-inner/index.wxml

xqd
@@ -1,7 +1,7 @@
 <!--pages/device-inner/index.wxml-->
 <view class="sg-container">
   <view class="sg-top sg-fix-top">
-    <van-search value="{{ number }}" placeholder="按设备固定资产编号模糊搜索" left-icon="none" use-action-slot use-right-icon-slot bind:change="onChange" data-name="number">
+    <van-search value="{{ number }}" placeholder="按设备固定资产编号模糊搜索" left-icon="none" use-action-slot use-right-icon-slot bind:change="onChange" data-name="number" bind:blur="search">
       <van-icon name="search" slot="right-icon" class="sg-icon sg-bold" bindtap="search"/>
       <van-icon name="filter-o" slot="action" class="sg-icon sg-index-color sg-bold" bindtap="navigate" data-url="/pages/filter/index"/>
     </van-search>

+ 2 - 2
mini/pages/draft/index.wxml

xqd
@@ -17,8 +17,8 @@
   <view class="sg-list-box sg-pad">
     <view class="sg-list" wx:for="{{list}}" hidden="{{tabIndex != index}}" wx:key="index">
       <block wx:for="{{item}}" wx:for-item="i_item" wx:for-index="i_index" wx:key="i_index">
-        <out-order-item wx:if="{{i_item.type == 1}}" item="{{i_item}}"></out-order-item>
-        <inner-order-item wx:else  item="{{i_item}}"></inner-order-item>
+        <out-order-item wx:if="{{i_item.type == 1}}" item="{{i_item}}" role="{{role}}" bind:update="search"></out-order-item>
+        <inner-order-item wx:else item="{{i_item}}" role="{{role}}" bind:update="search"></inner-order-item>
       </block>
     </view>
   </view>

+ 0 - 7
mini/pages/index/index.js

xqd
@@ -75,13 +75,6 @@ Page({
   },
   navigate: function(e) {
     var url = e.currentTarget.dataset.url
-    if(['/pages/create-project/index', '/pages/create-project-role/index'].indexOf(url) != -1) {
-      var role = this.data.topRole
-      if(!role || ['manager', 'admin'].indexOf(role.key) == -1) {
-        util.error('没有权限');
-        return false;
-      }
-    }
     wx.navigateTo({
       url: url,
     })

+ 3 - 3
mini/pages/index/index.wxml

xqd xqd
@@ -2,11 +2,11 @@
 <view class="sg-container" style="overflow: hidden;">
   <view class="flexdstyle">
     <view class="sg-top-box sg-index-bg">
-      <view class="sg-top-item sg-font-xs" bindtap="navigate" data-url="/pages/create-project/index">
+      <view class="sg-top-item sg-font-xs" bindtap="navigate" data-url="/pages/create-project/index" wx:if="{{topRole && topRole.rights && topRole.rights.newProject}}">
         <van-icon name="edit" class="sg-icon" />
         <view class="sg-top-name">新建项目</view>
       </view>
-      <view class="sg-top-item sg-font-xs" bindtap="navigate" data-url="/pages/create-project-role/index">
+      <view class="sg-top-item sg-font-xs" bindtap="navigate" data-url="/pages/create-project-role/index" wx:if="{{topRole && topRole.rights && topRole.rights.memberAdd}}">
         <van-icon name="user-o" class="sg-icon" />
         <view class="sg-top-name">成员添加</view>
       </view>
@@ -40,7 +40,7 @@
             <view class="sg-name sg-bold">{{ item.name }}</view>
             <view class="sg-date sg-gray-color sg-font-small">{{ item.date }}</view>
           </view>
-          <view class="sg-bottom sg-font-small sg-margin-top-sm">
+          <view class="sg-bottom sg-font-xs sg-margin-top-sm">
             <view class="sg-desc">项目经理:{{ item.manager ? item.manager.name : '无' }}</view>
             <view class="sg-desc">电话:{{ item.manager ? item.manager.phone : '无' }}</view>
           </view>

+ 3 - 0
mini/pages/index/index.wxss

xqd
@@ -3,6 +3,9 @@
   position: fixed;
   width: 100%;
 }
+.sg-container {
+  background: white;
+}
 .sg-top-box {
   color: white;
   display: flex;

+ 9 - 2
mini/pages/note-detail/index.js

xqd xqd
@@ -9,7 +9,8 @@ Page({
    */
   data: {
     id: 1,
-    note: null
+    note: null,
+    role: null
   },
 
   /**
@@ -20,7 +21,13 @@ Page({
     this.setData({
       id
     })
-    api.getByName(this, 'notifications/detail', 'note', {id: id});
+    var that = this;
+    api.getByName(this, 'notifications/detail', 'note', {id: id}, function() {
+      var order = that.data.note ? that.data.note.order : null
+      if(order) {
+        api.getByName(that, 'orders/getRole', 'role', {id: order.project_id});
+      }
+    });
   },
 
   /**

+ 3 - 2
mini/pages/note-detail/index.wxml

xqd
@@ -4,7 +4,8 @@
   <view class="sg-pad">
     <view class="sg-gray-color sg-font-xs sg-pad-tb-sm">{{note.created_at}}</view>
     <view class="sg-pad-tb">{{note.content}}</view>
-    <out-order-item wx:if="{{note.order.type == 1}}" item="{{note.order}}"></out-order-item>
-    <inner-order-item wx:else item="{{note.order}}"></inner-order-item>
+    <out-order-item wx:if="{{note.order.type == 1}}" item="{{note.order}}" role="{{role}}" showDelete="{{false}}"></out-order-item>
+    <inner-order-item wx:else item="{{note.order}}" role="{{role}}" showDelete="{{false}}"></inner-order-item>
   </view>
+  <van-dialog id="van-dialog" />
 </view>

+ 1 - 1
mini/pages/order-detail-inner/index.js

xqd
@@ -54,7 +54,7 @@ Page({
       })
       that.updateDeviceTotal()
       api.getByName(that, 'orders/getRole', 'role', {
-        id: id
+        id: that.data.order ? that.data.order.project_id : ''
       }, function (res) {
         that.updateActionType()
       });

+ 16 - 12
mini/pages/order-detail/index.js

xqd xqd xqd xqd xqd
@@ -22,7 +22,8 @@ Page({
     remark: '',
     order_device: {},
     showPrice: false,
-    device_price: ''
+    device_price: '',
+    right: null
   },
 
   /**
@@ -48,16 +49,17 @@ Page({
     var id = this.data.id
     api.getByName(this, 'orders/detail', 'order', {
       id: id
-    }, function (res) {
+    }, function () {
       that.setData({
         remark: that.data.order.remark
       })
       that.updateDeviceTotal()
       api.getByName(that, 'orders/getRole', 'role', {
-        id: id
-      }, function (res) {
+        id: that.data.order ? that.data.order.project_id : ''
+      }, function() {
         that.updateActionType()
       });
+      
     });
   },
 
@@ -65,12 +67,14 @@ Page({
     var actionType = ''
     var role = this.data.role
     var order = this.data.order
-    if (order.project_role_id == role.id) {
-      if (['machine', 'assist', 'manager'].indexOf(role.project_role.key) != -1) actionType = 'check'
-      if(order.status_key == 'checked' && role.project_role.key == 'work') actionType = 'pass'
-      if(order.status_key == 'reject' && role.project_role.key == 'work') actionType = 're-submit'
+    var changePrice = false
+    if (order.level == role.level) {
+      if(['checking', 'checked'].indexOf(order.status_key) != -1 && role && role.rights && role.rights.rentCheck) actionType = 'check';
+      else if(order.status_key == 'checked' && role.key == 'work') actionType = 'pass'
+      else if(order.status_key == 'reject' && role.key == 'work') actionType = 're-submit'
+
+      changePrice = role && role.rights && role.rights.rentMoneyChange
     }
-    var changePrice = actionType == 'pass' || (actionType == 'check' && role.project_role.key == 'machine')
     this.setData({
       actionType,
       changePrice
@@ -102,7 +106,7 @@ Page({
     if(show) {
       this.setData({
         order_device: item,
-        device_price: item.pivot.price / 100
+        device_price: item.price / 100
       })
     }
     this.setData({
@@ -113,9 +117,9 @@ Page({
   updateDeviceTotal: function () {
     var total = 0
     var order = this.data.order
-    var devices = order.devices ? order.devices : []
+    var devices = order.order_devices ? order.order_devices : []
     for (var i = 0; i < devices.length; ++i) {
-      total = total + devices[i].pivot.quantity
+      total = total + devices[i].quantity
     }
     this.setData({
       device_total: total,

+ 7 - 7
mini/pages/order-detail/index.wxml

xqd xqd
@@ -38,7 +38,7 @@
       </view>
       <view class="sg-form-item sg-pad sg-top-border">
         <view class="sg-label">备注</view>
-        <input value="{{remark}}" class="sg-input" bindinput="onChange" data-name="remark" placeholder="订单备注填写"></input>
+        <input value="{{remark}}" class="sg-input" bindinput="onChange" data-name="remark" disabled="{{true}}"></input>
       </view>
     </view>
   </view>
@@ -52,20 +52,20 @@
       <block wx:else>
         <view class="sg-item sg-pad sg-margin" wx:for="{{devices}}" wx:key="index" bindtap="selectDevice"
           data-index="{{index}}">
-          <view class="sg-title sg-bold">{{index+1}}. 租赁设备详情:{{item.name}} - {{item.pivot ? item.pivot.name : ''}}
+          <view class="sg-title sg-bold">{{index+1}}. {{item.device_type ? item.device_type.name : ''}} - {{item.device_name ? item.device_name.name : ''}} - {{item.spec ? item.spec.name : ''}}
           </view>
           <view class="sg-content sg-gray-color sg-font-small">
-            <view class="sg-margin-tb-sm">租赁方式:按天计费</view>
+            <view class="sg-margin-tb-sm">租赁方式:{{item.rent_type ? item.rent_type.name : ''}}</view>
             <view class="sg-margin-tb-sm sg-flex sg-align-center sg-space-between">
-              <view>租赁单价:¥{{item.pivot ? item.pivot.price / 100 : ''}}</view>
-              <view>数量:{{item.pivot ? item.pivot.quantity : ''}}</view>
+              <view>租赁单价:¥{{item.price / 100}}</view>
+              <view>数量:{{item.quantity}}</view>
             </view>
             <view class="sg-margin-tb-sm">租赁时间:<text
-                class="sg-rent-date sg-border">{{item.pivot ? (item.pivot.start_date + '至' + item.pivot.end_date) : ''}}</text>
+                class="sg-rent-date sg-border">{{item.start_date ? (item.start_date + '至' + item.end_date) : ''}}</text>
             </view>
           </view>
           <view class="sg-footer sg-flex sg-align-center sg-space-between sg-margin-top-sm">
-            <view class="sg-font-lg sg-bold">总金额:¥{{item.pivot.price * item.pivot.quantity / 100}}</view>
+            <view class="sg-font-lg sg-bold">总金额:¥{{item.price * item.quantity / 100}}</view>
             <view class="sg-btn sg-index-bg sg-pad-sm sg-white" hidden="{{!changePrice}}" bindtap="switchShowPrice"
               data-item="{{item}}" data-show="{{true}}">修改价格</view>
           </view>

+ 1 - 0
mini/pages/order/index.js

xqd
@@ -37,6 +37,7 @@ Page({
    * 生命周期函数--监听页面加载
    */
   onLoad: function (options) {
+    // project_id
     var id = options.id ? options.id : 1
     var type = options.type ? options.type : 'list'
     var tabIndex = options.index ? options.index : 0

+ 22 - 14
mini/pages/project/index.js

xqd xqd xqd xqd
@@ -15,7 +15,8 @@ Page({
       img: 'http://t18.9026.com/mini/create-order.png',
       title: '创建订单',
       desc: '创建外部设备租赁订单',
-      url: '/pages/create-order/index'
+      url: '/pages/create-order/index',
+      hidden: true
     }, {
       img: 'http://t18.9026.com/mini/rent-check.png',
       title: '租赁审核',
@@ -36,7 +37,8 @@ Page({
       img: 'http://t18.9026.com/mini/use-apply.png',
       title: '调用申请',
       desc: '机电负责人调用设备',
-      url: '/pages/create-order-inner/index'
+      url: '/pages/create-order-inner/index',
+      hidden: true
     }, {
       img: 'http://t18.9026.com/mini/rent-check.png',
       title: '调用审核',
@@ -64,7 +66,7 @@ Page({
       desc: '设备维修上报',
       url: '/pages/repair/index'
     }],
-    right: null
+    role: null
   },
 
   /**
@@ -79,25 +81,31 @@ Page({
     api.getByName(this, 'getUserInfo', 'userInfo', {}, function(res) {
       app.updateUserInfo(res);
     });
-    api.getByName(this, 'users/getRight', 'right', {id: id});
+    var that = this;
+    api.getByName(this, 'project-roles/getRoleAndRights', 'role', {id: id}, function() {
+      that.updateMenuItemShow()
+    });
     wx.setStorageSync('sg-added-devices', [])
   },
 
+  updateMenuItemShow() {
+    var role = this.data.role
+    var device_rent_menus = this.data.device_rent_menus
+    device_rent_menus[0].hidden = !(role && role.rights && role.rights.rentCreate)
+    var device_use_menus = this.data.device_use_menus
+    device_use_menus[0].hidden = !(role && role.rights && role.rights.applyCreate)
+    this.setData({
+      device_rent_menus,
+      device_use_menus
+    })
+  },
+
   navigate: function(e) {
     var url = e.currentTarget.dataset.url
-    var right = this.data.right
     var id = this.data.id
-    if(url == '/pages/device-inner/index?id=' + this.data.id) {
+    if(url == '/pages/device-inner/index?id=' + id) {
       app.resetFilter();
     }
-    if(url == '/pages/create-order/index?id=' + id && (!right || !right.createOut)) {
-      util.error('没有权限')
-      return false;
-    }
-    if(url == '/pages/create-order-inner/index?id=' + id && (!right || !right.createInner)) {
-      util.error('没有权限')
-      return false;
-    }
     wx.navigateTo({
       url: url,
     })

+ 3 - 3
mini/pages/project/index.wxml

xqd xqd xqd
@@ -11,7 +11,7 @@
       </view>
       <view class="sg-phone-user sg-flex sg-align-center sg-space-between">
         <view class="sg-phone sg-gray-color sg-font-small">{{ userInfo.phone }}</view>
-        <block wx:if="{{ right && right.managerMember }}">
+        <block wx:if="{{ role && role.rights && role.rights.memberManage }}">
           <view class="sg-user sg-font-small sg-index-color sg-flex sg-align-center" bindtap="navigate"
           data-url="/pages/project-user/index?id={{id}}">
           <van-icon name="user-o" /><text>人员管理</text></view>
@@ -26,7 +26,7 @@
     </view>
     <view class="sg-menu-list">
       <block wx:for="{{device_rent_menus}}" wx:key="index">
-        <view class="sg-item sg-flex sg-align-center sg-pad" bindtap="navigate" data-url="{{item.url}}?id={{id}}">
+        <view class="sg-item sg-flex sg-align-center sg-pad" bindtap="navigate" data-url="{{item.url}}?id={{id}}" wx:if="{{!item.hidden}}">
           <image class="sg-img" src="{{item.img}}" mode="widthFix"></image>
           <view class="sg-name sg-margin-top-sm">{{item.title}}</view>
           <view class="sg-desp sg-margin-top-sm sg-gray-color sg-font-xs">{{item.desc}}</view>
@@ -40,7 +40,7 @@
       <text class="sg-sub-title sg-gray-color">内部设备调用</text>
     </view>
     <view class="sg-menu-list">
-      <view class="sg-item sg-flex sg-align-center sg-pad" wx:for="{{device_use_menus}}" wx:key="index" bindtap="navigate" data-url="{{item.url}}?id={{id}}">
+      <view class="sg-item sg-flex sg-align-center sg-pad" wx:for="{{device_use_menus}}" wx:key="index" bindtap="navigate" data-url="{{item.url}}?id={{id}}" wx:if="{{!item.hidden}}">
         <image class="sg-img" src="{{item.img}}" mode="widthFix"></image>
         <view class="sg-name sg-margin-top-sm">{{item.title}}</view>
         <view class="sg-desp sg-margin-top-sm sg-gray-color sg-font-xs">{{item.desc}}</view>

+ 2 - 2
mini/pages/use-record/index.js

xqd xqd
@@ -12,7 +12,7 @@ Page({
     inner_device: null,
     id: '',
     activeNames: ['1', '2'],
-    records: [],
+    order_devices: [],
     repair_devices: []
   },
 
@@ -25,7 +25,7 @@ Page({
       id
     })
     api.getByName(this, 'inner-devices/detail', 'inner_device', {id: id});
-    api.getByName(this, 'use-records/get', 'records', {id: id});
+    api.getByName(this, 'order-devices/get', 'order_devices', {id: id});
     api.getByName(this, 'repair-devices/get', 'repair_devices', {id: id});
   },
 

+ 3 - 3
mini/pages/use-record/index.wxml

xqd
@@ -4,12 +4,12 @@
   <van-collapse value="{{ activeNames }}" bind:change="onChange">
     <van-collapse-item title="历史阅历" name="1">
       <view class="sg-list">
-        <block wx:if="{{records.length > 0}}">
-          <view class="sg-item" wx:for="{{records}}" wx:key="index">
+        <block wx:if="{{order_devices.length > 0}}">
+          <view class="sg-item" wx:for="{{order_devices}}" wx:key="index">
             <view class="sg-date sg-flex sg-align-center sg-space-between sg-index-color sg-bold sg-pad-tb-sm sg-bottom-border">
               <view>{{item.start_date}}</view>
               <view>-</view>
-              <view>{{item.end_date}}</view>
+              <view>{{ index == 0 && inner_device.end_date ? '' : item.end_date}}</view>
             </view>
             <view class="sg-flex sg-align-center sg-bottom-border sg-space-between sg-pad-tb-sm">
               <view>调用项目</view>

+ 4 - 1
mini/pages/use-record/index.wxss

xqd
@@ -1 +1,4 @@
-/* pages/use-record/index.wxss */
+/* pages/use-record/index.wxss */
+.sg-fix-top {
+  z-index: 100;
+}

+ 1 - 1
mini/utils/env.js

xqd
@@ -1,3 +1,3 @@
-const isTest = false;
+const isTest = true;
 export const baseUrl = isTest ? 'http://app.rt/api/mini/' : 'http://t18.9026.com/api/mini/';
 export const imgHost = isTest ? 'http://app.rt/images/' : 'http://t18.9026.com/images/'

+ 92 - 0
resources/views/admin/project-role-rights/index.blade.php

xqd
@@ -0,0 +1,92 @@
+@extends('admin.layout-content')
+
+@section('header')
+    <style>
+        .layui-table th, 
+        .layui-card td {
+            text-align: center;
+            cursor: pointer;
+        }
+    </style>
+@endsection
+
+@section('content')
+    <div class="layui-card">
+        <div class="layui-card-header sg-card-header">
+            {{ $model_name }}(点击按钮切换权限)
+        </div>
+        <div class="layui-card-body">
+            <table class="layui-table">
+                <thead>
+                <tr>
+                    <th></th>
+                    @foreach($project_roles as $project_role)
+                        <th>{{ $project_role->name }}</th>
+                    @endforeach
+                </tr>
+                </thead>
+                <tbody>
+                @foreach($items as $item)
+                <tr>
+                    @foreach($item as $key => $i_item)
+                        @if($key == 0)
+                            <td>{{ $i_item->name }}</td>
+                        @elseif($i_item['has'])
+                            <td class="sg-change-btn" data-has="1" data-right-id="{{$i_item['right_id']}}" data-role-id="{{$i_item['role_id']}}"><span class="layui-badge layui-bg-green">有权</span></td>
+                        @else
+                            <td class="sg-change-btn" data-has="2" data-right-id="{{$i_item['right_id']}}" data-role-id="{{$i_item['role_id']}}"><span class="layui-badge layui-bg-gray">无权</span></td>
+                        @endif
+                    @endforeach
+                </tr>
+                @endforeach
+                </tbody>
+            </table>
+        </div>
+    </div>
+@endsection
+
+@section('footer')
+    <script>
+        $(function () {
+            layui.use(['layer'], function () {
+                var layer = layui.layer;
+                $('.sg-change-btn').on('click', function () {
+                    var has = $(this).attr('data-has');
+                    var right_id = $(this).attr('data-right-id');
+                    var role_id = $(this).attr('data-role-id');
+                    var msg = has === '2' ? '确定授予该权利吗?' : '确定取消该权利吗?';
+                    layer.confirm(msg, function(index) {
+                        $.ajax({
+                            method: 'POST',
+                            url: '{{ $pre_uri }}' + 'change',
+                            headers: {
+                                'X-CSRF-TOKEN': '{{ csrf_token() }}'
+                            },
+                            data: {
+                                right_id: right_id,
+                                role_id: role_id,
+                                has: has
+                            },
+                            success: function (data) {
+                                if(data.status === 'success') {
+                                    window.location.reload()
+                                } else {
+                                    layer.msg(data.info, {
+                                        icon: 2
+                                    });
+                                }
+                                layer.close(index);
+                            },
+                            error: function () {
+                                layer.close(index);
+                                layer.msg('操作失败', {
+                                    icon: 2
+                                });
+                            }
+                        });
+                    });
+                })
+            })
+        })
+    </script>
+@endsection

+ 4 - 1
routes/api.php

xqd xqd xqd
@@ -34,6 +34,7 @@ $api->version('v1', ['namespace' => 'App\Http\Controllers\Api\mini', 'prefix' =>
     $api->any('project-roles/get', 'ProjectRoleController@get');
     $api->any('project-roles/getAll', 'ProjectRoleController@getAll');
     $api->any('project-roles/getByExclude', 'ProjectRoleController@getByExclude');
+    $api->any('project-roles/getRoleAndRights', 'ProjectRoleController@getRoleAndRights');
 
     $api->any('project-users/detail', 'ProjectUserController@detail');
 
@@ -67,7 +68,7 @@ $api->version('v1', ['namespace' => 'App\Http\Controllers\Api\mini', 'prefix' =>
     $api->any('repair-devices/create', 'RepairDeviceController@create');
     $api->any('repair-devices/get', 'RepairDeviceController@get');
 
-    $api->any('use-records/get', 'UseRecordController@get');
+    $api->any('order-devices/get', 'OrderDeviceController@get');
 
     $api->any('parts/get', 'PartController@get');
 
@@ -93,4 +94,6 @@ $api->version('v1', ['namespace' => 'App\Http\Controllers\Api\mini', 'prefix' =>
     $api->any('users/getRight', 'UserController@getRight');
 
     $api->any('feedback/create', 'FeedbackController@create');
+
+    $api->any('rights/get', 'RightController@get');
 });