Commit 693664e7 by 宁成龙

完善客户地址删除

parent 96cc3845
...@@ -26,12 +26,6 @@ class UserEditAction extends AbstractTool ...@@ -26,12 +26,6 @@ class UserEditAction extends AbstractTool
$this->action = $action; $this->action = $action;
} }
// // 确认弹窗信息
// public function confirm()
// {
// return '您确定要已选中的文章吗?';
// }
public function render() public function render()
{ {
$form = EditUserHandle::make(['key'=>$this->getKey()]); $form = EditUserHandle::make(['key'=>$this->getKey()]);
......
<?php
namespace App\Admin\Actions\UserAddress;
use App\Admin\Service\UserService;
use App\Models\Order as OrderModel;
use App\Models\User;
use App\Models\UserAddress;
use Dcat\Admin\Grid\BatchAction;
use Dcat\Admin\Grid\Tools\AbstractTool;
use Illuminate\Http\Request;
use Dcat\Admin\Grid\RowAction;
class UserAddressDeleteAction extends RowAction
{
/**
* 按钮样式定义,默认 btn btn-white waves-effect
*
* @var string
*/
protected $style = 'btn btn-white waves-effect';
/**
* 按钮文本
*
* @return string|void
*/
public function title()
{
$buttonName = "删除";
return $buttonName;
}
public function html()
{
$class = $this->getElementClass();
$color = "btn btn-danger btn-sm btn-mini";
// 获取当前行数据ID
$id = $this->getKey();
$this->setHtmlAttribute([
'data-id' => $id,
"class" => "{$class} {$color}",
]);
return parent::html();
}
/**
* 确认弹窗,如果不需要则返回空即可
*
* @return array|string|void
*/
public function confirm()
{
$buttonName = "删除";
return ["是否确认 {$buttonName} ?"];
}
/**
* 处理请求
* 如果你的类中包含了此方法,则点击按钮后会自动向后端发起ajax请求,并且会通过此方法处理请求逻辑
*
* @param Request $request
*/
public function handle(Request $request)
{
// 获取 parameters 方法传递的参数
$rowData = $request->get('rowData');
try {
UserAddress::deleteById($rowData['address_id']);
} catch (\Throwable $e) {
return $this->response()->error($e->getMessage());
}
return $this->response()->success('操作成功')->refresh();
}
/**
* 设置请求参数
*
* @return array|void
*/
public function parameters()
{
return [
'rowData' => $this->row,
];
}
}
<?php
namespace App\Admin\Actions\UserAddress;
use App\Admin\Forms\User\AssignUserHandle;
use App\Admin\Forms\UserAddress\EditUserAddressHandle;
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 UserAddressEditAction extends AbstractTool
{
protected $action;
protected $htmlClasses = ['btn btn-sm btn-primary'];
// 注意action的构造方法参数一定要给默认值
public function __construct($title = null, $action = 1)
{
$this->title = $title;
$this->action = $action;
}
public function render()
{
$form = EditUserAddressHandle::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 style="margin-right: 5px" class="btn btn-sm 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,
];
}
}
...@@ -61,7 +61,7 @@ class EditUserHandle extends Form implements LazyRenderable ...@@ -61,7 +61,7 @@ class EditUserHandle extends Form implements LazyRenderable
$form->width(5)->text('email'); $form->width(5)->text('email');
}); });
$this->row(function (Row $form) { $this->row(function (Row $form) {
$form->width(5)->text('reg_source')->required(); $form->width(5)->select('reg_source')->options(admin_trans('user.options.reg_source'))->required();
$form->width(5)->text('remark'); $form->width(5)->text('remark');
}); });
} }
......
<?php
namespace App\Admin\Forms\UserAddress;
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 EditUserAddressHandle 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)->select('reg_source')->options(admin_trans('user.options.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,11 @@ ...@@ -2,6 +2,11 @@
namespace App\Admin\Renderable; namespace App\Admin\Renderable;
use App\Admin\Actions\UserAddress\UserAddressDeleteAction;
use App\Admin\Actions\User\UserAssignAction;
use App\Admin\Actions\User\UserStatusAction;
use App\Admin\Actions\User\UserTransferAction;
use App\Admin\Actions\UserAddress\UserAddressEditAction;
use App\Admin\Repositories\Inquiry; use App\Admin\Repositories\Inquiry;
use App\Admin\Repositories\User; use App\Admin\Repositories\User;
use App\Admin\Service\UserAddressService; use App\Admin\Service\UserAddressService;
...@@ -22,11 +27,27 @@ class UserAddress extends \Dcat\Admin\Support\LazyRenderable ...@@ -22,11 +27,27 @@ class UserAddress extends \Dcat\Admin\Support\LazyRenderable
$grid->title("address"); $grid->title("address");
$grid->disableFilterButton(); $grid->disableFilterButton();
$grid->disableRefreshButton(); $grid->disableRefreshButton();
$grid->disableBatchDelete();
$grid->disableCreateButton(); $grid->disableCreateButton();
$grid->disableBatchDelete();
$grid->disableEditButton();
UserAddressService::listField($grid); UserAddressService::listField($grid);
});
// $addressList = \App\Models\UserAddress::getListByUserId($id);
$grid->tools([
new UserTransferAction("转让销售"),
]);
$grid->actions(function (Grid\Displayers\Actions $actions) {
$actions->disableDelete();
$actions->disableEdit();
$actions->disableQuickEdit();
$actions->disableView();
// 当前行的数据数组
// $rowArray = $actions->row->toArray();
// 获取当前行主键值
$deleteAction = new UserAddressDeleteAction();
$deleteAction->setRow($actions->row);
$deleteAction->setKey($actions->getKey());
$actions->append($deleteAction);
});
});
} }
} }
...@@ -77,8 +77,8 @@ class UserService ...@@ -77,8 +77,8 @@ class UserService
// $rowArray = $actions->row->toArray(); // $rowArray = $actions->row->toArray();
// 获取当前行主键值 // 获取当前行主键值
$id = $actions->getKey(); $id = $actions->getKey();
$actions->append('<a href="' . admin_url("/users/{$id}") . '" class="btn btn-primary btn-sm $actions->append('<a style="margin-right: 5px" href="' . admin_url("/users/{$id}") . '" class="btn btn-primary btn-sm
btn-mini">detail</a> '); btn-mini">detail</a>');
//状态按钮 //状态按钮
$actions->append(new UserStatusAction()); $actions->append(new UserStatusAction());
}); });
......
...@@ -42,4 +42,8 @@ class UserAddress extends Model ...@@ -42,4 +42,8 @@ class UserAddress extends Model
return ($res) ? $res->toArray() : []; return ($res) ? $res->toArray() : [];
} }
public static function deleteById($addressId){
return self::where('address_id', $addressId)->delete();
}
} }
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