Commit 5cfde9dd by felix

后台更新

parent 80e4219f
<?php <?php
require_once(PLUGIN_DIR . 'Dao/SearchDao.php'); require_once(PLUGIN_DIR . 'Dao/SearchDao.php');
require_once(PLUGIN_DIR . 'Dao/InsertDao.php'); require_once(PLUGIN_DIR . 'Dao/InsertDao.php');
require_once(PLUGIN_DIR . 'Tools/Image.php'); require_once(PLUGIN_DIR . 'Tools/Image.php');
require_once(PLUGIN_DIR . 'Tools/Core.php'); require_once(PLUGIN_DIR . 'Tools/Core.php');
require_once(PLUGIN_DIR . 'Admin/Tospur_House.php'); require_once(PLUGIN_DIR . 'Admin/Tospur_House.php');
class House extends Tospur_House{ class House extends Tospur_House{
public static function init_view(){ public static function init_view(){
wp_enqueue_script('jquery-ui'); wp_enqueue_script('jquery-ui');
wp_enqueue_script('bootstrapjs'); wp_enqueue_script('bootstrapjs');
wp_enqueue_style('jquery-ui_css'); wp_enqueue_script('validate');
wp_enqueue_style('bootstrapcss'); wp_enqueue_style('jquery-ui_css');
wp_enqueue_style('bootstrapcss');
global $wpdb; wp_enqueue_style('bootstrapMinCss');
$type = $_POST["type"];
$context = array(); global $wpdb;
$context['siteUrl'] = get_site_url(); $type = $_POST["type"];
if($type==1){ $context = array();
$insert_tospur_house_array = array( $context['siteUrl'] = get_site_url();
'name' => $_POST['housename'], if($type==1){
'average_price' => $_POST['average_price'], $insert_tospur_house_array = array(
'latest_news' => $_POST['latest_news'], 'name' => $_POST['housename'],
'address' => $_POST['address'], 'average_price' => $_POST['average_price'],
'traffic' => $_POST['traffic'], 'latest_news' => $_POST['latest_news'],
'periphery' => $_POST['periphery'], 'address' => $_POST['address'],
'developer' => $_POST['developers'], 'traffic' => $_POST['traffic'],
'check_in_time' => $_POST['check_in_time'], 'periphery' => $_POST['periphery'],
'property_age' => $_POST['property_age'], 'developer' => $_POST['developers'],
'decoration' => $_POST['decoration'], 'check_in_time' => $_POST['check_in_time'],
'covered_area' => $_POST['covered_area'], 'property_age' => $_POST['property_age'],
'volume_rate' => $_POST['volume_rate'], 'decoration' => $_POST['decoration'],
'greening_rate' => $_POST['greening_rate'], 'covered_area' => $_POST['covered_area'],
'households' => $_POST['households'], 'volume_rate' => $_POST['volume_rate'],
'parking_spaces' => $_POST['parking_spaces'], 'greening_rate' => $_POST['greening_rate'],
'property_management' => $_POST['property_management'], 'households' => $_POST['households'],
'overview' => $_POST['overview'], 'parking_spaces' => $_POST['parking_spaces'],
'city_id' => $_POST['baseCity'], 'property_management' => $_POST['property_management'],
'district_id' => $_POST['baseAreaId'], 'overview' => $_POST['overview'],
'plate_id' => $_POST["basePlateId"], 'city_id' => $_POST['baseCity'],
'room_id' => $_POST['baseRoom'], 'district_id' => $_POST['baseAreaId'],
"location" => $_POST["location"], 'plate_id' => $_POST["basePlateId"],
'status' =>$_POST['status'], 'room_id' => $_POST['baseRoom'],
"property_money" => $_POST["property_money"], "location" => $_POST["location"],
'community_name' => $_POST["community_name"], 'status' =>$_POST['status'],
); "property_money" => $_POST["property_money"],
$wpdb->query("START TRANSACTION"); 'community_name' => $_POST["community_name"],
if(isset($_POST['houseId'])){ );
$result = House::data_update($_POST['houseId'],$insert_tospur_house_array); $wpdb->query("START TRANSACTION");
if($result != 203){ if(isset($_POST['houseId'])){
$wpdb->query("ROLLBACK"); $result = House::data_update($_POST['houseId'],$insert_tospur_house_array);
print_r($result); if($result != 203){
echo "新房房源修改失败"; $wpdb->query("ROLLBACK");
}else{ print_r($result);
$wpdb->query("COMMIT"); echo "新房房源修改失败";
echo "新房房源修改成功"; }else{
} $wpdb->query("COMMIT");
}else{ echo "新房房源修改成功";
$result = House::data_insert($insert_tospur_house_array); }
print_r($result); }else{
if($result != 200){ $result = House::data_insert($insert_tospur_house_array);
$wpdb->query("ROLLBACK"); if($result != 200){
print_r($result);; $wpdb->query("ROLLBACK");
echo "新增房源失败"; print_r($result);;
}else{ echo "新增房源失败";
$wpdb->query("COMMIT"); }else{
echo "新增房源成功"; $wpdb->query("COMMIT");
} echo "新增房源成功";
} }
exit; }
}else if(isset($_GET['edit'])){ exit;
$context['houseId'] = $_GET['id']; }else if(isset($_GET['edit'])){
$context = array_merge($context,SearchDao::getDetailInfo($_GET['id'],"edit")); $context['houseId'] = $_GET['id'];
$context["district"] = SearchDao::searchCity($context['result']->city_id); $context = array_merge($context,SearchDao::getDetailInfo($_GET['id'],"edit"));
$context["plate"] = SearchDao::searchCity($context['result']->city_id,$context['result']->district_id); $context["district"] = SearchDao::searchCity($context['result']->city_id);
$context["mark"] = SearchDao::searchHouseTag($_GET['id']); $context["plate"] = SearchDao::searchCity($context['result']->city_id,$context['result']->district_id);
} $context["mark"] = SearchDao::searchHouseTag($_GET['id']);
$context['role'] = SecHandHouse::getCurrentRole(); }
$context["city"] = SearchDao::searchCity(); $context['role'] = SecHandHouse::getCurrentRole();
$context["buildProperty"] = SearchDao::searchBuildProperty(); $context["city"] = SearchDao::searchCity();
$context["room"] = SearchDao::searchRoom(); $context["buildProperty"] = SearchDao::searchBuildProperty();
$context["photoType"] = SearchDao::searchPhotoType(); $context["room"] = SearchDao::searchRoom();
$context["status"] = searchDao::searchStatusType(1); $context["photoType"] = SearchDao::searchPhotoType();
Timber::render("newhouse.html",$context); $context["status"] = searchDao::searchStatusType(1);
} Timber::render("newhouse.html",$context);
}
public static function data_update($houseId,$insert_tospur_house_array){
global $wpdb; public static function data_update($houseId,$insert_tospur_house_array){
$data = $_POST["data"]; global $wpdb;
$wpdb->update(Config::TOSPUR_HOUSE_TABLE,$insert_tospur_house_array,array("id" => $houseId)); $data = $_POST["data"];
$result = 203; $wpdb->update(Config::TOSPUR_HOUSE_TABLE,$insert_tospur_house_array,array("id" => $houseId));
$exist_ids = array(); $result = 203;
if(isset($_POST['exists'])){ $exist_ids = array();
foreach($_POST['exists'] as $id => $item){ if(isset($_POST['exists'])){
$wpdb->update(Config::A_DISTRICT_AREA_TABLE,array( foreach($_POST['exists'] as $id => $item){
"buildproperty_id" => $item['buildProperty'], $wpdb->update(Config::A_DISTRICT_AREA_TABLE,array(
"house_area" => $item['housearea'] "buildproperty_id" => $item['buildProperty'],
),array("image_id" => $id)); "house_area" => $item['housearea']
$exist_ids[] = $id; ),array("image_id" => $id));
} $exist_ids[] = $id;
$old_exists_ids = explode(",",$_POST['exists_ids']); }
$delete_ids = array(); $old_exists_ids = explode(",",$_POST['exists_ids']);
foreach(array_diff($old_exists_ids,$exist_ids) as $key => $id){ $delete_ids = array();
$delete_ids[] = $id; foreach(array_diff($old_exists_ids,$exist_ids) as $key => $id){
} $delete_ids[] = $id;
$delete_ids = implode(",",$delete_ids); }
$wpdb->query("delete from ".Config::A_DISTRICT_AREA_TABLE." where house_id = {$houseId} and image_id in ({$delete_ids});"); $delete_ids = implode(",",$delete_ids);
$wpdb->query("delete from ".Config::A_HOUSE_IMAGE_TABLE." where house_id = {$houseId} and image_id in ({$delete_ids});"); $wpdb->query("delete from ".Config::A_DISTRICT_AREA_TABLE." where house_id = {$houseId} and image_id in ({$delete_ids});");
} $wpdb->query("delete from ".Config::A_HOUSE_IMAGE_TABLE." where house_id = {$houseId} and image_id in ({$delete_ids});");
InsertDao::addMainImage($houseId,$data); }
InsertDao::addMainImage($houseId,$data);
$exists_photo_ids = array();
if(isset($_POST['exists_photo'])){ $exists_photo_ids = array();
foreach($_POST['exists_photo'] as $id => $item){ if(isset($_POST['exists_photo'])){
$wpdb->update(Config::TOSPUR_IMAGE_TABLE,array( foreach($_POST['exists_photo'] as $id => $item){
"image_type" => $item['type'], $wpdb->update(Config::TOSPUR_IMAGE_TABLE,array(
),array("id" => $id)); "image_type" => $item['type'],
$exists_photo_ids[] = $id; ),array("id" => $id));
} $exists_photo_ids[] = $id;
} }
$old_exists_photo_ids = explode(",",$_POST['exists_photo_ids']); }
$delete_photo_ids = array(); $old_exists_photo_ids = explode(",",$_POST['exists_photo_ids']);
foreach(array_diff($old_exists_photo_ids,$exists_photo_ids) as $key => $id){ $delete_photo_ids = array();
$delete_photo_ids[] = $id; foreach(array_diff($old_exists_photo_ids,$exists_photo_ids) as $key => $id){
} $delete_photo_ids[] = $id;
$delete_photo_ids = implode(",",$delete_photo_ids); }
$wpdb->query("delete from ".Config::A_HOUSE_IMAGE_TABLE." where house_id = {$houseId} and image_id in ({$delete_photo_ids});"); $delete_photo_ids = implode(",",$delete_photo_ids);
$wpdb->query("delete from ".Config::A_HOUSE_IMAGE_TABLE." where house_id = {$houseId} and image_id in ({$delete_photo_ids});");
$wpdb->delete(Config::A_HOUSE_RECOMMEND_TABLE,array("house_id" => $houseId));
$res = InsertDao::addRecommend($houseId,$data); $wpdb->delete(Config::A_HOUSE_RECOMMEND_TABLE,array("house_id" => $houseId));
if($res == 504){ $res = InsertDao::addRecommend($houseId,$data);
$result = $res; if($res == 504){
echo "推荐房源修改失败"; $result = $res;
} echo "推荐房源修改失败";
}
$wpdb->delete(Config::A_HOUSE_USER_TABLE,array("house_id" => $houseId));
$res = InsertDao::addRecConsultant($houseId,$data); $wpdb->delete(Config::A_HOUSE_USER_TABLE,array("house_id" => $houseId));
if($res == 505){ $res = InsertDao::addRecConsultant($houseId,$data);
$result = $res; if($res == 505){
echo "推荐置业顾问修改失败"; $result = $res;
} echo "推荐置业顾问修改失败";
InsertDao::addHouseTag($_POST['mark'],$houseId); }
return $result; InsertDao::addHouseTag($_POST['mark'],$houseId);
} return $result;
}
public static function data_insert($params){
global $wpdb; public static function data_insert($params){
//房源与类型以及面积信息 global $wpdb;
$data = $_POST["data"]; //房源与类型以及面积信息
//获取新房信息,存入tospur_house表 $data = $_POST["data"];
$params['user_id'] = get_current_user_id(); //获取新房信息,存入tospur_house表
$params['creattime'] = date("Y-m-d H:i:s"); $params['user_id'] = get_current_user_id();
$params['house_type'] = 0; $params['creattime'] = date("Y-m-d H:i:s");
$res = $wpdb->get_results('SELECT * FROM tospur_house WHERE name="' . $_POST['housename'] . '" and address="' . $_POST['address'] . '" and house_type=0', OBJECT); $params['house_type'] = 0;
if (!$res) { $res = $wpdb->get_results('SELECT * FROM tospur_house WHERE name="' . $_POST['housename'] . '" and address="' . $_POST['address'] . '" and house_type=0', OBJECT);
$houseId = InsertDao::insert_tospur_house($params); if (!$res) {
$houseId = InsertDao::insert_tospur_house($params);
InsertDao::addMainImage($houseId,$data);
InsertDao::addMainImage($houseId,$data);
InsertDao::addRecommend($houseId,$data);
InsertDao::addRecommend($houseId,$data);
InsertDao::addRecConsultant($houseId,$data);
InsertDao::addRecConsultant($houseId,$data);
InsertDao::addHouseTag($_POST['mark'],$houseId);
InsertDao::addHouseTag($_POST['mark'],$houseId);
}else{
return 506; }else{
} return 506;
return 200; }
} return 200;
}
} }
\ No newline at end of file
<?php <?php
class Tospur_House{ class Tospur_House{
public static function getCurrentRole(){ public static function getCurrentRole(){
$current_user = wp_get_current_user(); $current_user = wp_get_current_user();
if ( !($current_user instanceof WP_User) ) if ( !($current_user instanceof WP_User) )
return; return;
$roles = $current_user->roles; $roles = $current_user->roles;
return $roles[0]; return $roles[0];
} }
} }
\ No newline at end of file
<?php <?php
if (!class_exists('WP_List_Table')) { if (!class_exists('WP_List_Table')) {
require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table.php'); require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table.php');
} }
class newHouseList extends WP_List_Table class newHouseList extends WP_List_Table
{ {
function __construct() function __construct()
{ {
global $status, $page; global $status, $page;
//Set parent defaults //Set parent defaults
parent::__construct(array( parent::__construct(array(
'singular' => 'newHouseList', //singular name of the listed records 'singular' => 'newHouseList', //singular name of the listed records
'plural' => 'newHouseLists', //plural name of the listed records 'plural' => 'newHouseLists', //plural name of the listed records
'ajax' => false //does this table support ajax? 'ajax' => false //does this table support ajax?
)); ));
} }
function column_default($item, $column_name) function column_default($item, $column_name)
{ {
switch ($column_name) { switch ($column_name) {
case'id': case'id':
case 'name': case 'name':
case 'address': case 'address':
case 'average_price': case 'average_price':
case 'developer': case 'developer':
case 'check_in_time': case 'check_in_time':
case 'room_id': case 'room_id':
case 'property_age': case 'property_age':
case 'decoration': case 'decoration':
case 'covered_area': case 'covered_area':
case 'status': case 'status':
case 'volume_rate': case 'volume_rate':
case 'greening_rate': case 'greening_rate':
case 'households': case 'households':
case 'parking_spaces': case 'parking_spaces':
case 'property_management': case 'property_management':
case 'property_money': case 'property_money':
default: default:
return '<a href="' . admin_url() . 'admin.php?page=newHouse&edit=true&id=' . $item['id'] . '">' . $item[$column_name] . '</a>'; return '<a href="' . admin_url() . 'admin.php?page=newHouse&edit=true&id=' . $item['id'] . '">' . $item[$column_name] . '</a>';
} }
} }
function column_cb($item) function column_cb($item)
{ {
return sprintf( return sprintf(
'<input type="checkbox" name="%1$s[]" value="%2$s" />', '<input type="checkbox" name="%1$s[]" value="%2$s" />',
/*$1%s*/ /*$1%s*/
$this->_args['singular'], //Let's simply repurpose the table's singular label ("score") $this->_args['singular'], //Let's simply repurpose the table's singular label ("score")
/*$2%s*/ /*$2%s*/
$item['id'] //The value of the checkbox should be the record's id $item['id'] //The value of the checkbox should be the record's id
); );
} }
function get_columns() function get_columns()
{ {
if( current_user_can('administrator') ) { if( current_user_can('administrator') ) {
$columns = array( $columns = array(
'cb' => '<input type="checkbox" />' 'cb' => '<input type="checkbox" />'
); );
} }
$columns['id']= 'ID'; $columns['id']= 'ID';
$columns['name']= '楼盘名'; $columns['name']= '楼盘名';
$columns['address']= '地址'; $columns['address']= '地址';
$columns['average_price']= '单价'; $columns['average_price']= '单价';
$columns['developer']= '开发商'; $columns['developer']= '开发商';
$columns['check_in_time']= '入住时间'; $columns['check_in_time']= '入住时间';
$columns['room_id']= '建筑类型'; $columns['room_id']= '建筑类型';
$columns['property_age']= '产权年限'; $columns['property_age']= '产权年限';
$columns['decoration']= '装修状况'; $columns['decoration']= '装修状况';
$columns['covered_area']= '建筑面积'; $columns['covered_area']= '建筑面积';
$columns['volume_rate']= '容积率'; $columns['volume_rate']= '容积率';
$columns['greening_rate']= '绿化率'; $columns['greening_rate']= '绿化率';
$columns['households']= '规划户数'; $columns['households']= '规划户数';
$columns['parking_spaces']= '车位数'; $columns['parking_spaces']= '车位数';
$columns['property_management']= '物业公司'; $columns['property_management']= '物业公司';
$columns['property_money']= '物业费'; $columns['property_money']= '物业费';
$columns['status']= '状态'; $columns['status']= '状态';
return $columns; return $columns;
} }
function get_sortable_columns() function get_sortable_columns()
{ {
$sortable_columns = array( $sortable_columns = array(
'id' => array('id', false), 'id' => array('id', false),
'name' => array('name', false), 'name' => array('name', false),
'address' => array('address', false), 'address' => array('address', false),
'average_price' => array('average_price', false), 'average_price' => array('average_price', false),
'developer' => array('developer', false), 'developer' => array('developer', false),
'check_in_time' => array('check_in_time', false), 'check_in_time' => array('check_in_time', false),
'room_id' => array('room_id', false), 'room_id' => array('room_id', false),
'property_age' => array('property_age', false), 'property_age' => array('property_age', false),
'decoration' => array('decoration', false), 'decoration' => array('decoration', false),
'covered_area' => array('covered_area', false), 'covered_area' => array('covered_area', false),
'status' => array('status', false), 'status' => array('status', false),
'volume_rate' => array('valvolume_rateid', false), 'volume_rate' => array('valvolume_rateid', false),
'greening_rate' => array('greening_rate', false), 'greening_rate' => array('greening_rate', false),
'households' => array('households', false), 'households' => array('households', false),
'parking_spaces' => array('parking_spaces', false), 'parking_spaces' => array('parking_spaces', false),
'property_management' => array('property_management', false), 'property_management' => array('property_management', false),
'property_money' => array('property_money', false), 'property_money' => array('property_money', false),
); );
return $sortable_columns; return $sortable_columns;
} }
function get_bulk_actions() function get_bulk_actions()
{ {
$actions = array( $actions = array(
'noCheck' => '未审核', 'noCheck' => '未审核',
'check' => '审核', 'check' => '审核',
'stopSale' =>'下架' 'stopSale' =>'下架'
); );
return $actions; return $actions;
} }
function process_bulk_action() function process_bulk_action()
{ {
$action = $this->current_action(); $action = $this->current_action();
if ($action) { if ($action) {
$string = null; $string = null;
$status = null; $status = null;
switch ($action) { switch ($action) {
case 'noCheck': case 'noCheck':
$id = $_POST['newhouselist']; $id = $_POST['newhouselist'];
if ($id) { if ($id) {
$string = '(' . implode(',', array_map('intval', $id)) . ')'; $string = '(' . implode(',', array_map('intval', $id)) . ')';
$status = 0; $status = 0;
} }
break; break;
case 'check': case 'check':
$id = $_POST['newhouselist']; $id = $_POST['newhouselist'];
if ($id) { if ($id) {
$string = '(' . implode(',', array_map('intval', $id)) . ')'; $string = '(' . implode(',', array_map('intval', $id)) . ')';
$status = 1; $status = 1;
} }
break; break;
case 'stopSale': case 'stopSale':
$id = $_POST['newhouselist']; $id = $_POST['newhouselist'];
if ($id) { if ($id) {
$string = '(' . implode(',', array_map('intval', $id)) . ')'; $string = '(' . implode(',', array_map('intval', $id)) . ')';
$status = 2; $status = 2;
} }
break; break;
} }
global $wpdb; global $wpdb;
$result = $wpdb->query('update tospur_house SET status='.$status .' where id in ' . $string); $result = $wpdb->query('update tospur_house SET status='.$status .' where id in ' . $string);
} }
} }
function prepare_items() function prepare_items()
{ {
global $wpdb; global $wpdb;
$per_page = 10; $per_page = 10;
$columns = $this->get_columns(); $columns = $this->get_columns();
$hidden = array(); $hidden = array();
$sortable = $this->get_sortable_columns(); $sortable = $this->get_sortable_columns();
$this->_column_headers = array($columns, $hidden, $sortable); $this->_column_headers = array($columns, $hidden, $sortable);
$this->process_bulk_action(); $this->process_bulk_action();
//$data = $this->example_data; //$data = $this->example_data;
$sql = "select * from tospur_house th $sql = "select * from tospur_house th
left join (select buildproperty_id,house_area,image_id,house_id as bph_id from a_district_area) ada on th.id = ada.bph_id left join (select buildproperty_id,house_area,image_id,house_id as bph_id from a_district_area) ada on th.id = ada.bph_id
left join (select value as did,literal as room_type from dic_room) dr on dr.did = th.room_id left join (select value as did,literal as room_type from dic_room) dr on dr.did = th.room_id
where 1=1 and house_type=0"; where 1=1 and house_type=0";
if($_POST["listCity"]!=0 ){ if($_POST["listCity"]!=0 ){
$sql = $sql." and city_id=".$_POST["listCity"]; $sql = $sql." and city_id=".$_POST["listCity"];
} }
if($_POST["listDistrict"] != 0 ){ if($_POST["listDistrict"] != 0 ){
$sql = $sql." and district_id=".$_POST["listDistrict"]; $sql = $sql." and district_id=".$_POST["listDistrict"];
} }
if($_POST["listPlate"] != 0){ if($_POST["listPlate"] != 0){
$sql = $sql." and plate_id=".$_POST["listPlate"]; $sql = $sql." and plate_id=".$_POST["listPlate"];
} }
if($_POST["buildProperty"]!=0){ if($_POST["buildProperty"]!=0){
$sql = $sql." and buildproperty_id=".$_POST["buildProperty"]; $sql = $sql." and buildproperty_id=".$_POST["buildProperty"];
} }
if($_POST["room"]!=0){ if($_POST["room"]!=0){
$sql = $sql." and room_id=".$_POST["room"]; $sql = $sql." and room_id=".$_POST["room"];
} }
if(isset($_POST["status"]) && $_POST["status"]!=-1){ if(isset($_POST["status"]) && $_POST["status"]!=-1){
$sql = $sql." and status=".$_POST["status"]; $sql = $sql." and status=".$_POST["status"];
} }
if($_POST["totalPrice"]!=NULL){ if($_POST["totalPrice"]!=NULL){
$priceArray = explode("-", $_POST['totalPrice']); $priceArray = explode("-", $_POST['totalPrice']);
$sql = $sql . " and average_price between ".$priceArray[0]." and ".$priceArray[1]; $sql = $sql . " and average_price between ".$priceArray[0]." and ".$priceArray[1];
} }
if($_POST["acreage"]!= NULL){ if($_POST["acreage"]!= NULL){
$areaArray = explode("-", $_POST['acreage']); $areaArray = explode("-", $_POST['acreage']);
$sql = $sql . " and covered_area between ".$areaArray[0]." and ".$areaArray[1]; $sql = $sql . " and covered_area between ".$areaArray[0]." and ".$areaArray[1];
} }
if($_POST["searchText"]!=NULL){ if($_POST["searchText"]!=NULL){
$sql = $sql . " and name like '%".$_POST['searchText']."%'"; $sql = $sql . " and name like '%".$_POST['searchText']."%'";
} }
$sql = $sql . " group by id"; $sql = $sql . " group by id";
$result = $wpdb->get_results($sql); $result = $wpdb->get_results($sql);
$data = array(); $data = array();
foreach ($result as $key => $value) { foreach ($result as $key => $value) {
$data[$key] = array( $data[$key] = array(
'id' => $value->id, 'id' => $value->id,
'name' => $value->name, 'name' => $value->name,
'address' => $value->address, 'address' => $value->address,
'average_price' => $value->average_price, 'average_price' => $value->average_price,
'developer' => $value->developer, 'developer' => $value->developer,
'check_in_time' => $value->check_in_time, 'check_in_time' => $value->check_in_time,
'room_id' => $value->room_type, 'room_id' => $value->room_type,
'property_age' => $value->property_age, 'property_age' => $value->property_age,
'decoration' => $value->decoration, 'decoration' => $value->decoration,
'covered_area' => $value->covered_area, 'covered_area' => $value->covered_area,
'volume_rate' => $value->volume_rate, 'volume_rate' => $value->volume_rate,
'greening_rate' => $value->greening_rate, 'greening_rate' => $value->greening_rate,
'households' => $value->households, 'households' => $value->households,
'parking_spaces' => $value->parking_spaces, 'parking_spaces' => $value->parking_spaces,
'property_management' => $value->property_management, 'property_management' => $value->property_management,
'property_money' => $value->property_money 'property_money' => $value->property_money
); );
if($value->status == 0){ if($value->status == 0){
$data[$key]['status'] ="未审核"; $data[$key]['status'] ="未审核";
}else if($value->status == 1){ }else if($value->status == 1){
$data[$key]['status'] ="审核"; $data[$key]['status'] ="审核";
}else if($value->status == 2){ }else if($value->status == 2){
$data[$key]['status'] ="下架"; $data[$key]['status'] ="下架";
} }
} }
function usort_reorder($a, $b) function usort_reorder($a, $b)
{ {
$orderby = (!empty($_REQUEST['orderby'])) ? $_REQUEST['orderby'] : 'valid'; //If no sort, default to title $orderby = (!empty($_REQUEST['orderby'])) ? $_REQUEST['orderby'] : 'valid'; //If no sort, default to title
$order = (!empty($_REQUEST['order'])) ? $_REQUEST['order'] : 'desc'; //If no order, default to asc $order = (!empty($_REQUEST['order'])) ? $_REQUEST['order'] : 'desc'; //If no order, default to asc
$result = strcmp($a[$orderby], $b[$orderby]); //Determine sort order $result = strcmp($a[$orderby], $b[$orderby]); //Determine sort order
return ($order === 'asc') ? $result : -$result; //Send final sort direction to usort return ($order === 'asc') ? $result : -$result; //Send final sort direction to usort
} }
usort($data, 'usort_reorder'); usort($data, 'usort_reorder');
$current_page = $this->get_pagenum(); $current_page = $this->get_pagenum();
$total_items = count($data); $total_items = count($data);
$data = array_slice($data, (($current_page - 1) * $per_page), $per_page); $data = array_slice($data, (($current_page - 1) * $per_page), $per_page);
$this->items = $data; $this->items = $data;
$this->set_pagination_args(array( $this->set_pagination_args(array(
'total_items' => $total_items, //WE have to calculate the total number of items 'total_items' => $total_items, //WE have to calculate the total number of items
'per_page' => $per_page, //WE have to determine how many items to show on a page 'per_page' => $per_page, //WE have to determine how many items to show on a page
'total_pages' => ceil($total_items / $per_page) //WE have to calculate the total number of pages 'total_pages' => ceil($total_items / $per_page) //WE have to calculate the total number of pages
)); ));
} }
} }
add_action( 'wp_ajax_updateList', 'newHouseList::prepare_items'); add_action( 'wp_ajax_updateList', 'newHouseList::prepare_items');
add_action( 'wp_ajax_nopriv_updateList', 'newHouseList::prepare_items'); add_action( 'wp_ajax_nopriv_updateList', 'newHouseList::prepare_items');
add_action( 'wp_ajax_searchListCity', 'SearchDao::ajax_searchListCity'); add_action( 'wp_ajax_searchListCity', 'SearchDao::ajax_searchListCity');
add_action( 'wp_ajax_nopriv_searchListCity', 'SearchDao::ajax_searchListCity'); add_action( 'wp_ajax_nopriv_searchListCity', 'SearchDao::ajax_searchListCity');
function function_newHouseList() function function_newHouseList()
{ {
$contest = array(); $contest = array();
$contest['page'] = $_REQUEST['page']; $contest['page'] = $_REQUEST['page'];
$contest['city'] = SearchDao::searchCity(); $contest['city'] = SearchDao::searchCity();
$contest['status'] = SearchDao::searchStatusType(1); $contest['status'] = SearchDao::searchStatusType(1);
$contest['buildProperty'] = SearchDao::searchBuildProperty(); $contest['buildProperty'] = SearchDao::searchBuildProperty();
$contest['room'] = searchDao::searchRoom(); $contest['room'] = searchDao::searchRoom();
if(isset($_POST['hasSearch'])){ if(isset($_POST['hasSearch'])){
$contest['district'] = SearchDao::searchCity($_POST['listCity']); $contest['district'] = SearchDao::searchCity($_POST['listCity']);
$contest['plate'] = SearchDao::searchCity($_POST['listCity'],$_POST['listDistrict']); $contest['plate'] = SearchDao::searchCity($_POST['listCity'],$_POST['listDistrict']);
$contest['dicTotalPrice'] = searchDao::searchTotalPrice($_POST['listCity']); $contest['dicTotalPrice'] = searchDao::searchTotalPrice($_POST['listCity']);
$contest['dicArea'] = searchDao::searchArea($_POST['listCity']); $contest['dicArea'] = searchDao::searchArea($_POST['listCity']);
$contest['cityId'] = $_POST['listCity']; $contest['cityId'] = $_POST['listCity'];
$contest['districtId'] = $_POST['listDistrict']; $contest['districtId'] = $_POST['listDistrict'];
$contest['plateId' ]= $_POST['listPlate']; $contest['plateId' ]= $_POST['listPlate'];
$contest['roomId']= $_POST['room']; $contest['roomId']= $_POST['room'];
$contest['buildPropertyId']= $_POST['buildProperty']; $contest['buildPropertyId']= $_POST['buildProperty'];
$contest['totalPrice'] = $_POST['totalPrice']; $contest['totalPrice'] = $_POST['totalPrice'];
$contest['acreage'] = $_POST['acreage']; $contest['acreage'] = $_POST['acreage'];
$contest['statusId'] = $_POST['status']; $contest['statusId'] = $_POST['status'];
} }
Timber::render("newHouseList.html",$contest); Timber::render("newHouseList.html",$contest);
} }
function addNewHouseTable(){ function addNewHouseTable(){
$newHouseList = new newHouseList(); $newHouseList = new newHouseList();
$newHouseList->prepare_items(); $newHouseList->prepare_items();
$newHouseList->display(); $newHouseList->display();
} }
?> ?>
<?php <?php
require_once(PLUGIN_DIR . 'Dao/SearchDao.php'); require_once(PLUGIN_DIR . 'Dao/SearchDao.php');
require_once(PLUGIN_DIR . 'Dao/InsertDao.php'); require_once(PLUGIN_DIR . 'Dao/InsertDao.php');
require_once(PLUGIN_DIR . 'Tools/Image.php'); require_once(PLUGIN_DIR . 'Tools/Image.php');
class RentHouse extends Tospur_House{ class RentHouse extends Tospur_House{
//二手房信息 //二手房信息
public static function rentHouse_html(){ public static function rentHouse_html(){
wp_enqueue_script('bootstrapjs'); wp_enqueue_script('bootstrapjs');
wp_enqueue_style('bootstrapcss'); wp_enqueue_style('bootstrapcss');
global $wpdb; global $wpdb;
$type = $_POST["type"]; $type = $_POST["type"];
$context = array(); $context = array();
$context['siteUrl'] = get_site_url(); $context['siteUrl'] = get_site_url();
//获取新房信息,存入tospur_house表 //获取新房信息,存入tospur_house表
$insert_tospur_house_array = array( $insert_tospur_house_array = array(
'name' => $_POST['housename'], 'name' => $_POST['housename'],
'house_number' =>$_POST['house_number'], 'house_number' =>$_POST['house_number'],
'rent'=>$_POST['rent'], 'rent'=>$_POST['rent'],
'buildproperty_id'=>$_POST['buildproperty_id'], 'buildproperty_id'=>$_POST['buildproperty_id'],
'covered_area' =>$_POST['covered_area'], 'covered_area' =>$_POST['covered_area'],
'floor' =>$_POST['floor'], 'floor' =>$_POST['floor'],
'faceto'=>$_POST['faceto'], 'faceto'=>$_POST['faceto'],
'decoration' => $_POST['decoration'], 'decoration' => $_POST['decoration'],
'age'=>$_POST['age'], 'age'=>$_POST['age'],
'matching_facilities'=>$_POST['matching_facilities'], 'matching_facilities'=>$_POST['matching_facilities'],
'flat'=>$_POST['flat'], 'flat'=>$_POST['flat'],
'suite'=>$_POST["suite"], 'suite'=>$_POST["suite"],
'overview' => $_POST['overview'], 'overview' => $_POST['overview'],
'city_id' => $_POST['baseCity'], 'city_id' => $_POST['baseCity'],
'district_id' => $_POST['baseAreaId'], 'district_id' => $_POST['baseAreaId'],
'plate_id' => $_POST["basePlateId"], 'plate_id' => $_POST["basePlateId"],
'address' => $_POST['address'], 'address' => $_POST['address'],
'community_name'=>$_POST['community_name'], 'community_name'=>$_POST['community_name'],
'traffic' => $_POST['traffic'], 'traffic' => $_POST['traffic'],
'periphery' => $_POST['periphery'], 'periphery' => $_POST['periphery'],
'status' =>$_POST['status'], 'status' =>$_POST['status'],
'owner_name'=>$_POST['owner_name'], 'owner_name'=>$_POST['owner_name'],
'owner_phone'=>$_POST['owner_phone'], 'owner_phone'=>$_POST['owner_phone'],
"location" => $_POST["location"], "location" => $_POST["location"],
); );
if($type==3){ if($type==3){
$wpdb->query("START TRANSACTION"); $wpdb->query("START TRANSACTION");
if(isset($_POST['houseId'])){ if(isset($_POST['houseId'])){
$result = RentHouse::data_update($_POST['houseId'],$insert_tospur_house_array); $result = RentHouse::data_update($_POST['houseId'],$insert_tospur_house_array);
if($result != 202){ if($result != 202){
$wpdb->query("ROLLBACK"); $wpdb->query("ROLLBACK");
print_r($result);; print_r($result);;
echo "租房房源修改失败"; echo "租房房源修改失败";
}else{ }else{
$wpdb->query("COMMIT"); $wpdb->query("COMMIT");
echo "租房房源修改成功"; echo "租房房源修改成功";
} }
}else { }else {
$result = RentHouse::rentHouseData_insert($insert_tospur_house_array); $result = RentHouse::rentHouseData_insert($insert_tospur_house_array);
if ($result != 200) { if ($result != 200) {
$wpdb->query("ROLLBACK"); $wpdb->query("ROLLBACK");
print_r($result);; print_r($result);;
echo "租房房源新增失败"; echo "租房房源新增失败";
} else { } else {
$wpdb->query("COMMIT"); $wpdb->query("COMMIT");
echo "租房房源新增成功"; echo "租房房源新增成功";
} }
} }
exit; exit;
}else if(isset($_GET['edit'])){ }else if(isset($_GET['edit'])){
$context['houseId'] = $_GET['id']; $context['houseId'] = $_GET['id'];
$context = array_merge($context,SearchDao::getDetailInfo($_GET['id'])); $context = array_merge($context,SearchDao::getDetailInfo($_GET['id']));
$context["district"] = SearchDao::searchCity($context['result']->city_id); $context["district"] = SearchDao::searchCity($context['result']->city_id);
$context["plate"] = SearchDao::searchCity($context['result']->city_id,$context['result']->district_id); $context["plate"] = SearchDao::searchCity($context['result']->city_id,$context['result']->district_id);
$context["mark"] = SearchDao::searchHouseTag($_GET['id']); $context["mark"] = SearchDao::searchHouseTag($_GET['id']);
} }
$context['role'] = SecHandHouse::getCurrentRole(); $context['role'] = SecHandHouse::getCurrentRole();
$context["city"] = SearchDao::searchCity(); $context["city"] = SearchDao::searchCity();
$context["buildProperty"] = SearchDao::searchBuildProperty(); $context["buildProperty"] = SearchDao::searchBuildProperty();
$context["room"] = SearchDao::searchRoom(); $context["room"] = SearchDao::searchRoom();
$context["photoType"] = SearchDao::searchPhotoType(); $context["photoType"] = SearchDao::searchPhotoType();
$context["status"] = searchDao::searchStatusType(2); $context["status"] = searchDao::searchStatusType(2);
Timber::render("rentHouse.html",$context); Timber::render("rentHouse.html",$context);
} }
public static function rentHouseData_insert($params) public static function rentHouseData_insert($params)
{ {
global $wpdb; global $wpdb;
//房源与类型以及面积信息 //房源与类型以及面积信息
$data = $_POST["data"]; $data = $_POST["data"];
$params['user_id'] = get_current_user_id(); $params['user_id'] = get_current_user_id();
$params['creattime'] = date("Y-m-d H:i:s"); $params['creattime'] = date("Y-m-d H:i:s");
$params['house_type'] = 2; $params['house_type'] = 2;
$res = $wpdb->get_results('SELECT * FROM tospur_house WHERE address="' .$params['address'] . '" and owner_name="' .$params['owner_name'] . '" and owner_phone="'.$params['owner_phone'].'" and house_type=2', OBJECT); $res = $wpdb->get_results('SELECT * FROM tospur_house WHERE address="' .$params['address'] . '" and owner_name="' .$params['owner_name'] . '" and owner_phone="'.$params['owner_phone'].'" and house_type=2', OBJECT);
if(!$res){ if(!$res){
$houseId = InsertDao::insert_tospur_house($params); $houseId = InsertDao::insert_tospur_house($params);
InsertDao::addMainImage($houseId,$data); InsertDao::addMainImage($houseId,$data);
InsertDao::addRecommend($houseId,$data); InsertDao::addRecommend($houseId,$data);
InsertDao::addRecConsultant($houseId,$data); InsertDao::addRecConsultant($houseId,$data);
InsertDao::addHouseTag($_POST['mark'],$houseId); InsertDao::addHouseTag($_POST['mark'],$houseId);
}else{ }else{
return 508; return 508;
} }
return 200; return 200;
} }
public static function data_update($houseId,$params){ public static function data_update($houseId,$params){
global $wpdb; global $wpdb;
$data = $_POST["data"]; $data = $_POST["data"];
$res = $wpdb->update(Config::TOSPUR_HOUSE_TABLE,$params,array("id" => $houseId)); $res = $wpdb->update(Config::TOSPUR_HOUSE_TABLE,$params,array("id" => $houseId));
$result = 202; $result = 202;
InsertDao::addMainImage($houseId,$data); InsertDao::addMainImage($houseId,$data);
$exists_photo_ids = array(); $exists_photo_ids = array();
if(isset($_POST['exists_photo'])){ if(isset($_POST['exists_photo'])){
foreach($_POST['exists_photo'] as $id => $item){ foreach($_POST['exists_photo'] as $id => $item){
$wpdb->update(Config::TOSPUR_IMAGE_TABLE,array( $wpdb->update(Config::TOSPUR_IMAGE_TABLE,array(
"image_type" => $item['type'], "image_type" => $item['type'],
),array("id" => $id)); ),array("id" => $id));
$exists_photo_ids[] = $id; $exists_photo_ids[] = $id;
} }
} }
$old_exists_photo_ids = explode(",",$_POST['exists_photo_ids']); $old_exists_photo_ids = explode(",",$_POST['exists_photo_ids']);
$delete_photo_ids = array(); $delete_photo_ids = array();
foreach(array_diff($old_exists_photo_ids,$exists_photo_ids) as $key => $id){ foreach(array_diff($old_exists_photo_ids,$exists_photo_ids) as $key => $id){
$delete_photo_ids[] = $id; $delete_photo_ids[] = $id;
} }
$delete_photo_ids = implode(",",$delete_photo_ids); $delete_photo_ids = implode(",",$delete_photo_ids);
$wpdb->query("delete from ".Config::A_HOUSE_IMAGE_TABLE." where house_id = {$houseId} and image_id in ({$delete_photo_ids});"); $wpdb->query("delete from ".Config::A_HOUSE_IMAGE_TABLE." where house_id = {$houseId} and image_id in ({$delete_photo_ids});");
$wpdb->delete(Config::A_HOUSE_RECOMMEND_TABLE,array("house_id" => $houseId)); $wpdb->delete(Config::A_HOUSE_RECOMMEND_TABLE,array("house_id" => $houseId));
InsertDao::addRecommend($houseId,$data); InsertDao::addRecommend($houseId,$data);
$wpdb->delete(Config::A_HOUSE_USER_TABLE,array("house_id" => $houseId)); $wpdb->delete(Config::A_HOUSE_USER_TABLE,array("house_id" => $houseId));
InsertDao::addRecConsultant($houseId,$data); InsertDao::addRecConsultant($houseId,$data);
InsertDao::addHouseTag($_POST['mark'],$houseId); InsertDao::addHouseTag($_POST['mark'],$houseId);
return $result; return $result;
} }
} }
<?php <?php
if (!class_exists('WP_List_Table')) { if (!class_exists('WP_List_Table')) {
require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table.php'); require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table.php');
} }
class rentHouseList extends WP_List_Table class rentHouseList extends WP_List_Table
{ {
function __construct() function __construct()
{ {
global $status, $page; global $status, $page;
//Set parent defaults //Set parent defaults
parent::__construct(array( parent::__construct(array(
'singular' => 'rentHouseList', //singular name of the listed records 'singular' => 'rentHouseList', //singular name of the listed records
'plural' => 'rentHouseList', //plural name of the listed records 'plural' => 'rentHouseList', //plural name of the listed records
'ajax' => false //does this table support ajax? 'ajax' => false //does this table support ajax?
)); ));
} }
function column_default($item, $column_name) function column_default($item, $column_name)
{ {
switch ($column_name) { switch ($column_name) {
case'id': case'id':
case 'name': case 'name':
case 'community_name': case 'community_name':
case 'rent': case 'rent':
case 'buildproperty_id': case 'buildproperty_id':
case 'covered_area': case 'covered_area':
case 'floor': case 'floor':
case 'faceto': case 'faceto':
case 'decoration': case 'decoration':
case 'age': case 'age':
case 'matching_facilities': case 'matching_facilities':
case 'user_id': case 'user_id':
case 'status': case 'status':
default: default:
return '<a href="' . admin_url() . 'admin.php?page=rentHouse&edit=true&id=' . $item['id'] . '">' . $item[$column_name] . '</a>'; return '<a href="' . admin_url() . 'admin.php?page=rentHouse&edit=true&id=' . $item['id'] . '">' . $item[$column_name] . '</a>';
} }
} }
function column_cb($item) function column_cb($item)
{ {
return sprintf( return sprintf(
'<input type="checkbox" name="%1$s[]" value="%2$s" />', '<input type="checkbox" name="%1$s[]" value="%2$s" />',
/*$1%s*/ /*$1%s*/
$this->_args['singular'], //Let's simply repurpose the table's singular label ("score") $this->_args['singular'], //Let's simply repurpose the table's singular label ("score")
/*$2%s*/ /*$2%s*/
$item['id'] //The value of the checkbox should be the record's id $item['id'] //The value of the checkbox should be the record's id
); );
} }
function get_columns() function get_columns()
{ {
if( current_user_can('administrator') ) { if( current_user_can('administrator') ) {
$columns = array( $columns = array(
'cb' => '<input type="checkbox" />' 'cb' => '<input type="checkbox" />'
); );
} }
$columns['id']= 'ID'; $columns['id']= 'ID';
$columns['name']= '租房标题'; $columns['name']= '租房标题';
$columns['community_name']= '小区名称'; $columns['community_name']= '小区名称';
$columns['rent']= '元/月'; $columns['rent']= '元/月';
$columns['buildproperty_id']= '户型'; $columns['buildproperty_id']= '户型';
$columns['covered_area']= '面积'; $columns['covered_area']= '面积';
$columns['floor']= '楼层'; $columns['floor']= '楼层';
$columns['faceto']= '朝向'; $columns['faceto']= '朝向';
$columns['decoration']= '装修状况'; $columns['decoration']= '装修状况';
$columns['age']= '年代'; $columns['age']= '年代';
$columns['matching_facilities']= '配套设施'; $columns['matching_facilities']= '配套设施';
$columns['user_id']= '置业顾问'; $columns['user_id']= '置业顾问';
$columns['status']= '状态'; $columns['status']= '状态';
return $columns; return $columns;
} }
function get_sortable_columns() function get_sortable_columns()
{ {
$sortable_columns = array( $sortable_columns = array(
'id' => array('id', false), 'id' => array('id', false),
'name' => array('name', false), 'name' => array('name', false),
'community_name' => array('community_name', false), 'community_name' => array('community_name', false),
'rent' => array('rent', false), 'rent' => array('rent', false),
'buildproperty_id' => array('buildproperty_id', false), 'buildproperty_id' => array('buildproperty_id', false),
'covered_area' => array('covered_area', false), 'covered_area' => array('covered_area', false),
'floor' => array('floor', false), 'floor' => array('floor', false),
'faceto' => array('faceto', false), 'faceto' => array('faceto', false),
'decoration' => array('decoration', false), 'decoration' => array('decoration', false),
'age' => array('age', false), 'age' => array('age', false),
'matching_facilities' => array('matching_facilities', false), 'matching_facilities' => array('matching_facilities', false),
'user_id' => array('user_id', false), 'user_id' => array('user_id', false),
'status' => array('status', false) 'status' => array('status', false)
); );
return $sortable_columns; return $sortable_columns;
} }
function get_bulk_actions() function get_bulk_actions()
{ {
$actions = array( $actions = array(
'noCheck' => '未审核', 'noCheck' => '未审核',
'check' => '审核', 'check' => '审核',
'selfSale'=>'自售', 'selfSale'=>'自售',
'otherSale'=>'他售', 'otherSale'=>'他售',
'invalid'=>'无效', 'invalid'=>'无效',
'reactivation'=>'重激活' 'reactivation'=>'重激活'
); );
return $actions; return $actions;
} }
function process_bulk_action() function process_bulk_action()
{ {
$action = $this->current_action(); $action = $this->current_action();
if ($action) { if ($action) {
$string = null; $string = null;
$status = null; $status = null;
switch ($action) { switch ($action) {
case 'noCheck': case 'noCheck':
$id = $_POST['renthouselist']; $id = $_POST['renthouselist'];
if ($id) { if ($id) {
$string = '(' . implode(',', array_map('intval', $id)) . ')'; $string = '(' . implode(',', array_map('intval', $id)) . ')';
$status = 0; $status = 0;
} }
break; break;
case 'check': case 'check':
$id = $_POST['renthouselist']; $id = $_POST['renthouselist'];
if ($id) { if ($id) {
$string = '(' . implode(',', array_map('intval', $id)) . ')'; $string = '(' . implode(',', array_map('intval', $id)) . ')';
$status = 1; $status = 1;
} }
break; break;
case 'selfSale': case 'selfSale':
$id = $_POST['renthouselist']; $id = $_POST['renthouselist'];
if ($id) { if ($id) {
$string = '(' . implode(',', array_map('intval', $id)) . ')'; $string = '(' . implode(',', array_map('intval', $id)) . ')';
$status = 2; $status = 2;
} }
break; break;
case 'otherSale': case 'otherSale':
$id = $_POST['renthouselist']; $id = $_POST['renthouselist'];
if ($id) { if ($id) {
$string = '(' . implode(',', array_map('intval', $id)) . ')'; $string = '(' . implode(',', array_map('intval', $id)) . ')';
$status = 3; $status = 3;
} }
break; break;
case 'invalid': case 'invalid':
$id = $_POST['renthouselist']; $id = $_POST['renthouselist'];
if ($id) { if ($id) {
$string = '(' . implode(',', array_map('intval', $id)) . ')'; $string = '(' . implode(',', array_map('intval', $id)) . ')';
$status = 4; $status = 4;
} }
break; break;
case 'reactivation': case 'reactivation':
$id = $_POST['renthouselist']; $id = $_POST['renthouselist'];
if ($id) { if ($id) {
$string = '(' . implode(',', array_map('intval', $id)) . ')'; $string = '(' . implode(',', array_map('intval', $id)) . ')';
$status = 5; $status = 5;
} }
break; break;
} }
global $wpdb; global $wpdb;
$result = $wpdb->query('update tospur_house SET status='.$status .' where id in ' . $string); $result = $wpdb->query('update tospur_house SET status='.$status .' where id in ' . $string);
} }
} }
function prepare_items() function prepare_items()
{ {
global $wpdb; global $wpdb;
$per_page = 10; $per_page = 10;
$columns = $this->get_columns(); $columns = $this->get_columns();
$hidden = array(); $hidden = array();
$sortable = $this->get_sortable_columns(); $sortable = $this->get_sortable_columns();
$this->_column_headers = array($columns, $hidden, $sortable); $this->_column_headers = array($columns, $hidden, $sortable);
$this->process_bulk_action(); $this->process_bulk_action();
//$data = $this->example_data; //$data = $this->example_data;
$params = array( $params = array(
"city_id" => $_POST["listCity"], "city_id" => $_POST["listCity"],
"district_id" => $_POST["listDistrict"], "district_id" => $_POST["listDistrict"],
"plate_id" =>$_POST["listPlate"], "plate_id" =>$_POST["listPlate"],
"buildproperty_id"=>$_POST["buildProperty"], "buildproperty_id"=>$_POST["buildProperty"],
"status" => $_POST["status"], "status" => $_POST["status"],
); );
$sql = "select * from tospur_house th $sql = "select * from tospur_house th
left join(select user_id as aus_id,house_id,user_type from a_house_user) ahu on th.id = ahu.house_id left join(select user_id as aus_id,house_id,user_type from a_house_user) ahu on th.id = ahu.house_id
left join(select id as consul_id,name as consul_name from tospur_consultant) tc on ahu.aus_id = tc.consul_id left join(select id as consul_id,name as consul_name from tospur_consultant) tc on ahu.aus_id = tc.consul_id
left join(select value,literal from dic_buildproperty) db on th.buildproperty_id = db.value left join(select value,literal from dic_buildproperty) db on th.buildproperty_id = db.value
where 1=1 and house_type=2 and ahu.user_type=1"; where 1=1 and house_type=2 and ahu.user_type=1";
if($_POST["listCity"]!=0 ){ if($_POST["listCity"]!=0 ){
$sql = $sql." and city_id=".$_POST["listCity"]; $sql = $sql." and city_id=".$_POST["listCity"];
} }
if($_POST["listDistrict"] != 0 ){ if($_POST["listDistrict"] != 0 ){
$sql = $sql." and district_id=".$_POST["listDistrict"]; $sql = $sql." and district_id=".$_POST["listDistrict"];
} }
if($_POST["listPlate"] != 0){ if($_POST["listPlate"] != 0){
$sql = $sql." and plate_id=".$_POST["listPlate"]; $sql = $sql." and plate_id=".$_POST["listPlate"];
} }
if($_POST["buildProperty"]!=0){ if($_POST["buildProperty"]!=0){
$sql = $sql." and buildproperty_id=".$_POST["buildProperty"]; $sql = $sql." and buildproperty_id=".$_POST["buildProperty"];
} }
if(isset($_POST["status"]) && $_POST["status"]!=-1){ if(isset($_POST["status"]) && $_POST["status"]!=-1){
$sql = $sql." and status=".$_POST["status"]; $sql = $sql." and status=".$_POST["status"];
} }
if($_POST["acreage"]!= NULL){ if($_POST["acreage"]!= NULL){
$areaArray = explode("-", $_POST['acreage']); $areaArray = explode("-", $_POST['acreage']);
$sql = $sql . " and covered_area between ".$areaArray[0]." and ".$areaArray[1]; $sql = $sql . " and covered_area between ".$areaArray[0]." and ".$areaArray[1];
} }
if($_POST["searchText"]!=NULL){ if($_POST["searchText"]!=NULL){
$sql = $sql . " and name like '%".$_POST['searchText']."%'"; $sql = $sql . " and name like '%".$_POST['searchText']."%'";
} }
$result = $wpdb->get_results($sql); $result = $wpdb->get_results($sql);
$data = array(); $data = array();
foreach ($result as $key => $value) { foreach ($result as $key => $value) {
$data[$key] = array( $data[$key] = array(
'id' => $value->id, 'id' => $value->id,
'name' => $value->name, 'name' => $value->name,
'community_name' => $value->community_name, 'community_name' => $value->community_name,
'rent' => $value->rent, 'rent' => $value->rent,
'buildproperty_id' => $value->literal, 'buildproperty_id' => $value->literal,
'covered_area' => $value->covered_area, 'covered_area' => $value->covered_area,
'floor' => $value->floor, 'floor' => $value->floor,
'faceto' => $value->faceto, 'faceto' => $value->faceto,
'decoration' => $value->decoration, 'decoration' => $value->decoration,
'age' => $value->age, 'age' => $value->age,
'matching_facilities'=> $value->matching_facilities, 'matching_facilities'=> $value->matching_facilities,
'user_id' => $value->consul_name, 'user_id' => $value->consul_name,
); );
if($value->status == 0){ if($value->status == 0){
$data[$key]['status'] ="未审核"; $data[$key]['status'] ="未审核";
}else if($value->status == 1){ }else if($value->status == 1){
$data[$key]['status'] ="审核"; $data[$key]['status'] ="审核";
}else if($value->status == 2){ }else if($value->status == 2){
$data[$key]['status'] ="自售"; $data[$key]['status'] ="自售";
}else if($value->status == 3){ }else if($value->status == 3){
$data[$key]['status'] ="他售"; $data[$key]['status'] ="他售";
}else if($value->status == 4){ }else if($value->status == 4){
$data[$key]['status'] ="无效"; $data[$key]['status'] ="无效";
}else if($value->status == 5){ }else if($value->status == 5){
$data[$key]['status'] ="重激活"; $data[$key]['status'] ="重激活";
} }
} }
function usort_reorder($a, $b) function usort_reorder($a, $b)
{ {
$orderby = (!empty($_REQUEST['orderby'])) ? $_REQUEST['orderby'] : 'valid'; //If no sort, default to title $orderby = (!empty($_REQUEST['orderby'])) ? $_REQUEST['orderby'] : 'valid'; //If no sort, default to title
$order = (!empty($_REQUEST['order'])) ? $_REQUEST['order'] : 'desc'; //If no order, default to asc $order = (!empty($_REQUEST['order'])) ? $_REQUEST['order'] : 'desc'; //If no order, default to asc
$result = strcmp($a[$orderby], $b[$orderby]); //Determine sort order $result = strcmp($a[$orderby], $b[$orderby]); //Determine sort order
return ($order === 'asc') ? $result : -$result; //Send final sort direction to usort return ($order === 'asc') ? $result : -$result; //Send final sort direction to usort
} }
usort($data, 'usort_reorder'); usort($data, 'usort_reorder');
$current_page = $this->get_pagenum(); $current_page = $this->get_pagenum();
$total_items = count($data); $total_items = count($data);
$data = array_slice($data, (($current_page - 1) * $per_page), $per_page); $data = array_slice($data, (($current_page - 1) * $per_page), $per_page);
$this->items = $data; $this->items = $data;
$this->set_pagination_args(array( $this->set_pagination_args(array(
'total_items' => $total_items, //WE have to calculate the total number of items 'total_items' => $total_items, //WE have to calculate the total number of items
'per_page' => $per_page, //WE have to determine how many items to show on a page 'per_page' => $per_page, //WE have to determine how many items to show on a page
'total_pages' => ceil($total_items / $per_page) //WE have to calculate the total number of pages 'total_pages' => ceil($total_items / $per_page) //WE have to calculate the total number of pages
)); ));
} }
} }
add_action( 'wp_ajax_updateList', 'newHouseList::prepare_items'); add_action( 'wp_ajax_updateList', 'newHouseList::prepare_items');
add_action( 'wp_ajax_nopriv_updateList', 'newHouseList::prepare_items'); add_action( 'wp_ajax_nopriv_updateList', 'newHouseList::prepare_items');
add_action( 'wp_ajax_searchListCity', 'SearchDao::ajax_searchListCity'); add_action( 'wp_ajax_searchListCity', 'SearchDao::ajax_searchListCity');
add_action( 'wp_ajax_nopriv_searchListCity', 'SearchDao::ajax_searchListCity'); add_action( 'wp_ajax_nopriv_searchListCity', 'SearchDao::ajax_searchListCity');
function function_rentHouseList() function function_rentHouseList()
{ {
$contest = array(); $contest = array();
$contest['page'] = $_REQUEST['page']; $contest['page'] = $_REQUEST['page'];
$contest['city'] = SearchDao::searchCity(); $contest['city'] = SearchDao::searchCity();
$contest['status'] = SearchDao::searchStatusType(2); $contest['status'] = SearchDao::searchStatusType(2);
$contest['buildProperty'] = SearchDao::searchBuildProperty(); $contest['buildProperty'] = SearchDao::searchBuildProperty();
if(isset($_POST['hasSearch'])){ if(isset($_POST['hasSearch'])){
$contest['district'] = SearchDao::searchCity($_POST['listCity']); $contest['district'] = SearchDao::searchCity($_POST['listCity']);
$contest['plate'] = SearchDao::searchCity($_POST['listCity'],$_POST['listDistrict']); $contest['plate'] = SearchDao::searchCity($_POST['listCity'],$_POST['listDistrict']);
$contest['dicTotalPrice'] = searchDao::searchTotalPrice($_POST['listCity']); $contest['dicTotalPrice'] = searchDao::searchTotalPrice($_POST['listCity']);
$contest['dicArea'] = searchDao::searchArea($_POST['listCity']); $contest['dicArea'] = searchDao::searchArea($_POST['listCity']);
$contest['cityId'] = $_POST['listCity']; $contest['cityId'] = $_POST['listCity'];
$contest['districtId'] = $_POST['listDistrict']; $contest['districtId'] = $_POST['listDistrict'];
$contest['plateId' ]= $_POST['listPlate']; $contest['plateId' ]= $_POST['listPlate'];
$contest['buildPropertyId']= $_POST['buildProperty']; $contest['buildPropertyId']= $_POST['buildProperty'];
$contest['totalPrice'] = $_POST['totalPrice']; $contest['totalPrice'] = $_POST['totalPrice'];
$contest['acreage'] = $_POST['acreage']; $contest['acreage'] = $_POST['acreage'];
$contest['statusId'] = $_POST['status']; $contest['statusId'] = $_POST['status'];
} }
Timber::render("rentHouseList.html",$contest); Timber::render("rentHouseList.html",$contest);
} }
function addRentTable(){ function addRentTable(){
$rentHouseList = new rentHouseList(); $rentHouseList = new rentHouseList();
$rentHouseList->prepare_items(); $rentHouseList->prepare_items();
$rentHouseList->display(); $rentHouseList->display();
} }
?> ?>
<?php <?php
require_once(PLUGIN_DIR . 'Dao/SearchDao.php'); require_once(PLUGIN_DIR . 'Dao/SearchDao.php');
require_once(PLUGIN_DIR . 'Dao/InsertDao.php'); require_once(PLUGIN_DIR . 'Dao/InsertDao.php');
require_once(PLUGIN_DIR . 'Tools/Image.php'); require_once(PLUGIN_DIR . 'Tools/Image.php');
class SecHandHouse extends Tospur_House{ class SecHandHouse extends Tospur_House{
//二手房信息 //二手房信息
public static function secHandHouse_html(){ public static function secHandHouse_html(){
wp_enqueue_script('bootstrapjs'); wp_enqueue_script('bootstrapjs');
wp_enqueue_style('bootstrapcss'); wp_enqueue_style('bootstrapcss');
global $wpdb; wp_enqueue_style('bootstrapMinCss');
$type = $_POST["type"]; global $wpdb;
$context = array(); $type = $_POST["type"];
$context['siteUrl'] = get_site_url(); $context = array();
$insert_tospur_house_array = array( $context['siteUrl'] = get_site_url();
'name' => $_POST['housename'], $insert_tospur_house_array = array(
'house_number' =>$_POST['house_number'], 'name' => $_POST['housename'],
'total_price' =>$_POST['total_price'], 'house_number' =>$_POST['house_number'],
'average_price' => $_POST['average_price'], 'total_price' =>$_POST['total_price'],
'buildproperty_id'=>$_POST['buildproperty_id'], 'average_price' => $_POST['average_price'],
'covered_area' =>$_POST['covered_area'], 'buildproperty_id'=>$_POST['buildproperty_id'],
'floor' =>$_POST['floor'], 'covered_area' =>$_POST['covered_area'],
'faceto'=>$_POST['faceto'], 'floor' =>$_POST['floor'],
'decoration' => $_POST['decoration'], 'faceto'=>$_POST['faceto'],
'age'=>$_POST['age'], 'decoration' => $_POST['decoration'],
'flat'=>$_POST['flat'], 'age'=>$_POST['age'],
'suite'=>$_POST["suite"], 'flat'=>$_POST['flat'],
'overview' => $_POST['overview'], 'suite'=>$_POST["suite"],
'city_id' => $_POST['baseCity'], 'overview' => $_POST['overview'],
'district_id' => $_POST['baseAreaId'], 'city_id' => $_POST['baseCity'],
'plate_id' => $_POST["basePlateId"], 'district_id' => $_POST['baseAreaId'],
'address' => $_POST['address'], 'plate_id' => $_POST["basePlateId"],
'community_name'=>$_POST['community_name'], 'address' => $_POST['address'],
'traffic' => $_POST['traffic'], 'community_name'=>$_POST['community_name'],
'periphery' => $_POST['periphery'], 'traffic' => $_POST['traffic'],
'status' =>$_POST['status'], 'periphery' => $_POST['periphery'],
'owner_name'=>$_POST['owner_name'], 'status' =>$_POST['status'],
'owner_phone'=>$_POST['owner_phone'], 'owner_name'=>$_POST['owner_name'],
"location" => $_POST["location"], 'owner_phone'=>$_POST['owner_phone'],
); "location" => $_POST["location"],
if($type==2){ );
$wpdb->query("START TRANSACTION"); if($type==2){
if(isset($_POST['houseId'])){ $wpdb->query("START TRANSACTION");
$result = SecHandHouse::data_update($_POST['houseId'],$insert_tospur_house_array); if(isset($_POST['houseId'])){
if($result != 201){ $result = SecHandHouse::data_update($_POST['houseId'],$insert_tospur_house_array);
$wpdb->query("ROLLBACK"); if($result != 201){
print_r( $result);; $wpdb->query("ROLLBACK");
echo "二手房房源修改失败"; print_r( $result);;
}else{ echo "二手房房源修改失败";
$wpdb->query("COMMIT"); }else{
echo "二手房房源修改成功"; $wpdb->query("COMMIT");
} echo "二手房房源修改成功";
}
}else {
$result = SecHandHouse::secHouseData_insert($insert_tospur_house_array); }else {
if ($result != 200) { $result = SecHandHouse::secHouseData_insert($insert_tospur_house_array);
$wpdb->query("ROLLBACK"); if ($result != 200) {
print_r( $result);; $wpdb->query("ROLLBACK");
echo "二手房房源新增失败"; print_r( $result);;
} else { echo "二手房房源新增失败";
$wpdb->query("COMMIT"); } else {
echo "二手房房源新增成功"; $wpdb->query("COMMIT");
} echo "二手房房源新增成功";
} }
exit; }
}else if(isset($_GET['edit'])){ exit;
$context['houseId'] = $_GET['id']; }else if(isset($_GET['edit'])){
$context = array_merge($context,SearchDao::getDetailInfo($_GET['id'])); $context['houseId'] = $_GET['id'];
$context["district"] = SearchDao::searchCity($context['result']->city_id); $context = array_merge($context,SearchDao::getDetailInfo($_GET['id']));
$context["plate"] = SearchDao::searchCity($context['result']->city_id,$context['result']->district_id); $context["district"] = SearchDao::searchCity($context['result']->city_id);
$context["mark"] = SearchDao::searchHouseTag($_GET['id']); $context["plate"] = SearchDao::searchCity($context['result']->city_id,$context['result']->district_id);
$context["featureOld"] = SearchDao::searchFeatureByHouse($_GET['id']); $context["mark"] = SearchDao::searchHouseTag($_GET['id']);
} $context["featureOld"] = SearchDao::searchFeatureByHouse($_GET['id']);
$context['role'] = SecHandHouse::getCurrentRole();
$context["city"] = SearchDao::searchCity(); }
$context["buildProperty"] = SearchDao::searchBuildProperty(); $context['role'] = SecHandHouse::getCurrentRole();
$context["room"] = SearchDao::searchRoom(); $context["city"] = SearchDao::searchCity();
$context["photoType"] = SearchDao::searchPhotoType(); $context["buildProperty"] = SearchDao::searchBuildProperty();
$context["status"] = searchDao::searchStatusType(2); $context["room"] = SearchDao::searchRoom();
$context["feature"] = searchDao::searchFeature(); $context["photoType"] = SearchDao::searchPhotoType();
Timber::render("secHandHouse.html",$context); $context["status"] = searchDao::searchStatusType(2);
$context["feature"] = searchDao::searchFeature();
} Timber::render("secHandHouse.html",$context);
public static function secHouseData_insert($params) }
{
global $wpdb; public static function secHouseData_insert($params)
//房源与类型以及面积信息 {
$data = $_POST["data"]; global $wpdb;
$params['user_id'] = get_current_user_id(); //房源与类型以及面积信息
$params['creattime'] = date("Y-m-d H:i:s"); $data = $_POST["data"];
$params['house_type'] = 1; $params['user_id'] = get_current_user_id();
//获取新房信息,存入tospur_house表 $params['creattime'] = date("Y-m-d H:i:s");
$res = $wpdb->get_results('SELECT * FROM tospur_house WHERE address="' .$params['address'] . '" and owner_name="' .$params['owner_name'] . '" and owner_phone="'.$params['owner_phone'].'" and house_type=1', OBJECT); $params['house_type'] = 1;
if(!$res){ //获取新房信息,存入tospur_house表
$houseId = InsertDao::insert_tospur_house($params); $res = $wpdb->get_results('SELECT * FROM tospur_house WHERE address="' .$params['address'] . '" and owner_name="' .$params['owner_name'] . '" and owner_phone="'.$params['owner_phone'].'" and house_type=1', OBJECT);
if(!$res){
InsertDao::addMainImage($houseId,$data); $houseId = InsertDao::insert_tospur_house($params);
InsertDao::addRecommend($houseId,$data); InsertDao::addMainImage($houseId,$data);
InsertDao::addRecConsultant($houseId,$data); InsertDao::addRecommend($houseId,$data);
if(isset($_POST['mark'])&&$_POST['mark']!=""){ InsertDao::addRecConsultant($houseId,$data);
InsertDao::addHouseTag($_POST['mark'],$houseId);
} if(isset($_POST['mark'])&&$_POST['mark']!=""){
InsertDao::addHouseTag($_POST['mark'],$houseId);
InsertDao::addHouseFeature($houseId,$data); }
InsertDao::addHouseFeature($houseId,$data);
}else{
return 507;
} }else{
return 200; return 507;
} }
return 200;
public static function data_update($houseId,$params){ }
global $wpdb;
$data = $_POST["data"]; public static function data_update($houseId,$params){
$res = $wpdb->update(Config::TOSPUR_HOUSE_TABLE,$params,array("id" => $houseId)); global $wpdb;
$result = 201; $data = $_POST["data"];
$res = $wpdb->update(Config::TOSPUR_HOUSE_TABLE,$params,array("id" => $houseId));
InsertDao::addMainImage($houseId,$data); $result = 201;
$exists_photo_ids = array(); InsertDao::addMainImage($houseId,$data);
if(isset($_POST['exists_photo'])){
foreach($_POST['exists_photo'] as $id => $item){ $exists_photo_ids = array();
$wpdb->update(Config::TOSPUR_IMAGE_TABLE,array( if(isset($_POST['exists_photo'])){
"image_type" => $item['type'], foreach($_POST['exists_photo'] as $id => $item){
),array("id" => $id)); $wpdb->update(Config::TOSPUR_IMAGE_TABLE,array(
$exists_photo_ids[] = $id; "image_type" => $item['type'],
} ),array("id" => $id));
} $exists_photo_ids[] = $id;
$old_exists_photo_ids = explode(",",$_POST['exists_photo_ids']); }
$delete_photo_ids = array(); }
foreach(array_diff($old_exists_photo_ids,$exists_photo_ids) as $key => $id){ $old_exists_photo_ids = explode(",",$_POST['exists_photo_ids']);
$delete_photo_ids[] = $id; $delete_photo_ids = array();
} foreach(array_diff($old_exists_photo_ids,$exists_photo_ids) as $key => $id){
$delete_photo_ids = implode(",",$delete_photo_ids); $delete_photo_ids[] = $id;
$wpdb->query("delete from ".Config::A_HOUSE_IMAGE_TABLE." where house_id = {$houseId} and image_id in ({$delete_photo_ids});"); }
$delete_photo_ids = implode(",",$delete_photo_ids);
$wpdb->delete(Config::A_HOUSE_RECOMMEND_TABLE,array("house_id" => $houseId)); $wpdb->query("delete from ".Config::A_HOUSE_IMAGE_TABLE." where house_id = {$houseId} and image_id in ({$delete_photo_ids});");
InsertDao::addRecommend($houseId,$data);
$wpdb->delete(Config::A_HOUSE_RECOMMEND_TABLE,array("house_id" => $houseId));
$wpdb->delete(Config::A_HOUSE_USER_TABLE,array("house_id" => $houseId)); InsertDao::addRecommend($houseId,$data);
InsertDao::addRecConsultant($houseId,$data);
$wpdb->delete(Config::A_HOUSE_USER_TABLE,array("house_id" => $houseId));
// $wpdb->delete(Config::A_HOUSE_TAG_TABLE,array("house_id" => $houseId)); InsertDao::addRecConsultant($houseId,$data);
$wpdb->query(
$wpdb->prepare( $wpdb->query(
"DELETE FROM a_house_tag $wpdb->prepare(
WHERE tag_id in(select tag_id from (select tag_id,tt.type from a_house_tag as aht "DELETE FROM a_house_tag
left JOIN tospur_tag tt on aht.tag_id = tt.id) as a WHERE tag_id in(select tag_id from (select tag_id,tt.type from a_house_tag as aht
where house_id = %d and a.type = 1);", $houseId) left JOIN tospur_tag tt on aht.tag_id = tt.id) as a
); where house_id = %d and a.type = 1);", $houseId)
InsertDao::addHouseFeature($houseId,$data); );
InsertDao::addHouseFeature($houseId,$data);
if(isset($_POST['mark'])&&$_POST['mark']!="") {
InsertDao::addHouseTag($_POST['mark'],$houseId); if(isset($_POST['mark'])&&$_POST['mark']!="") {
} InsertDao::addHouseTag($_POST['mark'],$houseId);
return $result; }
} return $result;
}
}
}
<?php <?php
if (!class_exists('WP_List_Table')) { if (!class_exists('WP_List_Table')) {
require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table.php'); require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table.php');
} }
class secHandHouseList extends WP_List_Table class secHandHouseList extends WP_List_Table
{ {
function __construct() function __construct()
{ {
global $status, $page; global $status, $page;
//Set parent defaults //Set parent defaults
parent::__construct(array( parent::__construct(array(
'singular' => 'secHandHouseList', //singular name of the listed records 'singular' => 'secHandHouseList', //singular name of the listed records
'plural' => 'secHandHouseLists', //plural name of the listed records 'plural' => 'secHandHouseLists', //plural name of the listed records
'ajax' => false //does this table support ajax? 'ajax' => false //does this table support ajax?
)); ));
} }
function column_default($item, $column_name) function column_default($item, $column_name)
{ {
switch ($column_name) { switch ($column_name) {
case'id': case'id':
case 'name': case 'name':
case 'community_name': case 'community_name':
case 'total_price': case 'total_price':
case 'average_price': case 'average_price':
case 'buildproperty_id': case 'buildproperty_id':
case 'covered_area': case 'covered_area':
case 'floor': case 'floor':
case 'faceto': case 'faceto':
case 'decoration': case 'decoration':
case 'age': case 'age':
case 'user_id': case 'user_id':
case 'status': case 'status':
default: default:
return '<a href="' . admin_url() . 'admin.php?page=secHandHouse&edit=true&id='. $item['id'].'">' . $item[$column_name] . '</a>'; return '<a href="' . admin_url() . 'admin.php?page=secHandHouse&edit=true&id='. $item['id'].'">' . $item[$column_name] . '</a>';
} }
} }
function column_cb($item) function column_cb($item)
{ {
return sprintf( return sprintf(
'<input type="checkbox" name="%1$s[]" value="%2$s" />', '<input type="checkbox" name="%1$s[]" value="%2$s" />',
/*$1%s*/ /*$1%s*/
$this->_args['singular'], //Let's simply repurpose the table's singular label ("score") $this->_args['singular'], //Let's simply repurpose the table's singular label ("score")
/*$2%s*/ /*$2%s*/
$item['id'] //The value of the checkbox should be the record's id $item['id'] //The value of the checkbox should be the record's id
); );
} }
function get_columns() function get_columns()
{ {
if( current_user_can('administrator') ) { if( current_user_can('administrator') ) {
$columns = array( $columns = array(
'cb' => '<input type="checkbox" />' 'cb' => '<input type="checkbox" />'
); );
} }
$columns['id']= 'ID'; $columns['id']= 'ID';
$columns['name']= '二手房标题'; $columns['name']= '二手房标题';
$columns['community_name']= '小区名称'; $columns['community_name']= '小区名称';
$columns['total_price']= '总价'; $columns['total_price']= '总价';
$columns['average_price']='单价'; $columns['average_price']='单价';
$columns['buildproperty_id']= '户型'; $columns['buildproperty_id']= '户型';
$columns['covered_area']= '面积'; $columns['covered_area']= '面积';
$columns['floor']= '楼层'; $columns['floor']= '楼层';
$columns['faceto']= '朝向'; $columns['faceto']= '朝向';
$columns['decoration']= '装修状况'; $columns['decoration']= '装修状况';
$columns['age']= '年代'; $columns['age']= '年代';
$columns['user_id']= '置业顾问'; $columns['user_id']= '置业顾问';
$columns['status']= '状态'; $columns['status']= '状态';
return $columns; return $columns;
} }
function get_sortable_columns() function get_sortable_columns()
{ {
$sortable_columns = array( $sortable_columns = array(
'id' => array('id', false), 'id' => array('id', false),
'name' => array('name', false), 'name' => array('name', false),
'community_name' => array('community_name', false), 'community_name' => array('community_name', false),
'total_price' => array('total_price', false), 'total_price' => array('total_price', false),
'average_price' => array('average_price', false), 'average_price' => array('average_price', false),
'buildproperty_id' => array('buildproperty_id', false), 'buildproperty_id' => array('buildproperty_id', false),
'covered_area' => array('covered_area', false), 'covered_area' => array('covered_area', false),
'floor' => array('floor', false), 'floor' => array('floor', false),
'faceto' => array('faceto', false), 'faceto' => array('faceto', false),
'decoration' => array('decoration', false), 'decoration' => array('decoration', false),
'age' => array('age', false), 'age' => array('age', false),
'user_id' => array('user_id', false), 'user_id' => array('user_id', false),
'status' => array('status', false) 'status' => array('status', false)
); );
return $sortable_columns; return $sortable_columns;
} }
function get_bulk_actions() function get_bulk_actions()
{ {
$actions = array( $actions = array(
'noCheck' => '未审核', 'noCheck' => '未审核',
'check' => '审核', 'check' => '审核',
'selfSale'=>'自售', 'selfSale'=>'自售',
'otherSale'=>'他售', 'otherSale'=>'他售',
'invalid'=>'无效', 'invalid'=>'无效',
'reactivation'=>'重激活' 'reactivation'=>'重激活'
); );
return $actions; return $actions;
} }
function process_bulk_action() function process_bulk_action()
{ {
$action = $this->current_action(); $action = $this->current_action();
if ($action) { if ($action) {
$string = null; $string = null;
$status = null; $status = null;
switch ($action) { switch ($action) {
case 'noCheck': case 'noCheck':
$id = $_POST['sechandhouselist']; $id = $_POST['sechandhouselist'];
if ($id) { if ($id) {
$string = '(' . implode(',', array_map('intval', $id)) . ')'; $string = '(' . implode(',', array_map('intval', $id)) . ')';
$status = 0; $status = 0;
} }
break; break;
case 'check': case 'check':
$id = $_POST['sechandhouselist']; $id = $_POST['sechandhouselist'];
if ($id) { if ($id) {
$string = '(' . implode(',', array_map('intval', $id)) . ')'; $string = '(' . implode(',', array_map('intval', $id)) . ')';
$status = 1; $status = 1;
} }
break; break;
case 'selfSale': case 'selfSale':
$id = $_POST['sechandhouselist']; $id = $_POST['sechandhouselist'];
if ($id) { if ($id) {
$string = '(' . implode(',', array_map('intval', $id)) . ')'; $string = '(' . implode(',', array_map('intval', $id)) . ')';
$status = 2; $status = 2;
} }
break; break;
case 'otherSale': case 'otherSale':
$id = $_POST['sechandhouselist']; $id = $_POST['sechandhouselist'];
if ($id) { if ($id) {
$string = '(' . implode(',', array_map('intval', $id)) . ')'; $string = '(' . implode(',', array_map('intval', $id)) . ')';
$status = 3; $status = 3;
} }
break; break;
case 'invalid': case 'invalid':
$id = $_POST['sechandhouselist']; $id = $_POST['sechandhouselist'];
print_r($id); print_r($id);
if ($id) { if ($id) {
$string = '(' . implode(',', array_map('intval', $id)) . ')'; $string = '(' . implode(',', array_map('intval', $id)) . ')';
$status = 4; $status = 4;
} }
break; break;
case 'reactivation': case 'reactivation':
$id = $_POST['sechandhouselist']; $id = $_POST['sechandhouselist'];
if ($id) { if ($id) {
$string = '(' . implode(',', array_map('intval', $id)) . ')'; $string = '(' . implode(',', array_map('intval', $id)) . ')';
$status = 5; $status = 5;
} }
break; break;
} }
global $wpdb; global $wpdb;
$result = $wpdb->query('update tospur_house SET status='.$status .' where id in ' . $string); $result = $wpdb->query('update tospur_house SET status='.$status .' where id in ' . $string);
} }
} }
function prepare_items() function prepare_items()
{ {
global $wpdb; global $wpdb;
$per_page = 10; $per_page = 10;
$columns = $this->get_columns(); $columns = $this->get_columns();
$hidden = array(); $hidden = array();
$sortable = $this->get_sortable_columns(); $sortable = $this->get_sortable_columns();
$this->_column_headers = array($columns, $hidden, $sortable); $this->_column_headers = array($columns, $hidden, $sortable);
$this->process_bulk_action(); $this->process_bulk_action();
//$data = $this->example_data; //$data = $this->example_data;
$sql = "select * from tospur_house th $sql = "select * from tospur_house th
left join(select user_id as aus_id,house_id,user_type from a_house_user) ahu on th.id = ahu.house_id left join(select user_id as aus_id,house_id,user_type from a_house_user) ahu on th.id = ahu.house_id
left join(select id as consul_id,name as consul_name from tospur_consultant) tc on ahu.aus_id = tc.consul_id left join(select id as consul_id,name as consul_name from tospur_consultant) tc on ahu.aus_id = tc.consul_id
left join(select value,literal from dic_buildproperty) db on th.buildproperty_id = db.value left join(select value,literal from dic_buildproperty) db on th.buildproperty_id = db.value
where 1=1 and house_type=1 and ahu.user_type=1"; where 1=1 and house_type=1 and ahu.user_type=1";
if($_POST["listCity"]!=0 ){ if($_POST["listCity"]!=0 ){
$sql = $sql." and city_id=".$_POST["listCity"]; $sql = $sql." and city_id=".$_POST["listCity"];
} }
if($_POST["listDistrict"] != 0 ){ if($_POST["listDistrict"] != 0 ){
$sql = $sql." and district_id=".$_POST["listDistrict"]; $sql = $sql." and district_id=".$_POST["listDistrict"];
} }
if($_POST["listPlate"] != 0){ if($_POST["listPlate"] != 0){
$sql = $sql." and plate_id=".$_POST["listPlate"]; $sql = $sql." and plate_id=".$_POST["listPlate"];
} }
if($_POST["buildProperty"]!=0){ if($_POST["buildProperty"]!=0){
$sql = $sql." and buildproperty_id=".$_POST["buildProperty"]; $sql = $sql." and buildproperty_id=".$_POST["buildProperty"];
} }
if(isset($_POST["status"]) && $_POST["status"]!=-1){ if(isset($_POST["status"]) && $_POST["status"]!=-1){
$sql = $sql." and status=".$_POST["status"]; $sql = $sql." and status=".$_POST["status"];
} }
if($_POST["totalPrice"]!=NULL){ if($_POST["totalPrice"]!=NULL){
$priceArray = explode("-", $_POST['totalPrice']); $priceArray = explode("-", $_POST['totalPrice']);
$sql = $sql . " and average_price between ".$priceArray[0]." and ".$priceArray[1]; $sql = $sql . " and average_price between ".$priceArray[0]." and ".$priceArray[1];
} }
if($_POST["acreage"]!= NULL){ if($_POST["acreage"]!= NULL){
$areaArray = explode("-", $_POST['acreage']); $areaArray = explode("-", $_POST['acreage']);
$sql = $sql . " and covered_area between ".$areaArray[0]." and ".$areaArray[1]; $sql = $sql . " and covered_area between ".$areaArray[0]." and ".$areaArray[1];
} }
if($_POST["searchText"]!=NULL){ if($_POST["searchText"]!=NULL){
$sql = $sql . " and name like '%".$_POST['searchText']."%'"; $sql = $sql . " and name like '%".$_POST['searchText']."%'";
} }
$result = $wpdb->get_results($sql); $result = $wpdb->get_results($sql);
$data = array(); $data = array();
foreach ($result as $key => $value) { foreach ($result as $key => $value) {
$data[$key] = array( $data[$key] = array(
'id' => $value->id, 'id' => $value->id,
'name' => $value->name, 'name' => $value->name,
'community_name' => $value->community_name, 'community_name' => $value->community_name,
'total_price' => $value->total_price, 'total_price' => $value->total_price,
'average_price'=> $value->average_price, 'average_price'=> $value->average_price,
'buildproperty_id' => $value->literal, 'buildproperty_id' => $value->literal,
'covered_area' => $value->covered_area, 'covered_area' => $value->covered_area,
'floor' => $value->floor, 'floor' => $value->floor,
'faceto' => $value->faceto, 'faceto' => $value->faceto,
'decoration' => $value->decoration, 'decoration' => $value->decoration,
'age' => $value->age, 'age' => $value->age,
'user_id' => $value->consul_name, 'user_id' => $value->consul_name,
); );
if($value->status == 0){ if($value->status == 0){
$data[$key]['status'] ="未审核"; $data[$key]['status'] ="未审核";
}else if($value->status == 1){ }else if($value->status == 1){
$data[$key]['status'] ="审核"; $data[$key]['status'] ="审核";
}else if($value->status == 2){ }else if($value->status == 2){
$data[$key]['status'] ="自售"; $data[$key]['status'] ="自售";
}else if($value->status == 3){ }else if($value->status == 3){
$data[$key]['status'] ="他售"; $data[$key]['status'] ="他售";
}else if($value->status == 4){ }else if($value->status == 4){
$data[$key]['status'] ="无效"; $data[$key]['status'] ="无效";
}else if($value->status == 5){ }else if($value->status == 5){
$data[$key]['status'] ="重激活"; $data[$key]['status'] ="重激活";
} }
} }
function usort_reorder($a, $b) function usort_reorder($a, $b)
{ {
$orderby = (!empty($_REQUEST['orderby'])) ? $_REQUEST['orderby'] : 'valid'; //If no sort, default to title $orderby = (!empty($_REQUEST['orderby'])) ? $_REQUEST['orderby'] : 'valid'; //If no sort, default to title
$order = (!empty($_REQUEST['order'])) ? $_REQUEST['order'] : 'desc'; //If no order, default to asc $order = (!empty($_REQUEST['order'])) ? $_REQUEST['order'] : 'desc'; //If no order, default to asc
$result = strcmp($a[$orderby], $b[$orderby]); //Determine sort order $result = strcmp($a[$orderby], $b[$orderby]); //Determine sort order
return ($order === 'asc') ? $result : -$result; //Send final sort direction to usort return ($order === 'asc') ? $result : -$result; //Send final sort direction to usort
} }
usort($data, 'usort_reorder'); usort($data, 'usort_reorder');
$current_page = $this->get_pagenum(); $current_page = $this->get_pagenum();
$total_items = count($data); $total_items = count($data);
$data = array_slice($data, (($current_page - 1) * $per_page), $per_page); $data = array_slice($data, (($current_page - 1) * $per_page), $per_page);
$this->items = $data; $this->items = $data;
$this->set_pagination_args(array( $this->set_pagination_args(array(
'total_items' => $total_items, //WE have to calculate the total number of items 'total_items' => $total_items, //WE have to calculate the total number of items
'per_page' => $per_page, //WE have to determine how many items to show on a page 'per_page' => $per_page, //WE have to determine how many items to show on a page
'total_pages' => ceil($total_items / $per_page) //WE have to calculate the total number of pages 'total_pages' => ceil($total_items / $per_page) //WE have to calculate the total number of pages
)); ));
} }
} }
add_action( 'wp_ajax_updateList', 'newHouseList::prepare_items'); add_action( 'wp_ajax_updateList', 'newHouseList::prepare_items');
add_action( 'wp_ajax_nopriv_updateList', 'newHouseList::prepare_items'); add_action( 'wp_ajax_nopriv_updateList', 'newHouseList::prepare_items');
function function_secHandHouseList() function function_secHandHouseList()
{ {
$contest = array(); $contest = array();
$contest['page'] = $_REQUEST['page']; $contest['page'] = $_REQUEST['page'];
$contest['city'] = SearchDao::searchCity(); $contest['city'] = SearchDao::searchCity();
$contest['status'] = SearchDao::searchStatusType(2); $contest['status'] = SearchDao::searchStatusType(2);
$contest['buildProperty'] = SearchDao::searchBuildProperty(); $contest['buildProperty'] = SearchDao::searchBuildProperty();
if(isset($_POST['hasSearch'])){ if(isset($_POST['hasSearch'])){
$contest['district'] = SearchDao::searchCity($_POST['listCity']); $contest['district'] = SearchDao::searchCity($_POST['listCity']);
$contest['plate'] = SearchDao::searchCity($_POST['listCity'],$_POST['listDistrict']); $contest['plate'] = SearchDao::searchCity($_POST['listCity'],$_POST['listDistrict']);
$contest['dicTotalPrice'] = searchDao::searchTotalPrice($_POST['listCity']); $contest['dicTotalPrice'] = searchDao::searchTotalPrice($_POST['listCity']);
$contest['dicArea'] = searchDao::searchArea($_POST['listCity']); $contest['dicArea'] = searchDao::searchArea($_POST['listCity']);
$contest['cityId'] = $_POST['listCity']; $contest['cityId'] = $_POST['listCity'];
$contest['districtId'] = $_POST['listDistrict']; $contest['districtId'] = $_POST['listDistrict'];
$contest['plateId' ]= $_POST['listPlate']; $contest['plateId' ]= $_POST['listPlate'];
$contest['buildPropertyId']= $_POST['buildProperty']; $contest['buildPropertyId']= $_POST['buildProperty'];
$contest['totalPrice'] = $_POST['totalPrice']; $contest['totalPrice'] = $_POST['totalPrice'];
$contest['acreage'] = $_POST['acreage']; $contest['acreage'] = $_POST['acreage'];
$contest['statusId'] = $_POST['status']; $contest['statusId'] = $_POST['status'];
} }
Timber::render("secHandHouseList.html",$contest); Timber::render("secHandHouseList.html",$contest);
} }
function addSecTable(){ function addSecTable(){
$secHandHouseList = new secHandHouseList(); $secHandHouseList = new secHandHouseList();
$secHandHouseList->prepare_items(); $secHandHouseList->prepare_items();
$secHandHouseList->display(); $secHandHouseList->display();
} }
?> ?>
This source diff could not be displayed because it is too large. You can view the blob instead.
/*!
* jQuery Validation Plugin v1.14.0
*
* http://jqueryvalidation.org/
*
* Copyright (c) 2015 Jörn Zaefferer
* Released under the MIT license
*/
(function( factory ) {
if ( typeof define === "function" && define.amd ) {
define( ["jquery"], factory );
} else {
factory( jQuery );
}
}(function( $ ) {
$.extend($.fn, {
// http://jqueryvalidation.org/validate/
validate: function( options ) {
// if nothing is selected, return nothing; can't chain anyway
if ( !this.length ) {
if ( options && options.debug && window.console ) {
console.warn( "Nothing selected, can't validate, returning nothing." );
}
return;
}
// check if a validator for this form was already created
var validator = $.data( this[ 0 ], "validator" );
if ( validator ) {
return validator;
}
// Add novalidate tag if HTML5.
this.attr( "novalidate", "novalidate" );
validator = new $.validator( options, this[ 0 ] );
$.data( this[ 0 ], "validator", validator );
if ( validator.settings.onsubmit ) {
this.on( "click.validate", ":submit", function( event ) {
if ( validator.settings.submitHandler ) {
validator.submitButton = event.target;
}
// allow suppressing validation by adding a cancel class to the submit button
if ( $( this ).hasClass( "cancel" ) ) {
validator.cancelSubmit = true;
}
// allow suppressing validation by adding the html5 formnovalidate attribute to the submit button
if ( $( this ).attr( "formnovalidate" ) !== undefined ) {
validator.cancelSubmit = true;
}
});
// validate the form on submit
this.on( "submit.validate", function( event ) {
if ( validator.settings.debug ) {
// prevent form submit to be able to see console output
event.preventDefault();
}
function handle() {
var hidden, result;
if ( validator.settings.submitHandler ) {
if ( validator.submitButton ) {
// insert a hidden input as a replacement for the missing submit button
hidden = $( "<input type='hidden'/>" )
.attr( "name", validator.submitButton.name )
.val( $( validator.submitButton ).val() )
.appendTo( validator.currentForm );
}
result = validator.settings.submitHandler.call( validator, validator.currentForm, event );
if ( validator.submitButton ) {
// and clean up afterwards; thanks to no-block-scope, hidden can be referenced
hidden.remove();
}
if ( result !== undefined ) {
return result;
}
return false;
}
return true;
}
// prevent submit for invalid forms or custom submit handlers
if ( validator.cancelSubmit ) {
validator.cancelSubmit = false;
return handle();
}
if ( validator.form() ) {
if ( validator.pendingRequest ) {
validator.formSubmitted = true;
return false;
}
return handle();
} else {
validator.focusInvalid();
return false;
}
});
}
return validator;
},
// http://jqueryvalidation.org/valid/
valid: function() {
var valid, validator, errorList;
if ( $( this[ 0 ] ).is( "form" ) ) {
valid = this.validate().form();
} else {
errorList = [];
valid = true;
validator = $( this[ 0 ].form ).validate();
this.each( function() {
valid = validator.element( this ) && valid;
errorList = errorList.concat( validator.errorList );
});
validator.errorList = errorList;
}
return valid;
},
// http://jqueryvalidation.org/rules/
rules: function( command, argument ) {
var element = this[ 0 ],
settings, staticRules, existingRules, data, param, filtered;
if ( command ) {
settings = $.data( element.form, "validator" ).settings;
staticRules = settings.rules;
existingRules = $.validator.staticRules( element );
switch ( command ) {
case "add":
$.extend( existingRules, $.validator.normalizeRule( argument ) );
// remove messages from rules, but allow them to be set separately
delete existingRules.messages;
staticRules[ element.name ] = existingRules;
if ( argument.messages ) {
settings.messages[ element.name ] = $.extend( settings.messages[ element.name ], argument.messages );
}
break;
case "remove":
if ( !argument ) {
delete staticRules[ element.name ];
return existingRules;
}
filtered = {};
$.each( argument.split( /\s/ ), function( index, method ) {
filtered[ method ] = existingRules[ method ];
delete existingRules[ method ];
if ( method === "required" ) {
$( element ).removeAttr( "aria-required" );
}
});
return filtered;
}
}
data = $.validator.normalizeRules(
$.extend(
{},
$.validator.classRules( element ),
$.validator.attributeRules( element ),
$.validator.dataRules( element ),
$.validator.staticRules( element )
), element );
// make sure required is at front
if ( data.required ) {
param = data.required;
delete data.required;
data = $.extend( { required: param }, data );
$( element ).attr( "aria-required", "true" );
}
// make sure remote is at back
if ( data.remote ) {
param = data.remote;
delete data.remote;
data = $.extend( data, { remote: param });
}
return data;
}
});
// Custom selectors
$.extend( $.expr[ ":" ], {
// http://jqueryvalidation.org/blank-selector/
blank: function( a ) {
return !$.trim( "" + $( a ).val() );
},
// http://jqueryvalidation.org/filled-selector/
filled: function( a ) {
return !!$.trim( "" + $( a ).val() );
},
// http://jqueryvalidation.org/unchecked-selector/
unchecked: function( a ) {
return !$( a ).prop( "checked" );
}
});
// constructor for validator
$.validator = function( options, form ) {
this.settings = $.extend( true, {}, $.validator.defaults, options );
this.currentForm = form;
this.init();
};
// http://jqueryvalidation.org/jQuery.validator.format/
$.validator.format = function( source, params ) {
if ( arguments.length === 1 ) {
return function() {
var args = $.makeArray( arguments );
args.unshift( source );
return $.validator.format.apply( this, args );
};
}
if ( arguments.length > 2 && params.constructor !== Array ) {
params = $.makeArray( arguments ).slice( 1 );
}
if ( params.constructor !== Array ) {
params = [ params ];
}
$.each( params, function( i, n ) {
source = source.replace( new RegExp( "\\{" + i + "\\}", "g" ), function() {
return n;
});
});
return source;
};
$.extend( $.validator, {
defaults: {
messages: {},
groups: {},
rules: {},
errorClass: "error",
validClass: "valid",
errorElement: "label",
focusCleanup: false,
focusInvalid: true,
errorContainer: $( [] ),
errorLabelContainer: $( [] ),
onsubmit: true,
ignore: ":hidden",
ignoreTitle: false,
onfocusin: function( element ) {
this.lastActive = element;
// Hide error label and remove error class on focus if enabled
if ( this.settings.focusCleanup ) {
if ( this.settings.unhighlight ) {
this.settings.unhighlight.call( this, element, this.settings.errorClass, this.settings.validClass );
}
this.hideThese( this.errorsFor( element ) );
}
},
onfocusout: function( element ) {
if ( !this.checkable( element ) && ( element.name in this.submitted || !this.optional( element ) ) ) {
this.element( element );
}
},
onkeyup: function( element, event ) {
// Avoid revalidate the field when pressing one of the following keys
// Shift => 16
// Ctrl => 17
// Alt => 18
// Caps lock => 20
// End => 35
// Home => 36
// Left arrow => 37
// Up arrow => 38
// Right arrow => 39
// Down arrow => 40
// Insert => 45
// Num lock => 144
// AltGr key => 225
var excludedKeys = [
16, 17, 18, 20, 35, 36, 37,
38, 39, 40, 45, 144, 225
];
if ( event.which === 9 && this.elementValue( element ) === "" || $.inArray( event.keyCode, excludedKeys ) !== -1 ) {
return;
} else if ( element.name in this.submitted || element === this.lastElement ) {
this.element( element );
}
},
onclick: function( element ) {
// click on selects, radiobuttons and checkboxes
if ( element.name in this.submitted ) {
this.element( element );
// or option elements, check parent select in that case
} else if ( element.parentNode.name in this.submitted ) {
this.element( element.parentNode );
}
},
highlight: function( element, errorClass, validClass ) {
if ( element.type === "radio" ) {
this.findByName( element.name ).addClass( errorClass ).removeClass( validClass );
} else {
$( element ).addClass( errorClass ).removeClass( validClass );
}
},
unhighlight: function( element, errorClass, validClass ) {
if ( element.type === "radio" ) {
this.findByName( element.name ).removeClass( errorClass ).addClass( validClass );
} else {
$( element ).removeClass( errorClass ).addClass( validClass );
}
}
},
// http://jqueryvalidation.org/jQuery.validator.setDefaults/
setDefaults: function( settings ) {
$.extend( $.validator.defaults, settings );
},
messages: {
required: "This field is required.",
remote: "Please fix this field.",
email: "Please enter a valid email address.",
url: "Please enter a valid URL.",
date: "Please enter a valid date.",
dateISO: "Please enter a valid date ( ISO ).",
number: "Please enter a valid number.",
digits: "Please enter only digits.",
creditcard: "Please enter a valid credit card number.",
equalTo: "Please enter the same value again.",
maxlength: $.validator.format( "Please enter no more than {0} characters." ),
minlength: $.validator.format( "Please enter at least {0} characters." ),
rangelength: $.validator.format( "Please enter a value between {0} and {1} characters long." ),
range: $.validator.format( "Please enter a value between {0} and {1}." ),
max: $.validator.format( "Please enter a value less than or equal to {0}." ),
min: $.validator.format( "Please enter a value greater than or equal to {0}." )
},
autoCreateRanges: false,
prototype: {
init: function() {
this.labelContainer = $( this.settings.errorLabelContainer );
this.errorContext = this.labelContainer.length && this.labelContainer || $( this.currentForm );
this.containers = $( this.settings.errorContainer ).add( this.settings.errorLabelContainer );
this.submitted = {};
this.valueCache = {};
this.pendingRequest = 0;
this.pending = {};
this.invalid = {};
this.reset();
var groups = ( this.groups = {} ),
rules;
$.each( this.settings.groups, function( key, value ) {
if ( typeof value === "string" ) {
value = value.split( /\s/ );
}
$.each( value, function( index, name ) {
groups[ name ] = key;
});
});
rules = this.settings.rules;
$.each( rules, function( key, value ) {
rules[ key ] = $.validator.normalizeRule( value );
});
function delegate( event ) {
var validator = $.data( this.form, "validator" ),
eventType = "on" + event.type.replace( /^validate/, "" ),
settings = validator.settings;
if ( settings[ eventType ] && !$( this ).is( settings.ignore ) ) {
settings[ eventType ].call( validator, this, event );
}
}
$( this.currentForm )
.on( "focusin.validate focusout.validate keyup.validate",
":text, [type='password'], [type='file'], select, textarea, [type='number'], [type='search'], " +
"[type='tel'], [type='url'], [type='email'], [type='datetime'], [type='date'], [type='month'], " +
"[type='week'], [type='time'], [type='datetime-local'], [type='range'], [type='color'], " +
"[type='radio'], [type='checkbox']", delegate)
// Support: Chrome, oldIE
// "select" is provided as event.target when clicking a option
.on("click.validate", "select, option, [type='radio'], [type='checkbox']", delegate);
if ( this.settings.invalidHandler ) {
$( this.currentForm ).on( "invalid-form.validate", this.settings.invalidHandler );
}
// Add aria-required to any Static/Data/Class required fields before first validation
// Screen readers require this attribute to be present before the initial submission http://www.w3.org/TR/WCAG-TECHS/ARIA2.html
$( this.currentForm ).find( "[required], [data-rule-required], .required" ).attr( "aria-required", "true" );
},
// http://jqueryvalidation.org/Validator.form/
form: function() {
this.checkForm();
$.extend( this.submitted, this.errorMap );
this.invalid = $.extend({}, this.errorMap );
if ( !this.valid() ) {
$( this.currentForm ).triggerHandler( "invalid-form", [ this ]);
}
this.showErrors();
return this.valid();
},
checkForm: function() {
this.prepareForm();
for ( var i = 0, elements = ( this.currentElements = this.elements() ); elements[ i ]; i++ ) {
this.check( elements[ i ] );
}
return this.valid();
},
// http://jqueryvalidation.org/Validator.element/
element: function( element ) {
var cleanElement = this.clean( element ),
checkElement = this.validationTargetFor( cleanElement ),
result = true;
this.lastElement = checkElement;
if ( checkElement === undefined ) {
delete this.invalid[ cleanElement.name ];
} else {
this.prepareElement( checkElement );
this.currentElements = $( checkElement );
result = this.check( checkElement ) !== false;
if ( result ) {
delete this.invalid[ checkElement.name ];
} else {
this.invalid[ checkElement.name ] = true;
}
}
// Add aria-invalid status for screen readers
$( element ).attr( "aria-invalid", !result );
if ( !this.numberOfInvalids() ) {
// Hide error containers on last error
this.toHide = this.toHide.add( this.containers );
}
this.showErrors();
return result;
},
// http://jqueryvalidation.org/Validator.showErrors/
showErrors: function( errors ) {
if ( errors ) {
// add items to error list and map
$.extend( this.errorMap, errors );
this.errorList = [];
for ( var name in errors ) {
this.errorList.push({
message: errors[ name ],
element: this.findByName( name )[ 0 ]
});
}
// remove items from success list
this.successList = $.grep( this.successList, function( element ) {
return !( element.name in errors );
});
}
if ( this.settings.showErrors ) {
this.settings.showErrors.call( this, this.errorMap, this.errorList );
} else {
this.defaultShowErrors();
}
},
// http://jqueryvalidation.org/Validator.resetForm/
resetForm: function() {
if ( $.fn.resetForm ) {
$( this.currentForm ).resetForm();
}
this.submitted = {};
this.lastElement = null;
this.prepareForm();
this.hideErrors();
var i, elements = this.elements()
.removeData( "previousValue" )
.removeAttr( "aria-invalid" );
if ( this.settings.unhighlight ) {
for ( i = 0; elements[ i ]; i++ ) {
this.settings.unhighlight.call( this, elements[ i ],
this.settings.errorClass, "" );
}
} else {
elements.removeClass( this.settings.errorClass );
}
},
numberOfInvalids: function() {
return this.objectLength( this.invalid );
},
objectLength: function( obj ) {
/* jshint unused: false */
var count = 0,
i;
for ( i in obj ) {
count++;
}
return count;
},
hideErrors: function() {
this.hideThese( this.toHide );
},
hideThese: function( errors ) {
errors.not( this.containers ).text( "" );
this.addWrapper( errors ).hide();
},
valid: function() {
return this.size() === 0;
},
size: function() {
return this.errorList.length;
},
focusInvalid: function() {
if ( this.settings.focusInvalid ) {
try {
$( this.findLastActive() || this.errorList.length && this.errorList[ 0 ].element || [])
.filter( ":visible" )
.focus()
// manually trigger focusin event; without it, focusin handler isn't called, findLastActive won't have anything to find
.trigger( "focusin" );
} catch ( e ) {
// ignore IE throwing errors when focusing hidden elements
}
}
},
findLastActive: function() {
var lastActive = this.lastActive;
return lastActive && $.grep( this.errorList, function( n ) {
return n.element.name === lastActive.name;
}).length === 1 && lastActive;
},
elements: function() {
var validator = this,
rulesCache = {};
// select all valid inputs inside the form (no submit or reset buttons)
return $( this.currentForm )
.find( "input, select, textarea" )
.not( ":submit, :reset, :image, :disabled" )
.not( this.settings.ignore )
.filter( function() {
if ( !this.name && validator.settings.debug && window.console ) {
console.error( "%o has no name assigned", this );
}
// select only the first element for each name, and only those with rules specified
if ( this.name in rulesCache || !validator.objectLength( $( this ).rules() ) ) {
return false;
}
rulesCache[ this.name ] = true;
return true;
});
},
clean: function( selector ) {
return $( selector )[ 0 ];
},
errors: function() {
var errorClass = this.settings.errorClass.split( " " ).join( "." );
return $( this.settings.errorElement + "." + errorClass, this.errorContext );
},
reset: function() {
this.successList = [];
this.errorList = [];
this.errorMap = {};
this.toShow = $( [] );
this.toHide = $( [] );
this.currentElements = $( [] );
},
prepareForm: function() {
this.reset();
this.toHide = this.errors().add( this.containers );
},
prepareElement: function( element ) {
this.reset();
this.toHide = this.errorsFor( element );
},
elementValue: function( element ) {
var val,
$element = $( element ),
type = element.type;
if ( type === "radio" || type === "checkbox" ) {
return this.findByName( element.name ).filter(":checked").val();
} else if ( type === "number" && typeof element.validity !== "undefined" ) {
return element.validity.badInput ? false : $element.val();
}
val = $element.val();
if ( typeof val === "string" ) {
return val.replace(/\r/g, "" );
}
return val;
},
check: function( element ) {
element = this.validationTargetFor( this.clean( element ) );
var rules = $( element ).rules(),
rulesCount = $.map( rules, function( n, i ) {
return i;
}).length,
dependencyMismatch = false,
val = this.elementValue( element ),
result, method, rule;
for ( method in rules ) {
rule = { method: method, parameters: rules[ method ] };
try {
result = $.validator.methods[ method ].call( this, val, element, rule.parameters );
// if a method indicates that the field is optional and therefore valid,
// don't mark it as valid when there are no other rules
if ( result === "dependency-mismatch" && rulesCount === 1 ) {
dependencyMismatch = true;
continue;
}
dependencyMismatch = false;
if ( result === "pending" ) {
this.toHide = this.toHide.not( this.errorsFor( element ) );
return;
}
if ( !result ) {
this.formatAndAdd( element, rule );
return false;
}
} catch ( e ) {
if ( this.settings.debug && window.console ) {
console.log( "Exception occurred when checking element " + element.id + ", check the '" + rule.method + "' method.", e );
}
if ( e instanceof TypeError ) {
e.message += ". Exception occurred when checking element " + element.id + ", check the '" + rule.method + "' method.";
}
throw e;
}
}
if ( dependencyMismatch ) {
return;
}
if ( this.objectLength( rules ) ) {
this.successList.push( element );
}
return true;
},
// return the custom message for the given element and validation method
// specified in the element's HTML5 data attribute
// return the generic message if present and no method specific message is present
customDataMessage: function( element, method ) {
return $( element ).data( "msg" + method.charAt( 0 ).toUpperCase() +
method.substring( 1 ).toLowerCase() ) || $( element ).data( "msg" );
},
// return the custom message for the given element name and validation method
customMessage: function( name, method ) {
var m = this.settings.messages[ name ];
return m && ( m.constructor === String ? m : m[ method ]);
},
// return the first defined argument, allowing empty strings
findDefined: function() {
for ( var i = 0; i < arguments.length; i++) {
if ( arguments[ i ] !== undefined ) {
return arguments[ i ];
}
}
return undefined;
},
defaultMessage: function( element, method ) {
return this.findDefined(
this.customMessage( element.name, method ),
this.customDataMessage( element, method ),
// title is never undefined, so handle empty string as undefined
!this.settings.ignoreTitle && element.title || undefined,
$.validator.messages[ method ],
"<strong>Warning: No message defined for " + element.name + "</strong>"
);
},
formatAndAdd: function( element, rule ) {
var message = this.defaultMessage( element, rule.method ),
theregex = /\$?\{(\d+)\}/g;
if ( typeof message === "function" ) {
message = message.call( this, rule.parameters, element );
} else if ( theregex.test( message ) ) {
message = $.validator.format( message.replace( theregex, "{$1}" ), rule.parameters );
}
this.errorList.push({
message: message,
element: element,
method: rule.method
});
this.errorMap[ element.name ] = message;
this.submitted[ element.name ] = message;
},
addWrapper: function( toToggle ) {
if ( this.settings.wrapper ) {
toToggle = toToggle.add( toToggle.parent( this.settings.wrapper ) );
}
return toToggle;
},
defaultShowErrors: function() {
var i, elements, error;
for ( i = 0; this.errorList[ i ]; i++ ) {
error = this.errorList[ i ];
if ( this.settings.highlight ) {
this.settings.highlight.call( this, error.element, this.settings.errorClass, this.settings.validClass );
}
this.showLabel( error.element, error.message );
}
if ( this.errorList.length ) {
this.toShow = this.toShow.add( this.containers );
}
if ( this.settings.success ) {
for ( i = 0; this.successList[ i ]; i++ ) {
this.showLabel( this.successList[ i ] );
}
}
if ( this.settings.unhighlight ) {
for ( i = 0, elements = this.validElements(); elements[ i ]; i++ ) {
this.settings.unhighlight.call( this, elements[ i ], this.settings.errorClass, this.settings.validClass );
}
}
this.toHide = this.toHide.not( this.toShow );
this.hideErrors();
this.addWrapper( this.toShow ).show();
},
validElements: function() {
return this.currentElements.not( this.invalidElements() );
},
invalidElements: function() {
return $( this.errorList ).map(function() {
return this.element;
});
},
showLabel: function( element, message ) {
var place, group, errorID,
error = this.errorsFor( element ),
elementID = this.idOrName( element ),
describedBy = $( element ).attr( "aria-describedby" );
if ( error.length ) {
// refresh error/success class
error.removeClass( this.settings.validClass ).addClass( this.settings.errorClass );
// replace message on existing label
error.html( message );
} else {
// create error element
error = $( "<" + this.settings.errorElement + ">" )
.attr( "id", elementID + "-error" )
.addClass( this.settings.errorClass )
.html( message || "" );
// Maintain reference to the element to be placed into the DOM
place = error;
if ( this.settings.wrapper ) {
// make sure the element is visible, even in IE
// actually showing the wrapped element is handled elsewhere
place = error.hide().show().wrap( "<" + this.settings.wrapper + "/>" ).parent();
}
if ( this.labelContainer.length ) {
this.labelContainer.append( place );
} else if ( this.settings.errorPlacement ) {
this.settings.errorPlacement( place, $( element ) );
} else {
place.insertAfter( element );
}
// Link error back to the element
if ( error.is( "label" ) ) {
// If the error is a label, then associate using 'for'
error.attr( "for", elementID );
} else if ( error.parents( "label[for='" + elementID + "']" ).length === 0 ) {
// If the element is not a child of an associated label, then it's necessary
// to explicitly apply aria-describedby
errorID = error.attr( "id" ).replace( /(:|\.|\[|\]|\$)/g, "\\$1");
// Respect existing non-error aria-describedby
if ( !describedBy ) {
describedBy = errorID;
} else if ( !describedBy.match( new RegExp( "\\b" + errorID + "\\b" ) ) ) {
// Add to end of list if not already present
describedBy += " " + errorID;
}
$( element ).attr( "aria-describedby", describedBy );
// If this element is grouped, then assign to all elements in the same group
group = this.groups[ element.name ];
if ( group ) {
$.each( this.groups, function( name, testgroup ) {
if ( testgroup === group ) {
$( "[name='" + name + "']", this.currentForm )
.attr( "aria-describedby", error.attr( "id" ) );
}
});
}
}
}
if ( !message && this.settings.success ) {
error.text( "" );
if ( typeof this.settings.success === "string" ) {
error.addClass( this.settings.success );
} else {
this.settings.success( error, element );
}
}
this.toShow = this.toShow.add( error );
},
errorsFor: function( element ) {
var name = this.idOrName( element ),
describer = $( element ).attr( "aria-describedby" ),
selector = "label[for='" + name + "'], label[for='" + name + "'] *";
// aria-describedby should directly reference the error element
if ( describer ) {
selector = selector + ", #" + describer.replace( /\s+/g, ", #" );
}
return this
.errors()
.filter( selector );
},
idOrName: function( element ) {
return this.groups[ element.name ] || ( this.checkable( element ) ? element.name : element.id || element.name );
},
validationTargetFor: function( element ) {
// If radio/checkbox, validate first element in group instead
if ( this.checkable( element ) ) {
element = this.findByName( element.name );
}
// Always apply ignore filter
return $( element ).not( this.settings.ignore )[ 0 ];
},
checkable: function( element ) {
return ( /radio|checkbox/i ).test( element.type );
},
findByName: function( name ) {
return $( this.currentForm ).find( "[name='" + name + "']" );
},
getLength: function( value, element ) {
switch ( element.nodeName.toLowerCase() ) {
case "select":
return $( "option:selected", element ).length;
case "input":
if ( this.checkable( element ) ) {
return this.findByName( element.name ).filter( ":checked" ).length;
}
}
return value.length;
},
depend: function( param, element ) {
return this.dependTypes[typeof param] ? this.dependTypes[typeof param]( param, element ) : true;
},
dependTypes: {
"boolean": function( param ) {
return param;
},
"string": function( param, element ) {
return !!$( param, element.form ).length;
},
"function": function( param, element ) {
return param( element );
}
},
optional: function( element ) {
var val = this.elementValue( element );
return !$.validator.methods.required.call( this, val, element ) && "dependency-mismatch";
},
startRequest: function( element ) {
if ( !this.pending[ element.name ] ) {
this.pendingRequest++;
this.pending[ element.name ] = true;
}
},
stopRequest: function( element, valid ) {
this.pendingRequest--;
// sometimes synchronization fails, make sure pendingRequest is never < 0
if ( this.pendingRequest < 0 ) {
this.pendingRequest = 0;
}
delete this.pending[ element.name ];
if ( valid && this.pendingRequest === 0 && this.formSubmitted && this.form() ) {
$( this.currentForm ).submit();
this.formSubmitted = false;
} else if (!valid && this.pendingRequest === 0 && this.formSubmitted ) {
$( this.currentForm ).triggerHandler( "invalid-form", [ this ]);
this.formSubmitted = false;
}
},
previousValue: function( element ) {
return $.data( element, "previousValue" ) || $.data( element, "previousValue", {
old: null,
valid: true,
message: this.defaultMessage( element, "remote" )
});
},
// cleans up all forms and elements, removes validator-specific events
destroy: function() {
this.resetForm();
$( this.currentForm )
.off( ".validate" )
.removeData( "validator" );
}
},
classRuleSettings: {
required: { required: true },
email: { email: true },
url: { url: true },
date: { date: true },
dateISO: { dateISO: true },
number: { number: true },
digits: { digits: true },
creditcard: { creditcard: true }
},
addClassRules: function( className, rules ) {
if ( className.constructor === String ) {
this.classRuleSettings[ className ] = rules;
} else {
$.extend( this.classRuleSettings, className );
}
},
classRules: function( element ) {
var rules = {},
classes = $( element ).attr( "class" );
if ( classes ) {
$.each( classes.split( " " ), function() {
if ( this in $.validator.classRuleSettings ) {
$.extend( rules, $.validator.classRuleSettings[ this ]);
}
});
}
return rules;
},
normalizeAttributeRule: function( rules, type, method, value ) {
// convert the value to a number for number inputs, and for text for backwards compability
// allows type="date" and others to be compared as strings
if ( /min|max/.test( method ) && ( type === null || /number|range|text/.test( type ) ) ) {
value = Number( value );
// Support Opera Mini, which returns NaN for undefined minlength
if ( isNaN( value ) ) {
value = undefined;
}
}
if ( value || value === 0 ) {
rules[ method ] = value;
} else if ( type === method && type !== "range" ) {
// exception: the jquery validate 'range' method
// does not test for the html5 'range' type
rules[ method ] = true;
}
},
attributeRules: function( element ) {
var rules = {},
$element = $( element ),
type = element.getAttribute( "type" ),
method, value;
for ( method in $.validator.methods ) {
// support for <input required> in both html5 and older browsers
if ( method === "required" ) {
value = element.getAttribute( method );
// Some browsers return an empty string for the required attribute
// and non-HTML5 browsers might have required="" markup
if ( value === "" ) {
value = true;
}
// force non-HTML5 browsers to return bool
value = !!value;
} else {
value = $element.attr( method );
}
this.normalizeAttributeRule( rules, type, method, value );
}
// maxlength may be returned as -1, 2147483647 ( IE ) and 524288 ( safari ) for text inputs
if ( rules.maxlength && /-1|2147483647|524288/.test( rules.maxlength ) ) {
delete rules.maxlength;
}
return rules;
},
dataRules: function( element ) {
var rules = {},
$element = $( element ),
type = element.getAttribute( "type" ),
method, value;
for ( method in $.validator.methods ) {
value = $element.data( "rule" + method.charAt( 0 ).toUpperCase() + method.substring( 1 ).toLowerCase() );
this.normalizeAttributeRule( rules, type, method, value );
}
return rules;
},
staticRules: function( element ) {
var rules = {},
validator = $.data( element.form, "validator" );
if ( validator.settings.rules ) {
rules = $.validator.normalizeRule( validator.settings.rules[ element.name ] ) || {};
}
return rules;
},
normalizeRules: function( rules, element ) {
// handle dependency check
$.each( rules, function( prop, val ) {
// ignore rule when param is explicitly false, eg. required:false
if ( val === false ) {
delete rules[ prop ];
return;
}
if ( val.param || val.depends ) {
var keepRule = true;
switch ( typeof val.depends ) {
case "string":
keepRule = !!$( val.depends, element.form ).length;
break;
case "function":
keepRule = val.depends.call( element, element );
break;
}
if ( keepRule ) {
rules[ prop ] = val.param !== undefined ? val.param : true;
} else {
delete rules[ prop ];
}
}
});
// evaluate parameters
$.each( rules, function( rule, parameter ) {
rules[ rule ] = $.isFunction( parameter ) ? parameter( element ) : parameter;
});
// clean number parameters
$.each([ "minlength", "maxlength" ], function() {
if ( rules[ this ] ) {
rules[ this ] = Number( rules[ this ] );
}
});
$.each([ "rangelength", "range" ], function() {
var parts;
if ( rules[ this ] ) {
if ( $.isArray( rules[ this ] ) ) {
rules[ this ] = [ Number( rules[ this ][ 0 ]), Number( rules[ this ][ 1 ] ) ];
} else if ( typeof rules[ this ] === "string" ) {
parts = rules[ this ].replace(/[\[\]]/g, "" ).split( /[\s,]+/ );
rules[ this ] = [ Number( parts[ 0 ]), Number( parts[ 1 ] ) ];
}
}
});
if ( $.validator.autoCreateRanges ) {
// auto-create ranges
if ( rules.min != null && rules.max != null ) {
rules.range = [ rules.min, rules.max ];
delete rules.min;
delete rules.max;
}
if ( rules.minlength != null && rules.maxlength != null ) {
rules.rangelength = [ rules.minlength, rules.maxlength ];
delete rules.minlength;
delete rules.maxlength;
}
}
return rules;
},
// Converts a simple string to a {string: true} rule, e.g., "required" to {required:true}
normalizeRule: function( data ) {
if ( typeof data === "string" ) {
var transformed = {};
$.each( data.split( /\s/ ), function() {
transformed[ this ] = true;
});
data = transformed;
}
return data;
},
// http://jqueryvalidation.org/jQuery.validator.addMethod/
addMethod: function( name, method, message ) {
$.validator.methods[ name ] = method;
$.validator.messages[ name ] = message !== undefined ? message : $.validator.messages[ name ];
if ( method.length < 3 ) {
$.validator.addClassRules( name, $.validator.normalizeRule( name ) );
}
},
methods: {
// http://jqueryvalidation.org/required-method/
required: function( value, element, param ) {
// check if dependency is met
if ( !this.depend( param, element ) ) {
return "dependency-mismatch";
}
if ( element.nodeName.toLowerCase() === "select" ) {
// could be an array for select-multiple or a string, both are fine this way
var val = $( element ).val();
return val && val.length > 0;
}
if ( this.checkable( element ) ) {
return this.getLength( value, element ) > 0;
}
return value.length > 0;
},
// http://jqueryvalidation.org/email-method/
email: function( value, element ) {
// From https://html.spec.whatwg.org/multipage/forms.html#valid-e-mail-address
// Retrieved 2014-01-14
// If you have a problem with this implementation, report a bug against the above spec
// Or use custom methods to implement your own email validation
return this.optional( element ) || /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/.test( value );
},
// http://jqueryvalidation.org/url-method/
url: function( value, element ) {
// Copyright (c) 2010-2013 Diego Perini, MIT licensed
// https://gist.github.com/dperini/729294
// see also https://mathiasbynens.be/demo/url-regex
// modified to allow protocol-relative URLs
return this.optional( element ) || /^(?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})).?)(?::\d{2,5})?(?:[/?#]\S*)?$/i.test( value );
},
// http://jqueryvalidation.org/date-method/
date: function( value, element ) {
return this.optional( element ) || !/Invalid|NaN/.test( new Date( value ).toString() );
},
// http://jqueryvalidation.org/dateISO-method/
dateISO: function( value, element ) {
return this.optional( element ) || /^\d{4}[\/\-](0?[1-9]|1[012])[\/\-](0?[1-9]|[12][0-9]|3[01])$/.test( value );
},
// http://jqueryvalidation.org/number-method/
number: function( value, element ) {
return this.optional( element ) || /^(?:-?\d+|-?\d{1,3}(?:,\d{3})+)?(?:\.\d+)?$/.test( value );
},
// http://jqueryvalidation.org/digits-method/
digits: function( value, element ) {
return this.optional( element ) || /^\d+$/.test( value );
},
// http://jqueryvalidation.org/creditcard-method/
// based on http://en.wikipedia.org/wiki/Luhn_algorithm
creditcard: function( value, element ) {
if ( this.optional( element ) ) {
return "dependency-mismatch";
}
// accept only spaces, digits and dashes
if ( /[^0-9 \-]+/.test( value ) ) {
return false;
}
var nCheck = 0,
nDigit = 0,
bEven = false,
n, cDigit;
value = value.replace( /\D/g, "" );
// Basing min and max length on
// http://developer.ean.com/general_info/Valid_Credit_Card_Types
if ( value.length < 13 || value.length > 19 ) {
return false;
}
for ( n = value.length - 1; n >= 0; n--) {
cDigit = value.charAt( n );
nDigit = parseInt( cDigit, 10 );
if ( bEven ) {
if ( ( nDigit *= 2 ) > 9 ) {
nDigit -= 9;
}
}
nCheck += nDigit;
bEven = !bEven;
}
return ( nCheck % 10 ) === 0;
},
// http://jqueryvalidation.org/minlength-method/
minlength: function( value, element, param ) {
var length = $.isArray( value ) ? value.length : this.getLength( value, element );
return this.optional( element ) || length >= param;
},
// http://jqueryvalidation.org/maxlength-method/
maxlength: function( value, element, param ) {
var length = $.isArray( value ) ? value.length : this.getLength( value, element );
return this.optional( element ) || length <= param;
},
// http://jqueryvalidation.org/rangelength-method/
rangelength: function( value, element, param ) {
var length = $.isArray( value ) ? value.length : this.getLength( value, element );
return this.optional( element ) || ( length >= param[ 0 ] && length <= param[ 1 ] );
},
// http://jqueryvalidation.org/min-method/
min: function( value, element, param ) {
return this.optional( element ) || value >= param;
},
// http://jqueryvalidation.org/max-method/
max: function( value, element, param ) {
return this.optional( element ) || value <= param;
},
// http://jqueryvalidation.org/range-method/
range: function( value, element, param ) {
return this.optional( element ) || ( value >= param[ 0 ] && value <= param[ 1 ] );
},
// http://jqueryvalidation.org/equalTo-method/
equalTo: function( value, element, param ) {
// bind to the blur event of the target in order to revalidate whenever the target field is updated
// TODO find a way to bind the event just once, avoiding the unbind-rebind overhead
var target = $( param );
if ( this.settings.onfocusout ) {
target.off( ".validate-equalTo" ).on( "blur.validate-equalTo", function() {
$( element ).valid();
});
}
return value === target.val();
},
// http://jqueryvalidation.org/remote-method/
remote: function( value, element, param ) {
if ( this.optional( element ) ) {
return "dependency-mismatch";
}
var previous = this.previousValue( element ),
validator, data;
if (!this.settings.messages[ element.name ] ) {
this.settings.messages[ element.name ] = {};
}
previous.originalMessage = this.settings.messages[ element.name ].remote;
this.settings.messages[ element.name ].remote = previous.message;
param = typeof param === "string" && { url: param } || param;
if ( previous.old === value ) {
return previous.valid;
}
previous.old = value;
validator = this;
this.startRequest( element );
data = {};
data[ element.name ] = value;
$.ajax( $.extend( true, {
mode: "abort",
port: "validate" + element.name,
dataType: "json",
data: data,
context: validator.currentForm,
success: function( response ) {
var valid = response === true || response === "true",
errors, message, submitted;
validator.settings.messages[ element.name ].remote = previous.originalMessage;
if ( valid ) {
submitted = validator.formSubmitted;
validator.prepareElement( element );
validator.formSubmitted = submitted;
validator.successList.push( element );
delete validator.invalid[ element.name ];
validator.showErrors();
} else {
errors = {};
message = response || validator.defaultMessage( element, "remote" );
errors[ element.name ] = previous.message = $.isFunction( message ) ? message( value ) : message;
validator.invalid[ element.name ] = true;
validator.showErrors( errors );
}
previous.valid = valid;
validator.stopRequest( element, valid );
}
}, param ) );
return "pending";
}
}
});
// ajax mode: abort
// usage: $.ajax({ mode: "abort"[, port: "uniqueport"]});
// if mode:"abort" is used, the previous request on that port (port can be undefined) is aborted via XMLHttpRequest.abort()
var pendingRequests = {},
ajax;
// Use a prefilter if available (1.5+)
if ( $.ajaxPrefilter ) {
$.ajaxPrefilter(function( settings, _, xhr ) {
var port = settings.port;
if ( settings.mode === "abort" ) {
if ( pendingRequests[port] ) {
pendingRequests[port].abort();
}
pendingRequests[port] = xhr;
}
});
} else {
// Proxy ajax
ajax = $.ajax;
$.ajax = function( settings ) {
var mode = ( "mode" in settings ? settings : $.ajaxSettings ).mode,
port = ( "port" in settings ? settings : $.ajaxSettings ).port;
if ( mode === "abort" ) {
if ( pendingRequests[port] ) {
pendingRequests[port].abort();
}
pendingRequests[port] = ajax.apply(this, arguments);
return pendingRequests[port];
}
return ajax.apply(this, arguments);
};
}
}));
\ No newline at end of file
<div class="wrap"> <div class="wrap">
<h2>新房列表</h2> <h2>新房列表</h2>
<form id="scores-filter" method="POST"> <form id="scores-filter" method="POST">
<!-- For plugins, we also need to ensure that the form posts back to our current page --> <!-- For plugins, we also need to ensure that the form posts back to our current page -->
<input type="hidden" name="page" value="{{page}}"/> <input type="hidden" name="page" value="{{page}}"/>
<select id="listCity" name="listCity"> <select id="listCity" name="listCity">
<option value="0"> 城市</option> <option value="0"> 城市</option>
{% for item in city %} {% for item in city %}
<option {{ item.id == cityId ?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option> <option {{ item.id == cityId ?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option>
{% endfor %} {% endfor %}
</select> </select>
<select id="listDistrict" name="listDistrict"> <select id="listDistrict" name="listDistrict">
<option value="0">区域</option> <option value="0">区域</option>
{% if district %} {% if district %}
{% for item in district %} {% for item in district %}
<option {{ item.id == districtId ?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option> <option {{ item.id == districtId ?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option>
{% endfor %} {% endfor %}
{% endif %} {% endif %}
</select> </select>
<select id="listPlate" name="listPlate"> <select id="listPlate" name="listPlate">
<option value="0">板块</option> <option value="0">板块</option>
{% if plate %} {% if plate %}
{% for item in plate %} {% for item in plate %}
<option {{ item.id == plateId ?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option> <option {{ item.id == plateId ?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option>
{% endfor %} {% endfor %}
{% endif %} {% endif %}
</select> </select>
<select id="totalPrice" name="totalPrice"> <select id="totalPrice" name="totalPrice">
<option value ="">价格</option> <option value ="">价格</option>
{% if dicTotalPrice %} {% if dicTotalPrice %}
{% for item in dicTotalPrice %} {% for item in dicTotalPrice %}
<option {{ item.value == totalPrice ?"selected":"" }} value="{{ item.value }}">{{ item.value }}</option> <option {{ item.value == totalPrice ?"selected":"" }} value="{{ item.value }}">{{ item.value }}</option>
{% endfor %} {% endfor %}
{% endif %} {% endif %}
</select> </select>
<select id="room" name="room"> <select id="room" name="room">
<option value="0">类型</option> <option value="0">类型</option>
{% for item in room %} {% for item in room %}
<option {{ item.id == roomId ?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option> <option {{ item.id == roomId ?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option>
{% endfor %} {% endfor %}
</select> </select>
<select id="buildProperty" name="buildProperty"> <select id="buildProperty" name="buildProperty">
<option value="0"> 房型</option> <option value="0"> 房型</option>
{% for item in buildProperty %} {% for item in buildProperty %}
<option {{ item.id == buildPropertyId ?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option> <option {{ item.id == buildPropertyId ?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option>
{% endfor %} {% endfor %}
</select> </select>
<select id="acreage" name="acreage"> <select id="acreage" name="acreage">
<option value ="">面积</option> <option value ="">面积</option>
{% if acreage %} {% if acreage %}
{% for item in dicArea %} {% for item in dicArea %}
<option {{ item.value == acreage ?"selected":"" }} value="{{ item.value }}">{{ item.value }}</option> <option {{ item.value == acreage ?"selected":"" }} value="{{ item.value }}">{{ item.value }}</option>
{% endfor %} {% endfor %}
{% endif %} {% endif %}
</select> </select>
<select name="status" name="status"> <select name="status" name="status">
<option value="-1">状态</option> <option value="-1">状态</option>
{% for item in status%} {% for item in status%}
<option {{ item.id == statusId ?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option> <option {{ item.id == statusId ?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option>
{% endfor %} {% endfor %}
</select> </select>
<input type="text" placeholder="请出入楼盘名" name="searchText"> <input type="text" placeholder="请出入楼盘名" name="searchText">
<input type="hidden" name="hasSearch" value="1"/> <input type="hidden" name="hasSearch" value="1"/>
<input type="submit" id="submit" class="button action" value="搜索"> <input type="submit" id="submit" class="button action" value="搜索">
<!-- Now we can render the completed list table --> <!-- Now we can render the completed list table -->
{{function("addNewHouseTable")}} {{function("addNewHouseTable")}}
</form> </form>
</div> </div>
<script> <script>
(function ($) { (function ($) {
$(document).ready(function(){ $(document).ready(function(){
$("#listCity").change(function(){ $("#listCity").change(function(){
var listCityId = $("#listCity").val(); var listCityId = $("#listCity").val();
var district =$("#listDistrict"); var district =$("#listDistrict");
var acreage =$("#acreage"); var acreage =$("#acreage");
var totalPrice = $("#totalPrice"); var totalPrice = $("#totalPrice");
$('#listDistrict').find('option:not(:first-child)').remove(); $('#listDistrict').find('option:not(:first-child)').remove();
$('#listPlate').find('option:not(:first-child)').remove(); $('#listPlate').find('option:not(:first-child)').remove();
$('#acreage').find('option:not(:first-child)').remove(); $('#acreage').find('option:not(:first-child)').remove();
$('#totalPrice').find('option:not(:first-child)').remove(); $('#totalPrice').find('option:not(:first-child)').remove();
$.ajax({ $.ajax({
type: "GET", type: "GET",
url: "/tospur/wp-admin/admin-ajax.php", url: "/tospur/wp-admin/admin-ajax.php",
data: "action=serachCity&cityId="+listCityId, data: "action=serachCity&cityId="+listCityId,
success:function(json){ success:function(json){
addOption(json,district); addOption(json,district);
} }
}); });
//面积 //面积
$.ajax({ $.ajax({
type: "GET", type: "GET",
url: "/tospur/wp-admin/admin-ajax.php", url: "/tospur/wp-admin/admin-ajax.php",
data: "action=searchArea&cityId="+listCityId, data: "action=searchArea&cityId="+listCityId,
success:function(json){ success:function(json){
for(var i = 0; i <=json.length-1; i++){ for(var i = 0; i <=json.length-1; i++){
var id = json[i]["id"]; var id = json[i]["id"];
var value = json[i]["value"]; var value = json[i]["value"];
var Option = $("<option>").attr({"value": value}).append(value); var Option = $("<option>").attr({"value": value}).append(value);
$("#acreage").append(Option); $("#acreage").append(Option);
} }
} }
}); });
//城市联动房子价格 //城市联动房子价格
$.ajax({ $.ajax({
type: "GET", type: "GET",
url: "/tospur/wp-admin/admin-ajax.php", url: "/tospur/wp-admin/admin-ajax.php",
data: "action=searchTotalPrice&cityId="+listCityId, data: "action=searchTotalPrice&cityId="+listCityId,
success:function(json){ success:function(json){
for(var i = 0; i <=json.length-1; i++){ for(var i = 0; i <=json.length-1; i++){
var id = json[i]["id"]; var id = json[i]["id"];
var value = json[i]["value"]; var value = json[i]["value"];
var Option = $("<option>").attr({"value": value}).append(value); var Option = $("<option>").attr({"value": value}).append(value);
$("#totalPrice").append(Option); $("#totalPrice").append(Option);
} }
} }
}); });
}) })
$("#listDistrict").change(function(){ $("#listDistrict").change(function(){
var listCityId = $("#listCity").val(); var listCityId = $("#listCity").val();
var listDistrict = $("#listDistrict").val(); var listDistrict = $("#listDistrict").val();
var listPlate = $("#listPlate"); var listPlate = $("#listPlate");
$('#listPlate').find('option:not(:first-child)').remove(); $('#listPlate').find('option:not(:first-child)').remove();
$.ajax({ $.ajax({
type: "GET", type: "GET",
url: "/tospur/wp-admin/admin-ajax.php", url: "/tospur/wp-admin/admin-ajax.php",
data: "action=serachCity&cityId="+listCityId+"&districtId="+listDistrict, data: "action=serachCity&cityId="+listCityId+"&districtId="+listDistrict,
success:function(json){ success:function(json){
addOption(json,listPlate); addOption(json,listPlate);
} }
}); });
}) })
function addOption(json,select){ function addOption(json,select){
for(var i = 0; i <=json.length-1; i++){ for(var i = 0; i <=json.length-1; i++){
var id = json[i]["id"]; var id = json[i]["id"];
var value = json[i]["value"]; var value = json[i]["value"];
var Option = $("<option>").attr({"value": id}).append(value); var Option = $("<option>").attr({"value": id}).append(value);
select.append(Option); select.append(Option);
} }
} }
}); });
})(jQuery); })(jQuery);
</script> </script>
\ No newline at end of file
<!DOCTYPE HTML> <!DOCTYPE HTML>
<html> <html>
<head> <head>
{% set title = houseId?"修改新房房源":"添加新房房源" %} {% set title = houseId?"修改新房房源":"添加新房房源" %}
<meta charset="utf-8"> <meta charset="utf-8">
<title>{{title}}</title> <title>{{title}}</title>
</head> </head>
<body> <body>
<h2 class="title">{{title}}</h2> <h2 class="title">{{title}}</h2>
<form action="" method="POST" enctype="multipart/form-data"> <form action="" method="POST" enctype="multipart/form-data" id="newHouse">
<table class="form-table"> <div class="row">
<tbody> <div class="col-md-11">
<tr> <div class="row">
<th><label for="housename">楼盘名</label></th> <div class="col-md-8">
<td> <input name="housename" id="housename" type="text" value="{{result.name}}" class="regular-text code" style="width: 150px;"></td> <table class="form-table">
</tr> <tbody>
<tr> <tr>
<th><label for="mark">标签:</label></th> <th><label for="housename">楼盘名</label></th>
<td> <input name="mark" id="mark" type="text" value="{{mark}}" class="regular-text code"></td> <td> <input name="housename" id="housename" type="text" value="{{result.name}}" class="form-control" style="width: 150px;"></td>
</tr> </tr>
<tr>
<th><label for="community_name">小区名</label></th> <tr>
<td> <input name="community_name" id="community_name" type="text" value="{{result.community_name}}" style="width: 150px;" class="regular-text code" ></td> <th><label for="mark">标签:</label></th>
</tr> <td> <input name="mark" id="mark" type="text" value="{{mark}}" class="form-control"></td>
<tr> </tr>
<th><label for="average_price">均价</label></th> <tr>
<td> <input name="average_price" id="average_price" type="text" value="{{result.average_price}}" class="regular-text code" style="width: 90px;"></td> <th><label for="community_name">小区名</label></th>
</tr> <td> <input name="community_name" id="community_name" type="text" value="{{result.community_name}}" style="width: 150px;" class="form-control" ></td>
<tr> </tr>
<th><label for="latest_news">最新动态</label></th> <tr>
<td><textarea name="latest_news" rows="4" cols="40" class="large-text code" style="width: 400px;">{{result.latest_news}}</textarea></td> <th><label for="address">地址</label></th>
</tr> <td> <input name="address" type="text" value="{{result.address}}" class="form-control"></td>
<tr> </tr>
<th><label for="from">所属地区</label></th> <tr>
<td> <th><label for="average_price">均价</label></th>
<select id="baseCity" name="baseCity"> <td> <input name="average_price" id="average_price" type="text" value="{{result.average_price}}" class="form-control" style="width: 90px;"></td>
<option value="-1"> 城市</option> </tr>
{% for item in city %} <tr>
<option {{ item.id == result.city_id?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option> <th><label for="latest_news">最新动态</label></th>
{% endfor %} <td><textarea name="latest_news" rows="4" cols="40" class="form-control" style="width: 400px;">{{result.latest_news}}</textarea></td>
</select> </tr>
<select id="baseAreaId" name="baseAreaId"> </tbody>
<option value = "-1">区域</option> </table>
{% if district %} </div>
{% for item in district %} </div>
<option {{ item.id == result.district_id?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option>
{% endfor %} <h2 class="title">位置及周边</h2>
{% endif %} <div class="row">
</select> <div class="col-md-8">
<select id="basePlateId" name="basePlateId"> <table class="form-table">
<option value = "-1">板块</option> <tbody>
{% if district %} <tr>
{% for item in plate %} <th><label for="from">所属地区</label></th>
<option {{ item.id == result.plate_id?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option> <td>
{% endfor %} <select id="baseCity" name="baseCity">
{% endif %} <option value="-1"> 城市</option>
</select> {% for item in city %}
</td> <option {{ item.id == result.city_id?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option>
</tr> {% endfor %}
<tr> </select>
<th><label for="location">地域坐标</label></th> <select id="baseAreaId" name="baseAreaId">
<td> <input name="location" id="location" type="text" value="{{result.location}}" class="regular-text code"></td> <option value = "-1">区域</option>
</tr> {% if district %}
<tr> {% for item in district %}
<th><label for="mainHouse">主力户型</label></th> <option {{ item.id == result.district_id?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option>
<td> {% endfor %}
<div id="preview"> {% endif %}
{% set exists_ids = "" %} </select>
{% for item in mainImage %} <select id="basePlateId" name="basePlateId">
{% if exists_ids != "" %} <option value = "-1">板块</option>
{% set exists_ids = exists_ids~"," %} {% if district %}
{% endif %} {% for item in plate %}
{% set exists_ids = exists_ids~item.id %} <option {{ item.id == result.plate_id?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option>
<div> {% endfor %}
<img src="{{siteUrl}}{{item.path}}" heghit="100" width="100"><br /> {% endif %}
<select name="exists[{{item.id}}][buildProperty]"> </select>
{% for i in buildProperty %} </td>
<option {{ i.id == item.buildproperty_id?"selected":"" }} value="{{i.id}}">{{i.value}}</option> </tr>
{% endfor %} <tr>
</select> <th><label for="location">地域坐标</label></th>
<input type="text" placeholder="面积" name="exists[{{item.id}}][housearea]" class="regular-text" value="{{item.area}}"> <td> <input name="location" id="location" type="text" value="{{result.location}}" class="form-control"></td>
<input type="button" value="取消" class="cancel existsCancel"> </tr>
</div> <tr>
{% endfor %} <th><label for="traffic">交通线路</label></th>
<input type="hidden" name="exists_ids" value="{{exists_ids}}" > <td> <input name="traffic" type="text" value="{{result.traffic}}" class="form-control" style="width: 300px;"></td>
<input type="file" name="files[0]" property="0" class = "files"multiple class="browser button button-hero"> </tr>
<P></P> <tr>
</div> <th><label for="periphery">周边配套</label></th>
</td> <td> <input name="periphery" type="text" value="{{result.periphery}}" class="form-control" style="width: 300px;"></td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
<h2 class="title">位置及周边</h2> </div>
<table class="form-table"> </div>
<tbody>
<tr> <h2 class="title">基本信息</h2>
<th><label for="address">地址</label></th> <div class="row">
<td> <input name="address" type="text" value="{{result.address}}" class="regular-text code"></td> <div class="col-md-8">
</tr> <table class="form-table">
<tr> <tbody>
<th><label for="traffic">交通线路</label></th> <tr>
<td> <input name="traffic" type="text" value="{{result.traffic}}" class="regular-text code" style="width: 300px;"></td> <th><label for="developers">建筑类型</label></th>
</tr> <td>
<tr> <select id="baseRoom" name="baseRoom">
<th><label for="periphery">周边配套</label></th> {% for item in room %}
<td> <input name="periphery" type="text" value="{{result.periphery}}" class="regular-text code" style="width: 300px;"></td> <option {{ item.id == result.room_id?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option>
</tr> {% endfor %}
</tbody> </select>
</table> </td>
<h2 class="title">基本信息</h2> </tr>
<table class="form-table"> <tr>
<tbody> <th><label for="developers">开发商</label></th>
<tr> <td> <input name="developers" type="text" value="{{result.developer}}" class="form-control" style="width: 150px;"></td>
<th><label for="developers">建筑类型</label></th> </tr>
<td> <tr>
<select id="baseRoom" name="baseRoom"> <th><label for="check_in_time">入住时间</label></th>
{% for item in room %} <td> <input name="check_in_time" id="checkin" type="text" value="{{result.check_in_time}}" class="form-control" style="width: 150px;"></td>
<option {{ item.id == result.room_id?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option> </tr>
{% endfor %} <tr>
</select> <th><label for="property_age">产权年限</label></th>
</td> <td> <input name="property_age" type="text" value="{{result.property_age}}" class="form-control" style="width: 90px;"></td>
</tr> </tr>
<tr> <tr>
<th><label for="developers">开发商</label></th> <th><label for="decoration">装修状况</label></th>
<td> <input name="developers" type="text" value="{{result.developer}}" class="regular-text code" style="width: 150px;"></td> <td> <input name="decoration" type="text" value="{{result.decoration}}" class="form-control"style="width: 90px;"></td>
</tr> </tr>
<tr> <tr>
<th><label for="check_in_time">入住时间</label></th> <th><label for="covered_area">建筑面积</label></th>
<td> <input name="check_in_time" id="checkin" type="text" value="{{result.check_in_time}}" class="regular-text code" style="width: 150px;"></td> <td> <input name="covered_area" type="text" value="{{result.covered_area}}" class="form-control" style="width: 90px;"></td>
</tr> </tr>
<tr> <tr>
<th><label for="property_age">产权年限</label></th> <th><label for="volume_rate">容积率</label></th>
<td> <input name="property_age" type="text" value="{{result.property_age}}" class="regular-text code" style="width: 90px;"></td> <td> <input name="volume_rate" type="text" value="{{result.volume_rate}}" class="form-control" style="width: 50px;"></td>
</tr> </tr>
<tr> <tr>
<th><label for="decoration">装修状况</label></th> <th><label for="greening_rate">绿化率</label></th>
<td> <input name="decoration" type="text" value="{{result.decoration}}" class="regular-text code"style="width: 90px;"></td> <td> <input name="greening_rate" type="text" value="{{result.greening_rate}}" class="form-control" style="width: 50px;"></td>
</tr> </tr>
<tr> <tr>
<th><label for="covered_area">建筑面积</label></th> <th><label for="households">规划户数</label></th>
<td> <input name="covered_area" type="text" value="{{result.covered_area}}" class="regular-text code" style="width: 90px;"></td> <td> <input name="households" type="text" value="{{result.households}}" class="form-control" style="width: 50px;"></td>
</tr> </tr>
<tr> <tr>
<th><label for="volume_rate">容积率</label></th> <th><label for="parking_spaces">车位数</label></th>
<td> <input name="volume_rate" type="text" value="{{result.volume_rate}}" class="regular-text code" style="width: 50px;"></td> <td> <input name="parking_spaces" type="text" value="{{result.parking_spaces}}" class="form-control" style="width: 50px;"></td>
</tr> </tr>
<tr> <tr>
<th><label for="greening_rate">绿化率</label></th> <th><label for="property_management">物业公司</label></th>
<td> <input name="greening_rate" type="text" value="{{result.greening_rate}}" class="regular-text code" style="width: 50px;"></td> <td> <input name="property_management" type="text" value="{{result.property_management}}" class="form-control" style="width: 150px;"></td>
</tr> </tr>
<tr> <tr>
<th><label for="households">规划户数</label></th> <th><label for="property_money">物业费</label></th>
<td> <input name="households" type="text" value="{{result.households}}" class="regular-text code" style="width: 50px;"></td> <td> <input name="property_money" type="text" value="{{result.property_money}}" class="form-control" style="width: 50px;"></td>
</tr> </tr>
<tr> <tr>
<th><label for="parking_spaces">车位数</label></th> <th><label for="overview">楼盘概述</label></th>
<td> <input name="parking_spaces" type="text" value="{{result.parking_spaces}}" class="regular-text code" style="width: 50px;"></td> <td> <textarea name="overview" rows="4" cols="40" class="form-control" style="width: 400px;">{{result.overview}}</textarea></td>
</tr> </tr>
<tr> </tbody>
<th><label for="property_management">物业公司</label></th> </table>
<td> <input name="property_management" type="text" value="{{result.property_management}}" class="regular-text code" style="width: 150px;"></td> </div>
</tr> </div>
<tr>
<th><label for="property_money">物业费</label></th> <h2 class="title">关联信息</h2>
<td> <input name="property_money" type="text" value="{{result.property_money}}" class="regular-text code" style="width: 50px;"></td> <div class="row">
</tr> <div class="col-md-12">
<tr> <table class="form-table">
<th><label for="overview">楼盘概述</label></th> <tbody>
<td> <textarea name="overview" rows="4" cols="40" class="large-text code" style="width: 400px;">{{result.overview}}</textarea></td> <tr>
</tr> <th><label for="mainHouse">主力户型</label></th>
</tbody> <td>
</table> <div id="preview">
<h2 class="title">关联信息</h2> {% set exists_ids = "" %}
<table class="form-table"> {% for item in mainImage %}
<tbody> {% if exists_ids != "" %}
<tr> {% set exists_ids = exists_ids~"," %}
<th><label>房源相册</label></th> {% endif %}
<td> {% set exists_ids = exists_ids~item.id %}
<div id="picList"> <div>
{% set exists_photo_ids = "" %} <img src="{{siteUrl}}{{item.path}}" heghit="100" width="100"><br />
{% for item in images %} <select name="exists[{{item.id}}][buildProperty]">
{% if exists_photo_ids != "" %} {% for i in buildProperty %}
{% set exists_photo_ids = exists_photo_ids~"," %} <option {{ i.id == item.buildproperty_id?"selected":"" }} value="{{i.id}}">{{i.value}}</option>
{% endif %} {% endfor %}
{% set exists_photo_ids = exists_photo_ids~item.image_id %} </select>
<p> <input type="text" placeholder="面积" name="exists[{{item.id}}][housearea]" class="form-control" value="{{item.area}}">
<input type="radio" name="frontCover" value="{{item.image_id}}" {{ result.frontCover_id == item.image_id?"checked":"" }} /> <input type="button" value="取消" class="cancel existsCancel">
<select name="exists_photo[{{ item.image_id }}][type]"> </div>
{% for i in photoType %} {% endfor %}
<option {{ i.id == item.image_type?"selected":"" }} value="{{ i.id }}">{{ i.value }}</option> <input type="hidden" name="exists_ids" value="{{exists_ids}}" >
{% endfor %} <input type="file" name="files[0]" property="0" class = "files"multiple class="browser button button-hero">
</select> <P></P>
<img src="{{siteUrl}}{{item.path}}" heghit="100" width="100"> </div>
<input type="button" value="取消" class="cancel existsCancel"> </td>
</p> </tr>
{% endfor %} <tr>
<input type="hidden" name="exists_photo_ids" value="{{exists_photo_ids}}" > <th><label>房源相册</label></th>
</div><br /> <td>
<button type="button" id="housePicture" class="button action" data-toggle="modal"> <div id="picList">
新增 {% set exists_photo_ids = "" %}
</button> {% for item in images %}
</td> {% if exists_photo_ids != "" %}
</tr> {% set exists_photo_ids = exists_photo_ids~"," %}
<tr> {% endif %}
<th><label for="traffic">推荐房源</label></th> {% set exists_photo_ids = exists_photo_ids~item.image_id %}
<td> <p>
<div id="houseImg"> <input type="radio" name="frontCover" value="{{item.image_id}}" {{ result.frontCover_id == item.image_id?"checked":"" }} />
{% for item in recommends %} <select name="exists_photo[{{ item.image_id }}][type]">
<p> {% for i in photoType %}
<img src="{{siteUrl}}{{item.path}}" height="100" width="100"> <option {{ i.id == item.image_type?"selected":"" }} value="{{ i.id }}">{{ i.value }}</option>
<input type="button" value="删除" class="imgCancel existsCancel"> {% endfor %}
<input type="hidden" name="data[recommend][]" value="{{item.id}}"> </select>
</p> <img src="{{siteUrl}}{{item.path}}" heghit="100" width="100">
{% endfor %} <input type="button" value="取消" class="cancel existsCancel">
</div><br /> </p>
<button type="button" class="button action" data-toggle="modal" data-target="#myModal" id="recHouseBt"> {% endfor %}
添加房源 <input type="hidden" name="exists_photo_ids" value="{{exists_photo_ids}}" >
</button> </div><br />
</td> <button type="button" id="housePicture" class="button action" data-toggle="modal">
</tr> 新增
<tr> </button>
<th><label for="periphery">置业顾问</label></th> </td>
<td> </tr>
<div id="consultantImg"> <tr>
{% for item in consultant %} <th><label for="traffic">推荐房源</label></th>
<p> <td>
<span>{{item.name}}</span> <div id="houseImg">
<input type="button" value="删除" class="consultantCancel existsCancel"> {% for item in recommends %}
<input type="hidden" name="data[recConsultant][]" value="{{item.id}}"> <p>
</p> <img src="{{siteUrl}}{{item.path}}" height="100" width="100">
{% endfor %} <input type="button" value="删除" class="imgCancel existsCancel">
</div><br /> <input type="hidden" name="data[recommend][]" value="{{item.id}}">
<button type="button" class="button action" data-toggle="modal" data-target="#myConsultant" id="recConsultantBt"> </p>
选择置业顾问 {% endfor %}
</button> </div><br />
</td> <button type="button" class="button action" data-toggle="modal" data-target="#myModal" id="recHouseBt">
</tr> 添加房源
{% if role == 'administrator' %} </button>
<tr> </td>
<th><label for="from">状态</label></th> </tr>
<td> <tr>
<select id="status" name="status"> <th><label for="periphery">置业顾问</label></th>
{% for item in status %} <td>
<option value={{item.id}}>{{item.value}}</option> <div id="consultantImg">
{% endfor %} {% for item in consultant %}
</select> <p>
</td> <span>{{item.name}}</span>
</tr> <input type="button" value="删除" class="consultantCancel existsCancel">
{% endif %} <input type="hidden" name="data[recConsultant][]" value="{{item.id}}">
</tbody> </p>
</table> {% endfor %}
<input type="text" name="type" value="1" hidden="hidden"> </div><br />
{% if houseId %} <button type="button" class="button action" data-toggle="modal" data-target="#myConsultant" id="recConsultantBt">
<input type="text" name="houseId" value="{{houseId}}" hidden="hidden"> 选择置业顾问
{% endif %} </button>
<input type="submit" id="submit" class="button action"> </td>
</form> </tr>
{% if role == 'administrator' %}
<tr>
<!-- Modal --> <th><label for="from">状态</label></th>
<!-- 新增房源弹出层 --> <td>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> <select id="status" name="status">
<div class="modal-dialog" role="document"> {% for item in status %}
<div class="modal-content"> <option value={{item.id}}>{{item.value}}</option>
{% endfor %}
<div class="modal-body" style="height: 300px;overflow: auto;"> </select>
<select id="cityId"> </td>
</select> </tr>
<select id="areaId"> {% endif %}
<option value = "-1">区域</option> </tbody>
</select> </table>
<select id="plateId"> </div>
<option value = "-1">板块</option> </div>
</select>
<select id="price"> <input type="text" name="type" value="1" hidden="hidden">
<option value = "-1">价格</option> {% if houseId %}
</select> <input type="text" name="houseId" value="{{houseId}}" hidden="hidden">
<select id="buildProperty"> {% endif %}
<option value = "-1">房型</option> </div>
{% for item in buildProperty %} <div class = "col-md-1">
<option value="{{ item.id }}">{{ item.value }}</option> <input type="submit" id="submit" class="button action" style="position: fixed;">
{% endfor %} </div>
</select> </div>
<select id="room"> </form>
<option value = "-1">类型</option>
{% for item in room %}
<option value="{{ item.id }}">{{ item.value }}</option> <!-- Modal -->
{% endfor %} <!-- 新增房源弹出层 -->
</select> <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<select id="acreage"> <div class="modal-dialog" role="document">
<option value = "-1">面积</option> <div class="modal-content">
</select>
<input type="text" placeholder="请出入楼盘名/地段名搜索" id="searchtext"> <div class="modal-body" style="height: 300px;overflow: auto;">
<button type="button" class="button action" id="search">搜索</button> <select id="cityId">
<ul id="houseList"> </select>
</ul> <select id="areaId">
</div> <option value = "-1">区域</option>
</div> </select>
</div> <select id="plateId">
</div> <option value = "-1">板块</option>
</select>
<!-- 置业顾问弹出层 --> <select id="price">
<div class="modal fade" id="myConsultant" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> <option value = "-1">价格</option>
<div class="modal-dialog" role="document"> </select>
<div class="modal-content"> <select id="buildProperty">
<div class="modal-body" style="height: 300px;overflow: auto;"> <option value = "-1">房型</option>
<select id="consultCity"> {% for item in buildProperty %}
</select> <option value="{{ item.id }}">{{ item.value }}</option>
<input type="text" placeholder="请出入置业顾问姓名搜索" id="consultantName"> {% endfor %}
<button type="button" class="button action" id="searchConsult">搜索</button> </select>
<ul id="consultantList"> <select id="room">
</ul> <option value = "-1">类型</option>
</div> {% for item in room %}
</div> <option value="{{ item.id }}">{{ item.value }}</option>
</div> {% endfor %}
</div> </select>
<select id="acreage">
<option value = "-1">面积</option>
<script> </select>
(function($){ <input type="text" placeholder="请出入楼盘名/地段名搜索" id="searchtext">
$(document).ready(function(){ <button type="button" class="button action" id="search">搜索</button>
<ul id="houseList">
//主力房源中选择图片file的下标 </ul>
var i = 0; </div>
//入住时间选择 </div>
$("#checkin").datepicker({ </div>
dateFormat: "yy-mm-dd" </div>
});
//主力房源选择文件 <!-- 置业顾问弹出层 -->
$("form").on("change",".files",function(){ <div class="modal fade" id="myConsultant" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
readURL(this,1); <div class="modal-dialog" role="document">
$(this).hide(); <div class="modal-content">
}); <div class="modal-body" style="height: 300px;overflow: auto;">
<select id="consultCity">
//主力房源中图片的删除功能 </select>
$("form").on("click",".cancel",function(){ <input type="text" placeholder="请出入置业顾问姓名搜索" id="consultantName" class="form-control">
$buttonid = $(this).attr("property"); <button type="button" class="button action" id="searchConsult">搜索</button>
$("[property = "+$buttonid+"]").remove(); <ul id="consultantList">
$("form input[type='file']:last-child").show(); </ul>
</div>
}); </div>
//基本信息的联动AJAX </div>
$("#baseCity").change(function(){ </div>
var cityId = $("#baseCity").val();
var baserArea = $("#baseAreaId");
$('#baseAreaId').find('option:not(:first-child)').remove(); <script>
$('#basePlateId').find('option:not(:first-child)').remove(); (function($){
$(document).ready(function(){
//城市联动区域 var titleFlag = 0;
$.ajax({ //主力房源中选择图片file的下标
type: "GET", var i = 0;
url: "/tospur/wp-admin/admin-ajax.php", //入住时间选择
data: "action=serachCity&cityId="+cityId, $("#checkin").datepicker({
success:function(json){ dateFormat: "yy-mm-dd"
addOption(json,baserArea); });
} //主力房源选择文件
}); $("form").on("change",".files",function(){
}); readURL(this,1);
//区域联动板块 $(this).hide();
$("#baseAreaId").change(function(){ });
var basePlate = $("#basePlateId");
var areaId = $("#baseAreaId").val(); //主力房源中图片的删除功能
var cityId = $("#baseCity").val(); $("form").on("click",".cancel",function(){
$('#basePlateId').find('option:not(:first-child)').remove(); $buttonid = $(this).attr("property");
$.ajax({ $("[property = "+$buttonid+"]").remove();
type: "GET", $("form input[type='file']:last-child").show();
url: "/tospur/wp-admin/admin-ajax.php",
data: "action=serachCity&cityId="+cityId+"&districtId="+areaId, });
success:function(json){ //基本信息的联动AJAX
addOption(json,basePlate); $("#baseCity").change(function(){
} var cityId = $("#baseCity").val();
}); var baserArea = $("#baseAreaId");
}); $('#baseAreaId').find('option:not(:first-child)').remove();
$('#basePlateId').find('option:not(:first-child)').remove();
//根据上方选择的城市,选择推荐房源的默认城市
$("#recHouseBt").click(function(){ //城市联动区域
$('#cityId').find('option').remove(); $.ajax({
$('#areaId').find('option:not(:first-child)').remove(); type: "GET",
$('#plateId').find('option:not(:first-child)').remove(); url: "/tospur/wp-admin/admin-ajax.php",
$('#price').find('option:not(:first-child)').remove(); data: "action=serachCity&cityId="+cityId,
$('#acreage').find('option:not(:first-child)').remove(); success:function(json){
$("#houseList").find("li").remove(); addOption(json,baserArea);
var acreage =$("#acreage"); }
var price = $("#price"); });
var cityId = $("#baseCity").val(); });
var cityName = $("#baseCity").find("option:selected").text(); //区域联动板块
var option = $("<option>").attr("value",cityId).append(cityName); $("#baseAreaId").change(function(){
$("#cityId").append(option); var basePlate = $("#basePlateId");
if(cityId != -1){ var areaId = $("#baseAreaId").val();
var area = $("#areaId"); var cityId = $("#baseCity").val();
$.ajax({ $('#basePlateId').find('option:not(:first-child)').remove();
type: "GET", $.ajax({
url: "/tospur/wp-admin/admin-ajax.php", type: "GET",
data: "action=serachCity&cityId="+cityId, url: "/tospur/wp-admin/admin-ajax.php",
success:function(json){ data: "action=serachCity&cityId="+cityId+"&districtId="+areaId,
addOption(json,area); success:function(json){
} addOption(json,basePlate);
}); }
});
//城市联动房子面积 });
$.ajax({
type: "GET", //根据上方选择的城市,选择推荐房源的默认城市
url: "/tospur/wp-admin/admin-ajax.php", $("#recHouseBt").click(function(){
data: "action=searchArea&cityId="+cityId, $('#cityId').find('option').remove();
success:function(json){ $('#areaId').find('option:not(:first-child)').remove();
addOption(json,acreage); $('#plateId').find('option:not(:first-child)').remove();
} $('#price').find('option:not(:first-child)').remove();
}); $('#acreage').find('option:not(:first-child)').remove();
//城市联动房子价格 $("#houseList").find("li").remove();
$.ajax({ var acreage =$("#acreage");
type: "GET", var price = $("#price");
url: "/tospur/wp-admin/admin-ajax.php", var cityId = $("#baseCity").val();
data: "action=searchUnitPriceRange&cityId="+cityId, var cityName = $("#baseCity").find("option:selected").text();
success:function(json){ var option = $("<option>").attr("value",cityId).append(cityName);
addOption(json,price); $("#cityId").append(option);
} if(cityId != -1){
}); var area = $("#areaId");
addList(0); $.ajax({
} type: "GET",
}); url: "/tospur/wp-admin/admin-ajax.php",
data: "action=serachCity&cityId="+cityId,
//区域联动板块 success:function(json){
$("#areaId").change(function(){ addOption(json,area);
var areaId = $("#areaId").val(); }
var cityId = $("#cityId").val(); });
var plate = $("#plateId");
$("#houseList").find("li").remove(); //城市联动房子面积
$('#plateId').find('option:not(:first-child)').remove(); $.ajax({
$.ajax({ type: "GET",
type: "GET", url: "/tospur/wp-admin/admin-ajax.php",
url: "/tospur/wp-admin/admin-ajax.php", data: "action=searchArea&cityId="+cityId,
data: "action=serachCity&cityId="+cityId+"&districtId="+areaId, success:function(json){
success:function(json){ addOption(json,acreage);
addOption(json,plate); }
} });
}); //城市联动房子价格
}); $.ajax({
type: "GET",
//推荐房源下显示图片信息以及房名 url: "/tospur/wp-admin/admin-ajax.php",
$("#areaId,#plateId,#buildProperty,#room,#acreage,#price").change(function(){ data: "action=searchUnitPriceRange&cityId="+cityId,
addList(0); success:function(json){
}); addOption(json,price);
}
//添加房源中搜索框的搜索 });
$("#search").click(function(){ addList(0);
$searchtext = $("#searchtext").val(); }
$("#houseList").find("li").remove(); });
$.ajax({
type: "post", //区域联动板块
url: "/tospur/wp-admin/admin-ajax.php", $("#areaId").change(function(){
data: "action=searchHouse&searchText="+$searchtext, var areaId = $("#areaId").val();
success:function(json){ var cityId = $("#cityId").val();
var result = json.result; var plate = $("#plateId");
for(var i = 0; i < result.length; i++){ $("#houseList").find("li").remove();
var name = result[i]["name"]; $('#plateId').find('option:not(:first-child)').remove();
var id = result[i]['id']; $.ajax({
var imgUrl = json.images[id]; type: "GET",
var img = $("<img>").attr({"src":imgUrl,"height":100,"width":100}); url: "/tospur/wp-admin/admin-ajax.php",
var li = $("<li>").addClass("addImg").append(img).append(name); data: "action=serachCity&cityId="+cityId+"&districtId="+areaId,
$("#houseList").append(li); success:function(json){
} addOption(json,plate);
} }
}); });
}) });
//根据上方选择的城市,选择推荐置业顾问的默认城市 //推荐房源下显示图片信息以及房名
$("#recConsultantBt").click(function(){ $("#areaId,#plateId,#buildProperty,#room,#acreage,#price").change(function(){
$('#consultCity').find('option').remove(); addList(0);
$("#consultantList").find("li").remove(); });
var consulCityId = $("#baseCity").val();
var consultantName =$("#consultantName").val(); //添加房源中搜索框的搜索
var cityName = $("#baseCity").find("option:selected").text(); $("#search").click(function(){
var option = $("<option>").attr("value",consulCityId).append(cityName); $searchtext = $("#searchtext").val();
$("#consultCity").append(option); $("#houseList").find("li").remove();
$.ajax({ $.ajax({
type: "GET", type: "post",
url: "/tospur/wp-admin/admin-ajax.php", url: "/tospur/wp-admin/admin-ajax.php",
data: "action=searchConsultant&consulCityId="+consulCityId+"&consultantName="+consultantName, data: "action=searchHouse&searchText="+$searchtext,
success:function(json){ success:function(json){
for(var i = 0; i <=json.length-1; i++){ var result = json.result;
var name = json[i]["consultantName"]; for(var i = 0; i < result.length; i++){
var imgUrl = json[i]["imageUrl"]; var name = result[i]["name"];
var img = $("<img>").attr({"src":imgUrl,"height":100,"width":100}); var id = result[i]['id'];
var li = $("<li>").attr("id",json[i]["id"]).append(img).append(name).addClass("consultantImg"); var imgUrl = json.images[id];
$("#consultantList").append(li); var img = $("<img>").attr({"src":imgUrl,"height":100,"width":100});
} var li = $("<li>").addClass("addImg").append(img).append(name);
} $("#houseList").append(li);
}); }
}); }
});
//添加置业顾问弹出层中搜索框的搜索内容 })
$("#searchConsult").click(function(){
var consulCityId = $("#consultCity").val(); //根据上方选择的城市,选择推荐置业顾问的默认城市
var consultantName =$("#consultantName").val(); $("#recConsultantBt").click(function(){
$("#consultantList").find("li").remove(); $('#consultCity').find('option').remove();
$.ajax({ $("#consultantList").find("li").remove();
type: "GET", var consulCityId = $("#baseCity").val();
url: "/tospur/wp-admin/admin-ajax.php", var consultantName =$("#consultantName").val();
data: "action=searchConsultant&consulCityId="+consulCityId+"&consultantName="+consultantName, var cityName = $("#baseCity").find("option:selected").text();
success:function(json){ var option = $("<option>").attr("value",consulCityId).append(cityName);
for( $("#consultCity").append(option);
var i = 0; i <=json.length-1; i++){ $.ajax({
var name = json[i]["consultantName"]; type: "GET",
var imgUrl = json[i]["imageUrl"]; url: "/tospur/wp-admin/admin-ajax.php",
var img = $("<img>").attr({"src":imgUrl,"height":100,"width":100}); data: "action=searchConsultant&consulCityId="+consulCityId+"&consultantName="+consultantName,
var li = $("<li>").append(img).append(name).addClass("consultantImg"); success:function(json){
$("#consultantList").append(li); for(var i = 0; i <=json.length-1; i++){
} var name = json[i]["consultantName"];
} var imgUrl = json[i]["imageUrl"];
}); var img = $("<img>").attr({"src":imgUrl,"height":100,"width":100});
}) var li = $("<li>").attr("id",json[i]["id"]).append(img).append(name).addClass("consultantImg");
$("#consultantList").append(li);
//点击添加房源中显示的列表,在界面中显示 }
$("#houseList").on("click",".addImg",function(){ }
var recommendHouse = $("<input>").attr({"type":"hidden","name":"data[recommend][]","value": $(this).attr("id")}); });
var url = $(this).find("img").attr("src"); });
var img = $("<img>").attr({"src":url,"height":100,"width":100});
var cancel = $("<input>").attr({"type":"button","value":"删除"}).addClass("imgCancel"); //添加置业顾问弹出层中搜索框的搜索内容
var p = $("<p>").append(img).append(cancel).append(recommendHouse); $("#searchConsult").click(function(){
$("#houseImg").append(p); var consulCityId = $("#consultCity").val();
controlCommand(); var consultantName =$("#consultantName").val();
}); $("#consultantList").find("li").remove();
//添加置业顾问 $.ajax({
$("#consultantList").on("click",".consultantImg",function(){ type: "GET",
var recommendConsultant = $("<input>").attr({"type":"hidden","name":"data[recConsultant][]","value": $(this).attr("id")}); url: "/tospur/wp-admin/admin-ajax.php",
var cancel = $("<input>").attr({"type":"button","value":"删除"}).addClass("consultantCancel"); data: "action=searchConsultant&consulCityId="+consulCityId+"&consultantName="+consultantName,
var font = $("<font>").append( $(this).text()); success:function(json){
var p = $("<p>").append(font).append(cancel).append(recommendConsultant); for(var i = 0; i <=json.length-1; i++){
$("#consultantImg").append(p); var name = json[i]["consultantName"];
}); var imgUrl = json[i]["imageUrl"];
var img = $("<img>").attr({"src":imgUrl,"height":100,"width":100});
//新增房源相册 var li = $("<li>").append(img).append(name).addClass("consultantImg");
$("#housePicture").click(function(){ $("#consultantList").append(li);
var checkBox = $("<input>").attr({"type":"radio","name":"frontCover","value":i}); }
var picDelet = $("<input>").attr({"type":"button","value":"删除"}).addClass("picDelet"); }
var file = $("<input>").attr({"type":"file","name":"files["+i+"]"}).addClass("picFiles"); });
var select = $("<select>").attr("name","data["+i+"][type]"); })
{% for item in photoType %}
select.append($("<option>").attr("value",{{item.id}}).append('{{item.value}}')); //点击添加房源中显示的列表,在界面中显示
{% endfor%} $("#houseList").on("click",".addImg",function(){
var p = $("<p>").append(checkBox).append(select).append(file).append(picDelet); var recommendHouse = $("<input>").attr({"type":"hidden","name":"data[recommend][]","value": $(this).attr("id")});
$("#picList").append(p); var url = $(this).find("img").attr("src");
i++ var img = $("<img>").attr({"src":url,"height":100,"width":100});
}); var cancel = $("<input>").attr({"type":"button","value":"删除"}).addClass("button action imgCancel");
var p = $("<p>").append(img).append(cancel).append(recommendHouse);
//房源相册 $("#houseImg").append(p);
$("#picList").on("change",".picFiles",function(){ controlCommand();
readURL(this,2); });
$(this).hide(); //添加置业顾问
}); $("#consultantList").on("click",".consultantImg",function(){
var recommendConsultant = $("<input>").attr({"type":"hidden","name":"data[recConsultant][]","value": $(this).attr("id")});
//删除房源相册、推荐房源、推荐置业顾问 var cancel = $("<input>").attr({"type":"button","value":"删除"}).addClass("button action consultantCancel");
$("#houseImg,#consultantImg,#picList").on("click",".imgCancel,.consultantCancel,.picDelet",function(){ var font = $("<font>").append( $(this).text());
$(this).parent("p").remove(); var p = $("<p>").append(font).append(cancel).append(recommendConsultant);
}); $("#consultantImg").append(p);
$("#preview,#picList,#houseImg,#consultantImg").on("click",".existsCancel",function(){ });
$(this).parent().remove();
}); //新增房源相册
$("#housePicture").click(function(){
$("#submit").click(function(){ var checkBox = $("<input>").attr({"type":"radio","name":"frontCover","value":i});
if($("#housename").val()==""){ var picDelet = $("<input>").attr({"type":"button","value":"删除"}).addClass("button action picDelet");
alert("请输入楼盘名"); var file = $("<input>").attr({"type":"file","name":"files["+i+"]"}).addClass("picFiles");
return false; var select = $("<select>").attr("name","data["+i+"][type]");
} var checkTd = $("<th>").append(checkBox);
}); var picDeletTd = $("<td>").append(picDelet);
var selectTd = $("<th>").append(select);
//file上传之前,显示图片的方法 var fileTd = $("<th>").append(file);
function readURL(input,type) { {% for item in photoType %}
if(type == 1){ select.append($("<option>").attr("value",{{item.id}}).append('{{item.value}}'));
if (input.files && input.files[0]){ {% endfor%}
var reader = new FileReader(); var p = $("<p>").append(checkTd).append(selectTd).append(fileTd).append(picDeletTd);
reader.onload = function (e) { var fontA = $("<font>").append("设为封面");
var img = $("<img>").attr({"id":"target","src":e.target.result,"heghit":100,"width":100}); var fontB = $("<font>").append("类型");
var button = $("<input>").attr({"type":"button","value":"取消","property":+i,"id":+i}).addClass("cancel"); var fontC = $("<font>").append("相册");
var type = $("<input>").attr({"type":"hidden","name":"data["+i+"][type]","value":4,"property":+i}); var tdA = $("<th>").append(fontA);
var file = $("<input>").attr({"type":"file","name":"files["+(i+1)+"]","property":+(i+1)}).addClass("files"); var tdB = $("<th>").append(fontB);
var select = $("<select>").attr({"name":"data["+i+"][buildProperty]"}); var tdC = $("<th>").append(fontC);
{% for item in buildProperty %}{{item.id}} var titleP = $("<p>").append(tdA).append(tdB).append(tdC);
select.append($("<option>").attr("value",{{item.id}}).append('{{item.value}}')); $("#picList").append(p);
{% endfor%} if( titleFlag== 0){
var areatext = $("<input>").attr({"type":"text","placeholder":"面积","name":"data["+i+"][housearea]"}).addClass("regular-text"); $("#picList").before(titleP);
var div = $("<div>").append(select).append(areatext).append(button).append(type); titleFlag = 1
var span = $("<span>").attr({"property":+i}).append(img).append(div); }
$("form").find("#preview > p").before(file); i++
$("#preview > p").append(span); });
i++;
} //房源相册
} $("#picList").on("change",".picFiles",function(){
}else{ readURL(this,2);
if (input.files && input.files[0]){ $(this).hide();
var reader = new FileReader(); });
reader.onload = function (e){
var img = $("<img>").attr({"src":e.target.result,"heghit":100,"width":100}); //删除房源相册、推荐房源、推荐置业顾问
$(input).before(img); $("#houseImg,#consultantImg,#picList").on("click",".imgCancel,.consultantCancel,.picDelet",function(){
} $(this).parents("p").remove();
} });
} $("#preview,#picList,#houseImg,#consultantImg").on("click",".existsCancel",function(){
reader.readAsDataURL(input.files[0]); $(this).parent().remove();
} });
function addOption(json,select){
var selectId = select.attr("id"); $('#newHouse').validate({
for(var i = 0; i <=json.length-1; i++){ onkeyup: false,
var id = json[i]["id"]; onfocusout: false,
var value = json[i]["value"]; rules: {
if(selectId == "acreage" || selectId == "price"){ housename:'required',
id = value; mark:'required',
} community_name:'required',
var Option = $("<option>").attr({"value": id}).append(value); address:'required',
select.append(Option); average_price:'required',
} latest_news:'required'
} },
messages: {
function controlCommand(){ housename:'请输入楼盘名称',
var num = $("#houseImg > p").length; mark:'请输入标签',
if(num>3){ community_name:'请输入小区名称',
alert("最多只能推荐3个房源"); address:'请输入地址',
$("#houseImg").find("p:last-child").remove(); average_price:'请输入均价',
} latest_news:'请输入最新动态'
} },
errorLabelContainer: "#notice",
errorElement: 'span',
submitHandler: function (form) {
function getUrlParmas(){ form.submit();
var href = location.search.substr(1,location.search.length-1); }
var params = href.split("&"); });
var map = {};
for(item in params){ //file上传之前,显示图片的方法
var key = params[item].split("=")[0] || ""; function readURL(input,type) {
var value = params[item].split("=")[1] || ""; if(type == 1){
map[key] = value; if (input.files && input.files[0]){
} var reader = new FileReader();
return map; reader.onload = function (e) {
} var img = $("<img>").attr({"id":"target","src":e.target.result,"heghit":100,"width":100});
var button = $("<input>").attr({"type":"button","value":"取消","property":+i,"id":+i}).addClass("button action cancel");
function addList($houseType){ var type = $("<input>").attr({"type":"hidden","name":"data["+i+"][type]","value":4,"property":+i});
$("#houseList").find("li").remove(); var file = $("<input>").attr({"type":"file","name":"files["+(i+1)+"]","property":+(i+1)}).addClass("files");
var cityId = $("#baseCity").val(); var select = $("<select>").attr({"name":"data["+i+"][buildProperty]"});
var buildPropertyId = $("#buildProperty").val(); {% for item in buildProperty %}{{item.id}}
var room = $("#room").val(); select.append($("<option>").attr("value",{{item.id}}).append('{{item.value}}'));
var areaId = $("#areaId").val(); {% endfor%}
var cityId = $("#cityId").val(); var areatext = $("<input>").attr({"type":"text","placeholder":"面积","name":"data["+i+"][housearea]"}).addClass("form-control");
var plateId = $("#plateId").val(); var div = $("<div>").append(select).append(areatext).append(button).append(type);
var acreage = $("#acreage").val(); var span = $("<span>").attr({"property":+i}).append(img).append(div);
var price = $("#price").val(); $("form").find("#preview > p").before(file);
$.ajax({ $("#preview > p").append(span);
type: "post", i++;
url: "/tospur/wp-admin/admin-ajax.php", }
data: "action=searchHouse&cityId="+cityId+"&districtId="+areaId+"&plateId="+plateId+"&buildPropertyId="+buildPropertyId+"&roomId="+room+"&acreage="+acreage+"&totalPrice="+price+"&houseType="+$houseType, }
success:function(json){ }else{
var result = json.result; if (input.files && input.files[0]){
var urlParams = getUrlParmas(); var reader = new FileReader();
for(var i = 0; i <result.length; i++){ reader.onload = function (e){
var name = result[i]["name"]; var img = $("<img>").attr({"src":e.target.result,"heghit":100,"width":100});
var id = result[i]['id']; $(input).before(img);
var imgUrl = result[i]['path']; }
var img = $("<img>").attr({"src":imgUrl,"height":100,"width":100}); }
var li = $("<li>").attr("id",id).addClass("addImg").append(img).append(name); }
if(urlParams["id"]){ reader.readAsDataURL(input.files[0]);
if(urlParams["id"]!=id){ }
$("#houseList").append(li); function addOption(json,select){
} var selectId = select.attr("id");
}else{ for(var i = 0; i <=json.length-1; i++){
$("#houseList").append(li); var id = json[i]["id"];
} var value = json[i]["value"];
} if(selectId == "acreage" || selectId == "price"){
} id = value;
}); }
} var Option = $("<option>").attr({"value": id}).append(value);
}); select.append(Option);
})(jQuery); }
}
</script>
function controlCommand(){
</body> var num = $("#houseImg > p").length;
if(num>3){
alert("最多只能推荐3个房源");
$("#houseImg").find("p:last-child").remove();
}
}
function getUrlParmas(){
var href = location.search.substr(1,location.search.length-1);
var params = href.split("&");
var map = {};
for(item in params){
var key = params[item].split("=")[0] || "";
var value = params[item].split("=")[1] || "";
map[key] = value;
}
return map;
}
function addList($houseType){
$("#houseList").find("li").remove();
var cityId = $("#baseCity").val();
var buildPropertyId = $("#buildProperty").val();
var room = $("#room").val();
var areaId = $("#areaId").val();
var cityId = $("#cityId").val();
var plateId = $("#plateId").val();
var acreage = $("#acreage").val();
var price = $("#price").val();
$.ajax({
type: "post",
url: "/tospur/wp-admin/admin-ajax.php",
data: "action=searchHouse&cityId="+cityId+"&districtId="+areaId+"&plateId="+plateId+"&buildPropertyId="+buildPropertyId+"&roomId="+room+"&acreage="+acreage+"&totalPrice="+price+"&houseType="+$houseType,
success:function(json){
var result = json.result;
var urlParams = getUrlParmas();
for(var i = 0; i <result.length; i++){
var name = result[i]["name"];
var id = result[i]['id'];
var imgUrl = result[i]['path'];
var img = $("<img>").attr({"src":imgUrl,"height":100,"width":100});
var li = $("<li>").attr("id",id).addClass("addImg").append(img).append(name);
if(urlParams["id"]){
if(urlParams["id"]!=id){
$("#houseList").append(li);
}
}else{
$("#houseList").append(li);
}
}
}
});
}
});
})(jQuery);
</script>
</body>
</html> </html>
\ No newline at end of file
<!DOCTYPE HTML> <!DOCTYPE HTML>
<html> <html>
<head> <head>
{% set title = houseId?"修改租房房源":"添租新房房源" %} {% set title = houseId?"修改租房房源":"添租新房房源" %}
<meta charset="utf-8"> <meta charset="utf-8">
<title>{{title}}</title> <title>{{title}}</title>
</head> </head>
<body> <body>
<h2 class="title">{{title}}</h2> <h2 class="title">{{title}}</h2>
<form action="" method="POST" enctype="multipart/form-data"> <form action="" method="POST" enctype="multipart/form-data">
<table class="form-table"> <table class="form-table">
<tbody> <tbody>
<tr> <tr>
<th><label for="housename">房源名:</label></th> <th><label for="housename">房源名:</label></th>
<td> <input name="housename" id="housename" type="text" value="{{result.name}}" class="regular-text code" style="width: 150px;"></td> <td> <input name="housename" id="housename" type="text" value="{{result.name}}" class="regular-text code" style="width: 150px;"></td>
</tr> </tr>
<tr> <tr>
<th><label for="mark">标签:</label></th> <th><label for="mark">标签:</label></th>
<td> <input name="mark" id="mark" type="text" value="{{mark}}" class="regular-text code"></td> <td> <input name="mark" id="mark" type="text" value="{{mark}}" class="regular-text code"></td>
</tr> </tr>
{% if not houseId %} {% if not houseId %}
<tr> <tr>
<th><label for="owner_name">业主姓名</label></th> <th><label for="owner_name">业主姓名</label></th>
<td> <input name="owner_name" id="owner_name" type="text" value="" class="regular-text code" style="width: 150px;"></td> <td> <input name="owner_name" id="owner_name" type="text" value="" class="regular-text code" style="width: 150px;"></td>
</tr> </tr>
<tr> <tr>
<th><label for="owner_phone">业主电话</label></th> <th><label for="owner_phone">业主电话</label></th>
<td> <input name="owner_phone" id="owner_phone" type="text" value="" class="regular-text code" style="width: 150px;"></td> <td> <input name="owner_phone" id="owner_phone" type="text" value="" class="regular-text code" style="width: 150px;"></td>
</tr> </tr>
{% endif %} {% endif %}
<tr> <tr>
<th><label for="rent">租金</label></th> <th><label for="rent">租金</label></th>
<td> <input name="rent" id="rent" type="text" value="{{result.rent}}" class="regular-text code" style="width: 90px;"></td> <td> <input name="rent" id="rent" type="text" value="{{result.rent}}" class="regular-text code" style="width: 90px;"></td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
<h2 class="title">基本信息</h2> <h2 class="title">基本信息</h2>
<table class="form-table"> <table class="form-table">
<tbody> <tbody>
<tr> <tr>
<th><label for="from">户型</label></th> <th><label for="from">户型</label></th>
<td> <td>
<select id="buildproperty_id" name="buildproperty_id"> <select id="buildproperty_id" name="buildproperty_id">
<option value="-1"> 户型</option> <option value="-1"> 户型</option>
{% for item in buildProperty %} {% for item in buildProperty %}
<option {{ item.id == result.buildproperty_id?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option> <option {{ item.id == result.buildproperty_id?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option>
{% endfor %} {% endfor %}
</select> </select>
</td> </td>
</tr> </tr>
<tr> <tr>
<th><label for="covered_area">面积</label></th> <th><label for="covered_area">面积</label></th>
<td> <input name="covered_area" type="text" value="{{result.covered_area}}" class="regular-text code" style="width: 90px;"></td> <td> <input name="covered_area" type="text" value="{{result.covered_area}}" class="regular-text code" style="width: 90px;"></td>
</tr> </tr>
<tr> <tr>
<th><label for="floor">楼层:</label></th> <th><label for="floor">楼层:</label></th>
<td> <input name="floor" type="text" value="{{result.floor}}" class="regular-text code" style="width: 90px;"></td> <td> <input name="floor" type="text" value="{{result.floor}}" class="regular-text code" style="width: 90px;"></td>
</tr> </tr>
<tr> <tr>
<th><label for="faceto">朝向:</label></th> <th><label for="faceto">朝向:</label></th>
<td> <input name="faceto" type="text" value="{{result.faceto}}" class="regular-text code" style="width: 70px;"></td> <td> <input name="faceto" type="text" value="{{result.faceto}}" class="regular-text code" style="width: 70px;"></td>
</tr> </tr>
<tr> <tr>
<th><label for="decoration">装修状况</label></th> <th><label for="decoration">装修状况</label></th>
<td> <input name="decoration" type="text" value="{{result.decoration}}" class="regular-text code" style="width: 70px;"></td> <td> <input name="decoration" type="text" value="{{result.decoration}}" class="regular-text code" style="width: 70px;"></td>
</tr> </tr>
<tr> <tr>
<th><label for="age">建筑年代</label></th> <th><label for="age">建筑年代</label></th>
<td> <input name="age" type="text" value="{{result.age}}" class="regular-text code" style="width: 70px;"></td> <td> <input name="age" type="text" value="{{result.age}}" class="regular-text code" style="width: 70px;"></td>
</tr> </tr>
<tr> <tr>
<th><label for="matching_facilities">配套设施</label></th> <th><label for="matching_facilities">配套设施</label></th>
<td> <input name="matching_facilities" type="text" value="{{result.matching_facilities}}" class="regular-text code"></td> <td> <input name="matching_facilities" type="text" value="{{result.matching_facilities}}" class="regular-text code"></td>
</tr> </tr>
<tr> <tr>
<th><label for="flat">楼号</label></th> <th><label for="flat">楼号</label></th>
<td> <input name="flat" type="text" value="{{result.flat}}" class="regular-text code" style=" width: 50px;"></td> <td> <input name="flat" type="text" value="{{result.flat}}" class="regular-text code" style=" width: 50px;"></td>
</tr> </tr>
<tr> <tr>
<th><label for="suite"></label></th> <th><label for="suite"></label></th>
<td> <input name="suite" type="text" value="{{result.suite}}" class="regular-text code" style=" width: 50px;"></td> <td> <input name="suite" type="text" value="{{result.suite}}" class="regular-text code" style=" width: 50px;"></td>
</tr> </tr>
<tr> <tr>
<th><label for="overview">房源点评</label></th> <th><label for="overview">房源点评</label></th>
<td> <textarea name="overview" rows="4" cols="40" class="large-text code" style=" width: 400px;">{{result.overview}}</textarea></td> <td> <textarea name="overview" rows="4" cols="40" class="large-text code" style=" width: 400px;">{{result.overview}}</textarea></td>
</tr> </tr>
<tr> <tr>
<th><label for="from">所属地区</label></th> <th><label for="from">所属地区</label></th>
<td> <td>
<select id="baseCity" name="baseCity"> <select id="baseCity" name="baseCity">
<option value="-1"> 城市</option> <option value="-1"> 城市</option>
{% for item in city %} {% for item in city %}
<option {{ item.id == result.city_id?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option> <option {{ item.id == result.city_id?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option>
{% endfor %} {% endfor %}
</select> </select>
<select id="baseAreaId" name="baseAreaId"> <select id="baseAreaId" name="baseAreaId">
<option value = -1">区域</option> <option value = -1">区域</option>
{% if district %} {% if district %}
{% for item in district %} {% for item in district %}
<option {{ item.id == result.district_id?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option> <option {{ item.id == result.district_id?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option>
{% endfor %} {% endfor %}
{% endif %} {% endif %}
</select> </select>
<select id="basePlateId" name="basePlateId"> <select id="basePlateId" name="basePlateId">
<option value = "-1">板块</option> <option value = "-1">板块</option>
{% if district %} {% if district %}
{% for item in plate %} {% for item in plate %}
<option {{ item.id == result.plate_id?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option> <option {{ item.id == result.plate_id?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option>
{% endfor %} {% endfor %}
{% endif %} {% endif %}
</select> </select>
</td> </td>
</tr> </tr>
<tr> <tr>
<th><label for="location">地域坐标</label></th> <th><label for="location">地域坐标</label></th>
<td> <input name="location" id="location" type="text" value="{{result.location}}" class="regular-text code"></td> <td> <input name="location" id="location" type="text" value="{{result.location}}" class="regular-text code"></td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
<h2 class="title">位置及周边</h2> <h2 class="title">位置及周边</h2>
<table class="form-table"> <table class="form-table">
<tbody> <tbody>
<tr> <tr>
<th><label for="address">地址</label></th> <th><label for="address">地址</label></th>
<td> <input name="address" type="text" value="{{result.address}}" class="regular-text code"></td> <td> <input name="address" type="text" value="{{result.address}}" class="regular-text code"></td>
</tr> </tr>
<tr> <tr>
<th><label for="address">小区名称</label></th> <th><label for="address">小区名称</label></th>
<td> <input name="community_name" type="text" value="{{result.community_name}}" class="regular-text code" style="width: 150px;"></td> <td> <input name="community_name" type="text" value="{{result.community_name}}" class="regular-text code" style="width: 150px;"></td>
</tr> </tr>
<tr> <tr>
<th><label for="traffic">交通线路</label></th> <th><label for="traffic">交通线路</label></th>
<td> <input name="traffic" type="text" value="{{result.traffic}}" class="regular-text code" style="width: 300px;"></td> <td> <input name="traffic" type="text" value="{{result.traffic}}" class="regular-text code" style="width: 300px;"></td>
</tr> </tr>
<tr> <tr>
<th><label for="periphery">周边配套</label></th> <th><label for="periphery">周边配套</label></th>
<td> <input name="periphery" type="text" value="{{result.periphery}}" class="regular-text code" ></td> <td> <input name="periphery" type="text" value="{{result.periphery}}" class="regular-text code" ></td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
<h2 class="title">关联信息</h2> <h2 class="title">关联信息</h2>
<table class="form-table"> <table class="form-table">
<tbody> <tbody>
<tr> <tr>
<th><label>房源相册</label></th> <th><label>房源相册</label></th>
<td> <td>
<div id="picList"> <div id="picList">
{% set exists_photo_ids = "" %} {% set exists_photo_ids = "" %}
{% for item in images %} {% for item in images %}
{% if exists_photo_ids != "" %} {% if exists_photo_ids != "" %}
{% set exists_photo_ids = exists_photo_ids~"," %} {% set exists_photo_ids = exists_photo_ids~"," %}
{% endif %} {% endif %}
{% set exists_photo_ids = exists_photo_ids~item.image_id %} {% set exists_photo_ids = exists_photo_ids~item.image_id %}
<p> <p>
<input type="radio" name="frontCover" value="{{item.image_id}}" {{ result.frontCover_id == item.image_id?"checked":"" }} /> <input type="radio" name="frontCover" value="{{item.image_id}}" {{ result.frontCover_id == item.image_id?"checked":"" }} />
<select name="exists_photo[{{ item.image_id }}][type]"> <select name="exists_photo[{{ item.image_id }}][type]">
{% for i in photoType %} {% for i in photoType %}
<option {{ i.id == item.image_type?"selected":"" }} value="{{ i.id }}">{{ i.value }}</option> <option {{ i.id == item.image_type?"selected":"" }} value="{{ i.id }}">{{ i.value }}</option>
{% endfor %} {% endfor %}
</select> </select>
<img src="{{siteUrl}}{{item.path}}" heghit="100" width="100"> <img src="{{siteUrl}}{{item.path}}" heghit="100" width="100">
<input type="button" value="取消" class="cancel existsCancel"> <input type="button" value="取消" class="cancel existsCancel">
</p> </p>
{% endfor %} {% endfor %}
<input type="hidden" name="exists_photo_ids" value="{{exists_photo_ids}}" > <input type="hidden" name="exists_photo_ids" value="{{exists_photo_ids}}" >
</div><br /> </div><br />
<button type="button" id="housePicture" class="button action" data-toggle="modal"> <button type="button" id="housePicture" class="button action" data-toggle="modal">
新增 新增
</button> </button>
</td> </td>
</tr> </tr>
<tr> <tr>
<th><label for="recommend">推荐房源</label></th> <th><label for="recommend">推荐房源</label></th>
<td> <td>
<div id="houseImg"></div><br /> <div id="houseImg"></div><br />
<button type="button" class="button action" data-toggle="modal" data-target="#myModal" id="recHouseBt" > <button type="button" class="button action" data-toggle="modal" data-target="#myModal" id="recHouseBt" >
添加房源 添加房源
</button> </button>
</td> </td>
</tr> </tr>
<tr> <tr>
<th><label for="consultant">置业顾问</label></th> <th><label for="consultant">置业顾问</label></th>
<td> <td>
<div id="consultantImg"> <div id="consultantImg">
{% for item in consultant %} {% for item in consultant %}
<p> <p>
<span>{{item.name}}</span> <span>{{item.name}}</span>
<input type="button" value="删除" class="consultantCancel existsCancel"> <input type="button" value="删除" class="consultantCancel existsCancel">
<input type="hidden" name="data[recConsultant][]" value="{{item.id}}"> <input type="hidden" name="data[recConsultant][]" value="{{item.id}}">
</p> </p>
{% endfor %} {% endfor %}
</div><br /> </div><br />
<button type="button" class="button action" data-toggle="modal" data-target="#myConsultant" id="recConsultantBt"> <button type="button" class="button action" data-toggle="modal" data-target="#myConsultant" id="recConsultantBt">
选择置业顾问 选择置业顾问
</button> </button>
</td> </td>
</tr> </tr>
{% if role == 'administrator' %} {% if role == 'administrator' %}
<tr> <tr>
<th><label for="from">状态</label></th> <th><label for="from">状态</label></th>
<td> <td>
<select id="status" name="status"> <select id="status" name="status">
{% for item in status %} {% for item in status %}
<option value={{item.id}}>{{item.value}}</option> <option value={{item.id}}>{{item.value}}</option>
{% endfor %} {% endfor %}
</select> </select>
</td> </td>
</tr> </tr>
{% endif %} {% endif %}
</tbody> </tbody>
</table> </table>
<input type="text" name="type" value="3" hidden="hidden"> <input type="text" name="type" value="3" hidden="hidden">
{% if houseId %} {% if houseId %}
<input type="text" name="houseId" value="{{houseId}}" hidden="hidden"> <input type="text" name="houseId" value="{{houseId}}" hidden="hidden">
{% endif %} {% endif %}
<input type="submit" id="submit" class="button action"> <input type="submit" id="submit" class="button action">
</form> </form>
<!-- Modal --> <!-- Modal -->
<!-- 新增房源弹出层 --> <!-- 新增房源弹出层 -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document"> <div class="modal-dialog" role="document">
<div class="modal-content"> <div class="modal-content">
<div class="modal-body" style="height: 300px;overflow: auto;"> <div class="modal-body" style="height: 300px;overflow: auto;">
<select id="cityId"> <select id="cityId">
</select> </select>
<select id="areaId"> <select id="areaId">
<option value = "-1">区域</option> <option value = "-1">区域</option>
</select> </select>
<select id="plateId"> <select id="plateId">
<option value = "-1">板块</option> <option value = "-1">板块</option>
</select> </select>
<select id="price"> <select id="price">
<option value = "-1">价格</option> <option value = "-1">价格</option>
</select> </select>
<select id="buildProperty"> <select id="buildProperty">
<option value = "-1">房型</option> <option value = "-1">房型</option>
{% for item in buildProperty %} {% for item in buildProperty %}
<option value="{{ item.id }}">{{ item.value }}</option> <option value="{{ item.id }}">{{ item.value }}</option>
{% endfor %} {% endfor %}
</select> </select>
<select id="room"> <select id="room">
<option value = "-1">类型</option> <option value = "-1">类型</option>
{% for item in room %} {% for item in room %}
<option value="{{ item.id }}">{{ item.value }}</option> <option value="{{ item.id }}">{{ item.value }}</option>
{% endfor %} {% endfor %}
</select> </select>
<select id="acreage"> <select id="acreage">
<option value = "-1">面积</option> <option value = "-1">面积</option>
</select> </select>
<input type="text" placeholder="请出入楼盘名/地段名搜索" id="searchtext"> <input type="text" placeholder="请出入楼盘名/地段名搜索" id="searchtext">
<button type="button" class="button action" id="search">搜索</button> <button type="button" class="button action" id="search">搜索</button>
<ul id="houseList"> <ul id="houseList">
</ul> </ul>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
<!-- 置业顾问弹出层 --> <!-- 置业顾问弹出层 -->
<div class="modal fade" id="myConsultant" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> <div class="modal fade" id="myConsultant" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document"> <div class="modal-dialog" role="document">
<div class="modal-content"> <div class="modal-content">
<div class="modal-body" style="height: 300px;overflow: auto;"> <div class="modal-body" style="height: 300px;overflow: auto;">
<select id="consultCity"> <select id="consultCity">
<option value=""> 城市</option> <option value=""> 城市</option>
{% for item in city %} {% for item in city %}
<option value="{{ item.id }}">{{ item.value }}</option> <option value="{{ item.id }}">{{ item.value }}</option>
{% endfor %} {% endfor %}
</select> </select>
<input type="text" placeholder="请出入置业顾问姓名搜索" id="consultantName"> <input type="text" placeholder="请出入置业顾问姓名搜索" id="consultantName">
<button type="button" class="button action" id="searchConsult">搜索</button> <button type="button" class="button action" id="searchConsult">搜索</button>
<ul id="consultantList"> <ul id="consultantList">
</ul> </ul>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
<script> <script>
(function($){ (function($){
$(document).ready(function(){ $(document).ready(function(){
var titleFlag = 0;
//主力房源中选择图片file的下标 //主力房源中选择图片file的下标
var i = 0; var i = 0;
//基本信息的联动AJAX //基本信息的联动AJAX
$("#baseCity").change(function(){ $("#baseCity").change(function(){
var cityId = $("#baseCity").val(); var cityId = $("#baseCity").val();
var baserArea = $("#baseAreaId"); var baserArea = $("#baseAreaId");
$('#baseAreaId').find('option:not(:first-child)').remove(); $('#baseAreaId').find('option:not(:first-child)').remove();
$('#basePlateId').find('option:not(:first-child)').remove(); $('#basePlateId').find('option:not(:first-child)').remove();
//城市联动区域 //城市联动区域
$.ajax({ $.ajax({
type: "GET", type: "GET",
url: "/tospur/wp-admin/admin-ajax.php", url: "/tospur/wp-admin/admin-ajax.php",
data: "action=serachCity&cityId="+cityId, data: "action=serachCity&cityId="+cityId,
success:function(json){ success:function(json){
addOption(json,baserArea); addOption(json,baserArea);
} }
}); });
}); });
//区域联动板块 //区域联动板块
$("#baseAreaId").change(function(){ $("#baseAreaId").change(function(){
var basePlate = $("#basePlateId"); var basePlate = $("#basePlateId");
var areaId = $("#baseAreaId").val(); var areaId = $("#baseAreaId").val();
var cityId = $("#baseCity").val(); var cityId = $("#baseCity").val();
$('#basePlateId').find('option:not(:first-child)').remove(); $('#basePlateId').find('option:not(:first-child)').remove();
$.ajax({ $.ajax({
type: "GET", type: "GET",
url: "/tospur/wp-admin/admin-ajax.php", url: "/tospur/wp-admin/admin-ajax.php",
data: "action=serachCity&cityId="+cityId+"&districtId="+areaId, data: "action=serachCity&cityId="+cityId+"&districtId="+areaId,
success:function(json){ success:function(json){
addOption(json,basePlate); addOption(json,basePlate);
} }
}); });
}); });
//根据上方选择的城市,选择推荐房源的默认城市 //根据上方选择的城市,选择推荐房源的默认城市
$("#recHouseBt").click(function(){ $("#recHouseBt").click(function(){
$('#cityId').find('option').remove(); $('#cityId').find('option').remove();
$('#areaId').find('option:not(:first-child)').remove(); $('#areaId').find('option:not(:first-child)').remove();
$('#plateId').find('option:not(:first-child)').remove(); $('#plateId').find('option:not(:first-child)').remove();
$('#price').find('option:not(:first-child)').remove(); $('#price').find('option:not(:first-child)').remove();
$('#acreage').find('option:not(:first-child)').remove(); $('#acreage').find('option:not(:first-child)').remove();
$("#houseList").find("li").remove(); $("#houseList").find("li").remove();
var acreage =$("#acreage"); var acreage =$("#acreage");
var price = $("#price"); var price = $("#price");
var cityId = $("#baseCity").val(); var cityId = $("#baseCity").val();
var cityName = $("#baseCity").find("option:selected").text(); var cityName = $("#baseCity").find("option:selected").text();
var option = $("<option>").attr("value",cityId).append(cityName); var option = $("<option>").attr("value",cityId).append(cityName);
$("#cityId").append(option); $("#cityId").append(option);
var area = $("#areaId"); var area = $("#areaId");
if(cityId != -1){ if(cityId != -1){
$.ajax({ $.ajax({
type: "GET", type: "GET",
url: "/tospur/wp-admin/admin-ajax.php", url: "/tospur/wp-admin/admin-ajax.php",
data: "action=serachCity&cityId="+cityId, data: "action=serachCity&cityId="+cityId,
success:function(json){ success:function(json){
addOption(json,area); addOption(json,area);
} }
}); });
//城市联动房子面积 //城市联动房子面积
$.ajax({ $.ajax({
type: "GET", type: "GET",
url: "/tospur/wp-admin/admin-ajax.php", url: "/tospur/wp-admin/admin-ajax.php",
data: "action=searchArea&cityId="+cityId, data: "action=searchArea&cityId="+cityId,
success:function(json){ success:function(json){
addOption(json,acreage); addOption(json,acreage);
} }
}); });
//城市联动房子价格 //城市联动房子价格
$.ajax({ $.ajax({
type: "GET", type: "GET",
url: "/tospur/wp-admin/admin-ajax.php", url: "/tospur/wp-admin/admin-ajax.php",
data: "action=searchUnitPriceRange&cityId="+cityId, data: "action=searchUnitPriceRange&cityId="+cityId,
success:function(json){ success:function(json){
addOption(json,price); addOption(json,price);
} }
}); });
addList(2); addList(2);
} }
}); });
//区域联动板块 //区域联动板块
$("#areaId").change(function(){ $("#areaId").change(function(){
var areaId = $("#areaId").val(); var areaId = $("#areaId").val();
var cityId = $("#cityId").val(); var cityId = $("#cityId").val();
var plate = $("#plateId"); var plate = $("#plateId");
$("#houseList").find("li").remove(); $("#houseList").find("li").remove();
$('#plateId').find('option:not(:first-child)').remove(); $('#plateId').find('option:not(:first-child)').remove();
$.ajax({ $.ajax({
type: "GET", type: "GET",
url: "/tospur/wp-admin/admin-ajax.php", url: "/tospur/wp-admin/admin-ajax.php",
data: "action=serachCity&cityId="+cityId+"&districtId="+areaId, data: "action=serachCity&cityId="+cityId+"&districtId="+areaId,
success:function(json){ success:function(json){
addOption(json,plate); addOption(json,plate);
} }
}); });
}); });
//推荐房源下显示图片信息以及房名 //推荐房源下显示图片信息以及房名
$("#areaId,#plateId,#buildProperty,#room,#acreage,#price").change(function(){ $("#areaId,#plateId,#buildProperty,#room,#acreage,#price").change(function(){
addList(2); addList(2);
}); });
//添加房源中搜索框的搜索 //添加房源中搜索框的搜索
$("#search").click(function(){ $("#search").click(function(){
$searchtext = $("#searchtext").val(); $searchtext = $("#searchtext").val();
$("#houseList").find("li").remove(); $("#houseList").find("li").remove();
$.ajax({ $.ajax({
type: "post", type: "post",
url: "/tospur/wp-admin/admin-ajax.php", url: "/tospur/wp-admin/admin-ajax.php",
data: "action=searchHouse&searchText="+$searchtext, data: "action=searchHouse&searchText="+$searchtext,
success:function(json){ success:function(json){
var result = json.result; var result = json.result;
for(var i = 0; i < result.length; i++){ for(var i = 0; i < result.length; i++){
var name = result[i]["name"]; var name = result[i]["name"];
var id = result[i]['id']; var id = result[i]['id'];
var imgUrl = json.images[id]; var imgUrl = json.images[id];
var img = $("<img>").attr({"src":imgUrl,"height":100,"width":100}); var img = $("<img>").attr({"src":imgUrl,"height":100,"width":100});
var li = $("<li>").addClass("addImg").append(img).append(name); var li = $("<li>").addClass("addImg").append(img).append(name);
$("#houseList").append(li); $("#houseList").append(li);
} }
} }
}); });
}) })
//根据上方选择的城市,选择推荐置业顾问的默认城市 //根据上方选择的城市,选择推荐置业顾问的默认城市
$("#recConsultantBt").click(function(){ $("#recConsultantBt").click(function(){
$('#consultCity').find('option').remove(); $('#consultCity').find('option').remove();
$("#consultantList").find("li").remove(); $("#consultantList").find("li").remove();
var consulCityId = $("#baseCity").val(); var consulCityId = $("#baseCity").val();
var consultantName =$("#consultantName").val(); var consultantName =$("#consultantName").val();
var cityName = $("#baseCity").find("option:selected").text(); var cityName = $("#baseCity").find("option:selected").text();
var option = $("<option>").attr("value",consulCityId).append(cityName); var option = $("<option>").attr("value",consulCityId).append(cityName);
$("#consultCity").append(option); $("#consultCity").append(option);
$.ajax({ $.ajax({
type: "GET", type: "GET",
url: "/tospur/wp-admin/admin-ajax.php", url: "/tospur/wp-admin/admin-ajax.php",
data: "action=searchConsultant&consulCityId="+consulCityId+"&consultantName="+consultantName, data: "action=searchConsultant&consulCityId="+consulCityId+"&consultantName="+consultantName,
success:function(json){ success:function(json){
for(var i = 0; i <=json.length-1; i++){ for(var i = 0; i <=json.length-1; i++){
var name = json[i]["consultantName"]; var name = json[i]["consultantName"];
var imgUrl = json[i]["imageUrl"]; var imgUrl = json[i]["imageUrl"];
var img = $("<img>").attr({"src":imgUrl,"height":100,"width":100}); var img = $("<img>").attr({"src":imgUrl,"height":100,"width":100});
var li = $("<li>").attr("id",json[i]["id"]).append(img).append(name).addClass("consultantImg"); var li = $("<li>").attr("id",json[i]["id"]).append(img).append(name).addClass("consultantImg");
$("#consultantList").append(li); $("#consultantList").append(li);
} }
} }
}); });
}); });
//添加置业顾问弹出层中搜索框的搜索内容 //添加置业顾问弹出层中搜索框的搜索内容
$("#searchConsult").click(function(){ $("#searchConsult").click(function(){
var consulCityId = $("#consultCity").val(); var consulCityId = $("#consultCity").val();
var consultantName =$("#consultantName").val(); var consultantName =$("#consultantName").val();
$("#consultantList").find("li").remove(); $("#consultantList").find("li").remove();
$.ajax({ $.ajax({
type: "GET", type: "GET",
url: "/tospur/wp-admin/admin-ajax.php", url: "/tospur/wp-admin/admin-ajax.php",
data: "action=searchConsultant&consulCityId="+consulCityId+"&consultantName="+consultantName, data: "action=searchConsultant&consulCityId="+consulCityId+"&consultantName="+consultantName,
success:function(json){ success:function(json){
for( for(
var i = 0; i <=json.length-1; i++){ var i = 0; i <=json.length-1; i++){
var name = json[i]["consultantName"]; var name = json[i]["consultantName"];
var imgUrl = json[i]["imageUrl"]; var imgUrl = json[i]["imageUrl"];
var img = $("<img>").attr({"src":imgUrl,"height":100,"width":100}); var img = $("<img>").attr({"src":imgUrl,"height":100,"width":100});
var li = $("<li>").append(img).append(name).addClass("consultantImg"); var li = $("<li>").append(img).append(name).addClass("consultantImg");
$("#consultantList").append(li); $("#consultantList").append(li);
} }
} }
}); });
}) })
//点击添加房源中显示的列表,在界面中显示 //点击添加房源中显示的列表,在界面中显示
$("#houseList").on("click",".addImg",function(){ $("#houseList").on("click",".addImg",function(){
var recommendHouse = $("<input>").attr({"type":"hidden","name":"data[recommend][]","value": $(this).attr("id")}); var recommendHouse = $("<input>").attr({"type":"hidden","name":"data[recommend][]","value": $(this).attr("id")});
var url = $(this).find("img").attr("src"); var url = $(this).find("img").attr("src");
var img = $("<img>").attr({"src":url,"height":100,"width":100}); var img = $("<img>").attr({"src":url,"height":100,"width":100});
var cancel = $("<input>").attr({"type":"button","value":"删除"}).addClass("imgCancel"); var cancel = $("<input>").attr({"type":"button","value":"删除"}).addClass("imgCancel");
var p = $("<p>").append(img).append(cancel).append(recommendHouse); var p = $("<p>").append(img).append(cancel).append(recommendHouse);
$("#houseImg").append(p); $("#houseImg").append(p);
controlCommand("houseImg",3,0); controlCommand("houseImg",3,0);
}); });
//添加置业顾问 //添加置业顾问
$("#consultantList").on("click",".consultantImg",function(){ $("#consultantList").on("click",".consultantImg",function(){
var recommendConsultant = $("<input>").attr({"type":"hidden","name":"data[recConsultant][]","value": $(this).attr("id")}); var recommendConsultant = $("<input>").attr({"type":"hidden","name":"data[recConsultant][]","value": $(this).attr("id")});
var cancel = $("<input>").attr({"type":"button","value":"删除"}).addClass("consultantCancel"); var cancel = $("<input>").attr({"type":"button","value":"删除"}).addClass("consultantCancel");
var font = $("<font>").append( $(this).text()); var font = $("<font>").append( $(this).text());
var p = $("<p>").append(font).append(cancel).append(recommendConsultant); var p = $("<p>").append(font).append(cancel).append(recommendConsultant);
$("#consultantImg").append(p); $("#consultantImg").append(p);
controlCommand("consultantImg",1,1); controlCommand("consultantImg",1,1);
}); });
//新增房源相册 //新增房源相册
$("#housePicture").click(function(){ $("#housePicture").click(function(){
var checkBox = $("<input>").attr({"type":"radio","name":"frontCover","value":i}); var checkBox = $("<input>").attr({"type":"radio","name":"frontCover","value":i});
var picDelet = $("<input>").attr({"type":"button","value":"删除"}).addClass("picDelet"); var picDelet = $("<input>").attr({"type":"button","value":"删除"}).addClass("button action picDelet");
var file = $("<input>").attr({"type":"file","name":"files["+i+"]"}).addClass("picFiles"); var file = $("<input>").attr({"type":"file","name":"files["+i+"]"}).addClass("picFiles");
var select = $("<select>").attr("name","data["+i+"][type]"); var select = $("<select>").attr("name","data["+i+"][type]");
{% for item in photoType %} var checkTd = $("<th>").append(checkBox);
select.append($("<option>").attr("value",{{item.id}}).append('{{item.value}}')); var picDeletTd = $("<td>").append(picDelet);
{% endfor%} var selectTd = $("<th>").append(select);
var p = $("<p>").append(checkBox).append(select).append(file).append(picDelet); var fileTd = $("<th>").append(file);
$("#picList").append(p); {% for item in photoType %}
i++ select.append($("<option>").attr("value",{{item.id}}).append('{{item.value}}'));
}); {% endfor%}
var p = $("<p>").append(checkTd).append(selectTd).append(fileTd).append(picDeletTd);
//房源相册 var fontA = $("<font>").append("设为封面");
$("#picList").on("change",".picFiles",function(){ var fontB = $("<font>").append("类型");
readURL(this,2); var fontC = $("<font>").append("相册");
$(this).hide(); var tdA = $("<th>").append(fontA);
}); var tdB = $("<th>").append(fontB);
var tdC = $("<th>").append(fontC);
//删除房源相册、推荐房源、推荐置业顾问 var titleP = $("<p>").append(tdA).append(tdB).append(tdC);
$("#houseImg,#consultantImg,#picList").on("click",".imgCancel,.consultantCancel,.picDelet",function(){ $("#picList").append(p);
$(this).parent("p").remove(); if( titleFlag== 0){
}); $("#picList").before(titleP);
$("#picList,#houseImg,#consultantImg").on("click",".existsCancel",function(){ titleFlag = 1
$(this).parent().remove(); }
}); i++
});
$("#submit").click(function(){
if($("#housename").val()==""){ //房源相册
alert("请输入楼盘名"); $("#picList").on("change",".picFiles",function(){
return false; readURL(this,2);
} $(this).hide();
}); });
//file上传之前,显示图片的方法 //删除房源相册、推荐房源、推荐置业顾问
function readURL(input,type) { $("#houseImg,#consultantImg,#picList").on("click",".imgCancel,.consultantCancel,.picDelet",function(){
if(type == 1){ $(this).parent("p").remove();
if (input.files && input.files[0]){ });
var reader = new FileReader(); $("#picList,#houseImg,#consultantImg").on("click",".existsCancel",function(){
reader.onload = function (e) { $(this).parent().remove();
var img = $("<img>").attr({"id":"target","src":e.target.result,"heghit":100,"width":100}); });
var button = $("<input>").attr({"type":"button","value":"取消","property":+i,"id":+i}).addClass("cancel");
var type = $("<input>").attr({"type":"hidden","name":"data["+i+"][type]","value":0,"property":+i}); $("#submit").click(function(){
var file = $("<input>").attr({"type":"file","name":"files["+(i+1)+"]","property":+(i+1)}).addClass("files"); if($("#housename").val()==""){
var select = $("<select>").attr({"name":"data["+i+"][buildProperty]"}); alert("请输入楼盘名");
{% for item in buildProperty %}{{item.id}} return false;
select.append($("<option>").attr("value",{{item.id}}).append('{{item.value}}')); }
{% endfor%} });
var areatext = $("<input>").attr({"type":"text","placeholder":"面积","name":"data["+i+"][housearea]"}).addClass("regular-text");
var div = $("<div>").append(select).append(areatext).append(button).append(type); //file上传之前,显示图片的方法
var span = $("<span>").attr({"property":+i}).append(img).append(div); function readURL(input,type) {
$("form").find("#preview > p").before(file); if(type == 1){
$("#preview > p").append(span); if (input.files && input.files[0]){
i++; var reader = new FileReader();
} reader.onload = function (e) {
} var img = $("<img>").attr({"id":"target","src":e.target.result,"heghit":100,"width":100});
}else{ var button = $("<input>").attr({"type":"button","value":"取消","property":+i,"id":+i}).addClass("cancel");
if (input.files && input.files[0]){ var type = $("<input>").attr({"type":"hidden","name":"data["+i+"][type]","value":0,"property":+i});
var reader = new FileReader(); var file = $("<input>").attr({"type":"file","name":"files["+(i+1)+"]","property":+(i+1)}).addClass("files");
reader.onload = function (e){ var select = $("<select>").attr({"name":"data["+i+"][buildProperty]"});
var img = $("<img>").attr({"src":e.target.result,"heghit":100,"width":100}); {% for item in buildProperty %}{{item.id}}
$(input).before(img); select.append($("<option>").attr("value",{{item.id}}).append('{{item.value}}'));
} {% endfor%}
} var areatext = $("<input>").attr({"type":"text","placeholder":"面积","name":"data["+i+"][housearea]"}).addClass("regular-text");
} var div = $("<div>").append(select).append(areatext).append(button).append(type);
reader.readAsDataURL(input.files[0]); var span = $("<span>").attr({"property":+i}).append(img).append(div);
} $("form").find("#preview > p").before(file);
function addOption(json,select){ $("#preview > p").append(span);
var selectId = select.attr("id"); i++;
for(var i = 0; i <=json.length-1; i++){ }
var id = json[i]["id"]; }
var value = json[i]["value"]; }else{
if(selectId == "acreage" || selectId == "price"){ if (input.files && input.files[0]){
id = value; var reader = new FileReader();
} reader.onload = function (e){
var Option = $("<option>").attr({"value": id}).append(value); var img = $("<img>").attr({"src":e.target.result,"heghit":100,"width":100});
select.append(Option); $(input).before(img);
} }
} }
}
function controlCommand(id,number,type){ reader.readAsDataURL(input.files[0]);
var num = $("#"+id+" > p").length; }
if(num>number){ function addOption(json,select){
if(type==0){ var selectId = select.attr("id");
alert("最多只能推荐3个房源"); for(var i = 0; i <=json.length-1; i++){
}else if(type==1){ var id = json[i]["id"];
alert("您只能推荐一位置业顾问"); var value = json[i]["value"];
} if(selectId == "acreage" || selectId == "price"){
$("#"+id).find("p:last-child").remove(); id = value;
} }
} var Option = $("<option>").attr({"value": id}).append(value);
select.append(Option);
function getUrlParmas(){ }
var href = location.search.substr(1,location.search.length-1); }
var params = href.split("&");
var map = {}; function controlCommand(id,number,type){
for(item in params){ var num = $("#"+id+" > p").length;
var key = params[item].split("=")[0] || ""; if(num>number){
var value = params[item].split("=")[1] || ""; if(type==0){
map[key] = value; alert("最多只能推荐3个房源");
} }else if(type==1){
return map; alert("您只能推荐一位置业顾问");
} }
$("#"+id).find("p:last-child").remove();
function addList($houseType){ }
$("#houseList").find("li").remove(); }
var cityId = $("#baseCity").val();
var buildPropertyId = $("#buildProperty").val(); function getUrlParmas(){
var room = $("#room").val(); var href = location.search.substr(1,location.search.length-1);
var areaId = $("#areaId").val(); var params = href.split("&");
var cityId = $("#cityId").val(); var map = {};
var plateId = $("#plateId").val(); for(item in params){
var acreage = $("#acreage").val(); var key = params[item].split("=")[0] || "";
var price = $("#price").val(); var value = params[item].split("=")[1] || "";
$.ajax({ map[key] = value;
type: "post", }
url: "/tospur/wp-admin/admin-ajax.php", return map;
data: "action=searchHouse&cityId="+cityId+"&districtId="+areaId+"&plateId="+plateId+"&buildPropertyId="+buildPropertyId+"&roomId="+room+"&acreage="+acreage+"&totalPrice="+price+"&houseType="+$houseType, }
success:function(json){
var result = json.result; function addList($houseType){
var urlParams = getUrlParmas(); $("#houseList").find("li").remove();
for(var i = 0; i <result.length; i++){ var cityId = $("#baseCity").val();
var name = result[i]["name"]; var buildPropertyId = $("#buildProperty").val();
var id = result[i]['id']; var room = $("#room").val();
var imgUrl = result[i]['path']; var areaId = $("#areaId").val();
var img = $("<img>").attr({"src":imgUrl,"height":100,"width":100}); var cityId = $("#cityId").val();
var li = $("<li>").attr("id",id).addClass("addImg").append(img).append(name); var plateId = $("#plateId").val();
if(urlParams["id"]){ var acreage = $("#acreage").val();
if(urlParams["id"]!=id){ var price = $("#price").val();
$("#houseList").append(li); $.ajax({
} type: "post",
}else{ url: "/tospur/wp-admin/admin-ajax.php",
$("#houseList").append(li); data: "action=searchHouse&cityId="+cityId+"&districtId="+areaId+"&plateId="+plateId+"&buildPropertyId="+buildPropertyId+"&roomId="+room+"&acreage="+acreage+"&totalPrice="+price+"&houseType="+$houseType,
} success:function(json){
} var result = json.result;
} var urlParams = getUrlParmas();
}); for(var i = 0; i <result.length; i++){
} var name = result[i]["name"];
var id = result[i]['id'];
var imgUrl = result[i]['path'];
}); var img = $("<img>").attr({"src":imgUrl,"height":100,"width":100});
})(jQuery); var li = $("<li>").attr("id",id).addClass("addImg").append(img).append(name);
if(urlParams["id"]){
</script> if(urlParams["id"]!=id){
$("#houseList").append(li);
</body> }
}else{
$("#houseList").append(li);
}
}
}
});
}
});
})(jQuery);
</script>
</body>
</html> </html>
\ No newline at end of file
<div class="wrap"> <div class="wrap">
<h2>租房房列表</h2> <h2>租房房列表</h2>
<form id="scores-filter" method="POST"> <form id="scores-filter" method="POST">
<!-- For plugins, we also need to ensure that the form posts back to our current page --> <!-- For plugins, we also need to ensure that the form posts back to our current page -->
<input type="hidden" name="page" value="{{page}}"/> <input type="hidden" name="page" value="{{page}}"/>
<input type="hidden" name="hasSearch" value="1"/> <input type="hidden" name="hasSearch" value="1"/>
<select id="listCity" name="listCity"> <select id="listCity" name="listCity">
<option value="0"> 城市</option> <option value="0"> 城市</option>
{% for item in city %} {% for item in city %}
<option {{ item.id == cityId ?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option> <option {{ item.id == cityId ?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option>
{% endfor %} {% endfor %}
</select> </select>
<select id="listDistrict" name="listDistrict"> <select id="listDistrict" name="listDistrict">
<option value="0">区域</option> <option value="0">区域</option>
{% if district %} {% if district %}
{% for item in district %} {% for item in district %}
<option {{ item.id == districtId ?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option> <option {{ item.id == districtId ?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option>
{% endfor %} {% endfor %}
{% endif %} {% endif %}
</select> </select>
<select id="listPlate" name="listPlate"> <select id="listPlate" name="listPlate">
<option value="0">板块</option> <option value="0">板块</option>
{% if plate %} {% if plate %}
{% for item in plate %} {% for item in plate %}
<option {{ item.id == plateId ?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option> <option {{ item.id == plateId ?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option>
{% endfor %} {% endfor %}
{% endif %} {% endif %}
</select> </select>
<select id="totalPrice" name="totalPrice"> <select id="totalPrice" name="totalPrice">
<option value ="">价格</option> <option value ="">价格</option>
{% if dicTotalPrice %} {% if dicTotalPrice %}
{% for item in dicTotalPrice %} {% for item in dicTotalPrice %}
<option {{ item.value == totalPrice ?"selected":"" }} value="{{ item.value }}">{{ item.value }}</option> <option {{ item.value == totalPrice ?"selected":"" }} value="{{ item.value }}">{{ item.value }}</option>
{% endfor %} {% endfor %}
{% endif %} {% endif %}
</select> </select>
<select id="buildProperty" name="buildProperty"> <select id="buildProperty" name="buildProperty">
<option value="0"> 房型</option> <option value="0"> 房型</option>
{% for item in buildProperty %} {% for item in buildProperty %}
<option {{ item.id == buildPropertyId ?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option> <option {{ item.id == buildPropertyId ?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option>
{% endfor %} {% endfor %}
</select> </select>
<select id="acreage" name="acreage"> <select id="acreage" name="acreage">
<option value ="">面积</option> <option value ="">面积</option>
{% if acreage %} {% if acreage %}
{% for item in dicArea %} {% for item in dicArea %}
<option {{ item.value == acreage ?"selected":"" }} value="{{ item.value }}">{{ item.value }}</option> <option {{ item.value == acreage ?"selected":"" }} value="{{ item.value }}">{{ item.value }}</option>
{% endfor %} {% endfor %}
{% endif %} {% endif %}
</select> </select>
<select name="status" name="status"> <select name="status" name="status">
<option value="-1">状态</option> <option value="-1">状态</option>
{% for item in status%} {% for item in status%}
<option {{ item.id == statusId ?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option> <option {{ item.id == statusId ?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option>
{% endfor %} {% endfor %}
</select> </select>
<input type="text" placeholder="请出入楼盘名/地段名搜索" name="searchText"> <input type="text" placeholder="请出入楼盘名/地段名搜索" name="searchText">
<input type="submit" id="submit" class="button action" value="搜索"> <input type="submit" id="submit" class="button action" value="搜索">
<!-- Now we can render the completed list table --> <!-- Now we can render the completed list table -->
{{function("addRentTable")}} {{function("addRentTable")}}
</form> </form>
</div> </div>
<script> <script>
(function ($) { (function ($) {
$(document).ready(function(){ $(document).ready(function(){
$("#listCity").change(function(){ $("#listCity").change(function(){
var listCityId = $("#listCity").val(); var listCityId = $("#listCity").val();
var district =$("#listDistrict"); var district =$("#listDistrict");
var acreage =$("#acreage"); var acreage =$("#acreage");
var totalPrice = $("#totalPrice"); var totalPrice = $("#totalPrice");
$('#listDistrict').find('option:not(:first-child)').remove(); $('#listDistrict').find('option:not(:first-child)').remove();
$('#listPlate').find('option:not(:first-child)').remove(); $('#listPlate').find('option:not(:first-child)').remove();
$.ajax({ $.ajax({
type: "GET", type: "GET",
url: "/tospur/wp-admin/admin-ajax.php", url: "/tospur/wp-admin/admin-ajax.php",
data: "action=serachCity&cityId="+listCityId, data: "action=serachCity&cityId="+listCityId,
success:function(json){ success:function(json){
addOption(json,district); addOption(json,district);
} }
}); });
//面积 //面积
$.ajax({ $.ajax({
type: "GET", type: "GET",
url: "/tospur/wp-admin/admin-ajax.php", url: "/tospur/wp-admin/admin-ajax.php",
data: "action=searchArea&cityId="+listCityId, data: "action=searchArea&cityId="+listCityId,
success:function(json){ success:function(json){
for(var i = 0; i <=json.length-1; i++){ for(var i = 0; i <=json.length-1; i++){
var id = json[i]["id"]; var id = json[i]["id"];
var value = json[i]["value"]; var value = json[i]["value"];
var Option = $("<option>").attr({"value": value}).append(value); var Option = $("<option>").attr({"value": value}).append(value);
$("#acreage").append(Option); $("#acreage").append(Option);
} }
} }
}); });
//城市联动房子价格 //城市联动房子价格
$.ajax({ $.ajax({
type: "GET", type: "GET",
url: "/tospur/wp-admin/admin-ajax.php", url: "/tospur/wp-admin/admin-ajax.php",
data: "action=searchUnitPriceRange&cityId="+listCityId, data: "action=searchUnitPriceRange&cityId="+listCityId,
success:function(json){ success:function(json){
for(var i = 0; i <=json.length-1; i++){ for(var i = 0; i <=json.length-1; i++){
var id = json[i]["id"]; var id = json[i]["id"];
var value = json[i]["value"]; var value = json[i]["value"];
var Option = $("<option>").attr({"value": value}).append(value); var Option = $("<option>").attr({"value": value}).append(value);
$("#totalPrice").append(Option); $("#totalPrice").append(Option);
} }
} }
}); });
}) })
$("#listDistrict").change(function(){ $("#listDistrict").change(function(){
var listCityId = $("#listCity").val(); var listCityId = $("#listCity").val();
var listDistrict = $("#listDistrict").val(); var listDistrict = $("#listDistrict").val();
var listPlate = $("#listPlate"); var listPlate = $("#listPlate");
$('#listPlate').find('option:not(:first-child)').remove(); $('#listPlate').find('option:not(:first-child)').remove();
$.ajax({ $.ajax({
type: "GET", type: "GET",
url: "/tospur/wp-admin/admin-ajax.php", url: "/tospur/wp-admin/admin-ajax.php",
data: "action=serachCity&cityId="+listCityId+"&districtId="+listDistrict, data: "action=serachCity&cityId="+listCityId+"&districtId="+listDistrict,
success:function(json){ success:function(json){
addOption(json,listPlate); addOption(json,listPlate);
} }
}); });
}) })
function addOption(json,select){ function addOption(json,select){
for(var i = 0; i <=json.length-1; i++){ for(var i = 0; i <=json.length-1; i++){
var id = json[i]["id"]; var id = json[i]["id"];
var value = json[i]["value"]; var value = json[i]["value"];
var Option = $("<option>").attr({"value": id}).append(value); var Option = $("<option>").attr({"value": id}).append(value);
select.append(Option); select.append(Option);
} }
} }
}); });
})(jQuery); })(jQuery);
</script> </script>
<!DOCTYPE HTML> <!DOCTYPE HTML>
<html> <html>
<head> <head>
{% set title = houseId?"修改二手房房源":"添加二手房房源" %} {% set title = houseId?"修改二手房房源":"添加二手房房源" %}
<meta charset="utf-8"> <meta charset="utf-8">
<title>{{title}}</title> <title>{{title}}</title>
</head> </head>
<body> <body>
<h2 class="title">{{title}}</h2> <h2 class="title">{{title}}</h2>
<form action="" method="POST" enctype="multipart/form-data"> <form action="" method="POST" enctype="multipart/form-data">
<table class="form-table"> <div class="row">
<tbody> <div class="col-md-11">
<tr> <div class="row">
<th><label for="housename">房源名:</label></th> <div class="col-md-8">
<td> <input name="housename" id="housename" type="text" value="{{result.name}}" class="regular-text code" style="width: 150px;"></td> <table class="form-table">
</tr> <tbody>
<tr> <tr>
<th><label for="address">小区名称</label></th> <th><label for="housename">房源名:</label></th>
<td> <input name="community_name" type="text" value="{{result.community_name}}" class="regular-text code" style="width: 150px;"></td> <td> <input name="housename" id="housename" type="text" value="{{result.name}}" class="form-control" style="width: 150px;"></td>
</tr> </tr>
<tr> <tr>
<th><label for="mark">标签:</label></th> <th><label for="address">小区名称</label></th>
<td> <input name="mark" id="mark" type="text" value="{{mark}}" class="regular-text code"></td> <td> <input name="community_name" type="text" value="{{result.community_name}}" class="form-control" style="width: 150px;"></td>
</tr> </tr>
{% if not houseId %} <tr>
<tr> <th><label for="mark">标签:</label></th>
<th><label for="owner_name">业主姓名</label></th> <td> <input name="mark" id="mark" type="text" value="{{mark}}" class="form-control"></td>
<td> <input name="owner_name" id="owner_name" type="text" value="" class="regular-text code" style="width: 150px;"></td> </tr>
</tr> {% if not houseId %}
<tr> <tr>
<th><label for="owner_phone">业主电话</label></th> <th><label for="owner_name">业主姓名</label></th>
<td> <input name="owner_phone" id="owner_phone" type="text" value="" class="regular-text code" style="width: 150px;"></td> <td> <input name="owner_name" id="owner_name" type="text" value="" class="form-control" style="width: 150px;"></td>
</tr> </tr>
{% endif %} <tr>
<tr> <th><label for="owner_phone">业主电话</label></th>
<th><label for="total_price">售价</label></th> <td> <input name="owner_phone" id="owner_phone" type="text" value="" class="form-control" style="width: 150px;"></td>
<td> <input name="total_price" id="total_price" type="text" value="{{result.total_price}}" class="regular-text code" style="width: 90px;"></td> </tr>
</tr> {% endif %}
<tr> <tr>
<th><label for="average_price">单价</label></th> <th><label for="total_price">售价</label></th>
<td> <input name="average_price" id="average_price" type="text" value="{{result.average_price}}" class="regular-text code" style="width: 90px;"></td> <td> <input name="total_price" id="total_price" type="text" value="{{result.total_price}}" class="form-control" style="width: 90px;"></td>
</tr> </tr>
</tbody> <tr>
</table> <th><label for="average_price">单价</label></th>
<h2 class="title">基本信息</h2> <td> <input name="average_price" id="average_price" type="text" value="{{result.average_price}}" class="form-control" style="width: 90px;"></td>
<table class="form-table"> </tr>
<tbody> </tbody>
<tr> </table>
<th><label for="from">户型</label></th> </div>
<td> </div>
<select id="buildproperty_id" name="buildproperty_id"> <h2 class="title">基本信息</h2>
{% for item in buildProperty %} <div class="row">
<option {{ item.id == result.buildproperty_id?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option> <div class="col-md-8">
{% endfor %} <table class="form-table">
</select> <tbody>
</td> <tr>
</tr> <th><label for="from">户型</label></th>
<tr> <td>
<th><label for="covered_area">面积</label></th> <select id="buildproperty_id" name="buildproperty_id">
<td> <input name="covered_area" type="text" value="{{result.covered_area}}" class="regular-text code" style="width: 90px;"></td> {% for item in buildProperty %}
</tr> <option {{ item.id == result.buildproperty_id?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option>
<tr> {% endfor %}
<th><label for="floor">楼层:</label></th> </select>
<td> <input name="floor" type="text" value="{{result.floor}}" class="regular-text code" style=" width: 70px;"></td> </td>
</tr> </tr>
<tr> <tr>
<th><label for="faceto">朝向:</label></th> <th><label for="covered_area">面积</label></th>
<td> <input name="faceto" type="text" value="{{result.faceto}}" class="regular-text code" style=" width: 70px;"></td> <td> <input name="covered_area" type="text" value="{{result.covered_area}}" class="form-control" style="width: 90px;"></td>
</tr> </tr>
<tr> <tr>
<th><label for="decoration">装修状况</label></th> <th><label for="floor">楼层:</label></th>
<td> <input name="decoration" type="text" value="{{result.decoration}}" class="regular-text code" style=" width: 70px;"></td> <td> <input name="floor" type="text" value="{{result.floor}}" class="form-control" style=" width: 70px;"></td>
</tr> </tr>
<tr> <tr>
<th><label for="age">建筑年代</label></th> <th><label for="faceto">朝向:</label></th>
<td> <input name="age" type="text" value="{{result.age}}" class="regular-text code" style=" width: 70px;"></td> <td> <input name="faceto" type="text" value="{{result.faceto}}" class="form-control" style=" width: 70px;"></td>
</tr> </tr>
<tr> <tr>
<th><label for="flat">楼号</label></th> <th><label for="decoration">装修状况</label></th>
<td> <input name="flat" type="text" value="{{result.flat}}" class="regular-text code" style=" width: 50px;"></td> <td> <input name="decoration" type="text" value="{{result.decoration}}" class="form-control" style=" width: 70px;"></td>
</tr> </tr>
<tr> <tr>
<th><label for="suite"></label></th> <th><label for="age">建筑年代</label></th>
<td> <input name="suite" type="text" value="{{result.suite}}" class="regular-text code" style=" width: 50px;"></td> <td> <input name="age" type="text" value="{{result.age}}" class="form-control" style=" width: 70px;"></td>
</tr> </tr>
<tr> <tr>
<th><label for="overview">房源点评</label></th> <th><label for="flat">楼号</label></th>
<td> <textarea name="overview" rows="4" cols="40" class="large-text code" style=" width: 400px;">{{result.overview}} <td> <input name="flat" type="text" value="{{result.flat}}" class="form-control" style=" width: 50px;"></td>
</textarea></td> </tr>
</tr> <tr>
<tr> <th><label for="suite"></label></th>
<th><label for="from">所属地区</label></th> <td> <input name="suite" type="text" value="{{result.suite}}" class="form-control" style=" width: 50px;"></td>
<td> </tr>
<select id="baseCity" name="baseCity"> <tr>
<option value="-1"> 城市</option> <th><label for="overview">房源点评</label></th>
{% for item in city %} <td> <textarea name="overview" rows="4" cols="40" class="form-control" style=" width: 400px;">{{result.overview}}</textarea></td>
<option {{ item.id == result.city_id?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option> </tr>
{% endfor %}
</select> </tbody>
<select id="baseAreaId" name="baseAreaId"> </table>
<option value = "-1">区域</option> </div>
{% if district %} </div>
{% for item in district %}
<option {{ item.id == result.district_id?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option> <h2 class="title">位置及周边</h2>
{% endfor %} <div class="row">
{% endif %} <div class="col-md-8">
</select> <table class="form-table">
<select id="basePlateId" name="basePlateId"> <tbody>
<option value = "-1">板块</option> <tr>
{% if district %} <th><label for="from">所属地区</label></th>
{% for item in plate %} <td>
<option {{ item.id == result.plate_id?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option> <select id="baseCity" name="baseCity">
{% endfor %} <option value="-1"> 城市</option>
{% endif %} {% for item in city %}
</select> <option {{ item.id == result.city_id?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option>
</td> {% endfor %}
</tr> </select>
<select id="baseAreaId" name="baseAreaId">
<tr> <option value = "-1">区域</option>
<th><label for="location">地域坐标</label></th> {% if district %}
<td> <input name="location" id="location" type="text" value="{{result.location}}" class="regular-text code"></td> {% for item in district %}
</tr> <option {{ item.id == result.district_id?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option>
</tbody> {% endfor %}
</table> {% endif %}
<h2 class="title">位置及周边</h2> </select>
<table class="form-table"> <select id="basePlateId" name="basePlateId">
<tbody> <option value = "-1">板块</option>
<tr> {% if district %}
<th><label for="address">地址</label></th> {% for item in plate %}
<td> <input name="address" type="text" value="{{result.address}}" class="regular-text code"></td> <option {{ item.id == result.plate_id?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option>
</tr> {% endfor %}
<tr> {% endif %}
<th><label for="traffic">交通线路</label></th> </select>
<td> <input name="traffic" type="text" value="{{result.traffic}}" class="regular-text code" style="width: 300px;"></td> </td>
</tr> </tr>
<tr>
<th><label for="periphery">周边配套</label></th> <tr>
<td> <input name="periphery" type="text" value="{{result.periphery}}" class="regular-text code" style="width: 300px;"></td> <th><label for="location">地域坐标</label></th>
</tr> <td> <input name="location" id="location" type="text" value="{{result.location}}" class="form-control"></td>
</tbody> </tr>
</table> <tr>
<th><label for="address">地址</label></th>
<h2 class="title">关联信息</h2> <td> <input name="address" type="text" value="{{result.address}}" class="form-control"></td>
<table class="form-table"> </tr>
<tbody> <tr>
<tr> <th><label for="traffic">交通线路</label></th>
<th><label>房源相册</label></th> <td> <input name="traffic" type="text" value="{{result.traffic}}" class="form-control" style="width: 300px;"></td>
<td> </tr>
<div id="picList"> <tr>
{% set exists_photo_ids = "" %} <th><label for="periphery">周边配套</label></th>
{% for item in images %} <td> <input name="periphery" type="text" value="{{result.periphery}}" class="form-control" style="width: 300px;"></td>
{% if exists_photo_ids != "" %} </tr>
{% set exists_photo_ids = exists_photo_ids~"," %} </tbody>
{% endif %} </table>
{% set exists_photo_ids = exists_photo_ids~item.image_id %} </div>
<p> </div>
<input type="radio" name="frontCover" value="{{item.image_id}}" {{ result.frontCover_id == item.image_id?"checked":"" }} /> <h2 class="title">关联信息</h2>
<select name="exists_photo[{{ item.image_id }}][type]"> <div class="row">
{% for i in photoType %} <div class="col-md-12">
<option {{ i.id == item.image_type?"selected":"" }} value="{{ i.id }}">{{ i.value }}</option> <table class="form-table">
{% endfor %} <tbody>
</select> <tr>
<img src="{{siteUrl}}{{item.path}}" heghit="100" width="100"> <th><label>房源相册</label></th>
<input type="button" value="取消" class="cancel existsCancel"> <td>
</p> <div id="picList">
{% endfor %} {% set exists_photo_ids = "" %}
<input type="hidden" name="exists_photo_ids" value="{{exists_photo_ids}}" > {% for item in images %}
</div><br /> {% if exists_photo_ids != "" %}
<button type="button" id="housePicture" class="button action" data-toggle="modal"> {% set exists_photo_ids = exists_photo_ids~"," %}
新增 {% endif %}
</button> {% set exists_photo_ids = exists_photo_ids~item.image_id %}
</td> <p>
</tr> <input type="radio" name="frontCover" value="{{item.image_id}}" {{ result.frontCover_id == item.image_id?"checked":"" }} />
<tr> <select name="exists_photo[{{ item.image_id }}][type]">
<th><label for="traffic">推荐房源</label></th> {% for i in photoType %}
<td> <option {{ i.id == item.image_type?"selected":"" }} value="{{ i.id }}">{{ i.value }}</option>
<div id="houseImg"> {% endfor %}
{% for item in recommends %} </select>
<p> <img src="{{siteUrl}}{{item.path}}" heghit="100" width="100">
<img src="{{siteUrl}}{{item.path}}" height="100" width="100"> <input type="button" value="取消" class="cancel existsCancel">
<input type="button" value="删除" class="imgCancel existsCancel"> </p>
<input type="hidden" name="data[recommend][]" value="{{item.id}}"> {% endfor %}
</p> <input type="hidden" name="exists_photo_ids" value="{{exists_photo_ids}}" >
{% endfor %} </div><br />
</div><br /> <button type="button" id="housePicture" class="button action" data-toggle="modal">
<button type="button" class="button action" data-toggle="modal" data-target="#myModal" id="recHouseBt"> 新增
添加房源 </button>
</button> </td>
</td> </tr>
</tr> <tr>
<tr> <th><label for="traffic">推荐房源</label></th>
<th><label for="feature">房源特色</label></th> <td>
<td> <div id="houseImg">
<div id="feature"> {% for item in recommends %}
{% for item in featureOld %} <p>
<p> <img src="{{siteUrl}}{{item.path}}" height="100" width="100">
<span>{{ item.name }}</span> <input type="button" value="删除" class="imgCancel existsCancel">
<input type="button" value="删除" class="featureCancel existsCancel"> <input type="hidden" name="data[recommend][]" value="{{item.id}}">
<input type="hidden" name="data[houseFeature][]" value="{{item.tag_id}}"> </p>
</p> {% endfor %}
{% endfor %} </div><br />
</div><br/> <button type="button" class="button action" data-toggle="modal" data-target="#myModal" id="recHouseBt">
<button type="button" class="button action" data-toggle="modal" data-target="#houseFeature" id="featureBt"> 添加房源
添加特色 </button>
</button> </td>
</td> </tr>
</tr> <tr>
<tr> <th><label for="feature">房源特色</label></th>
<th><label for="consultant">置业顾问</label></th> <td>
<td> <div id="feature">
<div id="consultantImg"> {% for item in featureOld %}
{% for item in consultant %} <p>
<p> <span>{{ item.name }}</span>
<span>{{item.name}}</span> <input type="button" value="删除" class="featureCancel existsCancel">
<input type="button" value="删除" class="consultantCancel existsCancel"> <input type="hidden" name="data[houseFeature][]" value="{{item.tag_id}}">
<input type="hidden" name="data[recConsultant][]" value="{{item.id}}"> </p>
</p> {% endfor %}
{% endfor %} </div><br/>
</div><br /> <button type="button" class="button action" data-toggle="modal" data-target="#houseFeature" id="featureBt">
<button type="button" class="button action" data-toggle="modal" data-target="#myConsultant" id="recConsultantBt"> 添加特色
选择置业顾问 </button>
</button> </td>
</td> </tr>
</tr> <tr>
{% if role == 'administrator' %} <th><label for="consultant">置业顾问</label></th>
<tr> <td>
<th><label for="from">状态</label></th> <div id="consultantImg">
<td> {% for item in consultant %}
<select id="status" name="status"> <p>
{% for item in status %} <span>{{item.name}}</span>
<option value={{item.id}}>{{item.value}}</option> <input type="button" value="删除" class="consultantCancel existsCancel">
{% endfor %} <input type="hidden" name="data[recConsultant][]" value="{{item.id}}">
</select> </p>
</td> {% endfor %}
</tr> </div><br />
{% endif %} <button type="button" class="button action" data-toggle="modal" data-target="#myConsultant" id="recConsultantBt">
</tbody> 选择置业顾问
</table> </button>
<input type="text" name="type" value="2" hidden="hidden"> </td>
{% if houseId %} </tr>
<input type="text" name="houseId" value="{{houseId}}" hidden="hidden"> {% if role == 'administrator' %}
{% endif %} <tr>
<input type="submit" id="submit" class="button action"> <th><label for="from">状态</label></th>
</form> <td>
<select id="status" name="status">
<!-- Modal --> {% for item in status %}
<!-- 新增房源弹出层 --> <option value={{item.id}}>{{item.value}}</option>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> {% endfor %}
<div class="modal-dialog" role="document"> </select>
<div class="modal-content"> </td>
</tr>
<div class="modal-body" style="height: 300px;overflow: auto;"> {% endif %}
<select id="cityId"> </tbody>
<option value="-1"> 城市</option> </table>
{% for item in city %} </div>
<option value="{{ item.id }}">{{ item.value }}</option> </div>
{% endfor %}
</select>
<select id="areaId"> <input type="text" name="type" value="2" hidden="hidden">
<option value = "-1">区域</option> {% if houseId %}
</select> <input type="text" name="houseId" value="{{houseId}}" hidden="hidden">
<select id="plateId"> {% endif %}
<option value = "-1">板块</option> </div>
</select> <div class="col-md-1">
<select id="price"> <input type="submit" id="submit" class="button action">
<option value = "-1">价格</option> </div>
</select> </div>
<select id="buildProperty"> </form>
<option value = "-1">房型</option>
{% for item in buildProperty %} <!-- Modal -->
<option value="{{ item.id }}">{{ item.value }}</option> <!-- 新增房源弹出层 -->
{% endfor %} <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
</select> <div class="modal-dialog" role="document">
<select id="room"> <div class="modal-content">
<option value = "-1">类型</option>
{% for item in room %} <div class="modal-body" style="height: 300px;overflow: auto;">
<option value="{{ item.id }}">{{ item.value }}</option> <select id="cityId">
{% endfor %} <option value="-1"> 城市</option>
</select> {% for item in city %}
<select id="acreage"> <option value="{{ item.id }}">{{ item.value }}</option>
<option value = "-1">面积</option> {% endfor %}
</select> </select>
<input type="text" placeholder="请出入楼盘名/地段名搜索" id="searchtext"> <select id="areaId">
<button type="button" class="button action" id="search">搜索</button> <option value = "-1">区域</option>
<ul id="houseList"> </select>
</ul> <select id="plateId">
</div> <option value = "-1">板块</option>
</div> </select>
</div> <select id="price">
</div> <option value = "-1">价格</option>
</select>
<!-- 置业顾问弹出层 --> <select id="buildProperty">
<div class="modal fade" id="myConsultant" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> <option value = "-1">房型</option>
<div class="modal-dialog" role="document"> {% for item in buildProperty %}
<div class="modal-content"> <option value="{{ item.id }}">{{ item.value }}</option>
<div class="modal-body" style="height: 300px;overflow: auto;"> {% endfor %}
<select id="consultCity"> </select>
<option value=""> 城市</option> <select id="room">
{% for item in city %} <option value = "-1">类型</option>
<option value="{{ item.id }}">{{ item.value }}</option> {% for item in room %}
{% endfor %} <option value="{{ item.id }}">{{ item.value }}</option>
</select> {% endfor %}
<input type="text" placeholder="请出入置业顾问姓名搜索" id="consultantName"> </select>
<button type="button" class="button action" id="searchConsult">搜索</button> <select id="acreage">
<ul id="consultantList"> <option value = "-1">面积</option>
</ul> </select>
</div> <input type="text" placeholder="请出入楼盘名/地段名搜索" id="searchtext" class="form-control">
</div> <button type="button" class="button action" id="search">搜索</button>
</div> <ul id="houseList">
</div> </ul>
</div>
<!-- 房源特色出层 --> </div>
<div class="modal fade" id="houseFeature" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> </div>
<div class="modal-dialog" role="document"> </div>
<div class="modal-content">
<table class="form-table" id="featureTable"> <!-- 置业顾问弹出层 -->
<tbody> <div class="modal fade" id="myConsultant" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<tr> <div class="modal-dialog" role="document">
<th style="width: 45px"><label for="feature">特色:</label></th> <div class="modal-content">
{% for item in feature %} <div class="modal-body" style="height: 300px;overflow: auto;">
<td id="{{ item.id }}">{{ item.value }}</td> <select id="consultCity">
{% endfor %} <option value=""> 城市</option>
</tr> {% for item in city %}
</tbody> <option value="{{ item.id }}">{{ item.value }}</option>
</table> {% endfor %}
</div> </select>
</div> <input type="text" placeholder="请出入置业顾问姓名搜索" id="consultantName" class="form-control">
</div> <button type="button" class="button action" id="searchConsult">搜索</button>
<ul id="consultantList">
</ul>
<script> </div>
(function($){ </div>
$(document).ready(function(){ </div>
//主力房源中选择图片file的下标 </div>
var i = 0;
//基本信息的联动AJAX <!-- 房源特色出层 -->
$("#baseCity").change(function(){ <div class="modal fade" id="houseFeature" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
var cityId = $("#baseCity").val(); <div class="modal-dialog" role="document">
var baserArea = $("#baseAreaId"); <div class="modal-content">
$('#baseAreaId').find('option:not(:first-child)').remove(); <table class="form-table" id="featureTable">
$('#basePlateId').find('option:not(:first-child)').remove(); <tbody>
<tr>
//城市联动区域 <th style="width: 45px"><label for="feature">特色:</label></th>
$.ajax({ {% for item in feature %}
type: "GET", <td id="{{ item.id }}">{{ item.value }}</td>
url: "/tospur/wp-admin/admin-ajax.php", {% endfor %}
data: "action=serachCity&cityId="+cityId, </tr>
success:function(json){ </tbody>
addOption(json,baserArea); </table>
} </div>
}); </div>
}); </div>
//区域联动板块
$("#baseAreaId").change(function(){
var basePlate = $("#basePlateId"); <script>
var areaId = $("#baseAreaId").val(); (function($){
var cityId = $("#baseCity").val(); $(document).ready(function(){
$('#basePlateId').find('option:not(:first-child)').remove(); var titleFlag = 0;
$.ajax({ //主力房源中选择图片file的下标
type: "GET", var i = 0;
url: "/tospur/wp-admin/admin-ajax.php", //基本信息的联动AJAX
data: "action=serachCity&cityId="+cityId+"&districtId="+areaId, $("#baseCity").change(function(){
success:function(json){ var cityId = $("#baseCity").val();
addOption(json,basePlate); var baserArea = $("#baseAreaId");
} $('#baseAreaId').find('option:not(:first-child)').remove();
}); $('#basePlateId').find('option:not(:first-child)').remove();
});
//城市联动区域
//根据上方选择的城市,选择推荐房源的默认城市 $.ajax({
$("#recHouseBt").click(function(){ type: "GET",
$('#cityId').find('option').remove(); url: "/tospur/wp-admin/admin-ajax.php",
$('#areaId').find('option:not(:first-child)').remove(); data: "action=serachCity&cityId="+cityId,
$('#plateId').find('option:not(:first-child)').remove(); success:function(json){
$('#price').find('option:not(:first-child)').remove(); addOption(json,baserArea);
$('#acreage').find('option:not(:first-child)').remove(); }
$("#houseList").find("li").remove(); });
var acreage =$("#acreage"); });
var price = $("#price"); //区域联动板块
var area = $("#areaId"); $("#baseAreaId").change(function(){
var cityId = $("#baseCity").val(); var basePlate = $("#basePlateId");
var cityName = $("#baseCity").find("option:selected").text(); var areaId = $("#baseAreaId").val();
var option = $("<option>").attr("value",cityId).append(cityName); var cityId = $("#baseCity").val();
$("#cityId").append(option); $('#basePlateId').find('option:not(:first-child)').remove();
if(cityId != -1){ $.ajax({
$.ajax({ type: "GET",
type: "GET", url: "/tospur/wp-admin/admin-ajax.php",
url: "/tospur/wp-admin/admin-ajax.php", data: "action=serachCity&cityId="+cityId+"&districtId="+areaId,
data: "action=serachCity&cityId="+cityId, success:function(json){
success:function(json){ addOption(json,basePlate);
addOption(json,area); }
} });
}); });
//城市联动房子面积 //根据上方选择的城市,选择推荐房源的默认城市
$.ajax({ $("#recHouseBt").click(function(){
type: "GET", $('#cityId').find('option').remove();
url: "/tospur/wp-admin/admin-ajax.php", $('#areaId').find('option:not(:first-child)').remove();
data: "action=searchArea&cityId="+cityId, $('#plateId').find('option:not(:first-child)').remove();
success:function(json){ $('#price').find('option:not(:first-child)').remove();
addOption(json,acreage); $('#acreage').find('option:not(:first-child)').remove();
} $("#houseList").find("li").remove();
}); var acreage =$("#acreage");
//城市联动房子价格 var price = $("#price");
$.ajax({ var area = $("#areaId");
type: "GET", var cityId = $("#baseCity").val();
url: "/tospur/wp-admin/admin-ajax.php", var cityName = $("#baseCity").find("option:selected").text();
data: "action=searchUnitPriceRange&cityId="+cityId, var option = $("<option>").attr("value",cityId).append(cityName);
success:function(json){ $("#cityId").append(option);
addOption(json,price); if(cityId != -1){
} $.ajax({
}); type: "GET",
addList(1) url: "/tospur/wp-admin/admin-ajax.php",
} data: "action=serachCity&cityId="+cityId,
}); success:function(json){
addOption(json,area);
//区域联动板块 }
$("#areaId").change(function(){ });
var areaId = $("#areaId").val();
var cityId = $("#cityId").val(); //城市联动房子面积
var plate = $("#plateId"); $.ajax({
$("#houseList").find("li").remove(); type: "GET",
$('#plateId').find('option:not(:first-child)').remove(); url: "/tospur/wp-admin/admin-ajax.php",
$.ajax({ data: "action=searchArea&cityId="+cityId,
type: "GET", success:function(json){
url: "/tospur/wp-admin/admin-ajax.php", addOption(json,acreage);
data: "action=serachCity&cityId="+cityId+"&districtId="+areaId, }
success:function(json){ });
addOption(json,plate); //城市联动房子价格
} $.ajax({
}); type: "GET",
}); url: "/tospur/wp-admin/admin-ajax.php",
data: "action=searchUnitPriceRange&cityId="+cityId,
//推荐房源下显示图片信息以及房名 success:function(json){
$("#areaId,#plateId,#buildProperty,#room,#acreage,#price").change(function(){ addOption(json,price);
addList(1) }
}); });
addList(1)
//添加房源中搜索框的搜索 }
$("#search").click(function(){ });
$searchtext = $("#searchtext").val();
$("#houseList").find("li").remove(); //区域联动板块
$.ajax({ $("#areaId").change(function(){
type: "post", var areaId = $("#areaId").val();
url: "/tospur/wp-admin/admin-ajax.php", var cityId = $("#cityId").val();
data: "action=searchHouse&searchText="+$searchtext, var plate = $("#plateId");
success:function(json){ $("#houseList").find("li").remove();
var result = json.result; $('#plateId').find('option:not(:first-child)').remove();
for(var i = 0; i < result.length; i++){ $.ajax({
var name = result[i]["name"]; type: "GET",
var id = result[i]['id']; url: "/tospur/wp-admin/admin-ajax.php",
var imgUrl = json.images[id]; data: "action=serachCity&cityId="+cityId+"&districtId="+areaId,
var img = $("<img>").attr({"src":imgUrl,"height":100,"width":100}); success:function(json){
var li = $("<li>").addClass("addImg").append(img).append(name); addOption(json,plate);
$("#houseList").append(li); }
} });
} });
});
}) //推荐房源下显示图片信息以及房名
$("#areaId,#plateId,#buildProperty,#room,#acreage,#price").change(function(){
//根据上方选择的城市,选择推荐置业顾问的默认城市 addList(1)
$("#recConsultantBt").click(function(){ });
$('#consultCity').find('option').remove();
$("#consultantList").find("li").remove(); //添加房源中搜索框的搜索
var consulCityId = $("#baseCity").val(); $("#search").click(function(){
var consultantName =$("#consultantName").val(); $searchtext = $("#searchtext").val();
var cityName = $("#baseCity").find("option:selected").text(); $("#houseList").find("li").remove();
var option = $("<option>").attr("value",consulCityId).append(cityName); $.ajax({
$("#consultCity").append(option); type: "post",
$.ajax({ url: "/tospur/wp-admin/admin-ajax.php",
type: "GET", data: "action=searchHouse&searchText="+$searchtext,
url: "/tospur/wp-admin/admin-ajax.php", success:function(json){
data: "action=searchConsultant&consulCityId="+consulCityId+"&consultantName="+consultantName, var result = json.result;
success:function(json){ for(var i = 0; i < result.length; i++){
for(var i = 0; i <=json.length-1; i++){ var name = result[i]["name"];
var name = json[i]["consultantName"]; var id = result[i]['id'];
var imgUrl = json[i]["imageUrl"]; var imgUrl = json.images[id];
var img = $("<img>").attr({"src":imgUrl,"height":100,"width":100}); var img = $("<img>").attr({"src":imgUrl,"height":100,"width":100});
var li = $("<li>").attr("id",json[i]["id"]).append(img).append(name).addClass("consultantImg"); var li = $("<li>").addClass("addImg").append(img).append(name);
$("#consultantList").append(li); $("#houseList").append(li);
} }
} }
}); });
}); })
//添加置业顾问弹出层中搜索框的搜索内容
$("#searchConsult").click(function(){ //根据上方选择的城市,选择推荐置业顾问的默认城市
var consulCityId = $("#consultCity").val(); $("#recConsultantBt").click(function(){
var consultantName =$("#consultantName").val(); $('#consultCity').find('option').remove();
$("#consultantList").find("li").remove(); $("#consultantList").find("li").remove();
$.ajax({ var consulCityId = $("#baseCity").val();
type: "GET", var consultantName =$("#consultantName").val();
url: "/tospur/wp-admin/admin-ajax.php", var cityName = $("#baseCity").find("option:selected").text();
data: "action=searchConsultant&consulCityId="+consulCityId+"&consultantName="+consultantName, var option = $("<option>").attr("value",consulCityId).append(cityName);
success:function(json){ $("#consultCity").append(option);
for(var i = 0; i <=json.length-1; i++){ $.ajax({
var name = json[i]["consultantName"]; type: "GET",
var imgUrl = json[i]["imageUrl"]; url: "/tospur/wp-admin/admin-ajax.php",
var img = $("<img>").attr({"src":imgUrl,"height":100,"width":100}); data: "action=searchConsultant&consulCityId="+consulCityId+"&consultantName="+consultantName,
var li = $("<li>").append(img).append(name).addClass("consultantImg"); success:function(json){
$("#consultantList").append(li); for(var i = 0; i <=json.length-1; i++){
} var name = json[i]["consultantName"];
} var imgUrl = json[i]["imageUrl"];
}); var img = $("<img>").attr({"src":imgUrl,"height":100,"width":100});
}) var li = $("<li>").attr("id",json[i]["id"]).append(img).append(name).addClass("consultantImg");
$("#consultantList").append(li);
//点击添加房源中显示的列表,在界面中显示 }
$("#houseList").on("click",".addImg",function(){ }
var recommendHouse = $("<input>").attr({"type":"hidden","name":"data[recommend][]","value": $(this).attr("id")}); });
var url = $(this).find("img").attr("src"); });
var img = $("<img>").attr({"src":url,"height":100,"width":100}); //添加置业顾问弹出层中搜索框的搜索内容
var cancel = $("<input>").attr({"type":"button","value":"删除"}).addClass("imgCancel"); $("#searchConsult").click(function(){
var p = $("<p>").append(img).append(cancel).append(recommendHouse); var consulCityId = $("#consultCity").val();
$("#houseImg").append(p); var consultantName =$("#consultantName").val();
controlCommand("houseImg",3,0); $("#consultantList").find("li").remove();
}); $.ajax({
//添加置业顾问 type: "GET",
$("#consultantList").on("click",".consultantImg",function(){ url: "/tospur/wp-admin/admin-ajax.php",
var recommendConsultant = $("<input>").attr({"type":"hidden","name":"data[recConsultant][]","value": $(this).attr("id")}); data: "action=searchConsultant&consulCityId="+consulCityId+"&consultantName="+consultantName,
var cancel = $("<input>").attr({"type":"button","value":"删除"}).addClass("consultantCancel"); success:function(json){
var font = $("<font>").append( $(this).text()); for(var i = 0; i <=json.length-1; i++){
var p = $("<p>").append(font).append(cancel).append(recommendConsultant); var name = json[i]["consultantName"];
$("#consultantImg").append(p); var imgUrl = json[i]["imageUrl"];
controlCommand("consultantImg",1,1); var img = $("<img>").attr({"src":imgUrl,"height":100,"width":100});
}); var li = $("<li>").append(img).append(name).addClass("consultantImg");
$("#consultantList").append(li);
//新增房源相册 }
$("#housePicture").click(function(){ }
var checkBox = $("<input>").attr({"type":"radio","name":"frontCover","value":i}); });
var picDelet = $("<input>").attr({"type":"button","value":"删除"}).addClass("picDelet"); })
var file = $("<input>").attr({"type":"file","name":"files["+i+"]"}).addClass("picFiles");
var select = $("<select>").attr("name","data["+i+"][type]"); //点击添加房源中显示的列表,在界面中显示
{% for item in photoType %} $("#houseList").on("click",".addImg",function(){
select.append($("<option>").attr("value",{{item.id}}).append('{{item.value}}')); var recommendHouse = $("<input>").attr({"type":"hidden","name":"data[recommend][]","value": $(this).attr("id")});
{% endfor%} var url = $(this).find("img").attr("src");
var p = $("<p>").append(checkBox).append(select).append(file).append(picDelet); var img = $("<img>").attr({"src":url,"height":100,"width":100});
$("#picList").append(p); var cancel = $("<input>").attr({"type":"button","value":"删除"}).addClass("imgCancel");
i++ var p = $("<p>").append(img).append(cancel).append(recommendHouse);
}); $("#houseImg").append(p);
//显示选中的特色 controlCommand("houseImg",3,0);
$("#featureTable").find("tr > td").click(function(){ });
var houseFeature = $("<input>").attr({"type":"hidden","name":"data[houseFeature][]","value": $(this).attr("id")}); //添加置业顾问
var cancel = $("<input>").attr({"type":"button","value":"删除"}).addClass("featureCancel"); $("#consultantList").on("click",".consultantImg",function(){
var font = $("<font>").append( $(this).text()); var recommendConsultant = $("<input>").attr({"type":"hidden","name":"data[recConsultant][]","value": $(this).attr("id")});
var p =$("<p>").append(houseFeature).append(font).append(cancel); var cancel = $("<input>").attr({"type":"button","value":"删除"}).addClass("consultantCancel");
$("#feature").append(p); var font = $("<font>").append( $(this).text());
var p = $("<p>").append(font).append(cancel).append(recommendConsultant);
}); $("#consultantImg").append(p);
controlCommand("consultantImg",1,1);
//房源相册 });
$("#picList").on("change",".picFiles",function(){
readURL(this,2); //新增房源相册
$(this).hide(); $("#housePicture").click(function(){
}); var checkBox = $("<input>").attr({"type":"radio","name":"frontCover","value":i});
var picDelet = $("<input>").attr({"type":"button","value":"删除"}).addClass("button action picDelet");
//删除房源相册、推荐房源、推荐置业顾问 var file = $("<input>").attr({"type":"file","name":"files["+i+"]"}).addClass("picFiles");
$("#houseImg,#consultantImg,#picList,#feature").on("click",".imgCancel,.consultantCancel,.picDelet,.featureCancel",function(){ var select = $("<select>").attr("name","data["+i+"][type]");
$(this).parent("p").remove(); var checkTd = $("<th>").append(checkBox);
}); var picDeletTd = $("<td>").append(picDelet);
var selectTd = $("<th>").append(select);
$("#picList,#houseImg,#consultantImg").on("click",".existsCancel",function(){ var fileTd = $("<th>").append(file);
$(this).parent().remove(); {% for item in photoType %}
}); select.append($("<option>").attr("value",{{item.id}}).append('{{item.value}}'));
{% endfor%}
$("#submit").click(function(){ var p = $("<p>").append(checkTd).append(selectTd).append(fileTd).append(picDeletTd);
if($("#housename").val()==""){ var fontA = $("<font>").append("设为封面");
alert("请输入楼盘名"); var fontB = $("<font>").append("类型");
return false; var fontC = $("<font>").append("相册");
} var tdA = $("<th>").append(fontA);
}); var tdB = $("<th>").append(fontB);
var tdC = $("<th>").append(fontC);
//file上传之前,显示图片的方法 var titleP = $("<p>").append(tdA).append(tdB).append(tdC);
function readURL(input,type) { $("#picList").append(p);
if(type == 1){ if( titleFlag== 0){
if (input.files && input.files[0]){ $("#picList").before(titleP);
var reader = new FileReader(); titleFlag = 1
reader.onload = function (e) { }
var img = $("<img>").attr({"id":"target","src":e.target.result,"heghit":100,"width":100}); i++
var button = $("<input>").attr({"type":"button","value":"取消","property":+i,"id":+i}).addClass("cancel"); });
var type = $("<input>").attr({"type":"hidden","name":"data["+i+"][type]","value":0,"property":+i}); //显示选中的特色
var file = $("<input>").attr({"type":"file","name":"files["+(i+1)+"]","property":+(i+1)}).addClass("files"); $("#featureTable").find("tr > td").click(function(){
var select = $("<select>").attr({"name":"data["+i+"][buildProperty]"}); var houseFeature = $("<input>").attr({"type":"hidden","name":"data[houseFeature][]","value": $(this).attr("id")});
{% for item in buildProperty %}{{item.id}} var cancel = $("<input>").attr({"type":"button","value":"删除"}).addClass("featureCancel");
select.append($("<option>").attr("value",{{item.id}}).append('{{item.value}}')); var font = $("<font>").append( $(this).text());
{% endfor%} var p =$("<p>").append(houseFeature).append(font).append(cancel);
var areatext = $("<input>").attr({"type":"text","placeholder":"面积","name":"data["+i+"][housearea]"}).addClass("regular-text"); $("#feature").append(p);
var div = $("<div>").append(select).append(areatext).append(button).append(type);
var span = $("<span>").attr({"property":+i}).append(img).append(div); });
$("form").find("#preview > p").before(file);
$("#preview > p").append(span); //房源相册
i++; $("#picList").on("change",".picFiles",function(){
} readURL(this,2);
} $(this).hide();
}else{ });
if (input.files && input.files[0]){
var reader = new FileReader(); //删除房源相册、推荐房源、推荐置业顾问
reader.onload = function (e){ $("#houseImg,#consultantImg,#picList,#feature").on("click",".imgCancel,.consultantCancel,.picDelet,.featureCancel",function(){
var img = $("<img>").attr({"src":e.target.result,"heghit":100,"width":100}); $(this).parent("p").remove();
$(input).before(img); });
}
} $("#picList,#houseImg,#consultantImg").on("click",".existsCancel",function(){
} $(this).parent().remove();
reader.readAsDataURL(input.files[0]); });
}
function addOption(json,select){ $("#submit").click(function(){
var selectId = select.attr("id"); if($("#housename").val()==""){
for(var i = 0; i <=json.length-1; i++){ alert("请输入楼盘名");
var id = json[i]["id"]; return false;
var value = json[i]["value"]; }
if(selectId == "acreage" || selectId == "price"){ });
id = value;
} //file上传之前,显示图片的方法
var Option = $("<option>").attr({"value": id}).append(value); function readURL(input,type) {
select.append(Option); if(type == 1){
} if (input.files && input.files[0]){
} var reader = new FileReader();
reader.onload = function (e) {
function controlCommand(id,number,type){ var img = $("<img>").attr({"id":"target","src":e.target.result,"heghit":100,"width":100});
var num = $("#"+id+" > p").length; var button = $("<input>").attr({"type":"button","value":"取消","property":+i,"id":+i}).addClass("cancel");
if(num>number){ var type = $("<input>").attr({"type":"hidden","name":"data["+i+"][type]","value":0,"property":+i});
if(type==0){ var file = $("<input>").attr({"type":"file","name":"files["+(i+1)+"]","property":+(i+1)}).addClass("files");
alert("最多只能推荐3个房源"); var select = $("<select>").attr({"name":"data["+i+"][buildProperty]"});
}else if(type==1){ {% for item in buildProperty %}{{item.id}}
alert("您只能推荐一位置业顾问"); select.append($("<option>").attr("value",{{item.id}}).append('{{item.value}}'));
} {% endfor%}
$("#"+id).find("p:last-child").remove(); var areatext = $("<input>").attr({"type":"text","placeholder":"面积","name":"data["+i+"][housearea]"}).addClass("form-control");
} var div = $("<div>").append(select).append(areatext).append(button).append(type);
} var span = $("<span>").attr({"property":+i}).append(img).append(div);
$("form").find("#preview > p").before(file);
function getUrlParmas(){ $("#preview > p").append(span);
var href = location.search.substr(1,location.search.length-1); i++;
var params = href.split("&"); }
var map = {}; }
for(item in params){ }else{
var key = params[item].split("=")[0] || ""; if (input.files && input.files[0]){
var value = params[item].split("=")[1] || ""; var reader = new FileReader();
map[key] = value; reader.onload = function (e){
} var img = $("<img>").attr({"src":e.target.result,"heghit":100,"width":100});
return map; $(input).before(img);
} }
}
function addList(houseType){ }
$("#houseList").find("li").remove(); reader.readAsDataURL(input.files[0]);
var cityId = $("#baseCity").val(); }
var buildPropertyId = $("#buildProperty").val(); function addOption(json,select){
var room = $("#room").val(); var selectId = select.attr("id");
var areaId = $("#areaId").val(); for(var i = 0; i <=json.length-1; i++){
var cityId = $("#cityId").val(); var id = json[i]["id"];
var plateId = $("#plateId").val(); var value = json[i]["value"];
var acreage = $("#acreage").val(); if(selectId == "acreage" || selectId == "price"){
var price = $("#price").val(); id = value;
$.ajax({ }
type: "post", var Option = $("<option>").attr({"value": id}).append(value);
url: "/tospur/wp-admin/admin-ajax.php", select.append(Option);
data: "action=searchHouse&cityId="+cityId+"&districtId="+areaId+"&plateId="+plateId+"&buildPropertyId="+buildPropertyId+"&roomId="+room+"&acreage="+acreage+"&totalPrice="+price+"&houseType="+houseType, }
success:function(json){ }
var result = json.result;
var urlParams = getUrlParmas(); function controlCommand(id,number,type){
for(var i = 0; i <result.length; i++){ var num = $("#"+id+" > p").length;
var name = result[i]["name"]; if(num>number){
var id = result[i]['id']; if(type==0){
var imgUrl = result[i]['path']; alert("最多只能推荐3个房源");
var img = $("<img>").attr({"src":imgUrl,"height":100,"width":100}); }else if(type==1){
var li = $("<li>").attr("id",id).addClass("addImg").append(img).append(name); alert("您只能推荐一位置业顾问");
if(urlParams["id"]){ }
if(urlParams["id"]!=id){ $("#"+id).find("p:last-child").remove();
$("#houseList").append(li); }
} }
}else{
$("#houseList").append(li); function getUrlParmas(){
} var href = location.search.substr(1,location.search.length-1);
} var params = href.split("&");
} var map = {};
}); for(item in params){
} var key = params[item].split("=")[0] || "";
}); var value = params[item].split("=")[1] || "";
})(jQuery); map[key] = value;
}
</script> return map;
}
</body>
function addList(houseType){
$("#houseList").find("li").remove();
var cityId = $("#baseCity").val();
var buildPropertyId = $("#buildProperty").val();
var room = $("#room").val();
var areaId = $("#areaId").val();
var cityId = $("#cityId").val();
var plateId = $("#plateId").val();
var acreage = $("#acreage").val();
var price = $("#price").val();
$.ajax({
type: "post",
url: "/tospur/wp-admin/admin-ajax.php",
data: "action=searchHouse&cityId="+cityId+"&districtId="+areaId+"&plateId="+plateId+"&buildPropertyId="+buildPropertyId+"&roomId="+room+"&acreage="+acreage+"&totalPrice="+price+"&houseType="+houseType,
success:function(json){
var result = json.result;
var urlParams = getUrlParmas();
for(var i = 0; i <result.length; i++){
var name = result[i]["name"];
var id = result[i]['id'];
var imgUrl = result[i]['path'];
var img = $("<img>").attr({"src":imgUrl,"height":100,"width":100});
var li = $("<li>").attr("id",id).addClass("addImg").append(img).append(name);
if(urlParams["id"]){
if(urlParams["id"]!=id){
$("#houseList").append(li);
}
}else{
$("#houseList").append(li);
}
}
}
});
}
});
})(jQuery);
</script>
</body>
</html> </html>
\ No newline at end of file
<div class="wrap"> <div class="wrap">
<h2>二手房列表</h2> <h2>二手房列表</h2>
<form id="scores-filter" method="POST"> <form id="scores-filter" method="POST">
<!-- For plugins, we also need to ensure that the form posts back to our current page --> <!-- For plugins, we also need to ensure that the form posts back to our current page -->
<input type="hidden" name="page" value="{{page}}"/> <input type="hidden" name="page" value="{{page}}"/>
<input type="hidden" name="hasSearch" value="1"/> <input type="hidden" name="hasSearch" value="1"/>
<select id="listCity" name="listCity"> <select id="listCity" name="listCity">
<option value="0"> 城市</option> <option value="0"> 城市</option>
{% for item in city %} {% for item in city %}
<option {{ item.id == cityId ?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option> <option {{ item.id == cityId ?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option>
{% endfor %} {% endfor %}
</select> </select>
<select id="listDistrict" name="listDistrict"> <select id="listDistrict" name="listDistrict">
<option value="0">区域</option> <option value="0">区域</option>
{% if district %} {% if district %}
{% for item in district %} {% for item in district %}
<option {{ item.id == districtId ?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option> <option {{ item.id == districtId ?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option>
{% endfor %} {% endfor %}
{% endif %} {% endif %}
</select> </select>
<select id="listPlate" name="listPlate"> <select id="listPlate" name="listPlate">
<option value="0">板块</option> <option value="0">板块</option>
{% if plate %} {% if plate %}
{% for item in plate %} {% for item in plate %}
<option {{ item.id == plateId ?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option> <option {{ item.id == plateId ?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option>
{% endfor %} {% endfor %}
{% endif %} {% endif %}
</select> </select>
<select id="totalPrice" name="totalPrice"> <select id="totalPrice" name="totalPrice">
<option value ="">价格</option> <option value ="">价格</option>
{% if dicTotalPrice %} {% if dicTotalPrice %}
{% for item in dicTotalPrice %} {% for item in dicTotalPrice %}
<option {{ item.value == totalPrice ?"selected":"" }} value="{{ item.value }}">{{ item.value }}</option> <option {{ item.value == totalPrice ?"selected":"" }} value="{{ item.value }}">{{ item.value }}</option>
{% endfor %} {% endfor %}
{% endif %} {% endif %}
</select> </select>
<select id="buildProperty" name="buildProperty"> <select id="buildProperty" name="buildProperty">
<option value="0"> 房型</option> <option value="0"> 房型</option>
{% for item in buildProperty %} {% for item in buildProperty %}
<option {{ item.id == buildPropertyId ?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option> <option {{ item.id == buildPropertyId ?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option>
{% endfor %} {% endfor %}
</select> </select>
<select id="acreage" name="acreage"> <select id="acreage" name="acreage">
<option value ="">面积</option> <option value ="">面积</option>
{% if acreage %} {% if acreage %}
{% for item in dicArea %} {% for item in dicArea %}
<option {{ item.value == acreage ?"selected":"" }} value="{{ item.value }}">{{ item.value }}</option> <option {{ item.value == acreage ?"selected":"" }} value="{{ item.value }}">{{ item.value }}</option>
{% endfor %} {% endfor %}
{% endif %} {% endif %}
</select> </select>
<select name="status" name="status"> <select name="status" name="status">
<option value="-1">状态</option> <option value="-1">状态</option>
{% for item in status%} {% for item in status%}
<option {{ item.id == statusId ?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option> <option {{ item.id == statusId ?"selected":"" }} value="{{ item.id }}">{{ item.value }}</option>
{% endfor %} {% endfor %}
</select> </select>
<input type="text" placeholder="请出入楼盘名/地段名搜索" name="searchText"> <input type="text" placeholder="请出入楼盘名/地段名搜索" name="searchText">
<input type="submit" id="submit" class="button action" value="搜索"> <input type="submit" id="submit" class="button action" value="搜索">
<!-- Now we can render the completed list table --> <!-- Now we can render the completed list table -->
{{function("addSecTable")}} {{function("addSecTable")}}
</form> </form>
</div> </div>
<script> <script>
(function ($) { (function ($) {
$(document).ready(function(){ $(document).ready(function(){
$("#listCity").change(function(){ $("#listCity").change(function(){
var listCityId = $("#listCity").val(); var listCityId = $("#listCity").val();
var district =$("#listDistrict"); var district =$("#listDistrict");
var acreage =$("#acreage"); var acreage =$("#acreage");
var totalPrice = $("#totalPrice"); var totalPrice = $("#totalPrice");
$('#listDistrict').find('option:not(:first-child)').remove(); $('#listDistrict').find('option:not(:first-child)').remove();
$('#listPlate').find('option:not(:first-child)').remove(); $('#listPlate').find('option:not(:first-child)').remove();
$.ajax({ $.ajax({
type: "GET", type: "GET",
url: "/tospur/wp-admin/admin-ajax.php", url: "/tospur/wp-admin/admin-ajax.php",
data: "action=serachCity&cityId="+listCityId, data: "action=serachCity&cityId="+listCityId,
success:function(json){ success:function(json){
addOption(json,district); addOption(json,district);
} }
}); });
//面积 //面积
$.ajax({ $.ajax({
type: "GET", type: "GET",
url: "/tospur/wp-admin/admin-ajax.php", url: "/tospur/wp-admin/admin-ajax.php",
data: "action=searchArea&cityId="+listCityId, data: "action=searchArea&cityId="+listCityId,
success:function(json){ success:function(json){
for(var i = 0; i <=json.length-1; i++){ for(var i = 0; i <=json.length-1; i++){
var id = json[i]["id"]; var id = json[i]["id"];
var value = json[i]["value"]; var value = json[i]["value"];
var Option = $("<option>").attr({"value": value}).append(value); var Option = $("<option>").attr({"value": value}).append(value);
$("#acreage").append(Option); $("#acreage").append(Option);
} }
} }
}); });
//城市联动房子价格 //城市联动房子价格
$.ajax({ $.ajax({
type: "GET", type: "GET",
url: "/tospur/wp-admin/admin-ajax.php", url: "/tospur/wp-admin/admin-ajax.php",
data: "action=searchTotalPrice&cityId="+listCityId, data: "action=searchTotalPrice&cityId="+listCityId,
success:function(json){ success:function(json){
for(var i = 0; i <=json.length-1; i++){ for(var i = 0; i <=json.length-1; i++){
var id = json[i]["id"]; var id = json[i]["id"];
var value = json[i]["value"]; var value = json[i]["value"];
var Option = $("<option>").attr({"value": value}).append(value); var Option = $("<option>").attr({"value": value}).append(value);
$("#totalPrice").append(Option); $("#totalPrice").append(Option);
} }
} }
}); });
}) })
$("#listDistrict").change(function(){ $("#listDistrict").change(function(){
var listCityId = $("#listCity").val(); var listCityId = $("#listCity").val();
var listDistrict = $("#listDistrict").val(); var listDistrict = $("#listDistrict").val();
var listPlate = $("#listPlate"); var listPlate = $("#listPlate");
$('#listPlate').find('option:not(:first-child)').remove(); $('#listPlate').find('option:not(:first-child)').remove();
$.ajax({ $.ajax({
type: "GET", type: "GET",
url: "/tospur/wp-admin/admin-ajax.php", url: "/tospur/wp-admin/admin-ajax.php",
data: "action=serachCity&cityId="+listCityId+"&districtId="+listDistrict, data: "action=serachCity&cityId="+listCityId+"&districtId="+listDistrict,
success:function(json){ success:function(json){
addOption(json,listPlate); addOption(json,listPlate);
} }
}); });
}) })
function addOption(json,select){ function addOption(json,select){
for(var i = 0; i <=json.length-1; i++){ for(var i = 0; i <=json.length-1; i++){
var id = json[i]["id"]; var id = json[i]["id"];
var value = json[i]["value"]; var value = json[i]["value"];
var Option = $("<option>").attr({"value": id}).append(value); var Option = $("<option>").attr({"value": id}).append(value);
select.append(Option); select.append(Option);
} }
} }
}); });
})(jQuery); })(jQuery);
</script> </script>
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