Browse Source

委托管理

huangsanjia 2 years ago
parent
commit
a1b0ddaedb

+ 49 - 0
application/admin/controller/Entrust.php

@@ -80,6 +80,55 @@ class Entrust extends Backend
         }
         $this->success();
     }
+    /**
+     * 编辑
+     *
+     * @param $ids
+     * @return string
+     * @throws DbException
+     * @throws \think\Exception
+     */
+    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) && !in_array($row[$this->dataLimitField], $adminIds)) {
+            $this->error(__('You have no permission'));
+        }
+        if (false === $this->request->isPost()) {
+            $company = ['美浓','翌星','亚新','涂料','其他'];
+            $this->view->assign('row', $row);
+            $this->view->assign('company', $company);
+            return $this->view->fetch();
+        }
+        $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'));
+        }
+        $this->success();
+    }
     //提交到检测
     public function submit(){
         if (false === $this->request->isPost()) {

+ 1 - 1
application/admin/view/entrust/add.html

@@ -24,7 +24,7 @@
         <label class="control-label col-xs-12 col-sm-2">{:__('Company')}:</label>
         <div class="col-xs-12 col-sm-8">
 <!--            <input id="c-company" data-rule="required" class="form-control" name="row[company]" >-->
-            {:build_select('row[company]', ['美浓'=>'美浓', '翌星'=>'翌星', '亚欣'=>'亚欣', '涂料'=>'涂料','其他'=>'其他'], 10,['class'=>'form-control company'])}
+            {:build_select('row[company]', ['美浓'=>'美浓', '翌星'=>'翌星', '亚新'=>'亚新', '涂料'=>'涂料','其他'=>'其他'], null,['class'=>'form-control company'])}
         </div>
     </div>
     <div class="form-group">

+ 15 - 4
application/admin/view/entrust/edit.html

@@ -27,19 +27,30 @@
     <div class="form-group">
         <label class="control-label col-xs-12 col-sm-2">{:__('Company')}:</label>
         <div class="col-xs-12 col-sm-8">
-            <input id="c-company" data-rule="required" class="form-control" name="row[company]" type="number" value="{$row.company|htmlentities}">
+            <select class="form-control select" name="row[company]" >
+                {foreach name="company" item="vo"}
+                <label for="row[status]-{$key}">
+                    <option class="form-control"  value="{$vo}" {if condition="$vo eq $row.company"}selected{/if} {if condition="$vo eq '亚新'"}disabled{/if}>{$vo}</option>
+                </label>
+                {/foreach}
+            </select>
+
         </div>
     </div>
     <div class="form-group">
         <label class="control-label col-xs-12 col-sm-2">{:__('Sample_no')}:</label>
         <div class="col-xs-12 col-sm-8">
-            <input id="c-sample_no" data-rule="required" class="form-control" name="row[sample_no]" type="text" value="{$row.sample_no|htmlentities}">
+            <input id="c-sample_no" data-rule="required" class="form-control" name="row[sample_no]" type="text" value="{$row.sample_no|htmlentities}" readonly>
         </div>
     </div>
     <div class="form-group">
         <label class="control-label col-xs-12 col-sm-2">是否双样:</label>
         <div class="col-xs-12 col-sm-8">
-            {:build_select('row[is_two]', ['0'=>'否', '1'=>'是'], null,['class'=>'form-control'])}
+            {if condition="$row.is_two eq 1"}
+                {:build_select('row[is_two]', ['0'=>'否', '1'=>'是'], 1,['class'=>'form-control is_two'])}
+            {else/}
+                {:build_select('row[is_two]', ['0'=>'否', '1'=>'是'], 0,['class'=>'form-control is_two'])}
+            {/if}
         </div>
     </div>
     <div class="form-group">
@@ -57,7 +68,7 @@
     <div class="form-group">
         <label class="control-label col-xs-12 col-sm-2">{:__('Create')}:</label>
         <div class="col-xs-12 col-sm-8">
-            <input id="c-create" data-rule="required" class="form-control datetimepicker" data-date-format="YYYY-MM-DD HH:mm:ss" data-use-current="true" name="row[create]" type="text" value="{$row.create}">
+            <input id="c-create" data-rule="required" class="form-control datetimepicker" data-date-format="YYYY-MM-DD HH:mm:ss" data-use-current="true" name="row[create]" type="text" value="{$row.create}" readonly>
         </div>
     </div>
     <div class="form-group">

+ 1 - 0
public/assets/js/backend/entrust.js

@@ -175,6 +175,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
             Controller.api.bindevent();
         },
         edit: function () {
+            $('.is_two').attr('disabled','disabled');
             Controller.api.bindevent();
         },
         submit:function () {