李浩杰 4 년 전
부모
커밋
575d2e4de2

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

xqd
@@ -20,7 +20,7 @@ class TestController extends Controller
 {
     public function index(Request $request)
     {
-        dd(ProjectRole::getCreateRole('apply', 2));
+        dd(Order::where('type', 1)->groupBy('project_id')->selectRaw('sum(money) as sum, project_id')->pluck('sum', 'project_id'));
 //    	return view('admin.test.index');
     }
 }

+ 65 - 11
app/Http/Controllers/Api/mini/DataController.php

xqd xqd
@@ -32,30 +32,28 @@ class DataController extends BaseController
 
     public function getYearsAndMonths(Request $request)
     {
-        $years = [
-            ['text' => '所有年', 'value' => '']
-        ];
+        $years = [];
 
         $this_year = Carbon::now()->year;
         for($i = 5; $i >= 0; $i--) {
             array_push($years, [
-                'text' => $this_year - $i,
-                'value' => $this_year - $i
+                'name' => $this_year - $i,
+                'id' => $this_year - $i
             ]);
         }
+        array_push($years, ['name' => '所有年', 'id' => '']);
         $months = [];
         for($i = 1; $i < 13; ++$i) {
             array_push($months, [
-                'text' => $i . '月',
-                'value' => $i
+                'name' => $i . '月',
+                'id' => $i
             ]);
         }
         $month = Carbon::now()->month;
-        $now = Carbon::now()->toDateString();
         return $this->success(['data' => [
-            ['key' => 'year', 'values' => $years, 'defaultIndex' => count($years) - 1],
-            ['key' => 'month', 'values' => $months, 'defaultIndex' => $month]
-        ], 'now' => $now]);
+            'array' => [$years, $months],
+            'index' => [count($years) - 2, $month - 1]
+        ]]);
     }
 
     public function getDateInfo()
@@ -320,4 +318,60 @@ class DataController extends BaseController
         }
         return compact('year', 'month', 'day');
     }
+
+    public function getYearAndMonthMoney(Request $request)
+    {
+        $date = $request->input('date');
+        if(!$date) {
+            $year_money = Order::where('type', 1)->sum('money') / 100;
+            $month_money = $year_money;
+        } else {
+            $start_year = Carbon::createFromTimeString(substr($date, 0, 4) . '-01-01 00:00:00')->toDateTimeString();
+            $end_year = Carbon::createFromTimeString(substr($date, 0, 4) . '-01-01 00:00:00')->addYear()->toDateTimeString();
+            $start_month = Carbon::createFromTimeString($date . ' 00:00:00')->toDateTimeString();
+            $end_month = Carbon::createFromTimeString($date . ' 00:00:00')->addMonth()->toDateTimeString();
+            $year_money = Order::where([
+                ['type', 1],
+                ['created_at', '>=', $start_year],
+                ['created_at', '<', $end_year]
+            ])->sum('money') / 100;
+            $month_money = Order::where([
+                    ['type', 1],
+                    ['created_at', '>=', $start_month],
+                    ['created_at', '<', $end_month]
+                ])->sum('money') / 100;
+        }
+        return $this->success(['data' => compact('year_money', 'month_money')]);
+    }
+
+    public function projectStat(Request $request)
+    {
+        $items = Order::where('type', 1);
+        $date = $request->input('date');
+        if($date) {
+            $start_month = Carbon::createFromTimeString($date . ' 00:00:00')->toDateTimeString();
+            $end_month = Carbon::createFromTimeString($date . ' 00:00:00')->addMonth()->toDateTimeString();
+            $items= $items->where([
+                ['created_at', '>=', $start_month],
+                ['created_at', '<', $end_month]
+            ]);
+        }
+        $orderBy = $request->input('orderBy');
+        $items = $items->groupBy('project_id')->selectRaw('sum(money) as sum, project_id')->pluck('sum', 'project_id');
+        $projects = Project::all();
+        foreach ($projects as $project) {
+            $project->money = 0;
+            foreach ($items as $key => $val) {
+                if($key == $project->id) {
+                    $project->money = $val / 1000;
+                    break;
+                }
+            }
+        }
+        if($orderBy == 'asc') $projects = $projects->sortBy('money');
+        else $projects = $projects->sortByDesc('money');
+        $values = $projects->pluck('money');
+        $names = $projects->pluck('name');
+        return $this->success(['data' => compact('values', 'names')]);
+    }
 }

+ 13 - 51
app/Http/Controllers/Api/mini/OrderController.php

xqd xqd xqd xqd xqd xqd xqd xqd xqd
@@ -15,6 +15,7 @@ use App\Models\ProjectUser;
 use App\Models\RentType;
 use App\Models\Spec;
 use App\Models\WorkPoint;
+use Carbon\Carbon;
 use Illuminate\Http\Request;
 use Illuminate\Support\Facades\Auth;
 use Illuminate\Support\Facades\Log;
@@ -50,22 +51,8 @@ class OrderController extends BaseController
         ]);
         if(!$order) return $this->error(['msg' => '订单创建失败']);
         Notification::send($order->id);
-        $devices = $request->input('devices');
-        $total = 0;
-        foreach($devices as $device) {
-            $price = $this->transMoney($device['price']);
-            $data = $this->getNameSpecRent($device);
-            OrderDevice::create(array_merge([
-                'order_id' => $order->id,
-                'project_id' => $order->project_id,
-                'quantity' => $device['quantity'],
-                'price' => $price,
-                'start_date' => $device['start_date'],
-                'end_date' => $device['end_date']
-            ], $data));
-            $total = $total + ($price * (int)$device['quantity']);
-        }
-        $order->update(['money' => $total]);
+        $order->updateOrderDevices($request->input('devices'));
+
         return $this->success();
     }
 
@@ -180,23 +167,7 @@ class OrderController extends BaseController
             'level' => $project_role ? $project_role['level'] : ''
         ]);
         if(!$res) return $this->error(['msg' => '订单修改失败']);
-        $devices = $request->input('devices');
-        $total = 0;
-        OrderDevice::where('order_id', '=', $order->id)->delete();
-        foreach($devices as $device) {
-            $price = $this->transMoney($device['price']);
-            OrderDevice::create([
-                'name' => $device['name'],
-                'order_id' => $order->id,
-                'device_id' => $device['type_id'],
-                'quantity' => $device['quantity'],
-                'price' => $price,
-                'start_date' => $device['start_date'],
-                'end_date' => $device['end_date']
-            ]);
-            $total = $total + ($price * (int)$device['quantity']);
-        }
-        $order->update(['money' => $total]);
+        $order->updateOrderDevices($request->input('devices'));
         return $this->success();
     }
 
@@ -236,23 +207,7 @@ class OrderController extends BaseController
                 }
             }
         } else {
-            OrderDevice::where('order_id', '=', $order->id)->delete();
-            foreach($devices as $device) {
-                OrderDevice::create([
-                    'name' => $device['name'],
-                    'order_id' => $order->id,
-                    'device_id' => $device['id'],
-                    'start_date' => $device['start_date'],
-                    'end_date' => $device['end_date']
-                ]);
-                if($device['id']) {
-                    InnerDevice::find($device['id'])->update([
-                        'start_date' => $device['start_date'],
-                        'end_date' => $device['end_date'],
-                        'work_point_id' => $request->input('work_point_id')
-                    ]);
-                }
-            }
+            $order->updateOrderDevices($devices);
         }
 
         return $this->success();
@@ -268,8 +223,12 @@ class OrderController extends BaseController
             ['level', '>=', $level]
         ];
         $is_draft = $request->input('is_draft');
+
         if($is_draft) {
             $search_items['is_draft'] = $is_draft;
+            if($is_draft == 1) {
+                $search_items['user_id'] = $user->id;
+            }
         }
         if($request->input('status')) {
             $status = Option::get('orders', 'status', $request->input('status'));
@@ -318,7 +277,7 @@ class OrderController extends BaseController
             $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);
+            $device->work_point = $order['workPoint'];
         }
         foreach($order['order_devices'] as $order_device) {
             $order_device->device_type = Device::find($order_device->device_id);
@@ -369,6 +328,7 @@ class OrderController extends BaseController
         } else if($request->input('type') == 're-submit') {
             $status = Option::get('orders', 'status', 'checking');
             $next_project_role = $project_role->getNext(null, $is_inner);
+            $order->updateOrderDevices($request->input('devices'));
         } else if($request->input('type') == 'reject') {
             $next_project_role = ProjectRole::getFirstRole($order);
         } else if($request->input('type') == 'back') {
@@ -378,6 +338,7 @@ class OrderController extends BaseController
                 $status = Option::get('orders', 'status', 'pass');
                 // 全部归还,下一角色改为最高角色
                 $next_project_role = ProjectRole::getLastRole($order);
+                OrderDevice::where('order_id', $order->id)->update(['end_date' => Carbon::now()->toDateString()]);
             } else {
                 // 部分归还,状态保持,下一角色保持,上一角色保持
                 $status = $order->status;
@@ -404,6 +365,7 @@ class OrderController extends BaseController
             'is_change' => $is_change,
             'remark' => $request->input('remark')
         ]);
+
         if($request->input('type') == 'back') {
             if($new_order) {
                 // 部分归还

+ 3 - 1
app/Http/Controllers/Api/mini/ProjectController.php

xqd
@@ -62,7 +62,9 @@ class ProjectController extends BaseController
 
     public function get(Request $request)
     {
-        $items = $this->model->where('active', 1);
+        $user = Auth::guard('mini')->user();
+
+        $items = $user->projects()->where('active', 1);
         $tmp_items = collect(['name']);
         foreach($tmp_items as $tmp_item) {
             if($request->has($tmp_item) && !empty($request->input($tmp_item))) {

+ 4 - 0
app/Models/BaseModel.php

xqd
@@ -95,4 +95,8 @@ class BaseModel extends Model
         if($type == 'name') return $option->name;
         else return '<div class="layui-badge layui-bg-' . $option->label_type . '">' . $option->name . '</div>';
     }
+
+    public function transMoney($money) {
+        return round($money * 100);
+    }
 }

+ 13 - 9
app/Models/Notification.php

xqd xqd
@@ -29,14 +29,18 @@ class Notification extends BaseModel
                 $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');
+                $project_role_ids = ProjectRole::whereIn('key', ['admin'])->pluck('id');
             } else {
                 // 调用完成且修改
-                $project_role_ids = ProjectRole::whereIn('key', ['machine'])->pluck('id');
+                $project_role_ids = ProjectRole::whereIn('key', ['admin'])->pluck('id');
             }
         } else if($order['status'] == $back_id) {
             $project_role_ids = ProjectRole::whereIn('key', ['admin'])->pluck('id');
         }
+
+        if($overdue) {
+            $project_role_ids = ProjectRole::whereIn('key', ['machine', 'admin'])->pluck('id');
+        }
         if(count($project_role_ids) > 0) {
             $user_ids = ProjectUser::where([
                 ['project_id', $order['project_id']]
@@ -62,26 +66,26 @@ class Notification extends BaseModel
             // 调用成功
             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', 'sub', 'admin'])) {
-                // 调用待处理
-                $status = 2;
             } else if($order['status'] == $reject_id) {
                 // 调用被驳回
                 $status = 3;
             } else if($order['status'] == $pass_id) {
-                // 调用已完成
-                $status = 5;
+                // 调用已完成,主动退回
+                $status = 6;
             } else if($order['status'] == $back_id) {
                 // 调用已归还
                 $status = 6;
             } else if($order['is_change'] == 1) {
                 // 调用修改通知
                 $status = 7;
+            } else if($role && in_array($role['key'], ['assist', 'manager', 'sub', 'admin'])) {
+                // 调用待处理
+                $status = 2;
             }
         }
-        // 调用时间到期 status = 4
+        // 调用时间到期,发送调用完成通知 status = 5
         if($overdue) {
-            $status = 4;
+            $status = 5;
         }
         foreach($user_ids as $user_id) {
             Notification::create([

+ 71 - 2
app/Models/Order.php

xqd xqd xqd
@@ -67,7 +67,7 @@ class Order extends BaseModel
             return $project_role ? $project_role->name . ' - ' . $option['name'] : $option['name'];
         } else if($option['key'] == 'pass') {
             if($this['is_change'] == 1) return '管理员 - 已修订';
-            return $this['type'] == 1 ? '提交人 - 已确定' : '已完成';
+            return '已完成';
         }
         return $option ? $option['name'] : '';
     }
@@ -138,7 +138,7 @@ class Order extends BaseModel
                 '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]);
+            OrderDevice::where('order_id', $this['id'])->whereIn('inner_device_id', $back_device_ids)->update(['order_id' => $new_order->id, 'end_date' => Carbon::now()->toDateString()]);
         }
         $free_id = Option::get('inner_devices', 'status', 'free');
         InnerDevice::whereIn('id', $back_device_ids)->update([
@@ -150,6 +150,75 @@ class Order extends BaseModel
         return $new_order;
     }
 
+    public function updateOrderDevices($devices)
+    {
+        OrderDevice::where('order_id', '=', $this['id'])->delete();
+        if($this['type'] == 1) {
+            $total = 0;
+            foreach($devices as $device) {
+                $price = $this->transMoney($device['price']);
+                $data = $this->getNameSpecRent($device);
+                OrderDevice::create(array_merge([
+                    'order_id' => $this['id'],
+                    'project_id' => $this['project_id'],
+                    'quantity' => $device['quantity'],
+                    'price' => $price,
+                    'start_date' => $device['start_date'],
+                    'end_date' => $device['end_date']
+                ], $data));
+                $total = $total + ($price * (int)$device['quantity']);
+            }
+            $this->update(['money' => $total]);
+        } else {
+            foreach($devices as $device) {
+                OrderDevice::create([
+                    'name' => $device['name'],
+                    'order_id' => $this['id'],
+                    'device_id' => $device['id'],
+                    'start_date' => $device['start_date'],
+                    'end_date' => $device['end_date']
+                ]);
+                if($device['id']) {
+                    InnerDevice::find($device['id'])->update([
+                        'start_date' => $device['start_date'],
+                        'end_date' => $device['end_date'],
+                        'work_point_id' => $this['work_point_id']
+                    ]);
+                }
+            }
+        }
+    }
+
+    public function getNameSpecRent($data)
+    {
+        $device = Device::find($data['type_id']);
+
+        $rent_type = RentType::firstOrCreate([
+            'name' => $data['rent']
+        ]);
+        if(!$device) return [
+            'device_id' => '',
+            'device_name_id' => '',
+            'spec_id' => '',
+            'rent_type_id' => $rent_type->id
+        ];
+        $device_name = DeviceName::firstOrCreate([
+            'device_id' => $device->id,
+            'name' => $data['name']
+        ]);
+        $spec = Spec::firstOrCreate([
+            'device_id' => $device->id,
+            'device_name_id' => $device_name->id,
+            'name' => $data['spec']
+        ]);
+        return [
+            'device_id' => $device->id,
+            'device_name_id' => $device_name->id,
+            'spec_id' => $spec->id,
+            'rent_type_id' => $rent_type->id
+        ];
+    }
+
     /**
      * @param Request $request
      * @return int(1改变2不改变)

+ 12 - 0
app/Models/ProjectUser.php

xqd xqd
@@ -1,6 +1,8 @@
 <?php
 
 namespace App\Models;
+use Illuminate\Http\Request;
+use Illuminate\Support\Facades\Validator;
 
 class ProjectUser extends BaseModel
 {
@@ -13,4 +15,14 @@ class ProjectUser extends BaseModel
     {
         return $this->belongsTo('App\Models\User', 'user_id');
     }
+
+    public function getValidator(Request $request, $type)
+    {
+        $validator = Validator::make($request->input('data'), [
+            'user_id' => 'required'
+        ], [
+            'user_id.required' => '用户必选'
+        ]);
+        return $validator;
+    }
 }

+ 4 - 2
mini/app.json

xqd xqd
@@ -1,9 +1,10 @@
 {
   "pages": [
     "pages/index/index",
+    "pages/data/index",
+    "pages/data-center/index",
     "pages/create-order/index",
     "pages/create-project-role/index",
-    "pages/data/index",
     "pages/order-inner/index",
     "pages/order/index",
     "pages/notification/index",
@@ -80,6 +81,7 @@
     "van-collapse-item": "@vant/weapp/collapse-item/index",
     "van-picker": "@vant/weapp/picker/index",
     "ec-canvas": "/ec-canvas/ec-canvas",
-    "van-uploader": "@vant/weapp/uploader/index"
+    "van-uploader": "@vant/weapp/uploader/index",
+    "sg-date-picker": "/components/sg-date-picker/index"
   }
 }

+ 1 - 1
mini/app.wxss

xqd
@@ -137,7 +137,7 @@
   font-size: 1.2rem;
 }
 .sg-icon-lg {
-  font-size: 1.5rem;
+  font-size: 1.8rem;
 }
 .sg-header {
   font-size: 1.2rem;

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

xqd xqd
@@ -25,6 +25,10 @@ Component({
     index: {
       type: String,
       value: ''
+    },
+    editDate: {
+      type: Boolean,
+      value: false
     }
   },
 
@@ -56,6 +60,12 @@ Component({
       this.triggerEvent('delete', {
         index
       }, {})
+    },
+    editDate: function(e) {
+      var index = e.currentTarget.dataset.index
+      this.triggerEvent('editDate', {
+        index
+      }, {})
     }
   }
 })

+ 2 - 3
mini/components/inner-device-card/index.wxml

xqd
@@ -33,10 +33,9 @@
   <view class="sg-bottom sg-font-xs sg-flex sg-align-center sg-space-between">
     <view class="sg-left">
       <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 class="sg-item sg-margin-tb-sm">借用时间:{{item.start_date ? item.start_date + '至' + item.end_date : (item.pivot ? item.pivot.start_date + '至' + item.pivot.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 class="sg-white sg-pad-sm sg-index-bg" wx:if="{{editDate}}" bindtap="editDate" data-index="{{index}}">修改时间</view>
   </view>
 </view>

+ 70 - 0
mini/components/sg-date-picker/index.js

xqd
@@ -0,0 +1,70 @@
+// components/sg-date-picker/index.js
+import http from '../../utils/http'
+Component({
+  /**
+   * 组件的属性列表
+   */
+  properties: {
+    date: String
+  },
+
+  /**
+   * 组件的初始数据
+   */
+  data: {
+    multiArray: [],
+    multiIndex: []
+  },
+
+  lifetimes: {
+    attached: function() {
+      var that = this
+      http({
+        url: 'data/getYearsAndMonths',
+        data: {},
+        success: function(res) {
+          if(res.code == 0) {
+            that.setData({
+              multiArray: res.data.array,
+              multiIndex: res.data.index
+            })
+            that.updateDate()
+          }
+        }
+      })
+    },
+    detached: function() {
+      // 在组件实例被从页面节点树移除时执行
+    },
+  },
+
+  /**
+   * 组件的方法列表
+   */
+  methods: {
+    updateDate: function() {
+      var multiArray = this.data.multiArray
+      var multiIndex = this.data.multiIndex
+      if(multiArray[0][multiIndex[0]].id == '') {
+        this.triggerEvent('update', {
+          date: ''
+        })
+      } else {
+        var date = multiArray[0][multiIndex[0]].id 
+        var month = multiArray[1][multiIndex[1]].id
+        month = month <= 9 ? '0' + month : month
+        this.triggerEvent('update', {
+          date: date + '-' + month + '-' + '01'
+        })
+      }
+    },
+    bindColumnChange: function(e) {
+      var multiIndex = this.data.multiIndex
+      multiIndex[e.detail.column] = e.detail.value
+      this.setData({
+        multiIndex: multiIndex
+      })
+      this.updateDate()
+    }
+  }
+})

+ 4 - 0
mini/components/sg-date-picker/index.json

xqd
@@ -0,0 +1,4 @@
+{
+  "component": true,
+  "usingComponents": {}
+}

+ 10 - 0
mini/components/sg-date-picker/index.wxml

xqd
@@ -0,0 +1,10 @@
+<!--components/sg-date-picker/index.wxml-->
+<view class="picker">
+  <view>时间选择</view>
+  <picker mode="multiSelector" bindchange="bindChange" bindcolumnchange="bindColumnChange" value="{{multiIndex}}" range="{{multiArray}}" range-key="name">
+    <view class="picker">
+      <text>{{multiArray[0][multiIndex[0]].id == '' ? multiArray[0][multiIndex[0]].name : multiArray[0][multiIndex[0]].name + '-' + multiArray[1][multiIndex[1]].name}}</text>
+      <van-icon name="arrow-down" class="sg-icon"></van-icon>
+    </view>
+  </picker>
+</view>

+ 1 - 0
mini/components/sg-date-picker/index.wxss

xqd
@@ -0,0 +1 @@
+/* components/sg-date-picker/index.wxss */

+ 37 - 1
mini/pages/create-order-inner/index.js

xqd xqd xqd xqd
@@ -27,7 +27,10 @@ Page({
     actionType: null,
     order: null,
     canEdit: true,
-    showBack: false
+    showBack: false,
+    showRent: false,
+    showDate: false,
+    deviceIndex: -1
   },
 
   /**
@@ -121,6 +124,9 @@ Page({
     else if (type == 'back') {
       this.switchShow(e)
       return false
+    } else if (type == 're-rent') {
+      this.switchShow(e)
+      return false
     }
     Dialog.confirm({
       title: '提示',
@@ -130,6 +136,31 @@ Page({
         that.submitCheck(e)
       })
   },
+  editDate: function(e) {
+    var deviceIndex = e.detail.index
+    var device = this.data.devices[deviceIndex]
+    var default_dates = [device.start_date, device.end_date]
+
+    this.setData({
+      showDate: true,
+      default_dates,
+      deviceIndex
+    })
+  },
+  confirmDate: function (e) {
+    var [start_date, end_date] = e.detail;
+    start_date = util.formatDate(start_date)
+    end_date = util.formatDate(end_date)
+    var devices = this.data.devices
+    var deviceIndex = this.data.deviceIndex
+    devices[deviceIndex].start_date = start_date
+    devices[deviceIndex].end_date = end_date
+    this.setData({
+      devices,
+      showDate: false
+    })
+
+  },
   submitCheck: function (e) {
     var type = e.currentTarget.dataset.type
     var is_change = e.currentTarget.dataset.change
@@ -204,6 +235,11 @@ Page({
       util.error('请选择调用设备');
       return false;
     }
+    if(type == 're-rent') {
+      this.setData({
+        showRent: false
+      })
+    }
     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', [])

+ 14 - 2
mini/pages/create-order-inner/index.wxml

xqd xqd xqd
@@ -56,6 +56,16 @@
       <van-button type="danger" class="sg-btn" block bindtap="submitCheck" data-type="back" data-change="{{false}}" data-name="showBack">确认</van-button>
     </view>
   </van-popup>
+  <van-popup show="{{ showRent }}" 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}}" bind:editDate="editDate" index="{{index}}" showStatus="{{false}}" editDate="{{true}}"></inner-device-card>
+    </view>
+    <view class="sg-btns sg-flex">
+      <van-button type="default" class="sg-btn" block bindtap="switchShow" data-name="showRent" data-show="{{false}}">取消</van-button>
+      <van-button type="danger" class="sg-btn" block bindtap="submit" data-type="re-rent" data-change="{{false}}" data-name="showRent">确认</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}}">
@@ -77,11 +87,13 @@
           <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">
-          <inner-device-card item="{{item}}" wx:for="{{devices}}" wx:key="index" data-index="{{index}}" showStatus="{{false}}" showDelete="{{canEdit}}" bind:delete="deleteDevice"></inner-device-card>
+          <inner-device-card item="{{item}}" wx:for="{{devices}}" wx:key="index" index="{{index}}" data-index="{{index}}" showStatus="{{false}}" showDelete="{{canEdit}}" bind:delete="deleteDevice" editDate="{{actionType == 'back'}}" bind:editDate="editDate"></inner-device-card>
         </view>
       </block>
     </view>
   </view>
+  <van-calendar show="{{ showDate }}" bind:close="switchShow" bind:confirm="confirmDate" data-show="{{false}}"
+    type="range" class="sg-calendar" default-date="{{default_dates}}" />
   <block wx:if="{{tabIndex == 1 &&  canEdit}}">
     <view class="sg-submit-box sg-pad sg-fix-bottom sg-flex sg-align-center sg-center" bindtap="goAdd"
       data-url="/pages/add-inner-device/index">
@@ -119,7 +131,7 @@
     <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' 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 class="sg-action sg-pad sg-index-bg sg-green-bg" bindtap="check" data-name="showRent" data-change="2" data-type='re-rent'>续租
       </view>
     </block>
   </view>

+ 381 - 0
mini/pages/data-center/index.js

xqd
@@ -0,0 +1,381 @@
+// pages/data/index.js
+import http from '../../utils/http'
+import util from '../../utils/util'
+import api from '../../utils/api'
+const app = getApp()
+import * as echarts from '../../ec-canvas/echarts';
+
+let chart = null;
+let option = {}
+
+function initChart(canvas, width, height, dpr) {
+  chart = echarts.init(canvas, null, {
+    width: width,
+    height: height,
+    devicePixelRatio: dpr // new
+  });
+  canvas.setChart(chart);
+
+  option = {
+    legend: {
+      data: []
+    },
+    xAxis: {
+      type: 'category',
+      data: []
+    },
+    yAxis: {
+      type: 'value',
+      show: false
+    },
+    series: [{
+      data: [],
+      type: 'bar'
+    }]
+  };
+
+  chart.setOption(option);
+  return chart;
+}
+
+Page({
+
+  /**
+   * 页面的初始数据
+   */
+  data: {
+    projects: [],
+    project_ids: [],
+    project_names: '',
+    total_money: '0',
+    month_money: '0',
+    projectShow: false,
+    index: 0,
+    show: false,
+    isSearch: true,
+    charts: [{
+      name: '柱状图',
+      type: 'bar'
+    }, {
+      name: '折线图',
+      type: 'line'
+    }, {
+      name: '饼状图',
+      type: 'pie'
+    }, {
+      name: '明细图',
+      type: 'detail'
+    }, {
+      name: '雷达图',
+      type: 'radar'
+    }],
+    chartIndex: 0,
+    dateTypes: [{
+      name: '按年',
+      type: 'year'
+    }, {
+      name: '按月',
+      type: 'month'
+    }],
+    dateIndex: 0,
+    dateShow: false,
+    years_months: [],
+    date: '',
+    start: '',
+    end: '',
+    max_date: '',
+    min_date: '',
+    filter: {},
+    data: [],
+    ec: {
+      onInit: initChart
+    },
+    detail_data: []
+  },
+
+  /**
+   * 生命周期函数--监听页面加载
+   */
+  onLoad: function (options) {
+    var that = this
+    api.getByName(this, 'projects/getAll', 'projects', {}, function (res) {
+      that.getData()
+    });
+    // api.getByName(this, 'data/getYearsAndMonths', 'years_months');
+    // var maxDate = (new Date()).getTime()
+    // var minDate = (new Date()).getTime() - 2 * 365 * 24 * 3600 * 1000
+    // this.setData({
+    //   minDate,
+    //   maxDate
+    // })
+    this.getDateInfo()
+    app.resetDataFilter()
+  },
+
+  switchCheck: function (e) {
+    var index = e.currentTarget.dataset.index
+    var projects = this.data.projects
+    projects[index].checked = projects[index].checked ? false : true
+    this.setData({
+      projects
+    })
+  },
+
+  closeProject: function (e) {
+    var project_ids = []
+    var project_names = []
+    var projects = this.data.projects
+    for (var i = 0; i < projects.length; ++i) {
+      if (projects[i].checked) {
+        project_ids.push(projects[i].id)
+        project_names.push(projects[i].name)
+      }
+    }
+    project_names = project_names.join(',')
+    this.setData({
+      project_ids,
+      project_names
+    })
+    this.switchShow(e)
+    this.getData()
+    this.getTotalInfo()
+  },
+
+  getSearchItems: function () {
+    var ids = this.data.project_ids
+    if (ids.length <= 0) return false
+    var filter = this.data.filter
+    var chart_type = this.data.charts[this.data.chartIndex]
+    // var chat 
+    return {
+      project_ids: ids,
+      start_date: this.data.start_date,
+      end_date: this.data.end_date,
+      date: this.data.date,
+      type: this.data.dateIndex == 0 ? 'year' : 'month',
+      device_ids: filter.device_ids,
+      device_name_ids: filter.device_name_ids,
+      spec_ids: filter.spec_ids,
+      rent_type_ids: filter.rent_type_ids,
+      chart_type: chart_type.type
+    }
+  },
+
+  getTotalInfo() {
+    var data = this.getSearchItems()
+    var that = this
+    http({
+      url: 'data/getTotalInfo',
+      data: data,
+      success: function (res) {
+        if (res.code == 0) {
+          that.setData(res.data)
+        }
+      }
+    })
+  },
+
+  getDetailData() {
+    var data = this.getSearchItems()
+    var that = this
+    http({
+      url: 'data/getDetailData',
+      data: data,
+      success: function (res) {
+        if (res.code == 0) {
+          that.setData({
+            detail_data: res.data
+          })
+        }
+      }
+    })
+  },
+
+  getData() {
+    var data = this.getSearchItems()
+    var that = this
+    if (!data.project_ids || data.project_ids.length <= 0) return false
+    var chart_type = this.data.charts[this.data.chartIndex]
+    http({
+      url: 'data/getStat',
+      data: data,
+      success: function (res) {
+        if (res.code == 0) {
+          if (chart_type == 'detail') {
+            that.setData({
+              detail_data: res.data
+            })
+          } else {
+            that.setData({
+              data: res.data
+            })
+            that.updateChart()
+          }
+        }
+      }
+    })
+  },
+
+  getDateInfo() {
+    var that = this
+    http({
+      url: 'data/getDateInfo',
+      data: {},
+      success: function (res) {
+        if (res.code == 0) {
+          that.setData(res.data)
+        }
+      }
+    })
+  },
+
+  onChange: function (e) {
+    var value = e.detail.value
+    var name = e.currentTarget.dataset.name
+    if (this.data[name] == value) return false;
+    this.setData({
+      [name]: value
+    })
+    if (name == 'chartIndex') {
+      var chart = this.data.charts[this.data.chartIndex]
+      if (chart.type == 'detail') {
+        this.getDetailData()
+      } else {
+        this.getData()
+      }
+    } else if (name == 'date') {
+      this.getTotalInfo()
+    }
+  },
+  updateChart: function () {
+    var data = this.data.data
+    option.xAxis.data = data.names;
+    option.legend = {
+      data: data.legends
+    }
+
+    var type = this.data.charts[this.data.chartIndex].type
+    if (type == 'pie') {
+      option.series = [{
+        data: data.data,
+        type: type,
+        label: {
+          position: 'inner',
+          formatter: '{b}\n{d}%'
+        }
+      }]
+      option.xAxis.show = false
+    } else if (type == 'radar') {
+      option.xAxis.show = false
+      option.radar = {
+        // shape: 'circle',
+        indicator: data.indicator
+      }
+      option.series = [{
+        type: type,
+        data: data.data
+      }]
+    } else {
+      option.xAxis.show = true
+      var values = data.values
+      for (var i = 0; i < values.length; ++i) {
+        option.series[i] = {
+          label: {
+            show: true,
+            position: 'top'
+          },
+          name: data.legends[i],
+          type: type,
+          data: values[i]
+        }
+      }
+    }
+
+    chart.setOption(option)
+  },
+
+  radioChange: function (e) {
+    var dateIndex = e.currentTarget.dataset.index
+    if (dateIndex == this.data.dateIndex) return false
+    var start_date = this.data.start_date
+    var end_date = this.data.end_date
+    var start_date = dateIndex == 1 ? start_date + '-01' : start_date.substr(0, 7)
+    var end_date = dateIndex == 1 ? end_date + '-01' : end_date.substr(0, 7)
+    this.setData({
+      dateIndex,
+      start_date,
+      end_date
+    })
+  },
+
+  switchShow: function (e) {
+    var name = e.currentTarget.dataset.name
+    var show = e.currentTarget.dataset.show ? e.currentTarget.dataset.show : !this.data[name]
+    this.setData({
+      [name]: show
+    })
+    if (name == 'dateShow' && !show) {
+      this.getData()
+    }
+  },
+  /**
+   * 生命周期函数--监听页面初次渲染完成
+   */
+  onReady: function () {
+
+  },
+
+  /**
+   * 生命周期函数--监听页面显示
+   */
+  onShow: function () {
+    this.getTabBar().init();
+    var filter = wx.getStorageSync('sg-data-filters')
+    this.setData({
+      filter: filter
+    })
+    this.getData()
+  },
+
+  navigate: function (e) {
+    var url = e.currentTarget.dataset.url
+    wx.navigateTo({
+      url: url,
+    })
+  },
+
+  /**
+   * 生命周期函数--监听页面隐藏
+   */
+  onHide: function () {
+
+  },
+
+  /**
+   * 生命周期函数--监听页面卸载
+   */
+  onUnload: function () {
+
+  },
+
+  /**
+   * 页面相关事件处理函数--监听用户下拉动作
+   */
+  onPullDownRefresh: function () {
+
+  },
+
+  /**
+   * 页面上拉触底事件的处理函数
+   */
+  onReachBottom: function () {
+
+  },
+
+  /**
+   * 用户点击右上角分享
+   */
+  onShareAppMessage: function () {
+
+  }
+})

+ 4 - 0
mini/pages/data-center/index.json

xqd
@@ -0,0 +1,4 @@
+{
+  "navigationBarTitleText": "数据中心",
+  "usingComponents": {}
+}

+ 125 - 0
mini/pages/data-center/index.wxml

xqd
@@ -0,0 +1,125 @@
+<!--pages/data/index.wxml-->
+<view class="sg-container sg-index-bg">
+  <view class="sg-flex sg-pad sg-align-center sg-index-bg">
+    <view class="sg-white-bg sg-pad-sm sg-flex-grow sg-gray-color sg-flex sg-align-center" bindtap="switchShow"
+      data-show="{{true}}" data-name="projectShow">
+      <view class="sg-flex-grow">{{project_names ? project_names : '选择查看项目'}}</view>
+      <van-icon name="arrow-down"></van-icon>
+    </view>
+    <van-icon name="search" class="sg-icon sg-white sg-pad-sm" style="padding-right: 0" bindtap="getData"></van-icon>
+  </view>
+  <van-popup show="{{ projectShow }}" position="bottom" custom-style="height: 100%;">
+    <view>
+      <view class="sg-flex sg-align-center sg-space-between sg-fix-top sg-white-bg sg-pad sg-white-bg"
+        style="box-sizing: border-box;z-index:100">
+        <view></view>
+        <view class="sg-bold">选择项目</view>
+        <view class="sg-gray-color" bindtap="closeProject" data-show="{{false}}" data-name="projectShow">确定</view>
+      </view>
+      <view class="sg-list sg-pad" style="margin-top: 80rpx">
+        <view wx:for="{{projects}}" wx:key="index"
+          class="sg-flex sg-align-center sg-space-between sg-pad-tb-sm sg-bottom-border {{item.checked ? 'sg-index-color' : ''}}"
+          bindtap="switchCheck" data-index="{{index}}">
+          <view>{{item.name}}</view>
+          <van-icon name="{{item.checked ? 'passed' : 'circle'}}" class="sg-icon" />
+        </view>
+      </view>
+    </view>
+  </van-popup>
+  <view class="sg-white sg-bold sg-flex sg-align-center sg-space-around">
+    <view class="sg-center">
+      <view class="sg-font-lg">{{total_money}}</view>
+      <view class="sg-font-xs sg-pad-tb-sm">项目累计消费</view>
+    </view>
+    <view class="sg-center">
+      <view class="sg-font-lg">{{month_money}}</view>
+      <view class="sg-font-xs sg-pad-tb-sm">当月累计消费</view>
+    </view>
+    <view class="sg-center">
+      <picker mode="date" value="{{date}}" start="{{min_date}}" end="{{max_date}}" bindchange="onChange"
+        data-name="date" fields="month">
+        <view class="picker">
+          <view>时间选择</view>
+          <view class="sg-font-small sg-pad-tb-sm sg-flex sg-align-center">
+            <text>{{date}}</text>
+            <van-icon name="arrow-down" class="sg-icon"></van-icon>
+          </view>
+        </view>
+      </picker>
+    </view>
+  </view>
+  <view class="sg-white-bg sg-chart-box" wx:if="{{!projectShow && !dateShow}}">
+    <block wx:if="{{project_names}}">
+      <view class="sg-flex sg-pad sg-align-center sg-space-between">
+        <view>
+          <picker bindchange="onChange" value="{{chartIndex}}" range="{{charts}}" range-key="name"
+            data-name="chartIndex" class="sg-flex-grow">
+            <view class="picker sg-flex sg-align-center">
+              <text>{{chartIndex >= 0 ? charts[chartIndex].name : '显示类型'}}</text>
+              <van-icon name="arrow-down"></van-icon>
+            </view>
+          </picker>
+        </view>
+        <view class="sg-flex sg-align-center">
+          <!-- <view class="sg-radio-group sg-flex sg-align-center sg-fon-small sg-margin-right sg-light-gray-bg">
+            <view class="sg-radio {{index == dateIndex ? 'sg-shadow sg-selected sg-index-bg sg-white sg-bold' : ''}}"
+              wx:for="{{dateTypes}}" wx:key="index" data-index="{{index}}" data-name="dateIndex" bindtap="radioChange">
+              {{item.name}}</view>
+          </view> -->
+          <van-icon name="notes-o" class="sg-icon-lg sg-margin-right" bindtap="switchShow" data-name="dateShow"
+            data-show="{{true}}"></van-icon>
+          <van-icon name="filter-o" class="sg-icon-lg" bindtap="navigate" data-url="/pages/filter-data/index">
+          </van-icon>
+        </view>
+      </view>
+      <view class="sg-chart">
+        <block wx:if="{{chartIndex == 3}}">
+          <detail-table data="{{detail_data}}"></detail-table>
+        </block>
+        <block wx:else>
+          <ec-canvas id="mychart-dom-bar" canvas-id="mychart-bar" ec="{{ ec }}"></ec-canvas>
+        </block>
+      </view>
+    </block>
+    <block wx:else>
+      <view class="sg-center sg-text-center sg-gray-color sg-font-small sg-pad">
+        <view>筛选条件暂无</view>
+        <view>请选择需要查看的项目后</view>
+        <view>数据才可进行查看</view>
+      </view>
+    </block>
+  </view>
+  <van-dialog use-slot title="选择日期范围" confirm-button-color="#5693FC" show="{{ dateShow }}" bind:confirm="switchShow" data-name="dateShow"
+    data-show="{{false}}">
+    <view class="sg-pad">
+      <view class="sg-flex sg-align-center sg-pad-tb-sm sg-space-between">
+        <view>日期范围</view>
+        <view class="sg-flex sg-align-center sg-space-between">
+          <picker mode="date" value="{{start_date}}" start="{{min_date}}" end="{{end_date}}"
+            fields="{{dateIndex == 0 ? 'month' : 'day'}}" bindchange="onChange" data-name="start_date">
+            <view class="picker">
+              {{start_date}}
+            </view>
+          </picker>
+          <view class="sg-bold sg-gray-color" style="margin: 0 15rpx">至</view>
+          <picker mode="date" value="{{end_date}}" start="{{min_date}}" end="{{end_date}}"
+            fields="{{dateIndex == 0 ? 'month' : 'day'}}" bindchange="onChange" data-name="end_date">
+            <view class="picker">
+              {{end_date}}
+            </view>
+          </picker>
+        </view>
+      </view>
+      <view class="sg-flex sg-align-center sg-pad-tb-sm sg-space-between sg-space-between">
+        <view class="sg-margin-right">按年按月</view>
+        <view>
+          <view class="sg-radio-group sg-flex sg-align-center sg-fon-small sg-margin-right sg-light-gray-bg">
+            <view class="sg-radio {{index == dateIndex ? 'sg-shadow sg-selected sg-index-bg sg-white sg-bold' : ''}}"
+              wx:for="{{dateTypes}}" wx:key="index" data-index="{{index}}" data-name="dateIndex" bindtap="radioChange">
+              {{item.name}}</view>
+          </view>
+        </view>
+      </view>
+    </view>
+  </van-dialog>
+</view>

+ 24 - 0
mini/pages/data-center/index.wxss

xqd
@@ -0,0 +1,24 @@
+/* pages/data/index.wxss */
+.sg-chart-box {
+  min-height: 90vh;
+  border-top-right-radius: 50rpx;
+  border-top-left-radius: 50rpx;
+  margin-top: 40rpx;
+}
+.sg-radio-group {
+  padding: 10rpx;
+  border-radius: 40rpx;
+}
+.sg-radio-group  .sg-selected {
+  border-radius: 40rpx;
+}
+.sg-radio-group .sg-radio {
+  padding: 10rpx 30rpx;
+}
+.sg-calendar {
+  margin-bottom: 200rpx;
+}
+.sg-chart {
+  width: 100%;
+  height: 50vh;
+}

+ 45 - 163
mini/pages/data/index.js

xqd xqd xqd xqd xqd xqd
@@ -47,7 +47,7 @@ Page({
     projects: [],
     project_ids: [],
     project_names: '',
-    total_money: '0',
+    year_money: '0',
     month_money: '0',
     projectShow: false,
     index: 0,
@@ -69,7 +69,7 @@ Page({
       name: '雷达图',
       type: 'radar'
     }],
-    chartIndex: 0,
+    chartIndex: 1,
     dateTypes: [{
       name: '按年',
       type: 'year'
@@ -90,7 +90,8 @@ Page({
     ec: {
       onInit: initChart
     },
-    detail_data: []
+    detail_data: [],
+    orderBy: 'asc'
   },
 
   /**
@@ -98,153 +99,62 @@ Page({
    */
   onLoad: function (options) {
     var that = this
-    api.getByName(this, 'projects/getAll', 'projects', {}, function (res) {
-      that.getData()
-    });
-    api.getByName(this, 'data/getYearsAndMonths', 'years_months');
-    // var maxDate = (new Date()).getTime()
-    // var minDate = (new Date()).getTime() - 2 * 365 * 24 * 3600 * 1000
-    // this.setData({
-    //   minDate,
-    //   maxDate
-    // })
-    this.getDateInfo()
-    app.resetDataFilter()
+    api.getByName(this, 'projects/getAll', 'projects', {});
   },
 
-  switchCheck: function (e) {
-    var index = e.currentTarget.dataset.index
-    var projects = this.data.projects
-    projects[index].checked = projects[index].checked ? false : true
+  updateValue: function(e) {
+    var name = e.currentTarget.dataset.name
+    var value = e.currentTarget.dataset.value
     this.setData({
-      projects
+      [name]: value
     })
+    if(name == 'orderBy') {
+      this.getChartData()
+    }
   },
 
-  closeProject: function (e) {
-    var project_ids = []
-    var project_names = []
-    var projects = this.data.projects
-    for (var i = 0; i < projects.length; ++i) {
-      if (projects[i].checked) {
-        project_ids.push(projects[i].id)
-        project_names.push(projects[i].name)
-      }
-    }
-    project_names = project_names.join(',')
+  updateDate(e) {
     this.setData({
-      project_ids,
-      project_names
+      date: e.detail.date
     })
-    this.switchShow(e)
-    this.getData()
-    this.getTotalInfo()
-  },
-
-  getSearchItems: function () {
-    var ids = this.data.project_ids
-    if (ids.length <= 0) return false
-    var filter = this.data.filter
-    var chart_type = this.data.charts[this.data.chartIndex]
-    // var chat 
-    return {
-      project_ids: ids,
-      start_date: this.data.start_date,
-      end_date: this.data.end_date,
-      date: this.data.date,
-      type: this.data.dateIndex == 0 ? 'year' : 'month',
-      device_ids: filter.device_ids,
-      device_name_ids: filter.device_name_ids,
-      spec_ids: filter.spec_ids,
-      rent_type_ids: filter.rent_type_ids,
-      chart_type: chart_type.type
-    }
+    this.getYearAndMonthMoney()
+    this.getChartData()
   },
 
-  getTotalInfo() {
-    var data = this.getSearchItems()
+  getYearAndMonthMoney() {
     var that = this
     http({
-      url: 'data/getTotalInfo',
-      data: data,
-      success: function (res) {
-        if (res.code == 0) {
+      url: 'data/getYearAndMonthMoney',
+      data: { 
+        date: this.data.date
+      },
+      success: function(res) {
+        if(res.code == 0) {
           that.setData(res.data)
         }
       }
     })
   },
 
-  getDetailData() {
-    var data = this.getSearchItems()
-    var that = this
-    http({
-      url: 'data/getDetailData',
-      data: data,
-      success: function (res) {
-        if (res.code == 0) {
-          that.setData({
-            detail_data: res.data
-          })
-        }
-      }
-    })
-  },
-
-  getData() {
-    var data = this.getSearchItems()
+  getChartData: function() {
+    var chartIndex = this.data.chartIndex
     var that = this
-    if (!data.project_ids || data.project_ids.length <= 0) return false
-    var chart_type = this.data.charts[this.data.chartIndex]
-    http({
-      url: 'data/getStat',
-      data: data,
-      success: function (res) {
-        if (res.code == 0) {
-          if (chart_type == 'detail') {
-            that.setData({
-              detail_data: res.data
-            })
-          } else {
+    if(chartIndex == 1) {
+      http({
+        url: 'data/projectStat',
+        data: {
+          date: this.data.date,
+          orderBy: this.data.orderBy
+        },
+        success: function(res) {
+          if(res.code == 0) {
             that.setData({
               data: res.data
             })
             that.updateChart()
           }
         }
-      }
-    })
-  },
-
-  getDateInfo() {
-    var that = this
-    http({
-      url: 'data/getDateInfo',
-      data: {},
-      success: function (res) {
-        if (res.code == 0) {
-          that.setData(res.data)
-        }
-      }
-    })
-  },
-
-  onChange: function (e) {
-    var value = e.detail.value
-    var name = e.currentTarget.dataset.name
-    if (this.data[name] == value) return false;
-    this.setData({
-      [name]: value
-    })
-    if (name == 'chartIndex') {
-      var chart = this.data.charts[this.data.chartIndex]
-      if (chart.type == 'detail') {
-        this.getDetailData()
-      } else {
-        this.getData()
-      }
-    } else if (name == 'date') {
-      this.getTotalInfo()
+      })
     }
   },
   updateChart: function () {
@@ -253,42 +163,19 @@ Page({
     option.legend = {
       data: data.legends
     }
-
-    var type = this.data.charts[this.data.chartIndex].type
-    if (type == 'pie') {
+    var chartIndex = this.data.chartIndex
+    if(chartIndex == 1) {
+      option.xAxis.show = true
+      var values = data.values
       option.series = [{
-        data: data.data,
-        type: type,
         label: {
-          position: 'inner',
-          formatter: '{b}\n{d}%'
-        }
-      }]
-      option.xAxis.show = false
-    } else if (type == 'radar') {
-      option.xAxis.show = false
-      option.radar = {
-        // shape: 'circle',
-        indicator: data.indicator
-      }
-      option.series = [{
-        type: type,
-        data: data.data
+          show: true,
+          position: 'top'
+        },
+        name: data.names,
+        type: 'bar',
+        data: values
       }]
-    } else {
-      option.xAxis.show = true
-      var values = data.values
-      for (var i = 0; i < values.length; ++i) {
-        option.series[i] = {
-          label: {
-            show: true,
-            position: 'top'
-          },
-          name: data.legends[i],
-          type: type,
-          data: values[i]
-        }
-      }
     }
 
     chart.setOption(option)
@@ -330,11 +217,6 @@ Page({
    */
   onShow: function () {
     this.getTabBar().init();
-    var filter = wx.getStorageSync('sg-data-filters')
-    this.setData({
-      filter: filter
-    })
-    this.getData()
   },
 
   navigate: function (e) {

+ 0 - 1
mini/pages/data/index.json

xqd
@@ -1,4 +1,3 @@
 {
-  "navigationBarTitleText": "数据中心",
   "usingComponents": {}
 }

+ 28 - 89
mini/pages/data/index.wxml

xqd xqd
@@ -1,13 +1,5 @@
 <!--pages/data/index.wxml-->
 <view class="sg-container sg-index-bg">
-  <view class="sg-flex sg-pad sg-align-center sg-index-bg">
-    <view class="sg-white-bg sg-pad-sm sg-flex-grow sg-gray-color sg-flex sg-align-center" bindtap="switchShow"
-      data-show="{{true}}" data-name="projectShow">
-      <view class="sg-flex-grow">{{project_names ? project_names : '选择查看项目'}}</view>
-      <van-icon name="arrow-down"></van-icon>
-    </view>
-    <van-icon name="search" class="sg-icon sg-white sg-pad-sm" style="padding-right: 0" bindtap="getData"></van-icon>
-  </view>
   <van-popup show="{{ projectShow }}" position="bottom" custom-style="height: 100%;">
     <view>
       <view class="sg-flex sg-align-center sg-space-between sg-fix-top sg-white-bg sg-pad sg-white-bg"
@@ -28,98 +20,45 @@
   </van-popup>
   <view class="sg-white sg-bold sg-flex sg-align-center sg-space-around">
     <view class="sg-center">
-      <view class="sg-font-lg">{{total_money}}</view>
-      <view class="sg-font-xs sg-pad-tb-sm">项目累计消费</view>
+      <view class="sg-font-lg">{{year_money}}</view>
+      <view class="sg-font-xs sg-pad-tb-sm">
+        <view>当年公司租赁设备</view>
+        <view>费用总和</view>
+      </view>
     </view>
     <view class="sg-center">
       <view class="sg-font-lg">{{month_money}}</view>
-      <view class="sg-font-xs sg-pad-tb-sm">当月累计消费</view>
+      <view class="sg-font-xs sg-pad-tb-sm">
+        <view>当月公司租赁设备</view>
+        <view>费用总和</view>
+      </view>
     </view>
     <view class="sg-center">
-      <picker mode="date" value="{{date}}" start="{{min_date}}" end="{{max_date}}" bindchange="onChange"
-        data-name="date" fields="month">
-        <view class="picker">
-          <view>时间选择</view>
-          <view class="sg-font-small sg-pad-tb-sm sg-flex sg-align-center">
-            <text>{{date}}</text>
-            <van-icon name="arrow-down" class="sg-icon"></van-icon>
-          </view>
-        </view>
-      </picker>
+      <sg-date-picker bind:update="updateDate"></sg-date-picker>
     </view>
   </view>
-  <view class="sg-white-bg sg-chart-box" wx:if="{{!projectShow && !dateShow}}">
-    <block wx:if="{{project_names}}">
-      <view class="sg-flex sg-pad sg-align-center sg-space-between">
-        <view>
-          <picker bindchange="onChange" value="{{chartIndex}}" range="{{charts}}" range-key="name"
-            data-name="chartIndex" class="sg-flex-grow">
-            <view class="picker sg-flex sg-align-center">
-              <text>{{chartIndex >= 0 ? charts[chartIndex].name : '显示类型'}}</text>
-              <van-icon name="arrow-down"></van-icon>
-            </view>
-          </picker>
-        </view>
-        <view class="sg-flex sg-align-center">
-          <!-- <view class="sg-radio-group sg-flex sg-align-center sg-fon-small sg-margin-right sg-light-gray-bg">
-            <view class="sg-radio {{index == dateIndex ? 'sg-shadow sg-selected sg-index-bg sg-white sg-bold' : ''}}"
-              wx:for="{{dateTypes}}" wx:key="index" data-index="{{index}}" data-name="dateIndex" bindtap="radioChange">
-              {{item.name}}</view>
-          </view> -->
-          <van-icon name="notes-o" class="sg-icon-lg sg-margin-right" bindtap="switchShow" data-name="dateShow"
-            data-show="{{true}}"></van-icon>
-          <van-icon name="filter-o" class="sg-icon-lg" bindtap="navigate" data-url="/pages/filter-data/index">
-          </van-icon>
-        </view>
-      </view>
-      <view class="sg-chart">
-        <block wx:if="{{chartIndex == 3}}">
-          <detail-table data="{{detail_data}}"></detail-table>
-        </block>
-        <block wx:else>
-          <ec-canvas id="mychart-dom-bar" canvas-id="mychart-bar" ec="{{ ec }}"></ec-canvas>
-        </block>
-      </view>
-    </block>
-    <block wx:else>
-      <view class="sg-center sg-text-center sg-gray-color sg-font-small sg-pad">
-        <view>筛选条件暂无</view>
-        <view>请选择需要查看的项目后</view>
-        <view>数据才可进行查看</view>
-      </view>
-    </block>
-  </view>
-  <van-dialog use-slot title="选择日期范围" confirm-button-color="#5693FC" show="{{ dateShow }}" bind:confirm="switchShow" data-name="dateShow"
-    data-show="{{false}}">
-    <view class="sg-pad">
-      <view class="sg-flex sg-align-center sg-pad-tb-sm sg-space-between">
-        <view>日期范围</view>
-        <view class="sg-flex sg-align-center sg-space-between">
-          <picker mode="date" value="{{start_date}}" start="{{min_date}}" end="{{end_date}}"
-            fields="{{dateIndex == 0 ? 'month' : 'day'}}" bindchange="onChange" data-name="start_date">
-            <view class="picker">
-              {{start_date}}
-            </view>
-          </picker>
-          <view class="sg-bold sg-gray-color" style="margin: 0 15rpx">至</view>
-          <picker mode="date" value="{{end_date}}" start="{{min_date}}" end="{{end_date}}"
-            fields="{{dateIndex == 0 ? 'month' : 'day'}}" bindchange="onChange" data-name="end_date">
-            <view class="picker">
-              {{end_date}}
-            </view>
-          </picker>
-        </view>
+  <view class="sg-white-bg sg-chart-box">
+    <view class="sg-flex sg-pad sg-align-center sg-space-between">
+      <view>
+        <van-icon name="ascending" wx:if="{{orderBy == 'asc'}}" class="sg-index-color sg-icon-lg" bindtap="updateValue" data-name="orderBy" data-value="desc"/>
+        <van-icon name="descending" wx:else class="sg-index-color sg-icon-lg" bindtap="updateValue" data-name="orderBy" data-value="asc"/>
       </view>
-      <view class="sg-flex sg-align-center sg-pad-tb-sm sg-space-between sg-space-between">
-        <view class="sg-margin-right">按年按月</view>
-        <view>
-          <view class="sg-radio-group sg-flex sg-align-center sg-fon-small sg-margin-right sg-light-gray-bg">
+      <view class="sg-flex sg-align-center">
+        <!-- <view class="sg-radio-group sg-flex sg-align-center sg-fon-small sg-margin-right sg-light-gray-bg">
             <view class="sg-radio {{index == dateIndex ? 'sg-shadow sg-selected sg-index-bg sg-white sg-bold' : ''}}"
               wx:for="{{dateTypes}}" wx:key="index" data-index="{{index}}" data-name="dateIndex" bindtap="radioChange">
               {{item.name}}</view>
-          </view>
-        </view>
+          </view> -->
+        <van-icon name="notes-o" class="sg-icon-lg sg-margin-right" bindtap="switchShow" data-name="dateShow"
+          data-show="{{true}}"></van-icon>
+        <van-icon name="filter-o" class="sg-icon-lg" bindtap="navigate" data-url="/pages/filter-data/index">
+        </van-icon>
       </view>
     </view>
-  </van-dialog>
+    <view class="sg-chart sg-flex sg-align-center sg-space-between">
+      <van-icon name="arrow-left" class="sg-icon-lg sg-index-color" hidden="{{chartIndex == 0}}"/>
+      <ec-canvas id="mychart-dom-bar" canvas-id="mychart-bar" ec="{{ ec }}"></ec-canvas>
+      <van-icon name="arrow" class="sg-icon-lg sg-index-color"  hidden="{{chartIndex == 2}}"/>
+    </view>
+  </view>
 </view>

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

xqd
@@ -11,7 +11,7 @@
     </view>
     <view class="sg-tabs sg-flex sg-align-center sg-white-bg sg-pad sg-bottom-border sg-top-border sg-font-small">
       <view wx:for="{{tabs}}" wx:key="index" class="sg-tab {{tabIndex == index ? 'sg-selected' : ''}}"
-        bindtap="switchTab" data-index="{{index}}" hidden="{{ type=='check' && index > 2 }}">{{ item }}</view>
+        bindtap="switchTab" data-index="{{index}}" hidden="{{ index == 2 && (!role || !role.rights || !role.rights.applyHandle) }}">{{ item }}</view>
     </view>
   </view>
   <view class="sg-list-box sg-pad">

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

xqd
@@ -30,7 +30,7 @@ Page({
     this.setData({
       list: []
     })
-    this.getList();
+    this.search();
     api.getByName(this, 'notifications/notReadCount', 'notReadCount');
     var that = this;
     api.getByName(this, 'users/getTopRole', 'topRole', {}, function(res) {

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

xqd
@@ -88,7 +88,7 @@ Page({
     http({
       url: 'orders/changePrice',
       data: {
-        id: order_device.pivot.id,
+        id: order_device.id,
         price: price
       },
       success: function (res) {

+ 5 - 1
mini/pages/project-user/index.js

xqd xqd xqd
@@ -1,6 +1,7 @@
 // pages/project-user/index.js
 import http from '../../utils/http'
 import util from '../../utils/util'
+import api from '../../utils/api'
 import Dialog from '../../miniprogram_npm/@vant/weapp/dialog/dialog';
 Page({
 
@@ -12,7 +13,8 @@ Page({
     list: [],
     keyword: '',
     project: null,
-    showAction: false
+    showAction: false,
+    role: null
   },
 
   /**
@@ -82,6 +84,8 @@ Page({
   selectUser: function (e) {
     var index = e.currentTarget.dataset.index
     var list = this.data.list
+    var item = list[index]
+    if(item.project_role.level >= this.data.project.role.level) return false
     for (var i = 0; i < list.length; ++i) {
       if (i != index) list[i].selected = false
     }

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

xqd
@@ -34,7 +34,7 @@
       </block>
     </view>
   </view>
-  <view class="sg-menu-box sg-pad">
+  <view class="sg-menu-box sg-pad" wx:if="{{ role && role.rights && role.rights.applyHandle }}">
     <view class="sg-menu-header">
       <text class="sg-title sg-bold">设备调用</text>
       <text class="sg-sub-title sg-gray-color">内部设备调用</text>

+ 2 - 0
routes/api.php

xqd
@@ -83,6 +83,8 @@ $api->version('v1', ['namespace' => 'App\Http\Controllers\Api\mini', 'prefix' =>
     $api->any('data/getStat', 'DataController@getStat');
     $api->any('data/getTotalInfo', 'DataController@getTotalInfo');
     $api->any('data/getDetailData', 'DataController@getDetailData');
+    $api->any('data/getYearAndMonthMoney', 'DataController@getYearAndMonthMoney');
+    $api->any('data/projectStat', 'DataController@projectStat');
 
     $api->any('device-names/get', 'DeviceNameController@get');