salesOrder.js 8.7 KB

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