feature: kpi
This commit is contained in:
parent
0801237869
commit
3dfbbe52e0
|
|
@ -26,6 +26,14 @@ class Item extends Backend
|
|||
$this->view->assign("unitList", $this->model->getUnitList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 下拉搜索
|
||||
*/
|
||||
public function selectpage()
|
||||
{
|
||||
return parent::selectpage();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -3,6 +3,10 @@
|
|||
namespace app\admin\controller\kpi;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
use Exception;
|
||||
use PDOException;
|
||||
use think\Db;
|
||||
use think\exception\ValidateException;
|
||||
|
||||
/**
|
||||
* kpi模板
|
||||
|
|
@ -33,5 +37,69 @@ class Template extends Backend
|
|||
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
|
||||
*/
|
||||
|
||||
/**
|
||||
* 添加
|
||||
*
|
||||
* @return string
|
||||
* @throws \think\Exception
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
if (false === $this->request->isPost()) {
|
||||
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);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
$params['create_time'] = date('Y-m-d H:i:s');
|
||||
$params['update_time'] = date('Y-m-d H:i:s');
|
||||
|
||||
|
||||
$result = $this->model->allowField(true)->save($params);
|
||||
|
||||
$templateId = $result;
|
||||
|
||||
$templateItem = [];
|
||||
$kpiItems = json_decode($params['kpiitem'], true);
|
||||
|
||||
foreach ($kpiItems as $kpiItem) {
|
||||
$templateItem[] = [
|
||||
'admin_id' => $this->auth->id,
|
||||
'template_id' => $templateId,
|
||||
'item_id' => $kpiItem['id'],
|
||||
'rate' => $kpiItem['rate'],
|
||||
];
|
||||
}
|
||||
|
||||
Db::name('kpi_template_item')
|
||||
->insert($templateItem);
|
||||
|
||||
Db::commit();
|
||||
} catch (ValidateException|PDOException|Exception $e) {
|
||||
Db::rollback();
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
if ($result === false) {
|
||||
$this->error(__('No rows were inserted'));
|
||||
}
|
||||
$this->success();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,6 +24,34 @@
|
|||
<input id="c-update_time" class="form-control datetimepicker" data-date-format="YYYY-MM-DD HH:mm:ss" data-use-current="true" name="row[update_time]" type="text" value="{:date('Y-m-d H:i:s')}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
<div class="col-xs-12">
|
||||
<table class="table fieldlist" data-template="kpiitemtpl" data-name="row[kpiitem]" id="second-table">
|
||||
<tr>
|
||||
<td>{:__('指标')}</td>
|
||||
<td>{:__('比例')}</td>
|
||||
<td width="100"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="4"><a href="javascript:;" class="btn btn-sm btn-success btn-append"><i class="fa fa-plus"></i> {:__('Append')}</a></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<!--请注意实际开发中textarea应该添加个hidden进行隐藏-->
|
||||
<textarea name="row[kpiitem]" class="form-control" cols="30" rows="5">[{"id":"1","rate":"20"}]</textarea>
|
||||
<script id="kpiitemtpl" type="text/html">
|
||||
<tr class="form-inline">
|
||||
<td><input type="text" name="<%=name%>[<%=index%>][id]" class="form-control selectpage" data-source="kpi/item/selectpage" data-field="name" value="<%=row.id%>" placeholder="指标"/></td>
|
||||
<td><input type="text" name="<%=name%>[<%=index%>][rate]" class="form-control" value="<%=row['rate']%>" size="30"></td>
|
||||
<td>
|
||||
<!--下面的两个按钮务必保留-->
|
||||
<span class="btn btn-sm btn-danger btn-remove"><i class="fa fa-times"></i></span>
|
||||
<span class="btn btn-sm btn-primary btn-dragsort"><i class="fa fa-arrows"></i></span>
|
||||
</td>
|
||||
</tr>
|
||||
</script>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group layer-footer">
|
||||
<label class="control-label col-xs-12 col-sm-2"></label>
|
||||
<div class="col-xs-12 col-sm-8">
|
||||
|
|
|
|||
|
|
@ -40,6 +40,10 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
|
|||
Table.api.bindevent(table);
|
||||
},
|
||||
add: function () {
|
||||
$(document).on("fa.event.appendfieldlist", "#second-table .btn-append", function (e, obj) {
|
||||
//绑定动态下拉组件
|
||||
Form.events.selectpage(obj);
|
||||
});
|
||||
Controller.api.bindevent();
|
||||
},
|
||||
edit: function () {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user