/** * Created by luocj on 2016/11/1. */ var provinceHTML = ''; var cityHTML = ''; var districtHTML = ''; var inputBase = $('.inputBase_temp').prop('outerHTML'); var hotel_name = ''; var user_id = ''; var province1 = ''; var city1 = ''; var district1 = ''; $(document).ready(function () { hotel_name = getPar('hotel_name'); hotel_id = getPar('hotel_id'); chooseProvince(); chooseCity(); chooseDistrict(); commit(); addBaseRoomType(); getHotelInfo() }); //选择省 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 = ''; 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 = ''; 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 = ''; 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) { var param = { type: 'hotel_AddHotelProduct', op: 'deletebaseroom', hotel_id: hotel_id, baseroomname: $(obj).closest('div').children('.base_room_type').val() } ZZLog(param); $.ajax({ url: base_api, data: param, dataType: 'json', type: 'post', success: function (res_data) { ZZLog(res_data); if (res_data['mes'] == '0') { alert('有库存,不能删除'); } else if (res_data['mes'] == '1') { $(obj).closest('div').remove(); } }, error: function (e) { ZZLog(e); } }) } //提交 function commit() { $('.save').bind('click', function () { var province = $('#province').val(); var hotel_name = $('.hotelNameInput').val(); var city = $('#city').val(); var district = $('#district').val(); var address = $('.inputAddress').val(); //var status = $('.status_value').val(); var star_level = $('.star_level').val(); var sum_base_room_type = new Array; if (address == '') { alert('请填写地址!!!'); return; } //判断地区非空 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; // } if ("" == hotel_name) { alert('请输入酒店名字!!!'); } //判断基本状态非空 $('.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_UpdateHotel', hotel_id: hotel_id, hotel_name: hotel_name, area_id: area_id, address: address, //status: status, base_room_type: sum_base_room_type, star_level: star_level, op: 'update' }; 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 { alert('修改成功'); window.location.href = 'hotel_list.html'; } }, error: function (error) { alert('system ajax http error'); ZZLog(error); } }) }) } function getHotelInfo() { var param = { op: '1', type: 'hotel_HotelList', hotel_name: hotel_name, current: 1, page_size: 10 }; $.ajax({ data: param, dataType: 'json', type: 'post', url: base_api, success: function (res_data) { ZZLog(res_data); if (res_data['code'] != "0") { alert(res_data['info']) } showMainHTML(res_data) }, error: function (error) { alert('system ajax http error'); ZZLog(error); } }) } function showMainHTML(data) { var replace_main = data['hotel_list'][0]; $('.hotelNameInput').val(replace_main['hotel_name']); $('.inputAddress').val(replace_main['hotel_address']); //$('.status_value').val(replace_main['hotel_status']); var param = { op: 'show', hotel_name: $('.hotelNameInput').val(), hotel_id: getPar('hotel_id'), address: $('.inputAddress').val(), //status: $('.status_value').val(), star_level: $('.star_level').val(), type: 'hotel_UpdateHotel' }; ZZLog(param); $.ajax({ data: param, type: 'post', dataType: 'json', url: base_api, success: function (res_data) { ZZLog(res_data); $('#province').val(res_data['area']['province']); province1 = res_data['area']['province']; //替换市 var sumHTML1 = ''; for (var i = 0; i < res_data['city'].length; i++) { var HTML = ''; HTML = HTML.replace('0', res_data['city'][i]['area_id']); HTML = HTML.replace('选择市', res_data['city'][i]['area_name']); sumHTML1 += HTML } $('#city').html(sumHTML1); $('#city').val(res_data['area']['city']); if (res_data['area']['city']) { $('#city').val(res_data['area']['city']); } city1 = res_data['area']['city']; //替换区 if (res_data['town'].length<='0') { $('#district').hide(); }else { $('#district').show(); var sumHTML2 = ''; for (var i = 0; i < res_data['town'].length; i++) { var HTML = ''; HTML = HTML.replace('0', res_data['town'][i]['area_id']); HTML = HTML.replace('选择区', res_data['town'][i]['area_name']); sumHTML2 += HTML } $('#district').html(sumHTML2); if (res_data['area']['town']) { $('#district').val(res_data['area']['town']); } } //换星级 if (res_data['star_level'] != null) { $('.star_level').val(res_data['star_level']); } else { $('.star_level').val(31); } district1 = res_data['area']['town']; //替换基本房型 if (res_data['room_type_all'][0] === null) { } else { for (var i = 0; i < res_data['room_type_all'].length; i++) { var dict = res_data['room_type_all']; var HTML = inputBase; HTML = HTML.replace('display:none!important;', ''); HTML = HTML.replace('[disabled]', 'disabled="true"'); HTML = HTML.replace('inputBase_temp', 'inputBase'); HTML = HTML.replace('value=""', 'value="' + dict[i] + '"'); //HTML = HTML.replace('删除', ''); $('#roomTypeShow').append(HTML); } } }, error: function (error) { ZZLog(error); alert('Ajax错误'); } }) }