salesOrder.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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. $("#salesOrderStatus").val(2);
  114. $("#salesCustomerIdHtml").html("已经选择客诉记录:"+customer.customerId);
  115. $("#salesCustomerId").val(customer.customerId);
  116. sc.setCompanyId(customer.companyId);
  117. sc.setStoreId(customer.storeId);
  118. /*设置用户姓名、电话*/
  119. $("#salesAddressName").val(customer.customerName);
  120. $("#salesAddressTel").val(customer.customerTel);
  121. /* 售后订单的支付时间、支付方式默认 */
  122. $("#salesPayTime").val(customer.salesTime+" 08:00:00");
  123. // sc.setUlcById(0,1,11);
  124. ulc.setUlcById(0,customer.customerProvinceId,customer.customerCityId,customer.customerDistrictId);
  125. }else{
  126. }
  127. $("#salesCustomer").show();
  128. }
  129. });
  130. layer.close(index);
  131. }
  132. /**
  133. * 选择商品回调
  134. * @param colorIds
  135. */
  136. function setSelectProduct(colorIds){
  137. var index = layer.load(1, {
  138. shade: [0.5,'#fff'] //0.1透明度的白色背景
  139. });
  140. $("#all_add_product").show();
  141. var colorIdArray = colorIds.split("_");
  142. for(var i=0;i<colorIdArray.length;i++){
  143. var colorId = colorIdArray[i];
  144. if(colorId == ""){
  145. break;
  146. }
  147. var flag = true;
  148. $("#add_product").find("tr").each(function (){
  149. var colId = $(this).find(".color_id").eq(0).val();
  150. if(colId == colorId){
  151. flag = false;
  152. }
  153. })
  154. if(!flag){
  155. continue;
  156. }
  157. $.ajax({
  158. type: "POST",
  159. data: { colorId : colorId},
  160. url: url_path +"/admin/product/get_product",
  161. success: function(data){
  162. var html = "";
  163. if (data.returnCode == 200 && data.returnMsg.productColorList.length > 0 ) {
  164. for(var i=0;i<data.returnMsg.productColorList.length;i++){
  165. var productColor = data.returnMsg.productColorList[i];
  166. html += '<tr class="text-c">' +
  167. '<input type="hidden" class="color_id" id="" value="'+ productColor.colorId +'" >' +
  168. '<input type="hidden" class="color_price" id="" value="'+ productColor.colorPrice +'" >' +
  169. '<input type="hidden" class="color_discount" id="" value="'+ productColor.colorDiscount +'" >' +
  170. ' <td>'+ cufte(productColor.productName) +'</td>' +
  171. ' <td>'+ cufte(productColor.colorName) +'</td>' +
  172. ' <td>'+ cufte(productColor.colorPrice)/100 +'</td>' +
  173. ' <td>'+ cufte(productColor.colorBar) +'</td>' +
  174. ' <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>' +
  175. ' <td><a href="javascript:void(0)" class="del_product all_down" onclick="delProduct($(this))" >删除</a></td>' +
  176. ' </tr>';
  177. }
  178. }else{
  179. html = '<tr class="text-c"><td colspan="12">没有搜索到商品,请重试!</td></tr>';
  180. }
  181. $("#add_product").append(html);
  182. /*计算价格*/
  183. calculatePrice();
  184. }
  185. });
  186. }
  187. layer.close(index);
  188. }
  189. /**
  190. * 删除商品
  191. */
  192. function delProduct($this){
  193. $this.parents("tr").remove();
  194. }
  195. /**
  196. * 计算价格
  197. */
  198. function calculatePrice(){
  199. /*总价,折扣价,优惠金额*/
  200. var colorDiscountAll = 0,colorPriceAll = 0,salesPayMoneyAll=0;
  201. $("#add_product").find("tr").each(function(){
  202. var colorDiscount = 0,colorPrice = 0,salesPayMoney=0,itemNum=0;
  203. colorDiscount = parseInt($(this).find(".color_discount").val())/100;
  204. colorPrice = parseInt($(this).find(".color_price").val())/100;
  205. itemNum = $(this).find(".item-num").val();
  206. if(!isEmpty(itemNum)){
  207. return;
  208. }
  209. itemNum = parseInt(itemNum);
  210. salesPayMoney = colorPrice -colorDiscount;
  211. if(salesPayMoney < 0){
  212. salesPayMoney = 0;
  213. }
  214. colorDiscountAll += colorDiscount*itemNum;
  215. colorPriceAll += colorPrice*itemNum;
  216. salesPayMoneyAll += salesPayMoney*itemNum;
  217. })
  218. $("#salesAmount").val(colorPriceAll);
  219. $("#salesPayMoney").val(colorDiscountAll);
  220. $("#salesDiscountMoney").val(salesPayMoneyAll);
  221. $("#salesLastMoney").val(colorDiscountAll);
  222. }