代理商管理
This commit is contained in:
parent
da78ff5978
commit
9c9832245c
102
app/Domains/Virtual/Http/Controllers/AgentController.php
Normal file
102
app/Domains/Virtual/Http/Controllers/AgentController.php
Normal file
@ -0,0 +1,102 @@
|
||||
<?php
|
||||
namespace App\Domains\Virtual\Http\Controllers;
|
||||
|
||||
use App\Core\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Exceptions\NotExistException;
|
||||
use App\Domains\Virtual\Services\AgentService;
|
||||
use App\Domains\Virtual\Repositories\AgentRepository;
|
||||
|
||||
class AgentController extends Controller
|
||||
{
|
||||
protected $request;
|
||||
protected $agentService;
|
||||
|
||||
/**
|
||||
* 构造函数,自动注入.
|
||||
*/
|
||||
public function __construct(Request $request, AgentService $agentService)
|
||||
{
|
||||
$this->request = $request;
|
||||
$this->agentService = $agentService;
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$conditions = $this->request->all();
|
||||
$conditions['limit'] = $this->request->get('limit', 20);
|
||||
|
||||
$agents = $this->agentService->index($conditions);
|
||||
|
||||
$agents->load(['company:id,name']);
|
||||
|
||||
return res($agents, '代理商列表', 201);
|
||||
}
|
||||
|
||||
/**
|
||||
* 代理商详情.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
$node = app(AgentRepository::class)->find($id);
|
||||
|
||||
if (!$node) {
|
||||
throw new NotExistException('代理商不存在或已删除');
|
||||
}
|
||||
|
||||
$node->load(['company:id,name']);
|
||||
|
||||
return res($node, '代理商详情', 201);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 创建.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$attributes = $this->request->all();
|
||||
|
||||
$account = $this->agentService->store($attributes);
|
||||
|
||||
return res($account, '创建成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update($id)
|
||||
{
|
||||
$attributes = $this->request->all();
|
||||
$attributes['id'] = $id;
|
||||
|
||||
$account = $this->agentService->store($attributes);
|
||||
|
||||
return res($account, '修改成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy()
|
||||
{
|
||||
$ids = $this->request->ids();
|
||||
|
||||
$this->agentService->destroy($ids);
|
||||
|
||||
return res(true, '删除成功');
|
||||
}
|
||||
}
|
72
app/Domains/Virtual/Repositories/AgentRepository.php
Normal file
72
app/Domains/Virtual/Repositories/AgentRepository.php
Normal file
@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Virtual\Repositories;
|
||||
|
||||
use App\Core\Repository;
|
||||
use App\Models\Virtual\Agent as Model;
|
||||
|
||||
class AgentRepository extends Repository
|
||||
{
|
||||
/**
|
||||
* 是否关闭缓存
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $cacheSkip = false;
|
||||
|
||||
/**
|
||||
* 是否开启数据转化
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $needTransform = false;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $fieldSearchable = [
|
||||
'id' => '=',
|
||||
// 'created_at' => 'like',
|
||||
'name' => 'like',
|
||||
];
|
||||
|
||||
public function model()
|
||||
{
|
||||
return Model::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据格式化
|
||||
*
|
||||
* @param mixed $result
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function transform($model)
|
||||
{
|
||||
return $model->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询条件
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function withConditions(array $conditions = [])
|
||||
{
|
||||
if (isset($conditions['id'])) {
|
||||
$conditions['id'] = array_wrap($conditions['id']);
|
||||
$this->model = $this->model->whereIn('id', $conditions['id']);
|
||||
}
|
||||
|
||||
if (!empty($conditions['name'])) {
|
||||
$this->model = $this->model->where('name', 'like', "%{$conditions['name']}%");
|
||||
}
|
||||
|
||||
if (isset($conditions['status'])) {
|
||||
$this->model = $this->model->where('status', $conditions['status']);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
@ -36,6 +36,13 @@ $router->group(['prefix' => 'virtual', 'as' => 'virtual', 'middleware' => ['admi
|
||||
// $router->post('/company/addresses/update/{id}', ['as' => 'company.addresses.update', 'uses' => 'CompanyAddressController@update']);
|
||||
// $router->post('/company/addresses/destroy', ['as' => 'company.addresses.destroy', 'uses' => 'CompanyAddressController@destroy']);
|
||||
|
||||
// 代理商管理
|
||||
$router->get('/agents/index', ['as' => 'agents.index', 'uses' => 'AgentController@index']);
|
||||
$router->get('/agents/show/{id}', ['as' => 'agents.show', 'uses' => 'AgentController@show']);
|
||||
$router->post('/agents/create', ['as' => 'agents.create', 'uses' => 'AgentController@create']);
|
||||
$router->post('/agents/update/{id}', ['as' => 'agents.update', 'uses' => 'AgentController@update']);
|
||||
$router->post('/agents/destroy', ['as' => 'agents.destroy', 'uses' => 'AgentController@destroy']);
|
||||
|
||||
// 定价管理
|
||||
$router->get('/products/index', ['as' => 'products.index', 'uses' => 'ProductController@index']);
|
||||
$router->get('/products/history', ['as' => 'products.history', 'uses' => 'ProductController@history']);
|
||||
|
129
app/Domains/Virtual/Services/AgentService.php
Normal file
129
app/Domains/Virtual/Services/AgentService.php
Normal file
@ -0,0 +1,129 @@
|
||||
<?php
|
||||
namespace App\Domains\Virtual\Services;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use App\Core\Service;
|
||||
use App\Models\Virtual\Agent;
|
||||
use Illuminate\Validation\Rule;
|
||||
use App\Exceptions\NotExistException;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use App\Domains\Virtual\Services\CommonService;
|
||||
use App\Domains\Virtual\Repositories\AgentRepository;
|
||||
|
||||
class AgentService extends Service
|
||||
{
|
||||
protected $agentServiceRepository;
|
||||
|
||||
protected static $agents;
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(AgentRepository $agentServiceRepository)
|
||||
{
|
||||
$this->agentServiceRepository = $agentServiceRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* 代理商列表
|
||||
*
|
||||
* @param array $conditions
|
||||
* @return mixed
|
||||
*/
|
||||
public function index(array $conditions = [])
|
||||
{
|
||||
$limit = $conditions['limit'] ?? 20;
|
||||
|
||||
$agents = $this->agentServiceRepository->withConditions($conditions)
|
||||
->applyConditions()->paginate($limit);
|
||||
|
||||
$agents->map(function ($item) {
|
||||
$item->status = $item->deleted_at ? 2 : $item->status;
|
||||
$item->created_at = Carbon::parse($item->created_at)->format('Y-m-d');
|
||||
$item->updated_at = Carbon::parse($item->updated_at)->format('Y-m-d');
|
||||
});
|
||||
|
||||
return $agents;
|
||||
}
|
||||
|
||||
/**
|
||||
* 存储代理商
|
||||
*
|
||||
* @param array $attributes
|
||||
* @param Agent $parent
|
||||
* @return Agent
|
||||
*/
|
||||
public function store(array $attributes = [])
|
||||
{
|
||||
$attributes = array_only($attributes, array_merge(app(Agent::class)->getFillable()));
|
||||
|
||||
$rule = [
|
||||
'company_id' => ['required', 'exists:virtual_companies,id'],
|
||||
'name' => ['required', 'between:2,32', Rule::unique($this->agentServiceRepository->getTable(), 'name')->ignore($attributes['id'])->whereNUll('deleted_at')],
|
||||
'contacts' => ['string', 'between:2,32'],
|
||||
'mobile' => ['string', 'cn_phone'],
|
||||
'address' => ['string'],
|
||||
'extends' => ['array'],
|
||||
];
|
||||
|
||||
$message = [
|
||||
'company_id.required' => '请输入企业ID',
|
||||
'company_id.exists' => '企业不存在或已删除',
|
||||
'name.required' => '请输入代理商名称',
|
||||
'name.between' => '代理商名称长度不合法',
|
||||
'name.unique' => '代理商名称已经被其他用户所使用',
|
||||
'contacts.between' => '联系人长度不合法',
|
||||
'mobile.cn_phone' => '手机号不合法',
|
||||
];
|
||||
|
||||
Validator::validate($attributes, $rule, $message);
|
||||
|
||||
if (!$attributes['id']) {
|
||||
$maxId = Agent::withTrashed()->max('id');
|
||||
$attributes['id'] = $maxId ? $maxId + 1 : 1;
|
||||
|
||||
$maxSn = Agent::withTrashed()->max('sn');
|
||||
$maxSn = intval(str_replace('No', '', $maxSn));
|
||||
$attributes['sn'] = CommonService::stringifyCompanyId($maxSn + 1);
|
||||
|
||||
$node = $this->agentServiceRepository->create($attributes);
|
||||
}
|
||||
|
||||
if ($attributes['id']) {
|
||||
$node = $this->agentServiceRepository->find($attributes['id']);
|
||||
|
||||
if (!$node) {
|
||||
throw new NotExistException('代理商不存在或已删除');
|
||||
}
|
||||
|
||||
$this->agentServiceRepository->setModel($node)->update($attributes);
|
||||
}
|
||||
|
||||
return $node;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function destroy($ids)
|
||||
{
|
||||
$ids = is_array($ids) ? $ids : [$ids];
|
||||
|
||||
$this->agentServiceRepository->destroy($ids);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function load($id)
|
||||
{
|
||||
if (!self::$agents) {
|
||||
self::$agents = app(AgentRepository::class)->select(['id', 'name', 'status'])->withTrashed()->get()->keyBy('id')->toArray();
|
||||
}
|
||||
|
||||
return self::$agents[$id];
|
||||
}
|
||||
}
|
56
app/Models/Virtual/Agent.php
Normal file
56
app/Models/Virtual/Agent.php
Normal file
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Virtual;
|
||||
|
||||
use App\Models\CompanyBase;
|
||||
|
||||
/**
|
||||
* App\Models\Virtual\Agent
|
||||
*
|
||||
* @property int $id 代理商ID
|
||||
* @property int $company_id 企业ID
|
||||
* @property string $sn 代理商编号
|
||||
* @property string $name 代理商名称
|
||||
* @property string $contacts 联系人
|
||||
* @property string $mobile 手机号
|
||||
* @property string $address 地址
|
||||
* @property string|null $remark 订单备注
|
||||
* @property array|null $extends 扩展信息
|
||||
* @property \Illuminate\Support\Carbon|null $created_at
|
||||
* @property \Illuminate\Support\Carbon|null $updated_at
|
||||
* @property \Illuminate\Support\Carbon|null $deleted_at
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Virtual\CompanyAccount[] $accounts
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Virtual\CompanyAddress[] $addresses
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Virtual\Company newModelQuery()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Virtual\Company newQuery()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Virtual\Company query()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Virtual\Company whereAddress($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Virtual\Company whereContacts($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Virtual\Company whereCreatedAt($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Virtual\Company whereDeletedAt($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Virtual\Company whereExtends($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Virtual\Company whereId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Virtual\Company whereMobile($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Virtual\Company whereName($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Virtual\Company whereRemark($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Virtual\Company whereSn($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Virtual\Company whereUpdatedAt($value)
|
||||
* @mixin \Eloquent
|
||||
* @property int $status 状态 0:正常 1:禁用
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Virtual\Company whereStatus($value)
|
||||
*/
|
||||
class Agent extends CompanyBase
|
||||
{
|
||||
protected $table = 'virtual_agents';
|
||||
|
||||
protected $fillable = ['id', 'company_id','sn', 'name' , 'contacts', 'mobile', 'address', 'remark', 'extends', 'status'];
|
||||
|
||||
protected $casts = [
|
||||
'extends' => 'array',
|
||||
];
|
||||
|
||||
public function company()
|
||||
{
|
||||
return $this->belongsTo(Company::class, 'company_id', 'id');
|
||||
}
|
||||
}
|
@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class AddVirtualOrderCardsPartitionIdx extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('virtual_order_cards', function (Blueprint $table) {
|
||||
$table->index(['sim']);
|
||||
$table->index(['company_id', 'package_id']);
|
||||
$table->index(['service_end_at']);
|
||||
});
|
||||
|
||||
Schema::table('virtual_order_renewal_cards', function (Blueprint $table) {
|
||||
$table->index(['sim']);
|
||||
$table->index(['company_id', 'package_id']);
|
||||
$table->index(['service_end_at']);
|
||||
});
|
||||
|
||||
Schema::table('virtual_order_renewal_package_cards', function (Blueprint $table) {
|
||||
$table->index(['sim']);
|
||||
$table->index(['company_id', 'package_id']);
|
||||
$table->index(['service_end_at']);
|
||||
});
|
||||
|
||||
Schema::table('virtual_order_flows_package_cards', function (Blueprint $table) {
|
||||
$table->index(['sim']);
|
||||
$table->index(['company_id', 'package_id']);
|
||||
$table->index(['service_end_at']);
|
||||
});
|
||||
|
||||
Schema::table('virtual_order_upgrade_cards', function (Blueprint $table) {
|
||||
$table->index(['sim']);
|
||||
$table->index(['company_id', 'package_id']);
|
||||
$table->index(['service_end_at']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('virtual_order_cards', function (Blueprint $table) {
|
||||
$table->dropIndex("virtual_order_cards_sim_index");
|
||||
$table->dropIndex("virtual_order_cards_company_id_package_id_index");
|
||||
$table->dropIndex("virtual_order_cards_service_end_at_index");
|
||||
});
|
||||
|
||||
Schema::table('virtual_order_renewal_cards', function (Blueprint $table) {
|
||||
$table->dropIndex("virtual_order_renewal_cards_sim_index");
|
||||
$table->dropIndex("virtual_order_renewal_cards_company_id_package_id_index");
|
||||
$table->dropIndex("virtual_order_renewal_cards_service_end_at_index");
|
||||
});
|
||||
|
||||
Schema::table('virtual_order_renewal_package_cards', function (Blueprint $table) {
|
||||
$table->dropIndex("virtual_order_renewal_package_cards_sim_index");
|
||||
$table->dropIndex("virtual_order_renewal_package_cards_company_id_package_id_index");
|
||||
$table->dropIndex("virtual_order_renewal_package_cards_service_end_at_index");
|
||||
});
|
||||
|
||||
Schema::table('virtual_order_flows_package_cards', function (Blueprint $table) {
|
||||
$table->dropIndex("virtual_order_flows_package_cards_sim_index");
|
||||
$table->dropIndex("virtual_order_flows_package_cards_company_id_package_id_index");
|
||||
$table->dropIndex("virtual_order_flows_package_cards_service_end_at_index");
|
||||
});
|
||||
|
||||
Schema::table('virtual_order_upgrade_cards', function (Blueprint $table) {
|
||||
$table->dropIndex("virtual_order_upgrade_cards_sim_index");
|
||||
$table->dropIndex("virtual_order_upgrade_cards_company_id_package_id_index");
|
||||
$table->dropIndex("virtual_order_upgrade_cards_service_end_at_index");
|
||||
});
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateVirtualAgentsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('virtual_agents', function (Blueprint $table) {
|
||||
$table->increments('id')->comment('代理商ID');
|
||||
$table->integer('company_id')->unsigned()->default(0)->comment('企业ID');
|
||||
$table->string('sn', 32)->comment('代理商编号');
|
||||
$table->string('name', 32)->default('')->comment('代理商名称');
|
||||
$table->string('contacts', 20)->default('')->comment('联系人');
|
||||
$table->string('mobile', 20)->default('')->comment('手机号');
|
||||
$table->string('address')->default('')->comment('地址');
|
||||
$table->text('remark')->nullable()->comment('订单备注');
|
||||
$table->text('extends')->nullable()->comment('扩展信息');
|
||||
$table->tinyInteger('status')->unsigned()->default(0)->comment('状态 0:正常 1:禁用');
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
|
||||
$table->unique(['sn', 'deleted_at']);
|
||||
$table->comment("VD代理商");
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('virtual_agents');
|
||||
}
|
||||
}
|
51
frontend/src/api/virtual/agents.js
Normal file
51
frontend/src/api/virtual/agents.js
Normal file
@ -0,0 +1,51 @@
|
||||
/**
|
||||
* 代理商管理
|
||||
*/
|
||||
|
||||
/**
|
||||
* [index 代理商列表]
|
||||
* @param {[type]} data [description]
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
export function index(data) {
|
||||
return service.get('api/virtual/agents/index', {
|
||||
params: data
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* [show 代理商详情]
|
||||
* @param {[type]} id [description]
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
export function show(id) {
|
||||
return service.get(`api/virtual/agents/show/${id}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* [create 创建代理商]
|
||||
* @param {[type]} data [description]
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
export function create(data) {
|
||||
return serviceForm.post('api/virtual/agents/create', data);
|
||||
}
|
||||
|
||||
/**
|
||||
* [update 修改代理商]
|
||||
* @param {[type]} data [description]
|
||||
* @param {[type]} id [角色id]
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
export function update(data, id) {
|
||||
return serviceForm.post(`api/virtual/agents/update/${id}`, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* [destroy 删除代理商]
|
||||
* @param {[type]} data [description]
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
export function destroy(data) {
|
||||
return service.post('api/virtual/agents/destroy', data);
|
||||
}
|
@ -19,6 +19,7 @@ const routes = [
|
||||
{ path: '/iframe', name: 'Iframe', component: load('iframe/index'), meta: { title: 'iframe' } },
|
||||
{ path: '/companies', name: 'Companies', component: load('virtual/companies/index'), meta: { title: '企业管理' } },
|
||||
{ path: '/company/accounts', name: 'CompanyAccounts', component: load('virtual/company_accounts/index'), meta: { title: '账号管理' } },
|
||||
{ path: '/agents', name: 'Agents', component: load('virtual/agents/index'), meta: { title: '代理商管理' } },
|
||||
{ path: '/packages/:type', name: 'Packages', component: load('virtual/packages/index'), meta: { title: '套餐管理' } },
|
||||
{ path: '/products/:type', name: 'Products', component: load('virtual/products/index'), meta: { title: '定价管理' } },
|
||||
{ path: '/properties', name: 'Properties', component: load('virtual/properties/index'), meta: { title: '属性管理' } },
|
||||
|
71
frontend/src/views/virtual/agents/detail.vue
Normal file
71
frontend/src/views/virtual/agents/detail.vue
Normal file
@ -0,0 +1,71 @@
|
||||
<template>
|
||||
<Modal
|
||||
:footer-hide="true"
|
||||
:mask-closable="false"
|
||||
@on-visible-change="visibleChange"
|
||||
title="代理商详情"
|
||||
v-model="my_show"
|
||||
width="900"
|
||||
>
|
||||
<div class="page-detail-wrap" v-if="data">
|
||||
<Row :gutter="16">
|
||||
<Col span="12">
|
||||
<Divider>基础信息</Divider>
|
||||
<ul>
|
||||
<li class="ui-list">
|
||||
<div class="ui-list-title">所属企业:</div>
|
||||
<div class="ui-list-content">{{data.id}}</div>
|
||||
</li>
|
||||
|
||||
<li class="ui-list">
|
||||
<div class="ui-list-title">代理商编号:</div>
|
||||
<div class="ui-list-content">{{data.id}}</div>
|
||||
</li>
|
||||
|
||||
<li class="ui-list">
|
||||
<div class="ui-list-title">代理商名称:</div>
|
||||
<div class="ui-list-content">{{data.name}}</div>
|
||||
</li>
|
||||
|
||||
<li class="ui-list">
|
||||
<div class="ui-list-title">联系人:</div>
|
||||
<div class="ui-list-content">{{data.contacts}}</div>
|
||||
</li>
|
||||
|
||||
<li class="ui-list">
|
||||
<div class="ui-list-title">手机号:</div>
|
||||
<div class="ui-list-content">{{data.mobile}}</div>
|
||||
</li>
|
||||
|
||||
<li class="ui-list">
|
||||
<div class="ui-list-title">代理商地址:</div>
|
||||
<div class="ui-list-content">{{data.address}}</div>
|
||||
</li>
|
||||
</ul>
|
||||
</Col>
|
||||
<Col span="12">
|
||||
<Divider>其他信息</Divider>
|
||||
<ul>
|
||||
<li class="ui-list">
|
||||
<div class="ui-list-title">备注:</div>
|
||||
<div class="ui-list-content">{{data.remark}}</div>
|
||||
</li>
|
||||
|
||||
<li class="ui-list">
|
||||
<div class="ui-list-title">创建时间:</div>
|
||||
<div class="ui-list-content">{{moment(data.created_at).format("YYYY-MM-DD")}}</div>
|
||||
</li>
|
||||
|
||||
<li class="ui-list">
|
||||
<div class="ui-list-title">更新时间:</div>
|
||||
<div class="ui-list-content">{{moment(data.updated_at).format("YYYY-MM-DD")}}</div>
|
||||
</li>
|
||||
</ul>
|
||||
</Col>
|
||||
</Row>
|
||||
</div>
|
||||
</Modal>
|
||||
</template>
|
||||
|
||||
<script src="./js/detail.js"></script>
|
||||
|
111
frontend/src/views/virtual/agents/edit.vue
Normal file
111
frontend/src/views/virtual/agents/edit.vue
Normal file
@ -0,0 +1,111 @@
|
||||
<template>
|
||||
<Modal
|
||||
:closable="false"
|
||||
:mask-closable="false"
|
||||
:title="data?'编辑代理商':'添加代理商'"
|
||||
@on-visible-change="visibleChange"
|
||||
v-model="my_show"
|
||||
>
|
||||
<div class="page-edit-wrap uinn-lr20">
|
||||
<ui-loading :show="page_loading.show"></ui-loading>
|
||||
|
||||
<ul>
|
||||
<li class="ui-list">
|
||||
<div class="ui-list-title">
|
||||
<span class="title-require">*</span>代理商名称:
|
||||
</div>
|
||||
<div class="ui-list-content">
|
||||
<p>
|
||||
<Input :disabled="data?true:false" v-model.trim="params.name"></Input>
|
||||
</p>
|
||||
<ul class="common-tips-wraper umar-t5">
|
||||
<li class="t-title">提示</li>
|
||||
<li class="t-content">长度在2-32之间</li>
|
||||
</ul>
|
||||
</div>
|
||||
</li>
|
||||
|
||||
<li class="ui-list">
|
||||
<div class="ui-list-title">联系人</div>
|
||||
<div class="ui-list-content">
|
||||
<p>
|
||||
<Input :maxlength="32" v-model.trim="params.contacts"></Input>
|
||||
</p>
|
||||
<ul class="common-tips-wraper umar-t5">
|
||||
<li class="t-title">提示</li>
|
||||
<li class="t-content">长度在2-32之间</li>
|
||||
</ul>
|
||||
</div>
|
||||
</li>
|
||||
|
||||
<li class="ui-list">
|
||||
<div class="ui-list-title">手机号:</div>
|
||||
<div class="ui-list-content">
|
||||
<Input v-model.trim="params.mobile"></Input>
|
||||
</div>
|
||||
</li>
|
||||
|
||||
<li class="ui-list">
|
||||
<div class="ui-list-title">地址:</div>
|
||||
<div class="ui-list-content">
|
||||
<p>
|
||||
<Input :maxlength="32" v-model.trim="params.address"></Input>
|
||||
</p>
|
||||
</div>
|
||||
</li>
|
||||
|
||||
<li class="ui-list">
|
||||
<div class="ui-list-title">备注:</div>
|
||||
<div class="ui-list-content">
|
||||
<p>
|
||||
<Input :maxlength="32" v-model.trim="params.remark"></Input>
|
||||
</p>
|
||||
</div>
|
||||
</li>
|
||||
|
||||
<li class="ui-list">
|
||||
<div class="ui-list-title">银行账号:</div>
|
||||
<div class="ui-list-content">
|
||||
<p>
|
||||
<Input :maxlength="32" v-model.trim="params.extends.bank_account"></Input>
|
||||
</p>
|
||||
</div>
|
||||
</li>
|
||||
|
||||
<li class="ui-list">
|
||||
<div class="ui-list-title">微信账号:</div>
|
||||
<div class="ui-list-content">
|
||||
<p>
|
||||
<Input :maxlength="32" v-model.trim="params.extends.wechat_account"></Input>
|
||||
</p>
|
||||
</div>
|
||||
</li>
|
||||
|
||||
<li class="ui-list">
|
||||
<div class="ui-list-title">支付宝账号:</div>
|
||||
<div class="ui-list-content">
|
||||
<p>
|
||||
<Input :maxlength="32" v-model.trim="params.extends.alipay_account"></Input>
|
||||
</p>
|
||||
</div>
|
||||
</li>
|
||||
|
||||
<li class="ui-list">
|
||||
<div class="ui-list-title">状态:</div>
|
||||
<div class="ui-list-content lh-32">
|
||||
<Switch size="large" :true-value="0" :false-value="1" v-model="params.status">
|
||||
<span slot="open">启用</span>
|
||||
<span slot="close">禁用</span>
|
||||
</Switch>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<footer class="ta-c" slot="footer">
|
||||
<Button @click="clear" class="w-80" ghost type="primary">取消</Button>
|
||||
<Button :loading="loading" @click="ok" class="w-80" type="primary">提交</Button>
|
||||
</footer>
|
||||
</Modal>
|
||||
</template>
|
||||
|
||||
<script src="./js/edit.js"></script>
|
97
frontend/src/views/virtual/agents/index.vue
Normal file
97
frontend/src/views/virtual/agents/index.vue
Normal file
@ -0,0 +1,97 @@
|
||||
<template>
|
||||
<div class="page-wrap">
|
||||
<ui-loading :show="page_loading.show"></ui-loading>
|
||||
|
||||
<div class="page-handle-wrap">
|
||||
<ul class="handle-wraper bd-b">
|
||||
<li class="f-l">
|
||||
<div class="text-exp">
|
||||
<b>全部信息</b>
|
||||
</div>
|
||||
</li>
|
||||
<li class="f-r">
|
||||
<div class="handle-item">
|
||||
<Button
|
||||
@click="openEdit(true, null)"
|
||||
icon="md-add"
|
||||
type="primary"
|
||||
v-if="hasPermission('create')"
|
||||
>添加代理商</Button>
|
||||
</div>
|
||||
|
||||
<div class="handle-item">
|
||||
<Button @click="search.show=!search.show" ghost icon="ios-search" type="primary">搜索</Button>
|
||||
</div>
|
||||
|
||||
<div class="handle-item">
|
||||
<Button @click="index(1)" icon="md-refresh">刷新</Button>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<div class="search-wrap" v-show="search.show">
|
||||
<ul class="handle-wraper">
|
||||
<li class="handle-item w-250">
|
||||
<AutoComplete
|
||||
@on-search="handleCompleteCompanies"
|
||||
icon="ios-search"
|
||||
placeholder="请输入代理商名称"
|
||||
v-model.trim="params.name"
|
||||
>
|
||||
<Option
|
||||
:key="item.id"
|
||||
:value="item.name"
|
||||
v-for="item in completeHandledCompanies"
|
||||
>{{ item.name }}</Option>
|
||||
</AutoComplete>
|
||||
</li>
|
||||
|
||||
<li class="handle-item w-250">
|
||||
<Select clearable placeholder="套餐状态" v-model="params.status">
|
||||
<Option :value="0">已启用</Option>
|
||||
<Option :value="1">已禁用</Option>
|
||||
<Option :value="2">已删除</Option>
|
||||
</Select>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<ul class="handle-wraper">
|
||||
<li class="f-r">
|
||||
<div class="handle-item">
|
||||
<Button @click="index(1)" ghost type="primary">立即搜索</Button>
|
||||
</div>
|
||||
<div class="handle-item">
|
||||
<Button @click="resetSearch" ghost type="warning">重置搜索</Button>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="page-list-wrap">
|
||||
<Table :columns="table_titles" :data="list_data ? list_data.data : []"></Table>
|
||||
</div>
|
||||
|
||||
<div class="page-turn-wrap" v-if="list_data">
|
||||
<Page
|
||||
:current="Number(list_data.current_page)"
|
||||
:page-size="Number(list_data.per_page)"
|
||||
:total="Number(list_data.total)"
|
||||
@on-change="index"
|
||||
show-elevator
|
||||
show-total
|
||||
></Page>
|
||||
</div>
|
||||
|
||||
<ui-edit
|
||||
:data="editObj.data"
|
||||
:show.sync="editObj.show"
|
||||
@add-success="index"
|
||||
@update-success="index(list_data.current_page)"
|
||||
></ui-edit>
|
||||
|
||||
<ui-detail :data="detailObj.data" :show.sync="detailObj.show"></ui-detail>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script src="./js/index.js"></script>
|
29
frontend/src/views/virtual/agents/js/detail.js
Normal file
29
frontend/src/views/virtual/agents/js/detail.js
Normal file
@ -0,0 +1,29 @@
|
||||
export default {
|
||||
props: {
|
||||
show: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
data: {
|
||||
type: Object,
|
||||
default() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
show(bool) {
|
||||
this.my_show = bool;
|
||||
}
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
my_show: false
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
visibleChange(bool) {
|
||||
this.$emit('update:show', bool);
|
||||
}
|
||||
}
|
||||
};
|
110
frontend/src/views/virtual/agents/js/edit.js
Normal file
110
frontend/src/views/virtual/agents/js/edit.js
Normal file
@ -0,0 +1,110 @@
|
||||
import * as API from 'api/virtual/agents';
|
||||
|
||||
export default {
|
||||
props: {
|
||||
show: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
data: {
|
||||
type: Object,
|
||||
default() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
my_show: false,
|
||||
isUpdate: false,
|
||||
loading: false,
|
||||
params: {
|
||||
company_id: '',
|
||||
name: '',
|
||||
contacts: '',
|
||||
mobile: '',
|
||||
address: '',
|
||||
remark: '',
|
||||
status: 0
|
||||
}
|
||||
};
|
||||
},
|
||||
watch: {
|
||||
show(bool) {
|
||||
this.my_show = bool;
|
||||
if (bool) {
|
||||
if (this.data) {
|
||||
for (let k in this.data) {
|
||||
if (k in this.params) {
|
||||
this.params[k] = this.data[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
ok() {
|
||||
if (!this.params.company_id) {
|
||||
this.$Message.info('请选择代理商');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.params.name) {
|
||||
this.$Message.info('请填写代理商名称');
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.params.contacts && !(/[\s\S]{2,32}/.test(this.params.contacts))) {
|
||||
this.$Message.info('联系人长度在2-32之间');
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.data) {
|
||||
// 编辑
|
||||
API.update(this.params, this.data.id).then(res => {
|
||||
this.loading = false;
|
||||
if (res.code == 0) {
|
||||
this.$emit('update-success');
|
||||
this.$Message.success('更新成功');
|
||||
this.clear();
|
||||
this.completeCompanyInitialized = false;
|
||||
}
|
||||
}).catch(err => {
|
||||
this.loading = false;
|
||||
});
|
||||
} else {
|
||||
// 添加
|
||||
API.create(this.params).then(res => {
|
||||
this.loading = false;
|
||||
if (res.code == 0) {
|
||||
this.$emit('add-success');
|
||||
this.$Message.success('添加成功');
|
||||
this.clear();
|
||||
this.completeCompanyInitialized = false;
|
||||
}
|
||||
}).catch(err => {
|
||||
this.loading = false;
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
visibleChange(bool) {
|
||||
if (!bool) {
|
||||
this.$emit('update:show', false);
|
||||
}
|
||||
},
|
||||
|
||||
clear() {
|
||||
for (let k in this.params) {
|
||||
if (k == 'status') {
|
||||
this.params[k] = 0;
|
||||
} else {
|
||||
this.params[k] = '';
|
||||
}
|
||||
}
|
||||
|
||||
this.my_show = false;
|
||||
}
|
||||
}
|
||||
};
|
264
frontend/src/views/virtual/agents/js/index.js
Normal file
264
frontend/src/views/virtual/agents/js/index.js
Normal file
@ -0,0 +1,264 @@
|
||||
import * as API from "api/virtual/agents";
|
||||
export default {
|
||||
name: "Companies",
|
||||
components: {
|
||||
UiEdit: resolve => require(["views/virtual/agents/edit"], resolve),
|
||||
UiDetail: resolve => require(["views/virtual/agents/detail"], resolve)
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
params: {
|
||||
name: "",
|
||||
status: ""
|
||||
},
|
||||
trashed: null,
|
||||
list_data: null,
|
||||
editObj: {
|
||||
show: false,
|
||||
data: null
|
||||
},
|
||||
detailObj: {
|
||||
show: false,
|
||||
data: null
|
||||
},
|
||||
search: {
|
||||
show: false
|
||||
},
|
||||
table_titles: [
|
||||
{
|
||||
title: "ID",
|
||||
key: "id",
|
||||
width: 80
|
||||
},
|
||||
{
|
||||
title: "代理商名称",
|
||||
key: "name",
|
||||
width: 300
|
||||
},
|
||||
{
|
||||
title: "所属企业",
|
||||
key: "company.name",
|
||||
width: 300
|
||||
},
|
||||
{
|
||||
title: "联系人",
|
||||
key: "contacts"
|
||||
},
|
||||
{
|
||||
title: "电话",
|
||||
key: "mobile"
|
||||
},
|
||||
{
|
||||
title: "地址",
|
||||
key: "address"
|
||||
},
|
||||
{
|
||||
title: "状态",
|
||||
key: "",
|
||||
width: 100,
|
||||
render: (h, { row, column, index }) => {
|
||||
let type = ["primary", "warning", "error"];
|
||||
let text = ["已启用", "已禁用", "已删除"];
|
||||
|
||||
return h(
|
||||
"Button",
|
||||
{
|
||||
props: {
|
||||
type: type[row.status],
|
||||
size: "small"
|
||||
}
|
||||
},
|
||||
text[row.status]
|
||||
);
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "创建时间",
|
||||
render: (h, { row, column, index }) => {
|
||||
return h("span", this.moment(row.created_at).format("YYYY-MM-DD"));
|
||||
},
|
||||
width: 170
|
||||
},
|
||||
{
|
||||
title: "操作",
|
||||
key: "action",
|
||||
render: (h, { row, column, index }) => {
|
||||
let html = [];
|
||||
|
||||
if (row.deleted_at) {
|
||||
return h(
|
||||
"Tag",
|
||||
{ props: { color: "default" } },
|
||||
"该代理商已被删除"
|
||||
);
|
||||
}
|
||||
|
||||
if (this.haveJurisdiction("show")) {
|
||||
html.push(
|
||||
h(
|
||||
"Button",
|
||||
{
|
||||
props: {
|
||||
type: "success",
|
||||
size: "small",
|
||||
disabled: false,
|
||||
icon: "md-eye"
|
||||
},
|
||||
class: ["btn"],
|
||||
on: {
|
||||
click: event => {
|
||||
this.detailObj = {
|
||||
show: true,
|
||||
data: row
|
||||
};
|
||||
}
|
||||
}
|
||||
},
|
||||
"查看"
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if (this.haveJurisdiction("update")) {
|
||||
html.push(
|
||||
h(
|
||||
"Button",
|
||||
{
|
||||
props: {
|
||||
type: "primary",
|
||||
size: "small",
|
||||
disabled: false,
|
||||
icon: "md-create"
|
||||
},
|
||||
class: ["btn"],
|
||||
on: {
|
||||
click: event => {
|
||||
this.openEdit(true, row);
|
||||
}
|
||||
}
|
||||
},
|
||||
"编辑"
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if (this.haveJurisdiction("destroy")) {
|
||||
html.push(
|
||||
h(
|
||||
"Button",
|
||||
{
|
||||
props: {
|
||||
type: "error",
|
||||
size: "small",
|
||||
disabled: false,
|
||||
icon: "md-trash"
|
||||
},
|
||||
class: ["btn"],
|
||||
on: {
|
||||
click: () => {
|
||||
this.$Modal.confirm({
|
||||
title: "提示",
|
||||
content: "删除后该代理商不可使用,请谨慎操作",
|
||||
onOk: () => {
|
||||
API.destroy({
|
||||
ids: row.id
|
||||
}).then(res => {
|
||||
if (res.code == 0) {
|
||||
this.$Message.success("删除成功");
|
||||
this.request();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
"删除"
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if (html.length) {
|
||||
return h("div", html);
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
},
|
||||
created() {
|
||||
this.index(1);
|
||||
},
|
||||
methods: {
|
||||
/**
|
||||
* [index 列表]
|
||||
* @param {Number} page [description]
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
index(page = 1) {
|
||||
let params = Object.assign(this.params, {
|
||||
orderBy: "id",
|
||||
sortedBy: "asc"
|
||||
});
|
||||
|
||||
if (params.status === 2) {
|
||||
params.status = undefined;
|
||||
params.trashed = "only";
|
||||
} else {
|
||||
params.trashed = "without";
|
||||
}
|
||||
|
||||
let data = this.searchDataHandle({}, { page }, params);
|
||||
|
||||
this.isShowLoading(true);
|
||||
API.index(data)
|
||||
.then(res => {
|
||||
this.isShowLoading(false);
|
||||
if (res.code == 0) {
|
||||
this.list_data = res.data;
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
this.isShowLoading(false);
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* [openEdit 打开编辑弹窗]
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
openEdit(bool, data = null) {
|
||||
this.editObj = {
|
||||
show: bool,
|
||||
data
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* [request 刷新]
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
request() {
|
||||
const result = this.list_data;
|
||||
let page = result.current_page;
|
||||
|
||||
if (this.list_data.data.length == 1) {
|
||||
page = this.returnPage(
|
||||
result.total,
|
||||
result.current_page,
|
||||
result.per_page
|
||||
);
|
||||
}
|
||||
|
||||
this.index(page);
|
||||
},
|
||||
|
||||
resetSearch() {
|
||||
for (let k in this.params) {
|
||||
this.params[k] = "";
|
||||
}
|
||||
this.trashed = null;
|
||||
this.index(1);
|
||||
}
|
||||
}
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user