ajun 5 лет назад
Родитель
Сommit
174fbe512b

+ 5 - 4
app/Filters/DemandFilters.php

@@ -51,9 +51,10 @@ class DemandFilters
 
     public function before()
     {
-        $user = Auth::user();
-        $authorities = $user->authorities();
-        $authorities = data_get($authorities,'*.id');
-        $this->queryBuilder->whereIn('authority_id',$authorities);
+//        dd(11);
+//        $user = Auth::user();
+//        $authorities = $user->authorities();
+//        $authorities = data_get($authorities,'*.id');
+//        $this->queryBuilder->whereIn('authority_id',$authorities);
     }
 }

+ 32 - 27
app/Http/Controllers/DemandController.php

@@ -6,6 +6,7 @@ use App\Components\AsyncResponse;
 use App\Demand;
 use App\Filters\DemandFilters;
 use App\Http\Requests\Demand\DemandRequest;
+use App\Services\DemandService;
 use Illuminate\Http\Request;
 use Illuminate\Contracts\Foundation\Application;
 use Illuminate\Contracts\View\Factory;
@@ -26,22 +27,31 @@ class DemandController extends Controller
     {
         // 查询权限
 
-        $demands = Demand::query()->with(['processes', 'initiator', 'handler', 'uploadFile'])->filter($filters)->paginate($request['paginate'] ?? 50);
+        $demands = Demand::query()->with(['processes', 'initiator', 'handler', 'uploadFile'])->filter($filters)->sql();
 
+        $demands = Demand::query()->with(['processes', 'initiator', 'handler', 'uploadFile'])->filter($filters)->paginate($request['paginate'] ?? 50);
         return view('maintenance.demand.index', compact('demands'));
     }
 
     /**
      * @param DemandRequest $request
+     * @param DemandService $service
      */
-    public function storeApi(DemandRequest $request)
+    public function storeApi(DemandRequest $request,DemandService $service)
     {
         // 创建权限
-
+        /** @var Demand $demand */
         $demand = Demand::query()->create($request->all());
 
-        if ($demand) $this->success($demand);
-        else $this->error('需求创建出现异常');
+        if ($demand) {
+
+            $file = $request->file('file');
+            if(isset($file))$service->saveUPLoadFile($demand,$file);
+
+            $this->success($demand);
+        } else{
+            $this->error('需求创建出现异常');
+        }
     }
 
     /**
@@ -64,32 +74,13 @@ class DemandController extends Controller
     /**
      * @param DemandRequest $request
      * @param Demand $demand
+     * @param DemandService $service
      */
-    public function uploadFileApi(DemandRequest $request, Demand $demand)
+    public function uploadFileApi(DemandRequest $request, Demand $demand,DemandService $service)
     {
         // 文件上传
 
-
-        $file = $request->file('file');
-        $tmpFile = $file->getRealPath();
-
-        if (!$demand->uploadFile()) $this->error('该需求已有描述图片');
-        if (!$file) $this->error('上传图片不得为空');
-        if (!$file->isValid()) $this->error('找不到上传图片');
-        if (!is_uploaded_file($tmpFile)) $this->error('文件错误');
-
-        $fileSuffix = $file->getClientOriginalExtension();
-
-        $fileName = date('ymd') . '-' . Uuid::uuid1();
-
-        $filePath = storage_path('app/public/files/issue/' . $fileName . '-issue' . $fileSuffix);
-
-        $result = move_uploaded_file($tmpFile, $filePath);
-
-        if (!$result) $this->error('文件上传失败');
-
-        $upLoadFile = $demand->saveFile($fileName,$fileSuffix);
-        if(!$upLoadFile)$this->error('文件上传失败');
+        $service->saveUPLoadFile($demand,$request['file']);
 
         $demand->loadMissing('authority', 'initiator', 'handler', 'uploadFile', 'processes');
 
@@ -112,4 +103,18 @@ class DemandController extends Controller
         }
     }
 
+    /**
+     * 完结需求
+     *
+     * @param DemandRequest $request
+     * @param Demand $demand
+     */
+    public function finishApi(DemandRequest $request, Demand $demand)
+    {
+        if($demand->update(['status','1']))
+            $this->success($demand);
+        else
+            $this->error('修改失败');
+    }
+
 }

+ 35 - 2
app/Services/DemandService.php

@@ -1,13 +1,46 @@
-<?php 
+<?php
 
 namespace App\Services;
 
 use App\Traits\ServiceAppAop;
 use App\Demand;
+use Illuminate\Http\UploadedFile;
+use Ramsey\Uuid\Uuid;
 
 class DemandService
 {
     use ServiceAppAop;
     protected $modelClass=Demand::class;
 
-}
+    /**
+     * saveUPLoadFile
+     * @param Demand $demand
+     * @param UploadedFile $file
+     * @return array
+     */
+    public function saveUPLoadFile(Demand $demand,UploadedFile $file): array
+    {
+        $tmpFile = $file->getRealPath();
+
+        if (!$demand->uploadFile()) return ['success'=>false,'message'=>'该需求已有描述图片'];
+        if (!$file) return ['success'=>false,'message'=>'上传图片不得为空'];
+        if (!$file->isValid())  return ['success'=>false,'message'=>'找不到上传图片'];
+        if (!is_uploaded_file($tmpFile)) return ['success'=>false,'message'=>'文件错误'];
+
+        $fileSuffix = $file->getClientOriginalExtension();
+
+        $fileName = date('ymd') . '-' . Uuid::uuid1();
+
+        $filePath = storage_path('app/public/files/issue/' . $fileName . '-issue' . $fileSuffix);
+
+        $result = move_uploaded_file($tmpFile, $filePath);
+
+        if (!$result) return ['success'=>false,'message'=>'文件上传失败'];
+
+        $upLoadFile = $demand->saveFile($fileName,$fileSuffix);
+        if(!$upLoadFile)return ['success'=>false,'message'=>'文件上传失败'];
+
+        return ['success'=>true,'data'=>$demand];
+    }
+
+}

+ 2 - 0
resources/views/layouts/app.blade.php

@@ -25,6 +25,7 @@
             @component('layouts.menu')@endcomponent
         </div>
     </nav>
+    @component('maintenance.demand._create')@endcomponent
     @yield('content')
     <hr>
 </div>
@@ -94,5 +95,6 @@
         }
     });
 </script>
+@component('maintenance.demand._createjs')@endcomponent
 @yield('lastScript')
 </html>

+ 96 - 0
resources/views/maintenance/demand/_create.blade.php

@@ -0,0 +1,96 @@
+<div id="demand-div">
+    <div class="container-fluid position-absolute" style="z-index:300;top: 100px;">
+        <form class="d-flex float-right">
+            <button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenu2" data-toggle="dropdown"
+                    aria-haspopup="true" aria-expanded="false">
+                提出问题
+            </button>
+            <div class="dropdown-menu" aria-labelledby="dropdownMenu2">
+                <button class="dropdown-item" type="button" @click="showAddDemand()">提出问题</button>
+                <a href={{url('maintenance/demand/')}} class="dropdown-item">问题列表</a>
+            </div>
+        </form>
+    </div>
+
+
+    <div class="modal" tabindex="-1" id="add-demand">
+        <div class="modal-dialog modal-lg">
+            <div class="modal-content">
+                <div class="modal-header">
+                    <h4>问题详情添加</h4>
+                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
+                        <span aria-hidden="true">&times;</span>
+                    </button>
+                </div>
+
+                <div class="modal-body">
+                    <div class="form-group row">
+                        <label for="add-demand-auth" class="col-sm-2 col-form-label text-right">问题可见权限</label>
+                        <div class="col-sm-10 form-inline">
+                            <select name="add-demand-auth" id="add-demand-auth" class="form-control col-sm-7"
+                                    v-model="addDemand.authority_id"
+                                    :class="demandErrors.authority_id?'is-invalid':''"
+                                    @focus="demandErrors.authority_id!==null ? demandErrors.authority_id=null:''">
+                                <option value=""></option>
+                            </select>
+                            <input type="text" class="form-control col-sm-3 ml-1" @input="filterAuth($e)"
+                                   placeholder="输入权限进行删选">
+                            <div class="invalid-feedback" v-if="demandErrors.authority_id">
+                                @{{ demandErrors.authority_id[0] }}
+                            </div>
+                        </div>
+                    </div>
+
+                    <div class="form-group row">
+                        <label for="add-demand-type" class="col-sm-2 col-form-label text-right">问题类型</label>
+                        <div class="col-sm-10 form-inline">
+                            <select name="add-demand-auth" id="add-demand-type" class="form-control col-sm-10"
+                                    v-model="addDemand.type"
+                                    :class="demandErrors.type?'is-invalid':''"
+                                    @focus="demandErrors.type!==null ? demandErrors.type=null:''">
+                                <option v-for="(type,index) in types" :value="type.name">@{{ type.value }}</option>
+                            </select>
+                            <div class="invalid-feedback" v-if="demandErrors.type">
+                                @{{ demandErrors.type[0] }}
+                            </div>
+                        </div>
+                    </div>
+
+                    <div class="form-group row">
+                        <label for="add-demand-description" class="col-sm-2 col-form-label text-right">问题描述</label>
+                        <div class="col-sm-10 form-inline">
+                            <textarea  id="add-demand-description" class="form-control col-sm-10"
+                                       v-model="addDemand.description"
+                                      :class="demandErrors.description?'is-invalid':''"
+                                      @focus="demandErrors.description!==null ? demandErrors.description=null:''"
+                            ></textarea>
+
+                            <div class="invalid-feedback" v-if="demandErrors.description">
+                                @{{ demandErrors.description[0] }}
+                            </div>
+                        </div>
+                    </div>
+
+
+                    <div class="form-group row">
+                        <label for="add-demand-file" class="col-sm-2 col-form-label text-right">上传文件</label>
+                        <div class="col-sm-10 form-inline">
+                            <input type="file" name="name" id="add-demand-file" class="form-control-file col-sm-10"
+                                   placeholder="输入配置名称"
+                                   :class="demandErrors.file?'is-invalid':''"
+                                   @focus="demandErrors.file!==null ? demandErrors.file=null:''">
+                            <div class="invalid-feedback" v-if="demandErrors.file">
+                                @{{ demandErrors.file[0] }}
+                            </div>
+                        </div>
+                    </div>
+                </div>
+                <div class="modal-footer">
+                    <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
+                    <button type="button" class="btn btn-primary" @click="createDemand">提交</button>
+                </div>
+            </div>
+
+        </div>
+    </div>
+</div>

+ 64 - 0
resources/views/maintenance/demand/_createjs.blade.php

@@ -0,0 +1,64 @@
+<script>
+    new Vue({
+        el: "#demand-div",
+        data: {
+            types: [{name:0,value:'需求'},{name:1,value:'问题'}],
+            addDemand: {},
+            authorities: [],
+            authoritiesFilter: [],
+            demandErrors: {}
+        },
+        created() {
+            this.authoritiesFilter = JSON.parse(JSON.stringify(this.authorities));
+        },
+        mounted() {
+
+        },
+        methods: {
+            /** 筛选 */
+            filterAuth($e) {
+                let value = $($e).val();
+                let authorities = JSON.parse(JSON.stringify(this.authorities));
+                if (value === null) {
+                    this.authoritiesFilter = authorities;
+                    return;
+                }
+                this.authoritiesFilter = authorities.filter(function (item) {
+                    return item.includes(value);
+                });
+            },
+            /** 创建 */
+            showAddDemand() {
+                this.addDemand = {};
+                $('#add-demand').modal('show')
+            },
+            /** 创建 */
+            createDemand() {
+                let url = '{{url('apiLocal/demand/store')}}';
+
+                window.tempTip.setIndex(1999);
+                window.tempTip.setDuration(3000);
+
+                let formData = new FormData();
+                let file = document.querySelector('#add-demand-file').files[0];
+                formData.append('authority_id', this.addDemand['authority_id']);
+                formData.append('type', this.addDemand['type']);
+                formData.append('description', this.addDemand['description']);
+                formData.append('file', file);
+
+                window.axios.post(url, formData, {
+                    'Content-Type': 'multipart/form-data'
+                }).then(res => {
+                    if (res.data.success) {
+                        window.tempTip.showSuccess('问题提交成功');
+                        $('#add-demand').modal('hide')
+                        return;
+                    }
+                    window.tempTip.show('问题提交失败');
+                }).catch(err => {
+                    window.tempTip.show(err);
+                });
+            },
+        }
+    });
+</script>

+ 33 - 23
resources/views/maintenance/demand/_table.blade.php

@@ -1,24 +1,30 @@
-<table class="table table-striped table-sm table-hover">
-    <tr>
-        <th colspan="2">序号</th>
-        <th colspan="2">需求描述</th>
-        <th colspan="1" rowspan="3">过程</th>
-        <th colspan="2">附件</th>
-        <th colspan="2">发起人</th>
-        <th colspan="2">处理人</th>
-        <th colspan="2">发起时间</th>
-        <th colspan="2">状态</th>
-        <th colspan="2">操作</th>
-    </tr>
-    <tr>
-        <th>说明</th>
-        <th>经手人</th>
-        <th>时间</th>
-    </tr>
+<table class="table table-striped table-bordered table-sm table-hover">
+    <thead class="text-center">
+        <tr class="align-text-bottom">
+            <th rowspan="2">序号</th>
+            <th rowspan="2">类型</th>
+            <th rowspan="2">需求描述</th>
+            <th colspan="3" rowspan="1">过程</th>
+            <th rowspan="2">附件</th>
+            <th rowspan="2">发起人</th>
+            <th rowspan="2">处理人</th>
+            <th rowspan="2">发起时间</th>
+            <th rowspan="2">状态</th>
+            <th rowspan="2">操作</th>
+        </tr>
+        <tr class="thead-light">
+            <th>说明</th>
+            <th>经手人</th>
+            <th>时间</th>
+        </tr>
+    </thead>
+    <tbody>
     <template v-if="demands.length>0">
-        <tr class="text-center" v-for="(demand,i) in demands"  @click="selectTr===i+1?selectTr=0:selectTr=i+1" :class="selectTr===i+1?'focusing' : ''">
+        <tr class="text-center" v-for="(demand,i) in demands" @click="selectTr===i+1?selectTr=0:selectTr=i+1"
+            :class="selectTr===i+1?'focusing' : ''">
             <td>@{{ i+1 }}</td>
             <td>@{{ demand.type }}</td>
+            <td>@{{ demand.description }}</td>
             <template v-for="(process,index) in demand.processes">
                 <td>@{{ process.explain }}</td>
                 <td>@{{ process.processor ? process.processor.name : '' }}</td>
@@ -35,7 +41,6 @@
             <td>@{{ demand.handler ? demand.handler.name : '' }}</td>
             <td>@{{ demand.created_at }}</td>
             <td>@{{ demand.status }}</td>
-            <td>@{{ demand.status }}</td>
             <td>
                 <button class="btn btn-outline-success">完结</button>
                 <button class="btn btn-outline-danger">删</button>
@@ -43,9 +48,14 @@
         </tr>
     </template>
     <template v-else>
-        <div class="alert alert-info text-center" >
-            按条件查询的数据结果未空
-        </div>
+        <tr>
+            <td colspan="11">
+                <div class="alert alert-info text-center">
+                    按条件查询的数据结果未空
+                </div>
+            </td>
+        </tr>
     </template>
+    </tbody>
 </table>
-{{$suppliers->withQueryString()->links()}}
+{{ $demands->withQueryString()->links() }}

+ 39 - 3
resources/views/maintenance/demand/index.blade.php

@@ -34,22 +34,58 @@
                 uploadError:[],
             },
             created() {
+                let that = this;
                 this.demands.forEach(function (item,index,self){
-                    self[index]['status'] = this.status[item['status']]['value'] ?? '';
-                    self[index]['type'] = this.types[item['type']]['value']  ?? '';
+                    self[index]['status'] = that.status[item['status']].value ?? '';
+                    self[index]['type'] = that.types[item['type']]['value']  ?? '';
                 });
             },
             mounted(){
                 $('#list').removeClass('d-none');
+                let data = [
+                    [
+                        {name:'created_at_start',type:'time',tip:'创建开始时间'},
+                        {name:'created_at_end',type:'time',tip:'创建结束时间'},
+                        {name:'type',type:'select',data:this.types,placeholder:'类型'},
+                    ]
+                ];
+                let form=new query({
+                    el:"#form_div",
+                    condition:data,
+                });
+                form.init();
             },
             methods: {
                 /** 完结需求 */
                 finishDemand(demand){
-
+                    let url = '{{url('apiLocal/demand/finish')}}';
+                    window.tempTip.setDuration(3000);
+                    window.axios.post(url,{id:demand['id']}).then(res=>{
+                        if(res.data.success){
+                            window.tempTip.showSuccess('需求完结成功');
+                            demand.status = '已处理'
+                            return ;
+                        }
+                        window.tempTip.show('需求完结失败'+res.data.message);
+                    }).catch(err=>{
+                        window.tempTip.show('需求完结异常'+err);
+                    });
                 },
                 /** 删除 */
                 destroyDemand(demand,index){
+                    if(!confirm('确定要删除当前需求吗?')){return ;}
 
+                    window.tempTip.setDuration(3000);
+                    let url = '{{url('apiLocal/demand/destroy')}}'+'/'+demand['id'];
+                    window.axios.delete(url).then(res=>{
+                        if(res.data.success){
+                            this.$delete(this.demands,index);
+                            return ;
+                        }
+                        window.tempTip.show(res.data.message);
+                    }).catch(err=>{
+                        window.tempTip.show('删除出现异常'+err);
+                    });
                 },
                 /** 添加处理过程 */
                 addProcess(demand,explain){

+ 1 - 0
routes/apiLocal.php

@@ -162,4 +162,5 @@ Route::group(['prefix'=>'demand'],function(){
     Route::post('update','DemandController@updateApi')->name('demand.updateApi');
     Route::post('uploadFile','DemandController@uploadFileApi')->name('demand.uploadFileApi');
     Route::delete('destroy','DemandController@destroyApi')->name('demand.destroyApi');
+    Route::post('finish','DemandController@finishApi')->name('demand.finishApi');
 });