Commit aea1be8e by 宁成龙

完善客户编辑功能

parent 942bc96e
<?php
namespace App\Admin\Actions\User;
use App\Admin\Forms\User\AssignUserHandle;
use App\Admin\Forms\User\EditUserHandle;
use App\Models\Order as OrderModel;
use App\Models\User;
use Dcat\Admin\Grid;
use Dcat\Admin\Grid\BatchAction;
use Dcat\Admin\Grid\Tools\AbstractTool;
use Dcat\Admin\Widgets\Modal;
use Illuminate\Http\Request;
use Dcat\Admin\Grid\RowAction;
class UserEditAction extends AbstractTool
{
protected $action;
protected $htmlClasses = ['btn btn-primary btn-sm btn-mini'];
// 注意action的构造方法参数一定要给默认值
public function __construct($title = null, $action = 1)
{
$this->title = $title;
$this->action = $action;
}
// // 确认弹窗信息
// public function confirm()
// {
// return '您确定要已选中的文章吗?';
// }
public function render()
{
$form = EditUserHandle::make(['key'=>$this->getKey()]);
$buttonName = trans('user.labels.handle');
return Modal::make()->lg()->title($this->title)->body($form->payload(['key'=>$this->getKey()]))->onLoad
($this->getModalScript())->button('<button class="btn btn-primary">
<i class="feather icon-check-circle"></i><span class="d-none d-sm-inline" style="margin-left: 5px">' . $buttonName . '</span>
</button>');
}
protected function getModalScript()
{
return <<<JS
var key = {$this->getKey()}
$('#id').val(key);
JS;
}
public function html()
{
return parent::html(); // TODO: Change the autogenerated stub
}
// 设置请求参数
public function parameters()
{
return [
'action' => $this->action,
];
}
}
......@@ -43,7 +43,7 @@ class UserController extends AdminController
protected function detail($id)
{
$address_list = (\App\Admin\Renderable\UserAddress::make(["key" => $id])->render());
return UserDetail::make(["key" => $id])->render()->render().$address_list;
return UserDetail::make(["key" => $id])->render().$address_list;
}
/**
......
<?php
namespace App\Admin\Forms\User;
use App\Models\Cms\CmsUser;
use App\Models\Inquiry;
use App\Models\User;
use Dcat\Admin\Contracts\LazyRenderable;
use Dcat\Admin\Form\Row;
use Dcat\Admin\Traits\LazyWidget;
use Dcat\Admin\Widgets\Form;
class EditUserHandle extends Form implements LazyRenderable
{
use LazyWidget;
/**
* Handle the form request.
*
* @param array $input
*
* @return mixed
*/
public function handle(array $input)
{
try {
$id = explode(",", $input['id']);
// $userList = User::getListByIdArr($ids);
$userInfo = User::getInfoByUserId($id);
if (!$userInfo) {
throw new \Exception('客户不存在');
}
User::updateById($id, $input);
return $this
->response()
->success(trans('admin.update_succeeded'))
->refresh();
} catch (\Throwable $throwable) {
// var_dump((string)$throwable);
return $this->response()->error(trans('admin.update_failed'));
}
}
/**
* Build a form here.
*/
public function form()
{
$this->disableResetButton();
$this->hidden('id')->attribute('id', 'id')->width(4);
$this->row(function (Row $form) {
$form->width(5)->text('company_name')->required();
$form->width(5)->text('user_sn');
});
$this->row(function (Row $form) {
$form->width(5)->text('first_name')->required();
$form->width(5)->text('last_name');
});
$this->row(function (Row $form) {
$form->width(5)->text('phone')->required();
$form->width(5)->text('email');
});
$this->row(function (Row $form) {
$form->width(5)->text('reg_source')->required();
$form->width(5)->text('remark');
});
}
/**
* The data of the form.
*
* @return array
*/
public function default()
{
$userInfo = User::getInfoByUserId($this->payload['key']);
return $userInfo;
}
}
......@@ -2,6 +2,7 @@
namespace App\Admin\Renderable;
use App\Admin\Actions\User\UserEditAction;
use App\Admin\Repositories\Inquiry;
use App\Admin\Repositories\User;
use App\Models\InquiryItems;
......@@ -19,10 +20,13 @@ class UserDetail extends \Dcat\Admin\Support\LazyRenderable
// 只填充内容,不需要标题
return Show::make($id, new User(), function (Show $show) {
$show->panel()
->tools(function ($tools) {
// $tools->disableEdit();
->tools(function (Show\Tools $tools) {
$userEditAction = new UserEditAction("用户编辑");
$userEditAction->setKey($this->key);
$tools->disableEdit();
$tools->disableList();
$tools->disableDelete();
$tools->append($userEditAction);
});
$show->row(function (Show\Row $show) {
$show->width(4)->field('company_name');
......@@ -40,7 +44,7 @@ class UserDetail extends \Dcat\Admin\Support\LazyRenderable
$show->width(4)->field('reg_source')->using(admin_trans('user.options.reg_source'));
$show->width(4)->field('remark');
});
});
})->render();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment