소스 검색

● 内部设备新增和编辑的时候,取消目前工点

ChenWuJie 4 년 전
부모
커밋
9e39d20d82

+ 7 - 4
app/Http/Controllers/Admin/InnerDeviceController.php

xqd xqd
@@ -94,8 +94,10 @@ class InnerDeviceController extends BaseController
         list($model, $model_name, $pre_uri) = array($this->model, $this->model_name, $this->pre_uri);
         $options = $this->device_name->getNameSpecOptions();
         $status_options = Option::get('inner_devices', 'status');
-        $project_work_point_options = (new Project())->getTwoLevelOptions();
-        return view($this->view_path . 'create', compact('model', 'model_name','pre_uri', 'options', 'status_options', 'project_work_point_options'));
+//        $project_work_point_options = (new Project())->getTwoLevelOptions();
+        $project_options = Project::getNotOneProjectOptions();
+
+        return view($this->view_path . 'create', compact('model', 'model_name','pre_uri', 'options', 'status_options', 'project_options'));
     }
 
     public function transObject($items)
@@ -129,9 +131,10 @@ class InnerDeviceController extends BaseController
         if(empty($request->input('id')) || empty($item = $this->model->find($request->input('id')))) return back()->withErrors(['sg_error_info' => '找不到要编辑的数据']);
         $options = $this->device_name->getNameSpecOptions();
         $status_options = Option::get('inner_devices', 'status');
-        $project_work_point_options = (new Project())->getTwoLevelOptions();
+//        $project_work_point_options = (new Project())->getTwoLevelOptions();
+        $project_options = Project::getNotOneProjectOptions();
         list($model, $model_name, $pre_uri) = array($this->model, $this->model_name, $this->pre_uri);
-        return view($this->view_path . 'edit', compact('model', 'model_name', 'pre_uri', 'item', 'options', 'status_options', 'project_work_point_options'));
+        return view($this->view_path . 'edit', compact('model', 'model_name', 'pre_uri', 'item', 'options', 'status_options', 'project_options'));
     }
 
     public function update(Request $request)

+ 3 - 1
app/Models/Project.php

xqd
@@ -115,7 +115,9 @@ class Project extends BaseModel
     {
         return self::where('id', '>', 0)->get()->toArray();
     }
-
+    public static function getNotOneProjectOptions(){
+        return self::where('id','!=',1)->get();
+    }
     public function createDefaultUser()
     {
         $user_id = $this['user_id'];

+ 2 - 1
resources/views/admin/inner-devices/create.blade.php

xqd
@@ -23,7 +23,8 @@
                         @include('share.name-select-form', ['device_name_id' => '', 'options' => $options])
                         @include('share.layui-form-item', ['type' => 'input', 'name' => 'spec_name', 'label' => '规格型号', 'required' => true, 'value' => (old('data') ? old('data')['spec_id'] : '')])
                         @include('share.layui-form-item', ['type' => 'radio', 'name' => 'status', 'label' => '状态', 'selected_id' => (old('data') ? old('data')['status'] : ''), 'options' => $status_options])
-                        @include('share.project-work-point-select-form', ['project_id' => '', 'work_point_id' => '', 'options' => $project_work_point_options])
+                        @include('share.project-select-form', ['project_id' => '', 'options' => $project_options])
+                        {{--@include('share.project-work-point-select-form', ['project_id' => '', 'work_point_id' => '', 'options' => $project_work_point_options])--}}
                         @include('share.layui-form-item', ['type' => 'input', 'name' => 'number', 'label' => '固定资产编号', 'required' => true, 'value' => (old('data') ? old('data')['number'] : '')])
                         @include('share.layui-form-item', ['id' => 'sg-produce-date', 'type' => 'date', 'name' => 'produce_date', 'label' => '出厂日期', 'required' => true, 'value' => (old('data') ? old('data')['produce_date'] : '')])
                         @include('share.layui-form-item', ['type' => 'input', 'name' => 'shape', 'label' => '外形尺寸', 'required' => true, 'value' => (old('data') ? old('data')['shape'] : '')])

+ 1 - 1
resources/views/admin/inner-devices/edit.blade.php

xqd
@@ -24,7 +24,7 @@
                         @include('share.name-select-form', ['device_name_id' => $item->device_name_id,'options' => $options])
                         @include('share.layui-form-item', ['type' => 'input', 'name' => 'spec_name', 'label' => '规格型号', 'required' => true, 'value' => $item->spec_name])
                         @include('share.layui-form-item', ['type' => 'radio', 'name' => 'status', 'label' => '状态', 'selected_id' => $item->status, 'options' => $status_options])
-                        @include('share.project-work-point-select-form', ['project_id' => $item->project_id, 'work_point_id' => $item->work_point_id, 'options' => $project_work_point_options])
+                        @include('share.project-select-form', ['project_id' => $item->project_id,  'options' => $project_options])
                         @include('share.layui-form-item', ['type' => 'input', 'name' => 'number', 'label' => '固定资产编号', 'required' => true, 'value' => $item->number])
                         @include('share.layui-form-item', ['id' => 'sg-produce-date', 'type' => 'date', 'name' => 'produce_date', 'label' => '出厂日期', 'required' => true, 'value' => $item->produce_date])
                         @include('share.layui-form-item', ['type' => 'input', 'name' => 'shape', 'label' => '外形尺寸', 'required' => true, 'value' => $item->shape])

+ 62 - 0
resources/views/share/project-select-form.blade.php

xqd
@@ -0,0 +1,62 @@
+<?php
+?>
+<style type="text/css">
+
+</style>
+<div class="layui-form-item {{ $errors->has('project_id') ? 'has-error' : '' }}">
+    <label class="layui-form-label" style="padding: 0px;">在用项目</label>
+    <div class="layui-input-block">
+        <select name="project_id" lay-filter="project_id">
+            @foreach($options as $option)
+                <option value="{{$option->id}}" {{$option->id == $project_id ? 'selected' : ''}}>{{$option->name}}</option>
+            @endforeach
+        </select>
+        @if($errors->has('project_id'))
+            <span class="help-block">{{ $errors->first('project_id') }}</span>
+        @endif
+    </div>
+    @if($errors->has('project_id'))
+        <span class="help-block">{{ $errors->first('project_id') }}</span>
+    @endif
+</div>
+
+<script>
+    $(function() {
+        layui.use(['form'], function() {
+            let form = layui.form;
+            let projects = JSON.parse('{!! $options !!}');
+            let work_points = [];
+            let project_id = '{{ $project_id }}';
+            {{--let work_point_id = '{{ $work_point_id }}';--}}
+            {{--let hide_spec = '{{ isset($hide_spec) ? "yes" : "no" }}';--}}
+            // console.log(hide_spec)
+
+            // form.on('select(project_id)', function(data) {
+            //     project_id = data.value;
+            //     work_point_id = '';
+            //     updateWorkPoint()
+            // });
+
+            // updateWorkPoint();
+            //
+            // function updateWorkPoint() {
+            //     let name_index = getIndex(projects, project_id);
+            //     work_points = projects[name_index].work_points;
+            //     let options = '';
+            //     for(let i = 0; i < work_points.length; ++i) {
+            //         options += '<option value=' + work_points[i].value + (parseInt(work_points[i].value) === parseInt(work_point_id) ? ' selected' : '') + '>' + work_points[i].text + '</option>'
+            //     }
+            //     $("select[name='work_point_id']").html(options);
+            //     form.render('select');
+            // }
+
+            // function getIndex(list, id) {
+            //     id = parseInt(id);
+            //     for(var i = 0; i < list.length; ++i) {
+            //         if(list[i].value === id) return i;
+            //     }
+            //     return 0;
+            // }
+        })
+    })
+</script>