Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 
 

372 рядки
13 KiB

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