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.

modify_hotel_info.js 12 KiB

3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. /**
  2. * Created by luocj on 2016/11/1.
  3. */
  4. var provinceHTML = '';
  5. var cityHTML = '';
  6. var districtHTML = '';
  7. var inputBase = $('.inputBase_temp').prop('outerHTML');
  8. var hotel_name = '';
  9. var user_id = '';
  10. var province1 = '';
  11. var city1 = '';
  12. var district1 = '';
  13. $(document).ready(function () {
  14. hotel_name = getPar('hotel_name');
  15. hotel_id = getPar('hotel_id');
  16. chooseProvince();
  17. chooseCity();
  18. chooseDistrict();
  19. commit();
  20. addBaseRoomType();
  21. getHotelInfo()
  22. });
  23. //选择省
  24. function chooseProvince() {
  25. provinceHTML = $('#province').html();
  26. cityHTML = $('#city').html();
  27. var apiurl = base_api + "?type=hotel_AddHotelProduct&op=provinceCity &area_id=";
  28. ZZLog(apiurl);
  29. $.getJSON(apiurl, function (res_data) {
  30. ZZLog(res_data);
  31. if (res_data['code'] != "0") {
  32. alert(res_data['info']);
  33. } else {
  34. //地区
  35. var area_list = res_data['area_list'];
  36. var areaHTML = '<option value="0" style="font-size:12px;">选择省</option>';
  37. for (var i = 0, m = area_list.length; i < m; i++) {
  38. var tempDict = area_list[i];
  39. var tempHTML = provinceHTML;
  40. tempHTML = tempHTML.replace('选择省', tempDict['area_name']);
  41. tempHTML = tempHTML.replace('0', tempDict['area_id']);
  42. areaHTML += tempHTML;
  43. }
  44. if (areaHTML) {
  45. $('#province').html(areaHTML);
  46. $('#province')[0].selectedIndex = 0;
  47. }
  48. }
  49. })
  50. }
  51. //选择市
  52. function chooseCity() {
  53. districtHTML = $('#district').html();
  54. $('#province').bind('change', function () {
  55. var area_id = $(this).val();
  56. if (area_id == "0" || area_id == "") {
  57. $('#city').html(cityHTML);
  58. return;
  59. }
  60. var url = base_api + "?type=hotel_AddHotelProduct&op=provinceCity&area_id=" + area_id;
  61. ZZLog(url);
  62. $.getJSON(url, function (res_data) {
  63. ZZLog(res_data);
  64. if (res_data['code'] != "0") {
  65. alert(res_data['info']);
  66. } else {
  67. //地区
  68. var area_list = res_data['area_list'];
  69. var areaHTML = '<option value="0" style="font-size: 12px;">选择市</option>';
  70. for (var i = 0, m = area_list.length; i < m; i++) {
  71. var tempDict = area_list[i];
  72. var tempHTML = cityHTML;
  73. tempHTML = tempHTML.replace('选择市', tempDict['area_name']);
  74. tempHTML = tempHTML.replace('0', tempDict['area_id']);
  75. areaHTML += tempHTML;
  76. }
  77. if (areaHTML) {
  78. $('#city').html(areaHTML);
  79. $('#city')[0].selectedIndex = 0;
  80. }
  81. }
  82. })
  83. });
  84. }
  85. //选择区
  86. function chooseDistrict() {
  87. $('#city').bind('change', function () {
  88. var area_id = $(this).val();
  89. if (area_id == "0" || area_id == "") {
  90. $('#district').html(districtHTML);
  91. return;
  92. }
  93. var url = base_api + "?type=hotel_AddHotelProduct&op=provinceCity&area_id=" + area_id;
  94. ZZLog(url);
  95. $.getJSON(url, function (res_data) {
  96. ZZLog(res_data);
  97. if (res_data['code'] != "0") {
  98. alert(res_data['info']);
  99. } else {
  100. //地区
  101. var area_list = res_data['area_list'];
  102. var areaHTML = '<option value="0" style="font-size: 12px;">选择区</option>';
  103. for (var i = 0, m = area_list.length; i < m; i++) {
  104. var tempDict = area_list[i];
  105. var tempHTML = districtHTML;
  106. tempHTML = tempHTML.replace('选择区', tempDict['area_name']);
  107. tempHTML = tempHTML.replace('0', tempDict['area_id']);
  108. areaHTML += tempHTML;
  109. }
  110. if (areaHTML) {
  111. $('#district').html(areaHTML);
  112. $('#district')[0].selectedIndex = 0;
  113. }
  114. if (area_list==''){
  115. $('#district').hide();
  116. }else {
  117. $('#district').show();
  118. }
  119. }
  120. })
  121. });
  122. }
  123. //添加基础房型
  124. function addBaseRoomType() {
  125. $('#add').bind('click', function () {
  126. var HTML = inputBase;
  127. HTML = HTML.replace('display:none!important;', '');
  128. HTML = HTML.replace('inputBase_temp', 'inputBase');
  129. $('#roomTypeShow').append(HTML);
  130. })
  131. }
  132. //删除
  133. function deleteBRT(obj) {
  134. var param = {
  135. type: 'hotel_AddHotelProduct',
  136. op: 'deletebaseroom',
  137. hotel_id: hotel_id,
  138. baseroomname: $(obj).closest('div').children('.base_room_type').val()
  139. }
  140. ZZLog(param);
  141. $.ajax({
  142. url: base_api,
  143. data: param,
  144. dataType: 'json',
  145. type: 'post',
  146. success: function (res_data) {
  147. ZZLog(res_data);
  148. if (res_data['mes'] == '0') {
  149. alert('有库存,不能删除');
  150. } else if (res_data['mes'] == '1') {
  151. $(obj).closest('div').remove();
  152. }
  153. },
  154. error: function (e) {
  155. ZZLog(e);
  156. }
  157. })
  158. }
  159. //提交
  160. function commit() {
  161. $('.save').bind('click', function () {
  162. var province = $('#province').val();
  163. var hotel_name = $('.hotelNameInput').val();
  164. var city = $('#city').val();
  165. var district = $('#district').val();
  166. var address = $('.inputAddress').val();
  167. //var status = $('.status_value').val();
  168. var star_level = $('.star_level').val();
  169. var sum_base_room_type = new Array;
  170. if (address == '') {
  171. alert('请填写地址!!!');
  172. return;
  173. }
  174. //判断地区非空
  175. var area_id = '';
  176. if (district == '0' && city != '0') {
  177. area_id = city;
  178. } else if (district == '0' && city == '0') {
  179. area_id = province;
  180. } else if (district != '0') {
  181. area_id = district
  182. } else {
  183. area_id = '';
  184. }
  185. if (area_id == '') {
  186. alert('请选择地区!!!')
  187. return false;
  188. }
  189. // //判断状态非空
  190. // if ("-1" == status) {
  191. // alert('请选择状态!!!');
  192. // return false;
  193. // }
  194. if ("" == hotel_name) {
  195. alert('请输入酒店名字!!!');
  196. }
  197. //判断基本状态非空
  198. $('.inputBase').each(function (index, dom) {
  199. var base_room_type = $(this).find(".base_room_type").val();
  200. if (base_room_type != "") {
  201. sum_base_room_type.push(base_room_type);
  202. } else {
  203. $(this).find(".base_room_type").focus();
  204. return false;
  205. }
  206. });
  207. if (sum_base_room_type.length < $('.inputBase').length) {
  208. alert('请完整填写!!!');
  209. return false;
  210. }
  211. // sum_base_room_type = sum_base_room_type.join(",");
  212. var param = {
  213. type: 'hotel_UpdateHotel',
  214. hotel_id: hotel_id,
  215. hotel_name: hotel_name,
  216. area_id: area_id,
  217. address: address,
  218. //status: status,
  219. base_room_type: sum_base_room_type,
  220. star_level: star_level,
  221. op: 'update'
  222. };
  223. ZZLog(param);
  224. $.ajax({
  225. data: param,
  226. type: 'post',
  227. dataType: 'json',
  228. url: base_api,
  229. success: function (res_data) {
  230. if (res_data['code'] != 0) {
  231. alert(res_data['info'])
  232. } else {
  233. alert('修改成功');
  234. window.location.href = 'hotel_list.html';
  235. }
  236. },
  237. error: function (error) {
  238. alert('system ajax http error');
  239. ZZLog(error);
  240. }
  241. })
  242. })
  243. }
  244. function getHotelInfo() {
  245. var param = {
  246. op: '1',
  247. type: 'hotel_HotelList',
  248. hotel_name: hotel_name,
  249. current: 1,
  250. page_size: 10
  251. };
  252. $.ajax({
  253. data: param,
  254. dataType: 'json',
  255. type: 'post',
  256. url: base_api,
  257. success: function (res_data) {
  258. ZZLog(res_data);
  259. if (res_data['code'] != "0") {
  260. alert(res_data['info'])
  261. }
  262. showMainHTML(res_data)
  263. },
  264. error: function (error) {
  265. alert('system ajax http error');
  266. ZZLog(error);
  267. }
  268. })
  269. }
  270. function showMainHTML(data) {
  271. var replace_main = data['hotel_list'][0];
  272. $('.hotelNameInput').val(replace_main['hotel_name']);
  273. $('.inputAddress').val(replace_main['hotel_address']);
  274. //$('.status_value').val(replace_main['hotel_status']);
  275. var param = {
  276. op: 'show',
  277. hotel_name: $('.hotelNameInput').val(),
  278. hotel_id: getPar('hotel_id'),
  279. address: $('.inputAddress').val(),
  280. //status: $('.status_value').val(),
  281. star_level: $('.star_level').val(),
  282. type: 'hotel_UpdateHotel'
  283. };
  284. ZZLog(param);
  285. $.ajax({
  286. data: param,
  287. type: 'post',
  288. dataType: 'json',
  289. url: base_api,
  290. success: function (res_data) {
  291. ZZLog(res_data);
  292. $('#province').val(res_data['area']['province']);
  293. province1 = res_data['area']['province'];
  294. //替换市
  295. var sumHTML1 = '<option value="0" selected="selected" style="font-size: 12px;">选择市</option>';
  296. for (var i = 0; i < res_data['city'].length; i++) {
  297. var HTML = '<option value="0" style="font-size: 12px;">选择市</option>';
  298. HTML = HTML.replace('0', res_data['city'][i]['area_id']);
  299. HTML = HTML.replace('选择市', res_data['city'][i]['area_name']);
  300. sumHTML1 += HTML
  301. }
  302. $('#city').html(sumHTML1);
  303. $('#city').val(res_data['area']['city']);
  304. if (res_data['area']['city']) {
  305. $('#city').val(res_data['area']['city']);
  306. }
  307. city1 = res_data['area']['city'];
  308. //替换区
  309. if (res_data['town'].length<='0') {
  310. $('#district').hide();
  311. }else {
  312. $('#district').show();
  313. var sumHTML2 = '<option value="0" selected="selected" style="font-size: 12px;">选择区</option>';
  314. for (var i = 0; i < res_data['town'].length; i++) {
  315. var HTML = '<option value="0" style="font-size: 12px;">选择区</option>';
  316. HTML = HTML.replace('0', res_data['town'][i]['area_id']);
  317. HTML = HTML.replace('选择区', res_data['town'][i]['area_name']);
  318. sumHTML2 += HTML
  319. }
  320. $('#district').html(sumHTML2);
  321. if (res_data['area']['town']) {
  322. $('#district').val(res_data['area']['town']);
  323. }
  324. }
  325. //换星级
  326. if (res_data['star_level'] != null) {
  327. $('.star_level').val(res_data['star_level']);
  328. } else {
  329. $('.star_level').val(31);
  330. }
  331. district1 = res_data['area']['town'];
  332. //替换基本房型
  333. if (res_data['room_type_all'][0] === null) {
  334. } else {
  335. for (var i = 0; i < res_data['room_type_all'].length; i++) {
  336. var dict = res_data['room_type_all'];
  337. var HTML = inputBase;
  338. HTML = HTML.replace('display:none!important;', '');
  339. HTML = HTML.replace('[disabled]', 'disabled="true"');
  340. HTML = HTML.replace('inputBase_temp', 'inputBase');
  341. HTML = HTML.replace('value=""', 'value="' + dict[i] + '"');
  342. //HTML = HTML.replace('<span class="deleteBRT" onclick="deleteBRT(this)" style="cursor: pointer">删除</span>', '');
  343. $('#roomTypeShow').append(HTML);
  344. }
  345. }
  346. },
  347. error: function (error) {
  348. ZZLog(error);
  349. alert('Ajax错误');
  350. }
  351. })
  352. }