You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

add_new_hotel.js 7.0 KiB

3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. /**
  2. * Created by luocj on 2016/10/28.
  3. */
  4. var provinceHTML = '';
  5. var cityHTML = '';
  6. var inputBase = $('.inputBase_temp').prop('outerHTML');
  7. var districtHTML = '';
  8. $(document).ready(function () {
  9. chooseProvince();
  10. chooseCity();
  11. chooseDistrict()
  12. commit();
  13. addBaseRoomType();
  14. });
  15. //选择省
  16. function chooseProvince() {
  17. provinceHTML = $('#province').html();
  18. cityHTML = $('#city').html();
  19. var apiurl = base_api + "?type=hotel_AddHotelProduct&op=provinceCity &area_id=";
  20. ZZLog(apiurl);
  21. $.getJSON(apiurl, function (res_data) {
  22. ZZLog(res_data);
  23. if (res_data['code'] != "0") {
  24. alert(res_data['info']);
  25. } else {
  26. //地区
  27. var area_list = res_data['area_list'];
  28. var areaHTML = '<option value="0" style="font-size:12px;">选择省</option>';
  29. for (var i = 0, m = area_list.length; i < m; i++) {
  30. var tempDict = area_list[i];
  31. var tempHTML = provinceHTML;
  32. tempHTML = tempHTML.replace('选择省', tempDict['area_name']);
  33. tempHTML = tempHTML.replace('0', tempDict['area_id']);
  34. areaHTML += tempHTML;
  35. }
  36. if (areaHTML) {
  37. $('#province').html(areaHTML);
  38. $('#province')[0].selectedIndex = 0;
  39. }
  40. }
  41. })
  42. }
  43. //选择市
  44. function chooseCity() {
  45. districtHTML = $('#district').html();
  46. $('#province').bind('change', function () {
  47. var area_id = $(this).val();
  48. if (area_id == "0" || area_id == "") {
  49. $('#city').html(cityHTML);
  50. return;
  51. }
  52. var url = base_api + "?type=hotel_AddHotelProduct&op=provinceCity&area_id=" + area_id;
  53. ZZLog(url);
  54. $.getJSON(url, function (res_data) {
  55. ZZLog(res_data);
  56. if (res_data['code'] != "0") {
  57. alert(res_data['info']);
  58. } else {
  59. //地区
  60. var area_list = res_data['area_list'];
  61. var areaHTML = '<option value="0" style="font-size: 12px;">选择市</option>';
  62. for (var i = 0, m = area_list.length; i < m; i++) {
  63. var tempDict = area_list[i];
  64. var tempHTML = cityHTML;
  65. tempHTML = tempHTML.replace('选择市', tempDict['area_name']);
  66. tempHTML = tempHTML.replace('0', tempDict['area_id']);
  67. areaHTML += tempHTML;
  68. }
  69. if (areaHTML) {
  70. $('#city').html(areaHTML);
  71. $('#city')[0].selectedIndex = 0;
  72. }
  73. }
  74. })
  75. });
  76. }
  77. //选择区
  78. function chooseDistrict() {
  79. $('#city').bind('change', function () {
  80. var area_id = $(this).val();
  81. if (area_id == "0" || area_id == "") {
  82. $('#district').html(districtHTML);
  83. return;
  84. }
  85. var url = base_api + "?type=hotel_AddHotelProduct&op=provinceCity&area_id=" + area_id;
  86. ZZLog(url);
  87. $.getJSON(url, function (res_data) {
  88. ZZLog(res_data);
  89. if (res_data['code'] != "0") {
  90. alert(res_data['info']);
  91. } else {
  92. //地区
  93. var area_list = res_data['area_list'];
  94. var areaHTML = '<option value="0" style="font-size: 12px;">选择区</option>';
  95. for (var i = 0, m = area_list.length; i < m; i++) {
  96. var tempDict = area_list[i];
  97. var tempHTML = districtHTML;
  98. tempHTML = tempHTML.replace('选择区', tempDict['area_name']);
  99. tempHTML = tempHTML.replace('0', tempDict['area_id']);
  100. areaHTML += tempHTML;
  101. }
  102. if (areaHTML) {
  103. $('#district').html(areaHTML);
  104. $('#district')[0].selectedIndex = 0;
  105. }
  106. if (area_list==''){
  107. $('#district').hide();
  108. }else {
  109. $('#district').show();
  110. }
  111. }
  112. })
  113. });
  114. }
  115. //添加基础房型
  116. function addBaseRoomType() {
  117. $('#add').bind('click', function () {
  118. var HTML = inputBase;
  119. HTML = HTML.replace('display:none!important;', '');
  120. HTML = HTML.replace('inputBase_temp', 'inputBase');
  121. $('#roomTypeShow').append(HTML);
  122. })
  123. }
  124. //删除
  125. function deleteBRT(obj) {
  126. $(obj).closest('div').remove();
  127. }
  128. //提交
  129. function commit() {
  130. $('.save').bind('click', function () {
  131. var hotel_name = $('.hotelNameInput').val();
  132. var province = $('#province').val();
  133. var city = $('#city').val();
  134. var district = $('#district').val();
  135. var address = $('.inputAddress').val();
  136. var status = $('.status_value').val();
  137. var sum_base_room_type = new Array;
  138. var star_level = $('.star_level').val();
  139. //判断非空
  140. //酒店名称判断非空
  141. if ("" == hotel_name) {
  142. alert('请完整填写!!!')
  143. $('.hotelNameInput').focus();
  144. return false;
  145. }
  146. //判断地区非空
  147. var area_id ='';
  148. if (district=='0'&&city!=0){
  149. area_id = city;
  150. }else if (district=='0'&&city=='0'){
  151. area_id= province;
  152. }else if (district !='0'){
  153. area_id = district
  154. }else {
  155. area_id = '';
  156. }
  157. if (area_id ==''){
  158. alert('请选择地区!!!')
  159. return false;
  160. }
  161. // //判断状态非空
  162. // if ("-1" == status) {
  163. // alert('请选择状态!!!');
  164. // return false;
  165. // }
  166. //判断基本状态非空
  167. $('.inputBase').each(function (index, dom) {
  168. var base_room_type = $(this).find(".base_room_type").val();
  169. if (base_room_type != "") {
  170. sum_base_room_type.push(base_room_type);
  171. } else {
  172. $(this).find(".base_room_type").focus();
  173. return false;
  174. }
  175. });
  176. if (sum_base_room_type.length < $('.inputBase').length) {
  177. alert('请完整填写!!!');
  178. return false;
  179. }
  180. // sum_base_room_type = sum_base_room_type.join(",");
  181. var param = {
  182. type: 'hotel_Addhotel',
  183. hotel_name: hotel_name,
  184. province: province,
  185. area_id: area_id,
  186. address: address,
  187. //status: status,
  188. base_room_type: sum_base_room_type,
  189. star_level:star_level
  190. };
  191. ZZLog(param);
  192. $.ajax({
  193. data: param,
  194. type: 'post',
  195. dataType: 'json',
  196. url: base_api,
  197. success: function (res_data) {
  198. if (res_data['code'] != 0) {
  199. alert(res_data['info'])
  200. } else {
  201. window.location.href='hotel_list.html';
  202. }
  203. },
  204. error: function (error) {
  205. alert('system ajax http error');
  206. ZZLog(error);
  207. }
  208. })
  209. })
  210. }