lizhen_gitee пре 7 месеци
родитељ
комит
501f4b1e39
2 измењених фајлова са 106 додато и 1 уклоњено
  1. 96 1
      application/admin/controller/Coach.php
  2. 10 0
      public/assets/js/backend/coach.js

+ 96 - 1
application/admin/controller/Coach.php

@@ -4,6 +4,10 @@ namespace app\admin\controller;
 
 use app\common\controller\Backend;
 use think\Db;
+use Exception;
+use think\exception\DbException;
+use think\exception\PDOException;
+use think\exception\ValidateException;
 /**
  * 教练
  *
@@ -11,7 +15,7 @@ use think\Db;
  */
 class Coach extends Backend
 {
-    protected $noNeedLogin = ['vue_index','color_list','coach_set'];
+    protected $noNeedLogin = ['vue_index','color_list','coach_set','vue_add','vue_edit'];
     /**
      * Coach模型对象
      * @var \app\admin\model\Coach
@@ -108,4 +112,95 @@ class Coach extends Backend
         $this->result('',1,'设置成功','json');
     }
 
+    /**
+     * 添加
+     *
+     * @return string
+     * @throws \think\Exception
+     */
+    public function vue_add()
+    {
+        if (false === $this->request->isPost()) {
+            return $this->view->fetch('add');
+        }
+        $params = $this->request->post('row/a');
+        if (empty($params)) {
+            $this->error(__('Parameter %s can not be empty', ''));
+        }
+        $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()->validate($validate);
+            }
+            $result = $this->model->allowField(true)->save($params);
+            Db::commit();
+        } catch (ValidateException|PDOException|Exception $e) {
+        Db::rollback();
+        $this->error($e->getMessage());
+    }
+        if ($result === false) {
+            $this->error(__('No rows were inserted'));
+        }
+        $url = '/admin.php/lessonslotnew';
+        $this->success('',$url);
+    }
+
+    /**
+     * 编辑
+     *
+     * @param $ids
+     * @return string
+     * @throws DbException
+     * @throws \think\Exception
+     */
+    public function vue_edit($ids = null)
+    {
+        $row = $this->model->get($ids);
+        if (!$row) {
+            $this->error(__('No Results were found'));
+        }
+        $adminIds = $this->getDataLimitAdminIds();
+        if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) {
+            $this->error(__('You have no permission'));
+        }
+        if (false === $this->request->isPost()) {
+            $this->view->assign('row', $row);
+            return $this->view->fetch('edit');
+        }
+        $params = $this->request->post('row/a');
+        if (empty($params)) {
+            $this->error(__('Parameter %s can not be empty', ''));
+        }
+        $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()->validate($validate);
+            }
+            $result = $row->allowField(true)->save($params);
+            Db::commit();
+        } catch (ValidateException|PDOException|Exception $e) {
+        Db::rollback();
+        $this->error($e->getMessage());
+    }
+        if (false === $result) {
+            $this->error(__('No rows were updated'));
+        }
+        $url = '/admin.php/lessonslotnew';
+        $this->success('',$url);
+    }
+
 }

+ 10 - 0
public/assets/js/backend/coach.js

@@ -71,6 +71,16 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
         edit: function () {
             Controller.api.bindevent();
         },
+        vue_add: function () {
+            Form.api.bindevent($("form[role=form]"), function(data, ret){
+                window.location.href = ret.url;
+            })
+        },
+        vue_edit: function () {
+            Form.api.bindevent($("form[role=form]"), function(data, ret){
+                window.location.href = ret.url;
+            })
+        },
         api: {
             bindevent: function () {
                 Form.api.bindevent($("form[role=form]"));