salesOrder.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /**
  2. * 打开商品列表
  3. */
  4. function add_product() {
  5. layer_show("商品列表",url_path + "/admin/salesOrder/to_add_product","1000","500");
  6. }
  7. /**
  8. * 打开客诉列表
  9. */
  10. function add_customer() {
  11. layer_show("客诉列表",url_path + "/admin/customer/to_add_customer_list","1000","500");
  12. }
  13. $(function(){
  14. $("#salesOrderStatus").change(function(){
  15. var status = $(this).val();
  16. if(status == 1){ //正常订单
  17. $("#selectCustomer").hide();
  18. }else{
  19. $("#selectCustomer").show();
  20. }
  21. })
  22. })
  23. $(function(){
  24. $("#form-order-add").Validform({
  25. tiptype: function (msg, o, cssctl) {
  26. if (o.type == 3) {//失败
  27. layer.msg(msg, {icon: 5, time: 3000});
  28. $(window).scrollTop(o.obj.offset().top - 40);
  29. }
  30. },
  31. datatype: {//自定义验证类型
  32. },
  33. ignoreHidden: true,
  34. tipSweep: true, //若为true,则只在表单提交时验证
  35. ajaxPost: true, //异步提交
  36. beforeCheck: function (curform) { //验证通过之前执行的函数
  37. var flag = false;
  38. },
  39. beforeSubmit: function (curform) { //验证通过之后执行的函数
  40. var addressProvince = $("#addressProvince").find("option:selected").text();
  41. var addressCity = $("#addressCity").find("option:selected").text();
  42. var addressCountry = $("#addressCountry").find("option:selected").text();
  43. var addressDesc = $("#addressDesc").val();
  44. var salesAddressInfo = addressProvince + " " + addressCity + " " + addressCountry + " " + addressDesc
  45. $("#salesAddressInfo").val(salesAddressInfo);
  46. var flag = false;
  47. /*封装订单项*/
  48. var orderItemArray = new Array();
  49. $("#add_product").find("tr").each(function(){
  50. var orderItem = new Object();
  51. orderItem.itemColorId = $(this).find(".color_id").val();
  52. orderItem.itemNum = $(this).find(".item-num").val();
  53. orderItemArray.push(orderItem);
  54. flag = true;
  55. })
  56. if(!flag){
  57. vailErrorMsg($(".add-order-button"),"必须要有一个产品");
  58. return false;
  59. }
  60. $("#orderItemString").val(JSON.stringify(orderItemArray));
  61. var index = layer.load(1, {
  62. shade: [0.5,'#fff'] //0.1透明度的白色背景
  63. });
  64. },
  65. callback: function (data) {//异步回调函数
  66. if (data) {
  67. var index = layer.alert(data.resultMsg, function (index) {
  68. if (data.resultCode == 200) {
  69. location.href = url_path + "/admin/salesOrder/list_order_page";
  70. }else {
  71. layer.close(index);
  72. }
  73. });
  74. layer.close(index);
  75. }
  76. }
  77. });
  78. });
  79. /**
  80. * 客诉回调
  81. * @param colorIds
  82. */
  83. function setSelectCustomer(customerId){
  84. var index = layer.load(1, {
  85. shade: [0.5,'#fff'] //0.1透明度的白色背景
  86. });
  87. $.ajax({
  88. type: "POST",
  89. data: { customerId : customerId},
  90. url: url_path +"/admin/customer/get_customer_info",
  91. success: function(data){
  92. if (data.returnCode == 200 && data.returnMsg.customer != null ) {
  93. var customer = data.returnMsg.customer;
  94. $("#salesCustomerIdHtml").html(customer.customerId);
  95. $("#salesCustomerId").val(customer.customerId);
  96. }else{
  97. }
  98. $("#salesCustomer").show();
  99. }
  100. });
  101. layer.close(index);
  102. }
  103. /**
  104. * 选择商品回调
  105. * @param colorIds
  106. */
  107. function setSelectProduct(colorIds){
  108. var index = layer.load(1, {
  109. shade: [0.5,'#fff'] //0.1透明度的白色背景
  110. });
  111. $("#all_add_product").show();
  112. var colorIdArray = colorIds.split("_");
  113. for(var i=0;i<colorIdArray.length;i++){
  114. var colorId = colorIdArray[i];
  115. if(colorId == ""){
  116. break;
  117. }
  118. var flag = true;
  119. $("#add_product").find("tr").each(function (){
  120. var colId = $(this).find(".color_id").eq(0).val();
  121. if(colId == colorId){
  122. flag = false;
  123. }
  124. })
  125. if(!flag){
  126. continue;
  127. }
  128. $.ajax({
  129. type: "POST",
  130. data: { colorId : colorId},
  131. url: url_path +"/admin/product/get_product",
  132. success: function(data){
  133. var html = "";
  134. if (data.returnCode == 200 && data.returnMsg.productColorList.length > 0 ) {
  135. for(var i=0;i<data.returnMsg.productColorList.length;i++){
  136. var productColor = data.returnMsg.productColorList[i];
  137. html += '<tr class="text-c">' +
  138. '<input type="hidden" class="color_id" id="" value="'+ productColor.colorId +'" >' +
  139. '<input type="hidden" class="color_price" id="" value="'+ productColor.colorPrice +'" >' +
  140. '<input type="hidden" class="color_discount" id="" value="'+ productColor.colorDiscount +'" >' +
  141. ' <td>'+ cufte(productColor.productName) +'</td>' +
  142. ' <td>'+ cufte(productColor.colorName) +'</td>' +
  143. ' <td>'+ cufte(productColor.colorPrice)/100 +'</td>' +
  144. ' <td>'+ cufte(productColor.colorBar) +'</td>' +
  145. ' <td><input type="text" class="input-text input-number item-num" value="1" style="width: 100%;border: none;text-align: center;" name="" id="" placeholder="产品数量" onkeyup="keyFun($(this),999,1)" onpaste="keyFun($(this),999,1)"></td>' +
  146. ' <td><a href="javascript:void(0)" class="del_product all_down" onclick="delProduct($(this))" >删除</a></td>' +
  147. ' </tr>';
  148. }
  149. }else{
  150. html = '<tr class="text-c"><td colspan="12">没有搜索到商品,请重试!</td></tr>';
  151. }
  152. $("#add_product").append(html);
  153. /*计算价格*/
  154. calculatePrice();
  155. }
  156. });
  157. }
  158. layer.close(index);
  159. }
  160. /**
  161. * 删除商品
  162. */
  163. function delProduct($this){
  164. $this.parents("tr").remove();
  165. }
  166. /**
  167. * 计算价格
  168. */
  169. function calculatePrice(){
  170. /*总价,折扣价,优惠金额*/
  171. var colorDiscountAll = 0,colorPriceAll = 0,salesPayMoneyAll=0;
  172. $("#add_product").find("tr").each(function(){
  173. var colorDiscount = 0,colorPrice = 0,salesPayMoney=0,itemNum=0;
  174. colorDiscount = parseInt($(this).find(".color_discount").val())/100;
  175. colorPrice = parseInt($(this).find(".color_price").val())/100;
  176. itemNum = $(this).find(".item-num").val();
  177. if(!isEmpty(itemNum)){
  178. return;
  179. }
  180. itemNum = parseInt(itemNum);
  181. salesPayMoney = colorPrice -colorDiscount;
  182. if(salesPayMoney < 0){
  183. salesPayMoney = 0;
  184. }
  185. colorDiscountAll += colorDiscount*itemNum;
  186. colorPriceAll += colorPrice*itemNum;
  187. salesPayMoneyAll += salesPayMoney*itemNum;
  188. })
  189. $("#salesAmount").val(colorPriceAll);
  190. $("#salesPayMoney").val(colorDiscountAll);
  191. $("#salesDiscountMoney").val(salesPayMoneyAll);
  192. $("#salesLastMoney").val(colorDiscountAll);
  193. }