thinkphp 地区管理功能,因为最近有些系统有这方面的需求行业不一样用到区域也不一样,完成70%, ajax 双击修改地区部分没实现,有时间弄下。本来打算移植ecshop 的不过有点麻烦。还是自己写把。数据库部分来自ecshop region表。至于前端部分,参考任何一个城市级联即可实现,高端上档次!
实现效果:
前台代码:<form>
<br>
<table>
<br>
<tr>
<br>
<th>
<br>
{if $region_type=3}{$regionts}:<br>
<input><br>
<input><br>
<input><br>
<input><br>
{/if}<br>
<a>$region_typeyuanshi,'parentid'=>$fuID))}">返回上一级</a><br>
</th>
<br>
</tr>
<br>
</table>
<br>
</form>
<br>
<div>
<br>
<table>
<br>
<tr><td>{$region_type}</td></tr>
<br>
<tr>
<br>
<td>
<br>
<present><br>
<volist><br>
<div>
<span>{$vo['region_name']}</span><span>|</span><br>
{if $region_type=3}<br>
<a>$region_type,'parentid'=>$vo['Id']))}">管理</a><br>
{/if}<br>
<a>$vo['Id'],'parentid'=>$vo['Id']))}" >删除</a>
</div>
<br>
</volist><br>
<else></else><br>
<div>暂无地区</div><br>
</present><br>
</td>
<br>
</tr>
<br>
<tr><td></td></tr>
<br>
</table>
<br>
</div>
<br>
<p><br>
<font>注视:</font>1级地区:国家 2级地区:省份 3级地区:市级 4级地区:县/区<br>
</p>
public function region(){<br>
<br>
$parent_id = intval(trim($_GET['parentid']));//父ID<br>
$region = D("region");<br>
$regionarr = $region->where(" parent_id=".$parent_id)->select();<br>
if( $_GET['regiontype']=="" ){<br>
$region_type = '0';<br>
$regionts = "新增1级地区";<br>
}else{<br>
if($regionarr[0]['Id'] == ""){<br>
//取出上一级的region_type<br>
$regiontypearr = $region->where('id='.$parent_id)->field('region_type')->find();<br>
<br>
$region_type = $regiontypearr['region_type']+1;<br>
}else{<br>
$region_type = $regionarr[0]['region_type'];<br>
}<br>
$regionts = $region_type+1;<br>
$regionts = "新增".$regionts."级地区";<br>
}<br>
<br>
$this->assign("region_type",$region_type);//属于省份还是市<br>
$region_typeyuanshi=$region_type-1;<br>
$this->assign("region_typeyuanshi",$region_typeyuanshi);<br>
$this->assign("regionts",$regionts);//文字提示<br>
<br>
if( $regionarr[0]['parent_id'] != 0){<br>
$fuidarr = $region->where("id=".$regionarr[0]['parent_id'])->find();//用fuID去取fuID的parent_id;<br>
$this->assign("fuID", $fuidarr['parent_id'] );//返回上一级的时候,取的fuID<br>
}<br>
<br>
if( $region_type == 0 ){<br>
$this->assign('Id', '0' );<br>
}else{<br>
$this->assign('Id', $parent_id );<br>
}<br>
$this->assign('list',$regionarr);<br>
<br>
<br>
$this->display();<br>
}<br>
<br>
function delRegion(){<br>
<br>
$region = D("Region");<br>
//删除<br>
if( $_GET['regionid'] != "" ){<br>
//先判断是否有子分类<br>
$regionid= intval( $_GET['regionid'] );<br>
$ziarr = $region->where("parent_id=".$regionid)->select();<br>
if( $ziarr[0]['Id'] != "" ){<br>
$this->error("请先删除子分类!");<br>
}else{<br>
$region->Id=$regionid;<br>
if($region->delete()){<br>
$this->success();<br>
}else{<br>
$this->error("删除失败");<br>
}<br>
}<br>
}<br>
}<br>
<br>
public function add(){<br>
$Region = D('Region');<br>
$region_name=trim($_POST['region_name']);<br>
if(!$region_name) $this->error("新增地区不能为空!");<br>
$Region->region_name = $region_name;<br>
$Region->region_type = trim($_POST['region_type']);<br>
$Region->parent_id = trim($_POST['parent_id']);<br>
if($Region->add()){<br>
$this->success('添加成功!');<br>
}else{<br>
$this->error($Region->getError());<br>
}<br>
}
数据库结构:CREATE TABLE `sp_region` (<br>
`Id` INT(11) NOT NULL AUTO_INCREMENT,<br>
`parent_id` INT(11) DEFAULT NULL,<br>
`region_name` VARCHAR(120) CHARACTER SET gbk DEFAULT NULL,<br>
`region_type` SMALLINT(5) DEFAULT NULL,<br>
`agency_id` SMALLINT(5) UNSIGNED NOT NULL DEFAULT '0',<br>
`is_show` SMALLINT(5) NOT NULL DEFAULT '0',<br>
PRIMARY KEY (`Id`)<br>
) ENGINE=MYISAM AUTO_INCREMENT=3417 DEFAULT CHARSET=utf8 COLLATE=utf8_bin
数据的话,ecshop 里面region 表和其一样。
AD:真正免费,域名+虚机+企业邮箱=0元