Commit 26d04e02 by LiuJunYi

区域管理BUG修复

parent ee5c38d7
...@@ -53,7 +53,9 @@ class Region extends AuthBase ...@@ -53,7 +53,9 @@ class Region extends AuthBase
public function del() public function del()
{ {
if (request()->isAjax()) { if (request()->isAjax()) {
$res = RegionModel::destroy(input('id')); $ids = $this->getAllIds([input('id')]);
array_unshift($ids, input('id'));
$res = RegionModel::destroy($ids);
if ($res) { if ($res) {
return json(['code' => 0, 'msg' => '删除成功']); return json(['code' => 0, 'msg' => '删除成功']);
} }
...@@ -62,6 +64,22 @@ class Region extends AuthBase ...@@ -62,6 +64,22 @@ class Region extends AuthBase
} }
/** /**
* 获取所有的分类
* @param $id
*/
public function getAllIds($ids = [18])
{
static $list = [];
$pids = RegionModel::where('pid', 'in', $ids)->column('id');
if ($pids) {
$list = array_merge($list, $pids);
self::getAllIds($pids);
}
return $list;
}
/**
* 修改 * 修改
* @return \think\response\Json * @return \think\response\Json
*/ */
...@@ -87,14 +105,14 @@ class Region extends AuthBase ...@@ -87,14 +105,14 @@ class Region extends AuthBase
*/ */
public function select() public function select()
{ {
if(input('id')==0){ if (input('id') == 0) {
return []; return [];
} }
$list = RegionModel::where('pid', input('id'))->select(); $list = RegionModel::where('pid', input('id'))->select();
if(!$list){ if (!$list) {
return []; return [];
} }
$list = collection($list)->visible(['id','title']); $list = collection($list)->visible(['id', 'title']);
return json($list); return json($list);
} }
......
...@@ -46,7 +46,7 @@ ...@@ -46,7 +46,7 @@
<a href="<?php echo url("@admin/Project/tags")?>">标签管理</a> <a href="<?php echo url("@admin/Project/tags")?>">标签管理</a>
</li> </li>
<li <?php if(CONTROLLER_NAME == 'Region'&&(ACTION_NAME=='citys'||ACTION_NAME=='index')){echo 'class="active"';}?>> <li <?php if(CONTROLLER_NAME == 'Region'&&(ACTION_NAME=='citys'||ACTION_NAME=='index')){echo 'class="active"';}?>>
<a href="<?php echo url("@admin/Region/index")?>">城市管理</a> <a href="<?php echo url("@admin/Region/index")?>">区域管理</a>
</li> </li>
</ul> </ul>
</li> </li>
......
...@@ -84,7 +84,7 @@ ...@@ -84,7 +84,7 @@
}); });
//只展开树形的第一级节点 //只展开树形的第一级节点
$table.treegrid('getRootNodes').treegrid('expand'); $table.treegrid('getRootNodes').treegrid('expandAll');
}, },
onCheck: function (row) { onCheck: function (row) {
...@@ -117,8 +117,7 @@ ...@@ -117,8 +117,7 @@
'<button type="button" class="RoleOfdelete btn-small btn btn-danger" style="margin-right:15px;"><i class="fa fa-trash-o" ></i>&nbsp;删除</button>' '<button type="button" class="RoleOfdelete btn-small btn btn-danger" style="margin-right:15px;"><i class="fa fa-trash-o" ></i>&nbsp;删除</button>'
]; ];
if (row.level >= 3) { if (row.level >= 3) {
arr.shift(); arr.splice(1, 1);
arr.shift();
} }
return "<div class=\"form-inline\" style='float: right;'>" + arr.join('') + "</div>"; return "<div class=\"form-inline\" style='float: right;'>" + arr.join('') + "</div>";
...@@ -155,6 +154,10 @@ ...@@ -155,6 +154,10 @@
<script> <script>
function add(id) { function add(id) {
var title = $("#title_" + id).val(); var title = $("#title_" + id).val();
if (title.trim().length === 0) {
layer.msg('名称不能为空',{icon:2});
return false;
}
$.post("{:url('add')}", {title: title, pid: id}, function (res) { $.post("{:url('add')}", {title: title, pid: id}, function (res) {
if (res.code === 0) { if (res.code === 0) {
location.reload(); location.reload();
...@@ -180,6 +183,10 @@ ...@@ -180,6 +183,10 @@
function update(id) { function update(id) {
var title = $("#title_" + id).val(); var title = $("#title_" + id).val();
$.post("{:url('edit')}", {title: title, id: id}, function (res) { $.post("{:url('edit')}", {title: title, id: id}, function (res) {
if (title.trim().length === 0) {
layer.msg('名称不能为空',{icon:2});
return false;
}
if (res.code === 0) { if (res.code === 0) {
location.reload(); location.reload();
} else { } else {
......
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 to comment