ソースを参照

BUG修复:客户管理-页面校验,物流计费删除方法丢失

Zhouzhendong 5 年 前
コミット
9b19a52beb

+ 3 - 0
app/CustomerTag.php

@@ -2,10 +2,13 @@
 
 namespace App;
 
+use App\Traits\ModelTimeFormat;
 use Illuminate\Database\Eloquent\Model;
 
 class CustomerTag extends Model
 {
+    use ModelTimeFormat;
+
     protected $fillable=[
         "name","explanation"
     ];

+ 17 - 2
app/Http/Controllers/CustomerBaseController.php

@@ -2,6 +2,8 @@
 
 namespace App\Http\Controllers;
 
+use App\Customer;
+use App\CustomerTag;
 use App\Owner;
 use App\Services\LogService;
 use Illuminate\Http\Request;
@@ -20,9 +22,10 @@ class CustomerBaseController extends Controller
     public function index(Request $request)
     {
         if(!Gate::allows('客户-查询')){ return redirect('denied');  }
-        $customers = app('CustomerService')->paginate($request->input(),["owners.contracts.files"]);
+        $customers = app('CustomerService')->paginate($request->input(),["owners.contracts.files","tags:id,name"]);
         $owners = app("OwnerService")->getIntersectPermitting(['id','name','customer_id']);
-        return response()->view('customer.customer.index',compact("customers","owners"));
+        $tags = CustomerTag::query()->get(["id","name"]);
+        return response()->view('customer.customer.index',compact("customers","owners","tags"));
     }
 
     /**
@@ -141,4 +144,16 @@ class CustomerBaseController extends Controller
         if ($row==count($ids))return ["success"=>true];
         return ["success"=>false,"data"=>"修改错误,影响了“".$row."”个项目"];
     }
+
+    public function addTag(Request $request)
+    {
+        $tags = $request->input("tags");
+        $id = $request->input("id");
+        /** @var Customer $customer */
+        $customer = app("CustomerService")->find($id);
+        if (!$customer)return ["success"=>false,"data"=>"客户不存在"];
+        $customer->tags()->sync($tags);
+        $customer->load("tags");
+        return ["success"=>true,"data"=>$customer->tags];
+    }
 }

+ 5 - 0
app/Http/Controllers/CustomerTagController.php

@@ -57,4 +57,9 @@ class CustomerTagController extends Controller
             "name" => "标签名"
         ]);
     }
+
+    public function get()
+    {
+        return ["success"=>true,"data"=>CustomerTag::query()->get(["id","name"])];
+    }
 }

+ 13 - 1
app/Http/Controllers/PriceModelController.php

@@ -21,6 +21,7 @@ use Illuminate\Http\Request;
 use Illuminate\Support\Facades\Cache;
 use Illuminate\Support\Facades\Gate;
 use Illuminate\Support\Facades\Validator;
+use Illuminate\Validation\Rule;
 use Maatwebsite\Excel\Facades\Excel;
 
 class PriceModelController extends Controller
@@ -353,7 +354,10 @@ class PriceModelController extends Controller
             'name'=>['required',$id?"unique:owner_price_operations,name,$id":'unique:owner_price_operations,name'],
             'priority'=>['required','integer','min:0','max:100'],
             'rules.*.strategy'=>['required_if:operation_type,出库'],
-            'rules.*.amount'=>['required',"integer"],
+            'rules.*.amount'=>[Rule::requiredIf(function () use ($params) {
+                if ("operation_type" == "入库")return true;
+                return false;
+            }),"integer"],
             'rules.*.unit_id'=>['required','integer'],
             'rules.*.unit_price'=>['required','numeric',"min:0"],
             'rules.*.priority'=>['required_if:operation_type,出库','integer','min:0','max:100'],
@@ -753,6 +757,14 @@ class PriceModelController extends Controller
         LogService::log(__METHOD__,"计费模型-删除物流计费详情",$id);
         return ["success"=>true];
     }
+    public function logisticDestroy($id)
+    {
+        if(!Gate::allows('计费模型-物流-删除')){ return ["success"=>false,"data"=>"无权操作"];  }
+        if (!$id)return ["success"=>false,"data"=>"非法参数"];
+        app("OwnerPriceLogisticService")->destroy($id);
+        LogService::log(__METHOD__,"计费模型-删除物流计费",$id);
+        return ["success"=>true];
+    }
 
     private function logisticValidator(array $params,$id = null)
     {

+ 7 - 0
app/Services/CustomerService.php

@@ -16,6 +16,13 @@ Class CustomerService
     public function paginate(array $params, array $withs=[])
     {
         $query = Customer::query()->with($withs)->orderByDesc('id');
+        if ($params["tags"] ?? false){
+            $query->whereHas("tags",function ($builder)use($params){
+                /** @var Builder $builder */
+                $builder->whereIn("id",explode(",",$params["tags"]));
+            });
+            unset($params["tags"]);
+        }
         $columnQueryRules=[
             'company_name' => ['like' => ''],
             'contact_man' => ['like' => ''],

+ 6 - 0
app/Services/OwnerPriceLogisticService.php

@@ -34,6 +34,12 @@ Class OwnerPriceLogisticService
         return $query->update($values);
     }
 
+    public function destroy($id)
+    {
+        OwnerPriceLogistic::destroy($id);
+        OwnerPriceLogisticDetail::query()->where("owner_price_logistic_id",$id)->delete();
+    }
+
     public function updateDetail(array $params, array $values)
     {
         $query = OwnerPriceLogisticDetail::query();

+ 57 - 0
resources/views/customer/customer/index.blade.php

@@ -28,6 +28,7 @@
                     <th>日志</th>
                     <th>合同</th>
                     <th>创建时间</th>
+                    <th>标签</th>
                     <th>操作</th>
                 </tr>
                 <tr v-for="(customer,i) in customers" :id="'model-'+customer.id">
@@ -43,9 +44,24 @@
                     <td v-if="customer.contractQuantity>0" class="cursor-pointer" @click="showContract(customer.id)"><span class="fa" :class="contractIds['_'+customer.id] === true ? 'fa-angle-double-down' : 'fa-angle-double-right'"></span>@{{ customer.contractQuantity }}份合同</td>
                     <td v-else>#</td>
                     <td>@{{ customer.created_at }}</td>
+                    <td>
+                        <div v-show="tagIndexes[i]">
+                            <select :id="'sel-'+i" class="selectpicker" multiple data-live-search="true" title="标签(多选)">
+                                <option v-for="tag in tags" :value="tag.name">@{{ tag.value }}</option>
+                            </select><br>
+                            <button class="btn btn-sm btn-success" @click="addTag(i)">确定</button>
+                            <button class="btn btn-sm btn-danger" @click="cancelTag(i)">取消</button>
+                        </div>
+                        <div v-if="!tagIndexes[i]">
+                            <span v-for="(tag,i) in customer.tags">
+                                <span class="badge badge-primary m-1" >@{{ tag.name }}</span><br v-if="(i+1)%2 === 0">
+                            </span>
+                        </div>
+                    </td>
                     <td>
                         @can("客户-编辑")
                             <button class="btn btn-sm btn-outline-success" @click="addContract(i)">新建合同</button>
+                            <button v-if="!tagIndexes[i]" class="btn btn-sm btn-info text-white" @click="setTag(i)">设定标签</button>
                             <button class="btn btn-sm btn-outline-primary" @click="relatedOwner(i)">关联项目</button>
                             <a :href="'{{url('customer/customer')}}/'+customer.id+'/edit'"><button class="btn btn-sm btn-outline-info">改</button></a>
                         @endcan
@@ -78,6 +94,12 @@
                 ],
                 ownerIds:[],
                 ownerNames:[],
+                tagIndexes : [],
+                tags:[
+                    @foreach($tags as $tag)
+                    {name:"{{$tag->id}}",value:"{{$tag->name}}"},
+                    @endforeach
+                ],
             },
             mounted(){
                 this._formatOwner();
@@ -88,6 +110,8 @@
                         {name:'company_name',type:'input',tip:'可在检索值前加百分号(%)进行模糊搜索',placeholder:'公司名称'},
                         {name:'contact_man',type:'input',tip:'可在检索值前加百分号(%)进行模糊搜索',placeholder:'联系人'},
                         {name:'phone',type:'input',tip:'可在检索值前加百分号(%)进行模糊搜索',placeholder:'联系电话'},
+                        {name:'tags',type:'select_multiple_select',tip:['输入关键词快速定位下拉列表,回车确定','选择要显示的客户'],
+                            placeholder:['标签','定位或多选标签'],data:this.tags},
                     ]
                 ];
                 new query({
@@ -96,6 +120,39 @@
                 }).init();
             },
             methods:{
+                addTag(index){
+                    let val = $("#sel-"+index).selectpicker('val');
+                    let url = "{{url('customer/customer/addTag')}}";
+                    let params = {id:this.customers[index]['id'],tags:val};
+                    window.tempTip.postBasicRequest(url,params,(res)=>{
+                        this.customers[index].tags = res;
+                        this.tagIndexes[index] = false;
+                        this.$forceUpdate();
+                        return "设定标签成功";
+                    });
+                },
+                cancelTag(index){
+                    this.tagIndexes[index] = false;
+                    this.$forceUpdate();
+                },
+                setTag(index) {
+                    this.tagIndexes[index] = true;
+                    let defaults = [];
+                    if (this.customers[index].tags){
+                        this.customers[index].tags.forEach(tag=>{
+                            defaults.push(tag.id);
+                        });
+                    }
+                    this.$forceUpdate();
+                    /*if (this.tags.length<1){
+                        window.tempTip.postBasicRequest("{{--{{url('customer/customer/customerTag/get')}}--}}",{},(res)=>{
+                            this.tags = res;
+                        });
+                    }*/
+                    //setTimeout(()=>{
+                        $(".selectpicker").selectpicker('refresh').selectpicker('val',defaults);
+                    //},500);
+                },
                 _formatOwner(){
                     let ownerIds=[];
                     let ownerNames=[];

+ 1 - 1
resources/views/customer/customer/menu.blade.php

@@ -15,7 +15,7 @@
             </li>@endcan
             @can('客户-客户标签')
             <li class="nav-item">
-                <a class="nav-link" href="{{url('customer/customer/customerTag')}}" :class="{active:isActive('customerTag',3)}">客户状态</a>
+                <a class="nav-link" href="{{url('customer/customer/customerTag')}}" :class="{active:isActive('customerTag',3)}">客户标签</a>
             </li>@endcan
             {{$slot}}
         </ul>

+ 7 - 7
resources/views/customer/customer/tag/_edit.blade.php

@@ -6,22 +6,22 @@
             </div>
             <div class="modal-body">
                 <div class="row">
-                    <label class="col-2 offset-1" for="name">名</label>
-                    <input class="col-7 form-control form-control-sm" :class="errors.name ? 'is-invalid' : ''" id="name" type="text" v-model="status.name">
+                    <label class="col-2 offset-1" for="name">标签名</label>
+                    <input class="col-7 form-control form-control-sm" :class="errors.name ? 'is-invalid' : ''" id="name" type="text" v-model="tag.name">
                     <span class="invalid-feedback mt-0 offset-3" role="alert" v-if="errors.name">
                         <strong>@{{ errors.name[0] }}</strong>
                     </span>
                 </div>
                 <div class="row mt-2">
-                    <label class="col-2 offset-1" for="description">说明</label>
-                    <textarea class="col-7 form-control form-control-sm" :class="errors.description ? 'is-invalid' : ''" id="description" type="text" v-model="status.description"></textarea>
-                    <span class="invalid-feedback mt-0 offset-3" role="alert" v-if="errors.description">
-                        <strong>@{{ errors.description[0] }}</strong>
+                    <label class="col-2 offset-1" for="explanation">说明</label>
+                    <textarea class="col-7 form-control form-control-sm" :class="errors.explanation ? 'is-invalid' : ''" id="explanation" type="text" v-model="tag.explanation"></textarea>
+                    <span class="invalid-feedback mt-0 offset-3" role="alert" v-if="errors.explanation">
+                        <strong>@{{ errors.explanation[0] }}</strong>
                     </span>
                 </div>
             </div>
             <div class="modal-footer">
-                <button type="button" class="btn btn-success" @click="submitCustomerLogStatus()">提交</button>
+                <button type="button" class="btn btn-success" @click="submitCustomerTag()">提交</button>
             </div>
         </div>
     </div>

+ 72 - 38
resources/views/customer/customer/tag/index.blade.php

@@ -8,28 +8,32 @@
     </div>
     <div class="container-fluid" id="container">
         @include("customer.customer.tag._edit")
-        <div class="row pull-right">
-            @can("客户-客户标签-录入")<button class="btn btn-outline-info mb-1 mr-3" @click="openModal()"><span class="fa fa-plus"></span>&nbsp;新&nbsp;&nbsp;增</button>@endcan
+        <div class="card">
+            <div class="card-body">
+                <div class="row pull-right">
+                    @can("客户-客户标签-录入")<button class="btn btn-outline-info mb-1 mr-3" @click="openModal()"><span class="fa fa-plus"></span>&nbsp;新&nbsp;&nbsp;增</button>@endcan
+                </div>
+                <table class="table table-striped table-hover">
+                    <tr>
+                        <th>序号</th>
+                        <th>标签名</th>
+                        <th>说明</th>
+                        <th>创建时间</th>
+                        <th>操作</th>
+                    </tr>
+                    <tr v-for="(tag,i) in tags">
+                        <td>@{{ i+1 }}</td>
+                        <td>@{{ tag.name }}</td>
+                        <td><div style="white-space: normal;max-width: 200px">@{{ tag.explanation }}</div></td>
+                        <td>@{{ tag.createdAt }}</td>
+                        <td>
+                            @can("客户-客户标签-编辑")<button class="btn btn-sm btn-outline-info" @click="openModal(tag)">改</button>@endcan
+                            @can("客户-客户标签-删除")<button class="btn btn-sm btn-outline-danger" @click="deleteTag(tag,i)">删</button>@endcan
+                        </td>
+                    </tr>
+                </table>
+            </div>
         </div>
-        <table class="table table-striped table-hover">
-            <tr>
-                <th>序号</th>
-                <th>标签名</th>
-                <th>说明</th>
-                <th>创建时间</th>
-                <th>操作</th>
-            </tr>
-            <tr v-for="(tag,i) in tags">
-                <td>@{{ i+1 }}</td>
-                <td>@{{ tag.name }}</td>
-                <td>@{{ tag.explanation }}</td>
-                <td>@{{ tag.createdAt }}</td>
-                <td>
-                    @can("客户-客户标签-编辑")<button class="btn btn-sm btn-outline-info" @click="openModal(tag)">改</button>@endcan
-                    @can("客户-客户标签-删除")<button class="btn btn-sm btn-outline-danger" @click="deleteModel(tag,i)">删</button>@endcan
-                </td>
-            </tr>
-        </table>
     </div>
 @stop
 
@@ -44,29 +48,59 @@
                     @endforeach
                 ],
                 tag:{},
+                errors:[],
             },
             methods:{
                 openModal(tag = null){
-                    if (model) this.tag={id:tag.id,name:tag.name,explanation:tag.explanation};
+                    if (tag) this.tag={id:tag.id,name:tag.name,explanation:tag.explanation};
                     else this.tag={id:"",name:"",explanation:""};
                     $("#modal").modal("show");
                 },
-            },
-            deleteModel(tag,index){
-                window.tempTip.setDuration(3000);
-                let url="{{url('customer/customer/customerTag')}}"+"/"+tag.id;
-                let msg="成功删除状态“"+tag.name+"”";
-                window.axios.delete(url).then(res=>{
-                    if (res.data.success){
-                        this.$delete(this.tags,index);
-                        window.tempTip.setDuration(2000);
-                        window.tempTip.showSuccess(msg);
-                        return;
-                    }
-                    window.tempTip.show(res.data.data);
-                }).catch(err=>{
-                    window.tempTip.show("网络错误:"+err);
-                });
+                submitCustomerTag(){
+                    let url="{{url('customer/customer/customerTag/save')}}";
+                    let msg=this.tag.id ? "成功修改标签“"+this.tag.name+"”"  : "成功新增标签“"+this.tag.name+"”";
+                    window.tempTip.postBasicRequest(url,this.tag,(res)=>{
+                        if(res && res.errors){
+                            this.errors = res.errors;
+                            return '';
+                        }
+                        if (this.tag.id){
+                            this.tags.some((tag)=> {
+                                if (tag.id === this.tag.id){
+                                    tag.name = this.tag.name;
+                                    tag.explanation = this.tag.explanation;
+                                    return true;
+                                }
+                            });
+                        }else this.tags.unshift({
+                            id:res.id,
+                            name:res.name,
+                            explanation:res.explanation,
+                            createdAt:res.created_at,
+                        });
+
+                        $("#modal").modal("hide");
+                        return msg;
+                    },true);
+                },
+                deleteTag(tag,index){
+                    window.tempTip.confirm("确定要删除标签“"+tag.name+"”吗",()=> {
+                        window.tempTip.setDuration(3000);
+                        let url="{{url('customer/customer/customerTag')}}"+"/"+tag.id;
+                        let msg="成功删除状态“"+tag.name+"”";
+                        window.axios.delete(url).then(res=>{
+                            if (res.data.success){
+                                this.$delete(this.tags,index);
+                                window.tempTip.setDuration(2000);
+                                window.tempTip.showSuccess(msg);
+                                return;
+                            }
+                            window.tempTip.show(res.data.data);
+                        }).catch(err=>{
+                            window.tempTip.show("网络错误:"+err);
+                        });
+                    });
+                },
             },
         });
     </script>

+ 2 - 0
routes/web.php

@@ -606,12 +606,14 @@ Route::group(['prefix'=>'customer'],function(){
         Route::post('getLogStatus', 'CustomerLogStatusController@get');
         Route::post('storeLog', 'CustomerLogController@store');
         Route::post('relatedOwner', 'CustomerBaseController@relatedOwner');
+        Route::post('addTag', 'CustomerBaseController@addTag');
         Route::group(['prefix' => 'customerLogStatus'], function () {
             Route::post('save', 'CustomerLogStatusController@save');
             Route::post('destroy', 'CustomerLogStatusController@destroy');
         });
         Route::group(['prefix' => 'customerTag'], function () {
             Route::post('save', 'CustomerTagController@save');
+            Route::post('get', 'CustomerTagController@get');
         });
         Route::resource('customerTag', 'CustomerTagController',['only' => ['index',"destroy"]]);
         Route::resource('customerLog', 'CustomerLogController', ['only' => ['index', 'show', 'create', 'store', 'update', 'edit', 'destroy']]);