From 2d3a85ca8c03fe798e175e3b7af1ae5a78662019 Mon Sep 17 00:00:00 2001 From: zhuyu Date: Sun, 11 May 2025 21:57:03 +0800 Subject: [PATCH] feature: schedule --- addons/editable/bootstrap.js | 7 ++- application/admin/controller/oa/Schedule.php | 52 +++++++++++++++++++- application/admin/lang/zh-cn/oa/schedule.php | 1 + application/admin/model/oa/Schedule.php | 2 +- public/assets/js/addons.js | 7 ++- public/assets/js/backend/oa/schedule.js | 10 +++- 6 files changed, 72 insertions(+), 7 deletions(-) diff --git a/addons/editable/bootstrap.js b/addons/editable/bootstrap.js index 6a88649..2942c43 100644 --- a/addons/editable/bootstrap.js +++ b/addons/editable/bootstrap.js @@ -16,9 +16,12 @@ if ($("table.table").length > 0) { require(['editable', 'table'], function (Editable, Table) { $.fn.bootstrapTable.defaults.onEditableSave = function (field, row, oldValue, $el) { var data = {}; - data["row[" + field + "]"] = row[field]; + data["row[field]"] = field; + for(var i in row){ + data["row[" + i + "]"] = row[i]; + } Fast.api.ajax({ - url: this.extend.edit_url + "/ids/" + row[this.pk], + url: this.extend.editable + "/idsssssssssss/" + row[this.pk], data: data }); }; diff --git a/application/admin/controller/oa/Schedule.php b/application/admin/controller/oa/Schedule.php index 6f1bce8..63f7a57 100644 --- a/application/admin/controller/oa/Schedule.php +++ b/application/admin/controller/oa/Schedule.php @@ -109,6 +109,7 @@ class Schedule extends Backend foreach ($adminIds as $adminId) { $res[$adminId][$tmpDate] = '无'; + $res[$adminId]['admin_id'] = $adminId; $res[$adminId]['name'] = $adminNames[$adminId]; } @@ -251,8 +252,57 @@ class Schedule extends Backend } - public function xtablesave() + public function editable() { + + $params = $this->request->post('row/a'); + if (empty($params)) { + $this->error(__('Parameter %s can not be empty', '')); + } + + + $date = $params['field']; + $adminId = $params['admin_id']; + + $value = $params[$date] ?? '无'; + $valueMap = [ + '无' => 0, + '早班' => 1, + '中班' => 2, + '晚班' => 3, + '行政班' => 4, + ]; + + if ($value == '无') { + $this->model->where('exec_admin_id', $adminId)->delete(); + $this->success(); + } + + $dbValue = $valueMap[$value]; + + $data = $this->model + ->where('date', '=', $date) + ->where('exec_admin_id', '=', $adminId) + ->find(); + + $nowTime = date('Y-m-d H:i:s'); + if (!empty($data)) { + $data->save([ + "date" => $date, + "exec_admin_id" => $adminId, + "type" => $dbValue, + "update_time" => $nowTime, + ]); + } + + $this->model->insert([ + "date" => $date, + "exec_admin_id" => $adminId, + "type" => $dbValue, + "create_time" => $nowTime, + "update_time" => $nowTime, + ]); + $this->success(); } } diff --git a/application/admin/lang/zh-cn/oa/schedule.php b/application/admin/lang/zh-cn/oa/schedule.php index 74d25ab..d3a348b 100644 --- a/application/admin/lang/zh-cn/oa/schedule.php +++ b/application/admin/lang/zh-cn/oa/schedule.php @@ -8,6 +8,7 @@ return [ 'Type 1' => '早班', 'Type 2' => '中班', 'Type 3' => '晚班', + 'Type 4' => '行政班', 'Date' => '日期', 'Create_time' => '创建时间', 'Update_time' => '编辑时间', diff --git a/application/admin/model/oa/Schedule.php b/application/admin/model/oa/Schedule.php index e01e4fb..991b076 100644 --- a/application/admin/model/oa/Schedule.php +++ b/application/admin/model/oa/Schedule.php @@ -32,7 +32,7 @@ class Schedule extends Model public function getTypeList() { - return ['1' => __('Type 1'), '2' => __('Type 2'), '3' => __('Type 3')]; + return ['1' => __('Type 1'), '2' => __('Type 2'), '3' => __('Type 3'), '4' => __('Type 4')]; } diff --git a/public/assets/js/addons.js b/public/assets/js/addons.js index 177dd6d..9f277e3 100755 --- a/public/assets/js/addons.js +++ b/public/assets/js/addons.js @@ -330,9 +330,12 @@ if ($("table.table").length > 0) { require(['editable', 'table'], function (Editable, Table) { $.fn.bootstrapTable.defaults.onEditableSave = function (field, row, oldValue, $el) { var data = {}; - data["row[" + field + "]"] = row[field]; + data["row[field]"] = field; + for(var i in row){ + data["row[" + i + "]"] = row[i]; + } Fast.api.ajax({ - url: this.extend.edit_url + "/ids/" + row[this.pk], + url: this.extend.editable + "/idsssssssssss/" + row[this.pk], data: data }); }; diff --git a/public/assets/js/backend/oa/schedule.js b/public/assets/js/backend/oa/schedule.js index 0889440..04dd289 100644 --- a/public/assets/js/backend/oa/schedule.js +++ b/public/assets/js/backend/oa/schedule.js @@ -45,7 +45,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'editable'], function extend: { index_url: 'oa/schedule/custom_index' + location.search, // add_url: 'oa/schedule/add', - // edit_url: 'oa/schedule/edit', + editable: 'oa/schedule/editable', // del_url: 'oa/schedule/del', // multi_url: 'oa/schedule/multi', // import_url: 'oa/schedule/import', @@ -59,6 +59,10 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'editable'], function defaultColumnArr.push({ "title":"用户名", "field":"name", + },{ + "title":"用户id", + "field":"admin_id", + "visible":false }); const startDate = new Date(new Date().setDate(1)); @@ -107,6 +111,10 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'editable'], function changeColumn = [{ "title":"用户名", "field":"name", + },{ + "title":"用户id", + "field":"admin_id", + "visible":false }]; const today = new Date();