李浩杰 před 4 roky
rodič
revize
d3e582a7bf

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

xqd
@@ -17,7 +17,7 @@ class TestController extends Controller
 {
     public function index(Request $request)
     {
-        dd(OrderDevice::where('device_id', 1)->pluck('order_id')->unique());
+        dd(count('1111'));
     	return view('admin.test.index');
     }
 }

+ 136 - 22
app/Http/Controllers/Api/mini/DataController.php

xqd xqd xqd xqd
@@ -2,6 +2,7 @@
 
 namespace App\Http\Controllers\Api\mini;
 
+use App\Models\Device;
 use App\Models\Order;
 use App\Models\OrderDevice;
 use App\Models\Project;
@@ -15,6 +16,14 @@ class DataController extends BaseController
 
     protected $order_device;
 
+    protected $order_ids = [];
+
+    protected $project_ids = [];
+
+    protected $start_at;
+
+    protected $end_at;
+
     public function __construct()
     {
         $this->order = new Order();
@@ -51,18 +60,46 @@ class DataController extends BaseController
 
     public function getDateInfo()
     {
-        $now = Carbon::now();
-        $date = $now->year . '-' . $now->month;
-        $min_date = Carbon::now()->subYears(1)->getTimestamp() * 1000;
-        return $this->success(['data' => compact('date', 'min_date')]);
+        $max_date = Carbon::now()->toDateString();
+//        $order = $this->order->orderBy('created_at', 'desc')->first();
+//        $min_date = $order ? substr($order->created_at, 0, 10) : Carbon::now()->subYear()->toDateString();
+        $min_date = Carbon::now()->subYears(10)->toDateString();
+        $date = substr($max_date, 0, 7);
+        $start_date = $max_date;
+        $end_date = Carbon::now()->addMonth()->toDateString();
+        $start_date = substr($start_date, 0, 7);
+        $end_date = substr($end_date, 0, 7);
+        return $this->success(['data' => compact('date', 'min_date', 'max_date', 'start_date', 'end_date')]);
     }
 
-    public function getStat(Request $request)
+    public function getStartAt($date)
+    {
+        return strlen($date) <= 7 ? $date . '-01 00:00:00' : $date . ' 00:00:00';
+    }
+
+    public function getEndAt($date)
+    {
+        return strlen($date) <= 7 ? Carbon::createFromTimeString($date . '-01 00:00:00')->addMonth(1)->toDateTimeString() : Carbon::createFromTimeString($date . ' 00:00:00')->addDay(1)->toDateTimeString();
+    }
+
+    public function getOrders(Request $request)
+    {
+        $order_ids = $this->getOrderIds($request);
+
+        $start_at = $this->getStartAt($request->input('start_date'));
+        $end_at = $this->getEndAt($request->input('end_date'));
+        return $this->order->whereIn('id', $order_ids)->where([
+            ['type', '=', 1],
+            ['created_at', '>=', $start_at],
+            ['created_at', '<', $end_at]
+        ])->get();
+    }
+
+    public function getOrderIds(Request $request)
     {
-        $date = $request->input('date') ? $request->input('date') : '2020-1';
-        $date_data = $this->parseDate($date);
-        $date = Carbon::createFromDate($date_data['year'], $date_data['month'], $date_data['day'])->toDateTimeString();
         $ids = $request->input('project_ids');
+        if(!$ids || count($ids) < 0) return false;
+        $this->project_ids = $ids;
         $order_devices = $this->order_device->whereIn('project_id', $ids);
 
         $in_items = ['device_ids', 'device_name_ids', 'spec_ids', 'rent_type_ids'];
@@ -72,46 +109,123 @@ class DataController extends BaseController
                 $item_ids = collect($request->input($item))->filter(function($id) {
                     return $id;
                 });
-                if($item_ids->count() > 0) {
+                if($item_ids && $item_ids->count() > 0) {
                     $order_devices = $order_devices->whereIn($key_items[$key], $item_ids);
                 }
             }
         }
 
-        $order_ids = $order_devices->pluck('order_id')->unique();
-        $orders = $this->order->whereIn('id', $order_ids)->get();
+        return $order_devices->pluck('order_id')->unique();
+    }
+
+    public function getStat(Request $request)
+    {
+        if(!$request->input('project_ids')) return $this->error(['msg' => '']);
+        if($request->input('chart_type') == 'pie') return $this->getPieData($request);
+        $orders = $this->getOrders($request);
+        if(!$orders) return $this->error(['msg' => '']);
         $names = [];
         $values = [];
         // year|month
         $type = $request->input('type') ? $request->input('type') : 'year';
         $cnt = 0;
-        $projects = Project::whereIn('id', $ids)->get();
+        $projects = Project::whereIn('id', $this->project_ids)->get();
 
         foreach($orders as $item) {
             if($this->inDate($names, $item->created_at, $type)) {
                 foreach ($projects as $key => $project) {
-                    $values[$key][$cnt-1] = $project->id == $item->project_id ? $values[$key][$cnt-1] + 1 : $values[$key][$cnt-1];
+                    $values[$key][$cnt-1] = $project->id == $item->project_id ? $values[$key][$cnt-1] + ($item->money / 100) : $values[$key][$cnt-1];
                 }
 
             } else {
                 $names[$cnt] = $type == 'year' ? substr($item->created_at, 0, 7) : substr($item->created_at, 0, 10);
                 foreach ($projects as $key => $project) {
-                    $values[$key][$cnt] = $project->id == $item->project_id ? 1 : 0;
+                    $values[$key][$cnt] = $project->id == $item->project_id ? ($item->money / 100) : 0;
                 }
                 $cnt = $cnt + 1;
             }
         }
         $legends = $projects->pluck('name');
+        return $this->success(['data' => compact('values', 'names', 'legends')]);
+    }
 
-        $total_project = $orders->sum('money') / 100;
-        $tmp = Carbon::createFromTimeString($date);
-        if($tmp->month == 12) {
-            $next_month = Carbon::createFromDate($tmp->year + 1, 1, 1)->toDateTimeString();
-        } else {
-            $next_month = Carbon::createFromDate($tmp->year, $tmp->month + 1, 1)->toDateTimeString();
+    public function getPieData(Request $request)
+    {
+        $order_ids = $this->getOrderIds($request);
+        if(!$order_ids) return $this->error(['msg' => '']);
+
+        $total = OrderDevice::whereIn('order_id', $order_ids)->count();
+        $devices = Device::all();
+        $data = [];
+        foreach($devices as $device) {
+            $tmp = OrderDevice::whereIn('order_id', $order_ids)->where('device_id', $device->id)->count();
+            $percent = $total > 0 ? round(($tmp / $total * 10000)) / 100 : '0';
+            array_push($data, ['name' => $device->name, 'value' => $percent]);
         }
-        $total_month = $orders->where('created_at', '<', $next_month)->sum('money') / 100;
-        return $this->success(['data' => compact('values', 'names', 'legends', 'total_project', 'total_month')]);
+
+        $legends = $devices->pluck('name');
+        return $this->success(['data' => compact('data', 'legends')]);
+    }
+
+    public function getDetailData(Request $request)
+    {
+        $order_ids = $this->getOrderIds($request);
+        if(!$order_ids) return $this->error(['msg' => '']);
+
+        $order_devices = OrderDevice::whereIn('order_id', $order_ids)->orderBy('created_at')->get();
+        $devices = Device::all();
+
+        $dates = [];
+        // year|month
+        $type = $request->input('type') ? $request->input('type') : 'year';
+        $columns = [];
+        $date = '';
+        $values = [
+            ['date' => '日期', 'total' => '总金额', 'data' => $devices->pluck('name')]
+        ];
+        foreach($order_devices as $item) {
+            if($this->inDate($dates, $item->created_at, $type)) {
+                foreach($devices as $key => $device) {
+                    $money = $device->id == $item->device_id ? ($item->price * $item->quantity) / 100 : 0;
+                    $columns[$key] = $columns[$key] + $money;
+                }
+            } else {
+                $date = $type == 'year' ? substr($item->created_at, 0, 7) : substr($item->created_at, 0, 10);
+                array_push($dates, $date);
+                if(count($columns) > 0) {
+                    array_push($values, [
+                        'date' => $date,
+                        'total' => collect($columns)->sum() / 100,
+                        'data' => $columns
+                    ]);
+                }
+                $columns = [];
+                foreach($devices as $device) {
+                    $money = $device->id == $item->device_id ? ($item->price * $item->quantity) / 100 : 0;
+                    array_push($columns, $money);
+                }
+            }
+        }
+        if(count($columns) > 0) {
+            array_push($values, [
+                'date' => $date,
+                'total' => collect($columns)->sum(),
+                'data' => $columns
+            ]);
+        }
+        return $this->success(['data' => $values]);
+    }
+
+    public function getTotalInfo(Request $request)
+    {
+        $start_at = $this->getStartAt($request->input('date'));
+        $end_at = $this->getStartAt($request->input('date'));
+        $total_money = $this->order->whereIn('project_id', $request->input('project_ids'))->sum('money') / 100;
+        $month_money = $this->order->whereIn('project_id', $request->input('project_ids'))->where([
+            ['created_at', '>=', $start_at],
+            ['created_at', '<', $end_at]
+        ])->sum('money') / 100;
+        return $this->success(['data' => compact('total_money', 'month_money')]);
     }
 
     public function inDate($dates, $created_at, $type)

+ 8 - 0
app/Models/DayStat.php

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

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

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

+ 30 - 0
database/migrations/2020_12_21_105350_add_project_id_today_stats.php

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

+ 26 - 0
database/seeds/DayStatSeeder.php

xqd
@@ -0,0 +1,26 @@
+<?php
+
+use Illuminate\Database\Seeder;
+
+class DayStatSeeder extends Seeder
+{
+    /**
+     * Run the database seeds.
+     *
+     * @return void
+     */
+    public function run()
+    {
+        $devices = \App\Models\Device::all();
+        \App\Models\DayStat::truncate();
+        $projects = \App\Models\Project::all();
+        for($i = 0; $i < 100; $i++) {
+            \App\Models\DayStat::create([
+                'date' => \Carbon\Carbon::now()->subDays(mt_rand(1, 100))->toDateString(),
+                'device_id' => $devices->random()->id,
+                'project_id' => $projects->random()->id,
+                'money' => mt_rand(1000, 9999)
+            ]);
+        }
+    }
+}

+ 2 - 1
database/seeds/MiniSeeder.php

xqd
@@ -241,6 +241,7 @@ class MiniSeeder extends Seeder
                 'end_date' => $end_date
             ]);
         }
-        $order->update(['money' => $money]);
+        $date_at = \Carbon\Carbon::now()->subDay(mt_rand(1, 20))->toDateTimeString();
+        $order->update(['money' => $money, 'created_at' => $date_at, 'updated_at' => $date_at]);
     }
 }

+ 6 - 0
mini/app.js

xqd
@@ -94,5 +94,11 @@ App({
     that.setData({
       [name]: val
     })
+  },
+  loginCallback: function(data) {
+    this.updateUserInfo(data)
+    wx.switchTab({
+      url: '/pages/index/index',
+    })
   }
 })

+ 1 - 1
mini/app.json

xqd
@@ -1,7 +1,7 @@
 {
   "pages": [
-    "pages/index/index",
     "pages/data/index",
+    "pages/index/index",
     "pages/order-inner/index",
     "pages/order/index",
     "pages/notification/index",

+ 1 - 1
mini/components/detail-table/index.js

xqd
@@ -4,7 +4,7 @@ Component({
    * 组件的属性列表
    */
   properties: {
-
+    data: Array
   },
 
   /**

+ 9 - 1
mini/components/detail-table/index.wxml

xqd
@@ -1,2 +1,10 @@
 <!--components/detail-table/index.wxml-->
-<text>components/detail-table/index.wxml</text>
+<view class="sg-box">
+  <view class="sg-table">
+    <view class="sg-row" wx:for="{{data}}" wx:key="index">
+    <view class="sg-cell {{index == 0 ? 'sg-light-gray-bg' : ''}}" >{{item.date}}</view>
+    <view class="sg-cell {{index == 0 ? 'sg-light-gray-bg' : ''}}" >{{item.total}}</view>
+    <view class="sg-cell {{index == 0 ? 'sg-light-gray-bg' : ''}}" wx:for="{{item.data}}" wx:key="i_index" wx:for-item="i_item" wx:for-index="i_index">{{i_item}}</view>
+  </view>
+  </view>
+</view>

+ 23 - 1
mini/components/detail-table/index.wxss

xqd
@@ -1 +1,23 @@
-/* components/detail-table/index.wxss */
+/* components/detail-table/index.wxss */
+.sg-row {
+  display: flex;
+  align-items: center;
+}
+.sg-light-gray-bg {
+  background: #f0f0f0;
+}
+.sg-cell {
+  width: 150rpx;
+  height: 50rpx;
+  border: 1px solid #f0f0f0;
+  font-size: 0.8rem;
+  line-height: 50rpx;
+  text-align: center;
+  overflow: hidden;
+}
+.sg-box {
+  display: flex;
+  align-items: center;
+  justify-content: center;
+  padding-top: 50rpx;
+}

+ 108 - 62
mini/pages/data/index.js

xqd xqd xqd xqd xqd xqd
@@ -25,7 +25,8 @@ function initChart(canvas, width, height, dpr) {
       data: []
     },
     yAxis: {
-      type: 'value'
+      type: 'value',
+      show: false
     },
     series: [{
       data: [],
@@ -46,8 +47,8 @@ Page({
     projects: [],
     project_ids: [],
     project_names: '',
-    total_project: '0',
-    total_month: '0',
+    total_money: '0',
+    month_money: '0',
     projectShow: false,
     index: 0,
     show: false,
@@ -80,10 +81,10 @@ Page({
     dateShow: false,
     years_months: [],
     date: '',
-    yearDate: '',
-    monthDate: '',
-    max_date: (new Date()).getTime(),
-    min_date: (new Date()).getTime(),
+    start: '',
+    end: '',
+    max_date: '',
+    min_date: '',
     filter: {},
     data: [],
     ec: {
@@ -132,91 +133,111 @@ Page({
     this.setData({project_ids, project_names})
     this.switchShow(e)
     this.getData()
+    this.getTotalInfo()
   },
 
-  getData() {
+  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 
-    var data = {
+    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
+      rent_type_ids: filter.rent_type_ids,
+      chart_type: chart_type.type
     }
-    var that = this
-    // http({
-    //   url: 'data/getStat',
-    //   data: data,
-    //   success: function(res) {
-
-    //   }
-    // })
-    api.getByName(this, 'data/getStat', 'data', data, function(res) {
-      that.updateChart()
-    });
   },
 
-  getDateInfo() {
+  getTotalInfo() {
+    var data = this.getSearchItems()
     var that = this
     http({
-      url: 'data/getDateInfo',
-      data: {},
-      success: function (res) {
-        if (res.code == 0) {
+      url: 'data/getTotalInfo',
+      data: data,
+      success: function(res) {
+        if(res.code == 0) {
           that.setData(res.data)
-          that.setData({
-            yearDate: res.data.date
-          })
         }
       }
     })
   },
 
-  onDateChange: function (e) {
-    var yearDate = e.detail.value[0].value + '-' + e.detail.value[1].value
-    this.setData({
-      yearDate
+  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
+          })
+        }
+      }
     })
   },
-  dateConfirm: function (e) {
-    this.switchShow(e)
-    this.updateDate()
-  },
-  monthDateConfirm: function (e) {
-    var date = e.detail
-    var monthDate = util.formatDate(date)
-    this.setData({
-      monthDate
+
+  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()
+          }
+        }
+      }
     })
-    this.switchShow(e)
-    this.updateDate()
   },
-  updateDate: function () {
-    var date = this.data.dateIndex == 0 ? this.data.yearDate : this.data.monthDate
-    this.setData({
-      date
+
+  getDateInfo() {
+    var that = this
+    http({
+      url: 'data/getDateInfo',
+      data: {},
+      success: function (res) {
+        if (res.code == 0) {
+          that.setData(res.data)
+        }
+      }
     })
-    this.getData()
   },
 
   onChange: function (e) {
-    var index = e.detail.value
+    var value = e.detail.value
     var name = e.currentTarget.dataset.name
+    if(this.data[name] == value) return false;
     this.setData({
-      [name]: index
+      [name]: value
     })
     if(name == 'chartIndex') {
       var chart = this.data.charts[this.data.chartIndex]
       if(chart.type == 'detail') {
         this.getDetailData()
       } else {
-        this.updateChart()
+        this.getData()
       }
+    } else if(name == 'date') {
+      this.getTotalInfo()
     }
   },
   updateChart: function() {
@@ -225,26 +246,48 @@ Page({
     option.legend = {
       data: data.legends
     }
+    
     var type = this.data.charts[this.data.chartIndex].type
-    var values = data.values
-    for(var i = 0; i < values.length; ++i) {
-      option.series[i] = {
-        label: {
-          show: true,
-          position: 'top'
-        },
-        name: data.legends[i],
+    if(type == 'pie') {
+      option.series = [{
+        data: data.data,
         type: type,
-        data: values[i]
+        label: {
+          position: 'inner',
+          formatter: '{b}\n{d}%'
+        }
+      }]
+      option.xAxis.show = false
+    } 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
+      dateIndex,
+      start_date,
+      end_date
     })
   },
 
@@ -254,6 +297,9 @@ Page({
     this.setData({
       [name]: show
     })
+    if(name == 'dateShow' && !show) {
+      this.getData()
+    }
   },
   /**
    * 生命周期函数--监听页面初次渲染完成

+ 57 - 22
mini/pages/data/index.wxml

xqd xqd xqd xqd
@@ -10,13 +10,16 @@
   </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 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 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>
@@ -25,24 +28,29 @@
   </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">{{data.total_project ? data.total_project : 0}}</view>
+      <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">{{data.total_month ? data.total_month : 0}}</view>
+      <view class="sg-font-lg">{{month_money}}</view>
       <view class="sg-font-xs sg-pad-tb-sm">当月累计消费</view>
     </view>
     <view class="sg-center">
-      <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>
+      <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 sg-pad" wx:if="{{!projectShow && !dateShow}}">
+  <view class="sg-white-bg sg-chart-box" wx:if="{{!projectShow && !dateShow}}">
     <block wx:if="{{project_names}}">
-      <view class="sg-flex sg-pad-tb sg-align-center sg-space-between">
+      <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">
@@ -53,14 +61,15 @@
           </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-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> -->
           <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>
+          <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">
@@ -73,18 +82,44 @@
       </view>
     </block>
     <block wx:else>
-      <view class="sg-center sg-text-center sg-gray-color sg-font-small">
+      <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-popup show="{{ dateShow && dateIndex == 0 }}" position="bottom" custom-style="height: 60vh">
-    <van-picker columns="{{ years_months }}" bind:change="onDateChange" class="sg-year-picker" title="请选择开始日期"
-      show-toolbar bind:cancel="switchShow" bind:confirm="dateConfirm" data-name="dateShow" data-show="{{false}}" />
-  </van-popup>
-  <van-calendar show="{{ dateShow && dateIndex == 1 }}" bind:close="switchShow" bind:confirm="monthDateConfirm"
-    data-name="dateShow" data-show="{{false}}" min-date="{{min_date}}" max-date="{{max_date}}" class="sg-calendar"
-    position="top" />
+  <van-dialog use-slot title="选择日期范围" 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>

+ 1 - 1
mini/pages/data/index.wxss

xqd
@@ -19,6 +19,6 @@
   margin-bottom: 200rpx;
 }
 .sg-chart {
-  width: 100vw;
+  width: 100%;
   height: 50vh;
 }

+ 14 - 5
mini/utils/http.js

xqd xqd xqd
@@ -27,7 +27,7 @@ const http = (data) => {
     },
     success: function (res) {
       if (data.showLoading) wx.hideLoading()
-      if(res.statusCode != 200) {
+      if (res.statusCode != 200) {
         wx.showToast({
           title: res.data.message,
           icon: 'none'
@@ -39,10 +39,13 @@ const http = (data) => {
           title: res.data.msg,
           icon: 'none'
         })
-        if(res.data.code == -100) {
-          // wx.navigateTo({
-          //   url: '/pages/login/index',
-          // })
+        if (res.data.code == -100) {
+          var url = getCurrentUrl()
+          if (url != 'pages/login/index') {
+            wx.navigateTo({
+              url: '/pages/login/index',
+            })
+          }
         }
       }
       typeof data.success === "function" && data.success(res.data)
@@ -54,4 +57,10 @@ const http = (data) => {
   })
 }
 
+const getCurrentUrl = () => {
+  var pages = getCurrentPages()
+  var page = pages[pages.length - 1]
+  return page.route
+}
+
 module.exports = http

+ 2 - 0
routes/api.php

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