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.
 
 
 
 

210 lines
7.2 KiB

  1. var lineNameJC = getPar("lineNameJC")
  2. var temp1 = getPar("prod_id");
  3. var line_name = getPar("lineName");
  4. var ind;
  5. var prod_id;
  6. var cus_price;
  7. var prod_price;
  8. var cus_price_id;
  9. var prod_price_id;
  10. var ticket_type;
  11. var end_area_id;
  12. var start_area_id;
  13. window.onload = function() {
  14. var index = '<span>线路名称:</span>'
  15. +'<span>'+lineNameJC+'</span>'
  16. +'<span>'+line_name+'</span>'
  17. $("#lineName").html(index);
  18. $.ajax({
  19. url:'./st-xm/control.php',
  20. type: "post",
  21. data: {type:"linemanager_tickets",id:temp1},
  22. dataType: "json",
  23. success: function (data) {
  24. if(data.code == 0){
  25. console.log(data);
  26. createHtml_list(data.list);
  27. }
  28. },
  29. fail: function (data) {
  30. // 此处放失败后执行的代码
  31. }
  32. });
  33. }
  34. //遍历列表
  35. function createHtml_list(data){
  36. var temp ="";
  37. for (var i = 0; i < data.length; i++){
  38. if(data[i].cus_price==null){
  39. temp += '<tr class="list_info" id="list_info'+i+'">'
  40. + '<td class="list_middle"><p>'+data[i].start_area_name+'</p></td>'
  41. + '<td class="list_middle">'+data[i].end_area_name+'</td>'
  42. + '<td class="list_middle">'+data[i].seat_name+'</td>'
  43. + '<td class="list_middle">'+data[i].ticket_type_name+'</td>'
  44. +'<td class="list_middle"><input class="" value="" placeholder="请填写零售价" style="width: 98px;text-align:right;" id="cus_price'+i+'">&nbsp元</td>'
  45. +'<td class="list_middle"><input class="" value="" placeholder="请填写分销价" style="width: 98px;text-align:right;" id="prod_price'+i+'">&nbsp元</td>'
  46. +'<td class="list_middle"><a><div id="save'+i+'" style="display:inline-block;cursor: pointer;"'
  47. +'start_area_id="'+data[i].start_area_id+'" end_area_id="'+data[i].end_area_id+'" ticket_type="'+data[i].ticket_type+'" prodId="'+data[i].prod_id+'" ind="'+i+'" class="save" >保存</div></a><a><div class="quxiao" style="display:inline-block;margin-left:12px;cursor: pointer;">取消</div></a></td>'
  48. + '</tr>'
  49. }else{
  50. temp += '<tr class="list_info" id="list_info'+i+'">'
  51. + '<td class="list_middle"><p>'+data[i].start_area_name+'</p></td>'
  52. + '<td class="list_middle">'+data[i].end_area_name+'</td>'
  53. + '<td class="list_middle">'+data[i].seat_name+'</td>'
  54. + '<td class="list_middle">'+data[i].ticket_type_name+'</td>'
  55. +'<td class="list_middle"><input value="'+data[i].cus_price+'" placeholder="请填写零售价" class="r_input" readonly="true" style="width: 98px;text-align:right;" id="cus_price'+i+'">&nbsp元</td>'
  56. +'<td class="list_middle"><input value="'+data[i].prod_price+'" placeholder="请填写分销价" class="r_input" readonly="true" style="width: 98px;text-align:right;" id="prod_price'+i+'">&nbsp元</td>'
  57. +'<td class="list_middle"><a><div id="save'+i+'" style="display:inline-block;cursor: pointer;"'
  58. +'start_area_id="'+data[i].start_area_id+'" end_area_id="'+data[i].end_area_id+'" ticket_type="'+data[i].ticket_type+'" prodId="'+data[i].prod_id+'" ind="'+i+'" class="save" >修改</div></a><a><div class="quxiao" style="display:inline-block;margin-left:12px;cursor: pointer;">取消</div></a></td>'
  59. + '</tr>'
  60. }
  61. }
  62. $("#list").html(temp);
  63. $(".save").click(function(){
  64. ind = $(this).attr("ind");
  65. prod_id = $(this).attr("prodId");
  66. ticket_type = $(this).attr("ticket_type");
  67. start_area_id = $(this).attr("start_area_id");
  68. end_area_id = $(this).attr("end_area_id");
  69. cus_price = $("#cus_price"+ind).val();
  70. prod_price = $("#prod_price"+ind).val();
  71. cus_price_id = "prod_price"+ind;
  72. prod_price_id = "cus_price"+ind;
  73. if($(this).text()=="保存"){
  74. goSave();
  75. // $(this).text("保存");
  76. // $("#cus_price"+ind).removeAttr("readonly");
  77. // $("#prod_price"+ind).removeAttr("readonly");
  78. // $("#cus_price"+ind).removeClass("r_input");
  79. // $("#prod_price"+ind).removeClass("r_input");
  80. }else if($(this).text()=="修改"){
  81. $(this).text("确定");
  82. $("#cus_price"+ind).removeAttr("readonly");
  83. $("#prod_price"+ind).removeAttr("readonly");
  84. $("#cus_price"+ind).removeClass("r_input");
  85. $("#prod_price"+ind).removeClass("r_input");
  86. }else if($(this).text()=="确定"){
  87. goAmenda();
  88. }
  89. })
  90. $(".quxiao").click(function(){
  91. $("#"+cus_price_id).attr("readonly","true");
  92. $("#"+prod_price_id).attr("readonly","true");
  93. $("#cus_price"+ind).addClass("r_input");
  94. $("#prod_price"+ind).addClass("r_input");
  95. $("#save"+ind).text("修改");
  96. })
  97. }
  98. function goSave(){
  99. $.ajax({
  100. url:'./st-xm/control.php',
  101. type: "post",
  102. data: {type:"linemanager_addticket",
  103. line_id:temp1,
  104. c_price:cus_price,
  105. p_price:prod_price,
  106. ticket_type:ticket_type,
  107. start_area_id:start_area_id,
  108. end_area_id:end_area_id
  109. },
  110. dataType: "json",
  111. success: function (data) {
  112. console.log(data);
  113. if(data.code == 0){
  114. $("#"+cus_price_id).attr("readonly","true");
  115. $("#"+prod_price_id).attr("readonly","true");
  116. $("#cus_price"+ind).addClass("r_input");
  117. $("#prod_price"+ind).addClass("r_input");
  118. $("#save"+ind).text("修改");
  119. alert('保存成功');
  120. }else{
  121. alert('保存失败!')
  122. }
  123. },
  124. fail: function (data) {
  125. alert("请检查网络!");
  126. // 此处放失败后执行的代码
  127. }
  128. });
  129. }
  130. function goAmenda(){
  131. var r=confirm("请确认是否修改价格?")
  132. if (r==true)
  133. {
  134. $.ajax({
  135. url:'./st-xm/control.php',
  136. type: "post",
  137. data: {type:"linemanager_updateticket",
  138. line_id:temp1,
  139. c_price:cus_price,
  140. p_price:prod_price,
  141. ticket_type:ticket_type,
  142. start_area_id:start_area_id,
  143. end_area_id:end_area_id
  144. },
  145. dataType: "json",
  146. success: function (data) {
  147. console.log(data);
  148. if(data.code == 0){
  149. $("#"+cus_price_id).attr("readonly","true");
  150. $("#"+prod_price_id).attr("readonly","true");
  151. $("#cus_price"+ind).addClass("r_input");
  152. $("#prod_price"+ind).addClass("r_input");
  153. $("#save"+ind).text("修改");
  154. alert('保存成功');
  155. }else{
  156. alert('保存失败!')
  157. }
  158. },
  159. fail: function (data) {
  160. alert("请检查网络!");
  161. // 此处放失败后执行的代码
  162. }
  163. });
  164. }
  165. else
  166. {
  167. return;
  168. }
  169. }
  170. //得到url上的参数,并反映线路名称
  171. function getPar(par){
  172. var local_url = document.location.href;
  173. local_url = decodeURI(local_url);
  174. var get = local_url.indexOf(par +"=");
  175. if(get == -1){
  176. return false;
  177. }
  178. var get_par = local_url.slice(par.length + get + 1);
  179. var nextPar = get_par.indexOf("&");
  180. if(nextPar != -1){
  181. get_par = get_par.slice(0, nextPar);
  182. }
  183. return get_par;
  184. }