Commit 239a35e3 by 宁成龙

完善新增客户地址功能

parent 693664e7
...@@ -4,7 +4,7 @@ namespace App\Admin\Actions\UserAddress; ...@@ -4,7 +4,7 @@ namespace App\Admin\Actions\UserAddress;
use App\Admin\Forms\User\AssignUserHandle; use App\Admin\Forms\User\AssignUserHandle;
use App\Admin\Forms\UserAddress\EditUserAddressHandle; use App\Admin\Forms\UserAddress\SaveUserAddressHandle;
use App\Admin\Forms\User\EditUserHandle; use App\Admin\Forms\User\EditUserHandle;
use App\Models\Order as OrderModel; use App\Models\Order as OrderModel;
use App\Models\User; use App\Models\User;
...@@ -16,7 +16,7 @@ use Illuminate\Http\Request; ...@@ -16,7 +16,7 @@ use Illuminate\Http\Request;
use Dcat\Admin\Grid\RowAction; use Dcat\Admin\Grid\RowAction;
class UserAddressEditAction extends AbstractTool class UserAddressCreateAction extends AbstractTool
{ {
protected $action; protected $action;
protected $htmlClasses = ['btn btn-sm btn-primary']; protected $htmlClasses = ['btn btn-sm btn-primary'];
...@@ -29,23 +29,23 @@ class UserAddressEditAction extends AbstractTool ...@@ -29,23 +29,23 @@ class UserAddressEditAction extends AbstractTool
public function render() public function render()
{ {
$form = EditUserAddressHandle::make(['key'=>$this->getKey()]); $form = SaveUserAddressHandle::make(['user_id'=>$this->getKey()]);
$buttonName = trans('user.labels.handle'); $buttonName = trans('user.labels.handle');
return Modal::make()->lg()->title($this->title)->body($form->payload(['key'=>$this->getKey()]))->onLoad return Modal::make()->lg()->title($this->title)->body($form->payload(['user_id'=>$this->getKey()]))->onLoad
($this->getModalScript())->button('<button style="margin-right: 5px" class="btn btn-sm btn-primary"> ($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">' . <i class="feather icon-check-circle"></i><span class="d-none d-sm-inline" style="margin-left: 5px">' .
$buttonName . '</span> $buttonName . '</span>
</button>'); </button>');
} }
protected function getModalScript() protected function getModalScript()
{ {
return <<<JS return <<<JS
var key = {$this->getKey()} var key = {$this->getKey()}
$('#id').val(key); $('#user_id').val(key);
JS; JS;
} }
public function html() public function html()
{ {
return parent::html(); // TODO: Change the autogenerated stub return parent::html(); // TODO: Change the autogenerated stub
...@@ -56,6 +56,7 @@ JS; ...@@ -56,6 +56,7 @@ JS;
{ {
return [ return [
'action' => $this->action, 'action' => $this->action,
'user_id'=>$this->getKey()
]; ];
} }
} }
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
namespace App\Admin\Forms\UserAddress; namespace App\Admin\Forms\UserAddress;
use App\Models\Cms\CmsUser; use App\Models\Cms\CmsUser;
use App\Models\Country;
use App\Models\Inquiry; use App\Models\Inquiry;
use App\Models\User; use App\Models\User;
use Dcat\Admin\Contracts\LazyRenderable; use Dcat\Admin\Contracts\LazyRenderable;
...@@ -10,7 +11,7 @@ use Dcat\Admin\Form\Row; ...@@ -10,7 +11,7 @@ use Dcat\Admin\Form\Row;
use Dcat\Admin\Traits\LazyWidget; use Dcat\Admin\Traits\LazyWidget;
use Dcat\Admin\Widgets\Form; use Dcat\Admin\Widgets\Form;
class EditUserAddressHandle extends Form implements LazyRenderable class SaveUserAddressHandle extends Form implements LazyRenderable
{ {
use LazyWidget; use LazyWidget;
...@@ -24,12 +25,9 @@ class EditUserAddressHandle extends Form implements LazyRenderable ...@@ -24,12 +25,9 @@ class EditUserAddressHandle extends Form implements LazyRenderable
public function handle(array $input) public function handle(array $input)
{ {
try { try {
$id = explode(",", $input['id']); $userId = $this->payload['user_id'];
// $userList = User::getListByIdArr($ids); $address = 0;
$userInfo = User::getInfoByUserId($id);
if (!$userInfo) {
throw new \Exception('客户不存在');
}
User::updateById($id, $input); User::updateById($id, $input);
return $this return $this
->response() ->response()
...@@ -47,35 +45,32 @@ class EditUserAddressHandle extends Form implements LazyRenderable ...@@ -47,35 +45,32 @@ class EditUserAddressHandle extends Form implements LazyRenderable
public function form() public function form()
{ {
$this->disableResetButton(); $this->disableResetButton();
$this->hidden('id')->attribute('id', 'id')->width(4);
$this->row(function (Row $form) { $this->row(function (Row $row) {
$form->width(5)->text('company_name')->required(); $row->width(3)->text('first_name')->required();
$form->width(5)->text('user_sn'); $row->width(3)->text('last_name')->required();
});
$this->row(function (Row $row) {
$row->width(3)->select('address_type')->options(admin_trans('user-address.options.address_type'))
->required();
$row->width(3)->text('company_name');
}); });
$this->row(function (Row $form) { $this->row(function (Row $row) {
$form->width(5)->text('first_name')->required(); $row->width(3)->email('email')->required();
$form->width(5)->text('last_name'); $row->width(3)->text('phone')->required();
}); });
$this->row(function (Row $form) { $this->row(function (Row $row) {
$form->width(5)->text('phone')->required(); $row->width(3)->select('country')->options(Country::getCountryMap())->required();
$form->width(5)->text('email'); $row->width(3)->text('province');
$row->width(3)->text('city')->required();
$row->width(2)->text('post_code')->required();
}); });
$this->row(function (Row $form) { $this->row(function (Row $row) {
$form->width(5)->select('reg_source')->options(admin_trans('user.options.reg_source'))->required(); $row->width(12)->textarea('detail_address')->required();
$form->width(5)->text('remark'); });
$this->row(function (Row $row) {
$row->width(3)->switch('is_default')->required();
}); });
} }
/**
* The data of the form.
*
* @return array
*/
public function default()
{
$userInfo = User::getInfoByUserId($this->payload['key']);
return $userInfo;
}
} }
...@@ -64,7 +64,7 @@ class CreateUser extends \Dcat\Admin\Support\LazyRenderable ...@@ -64,7 +64,7 @@ class CreateUser extends \Dcat\Admin\Support\LazyRenderable
$table->width(2)->text('post_code')->required(); $table->width(2)->text('post_code')->required();
}); });
$table->row(function (Form\Row $table) { $table->row(function (Form\Row $table) {
$table->width(3)->textarea('detail_address')->required(); $table->width(12)->textarea('detail_address')->required();
}); });
$table->row(function (Form\Row $table) { $table->row(function (Form\Row $table) {
$table->width(3)->switch('is_default')->required(); $table->width(3)->switch('is_default')->required();
......
...@@ -6,7 +6,7 @@ use App\Admin\Actions\UserAddress\UserAddressDeleteAction; ...@@ -6,7 +6,7 @@ use App\Admin\Actions\UserAddress\UserAddressDeleteAction;
use App\Admin\Actions\User\UserAssignAction; use App\Admin\Actions\User\UserAssignAction;
use App\Admin\Actions\User\UserStatusAction; use App\Admin\Actions\User\UserStatusAction;
use App\Admin\Actions\User\UserTransferAction; use App\Admin\Actions\User\UserTransferAction;
use App\Admin\Actions\UserAddress\UserAddressEditAction; use App\Admin\Actions\UserAddress\UserAddressCreateAction;
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;
...@@ -32,8 +32,10 @@ class UserAddress extends \Dcat\Admin\Support\LazyRenderable ...@@ -32,8 +32,10 @@ class UserAddress extends \Dcat\Admin\Support\LazyRenderable
$grid->disableEditButton(); $grid->disableEditButton();
UserAddressService::listField($grid); UserAddressService::listField($grid);
$userAddressCreateAction = new UserAddressCreateAction("新增用户地址");
$userAddressCreateAction->setKey($this->key);
$grid->tools([ $grid->tools([
new UserTransferAction("转让销售"), $userAddressCreateAction,
]); ]);
$grid->actions(function (Grid\Displayers\Actions $actions) { $grid->actions(function (Grid\Displayers\Actions $actions) {
$actions->disableDelete(); $actions->disableDelete();
...@@ -46,6 +48,7 @@ class UserAddress extends \Dcat\Admin\Support\LazyRenderable ...@@ -46,6 +48,7 @@ class UserAddress extends \Dcat\Admin\Support\LazyRenderable
$deleteAction = new UserAddressDeleteAction(); $deleteAction = new UserAddressDeleteAction();
$deleteAction->setRow($actions->row); $deleteAction->setRow($actions->row);
$deleteAction->setKey($actions->getKey()); $deleteAction->setKey($actions->getKey());
$actions->append($deleteAction); $actions->append($deleteAction);
}); });
}); });
......
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