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.
 
 
 
 

308 lines
9.1 KiB

  1. var httpData;
  2. var bakData;
  3. if (window.ActiveXObject) {
  4. var myreq = new ActiveXObject("Microsoft.XMLHTTP");
  5. } else {
  6. var myreq = new XMLHttpRequest();
  7. }
  8. var id = '';
  9. var run_id = '';
  10. var tableText = '';
  11. var numText = '';
  12. window.onload = function() {
  13. id = getPar("id");
  14. run_id = getPar("run_id");
  15. tableText = document.getElementById("tableInfo").innerHTML;
  16. numText = document.getElementById("number_select").innerHTML;
  17. if (id) {
  18. var tnowtime = getDateTime(4);
  19. //var myURL = "./test_html/create.html?tt=" + tnowtime+"&id"+id;
  20. var myURL = "./st-xm/Api/createOrderContrill.php?method=getTicketInfo&tt=" + tnowtime + "&user_id=" + id + "&run_id=" + run_id;
  21. method(myURL);
  22. } else {}
  23. }
  24. function method(myURL) {
  25. $.getJSON(myURL,function(res_data){
  26. httpData=res_data;
  27. console.log(myURL);
  28. console.log(httpData);
  29. bakData = httpData;
  30. var code = httpData.code;
  31. if (code == '0') {
  32. document.getElementById("line").innerText = httpData.line;
  33. //出发下拉框
  34. var startArea = document.getElementById("startArea");
  35. var newHtml = '';
  36. for (var i = 0; i < httpData.stratArea.length; i++) {
  37. var source = startArea.innerHTML;
  38. if (i != 0) {
  39. source = source.replace('selected="selected"', '');
  40. }
  41. source = source.replace('0', i);
  42. source = source.replace('startArea', httpData.stratArea[i].area + "(" + httpData.stratArea[i].start_time + ")");
  43. newHtml += source;
  44. }
  45. startArea.innerHTML = newHtml;
  46. //到达下拉框
  47. var endArea = document.getElementById("endArea");
  48. newHtml = '';
  49. for (var i = 0; i < httpData.endArea.length; i++) {
  50. var source = endArea.innerHTML;
  51. if (i != 0) {
  52. source = source.replace('selected="selected"', '');
  53. }
  54. source = source.replace('0', i);
  55. source = source.replace('endArea', httpData.endArea[i].area + "(" + httpData.endArea[i].start_time + ")");
  56. newHtml += source;
  57. }
  58. endArea.innerHTML = newHtml;
  59. //表格
  60. tableInfo = document.getElementById("tableInfo");
  61. newHtml = ""
  62. for (var i = 0; i < httpData.tickets.length; i++) {
  63. var source = tableText;
  64. source = source.replace('座位', httpData.tickets[i].seat);
  65. source = source.replace('人群', httpData.tickets[i].crowd);
  66. source = source.replace('价格', httpData.tickets[i].price);
  67. //source = source.replace('库存', httpData.tickets[i].stock);
  68. httpData.tickets[i].stock = 5;
  69. source = source.replace('number_select', "ticket_" + httpData.tickets[i].id);
  70. if (httpData.tickets[i].stock > 0) {
  71. var s = numText;
  72. s = s.replace('default', 0);
  73. s = s.replace('num', 0);
  74. for (var j = 0; j < httpData.tickets[i].stock; j++) {
  75. var bak = numText;
  76. bak = bak.replace('selected="selected"', '');
  77. bak = bak.replace('default', j + 1);
  78. bak = bak.replace('num', j + 1);
  79. s = s + bak;
  80. }
  81. if (s) {
  82. source = source.replace(numText, s);
  83. }
  84. } else {
  85. source = source.replace(numText, '');
  86. }
  87. newHtml += source;
  88. }
  89. tableInfo.innerHTML = newHtml;
  90. //订单来源下拉框
  91. var orderSource = document.getElementById("orderSource");
  92. $.getJSON('./st-xm/Api/createOrderContrill.php?method=orderChannel',function(res_data){
  93. var HTML='<option value="-2" selected="selected" style="font-size: 12px;">请选择</option>';
  94. for (var i = 0,m=res_data.orderSource.length;i<m;i++) {
  95. var source = '<option value="'+res_data.orderSource[i].org_id+'" style="font-size: 12px;">'+res_data.orderSource[i].soure+'</option>';
  96. HTML+=source;
  97. }
  98. orderSource.innerHTML=HTML;
  99. });
  100. } else {
  101. alert(httpData.info);
  102. return;
  103. }
  104. });
  105. }
  106. function getPar(par) {
  107. //获取当前URL
  108. var local_url = document.location.href;
  109. local_url = decodeURI(local_url);
  110. //获取要取得的get参数位置
  111. var get = local_url.indexOf(par + "=");
  112. if (get == -1) {
  113. return false;
  114. }
  115. //截取字符串
  116. var get_par = local_url.slice(par.length + get + 1);
  117. //判断截取后的字符串是否还有其他get参数
  118. var nextPar = get_par.indexOf("&");
  119. if (nextPar != -1) {
  120. get_par = get_par.slice(0, nextPar);
  121. }
  122. return get_par;
  123. }
  124. function getDateTime(nTypeFlag) {
  125. var tNowTime = new Date();
  126. var myYear = ';' + tNowTime.getFullYear() + ';';
  127. var myMonth = ';' + (tNowTime.getMonth() + 1 - 0) + ';';
  128. var myDay = ';' + tNowTime.getDate() + ';';
  129. var myHour = ';' + tNowTime.getHours() + ';';
  130. var myMinu = ';' + tNowTime.getMinutes() + ';';
  131. var mySecond = ';' + tNowTime.getSeconds() + ';';
  132. if (myMonth.length < 4) myMonth = '0' + myMonth;
  133. if (myDay.length < 4) myDay = '0' + myDay;
  134. if (myHour.length < 4) myHour = '0' + myHour;
  135. if (myMinu.length < 4) myMinu = '0' + myMinu;
  136. if (mySecond.length < 4) mySecond = '0' + mySecond;
  137. var cNewTimeStr;
  138. //alert(tNowTime);
  139. switch (nTypeFlag + 1 - 1) {
  140. case 0:
  141. cNewTimeStr = myYear + '-' + myMonth + '-' + myDay;
  142. break;
  143. case 1:
  144. cNewTimeStr = myYear + myMonth + myDay;
  145. break;
  146. case 2:
  147. cNewTimeStr = myHour + ':' + myMinu + ':' + mySecond;
  148. break;
  149. case 3:
  150. cNewTimeStr = myHour + myMinu + mySecond;
  151. break;
  152. case 4:
  153. cNewTimeStr = myYear + myMonth + myDay + myHour + myMinu + mySecond;
  154. break;
  155. case 5:
  156. cNewTimeStr = myYear + '年' + myMonth + '月' + myDay + '日';
  157. break;
  158. case 6:
  159. cNewTimeStr = myYear;
  160. break;
  161. case 7:
  162. cNewTimeStr = myYear + '-' + myMonth;
  163. break;
  164. default:
  165. cNewTimeStr = myYear + '-' + myMonth + '-' + myDay + ' ' + myHour + ':' + myMinu + ':' + mySecond;
  166. break;
  167. }
  168. cNewTimeStr = cNewTimeStr.replace(/;/g, "");
  169. return cNewTimeStr;
  170. }
  171. $(document).ready(function() {
  172. var username = false;
  173. $("#username").on("blur", function() {
  174. if (/^[\u4e00-\u9fa5\w\s]+$/.test(this.value)) {
  175. $("#nameinfo").html("");
  176. username = true;
  177. } else {
  178. $("#nameinfo").html("*请输入正确的用户名");
  179. username = false;
  180. }
  181. });
  182. var usernum = false;
  183. $("#usernum").on("blur", function() {
  184. if (/^1[\d]{10}$/.test(this.value)) {
  185. $("#numinfo").html("");
  186. usernum = true;
  187. } else {
  188. $("#numinfo").html("*请输入正确的手机号码");
  189. usernum = false;
  190. }
  191. })
  192. var userid = false;
  193. $("#userid").on("blur", function() {
  194. if (/^[\d]{17}[xX0-9]$/.test(this.value)) {
  195. $("#idinfo").html("");
  196. userid = true;
  197. } else {
  198. $("#idinfo").html("*请输入正确的身份证号码");
  199. userid = false;
  200. }
  201. })
  202. var channelNum=false;
  203. $('#channelNum').on("blur",function(){
  204. var ch_num=$('#channelNum').val();
  205. if(ch_num.trim().length>0){
  206. $("#channel_num_info").html
  207. channelNum=true;
  208. }else{
  209. $("#channel_num_info").html("*请输入正确的渠道订单号");
  210. channelNum=false;
  211. }
  212. })
  213. $("#usersubmit").on("click", function() {
  214. if (username && usernum && userid && channelNum) {
  215. if($('#orderSource').val()=="-2"){
  216. $('#order_source').html('*请选择订单渠道');
  217. return;
  218. }
  219. var userName = document.getElementById("username").value;
  220. var userNum = document.getElementById("usernum").value;
  221. var userId = document.getElementById("userid").value;
  222. //alert(userName+"-"+userNum+"-"+userId);
  223. var start = parseInt(document.getElementById("startArea").value);
  224. var stratArea = bakData.stratArea[start].area;
  225. var stratTime = bakData.stratArea[start].start_time;
  226. var end = parseInt(document.getElementById("endArea").value);
  227. var endArea = bakData.endArea[end].area;
  228. var endTime = bakData.endArea[end].start_time;
  229. //订单渠道
  230. //...
  231. var order_from_org_id=$('#orderSource').val();
  232. var outside_order_id=$('#channelNum').val();
  233. var ticketText = '';
  234. for (var i = 0; i < bakData.tickets.length; i++) {
  235. var num = parseInt($("#ticket_" + bakData.tickets[i].id).val());
  236. if (num > 0) {
  237. if (ticketText) {
  238. var s = "{m" + bakData.tickets[i].prod_id + "p" + num + "|r" + run_id + "}";
  239. ticketText += s;
  240. } else {
  241. var s = "{m" + bakData.tickets[i].prod_id + "p" + num + "|r" + run_id + "}";
  242. ticketText += s;
  243. }
  244. }
  245. }
  246. var para_customer_info = "," + userName + ",1," + userNum + ",150," + userId + ",,,,";
  247. var myURL = "./st-xm/Api/add_new_order.php?prod=" + ticketText + "&customer={" + para_customer_info + "}&order_from_org_id="+order_from_org_id+"&outside_order_id="+outside_order_id;
  248. if (ticketText) {
  249. $.getJSON(myURL, function(res_data) {
  250. console.log(myURL);
  251. console.log(res_data);
  252. if (res_data["errcode"] != 0) {
  253. alert(res_data["errinfo"]);
  254. return;
  255. } else {
  256. var listURL = "./order_list.html";
  257. // 跳转前将URL编码
  258. listURL = encodeURI(listURL);
  259. window.location.href = listURL;
  260. var listURL = "./order_list.html";
  261. // 跳转前将URL编码
  262. listURL = encodeURI(listURL);
  263. window.location.href = listURL;
  264. }
  265. });
  266. } else {
  267. alert("请选择票种");
  268. return;
  269. }
  270. } else {
  271. if (username == false) {
  272. $("#usernum").blur();
  273. $("#userid").blur();
  274. $("#username").blur();
  275. $("#username").focus();
  276. } else if (usernum == false) {
  277. $("#usernum").blur();
  278. $("#userid").blur();
  279. $("#username").blur();
  280. $("#usernum").focus();
  281. } else if (userid == false) {
  282. $("#usernum").blur();
  283. $("#userid").blur();
  284. $("#username").blur();
  285. $("#userid").focus();
  286. } else {}
  287. }
  288. })
  289. })