李浩杰 il y a 4 ans
Parent
commit
f5c947dc5f
37 fichiers modifiés avec 1056 ajouts et 25 suppressions
  1. 1 2
      app/Http/Controllers/Admin/TestController.php
  2. 80 0
      app/Http/Controllers/Api/mini/ProjectController.php
  3. 53 0
      app/Http/Controllers/Api/mini/ProjectRoleController.php
  4. 38 0
      app/Http/Controllers/Api/mini/UserController.php
  5. 2 0
      app/Models/BaseModel.php
  6. 34 0
      app/Models/Project.php
  7. 8 0
      app/Models/ProjectRole.php
  8. 8 0
      app/Models/ProjectUser.php
  9. 11 0
      app/Models/User.php
  10. 32 0
      database/migrations/2020_12_09_004443_create_projects_table.php
  11. 32 0
      database/migrations/2020_12_09_014620_create_project_roles_table.php
  12. 34 0
      database/migrations/2020_12_09_014758_create_project_users_table.php
  13. 20 0
      database/seeds/ProjectRoleSeeder.php
  14. 20 0
      database/seeds/ProjectSeeder.php
  15. 6 3
      mini/app.json
  16. 43 2
      mini/app.wxss
  17. 1 0
      mini/components/navbar/index.wxss
  18. 183 0
      mini/pages/create-project-role/index.js
  19. 4 0
      mini/pages/create-project-role/index.json
  20. 43 0
      mini/pages/create-project-role/index.wxml
  21. 28 0
      mini/pages/create-project-role/index.wxss
  22. 94 0
      mini/pages/create-project/index.js
  23. 4 0
      mini/pages/create-project/index.json
  24. 9 0
      mini/pages/create-project/index.wxml
  25. 11 0
      mini/pages/create-project/index.wxss
  26. 58 1
      mini/pages/index/index.js
  27. 0 3
      mini/pages/index/index.json
  28. 21 6
      mini/pages/index/index.wxml
  29. 19 2
      mini/pages/index/index.wxss
  30. 4 4
      mini/pages/login/index.js
  31. 96 0
      mini/pages/project/index.js
  32. 3 0
      mini/pages/project/index.json
  33. 31 0
      mini/pages/project/index.wxml
  34. 4 0
      mini/pages/project/index.wxss
  35. 9 2
      mini/utils/util.js
  36. BIN
      public/mini/create-order.png
  37. 12 0
      routes/api.php

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

xqd
@@ -11,8 +11,7 @@ class TestController extends Controller
 {
     public function index(Request $request)
     {
-    	User::where('phone', '13438082119')->update(['open_id' => 'o6p1-5fOkxuGKfSxInNJ64sld8pQ']);
-    	dd(User::where('phone', '13438082119')->first());
+        dd(User::first()->projects->implode('name', ','));
     	return view('admin.test.index');
     }
 }

+ 80 - 0
app/Http/Controllers/Api/mini/ProjectController.php

xqd
@@ -0,0 +1,80 @@
+<?php
+
+namespace App\Http\Controllers\Api\mini;
+
+use App\Models\Project;
+use App\Models\ProjectRole;
+use App\Models\ProjectUser;
+use Illuminate\Http\Request;
+use Illuminate\Support\Facades\Auth;
+
+class ProjectController extends BaseController
+{
+    protected $model;
+
+    public function __construct()
+    {
+        $this->model = new Project();
+    }
+
+    public function addUser(Request $request)
+    {
+        $item = ProjectUser::where([
+            'project_id' => $request->input('project_id'),
+            'user_id' => $request->input('user_id'),
+//            'project_role_id' => $request->input('project_role_id')
+        ])->first();
+        if($item) return $this->error('该成员已添加');
+        $res = ProjectUser::create([
+            'project_id' => $request->input('project_id'),
+            'user_id' => $request->input('user_id'),
+            'project_role_id' => $request->input('project_role_id')
+        ]);
+        if(!$res) return $this->error('添加失败');
+        return $this->success('操作成功');
+    }
+
+    public function create(Request $request)
+    {
+        if(empty($request->input('name'))) return $this->error(['msg' => '项目名称不能为空']);
+        if($item = $this->model->where('name', $request->input('name'))->first()) return $this->error(['msg' => '项目名称已存在']);
+        $res = $this->model->create([
+            'name' => $request->input('name')
+        ]);
+        if(!$res) return $this->error(['msg' => '创建失败']);
+        return $this->success(['msg' => '创建成功']);
+    }
+
+    public function get(Request $request)
+    {
+        $items = $this->model;
+        $tmp_items = collect(['name']);
+        foreach($tmp_items as $tmp_item) {
+            if($request->has($tmp_item) && !empty($request->input($tmp_item))) {
+                $items = $items->where($tmp_item, 'like', '%' . $request->input($tmp_item) . '%');
+            }
+        }
+
+        $items = $items->paginate();
+
+        foreach($items as $item) {
+            $item->date = substr($item->created_at, 0, 10);
+            $item->manager = $item->getManager();
+        }
+
+        return $this->success(['msg' => '创建成功', 'data' => $items->items()]);
+    }
+
+    public function getAll(Request $request)
+    {
+        $items = $this->model->get();
+        return $this->success(['msg' => '创建成功', 'data' => $items]);
+    }
+
+    public function detail(Request $request)
+    {
+        $project = $this->model->find($request->input('id'));
+        $project->role = $project->getUserProjectRole();
+        return $this->success(['msg' => '创建成功', 'data' => $project]);
+    }
+}

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

xqd
@@ -0,0 +1,53 @@
+<?php
+
+namespace App\Http\Controllers\Api\mini;
+
+use App\Models\ProjectRole;
+use App\Models\ProjectUser;
+use Illuminate\Http\Request;
+
+class ProjectRoleController extends BaseController
+{
+    protected $model;
+
+    public function __construct()
+    {
+        $this->model = new ProjectRole();
+    }
+
+    public function create(Request $request)
+    {
+        if(empty($request->input('name'))) return $this->error(['msg' => '项目名称不能为空']);
+        if($item = $this->model->where('name', $request->input('name'))->first()) return $this->error(['msg' => '项目名称已存在']);
+        $res = $this->model->create([
+            'name' => $request->input('name')
+        ]);
+        if(!$res) return $this->error(['msg' => '创建失败']);
+        return $this->success(['msg' => '创建成功']);
+    }
+
+    public function get(Request $request)
+    {
+        $items = $this->model;
+        $tmp_items = collect(['name']);
+        foreach($tmp_items as $tmp_item) {
+            if($request->has($tmp_item) && !empty($request->input($tmp_item))) {
+                $items = $items->where($tmp_item, 'like', '%' . $request->input($tmp_item) . '%');
+            }
+        }
+
+        $items = $items->paginate();
+
+        foreach($items as $item) {
+            $item->date = substr($item->created_at, 0, 10);
+        }
+
+        return $this->success(['msg' => '创建成功', 'data' => $items->items()]);
+    }
+
+    public function getAll(Request $request)
+    {
+        $items = $this->model->get();
+        return $this->success(['msg' => '创建成功', 'data' => $items]);
+    }
+}

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

xqd
@@ -0,0 +1,38 @@
+<?php
+
+namespace App\Http\Controllers\Api\mini;
+
+use App\Models\User;
+use Illuminate\Http\Request;
+
+class UserController extends BaseController
+{
+    protected $model;
+
+    public function __construct()
+    {
+        $this->model = new User();
+    }
+
+    public function search(Request $request)
+    {
+        $items = $this->model;
+        $tmp_items = collect(['keyword']);
+        foreach($tmp_items as $tmp_item) {
+            if($request->has($tmp_item) && !empty($request->input($tmp_item))) {
+                $items = $items->where('name', 'like', '%' . $request->input($tmp_item) . '%')->orWhere('phone', 'like', '%' . $request->input($tmp_item) . '%');
+            }
+        }
+
+        $items = $items->limit(1)->get();
+
+        foreach($items as $item) {
+            $item->project = $item->projects->implode('name', ',');
+            $item->project = $item->project ? $item->project : '暂未添加项目';
+            $item->role = $item->project_roles->implode('name', ',');
+            $item->role = $item->role ? $item->role : '暂未添加角色';
+        }
+
+        return $this->success(['msg' => '操作成功', 'data' => $items]);
+    }
+}

+ 2 - 0
app/Models/BaseModel.php

xqd
@@ -23,6 +23,8 @@ class BaseModel extends Model
      */
     public $timestamps = true;
 
+    protected $guarded = [];
+
     protected $statusOptions = [
         ['id' => 1, 'name' => '未激活', 'color' => 'gray'],
         ['id' => 2, 'name' => '激活', 'color' => 'blue'],

+ 34 - 0
app/Models/Project.php

xqd
@@ -0,0 +1,34 @@
+<?php
+
+namespace App\Models;
+
+use Illuminate\Support\Facades\Auth;
+
+class Project extends BaseModel
+{
+
+    public function getManager()
+    {
+        $role = ProjectRole::where('name', '经理')->first();
+        if(!$role) return null;
+        $res = ProjectUser::where([
+            ['project_id', '=', $this['id']],
+            ['project_role_id', '=', $role->id]
+        ])->first();
+        if($res) return User::find($res['user_id']);
+        return false;
+    }
+
+    public function getUserProjectRole()
+    {
+        $user = Auth::guard('mini')->user();
+        $project_user = ProjectUser::where([
+            ['project_id', '=', $this['id']],
+            ['user_id', '=', $user->id]
+        ])->first();
+        if($project_user) {
+            return ProjectRole::find($project_user->project_role_id);
+        }
+        return null;
+    }
+}

+ 8 - 0
app/Models/ProjectRole.php

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

+ 8 - 0
app/Models/ProjectUser.php

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

+ 11 - 0
app/Models/User.php

xqd xqd
@@ -51,6 +51,7 @@ class User extends Authenticatable
         return $validator;
     }
 
+
     public function role()
     {
         return $this->belongsTo('App\Models\Role', 'role_id');
@@ -62,4 +63,14 @@ class User extends Authenticatable
         $token = hash('sha256', $token);
         $this->update(['token' => $token]);
     }
+
+    public function projects()
+    {
+        return $this->belongsToMany('App\Models\Project', 'project_users', 'project_id', 'user_id');
+    }
+
+    public function project_roles()
+    {
+        return $this->belongsToMany('App\Models\ProjectRole', 'project_users', 'project_role_id', 'user_id');
+    }
 }

+ 32 - 0
database/migrations/2020_12_09_004443_create_projects_table.php

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

+ 32 - 0
database/migrations/2020_12_09_014620_create_project_roles_table.php

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

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

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

+ 20 - 0
database/seeds/ProjectRoleSeeder.php

xqd
@@ -0,0 +1,20 @@
+<?php
+
+use Illuminate\Database\Seeder;
+
+class ProjectRoleSeeder extends Seeder
+{
+    /**
+     * Run the database seeds.
+     *
+     * @return void
+     */
+    public function run()
+    {
+        for($i = 0; $i < 10; ++$i) {
+            \App\Models\ProjectRole::create([
+                'name' => '角色' . ($i + 2)
+            ]);
+        }
+    }
+}

+ 20 - 0
database/seeds/ProjectSeeder.php

xqd
@@ -0,0 +1,20 @@
+<?php
+
+use Illuminate\Database\Seeder;
+
+class ProjectSeeder extends Seeder
+{
+    /**
+     * Run the database seeds.
+     *
+     * @return void
+     */
+    public function run()
+    {
+        for($i = 0; $i < 20; ++$i) {
+            \App\Models\Project::create([
+                'name' => '项目' . ($i + 2)
+            ]);
+        }
+    }
+}

+ 6 - 3
mini/app.json

xqd
@@ -1,14 +1,17 @@
 {
   "pages": [
+    "pages/project/index",
     "pages/index/index",
+    "pages/create-project-role/index",
+    "pages/create-project/index",
     "pages/login/index",
     "pages/logs/logs"
   ],
   "window": {
     "backgroundTextStyle": "light",
-    "navigationBarBackgroundColor": "#fff",
-    "navigationBarTitleText": "Weixin",
-    "navigationBarTextStyle": "black"
+    "navigationBarBackgroundColor": "#5693FC",
+    "navigationBarTitleText": "城通设备管理",
+    "navigationBarTextStyle": "white"
   },
   "sitemapLocation": "sitemap.json",
   "usingComponents": {

+ 43 - 2
mini/app.wxss

xqd xqd xqd
@@ -1,4 +1,9 @@
 /**app.wxss**/
+.sg-container {
+  min-height: 100vh;
+  padding-bottom: 100rpx;
+  background: #f7f7f7;
+}
 .sg-bg {
   width: 100%;
   position: fixed;
@@ -31,15 +36,27 @@
 .sg-bottom-border {
   border-bottom: 1px solid #ebedf0;
 }
+.sg-margin-top-sm {
+  margin-top: 30rpx;
+}
 .sg-margin-top {
   margin-top: 50rpx;
 }
+.sg-margin-tb {
+  margin: 30rpx 0;
+}
+.sg-margin-tb-sm {
+  margin: 15rpx 0;
+}
 .sg-shadow {
   box-shadow: 0px 4px 6px 1px #c9c9c9;
 }
 .sg-icon-img {
   width: 50rpx;
 }
+.sg-font-xs {
+  font-size: 0.8rem;
+}
 .sg-font-small {
   font-size: 0.9rem;
 }
@@ -50,14 +67,38 @@
   color: #5693FC;
 }
 .sg-avatar {
-  width: 100rpx;
+  width: 80rpx;
   border-radius: 50%;
   border: 2px solid white;
 }
 .sg-icon {
-  font-size: 1.5rem;
+  font-size: 1.2rem;
 }
 .sg-header {
   font-size: 1.2rem;
   font-weight: bold;
+}
+.sg-flex {
+  display: flex;
+}
+.sg-align-center {
+  align-items: center;
+}
+.sg-space-between {
+  justify-content: space-between;
+}
+.sg-flex-grow {
+  flex-grow: 1;
+}
+.sg-bottom-submit-box {
+  position: fixed;
+  bottom: 0;
+  left: 0;
+  width: 100%;
+  background: white;
+}
+.sg-big-avatar {
+  width: 130rpx;
+  margin-right: 30rpx;
+  border-radius: 50%;
 }

+ 1 - 0
mini/components/navbar/index.wxss

xqd
@@ -11,6 +11,7 @@
   border-top: 1px solid #ebedf0;
   font-size: 0.8rem;
   z-index: 1000;
+  background: white;
 }
 .sg-nav-box .sg-nav-list {
   display: flex;

+ 183 - 0
mini/pages/create-project-role/index.js

xqd
@@ -0,0 +1,183 @@
+// pages/create-project-role/index.js
+import http from '../../utils/http'
+import util from '../../utils/util'
+Page({
+
+  /**
+   * 页面的初始数据
+   */
+  data: {
+    keyword: '',
+    projects: [],
+    projectIndex: -1,
+    users: [],
+    userIndex: -1,
+    roleIndex: -1
+  },
+
+  /**
+   * 生命周期函数--监听页面加载
+   */
+  onLoad: function (options) {
+    this.getProjects()
+    this.getRoles()
+  },
+
+  submit() {
+    if(this.data.users.length <= 0) {
+      util.error('请选择成员')
+      return false
+    }
+    if(this.data.projectIndex < 0) {
+      util.error('请选择项目')
+      return false
+    }
+    if(this.data.roleIndex < 0) {
+      util.error('请选择角色')
+      return false
+    }
+    var user_id = this.data.users[0].id;
+    var project_id = this.data.projects[this.data.projectIndex].id;
+    var role_id = this.data.roles[this.data.roleIndex].id;
+    http({
+      url: 'projects/addUser',
+      data: {
+        user_id: user_id,
+        project_id: project_id,
+        project_role_id: role_id
+      },
+      success: function(res) {
+        if(res.code == 0) {
+          util.success('操作成功')
+        }
+      }
+    })
+  },
+
+  clear: function() {
+    this.setData({
+      keyword: ''
+    })
+  },
+
+  blur: function() {
+    var that = this
+    setTimeout(function() {
+      that.search()
+    }, 300)
+  },
+
+  search: function() {
+    var that = this
+    if(!this.data.keyword) return false;
+    http({
+      url: 'users/search',
+      data: {
+        keyword: this.data.keyword
+      },
+      success: function(res) {
+        if(res.code == 0) {
+          if(res.data.length <= 0) {
+            util.error('未找到相应用户')
+          }
+          that.setData({
+            users: res.data
+          })
+        }
+      }
+    })
+  },
+
+  bindPickerChange: function(e) {
+    var name = e.currentTarget.dataset.name
+    this.setData({
+      [name]: e.detail.value
+    })
+  },
+
+  getRoles: function() {
+    var that = this
+    http({
+      url: 'project-roles/getAll',
+      data: {},
+      success: function(res) {
+        if(res.code == 0) {
+          that.setData({
+            roles: res.data
+          })
+        }
+      }
+    })
+  },
+
+  getProjects: function() {
+    var that = this
+    http({
+      url: 'projects/getAll',
+      data: {},
+      success: function(res) {
+        if(res.code == 0) {
+          that.setData({
+            projects: res.data
+          })
+        }
+      }
+    })
+  },
+
+  updateInput: function(e) {
+    var name = e.currentTarget.dataset.name
+    this.setData({
+      [name]: e.detail.value
+    })
+  },
+
+  /**
+   * 生命周期函数--监听页面初次渲染完成
+   */
+  onReady: function () {
+
+  },
+
+  /**
+   * 生命周期函数--监听页面显示
+   */
+  onShow: function () {
+
+  },
+
+  /**
+   * 生命周期函数--监听页面隐藏
+   */
+  onHide: function () {
+
+  },
+
+  /**
+   * 生命周期函数--监听页面卸载
+   */
+  onUnload: function () {
+
+  },
+
+  /**
+   * 页面相关事件处理函数--监听用户下拉动作
+   */
+  onPullDownRefresh: function () {
+
+  },
+
+  /**
+   * 页面上拉触底事件的处理函数
+   */
+  onReachBottom: function () {
+
+  },
+
+  /**
+   * 用户点击右上角分享
+   */
+  onShareAppMessage: function () {
+
+  }
+})

+ 4 - 0
mini/pages/create-project-role/index.json

xqd
@@ -0,0 +1,4 @@
+{
+  "navigationBarTitleText": "人员添加",
+  "usingComponents": {}
+}

+ 43 - 0
mini/pages/create-project-role/index.wxml

xqd
@@ -0,0 +1,43 @@
+<!--pages/create-project-role/index.wxml-->
+<view class="sg-container">
+  <view class="sg-search-box sg-shadow">
+    <van-icon name="search" class="sg-index-color sg-search-icon" />
+    <input class="sg-search-input" placeholder="搜索成员的姓名或绑定手机号" bindblur="blur" bindinput="updateInput"
+      data-name="keyword" value="{{keyword}}"></input>
+    <van-icon name="close" class="sg-search-icon" bind:click="clear"/>
+  </view>
+  <view class="sg-user-box">
+    <view class="sg-user-list sg-margin-tb">
+      <view class="sg-user-item sg-pad sg-margin-top-sm" wx:for="{{users}}" wx:key="index">
+        <image class="sg-big-avatar" src="{{item.avatar}}" mode="widthFix"></image>
+        <view class="sg-right sg-flex-grow">
+          <view class="sg-name">{{item.name}}</view>
+          <view class="sg-project-role sg-gray-color sg-font-small sg-flex sg-align-center sg-space-between sg-margin-tb-sm">
+            <view class="sg-project">{{ item.project }}</view>
+            <view class="sg-role">{{ item.role }}</view>
+          </view>
+          <view class="sg-phone sg-gray-color sg-font-small">{{ item.phone }}</view>
+        </view>
+      </view>
+    </view>
+  </view>
+  <view class="sg-pick-box">
+    <view class="sg-pick-item sg-pad">
+      <view class="sg-pick-name">将他添加到:</view>
+      <picker bindchange="bindPickerChange" value="{{projectIndex}}" range="{{projects}}" range-key="name" data-name="projectIndex">
+        <view class="picker sg-gray-color">
+          {{projectIndex >= 0 ? projects[projectIndex].name : '请选择需要将他添加的项目'}}
+        </view>
+      </picker>
+    </view>
+    <view class="sg-pick-item sg-pad sg-margin-top-sm">
+      <view class="sg-pick-name">他的角色:</view>
+      <picker bindchange="bindPickerChange" value="{{roleIndex}}" range="{{roles}}" range-key="name" data-name="roleIndex">
+        <view class="picker sg-gray-color">
+          {{roleIndex >= 0 ? roles[roleIndex].name : '请选择他在项目中的角色'}}
+        </view>
+      </picker>
+    </view>
+  </view>
+  <view class="sg-bottom-submit-box sg-pad sg-center" bindtap="submit">立即添加</view>
+</view>

+ 28 - 0
mini/pages/create-project-role/index.wxss

xqd
@@ -0,0 +1,28 @@
+/* pages/create-project-role/index.wxss */
+.sg-search-box {
+  margin: 30rpx;
+  display: flex;
+  align-items: center;
+  background: white;
+  border-radius: 50rpx;
+  padding: 15rpx 20rpx;
+}
+.sg-search-icon {
+  margin-right: 20rpx;
+}
+.sg-search-box .sg-search-input {
+  flex-grow: 1;
+}
+.sg-pick-item {
+  display: flex;
+  align-items: center;
+  background: white;
+}
+.sg-user-item {
+  background: white;
+  display: flex;
+  align-items: center;
+}
+.sg-user-item .sg-name {
+  font-size: 1.1rem;
+}

+ 94 - 0
mini/pages/create-project/index.js

xqd
@@ -0,0 +1,94 @@
+// pages/create-project/index.js
+import http from '../../utils/http'
+import util from '../../utils/util'
+
+Page({
+
+  /**
+   * 页面的初始数据
+   */
+  data: {
+    name: ''
+  },
+
+  /**
+   * 生命周期函数--监听页面加载
+   */
+  onLoad: function (options) {
+
+  },
+
+  onChange: function(e) {
+    var name = e.currentTarget.dataset.name
+    this.setData({
+      [name]: e.detail
+    })
+  },
+
+  submit: function() {
+    if(!this.data.name) {
+      util.error('项目名称必填')
+      return false;
+    }
+    http({
+      url: 'projects/create',
+      data: {
+        name: this.data.name
+      },
+      success: function(res) {
+        if(res.code == 0) {
+          util.success('创建成功')
+        }
+      }
+    })
+  },
+
+  /**
+   * 生命周期函数--监听页面初次渲染完成
+   */
+  onReady: function () {
+
+  },
+
+  /**
+   * 生命周期函数--监听页面显示
+   */
+  onShow: function () {
+
+  },
+
+  /**
+   * 生命周期函数--监听页面隐藏
+   */
+  onHide: function () {
+
+  },
+
+  /**
+   * 生命周期函数--监听页面卸载
+   */
+  onUnload: function () {
+
+  },
+
+  /**
+   * 页面相关事件处理函数--监听用户下拉动作
+   */
+  onPullDownRefresh: function () {
+
+  },
+
+  /**
+   * 页面上拉触底事件的处理函数
+   */
+  onReachBottom: function () {
+
+  },
+
+  /**
+   * 用户点击右上角分享
+   */
+  onShareAppMessage: function () {
+
+  }
+})

+ 4 - 0
mini/pages/create-project/index.json

xqd
@@ -0,0 +1,4 @@
+{
+  "navigationBarTitleText": "新建项目",
+  "usingComponents": {}
+}

+ 9 - 0
mini/pages/create-project/index.wxml

xqd
@@ -0,0 +1,9 @@
+<!--pages/create-project/index.wxml-->
+<view class="sg-container">
+  <view class="sg-form">
+    <van-cell-group>
+      <van-field label="项目名称" value="{{ name }}" placeholder="请输入项目名称" bind:change="onChange" data-name="name"/>
+    </van-cell-group>
+  </view>
+  <view class="sg-submit-box sg-pad sg-center" bindtap="submit">立即上报</view>
+</view>

+ 11 - 0
mini/pages/create-project/index.wxss

xqd
@@ -0,0 +1,11 @@
+/* pages/create-project/index.wxss */
+.sg-container {
+  background: #f7f7f7;
+}
+.sg-submit-box {
+  position: fixed;
+  bottom: 0;
+  left: 0;
+  width: 100%;
+  background: white;
+}

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

xqd xqd xqd xqd xqd
@@ -1,5 +1,6 @@
 //index.js
 //获取应用实例
+import http from '../../utils/http'
 const app = getApp()
 
 Page({
@@ -8,7 +9,10 @@ Page({
     userInfo: {},
     hasUserInfo: false,
     canIUse: wx.canIUse('button.open-type.getUserInfo'),
-    keyword: ''
+    keyword: '',
+    page: 1,
+    list: [],
+    touchBottom: false
   },
   //事件处理函数
   bindViewTap: function() {
@@ -17,6 +21,7 @@ Page({
     })
   },
   onLoad: function () {
+    this.getList();
     if (app.globalData.userInfo) {
       this.setData({
         userInfo: app.globalData.userInfo,
@@ -44,6 +49,45 @@ Page({
       })
     }
   },
+  navigate: function(e) {
+    wx.navigateTo({
+      url: e.currentTarget.dataset.url,
+    })
+  },
+  updateInput: function(e) {
+    var name = e.currentTarget.dataset.name
+    this.setData({
+      [name]: e.detail.value
+    })
+  },
+  search: function() {
+    this.setData({
+      list: [],
+      page: 1
+    })
+    this.getList()
+  },
+  getList: function() {
+    if(this.data.touchBottom) return false;
+
+    var that = this
+    http({
+      url: 'projects/get',
+      data: {
+        page: this.data.page,
+        name: this.data.keyword
+      },
+      success: function(res) {
+        if(res.code == 0) {
+          var list = that.data.list.concat(res.data)
+          that.setData({
+            touchBottom: res.data.length == 0,
+            list: list
+          })
+        }
+      }
+    })
+  },
   getUserInfo: function(e) {
     console.log(e)
     app.globalData.userInfo = e.detail.userInfo
@@ -51,5 +95,18 @@ Page({
       userInfo: e.detail.userInfo,
       hasUserInfo: true
     })
+  },
+  onReachBottom: function() {
+    if(!this.data.touchBottom) {
+      this.setData({
+        page: this.data.page + 1
+      })
+      this.getList()
+    } else {
+      wx.showToast({
+        icon: 'none',
+        title: '没有更多了',
+      })
+    }
   }
 })

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

xqd
@@ -1,6 +1,3 @@
 {
-  "navigationBarBackgroundColor": "#5693FC",
-  "navigationBarTextStyle": "white",
-  "navigationBarTitleText": "城通设备管理",
   "usingComponents": {}
 }

+ 21 - 6
mini/pages/index/index.wxml

xqd
@@ -1,32 +1,47 @@
 <!--index.wxml-->
 <view class="sg-container">
   <view class="sg-top-box sg-index-bg">
-    <view class="sg-top-item sg-font-small">
+    <view class="sg-top-item sg-font-xs" bindtap="navigate" data-url="/pages/create-project/index">
       <van-icon name="edit" class="sg-icon"/>
       <view class="sg-top-name">新建项目</view>
     </view>
-    <view class="sg-top-item sg-font-small">
+    <view class="sg-top-item sg-font-xs">
       <van-icon name="user-o" class="sg-icon"/>
       <view class="sg-top-name">成员添加</view>
     </view>
-    <view class="sg-top-item sg-font-small">
+    <view class="sg-top-item sg-font-xs">
       <van-icon name="delete" class="sg-icon"/>
       <view class="sg-top-name">草稿箱</view>
     </view>
-    <view class="sg-top-item sg-font-small sg-right-border">
+    <view class="sg-top-item sg-font-xs sg-right-border">
       <van-icon name="comment-o" class="sg-icon"/>
       <view class="sg-top-name">消息提示</view>
     </view>
-    <view class="sg-top-item sg-font-small">
+    <view class="sg-top-item sg-font-xs">
       <image class="sg-avatar" src="{{ userInfo.avatar }}" mode="widthFix"></image>
     </view>
   </view>
   <view class="sg-search-box sg-shadow">
     <van-icon name="search" class="sg-index-color sg-search-icon"/>
-    <input class="sg-search-input" placeholder="搜索相关项目"></input>
+    <input class="sg-search-input" placeholder="搜索相关项目" bindblur="search" bindinput="updateInput" data-name="keyword"></input>
   </view>
   <view class="sg-box sg-pad">
     <view class="sg-header">所有项目</view>
+    <view class="sg-list">
+      <view class="sg-item sg-index-card sg-shadow sg-pad sg-margin-top-sm" wx:for="{{list}}" wx:key="index" data-id="{{item.id}}" bindtap="navigate" data-url="/pages/project/index?id={{item.id}}">
+        <image class="sg-img" mode="widthFix" src="https://t18.9026.com/mini/test.png"></image>
+        <view class="sg-right">
+          <view class="sg-top">
+            <view class="sg-name sg-bold">{{ item.name }}</view>
+            <view class="sg-date sg-gray-color sg-font-small">{{ item.date }}</view>
+          </view>
+          <view class="sg-bottom sg-font-small sg-margin-top-sm">
+            <view class="sg-desc">经理:{{ item.manager ? item.manager.name : '无' }}</view>
+            <view class="sg-desc">电话:{{ item.manager ? item.manager.phone : '无' }}</view>
+          </view>
+        </view>
+      </view>
+    </view>
   </view>
   <navbar></navbar>
 </view>

+ 19 - 2
mini/pages/index/index.wxss

xqd xqd
@@ -4,14 +4,14 @@
   display: flex;
   align-items: center;
   justify-content: space-around;
-  padding: 50rpx 0 100rpx 0;
+  padding: 50rpx 15rpx 100rpx 15rpx;
 }
 .sg-top-item  {
   display: flex;
   align-items: center;
   flex-direction: column;
   justify-content: center;
-  padding: 0 20rpx;
+  padding: 0 15rpx;
 }
 .sg-top-item .sg-top-name {
   margin-top: 15rpx;
@@ -32,4 +32,21 @@
 }
 .sg-search-box .sg-search-input {
   flex-grow: 1;
+}
+.sg-box .sg-img {
+  width: 120rpx;
+}
+.sg-list .sg-item {
+  display: flex;
+  align-items: center;
+}
+.sg-list .sg-item .sg-right {
+  flex-grow: 1;
+  margin-left: 30rpx;
+}
+.sg-list .sg-item .sg-bottom,
+.sg-list .sg-item .sg-top {
+  display: flex;
+  align-items: center;
+  justify-content: space-between;
 }

+ 4 - 4
mini/pages/login/index.js

xqd xqd
@@ -82,11 +82,11 @@ Page({
 
   login: function() {
     if(!util.checkMobile(this.data.mobile)) {
-      util.showError('手机号格式错误')
+      util.error('手机号格式错误')
       return false;
     }
     if(!this.data.password) {
-      util.showError('密码必填')
+      util.error('密码必填')
       return false;
     }
     http({
@@ -106,11 +106,11 @@ Page({
 
   reset: function() {
     if(!util.checkMobile(this.data.mobile)) {
-      util.showError('手机号格式错误')
+      util.error('手机号格式错误')
       return false;
     }
     if(!this.data.name) {
-      util.showError('真实姓名必填')
+      util.error('真实姓名必填')
       return false;
     }
     http({

+ 96 - 0
mini/pages/project/index.js

xqd
@@ -0,0 +1,96 @@
+// pages/project/index.js
+import http from '../../utils/http'
+import util from '../../utils/util'
+var app = getApp()
+Page({
+
+  /**
+   * 页面的初始数据
+   */
+  data: {
+    id: -1,
+    userInfo: {}
+  },
+
+  /**
+   * 生命周期函数--监听页面加载
+   */
+  onLoad: function (options) {
+    var id = options.id ? options.id : 1
+    this.setData({
+      id: id,
+      userInfo: app.globalData.userInfo
+    })
+    this.getProject()
+  },
+
+  getProject() {
+    var that = this
+    http({
+      url: 'projects/detail',
+      data: {
+        id: this.data.id
+      },
+      success: function(res) {
+        console.log(res)
+        if(res.code == 0) {
+          that.setData({
+            project: res.data
+          })
+          wx.setNavigationBarTitle({
+            title: res.data.name,
+          })
+        }
+      }
+    })
+  },
+
+  /**
+   * 生命周期函数--监听页面初次渲染完成
+   */
+  onReady: function () {
+
+  },
+
+  /**
+   * 生命周期函数--监听页面显示
+   */
+  onShow: function () {
+
+  },
+
+  /**
+   * 生命周期函数--监听页面隐藏
+   */
+  onHide: function () {
+
+  },
+
+  /**
+   * 生命周期函数--监听页面卸载
+   */
+  onUnload: function () {
+
+  },
+
+  /**
+   * 页面相关事件处理函数--监听用户下拉动作
+   */
+  onPullDownRefresh: function () {
+
+  },
+
+  /**
+   * 页面上拉触底事件的处理函数
+   */
+  onReachBottom: function () {
+
+  },
+
+  /**
+   * 用户点击右上角分享
+   */
+  onShareAppMessage: function () {
+
+  }
+})

+ 3 - 0
mini/pages/project/index.json

xqd
@@ -0,0 +1,3 @@
+{
+  "usingComponents": {}
+}

+ 31 - 0
mini/pages/project/index.wxml

xqd
@@ -0,0 +1,31 @@
+<!--pages/project/index.wxml-->
+<view class="sg-container">
+  <view class="sg-user-box sg-pad sg-flex sg-align-center">
+    <image class="sg-big-avatar" src="{{userInfo.avatar}}" mode="widthFix"></image>
+    <view class="sg-right sg-flex-grow">
+      <view class="sg-name">{{userInfo.name}}</view>
+      <view
+        class="sg-project-role sg-gray-color sg-font-small sg-flex sg-align-center sg-space-between sg-margin-tb-sm">
+        <view class="sg-project">中铁二局项目部</view>
+        <view class="sg-role">{{ project.role ? project.role.name : '' }}</view>
+      </view>
+      <view class="sg-phone-user sg-flex sg-align-center sg-space-between">
+        <view class="sg-phone sg-gray-color sg-font-small">{{ userInfo.phone }}</view>
+        <view class="sg-user sg-font-small sg-index-color sg-flex sg-align-center"><van-icon name="user-o" /><text>人员管理</text></view>
+      </view>
+    </view>
+  </view>
+  <view class="sg-menu-box">
+    <view class="sg-header">
+      <view class="sg-title">设备租赁</view>
+      <view class="sg-sub-title">外部设备租赁</view>
+    </view>
+    <view class="sg-menu-list">
+      <view class="sg-menu-item">
+        <image class="sg-img" src="http://t18.9026.com/api/mini/create-order.png" mode="widthFix"></image>
+        <view class="sg-name">创建订单</view>
+        <view class="sg-desp">创建外部设备租赁订单</view>
+      </view>
+    </view>
+  </view>
+</view>

+ 4 - 0
mini/pages/project/index.wxss

xqd
@@ -0,0 +1,4 @@
+/* pages/project/index.wxss */
+.sg-user-box {
+  background: white;
+}

+ 9 - 2
mini/utils/util.js

xqd
@@ -18,15 +18,22 @@ const checkMobile = mobile => {
   return /^1[34578]\d{9}$/.test(mobile)
 }
 
-const showError = msg => {
+const error = msg => {
   wx.showToast({
     icon: 'none',
     title: msg,
   })
 }
 
+const success = msg => {
+  wx.showToast({
+    title: msg,
+  })
+}
+
 module.exports = {
   formatTime: formatTime,
   checkMobile: checkMobile,
-  showError: showError
+  error,
+  success
 }

BIN
public/mini/create-order.png


+ 12 - 0
routes/api.php

xqd
@@ -19,4 +19,16 @@ $api->version('v1', ['namespace' => 'App\Http\Controllers\Api\mini', 'prefix' =>
     $api->any('login', 'AuthController@login');
     $api->any('reset', 'AuthController@reset');
     $api->any('loginByWechat', 'AuthController@loginByWechat');
+
+    $api->any('projects/create', 'ProjectController@create');
+    $api->any('projects/get', 'ProjectController@get');
+    $api->any('projects/getAll', 'ProjectController@getAll');
+    $api->any('projects/addUser', 'ProjectController@addUser');
+    $api->any('projects/detail', 'ProjectController@detail');
+
+    $api->any('project-roles/create', 'ProjectRoleController@create');
+    $api->any('project-roles/get', 'ProjectRoleController@get');
+    $api->any('project-roles/getAll', 'ProjectRoleController@getAll');
+
+    $api->any('users/search', 'UserController@search');
 });