chenhao 4 лет назад
Родитель
Сommit
c4db572a2c

+ 104 - 0
application/admin/controller/Protableinfo.php

@@ -3,6 +3,9 @@
 namespace app\admin\controller;
 
 use app\common\controller\Backend;
+use think\Db;
+use think\exception\PDOException;
+use think\exception\ValidateException;
 
 /**
  * 报修详情
@@ -51,10 +54,12 @@ class Protableinfo extends Backend
             if ($this->request->request('keyField')) {
                 return $this->selectpage();
             }
+            $ids = $this->request->param('ids');
             list($where, $sort, $order, $offset, $limit) = $this->buildparams();
 
             $list = $this->model
                     ->with(['protable'])
+                    ->where('p_id',1)
                     ->where($where)
                     ->order($sort, $order)
                     ->paginate($limit);
@@ -68,7 +73,106 @@ class Protableinfo extends Backend
 
             return json($result);
         }
+        $ids = $this->request->param('ids');
+        $this->assignconfig('ids',$ids);
         return $this->view->fetch();
     }
+    /**
+     * 添加
+     */
+    public function add()
+    {
+        if ($this->request->isPost()) {
+            $params = $this->request->post("row/a");
+            if ($params) {
+                $params = $this->preExcludeFields($params);
 
+                if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
+                    $params[$this->dataLimitField] = $this->auth->id;
+                }
+                $result = false;
+                Db::startTrans();
+                try {
+                    //是否采用模型验证
+                    if ($this->modelValidate) {
+                        $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
+                        $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate;
+                        $this->model->validateFailException(true)->validate($validate);
+                    }
+                    $result = $this->model->allowField(true)->save($params);
+                    Db::commit();
+                } catch (ValidateException $e) {
+                    Db::rollback();
+                    $this->error($e->getMessage());
+                } catch (PDOException $e) {
+                    Db::rollback();
+                    $this->error($e->getMessage());
+                } catch (Exception $e) {
+                    Db::rollback();
+                    $this->error($e->getMessage());
+                }
+                if ($result !== false) {
+                    $this->success();
+                } else {
+                    $this->error(__('No rows were inserted'));
+                }
+            }
+            $this->error(__('Parameter %s can not be empty', ''));
+        }
+        $ids = $this->request->param('ids');
+        $this->assign('ids',$ids);
+        return $this->view->fetch();
+    }
+
+    /**
+     * 编辑
+     */
+    public function edit($ids = null)
+    {
+        $row = $this->model->get($ids);
+        if (!$row) {
+            $this->error(__('No Results were found'));
+        }
+        $adminIds = $this->getDataLimitAdminIds();
+        if (is_array($adminIds)) {
+            if (!in_array($row[$this->dataLimitField], $adminIds)) {
+                $this->error(__('You have no permission'));
+            }
+        }
+        if ($this->request->isPost()) {
+            $params = $this->request->post("row/a");
+            if ($params) {
+                $params = $this->preExcludeFields($params);
+                $result = false;
+                Db::startTrans();
+                try {
+                    //是否采用模型验证
+                    if ($this->modelValidate) {
+                        $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
+                        $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
+                        $row->validateFailException(true)->validate($validate);
+                    }
+                    $result = $row->allowField(true)->save($params);
+                    Db::commit();
+                } catch (ValidateException $e) {
+                    Db::rollback();
+                    $this->error($e->getMessage());
+                } catch (PDOException $e) {
+                    Db::rollback();
+                    $this->error($e->getMessage());
+                } catch (Exception $e) {
+                    Db::rollback();
+                    $this->error($e->getMessage());
+                }
+                if ($result !== false) {
+                    $this->success();
+                } else {
+                    $this->error(__('No rows were updated'));
+                }
+            }
+            $this->error(__('Parameter %s can not be empty', ''));
+        }
+        $this->view->assign("row", $row);
+        return $this->view->fetch();
+    }
 }

+ 12 - 12
application/admin/view/protableinfo/add.html

@@ -1,11 +1,11 @@
 <form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
 
-    <div class="form-group">
-        <label class="control-label col-xs-12 col-sm-2">{:__('P_id')}:</label>
-        <div class="col-xs-12 col-sm-8">
-            <input id="c-p_id" data-rule="required" data-source="p/index" class="form-control selectpage" name="row[p_id]" type="text" value="">
-        </div>
-    </div>
+<!--    <div class="form-group">-->
+<!--        <label class="control-label col-xs-12 col-sm-2">{:__('P_id')}:</label>-->
+<!--        <div class="col-xs-12 col-sm-8">-->
+            <input id="c-p_id" data-rule="required"  name="row[p_id]" type="hidden" value="{$ids}">
+<!--        </div>-->
+<!--    </div>-->
     <div class="form-group">
         <label class="control-label col-xs-12 col-sm-2">{:__('Image')}:</label>
         <div class="col-xs-12 col-sm-8">
@@ -32,12 +32,12 @@
             <input id="c-mobile" class="form-control" name="row[mobile]" type="text">
         </div>
     </div>
-    <div class="form-group">
-        <label class="control-label col-xs-12 col-sm-2">{:__('Switch')}:</label>
-        <div class="col-xs-12 col-sm-8">
-            <input id="c-switch" class="form-control" name="row[switch]" type="number">
-        </div>
-    </div>
+<!--    <div class="form-group">-->
+<!--        <label class="control-label col-xs-12 col-sm-2">{:__('Switch')}:</label>-->
+<!--        <div class="col-xs-12 col-sm-8">-->
+            <input id="c-switch" class="form-control" name="row[switch]" type="hidden" value="1">
+<!--        </div>-->
+<!--    </div>-->
     <div class="form-group">
         <label class="control-label col-xs-12 col-sm-2">{:__('Sort')}:</label>
         <div class="col-xs-12 col-sm-8">

+ 0 - 12
application/admin/view/protableinfo/edit.html

@@ -1,12 +1,6 @@
 <form id="edit-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
 
     <div class="form-group">
-        <label class="control-label col-xs-12 col-sm-2">{:__('P_id')}:</label>
-        <div class="col-xs-12 col-sm-8">
-            <input id="c-p_id" data-rule="required" data-source="p/index" class="form-control selectpage" name="row[p_id]" type="text" value="{$row.p_id|htmlentities}">
-        </div>
-    </div>
-    <div class="form-group">
         <label class="control-label col-xs-12 col-sm-2">{:__('Image')}:</label>
         <div class="col-xs-12 col-sm-8">
             <div class="input-group">
@@ -33,12 +27,6 @@
         </div>
     </div>
     <div class="form-group">
-        <label class="control-label col-xs-12 col-sm-2">{:__('Switch')}:</label>
-        <div class="col-xs-12 col-sm-8">
-            <input id="c-switch" class="form-control" name="row[switch]" type="number" value="{$row.switch|htmlentities}">
-        </div>
-    </div>
-    <div class="form-group">
         <label class="control-label col-xs-12 col-sm-2">{:__('Sort')}:</label>
         <div class="col-xs-12 col-sm-8">
             <input id="c-sort" class="form-control" name="row[sort]" type="number" value="{$row.sort|htmlentities}">

+ 9 - 9
application/admin/view/protableinfo/index.html

@@ -9,16 +9,16 @@
                         <a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}" ><i class="fa fa-refresh"></i> </a>
                         <a href="javascript:;" class="btn btn-success btn-add {:$auth->check('protableinfo/add')?'':'hide'}" title="{:__('Add')}" ><i class="fa fa-plus"></i> {:__('Add')}</a>
                         <a href="javascript:;" class="btn btn-success btn-edit btn-disabled disabled {:$auth->check('protableinfo/edit')?'':'hide'}" title="{:__('Edit')}" ><i class="fa fa-pencil"></i> {:__('Edit')}</a>
-                        <a href="javascript:;" class="btn btn-danger btn-del btn-disabled disabled {:$auth->check('protableinfo/del')?'':'hide'}" title="{:__('Delete')}" ><i class="fa fa-trash"></i> {:__('Delete')}</a>
-                        <a href="javascript:;" class="btn btn-danger btn-import {:$auth->check('protableinfo/import')?'':'hide'}" title="{:__('Import')}" id="btn-import-file" data-url="ajax/upload" data-mimetype="csv,xls,xlsx" data-multiple="false"><i class="fa fa-upload"></i> {:__('Import')}</a>
+<!--                        <a href="javascript:;" class="btn btn-danger btn-del btn-disabled disabled {:$auth->check('protableinfo/del')?'':'hide'}" title="{:__('Delete')}" ><i class="fa fa-trash"></i> {:__('Delete')}</a>-->
+<!--                        <a href="javascript:;" class="btn btn-danger btn-import {:$auth->check('protableinfo/import')?'':'hide'}" title="{:__('Import')}" id="btn-import-file" data-url="ajax/upload" data-mimetype="csv,xls,xlsx" data-multiple="false"><i class="fa fa-upload"></i> {:__('Import')}</a>-->
 
-                        <div class="dropdown btn-group {:$auth->check('protableinfo/multi')?'':'hide'}">
-                            <a class="btn btn-primary btn-more dropdown-toggle btn-disabled disabled" data-toggle="dropdown"><i class="fa fa-cog"></i> {:__('More')}</a>
-                            <ul class="dropdown-menu text-left" role="menu">
-                                <li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:;" data-params="status=normal"><i class="fa fa-eye"></i> {:__('Set to normal')}</a></li>
-                                <li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:;" data-params="status=hidden"><i class="fa fa-eye-slash"></i> {:__('Set to hidden')}</a></li>
-                            </ul>
-                        </div>
+<!--                        <div class="dropdown btn-group {:$auth->check('protableinfo/multi')?'':'hide'}">-->
+<!--                            <a class="btn btn-primary btn-more dropdown-toggle btn-disabled disabled" data-toggle="dropdown"><i class="fa fa-cog"></i> {:__('More')}</a>-->
+<!--                            <ul class="dropdown-menu text-left" role="menu">-->
+<!--                                <li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:;" data-params="status=normal"><i class="fa fa-eye"></i> {:__('Set to normal')}</a></li>-->
+<!--                                <li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:;" data-params="status=hidden"><i class="fa fa-eye-slash"></i> {:__('Set to hidden')}</a></li>-->
+<!--                            </ul>-->
+<!--                        </div>-->
 
                         
                     </div>

+ 7 - 15
application/api/controller/Policy.php

@@ -32,11 +32,9 @@ class Policy extends Api
         foreach ($data as &$v) {
             $v['image'] = config('site.httpurl') . $v['image'];
         }
-        if ($data) {
-            return $this->success('', $data);
-        } else {
-            return $this->error('暂无数据');
-        }
+
+        return $this->success('', $data);
+
     }
     /**
      * 政策分类
@@ -79,11 +77,8 @@ class Policy extends Api
             ->limit($pages)
             ->select();
 
-        if ($data) {
-            return $this->success('', $data);
-        } else {
-            return $this->error('暂无数据');
-        }
+        return $this->success('', $data);
+
     }
 
     /**
@@ -105,11 +100,8 @@ class Policy extends Api
             ->order('sort desc')
             ->find();
 
-        if ($data) {
-            return $this->success('', $data);
-        } else {
-            return $this->error('暂无数据');
-        }
+
+        return $this->success('', $data);
     }
 
     /**

+ 4 - 22
public/assets/js/backend/protable/lists.js

@@ -46,12 +46,12 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                             events: Table.api.events.operate,
                             buttons: [
                                 {
-                                    name: 'detail',
-                                    text: __('弹出窗口打开'),
+                                    name: '详情',
+                                    text: __('详情'),
                                     title: __('弹出窗口打开'),
                                     classname: 'btn btn-xs btn-primary btn-dialog',
                                     icon: 'fa fa-list',
-                                    url: 'example/bootstraptable/detail',
+                                    url: 'protableinfo/index',
                                     callback: function (data) {
                                         Layer.alert("接收到回传数据:" + JSON.stringify(data), {title: "回传数据"});
                                     },
@@ -60,25 +60,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                                         return true;
                                     }
                                 },
-                                {
-                                    name: 'ajax',
-                                    text: __('发送Ajax'),
-                                    title: __('发送Ajax'),
-                                    classname: 'btn btn-xs btn-success btn-magic btn-ajax',
-                                    icon: 'fa fa-magic',
-                                    url: 'example/bootstraptable/detail',
-                                    confirm: '确认发送',
-                                    success: function (data, ret) {
-                                        Layer.alert(ret.msg + ",返回数据:" + JSON.stringify(data));
-                                        //如果需要阻止成功提示,则必须使用return false;
-                                        //return false;
-                                    },
-                                    error: function (data, ret) {
-                                        console.log(data, ret);
-                                        Layer.alert(ret.msg);
-                                        return false;
-                                    }
-                                },
+
                             ],
                             formatter: Table.api.formatter.buttons
                         },

+ 10 - 5
public/assets/js/backend/protableinfo.js

@@ -5,8 +5,8 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
             // 初始化表格参数配置
             Table.api.init({
                 extend: {
-                    index_url: 'protableinfo/index' + location.search,
-                    add_url: 'protableinfo/add',
+                    index_url: 'protableinfo/index/ids/'+ Config.ids + location.search,
+                    add_url: 'protableinfo/add/ids/'+Config.ids,
                     edit_url: 'protableinfo/edit',
                     del_url: 'protableinfo/del',
                     multi_url: 'protableinfo/multi',
@@ -22,18 +22,23 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                 url: $.fn.bootstrapTable.defaults.extend.index_url,
                 pk: 'id',
                 sortName: 'id',
+                commonSearch:false,
+                showExport:false,
+                search:false,
                 columns: [
                     [
                         {checkbox: true},
-                        {field: 'id', title: __('Id')},
-                        {field: 'p_id', title: __('P_id')},
+                        {field:'id', title: __('序号'),formatter: function(value, row, index){
+                                return ++index;
+                            }, operate: false},
+                        {field: 'protable.name', title: __('所属项目')},
                         {field: 'image', title: __('Image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                         {field: 'title', title: __('Title'), operate: 'LIKE'},
                         {field: 'mobile', title: __('Mobile')},
                         {field: 'switch', title: __('Switch'), table: table, formatter: Table.api.formatter.toggle},
                         {field: 'sort', title: __('Sort')},
                         {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
-                        {field: 'protable.name', title: __('Protable.name')},
+
                         {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                     ]
                 ]