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.
 
 
 
 
 
 

395 lines
12 KiB

  1. var pro_id = getPar("pro_id");
  2. var date = getPar("go_date");
  3. var p_num = getPar("peo_no");
  4. var json_data = {
  5. //缓存数据
  6. pro_id: pro_id, //产品id
  7. date: date, //出行日期
  8. p_num: p_num, //出行人数
  9. style_type: 1, //显示状态
  10. go_person: '', //出行人信息
  11. go_person_num: 0, //出行人数量
  12. contacts_name: '', //联系人姓名
  13. m_phone: '', //联系人电话
  14. price: 0,
  15. };
  16. window.onload = function() {
  17. if(getStorJson("trave_around_fill_order") == null) {
  18. //第一次加载
  19. json_data.pro_id = pro_id; //产品id
  20. json_data.p_num = p_num;
  21. json_data.date = date;
  22. json_data.style_type = 1;
  23. json_data.go_person = '';
  24. json_data.go_person_num = 0;
  25. json_data.contacts_name = '';
  26. json_data.m_phone = '';
  27. var param = {
  28. pro_id: json_data.pro_id, //产品id
  29. date: json_data.date,
  30. p_num: json_data.p_num,
  31. }
  32. setStorJson('trave_around_fill_order', json_data); //初始化缓存
  33. baseInfo(param);
  34. $("#total_person").text("共" + json_data.p_num + "人");
  35. $("#go_person_ul").hide();
  36. $("#continue_add").hide();
  37. $("#show_add_go_people").show();
  38. $("#how_many_perple_add").text("需添" + Math.ceil(json_data.p_num / 5) + "人");
  39. } else {
  40. //不是第一次加载
  41. var temp_data = getStorJson('trave_around_fill_order');
  42. var temp_pro_id = getPar("pro_id");
  43. var temp_date = getPar("go_date");
  44. var temp_p_num = getPar("peo_no");
  45. temp_data.pro_id = temp_pro_id;
  46. temp_data.date = temp_date;
  47. temp_data.p_num = temp_p_num;
  48. setStorJson("trave_around_fill_order", temp_data);
  49. var param = {
  50. pro_id: temp_data.pro_id, //产品id
  51. date: temp_data.date,
  52. p_num: temp_data.p_num,
  53. }
  54. baseInfo(param);
  55. if(temp_data.style_type == 1 && temp_data.go_person_num == 0) {
  56. //没有选择出行人
  57. $("#go_person_ul").hide();
  58. $("#continue_add").hide();
  59. $("#show_add_go_people").show();
  60. $("#how_many_perple_add").text("需添" + Math.ceil(temp_data.p_num / 5) + "人");
  61. $("#total_person").text("共" + temp_data.p_num + "人");
  62. } else {
  63. //选择了出行人
  64. show_go_people();
  65. }
  66. $("#price").text(temp_data.price);
  67. $("#contacts_name_input").val(temp_data.contacts_name);
  68. $("#m_phone_input").val(temp_data.m_phone);
  69. }
  70. }
  71. function base_html(data) {
  72. //显示基础信息
  73. //得到价格
  74. var temp_data = getStorJson("trave_around_fill_order");
  75. temp_data.price = data.price;
  76. setStorJson('trave_around_fill_order', temp_data);
  77. $("#tickdes").text(data.tickdes);
  78. $("#zname").text(data.zname);
  79. $("#price").text(data.price);
  80. $("#start_date").text(data.start_date);
  81. $("#end_date").text(data.end_date);
  82. $("#start_time").text(data.start_time);
  83. $("#start_area").text(data.start_area);
  84. $("#end_area").text(data.end_area);
  85. $("#end_time").text(data.end_time);
  86. $("#loading_html").show();
  87. }
  88. function baseInfo(param) {
  89. //获取基础信息
  90. ZZLog(base_api + "around/getOrder&" + JSON.stringify(param));
  91. $.ajax({
  92. type: "post",
  93. url: base_api + "around/getOrder",
  94. data: param,
  95. dataType: 'json',
  96. success: function(res_data) {
  97. ZZLog(res_data);
  98. if(res_data.flag == true) {
  99. base_html(res_data.data);
  100. } else {
  101. alert(res_data.msg);
  102. }
  103. },
  104. error: function(e) {
  105. ZZLog(e);
  106. }
  107. });
  108. }
  109. function add_new_go_person() {
  110. //添加新的联系人
  111. //扫一下当前状态,保存内存
  112. var temp_data = getStorJson("trave_around_fill_order");
  113. temp_data.contacts_name = $("#contacts_name_input").val();
  114. temp_data.m_phone = $("#m_phone_input").val();
  115. setStorJson('trave_around_fill_order', temp_data);
  116. window.location.href = 'add_travel_person.html'; //添加出行人
  117. }
  118. function show_go_person_tancen(data) {
  119. //分别显示不同弹层弹层
  120. if(data.length == 0) {
  121. //显示去添加出行人的弹层
  122. $("#tancen_main_control").addClass("weui_actionsheet_toggle");
  123. $("#no_go_person").show();
  124. $("#mask").show();
  125. } else {
  126. //显示出行人列表的弹层
  127. $("#tancen_main_control").addClass("weui_actionsheet_toggle");
  128. $("#go_person_list").show();
  129. $("#mask").show();
  130. //加载后台得到的数据
  131. var temp_str = '';
  132. for(var i = 0; i < data.length; i++) {
  133. // temp_str += '<li id="go_person_' + data[i].customer_id + '" onclick="choice_or_cancle_person(this)" go_person_id="' + data[i].customer_id + '" class="ub ui_p_l25 ui_p_r25 ub-ac white_bccolor">' +
  134. // '<img class="tancen_edit" src="images/imgEditDis@2x.png" />' +
  135. // '<div class="tancen_name">' + data[i].customer_name + '</div>' +
  136. // '<div class="ub-f1 tancen_id_num">' + data[i].customer_id_card + '</div>' +
  137. // '<img id="" class="tancen_select" src="images/ic_nor@2x.png" />' +
  138. // '</li>';
  139. temp_str += '<li id="go_person_' + data[i].customer_id + '" go_person_id="' + data[i].customer_id + '" class="ub ub-ac white_bccolor">' +
  140. '<img onclick="edit_person(this)" class="tancen_edit ui_p_l25 ui_p_r10" src="images/imgEditDis@2x.png" />' +
  141. '<div class="ub ub-f1" onclick="choice_or_cancle_person(this)">' +
  142. '<div style="width: 1%;" class="tancen_name ub-f1">' + data[i].customer_name + '</div>' +
  143. '<div style="width: 1%;" class=" tancen_id_num ub-f4">' + data[i].customer_id_card + '</div>' +
  144. '<img id="" class="tancen_select ub-ae ui_p_r25" src="images/ic_nor@2x.png" />' +
  145. '</div>' +
  146. '</li>';
  147. }
  148. $("#ul_tancen").html(temp_str);
  149. var temp_data = getStorJson("trave_around_fill_order");
  150. //判断已经选中的联系人为选中状态
  151. if(temp_data.go_person_num != 0) {
  152. //已经选中了几个联系人
  153. for(var i = 0; i < temp_data.go_person_num; i++) {
  154. $("#go_person_" + temp_data.go_person[i].customer_id).children().eq(1).children().eq(2).attr("src", "images/ic_sel@2x.png"); //标记选中
  155. $("#go_person_" + temp_data.go_person[i].customer_id).addClass("go_person_selected"); //父元素加上标记类
  156. }
  157. } else {
  158. //没有选择联系人
  159. }
  160. }
  161. }
  162. //修改出行人
  163. function edit_person(which_obj) {
  164. var go_person_id = $(which_obj).parent().attr("go_person_id"); //出行人id
  165. var name = $(which_obj).parent().children().eq(1).children().eq(0).text(); //姓名
  166. var idcard = $(which_obj).parent().children().eq(1).children().eq(1).text(); //id
  167. window.location.href = 'change_travel_person.html?go_person_id=' + go_person_id + "&name=" + name + "&idcard=" + idcard; //添加出行人
  168. }
  169. //选择或者取消出行人
  170. function choice_or_cancle_person(which_obj) {
  171. if($(which_obj).children().eq(2).attr("src") == "images/ic_nor@2x.png") {
  172. //没被选中,变成选中
  173. $(which_obj).children().eq(2).attr("src", "images/ic_sel@2x.png")
  174. $(which_obj).parent().addClass("go_person_selected"); //加上选中标记类
  175. } else {
  176. //已经选中,变成没选中
  177. $(which_obj).children().eq(2).attr("src", "images/ic_nor@2x.png")
  178. $(which_obj).parent().removeClass("go_person_selected"); //删除选中标记类
  179. }
  180. }
  181. function cancel_tancen() {
  182. //关掉所有弹层和蒙版
  183. $("#tancen_main_control").removeClass("weui_actionsheet_toggle");
  184. $("#mask").hide();
  185. $("#go_person_list").hide();
  186. $("#no_go_person").hide();
  187. }
  188. function add_go_person_tancen() {
  189. //获取出行人信息
  190. var param = {}
  191. ZZLog(base_api + "order/order/getCustomerList&" + JSON.stringify(param));
  192. $.ajax({
  193. type: "post",
  194. url: base_api + "order/order/getCustomerList",
  195. data: param,
  196. dataType: 'json',
  197. success: function(res_data) {
  198. ZZLog(res_data);
  199. if(res_data.flag == true) {
  200. show_go_person_tancen(res_data.data);
  201. } else {
  202. alert(res_data.msg);
  203. }
  204. },
  205. error: function(e) {
  206. ZZLog(e);
  207. }
  208. });
  209. }
  210. function ensure_go_person() {
  211. //确定按钮
  212. var total_people = $(".go_person_selected").length;
  213. var info_arr = [];
  214. $(".go_person_selected").each(function(index, dom) {
  215. var info_data = {
  216. customer_id: $(this).attr("go_person_id"),
  217. customer_name: $(this).children().eq(1).children().eq(0).text(),
  218. customer_id_card: $(this).children().eq(1).children().eq(1).text(),
  219. }
  220. info_arr.push(info_data);
  221. })
  222. var temp_data = getStorJson("trave_around_fill_order");
  223. temp_data.go_person_num = total_people;
  224. temp_data.go_person = info_arr;
  225. if(total_people > 0) {
  226. temp_data.style_type = 2;
  227. } else {
  228. temp_data.style_type = 1;
  229. }
  230. setStorJson('trave_around_fill_order', temp_data);
  231. if(total_people > 0) {
  232. cancel_tancen();
  233. show_go_people();
  234. } else {
  235. //确认后全部没有勾选
  236. cancel_tancen();
  237. $("#go_person_ul").hide();
  238. $("#continue_add").hide();
  239. $("#show_add_go_people").show();
  240. $("#how_many_perple_add").text("需添" + Math.ceil(json_data.p_num / 5) + "人");
  241. }
  242. }
  243. //显示出行人列表
  244. function show_go_people() {
  245. var temp_data = getStorJson("trave_around_fill_order"); //得到缓存
  246. var temp_str = '';
  247. for(var i = 0; i < temp_data.go_person_num; i++) {
  248. temp_str += '<li class="white_color_bg ">' +
  249. '<div class="ub ui_p_r25 ub-ac ">' +
  250. '<div class="ub ub-f1 ui_p_l25 ui_p_t15 ui_p_b15 people_name ">' + temp_data.go_person[i].customer_name + '</div>' +
  251. '<div class="ub ub-f2 ui_p_t15 ui_p_b15 id_card_css ">' + temp_data.go_person[i].customer_id_card + '</div>' +
  252. '<div go_person_id="' + temp_data.go_person[i].customer_id + '" onclick="remove_go_people(this)" class="ub ub-f1 ui_p_t15 ui_p_b15 text_right ub-pe jian_css ">' +
  253. '<img class="ub img_css " src="images/ic_remove@2x.png " />' +
  254. '</div>' +
  255. '</div>' +
  256. '<div class="ui_m_l25 inner_up_line_color "></div>' +
  257. '</li>';
  258. }
  259. $("#show_add_go_people").hide();
  260. $("#go_person_ul").show();
  261. $("#continue_add").show();
  262. $("#go_person_ul").html(temp_str);
  263. }
  264. //删除出行人信息
  265. function remove_go_people(which_obj) {
  266. var temp_data = getStorJson("trave_around_fill_order"); //得到缓存
  267. var info_arr = [];
  268. for(var i = 0; i < temp_data.go_person_num; i++) {
  269. var info_data = {
  270. customer_id: temp_data.go_person[i].customer_id,
  271. customer_name: temp_data.go_person[i].customer_name,
  272. customer_id_card: temp_data.go_person[i].customer_id_card,
  273. }
  274. if(temp_data.go_person[i].customer_id != $(which_obj).attr("go_person_id")) {
  275. info_arr.push(info_data);
  276. }
  277. }
  278. temp_data.go_person_num--;
  279. temp_data.go_person = info_arr;
  280. setStorJson('trave_around_fill_order', temp_data);
  281. if(temp_data.go_person_num > 0) {
  282. show_go_people();
  283. } else {
  284. $("#go_person_ul").hide();
  285. $("#continue_add").hide();
  286. $("#show_add_go_people").show();
  287. $("#how_many_perple_add").text("需添" + Math.ceil(json_data.p_num / 5) + "人");
  288. }
  289. }
  290. function payBtnDidClicked() {
  291. delay(makorder, 300);
  292. function makorder() {
  293. //支付
  294. var temp_data = getStorJson("trave_around_fill_order");
  295. if(temp_data.go_person_num < Math.ceil(temp_data.p_num / 5) || temp_data.go_person_num > temp_data.p_num) {
  296. if(temp_data.go_person_num < Math.ceil(temp_data.p_num / 5)) {
  297. alert("需添加" + Math.ceil(temp_data.p_num / 5) + "位出行人信息!");
  298. return;
  299. } else {
  300. alert("添加出行人信息过多!");
  301. return;
  302. }
  303. } else {
  304. var temp_name = $("#contacts_name_input").val();
  305. var temp_phone = $("#m_phone_input").val();
  306. if(temp_name == '' || temp_phone == '') {
  307. alert("请填写联系人信息!");
  308. return;
  309. } else {
  310. var phoneRe = /^1[3|4|5|7|8]\d{9}$/;
  311. if(!phoneRe.test(temp_phone)) {
  312. alert('请输入正确的手机号!')
  313. return;
  314. }
  315. temp_data.contacts_name = temp_name;
  316. temp_data.m_phone = temp_phone;
  317. var temp_str = '';
  318. for(var i = 0; i < temp_data.go_person_num; i++) {
  319. if(i == 0) {
  320. temp_str = temp_str + temp_data.go_person[i].customer_id;
  321. } else {
  322. temp_str = temp_str + "," + temp_data.go_person[i].customer_id;
  323. }
  324. }
  325. setStorJson('trave_around_fill_order', temp_data);
  326. var param = {
  327. pro_id: temp_data.pro_id, //产品id
  328. start_date: temp_data.date,
  329. p_num: temp_data.p_num,
  330. customer_name: temp_data.contacts_name,
  331. customer_moble: temp_data.m_phone,
  332. price: $("#price").text(),
  333. remark: temp_str,
  334. };
  335. $("#payBtn").removeAttr('onClick');
  336. $("#loadingToast").show();
  337. $.ajax({
  338. type: "post",
  339. url: base_api + "around/makeOrder",
  340. data: param,
  341. dataType: 'json',
  342. success: function(res_data) {
  343. ZZLog(res_data);
  344. if(res_data.flag == true) {
  345. //成功的回调,删除缓存
  346. clearStorage("trave_around_fill_order");
  347. $("#loadingToast").hide();
  348. $("#payBtn").attr('onClick', 'payBtnDidClicked();');
  349. window.location.href = res_data.url;
  350. } else {
  351. $("#loadingToast").hide();
  352. $("#payBtn").attr('onClick', 'payBtnDidClicked();');
  353. if(data.code != '10001') {
  354. alert(data.msg);
  355. } else {
  356. return;
  357. }
  358. }
  359. },
  360. error: function(e) {
  361. ZZLog(e);
  362. }
  363. });
  364. }
  365. }
  366. }
  367. }
  368. var delay = (function() {
  369. var timer = 0;
  370. return function(callback, time) {
  371. clearTimeout(timer);
  372. timer = setTimeout(callback, time);
  373. };
  374. })()