This commit is contained in:
xman 2025-04-01 17:19:25 +08:00
parent c5db908603
commit d037ec193d
11 changed files with 535 additions and 2 deletions

View File

@ -81,6 +81,8 @@ class Dispatch2 extends Backend
$row->btn_abnormal = (in_array($row->status, $this->model->btnActiveStatusList('btn_abnormal'))) ? true : false;
$row->btn_finished = (in_array($row->status, $this->model->btnActiveStatusList('btn_finished'))) ? true : false;
$row->is_disabled = (in_array($row->status, $this->model->btnActiveStatusList('disabled_status'))) ? true : false;
$row->btn_record = (in_array($row->status, $this->model->btnActiveStatusList('btn_record'))) ? true : false;
// $row->btn_income = (in_array($row->status, $this->model->btnActiveStatusList('btn_income')) && in_array($row->order->status, $orderModel->incomeBtnStatus())) ? true : false;
}
$result = array("total" => $list->total(), "rows" => $list->items());

View File

@ -0,0 +1,145 @@
<?php
namespace app\admin\controller\orders;
use app\common\controller\Backend;
use think\Db;
use think\Exception;
use think\exception\DbException;
use think\exception\PDOException;
use think\exception\ValidateException;
/**
* 任务记录
*
* @icon fa fa-circle-o
*/
class Dispatchrecord extends Backend
{
/**
* OrderDispatchRecord模型对象
* @var \app\admin\model\OrderDispatchRecord
*/
protected $model = null;
public function _initialize()
{
parent::_initialize();
$this->model = new \app\admin\model\OrderDispatchRecord;
$this->view->assign("needNoticeList", $this->model->getNeedNoticeList());
$this->view->assign("statusList", $this->model->getStatusList());
}
/**
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
*/
/**
* 添加
*
* @return string
* @throws \think\Exception
*/
public function add()
{
if (false === $this->request->isPost()) {
$dispatch_id = $this->request->get('dispatch_id');
$list = $this->model->where('dispatch_id',$dispatch_id)->order('id','desc')->select();
$this->assign('dispatch_id',$dispatch_id);
$this->assign('records',$list);
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['admin_id'] = $this->auth->id;
$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'));
}
$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()) {
$this->view->assign('row', $row);
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();
}
}

View File

@ -0,0 +1,19 @@
<?php
return [
'Dispatch_id' => '任务ID',
'Worker_id' => '师傅ID',
'Remark' => '备注',
'Need_notice' => '提醒师傅',
'Need_notice 0' => '不需要',
'Need_notice 1' => '需要',
'Status' => '通知状态',
'Status 0' => '未通知',
'Set status to 0'=> '设为未通知',
'Status 1' => '已通知',
'Set status to 1'=> '设为已通知',
'Notice_time' => '通知时间',
'Create_time' => '创建时间',
'Update_time' => '更新时间',
'Admin_id' => '管理员ID'
];

View File

@ -152,7 +152,14 @@ class OrderDispatch extends Model
self::STATUS_CANCEL,
self::STATUS_REFUSED,
self::STATUS_MOVE
]
],
'btn_record' => [
self::STATUS_TOGET,
self::STATUS_GOTIT,
self::STATUS_PLANIT,
self::STATUS_OVERTIME,
self::STATUS_CLOCK,
],
];
return $btns[$btn]??[];

View File

@ -0,0 +1,64 @@
<?php
namespace app\admin\model;
use think\Model;
class OrderDispatchRecord extends Model
{
// 表名
protected $name = 'order_dispatch_record';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'datetime';
protected $dateFormat = 'Y-m-d H:i:s';
// 定义时间戳字段名
protected $createTime = 'create_time';
protected $updateTime = 'update_time';
protected $deleteTime = false;
// 追加属性
protected $append = [
'need_notice_text',
'status_text'
];
public function getNeedNoticeList()
{
return ['0' => __('Need_notice 0'), '1' => __('Need_notice 1')];
}
public function getStatusList()
{
return ['0' => __('Status 0'), '1' => __('Status 1')];
}
public function getNeedNoticeTextAttr($value, $data)
{
$value = $value ?: ($data['need_notice'] ?? '');
$list = $this->getNeedNoticeList();
return $list[$value] ?? '';
}
public function getStatusTextAttr($value, $data)
{
$value = $value ?: ($data['status'] ?? '');
$list = $this->getStatusList();
return $list[$value] ?? '';
}
}

View File

@ -0,0 +1,27 @@
<?php
namespace app\admin\validate;
use think\Validate;
class OrderDispatchRecord extends Validate
{
/**
* 验证规则
*/
protected $rule = [
];
/**
* 提示消息
*/
protected $message = [
];
/**
* 验证场景
*/
protected $scene = [
'add' => [],
'edit' => [],
];
}

View File

@ -0,0 +1,76 @@
<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action=""
xmlns="http://www.w3.org/1999/html">
{notempty name='records'}
<div class="col-xs-12 col-sm-6">
{/notempty}
<input type="hidden" name="row[dispatch_id]" type="text" value="$dispatch.id">
<input type="hidden" name="row[worker_id]" type="text" value="$dispatch.worker_id">
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Remark')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-remark" data-rule="required" class="form-control" name="row[remark]" type="text">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Need_notice')}:</label>
<div class="col-xs-12 col-sm-8">
<select id="c-need_notice" data-rule="required" class="form-control selectpicker" name="row[need_notice]">
{foreach name="needNoticeList" item="vo"}
<option value="{$key}" {in name="key" value="0"}selected{/in}>{$vo}</option>
{/foreach}
</select>
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Notice_time')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-notice_time" class="form-control datetimepicker" data-date-format="YYYY-MM-DD HH:mm:ss" data-use-current="true" name="row[notice_time]" type="text" value="{:date('Y-m-d H:i:s')}">
</div>
</div>
{notempty name='records'}
</div>
{/notempty}
{notempty name='records'}
<div class="col-xs-12 col-sm-6">
<table>
<thead>
<tr>
<th>ID</th>
<th>备忘内容</th>
<th>通知</th>
<th>状态</th>
<th>时间</th>
</tr>
</thead>
<tbody>
{volist name="records" id="item"}
{$item.name} - {$item.age}
<tr>
<td>{$item.id}</td>
<td>{$item.remark}</td>
<td>{$item.need_notice_text}</td>
<td>{$item.status_text}</td>
<td>{$item.create_time}</td>
</tr>
{/volist}
</tbody>
</table>
</div>
{/notempty}
<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">
<button type="submit" class="btn btn-primary btn-embossed disabled">{:__('OK')}</button>
</div>
</div>
</form>

View File

@ -0,0 +1,69 @@
<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">{:__('Dispatch_id')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-dispatch_id" data-rule="required" data-source="dispatch/index" class="form-control selectpage" name="row[dispatch_id]" type="text" value="{$row.dispatch_id|htmlentities}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Worker_id')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-worker_id" data-rule="required" data-source="worker/index" class="form-control selectpage" name="row[worker_id]" type="text" value="{$row.worker_id|htmlentities}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Remark')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-remark" data-rule="required" class="form-control" name="row[remark]" type="text" value="{$row.remark|htmlentities}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Need_notice')}:</label>
<div class="col-xs-12 col-sm-8">
<select id="c-need_notice" data-rule="required" class="form-control selectpicker" name="row[need_notice]">
{foreach name="needNoticeList" item="vo"}
<option value="{$key}" {in name="key" value="$row.need_notice"}selected{/in}>{$vo}</option>
{/foreach}
</select>
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Status')}:</label>
<div class="col-xs-12 col-sm-8">
<div class="radio">
{foreach name="statusList" item="vo"}
<label for="row[status]-{$key}"><input id="row[status]-{$key}" name="row[status]" type="radio" value="{$key}" {in name="key" value="$row.status"}checked{/in} /> {$vo}</label>
{/foreach}
</div>
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Notice_time')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-notice_time" class="form-control datetimepicker" data-date-format="YYYY-MM-DD HH:mm:ss" data-use-current="true" name="row[notice_time]" type="text" value="{$row.notice_time}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Create_time')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-create_time" class="form-control datetimepicker" data-date-format="YYYY-MM-DD HH:mm:ss" data-use-current="true" name="row[create_time]" type="text" value="{$row.create_time}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Update_time')}:</label>
<div class="col-xs-12 col-sm-8">
<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="{$row.update_time}">
</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">
<button type="submit" class="btn btn-primary btn-embossed disabled">{:__('OK')}</button>
</div>
</div>
</form>

View File

@ -0,0 +1,46 @@
<div class="panel panel-default panel-intro">
<div class="panel-heading">
{:build_heading(null,FALSE)}
<ul class="nav nav-tabs" data-field="status">
<li class="{:$Think.get.status === null ? 'active' : ''}"><a href="#t-all" data-value="" data-toggle="tab">{:__('All')}</a></li>
{foreach name="statusList" item="vo"}
<li class="{:$Think.get.status === (string)$key ? 'active' : ''}"><a href="#t-{$key}" data-value="{$key}" data-toggle="tab">{$vo}</a></li>
{/foreach}
</ul>
</div>
<div class="panel-body">
<div id="myTabContent" class="tab-content">
<div class="tab-pane fade active in" id="one">
<div class="widget-body no-padding">
<div id="toolbar" class="toolbar">
<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('orders/dispatchrecord/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('orders/dispatchrecord/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('orders/dispatchrecord/del')?'':'hide'}" title="{:__('Delete')}" ><i class="fa fa-trash"></i> {:__('Delete')}</a>
<div class="dropdown btn-group {:$auth->check('orders/dispatchrecord/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">
{foreach name="statusList" item="vo"}
<li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:" data-params="status={$key}">{:__('Set status to ' . $key)}</a></li>
{/foreach}
</ul>
</div>
</div>
<table id="table" class="table table-striped table-bordered table-hover table-nowrap"
data-operate-edit="{:$auth->check('orders/dispatchrecord/edit')}"
data-operate-del="{:$auth->check('orders/dispatchrecord/del')}"
width="100%">
</table>
</div>
</div>
</div>
</div>
</div>

View File

@ -111,7 +111,9 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form','layer'], function ($,
text:"完成",
title:"完成",
icon: 'fa fa-check',
url: 'orders/dispatch2/finish',
url: function(row){
return 'orders/dispatch2/finish?dispatch_id='+row.id;
},
extend: 'data-toggle="tooltip" data-container="body"',
classname: 'btn btn-xs btn-success btn-dialog',
visible:function(row){
@ -121,6 +123,21 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form','layer'], function ($,
return false;
}
},
{
name: 'add-record',
text:"备忘",
title:"备忘",
icon: 'fa fa-record',
url: 'orders/dispatchrecord/add',
extend: 'data-toggle="tooltip" data-container="body"',
classname: 'btn btn-xs btn-warning btn-dialog',
visible:function(row){
if(row.btn_record){
return true;
}
return false;
}
},
],
}

View File

@ -0,0 +1,61 @@
define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
var Controller = {
index: function () {
// 初始化表格参数配置
Table.api.init({
extend: {
index_url: 'orders/dispatchrecord/index' + location.search,
// add_url: 'orders/dispatchrecord/add',
edit_url: 'orders/dispatchrecord/edit',
del_url: 'orders/dispatchrecord/del',
multi_url: 'orders/dispatchrecord/multi',
import_url: 'orders/dispatchrecord/import',
table: 'order_dispatch_record',
}
});
var table = $("#table");
// 初始化表格
table.bootstrapTable({
url: $.fn.bootstrapTable.defaults.extend.index_url,
pk: 'id',
sortName: 'id',
fixedColumns: true,
fixedRightNumber: 1,
columns: [
[
{checkbox: true},
{field: 'id', title: __('Id')},
{field: 'dispatch_id', title: __('Dispatch_id')},
{field: 'worker_id', title: __('Worker_id')},
{field: 'remark', title: __('Remark'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
{field: 'need_notice', title: __('Need_notice'), searchList: {"0":__('Need_notice 0'),"1":__('Need_notice 1')}, formatter: Table.api.formatter.normal},
{field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1')}, formatter: Table.api.formatter.status},
{field: 'notice_time', title: __('Notice_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
{field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
{field: 'update_time', title: __('Update_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
{field: 'admin_id', title: __('Admin_id')},
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
]
]
});
// 为表格绑定事件
Table.api.bindevent(table);
},
add: function () {
Controller.api.bindevent();
},
edit: function () {
Controller.api.bindevent();
},
api: {
bindevent: function () {
Form.api.bindevent($("form[role=form]"));
}
}
};
return Controller;
});