|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210 |
- /**
- * Created by luocj on 2016/10/28.
- */
- var provinceHTML = '';
- var cityHTML = '';
- var inputBase = $('.inputBase_temp').prop('outerHTML');
- var districtHTML = '';
- $(document).ready(function () {
- chooseProvince();
- chooseCity();
- chooseDistrict()
- commit();
- addBaseRoomType();
- });
- //选择省
- function chooseProvince() {
- provinceHTML = $('#province').html();
- cityHTML = $('#city').html();
- var apiurl = base_api + "?type=hotel_AddHotelProduct&op=provinceCity &area_id=";
- ZZLog(apiurl);
- $.getJSON(apiurl, function (res_data) {
- ZZLog(res_data);
- if (res_data['code'] != "0") {
- alert(res_data['info']);
- } else {
- //地区
- var area_list = res_data['area_list'];
- var areaHTML = '<option value="0" style="font-size:12px;">选择省</option>';
- for (var i = 0, m = area_list.length; i < m; i++) {
- var tempDict = area_list[i];
- var tempHTML = provinceHTML;
- tempHTML = tempHTML.replace('选择省', tempDict['area_name']);
- tempHTML = tempHTML.replace('0', tempDict['area_id']);
- areaHTML += tempHTML;
- }
- if (areaHTML) {
- $('#province').html(areaHTML);
- $('#province')[0].selectedIndex = 0;
- }
- }
- })
- }
- //选择市
- function chooseCity() {
- districtHTML = $('#district').html();
- $('#province').bind('change', function () {
- var area_id = $(this).val();
- if (area_id == "0" || area_id == "") {
- $('#city').html(cityHTML);
- return;
- }
- var url = base_api + "?type=hotel_AddHotelProduct&op=provinceCity&area_id=" + area_id;
- ZZLog(url);
- $.getJSON(url, function (res_data) {
- ZZLog(res_data);
- if (res_data['code'] != "0") {
- alert(res_data['info']);
- } else {
- //地区
- var area_list = res_data['area_list'];
- var areaHTML = '<option value="0" style="font-size: 12px;">选择市</option>';
- for (var i = 0, m = area_list.length; i < m; i++) {
- var tempDict = area_list[i];
- var tempHTML = cityHTML;
- tempHTML = tempHTML.replace('选择市', tempDict['area_name']);
- tempHTML = tempHTML.replace('0', tempDict['area_id']);
- areaHTML += tempHTML;
- }
- if (areaHTML) {
- $('#city').html(areaHTML);
- $('#city')[0].selectedIndex = 0;
- }
- }
- })
- });
- }
- //选择区
- function chooseDistrict() {
- $('#city').bind('change', function () {
- var area_id = $(this).val();
- if (area_id == "0" || area_id == "") {
- $('#district').html(districtHTML);
- return;
- }
- var url = base_api + "?type=hotel_AddHotelProduct&op=provinceCity&area_id=" + area_id;
- ZZLog(url);
- $.getJSON(url, function (res_data) {
- ZZLog(res_data);
- if (res_data['code'] != "0") {
- alert(res_data['info']);
- } else {
- //地区
- var area_list = res_data['area_list'];
- var areaHTML = '<option value="0" style="font-size: 12px;">选择区</option>';
- for (var i = 0, m = area_list.length; i < m; i++) {
- var tempDict = area_list[i];
- var tempHTML = districtHTML;
- tempHTML = tempHTML.replace('选择区', tempDict['area_name']);
- tempHTML = tempHTML.replace('0', tempDict['area_id']);
- areaHTML += tempHTML;
- }
- if (areaHTML) {
- $('#district').html(areaHTML);
- $('#district')[0].selectedIndex = 0;
- }
- if (area_list==''){
- $('#district').hide();
- }else {
- $('#district').show();
- }
- }
- })
- });
- }
- //添加基础房型
- function addBaseRoomType() {
- $('#add').bind('click', function () {
- var HTML = inputBase;
- HTML = HTML.replace('display:none!important;', '');
- HTML = HTML.replace('inputBase_temp', 'inputBase');
- $('#roomTypeShow').append(HTML);
- })
- }
- //删除
- function deleteBRT(obj) {
- $(obj).closest('div').remove();
- }
- //提交
- function commit() {
- $('.save').bind('click', function () {
- var hotel_name = $('.hotelNameInput').val();
- var province = $('#province').val();
- var city = $('#city').val();
- var district = $('#district').val();
- var address = $('.inputAddress').val();
- var status = $('.status_value').val();
- var sum_base_room_type = new Array;
- var star_level = $('.star_level').val();
- //判断非空
- //酒店名称判断非空
- if ("" == hotel_name) {
- alert('请完整填写!!!')
- $('.hotelNameInput').focus();
- return false;
- }
- //判断地区非空
- var area_id ='';
- if (district=='0'&&city!=0){
- area_id = city;
- }else if (district=='0'&&city=='0'){
- area_id= province;
- }else if (district !='0'){
- area_id = district
- }else {
- area_id = '';
- }
- if (area_id ==''){
- alert('请选择地区!!!')
- return false;
- }
- // //判断状态非空
- // if ("-1" == status) {
- // alert('请选择状态!!!');
- // return false;
- // }
- //判断基本状态非空
- $('.inputBase').each(function (index, dom) {
- var base_room_type = $(this).find(".base_room_type").val();
- if (base_room_type != "") {
- sum_base_room_type.push(base_room_type);
- } else {
- $(this).find(".base_room_type").focus();
- return false;
- }
- });
- if (sum_base_room_type.length < $('.inputBase').length) {
- alert('请完整填写!!!');
- return false;
- }
- // sum_base_room_type = sum_base_room_type.join(",");
- var param = {
- type: 'hotel_Addhotel',
- hotel_name: hotel_name,
- province: province,
- area_id: area_id,
- address: address,
- //status: status,
- base_room_type: sum_base_room_type,
- star_level:star_level
- };
- ZZLog(param);
- $.ajax({
- data: param,
- type: 'post',
- dataType: 'json',
- url: base_api,
- success: function (res_data) {
- if (res_data['code'] != 0) {
- alert(res_data['info'])
- } else {
- window.location.href='hotel_list.html';
- }
- },
- error: function (error) {
- alert('system ajax http error');
- ZZLog(error);
- }
- })
- })
- }
|