Browse Source

内部调用

李浩杰 4 năm trước cách đây
mục cha
commit
c339a63dfc

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

xqd xqd
@@ -2,6 +2,7 @@
 
 namespace App\Http\Controllers\Admin;
 
+use App\Models\InnerDevice;
 use App\Models\Order;
 use App\Models\OrderDevice;
 use App\Models\ProjectRole;
@@ -16,7 +17,9 @@ class TestController extends Controller
 {
     public function index(Request $request)
     {
-        dd(ProjectRole::getByKey('machine', 'id'));
+        dd(InnerDevice::get()->pluck('name')->unique()->map(function($item) {
+            return collect(['text' => $item, 'name' => $item]);
+        }));
     	return view('admin.test.index');
     }
 }

+ 7 - 1
app/Http/Controllers/Api/mini/DeviceController.php

xqd xqd
@@ -3,6 +3,7 @@
 namespace App\Http\Controllers\Api\mini;
 
 use App\Models\Device;
+use Illuminate\Http\Request;
 
 class DeviceController extends BaseController
 {
@@ -13,8 +14,13 @@ class DeviceController extends BaseController
         $this->model = new Device();
     }
 
-    public function get()
+    public function get(Request $request)
     {
+        if($request->input('type') == 'drop_menu') {
+            $items = $this->model->select('name as text', 'id as value')->get();
+            $items = $items->prepend(collect(['text' => '设备类型', 'value' => '']));
+            return $this->success(['data' => $items]);
+        }
         $items = $this->model->get();
         return $this->success(['data' => $items]);
     }

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

xqd
@@ -0,0 +1,55 @@
+<?php
+
+namespace App\Http\Controllers\Api\mini;
+
+use App\Models\InnerDevice;
+use App\Models\Option;
+use App\Models\WorkPoint;
+use Illuminate\Http\Request;
+
+class InnerDeviceController extends BaseController
+{
+    protected $model;
+
+    public function __construct()
+    {
+        $this->model = new InnerDevice();
+    }
+
+    public function get(Request $request)
+    {
+        if($request->input('type') == 'drop_menu') {
+            $items = $this->model->get()->pluck('name')->unique()->map(function($item) {
+                return collect(['text' => $item, 'value' => $item]);
+            });
+            $items = $items->prepend(collect(['text' => '设备名称', 'value' => '']));
+            return $this->success(['data' => $items]);
+        }
+        $items = $this->model->get();
+        return $this->success(['data' => $items]);
+    }
+
+    public function search(Request $request)
+    {
+        $items = $this->model->with('workPoint', 'spec', 'device');
+        $equal_items = ['device_id', 'name', 'spec_id'];
+        foreach ($equal_items as $item) {
+            if($request->input($item)) {
+                $items = $items->where($item, '=', $request->input($item));
+            }
+        }
+        $like_items = ['number'];
+        foreach ($like_items as $item) {
+            if($request->input($item)) {
+                $keyword = '%' . $request->input($item) . '%';
+                $items = $items->where($item, 'like', $keyword);
+            }
+        }
+//        $items = $items->orderBy('created_at');
+        $items = $items->paginate();
+        foreach($items as $item) {
+            $item->status = Option::find($item->status);
+        }
+        return $this->success(['data' => $items->items()]);
+    }
+}

+ 55 - 1
app/Http/Controllers/Api/mini/OrderController.php

xqd xqd xqd
@@ -3,6 +3,7 @@
 namespace App\Http\Controllers\Api\mini;
 
 use App\Models\Device;
+use App\Models\InnerDevice;
 use App\Models\Option;
 use App\Models\Order;
 use App\Models\OrderDevice;
@@ -38,7 +39,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_id,
+            'type' => 1
         ]);
         if(!$order) return $this->error(['msg' => '订单创建失败']);
         $devices = $request->input('devices');
@@ -60,6 +62,58 @@ class OrderController extends BaseController
         return $this->success();
     }
 
+    public function createInner(Request $request)
+    {
+        $project = Project::find($request->input('project_id'));
+        if(!$project) return $this->error(['msg' => '找不到项目']);
+        $devices = $request->input('devices');
+        $using_id = Option::get('inner_devices', 'status', 'using');
+        $free_id = Option::get('inner_devices', 'status', 'free');
+
+        foreach($devices as $device) {
+            $device = InnerDevice::find($device['id']);
+            if($device->status != $free_id) {
+                $status = Option::find($device->status);
+                $msg = $device['name'] . ($status ? $status['name'] : '使用中') . ',不能使用';
+                return $this->error(['msg' => $msg]);
+            }
+        }
+        $user = Auth::guard('mini')->user();
+        $project_role_id = $request->input('is_draft') == 1 ? ProjectRole::getByKey('machine', 'id') : ProjectRole::getByKey('assist', 'id');
+        $option = Option::get('orders', 'status', 'checking');
+
+        $order = Order::create([
+            'work_point_id' => $request->input('work_point_id'),
+            'remark' => $request->input('remark'),
+            'is_draft' => $request->input('is_draft'),
+            'status' => $option,
+            'order_number' => $this->model->createOrderNumber(),
+            'project_id' => $project->id,
+            'user_id' => $user->id,
+            'project_role_id' => $project_role_id,
+            'type' => 2
+        ]);
+        if(!$order) return $this->error(['msg' => '订单创建失败']);
+        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([
+                    'status' => $using_id,
+                    'start_date' => $device['start_date'],
+                    'end_date' => $device['end_date']
+                ]);
+            }
+        }
+
+        return $this->success();
+    }
+
     public function update(Request $request)
     {
         $order = $this->model->find($request->input('id'));

+ 27 - 0
app/Http/Controllers/Api/mini/SpecController.php

xqd
@@ -0,0 +1,27 @@
+<?php
+
+namespace App\Http\Controllers\Api\mini;
+
+use App\Models\Spec;
+use Illuminate\Http\Request;
+
+class SpecController extends BaseController
+{
+    protected $model;
+
+    public function __construct()
+    {
+        $this->model = new Spec();
+    }
+
+    public function get(Request $request)
+    {
+        if($request->input('type') == 'drop_menu') {
+            $items = $this->model->select('name as text', 'id as value')->get();
+            $items = $items->prepend(collect(['text' => '型号规格', 'value' => '']));
+            return $this->success(['data' => $items]);
+        }
+        $items = $this->model->get();
+        return $this->success(['data' => $items]);
+    }
+}

+ 21 - 0
app/Models/InnerDevice.php

xqd
@@ -0,0 +1,21 @@
+<?php
+
+namespace App\Models;
+
+class InnerDevice extends BaseModel
+{
+    public function workPoint()
+    {
+        return $this->belongsTo('App\Models\WorkPoint', 'work_point_id');
+    }
+
+    public function spec()
+    {
+        return $this->belongsTo('App\Models\Spec', 'spec_id');
+    }
+
+    public function device()
+    {
+        return $this->belongsTo('App\Models\Device', 'device_id');
+    }
+}

+ 8 - 0
app/Models/Spec.php

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

+ 42 - 0
database/migrations/2020_12_14_144025_create_inner_devices_table.php

xqd
@@ -0,0 +1,42 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class CreateInnerDevicesTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('inner_devices', function (Blueprint $table) {
+            $table->increments('id');
+            $table->string('name', 200)->nullable();
+            $table->unsignedInteger('device_id')->comment('设备类型ID')->nullable();
+            $table->unsignedInteger('spec_id')->comment('规格型号ID')->nullable();
+            $table->tinyInteger('status')->comment('状态1闲置中,2使用中,3故障')->nullable();
+            $table->string('number', 200)->nullable()->comment('固定资产编号');
+            $table->date('produce_date')->nullable()->comment('出厂日期');
+            $table->string('shape', 200)->nullable()->comment('外形尺寸');
+            $table->string('buy_origin', 200)->nullable()->comment('采购原值');
+            $table->string('manufacturer', 200)->nullable()->comment('生产厂家');
+            $table->date('start_date')->nullable()->comment('借用时间');
+            $table->date('end_date')->nullable()->comment('借用时间');
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('inner_devices');
+    }
+}

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

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

+ 30 - 0
database/migrations/2020_12_14_145218_add_type_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 AddTypeToOrders extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('orders', function (Blueprint $table) {
+            $table->tinyInteger('type')->nullable()->before('created_at')->default(1)->comment('类型:1外部租赁,2内部调用');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        //
+    }
+}

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

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

+ 36 - 0
database/seeds/InnerDeviceStatusSeeder.php

xqd
@@ -0,0 +1,36 @@
+<?php
+
+use Illuminate\Database\Seeder;
+
+class InnerDeviceStatusSeeder extends Seeder
+{
+    /**
+     * Run the database seeds.
+     *
+     * @return void
+     */
+    public function run()
+    {
+        $table = 'inner_devices';
+        $column = 'status';
+        $items = [
+            ['name' => '闲置中', 'key' => 'free', 'color' => '#07c160'],
+            ['name' => '使用中', 'key' => 'using', 'color' => '#ff976a'],
+            ['name' => '故障', 'key' => 'error', 'color' => '#ee0a24']
+        ];
+        \App\Models\Option::where([
+            ['table', '=', $table],
+            ['column', '=', $column]
+        ])->delete();
+        foreach($items as $key => $val) {
+            \App\Models\Option::create([
+                'table' => $table,
+                'column' => $column,
+                'name' => $val['name'],
+                'key' => $val['key'],
+                'sort' => $key + 1,
+                'color' => $val['color']
+            ]);
+        }
+    }
+}

+ 179 - 0
database/seeds/InnerOrderSeeder.php

xqd
@@ -0,0 +1,179 @@
+<?php
+
+use Illuminate\Database\Seeder;
+
+class InnerOrderSeeder extends Seeder
+{
+    /**
+     * Run the database seeds.
+     *
+     * @return void
+     */
+    public function run()
+    {
+        $total = 20;
+        for($i = 0; $i < $total; ++$i) {
+            \App\Models\Spec::create([
+                'name' => '规格' . ($i + 1),
+                'sort' => ($i + 1)
+            ]);
+        }
+
+        $this->call([
+            InnerDeviceStatusSeeder::class
+        ]);
+
+        $statuses = \App\Models\Option::get('inner_devices', 'status');
+        $specs = \App\Models\Spec::limit(3)->get();
+        $device_types = \App\Models\Device::limit(3)->get();
+        \App\Models\InnerDevice::truncate();
+        for($i = 0; $i < $total * 10; ++$i) {
+            \App\Models\InnerDevice::create([
+                'name' => '内部设备' . ($i + 1),
+                'device_id' => $device_types->random()->id,
+                'spec_id' => $specs->random()->id,
+                'status' => $statuses->whereIn('key', ['free', 'error'])->first()->id,
+                'number' => time(),
+                'produce_date' => '2020-01-01',
+                'shape' => '180cm*180cm',
+                'buy_origin' => '100',
+                'manufacturer' => '机械制造厂'
+            ]);
+            \App\Models\InnerDevice::create([
+                'name' => '内部设备' . ($i + 1),
+                'device_id' => $device_types->random()->id,
+                'spec_id' => $specs->random()->id,
+                'status' => $statuses->where('key', 'free')->first()->id,
+                'number' => time(),
+                'produce_date' => '2020-01-01',
+                'shape' => '180cm*180cm',
+                'buy_origin' => '100',
+                'manufacturer' => '机械制造厂'
+            ]);
+        }
+
+        $project = \App\Models\Project::first();
+        $work_points = \App\Models\WorkPoint::all();
+        $user = \App\Models\User::first();
+        $project_roles = \App\Models\ProjectRole::limit(7)->get();
+        $project_role = $project_roles->where('key', 'machine')->first();
+
+        // 草稿
+        for($i = 1; $i < $total; ++$i) {
+            $order = \App\Models\Order::create([
+                'work_point_id' => $work_points->random()->id,
+                'is_draft' => 1,
+                'status' => \App\Models\Option::get('orders', 'status', 'checking'),
+                'order_number' => \App\Models\Order::createOrderNumber(),
+                'project_id' => $project->id,
+                'user_id' => $user->id,
+                'project_role_id' => $project_role->id,
+                'type' => 2
+            ]);
+
+            $this->createOrderDevice($order);
+        }
+
+        // 待审核,checking
+        for($i = 1; $i < $total; ++$i) {
+            $order = \App\Models\Order::create([
+                'work_point_id' => $work_points->random()->id,
+                'is_draft' => 2,
+                'status' => \App\Models\Option::get('orders', 'status', 'checking'),
+                'order_number' => \App\Models\Order::createOrderNumber(),
+                'project_id' => $project->id,
+                'user_id' => $user->id,
+                'project_role_id' => $project_roles->first()->id,
+                'type' => 2
+            ]);
+
+            $this->createOrderDevice($order);
+        }
+
+        // 已审核,checked
+        for($i = 1; $i < $total; ++$i) {
+            $last_project_role = $project_roles->whereIn('key', ['assist', 'manager', 'admin'])->random();
+            $project_role = $project_roles->where('key', 'machine')->first();
+            if($last_project_role->key != 'admin') {
+                $project_role = $project_roles->where('need_check_inner', 1)->where('level', '>', $last_project_role->level)->first();
+            }
+            $order = \App\Models\Order::create([
+                'work_point_id' => $work_points->random()->id,
+                'is_draft' => 2,
+                'status' => \App\Models\Option::get('orders', 'status', 'checked'),
+                'order_number' => \App\Models\Order::createOrderNumber(),
+                'project_id' => $project->id,
+                'user_id' => $user->id,
+                'project_role_id' => $project_role->id,
+                'last_project_role_id' => $last_project_role->id,
+                'type' => 2
+            ]);
+
+            $this->createOrderDevice($order);
+        }
+
+        // 已完成,pass
+        for($i = 1; $i < $total; ++$i) {
+
+            $last_project_role = $project_roles->where('key', 'admin')->first();
+            $project_role = $project_roles->where('key', 'machine')->first();
+
+            $order = \App\Models\Order::create([
+                'work_point_id' => $work_points->random()->id,
+                'is_draft' => 2,
+                'status' => \App\Models\Option::get('orders', 'status', 'pass'),
+                'order_number' => \App\Models\Order::createOrderNumber(),
+                'project_id' => $project->id,
+                'user_id' => $user->id,
+                'project_role_id' => $project_role->id,
+                'last_project_role_id' => $last_project_role->id,
+                'type' => 2
+            ]);
+
+            $this->createOrderDevice($order);
+        }
+
+        // 已驳回,pass
+        for($i = 1; $i < $total; ++$i) {
+            $last_project_role = $project_roles->whereIn('key', ['assist', 'manager', 'admin'])->random();
+            $project_role = $project_roles->where('key', 'machine')->first();
+            $order = \App\Models\Order::create([
+                'work_point_id' => $work_points->random()->id,
+                'is_draft' => 2,
+                'status' => \App\Models\Option::get('orders', 'status', 'reject'),
+                'order_number' => \App\Models\Order::createOrderNumber(),
+                'project_id' => $project->id,
+                'user_id' => $user->id,
+                'project_role_id' => $project_role->id,
+                'last_project_role_id' => $last_project_role->id,
+                'type' => 2
+            ]);
+
+            $this->createOrderDevice($order);
+        }
+    }
+
+    public function createOrderDevice(\App\Models\Order $order)
+    {
+        $free_id = \App\Models\Option::get('inner_devices', 'status', 'free');
+        $using_id = \App\Models\Option::get('inner_devices', 'status', 'using');
+        for($j = 1; $j < 3; ++$j) {
+            $start_date = \Carbon\Carbon::now()->addDay(mt_rand(1, 4))->toDateString();
+            $end_date = \Carbon\Carbon::now()->addDay(mt_rand(5, 10))->toDateString();
+            $device = \App\Models\InnerDevice::where('status', $free_id)->where('id', '>', 10)->first();
+            \App\Models\OrderDevice::create([
+                'order_id' => $order['id'],
+                'device_id' => $device->id,
+                'start_date' => $start_date,
+                'end_date' => $end_date
+            ]);
+//            \Illuminate\Support\Facades\Log::info($order['work_point_id']);
+            $device->update([
+                'status' => $using_id,
+                'start_date' => $start_date,
+                'end_date' => $end_date,
+                'work_point_id' => $order['work_point_id']
+            ]);
+        }
+    }
+}

+ 13 - 3
database/seeds/MiniSeeder.php

xqd xqd xqd xqd xqd xqd
@@ -53,8 +53,9 @@ class MiniSeeder extends Seeder
             }
         }
 
+        \App\Models\Device::truncate();
         // 创建设备类型
-        $device_types = ['隧道掘进机', '钻机', '起重机械', '隧道牵引机械', '隧道掘进机', '混泥土泵送机械', '土石方机械', '运输机械', '其他'];
+        $device_types = ['隧道掘进机', '钻机', '起重机械', '隧道牵引机械', '混泥土泵送机械', '土石方机械', '运输机械', '其他'];
         foreach($device_types as $key => $value) {
             \App\Models\Device::create([
                 'name' => $value,
@@ -93,6 +94,7 @@ class MiniSeeder extends Seeder
                 'project_id' => $project->id,
                 'user_id' => $user->id,
                 'project_role_id' => $project_roles->first()->id,
+                'type' => 1
             ]);
 
             $this->createOrderDevice($order, $devices);
@@ -108,6 +110,7 @@ class MiniSeeder extends Seeder
                 'project_id' => $project->id,
                 'user_id' => $user->id,
                 'project_role_id' => $project_roles->first()->id,
+                'type' => 1
             ]);
 
             $this->createOrderDevice($order, $devices);
@@ -129,6 +132,7 @@ class MiniSeeder extends Seeder
                 'user_id' => $user->id,
                 'project_role_id' => $project_role->id,
                 'last_project_role_id' => $last_project_role->id,
+                'type' => 1
             ]);
 
             $this->createOrderDevice($order, $devices);
@@ -147,7 +151,8 @@ class MiniSeeder extends Seeder
                 'project_id' => $project->id,
                 'user_id' => $user->id,
                 'project_role_id' => $project_role->id,
-                'last_project_role_id' => $last_project_role->id
+                'last_project_role_id' => $last_project_role->id,
+                'type' => 1
             ]);
 
             $this->createOrderDevice($order, $devices);
@@ -165,11 +170,16 @@ class MiniSeeder extends Seeder
                 'project_id' => $project->id,
                 'user_id' => $user->id,
                 'project_role_id' => $project_role->id,
-                'last_project_role_id' => $last_project_role->id
+                'last_project_role_id' => $last_project_role->id,
+                'type' => 1
             ]);
 
             $this->createOrderDevice($order, $devices);
         }
+
+        $this->call([
+            InnerOrderSeeder::class
+        ]);
     }
 
     public function createOrderDevice(\App\Models\Order $order, \Illuminate\Support\Collection $devices)

+ 8 - 4
mini/app.json

xqd xqd xqd
@@ -1,5 +1,7 @@
 {
   "pages": [
+    "pages/create-order-inner/index",
+    "pages/add-inner-device/index",
     "pages/index/index",
     "pages/project/index",
     "pages/order/index",
@@ -15,9 +17,9 @@
   ],
   "tabBar": {
     "custom": true,
-		"color": "#000000",
-		"selectedColor": "#5693FC",
-		"backgroundColor": "#000000",
+    "color": "#000000",
+    "selectedColor": "#5693FC",
+    "backgroundColor": "#000000",
     "list": [
       {
         "pagePath": "pages/index/index"
@@ -47,6 +49,8 @@
     "van-popup": "@vant/weapp/popup/index",
     "van-calendar": "@vant/weapp/calendar/index",
     "van-tabbar": "@vant/weapp/tabbar/index",
-		"van-tabbar-item": "@vant/weapp/tabbar-item/index"
+    "van-tabbar-item": "@vant/weapp/tabbar-item/index",
+    "van-dropdown-menu": "@vant/weapp/dropdown-menu/index",
+    "van-dropdown-item": "@vant/weapp/dropdown-item/index"
   }
 }

+ 18 - 0
mini/app.wxss

xqd xqd xqd xqd
@@ -14,6 +14,12 @@
 .sg-pad-top {
   padding-top: 30rpx;
 }
+.sg-pad-bottom {
+  padding-bottom: 30rpx;
+}
+.sg-pad-bottom-sm {
+  padding-bottom: 15rpx;
+}
 .sg-pad-sm {
   padding: 15rpx;
 }
@@ -39,6 +45,9 @@
 .sg-gray-color {
   color: rgba(16, 16, 16, 0.5);
 }
+.sg-gray-bg {
+  background: rgba(16, 16, 16, 0.5);
+}
 .sg-bold {
   font-weight: bold;
 }
@@ -121,6 +130,9 @@
 .sg-space-between {
   justify-content: space-between;
 }
+.sg-just-center {
+  justify-content: center;
+}
 .sg-space-around {
   justify-content: space-around;
 }
@@ -174,4 +186,10 @@
 }
 .sg-block {
   width: 100%;
+}
+.sg-dot {
+  width: 20rpx;
+  height: 20rpx;
+  border-radius: 50%;
+  margin-right: 20rpx;
 }

+ 215 - 0
mini/pages/add-inner-device/index.js

xqd
@@ -0,0 +1,215 @@
+// pages/add-inner-device/index.js
+import http from '../../utils/http'
+import util from '../../utils/util'
+import api from '../../utils/api'
+
+Page({
+
+  /**
+   * 页面的初始数据
+   */
+  data: {
+    device_types: [],
+    type: '',
+    names: [],
+    name: '',
+    specs: [],
+    spec: '',
+    number: '',
+    list: [],
+    page: 1,
+    touchBottom: false,
+    showDate: false,
+    default_dates: [],
+    add_devices: [],
+    showAdded: false
+  },
+
+  /**
+   * 生命周期函数--监听页面加载d
+   */
+  onLoad: function (options) {
+    api.getByName(this, 'devices/get', 'device_types', {type: 'drop_menu'});
+    api.getByName(this, 'inner-devices/get', 'names', {type: 'drop_menu'});
+    api.getByName(this, 'specs/get', 'specs', {type: 'drop_menu'});
+    this.getList()
+  },
+
+  switchShowDate: function(e) {
+    this.setData({
+      showDate: e.currentTarget.dataset.show
+    })
+  },
+
+  switchShowAdded: function(e) {
+    this.setData({
+      showAdded: e.currentTarget.dataset.show
+    })
+  },
+
+  complete: function(e) {
+    wx.setStorageSync('sg-added-devices', this.data.add_devices)
+    wx.navigateBack({
+      delta: 0,
+    })
+  },
+
+  confirmDate: function(e) {
+    var ids = []
+    var add_devices = this.data.add_devices
+    for(var i = 0; i < add_devices.length; ++i) {
+      ids.push(add_devices[i].id)
+    }
+    var list = this.data.list
+    var [start_date, end_date] = e.detail;
+    start_date = util.formatDate(start_date)
+    end_date = util.formatDate(end_date)
+    for(var i = 0; i < list.length; ++i) {
+      if(ids.indexOf(list[i].id) == -1 && list[i].checked) {
+        var device = list[i]
+        device.start_date = start_date,
+        device.end_date = end_date
+        add_devices.push(device)
+      }
+    }
+    this.setData({
+      add_devices: add_devices
+    })
+    this.switchShowDate(e)
+  },
+
+  switchSelect: function(e) {
+    var list = this.data.list
+    var index = e.currentTarget.dataset.index
+    var can = e.currentTarget.dataset.can
+    if(can) {
+      list[index].checked = list[index].checked ? false : true
+      this.setData({
+        list
+      })
+    } else {
+      util.error('该设备暂不能借用')
+    }
+  },
+
+  onChange: function(e) {
+    var name = e.currentTarget.dataset.name
+    this.setData({
+      [name]: e.detail
+    })
+    this.search()
+  },
+
+  resetList: function() {
+    this.setData({
+      list: [],
+      page: 1,
+      touchBottom: false
+    })
+  },
+
+  search: function() {
+    this.resetList()
+    this.getList()
+  },
+
+  getList: function() {
+    var that = this
+    http({
+      url: 'inner-devices/search',
+      data: {
+        number: this.data.number,
+        device_id: this.data.type,
+        name: this.data.name,
+        spec_id: this.data.spec,
+        page: this.data.page
+      },
+      success: function (res) {
+        if (res.code == 0) {
+          var list = that.data.list
+          var touchBottom = that.data.touchBottom
+          list = list.concat(res.data);
+          if (res.data.length <= 0) {
+            touchBottom = true;
+          }
+          that.setData({
+            touchBottom,
+            list
+          })
+        }
+      }
+    })
+  },
+
+  deleteDevice: function(e) {
+    var index = e.currentTarget.dataset.index
+    var add_devices = this.data.add_devices
+    add_devices.splice(index, 1)
+    this.setData({
+      add_devices
+    })
+  },
+
+  /**
+   * 生命周期函数--监听页面初次渲染完成
+   */
+  onReady: function () {
+
+  },
+
+  /**
+   * 生命周期函数--监听页面显示
+   */
+  onShow: function () {
+    var add_devices = wx.getStorageSync('sg-added-devices')
+    add_devices = add_devices ? add_devices : []
+    this.setData({
+      add_devices
+    })
+  },
+
+  /**
+   * 生命周期函数--监听页面隐藏
+   */
+  onHide: function () {
+
+  },
+
+  /**
+   * 生命周期函数--监听页面卸载
+   */
+  onUnload: function () {
+
+  },
+
+  /**
+   * 页面相关事件处理函数--监听用户下拉动作
+   */
+  onPullDownRefresh: function () {
+
+  },
+
+  /**
+   * 页面上拉触底事件的处理函数
+   */
+  onReachBottom: function () {
+    if(!this.data.touchBottom) {
+      var page = this.data.page
+      page = page + 1;
+      this.setData({
+        page
+      })
+      this.getList()
+    }
+    if(this.data.touchBottom) {
+      util.error('没有更多数据了')
+    }
+  },
+
+  /**
+   * 用户点击右上角分享
+   */
+  onShareAppMessage: function () {
+
+  }
+})

+ 4 - 0
mini/pages/add-inner-device/index.json

xqd
@@ -0,0 +1,4 @@
+{
+  "navigationBarTitleText": "调用设备添加",
+  "usingComponents": {}
+}

+ 73 - 0
mini/pages/add-inner-device/index.wxml

xqd
@@ -0,0 +1,73 @@
+<!--pages/add-inner-device/index.wxml-->
+<view class="sg-container">
+  <view class="sg-search-box sg-fix-top">
+    <van-dropdown-menu>
+      <van-dropdown-item value="{{ type }}" options="{{ device_types }}" bind:change="onChange" bind:change="onChange"
+        data-name="type" />
+      <van-dropdown-item value="{{ name }}" options="{{ names }}" bind:change="onChange" bind:change="onChange"
+        data-name="name" />
+      <van-dropdown-item value="{{ spec }}" options="{{ specs }}" bind:change="onChange" bind:change="onChange"
+        data-name="spec" />
+    </van-dropdown-menu>
+    <van-search value="{{ number }}" placeholder="请输入固定资产编号模糊查询" bind:change="onChange" data-name="number"
+      left-icon="false" bind:search="search" use-right-icon-slot>
+      <van-icon name="search" bind:tap="search" slot="right-icon"></van-icon>
+    </van-search>
+  </view>
+  <view class="sg-list sg-pad">
+    <view class="sg-item sg-white-bg sg-pad sg-margin-bottom" wx:for="{{list}}" wx:key="index" bindtap="switchSelect"
+      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.name}}</view>
+        <view class="sg-status sg-flex sg-align-center">
+          <view class="sg-dot" style="background: {{item.status ? item.status.color : ''}}"></view>
+          <view class="sg-status-name">{{item.status ? item.status.name : ''}}</view>
+        </view>
+        <van-icon name="passed" wx:if="{{item.checked}}" class="sg-icon {{item.checked ? 'sg-index-color' : ''}}" />
+        <van-icon name="circle" wx:else class="sg-icon" />
+      </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 sg-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 sg-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 sg-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 sg-flex sg-space-between sg-align-center">
+        <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>
+        </view>
+        <view class="sg-white sg-pad-sm {{item.status && item.status.key == 'free' ? 'sg-green-bg' : 'sg-gray-bg'}}">
+          借用设备</view>
+      </view>
+    </view>
+  </view>
+  <van-dialog show="{{ showAdded }}" use-slot title="已添加设备" show-cancel-button bind:confirm="switchShowAdded" z-index="200" data-show="{{false}}">
+    <view class="sg-added-list">
+      <view class="sg-item sg-pad sg-bottom-border sg-flex sg-align-center sg-space-between" wx:for="{{add_devices}}" wx:key="index">
+        <view class="sg-left">
+          <view class="sg-name sg-font-small">{{item.device ? item.device.name + ' - ' : ''}}{{item.name}}</view>
+        <view class="sg-dates sg-font-xs sg-gray-color">{{item.start_date ? item.start_date + '至' + item.end_date : ''}}</view>
+        </view>
+        <view class="sg-right sg-red-bg sg-white sg-pad-sm" bindtap="deleteDevice" data-index="{{index}}">删除</view>
+      </view>
+    </view>
+  </van-dialog>
+  <van-calendar show="{{ showDate }}" bind:close="switchShowDate" bind:confirm="confirmDate" data-show="{{false}}"
+    type="range" class="sg-calendar" default-date="{{default_dates}}" />
+  <view class="sg-submit-box sg-fix-bottom sg-flex sg-align-center sg-center">
+    <view class="sg-action sg-pad sg-white-bg" bindtap="switchShowAdded" data-show="{{true}}">已添加({{add_devices.length}})</view>
+    <view class="sg-action sg-draft sg-pad sg-border-right sg-green-bg sg-white" bindtap="complete">完成</view>
+    <view class="sg-action sg-draft sg-pad sg-border-right sg-index-bg sg-white" bindtap="switchShowDate" data-show="{{true}}"
+      data-type='draft'>添加</view>
+  </view>
+</view>

+ 17 - 0
mini/pages/add-inner-device/index.wxss

xqd
@@ -0,0 +1,17 @@
+/* pages/add-inner-device/index.wxss */
+.sg-list {
+  margin-top: 220rpx;
+}
+.sg-icon {
+  z-index: 0;
+}
+.sg-search-box {
+  z-index: 100;
+}
+.sg-submit-box.sg-fix-bottom {
+  z-index: 1;
+  width: 100%;
+}
+.sg-submit-box .sg-action {
+  width: 50%;
+}

+ 199 - 0
mini/pages/create-order-inner/index.js

xqd
@@ -0,0 +1,199 @@
+// pages/create-order/index.js
+import http from '../../utils/http'
+import util from '../../utils/util'
+import api from '../../utils/api'
+Page({
+
+  /**
+   * 页面的初始数据
+   */
+  data: {
+    tabs: ['内部设备调用', '调用设备添加'],
+    tabIndex: 0,
+    work_points: [],
+    pointIndex: -1,
+    id: -1,
+    project: null,
+    remark: '',
+    devices: [],
+    // create/edit
+    type: 'create',
+    order_id: ''
+  },
+
+  /**
+   * 生命周期函数--监听页面加载
+   */
+  onLoad: function (options) {
+    var id = options.id ? options.id : 1
+    var type = options.type ? options.type : 'create'
+    var order_id = options.order_id ? options.order_id : ''
+    this.setData({
+      id,
+      type,
+      order_id
+    })
+    api.getProject(this)
+    api.getByName(this, 'work-points/get', 'work_points');
+    if(order_id) {
+      var that = this
+      api.getByName(this, 'orders/detail', 'order', {id: order_id}, function(res) {
+        that.initData()
+      });
+      wx.setNavigationBarTitle({
+        title: '修订订单',
+      })
+    }
+  },
+
+  navigate: function(e) {
+    wx.navigateTo({
+      url: e.currentTarget.dataset.url,
+    })
+  },
+  
+  initData: function() {
+    var order = this.data.order,
+    work_points = this.data.work_points,
+    pointIndex = this.data.pointIndex
+
+    for(var i = 0; i < work_points.length; ++i) {
+      if(work_points[i].id == order.work_point_id) {
+        pointIndex = i;
+        break;
+      }
+    }
+    var devices = 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
+      })
+    }
+    this.setData({
+      pointIndex,
+      remark: order.remark,
+      devices: local_devices
+    })
+  },
+
+  submit: function(e) {
+    var type = e.currentTarget.dataset.type
+    var is_draft = type == 'draft' ? 1 : 2
+    var submit_type = this.data.type
+    if(this.data.pointIndex < 0) {
+      util.error('需求工点必填');
+      return false;
+    }
+    if(this.data.devices.length <= 0) {
+      util.error('请选择调用设备');
+      return false;
+    }
+    var work_point = this.data.work_points[this.data.pointIndex]
+    var url = submit_type == 'create' ? 'orders/createInner' : 'orders/updateInner'
+    http({
+      url: url,
+      data: {
+        id: this.data.order_id,
+        project_id: this.data.id,
+        work_point_id: work_point.id,
+        remark: this.data.remark,
+        devices: this.data.devices,
+        is_draft: is_draft
+      },
+      success: function(res) {
+        if(res.code == 0) {
+          util.success('操作成功')
+        }
+      }
+    })
+  },
+
+  switchTab: function(e) {
+    this.setData({
+      tabIndex: e.currentTarget.dataset.index
+    })
+  },
+
+  onChange: function(e) {
+    var name = e.currentTarget.dataset.name
+    this.setData({
+      [name]: e.detail.value
+    })
+  },
+
+  /**
+   * 生命周期函数--监听页面初次渲染完成
+   */
+  onReady: function () {
+
+  },
+
+  /**
+   * 生命周期函数--监听页面显示
+   */
+  onShow: function () {
+    var devices = wx.getStorageSync('sg-added-devices')
+    devices = devices ? devices : []
+    this.setData({
+      devices
+    })
+  },
+
+  goAdd: function(e) {
+    var devices = this.data.devices
+    wx.setStorageSync('sg-added-devices', devices)
+    this.navigate(e)
+  },
+
+  deleteDevice: function(e) {
+    var index = e.currentTarget.dataset.index
+    var devices = this.data.devices
+    devices.splice(index, 1)
+    this.setData({
+      devices
+    })
+  },
+
+  /**
+   * 生命周期函数--监听页面隐藏
+   */
+  onHide: function () {
+
+  },
+
+  /**
+   * 生命周期函数--监听页面卸载
+   */
+  onUnload: function () {
+
+  },
+
+  /**
+   * 页面相关事件处理函数--监听用户下拉动作
+   */
+  onPullDownRefresh: function () {
+
+  },
+
+  /**
+   * 页面上拉触底事件的处理函数
+   */
+  onReachBottom: function () {
+
+  },
+
+  /**
+   * 用户点击右上角分享
+   */
+  onShareAppMessage: function () {
+
+  }
+})

+ 4 - 0
mini/pages/create-order-inner/index.json

xqd
@@ -0,0 +1,4 @@
+{
+  "navigationBarTitleText": "调用申请",
+  "usingComponents": {}
+}

+ 65 - 0
mini/pages/create-order-inner/index.wxml

xqd
@@ -0,0 +1,65 @@
+<!--pages/create-order/index.wxml-->
+<view class="sg-container">
+  <view class="sg-tabs sg-flex sg-align-center sg-space-around">
+    <block wx:for="{{tabs}}" wx:key="index">
+      <view class="sg-tab sg-pad {{index == tabIndex ? 'sg-seleted' : 'sg-gray-color'}}" bindtap="switchTab"
+        data-index="{{index}}">{{item}}</view>
+    </block>
+  </view>
+  <view class="sg-order-box" wx:if="{{tabIndex == 0}}">
+    <view class="sg-form">
+      <view class="sg-form-item sg-pad sg-top-border">
+        <view class="sg-label">项目名称</view>
+        <input value="{{project ? project.name : ''}}" class="sg-input" disabled="true"></input>
+      </view>
+      <view class="sg-form-item sg-pad sg-top-border">
+        <view class="sg-label">需求工点</view>
+        <picker bindchange="onChange" value="{{pointIndex}}" range="{{work_points}}" range-key="name"
+          data-name="pointIndex" class="sg-input">
+          <view class="picker sg-gray-color">
+            {{pointIndex >= 0 ? work_points[pointIndex].name : '选择所需的工点'}}
+          </view>
+        </picker>
+      </view>
+      <view class="sg-form-item sg-pad sg-top-border">
+        <view class="sg-label">调用设备</view>
+        <input value="{{devices.length}}" class="sg-input" disabled="true"></input>
+      </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>
+      </view>
+    </view>
+  </view>
+  <view class="sg-device-box" wx:if="{{tabIndex == 1}}">
+    <view class="sg-device-list sg-top-border">
+      <block wx:if="{{devices.length <= 0}}">
+        <view class="sg-center sg-pad">暂无设备</view>
+      </block>
+      <block wx:else>
+        <view class="sg-item sg-flex sg-align-center sg-bottom-border" wx:for="{{devices}}" wx:key="index"
+          bindtap="selectDevice" data-index="{{index}}">
+          <view class="sg-left 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.device ? item.device.name + ' - ' : ''}}{{item.name}}</view>
+            </view>
+            <view class="sg-left-bottom sg-gray-color sg-font-xs">{{item.start_date}}至{{item.end_date}}</view>
+          </view>
+          <view class="sg-right sg-pad sg-flex sg-align-center sg-icon">
+            <view class="sg-right sg-red-bg sg-white sg-pad-sm sg-font-small" bindtap="deleteDevice" data-index="{{index}}">删除</view>
+          </view>
+          <!-- <view class="sg-right sg-red-bg sg-pad sg-flex sg-align-center" bindtap="deleteDevice" data-index="{{index}}">删除</view> -->
+        </view>
+      </block>
+    </view>
+  </view>
+  <block wx:if="{{tabIndex == 1}}">
+    <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">
+      <van-icon name="plus" /><text>立即添加</text>
+    </view>
+  </block>
+  <view class="sg-submit-box sg-fix-bottom sg-flex sg-align-center sg-center" wx:if="{{tabIndex == 0}}">
+    <view class="sg-action sg-draft sg-pad sg-border-right" bindtap="submit" data-type='draft'>暂存</view>
+    <view class="sg-action sg-pad sg-index-bg sg-white" bindtap="submit" data-type='save'>提交</view>
+  </view>
+</view>

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

xqd
@@ -0,0 +1,46 @@
+/* pages/create-order/index.wxss */
+.sg-tabs {
+  background: white;
+}
+.sg-tab {
+  width: 50%;
+  box-sizing: border-box;
+  text-align: center;
+}
+.sg-tab:first-child {
+  border-right: 1px solid #ebedf0;
+}
+.sg-form-item {
+  display: flex;
+  width: 100%;
+  box-sizing: border-box;
+}
+.sg-form-item .sg-label {
+  padding-right: 30rpx;
+  min-width: 150rpx;
+}
+.sg-form-item .sg-input {
+  flex-grow: 1;
+  text-align: right;
+}
+.sg-order-box {
+  background: white;
+}
+.sg-submit-box {
+  justify-content: center;
+  background: white;
+}
+.sg-device-list .sg-item {
+  background: white;
+  align-items: center;
+}
+.sg-device-list .sg-item .sg-left {
+  display: flex;
+  height: 80rpx;
+}
+.sg-submit-box .sg-action {
+  width: 50%;
+}
+.sg-submit-box.sg-fix-bottom {
+  z-index: 1;
+}

+ 0 - 5
mini/pages/create-order/index.js

xqd
@@ -39,11 +39,6 @@ Page({
    * 生命周期函数--监听页面加载
    */
   onLoad: function (options) {
-    options = {
-      id: 1,
-      order_id: 99,
-      type: 'edit'
-    }
     var id = options.id ? options.id : 1
     var type = options.type ? options.type : 'create'
     var order_id = options.order_id ? options.order_id : ''

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

xqd
@@ -35,7 +35,8 @@ Page({
     device_use_menus: [{
       img: 'http://t18.9026.com/mini/use-apply.png',
       title: '调用申请',
-      desc: '机电负责人调用设备'
+      desc: '机电负责人调用设备',
+      url: '/pages/create-order-inner/index'
     }, {
       img: 'http://t18.9026.com/mini/rent-check.png',
       title: '调用审核',

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

xqd
@@ -38,7 +38,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_rent_menus}}" wx:key="index">
+      <view class="sg-item sg-flex sg-align-center sg-pad" wx:for="{{device_use_menus}}" wx:key="index">
         <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>

+ 1 - 1
mini/utils/http.js

xqd
@@ -1,4 +1,4 @@
-const isTest = false;
+const isTest = true;
 const baseUrl = isTest ? 'http://app.rt/api/mini/' : 'http://t18.9026.com/api/mini/';
 
 const http = (data) => {

+ 6 - 0
routes/api.php

xqd
@@ -42,7 +42,13 @@ $api->version('v1', ['namespace' => 'App\Http\Controllers\Api\mini', 'prefix' =>
 
     $api->any('devices/get', 'DeviceController@get');
 
+    $api->any('inner-devices/get', 'InnerDeviceController@get');
+    $api->any('inner-devices/search', 'InnerDeviceController@search');
+
+    $api->any('specs/get', 'SpecController@get');
+
     $api->any('orders/create', 'OrderController@create');
+    $api->any('orders/createInner', 'OrderController@createInner');
     $api->any('orders/update', 'OrderController@update');
     $api->any('orders/get', 'OrderController@get');
     $api->any('orders/detail', 'OrderController@detail');