billing.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. /* add = 添加 update = 修改*/
  2. var isAddOrUpDate = "add";
  3. var $isUpDateNode; //当isAddOrUpDate = update 的时候才会有值
  4. var TR_NUMBER = 0; //用于在添加产品的时候,一个区别值;
  5. $(function(){
  6. var loadIndex = 0;
  7. $("#form-order-add").Validform({
  8. tiptype: function (msg, o, cssctl) {
  9. if (o.type == 3) {//失败
  10. layer.msg(msg, {icon: 5, time: 3000});
  11. $(window).scrollTop(o.obj.offset().top - 40);
  12. }
  13. },
  14. datatype: {//自定义验证类型
  15. },
  16. ignoreHidden: true,
  17. tipSweep: true, //若为true,则只在表单提交时验证
  18. ajaxPost: true, //异步提交
  19. beforeCheck: function (curform) { //验证通过之前执行的函数
  20. var flag = false;
  21. },
  22. beforeSubmit: function (curform) { //验证通过之后执行的函数
  23. var billAmountCopy = Number($("#billAmountCopy").val());
  24. if(!isEmpty(billAmountCopy)){
  25. vailErrorMsg($("#billAmountCopy"),"开票金额为空!");
  26. return false;
  27. }
  28. if(Number(billAmountCopy) <= 0){
  29. vailErrorMsg($("#billAmountCopy"),"开票金额不能小于等于0!");
  30. return false;
  31. }
  32. // 计算价格
  33. var itemBillAmount = 0;
  34. $("#add_product").find("tr").each(function () {
  35. var billItemUnitPrice = Number($(this).find(".billItemUnitPrice").val());
  36. var billItemNum = Number($(this).find(".billItemNum").val());
  37. var billItemAmountPrice = accMul(billItemUnitPrice,billItemNum);
  38. $(this).find(".billItemAmountPrice").val(billItemAmountPrice);
  39. itemBillAmount += billItemAmountPrice;
  40. });
  41. if(billAmountCopy != itemBillAmount){
  42. vailErrorMsg($("#billAmountCopy"),"开票总金额与商品总金额不符!",3000);
  43. return false;
  44. }
  45. $("#billAmount").val(accMul(billAmountCopy,100));
  46. var flag = false;
  47. /*封装订单项*/
  48. var orderItemArray = new Array();
  49. $("#add_product").find("tr").each(function(){
  50. var billingItem = new Object();
  51. billingItem.colorId = $(this).find(".color_id").val();
  52. billingItem.billItemNum = $(this).find(".billItemNum").val();
  53. var unitPrice = $(this).find(".billItemUnitPrice").val();
  54. var amountPrice = $(this).find(".billItemAmountPrice").val();
  55. billingItem.billItemUnitPrice = accMul(unitPrice,100);
  56. billingItem.billItemAmountPrice = accMul(amountPrice,100);
  57. orderItemArray.push(billingItem);
  58. flag = true;
  59. });
  60. if(!flag){
  61. vailErrorMsg($(".add-order-button"),"必须要有一个产品");
  62. return false;
  63. }
  64. $("#orderItemString").val(JSON.stringify(orderItemArray));
  65. loadIndex = layer.load(1, {
  66. shade: [0.5,'#fff'] //0.1透明度的白色背景
  67. });
  68. },
  69. callback: function (data) {//异步回调函数
  70. if (data) {
  71. var index = layer.alert(data.resultMsg, function (index) {
  72. if (data.resultCode == 200) {
  73. location.href = url_path + "/admin/ei_billing/billing_list";
  74. }else {
  75. layer.close(index);
  76. }
  77. });
  78. if(loadIndex != 0 ){
  79. layer.close(loadIndex);
  80. }
  81. }
  82. return false;
  83. }
  84. });
  85. });
  86. /**
  87. * 查询发票余额
  88. */
  89. function select_amount() {
  90. var platId = $("#platId").val();
  91. var billOrderNo = $("#billOrderNo").val();
  92. if(!isEmpty(billOrderNo)){
  93. vailErrorMsg($("#billOrderNo"),"订单号不能为空!",3000);
  94. return false;
  95. }
  96. var index = layer.load(1, {
  97. shade: [0.5,'#fff'] //0.1透明度的白色背景
  98. });
  99. $.ajax({
  100. type: "POST",
  101. data: {
  102. platId : platId,
  103. billOrderNo : billOrderNo
  104. },
  105. url: url_path +"/admin/ei_billing/select_billing_amount",
  106. success: function(data){
  107. layer.close(index);
  108. if (data.returnCode == 200 ) {
  109. layer.msg("已成功获取订单信息", {icon: 1, time: 2000});
  110. var billing = data.returnMsg.billing;
  111. $("#billAmountCopy").val(accDiv(billing.billAmount,100));
  112. $("#billCompanyName").val(billing.billCompanyName);
  113. $("#billTaxNumber").val(billing.billTaxNumber);
  114. $("#all_add_product").show();
  115. TR_NUMBER ++;
  116. for(var i=0;i<billing.billingItemList.length;i++){
  117. var billingItem = billing.billingItemList[i];
  118. var html = '<tr class="text-c tr_chang_'+ TR_NUMBER +'">'
  119. + '<input type="hidden" class="color_id" id="" value="'+ billingItem.colorId +'" >'
  120. + ' <td>'+ cufte(billingItem.billItemProductName) +'</td>'
  121. + ' <td>'+ cufte(billingItem.billItemColorName) +'</td>'
  122. + '<td style="width: 50px;">'
  123. + '<input type="text" class="input-text input-number billItemUnitPrice" value="'+ accDiv(billingItem.billItemUnitPrice,100) +'" style="width: 100%;text-align: center;" name="billItemUnitPrice" id="" placeholder="产品单价" onblur="keyFunDecimal($(this),99999,0.01)" onpaste="keyFunDecimal($(this),999,0.01)">'
  124. + '</td>'
  125. + '<td style="width: 50px;">'
  126. + '<input type="text" class="input-text input-number billItemNum" value="'+ billingItem.billItemNum +'" style="width: 100%;text-align: center;" name="billItemNum" id="" placeholder="产品数量" onkeyup="keyFun($(this),999,1)" onpaste="keyFun($(this),999,1)">'
  127. + '</td>'
  128. + '<td style="width: 50px;">'
  129. + '<input type="text" class="input-text input-number billItemAmountPrice" value="'+ accDiv(billingItem.billItemAmountPrice,100) +'" style="width: 100%;text-align: center;" name="billItemAmountPrice" id="" placeholder="合计金额" onblur="keyFunDecimal($(this),99999,0.01)" onpaste="keyFunDecimal($(this),999,0.01)">'
  130. + '</td>'
  131. + '<td>'
  132. + '<a href="javascript:void(0)" class="del_product all_down" onclick="updateProduct($(this))" >修改</a>&nbsp;'
  133. + '<a href="javascript:void(0)" class="del_product all_down" onclick="delProduct($(this))" >删除</a>'
  134. + '</td>';
  135. $("#add_product").append(html);
  136. }
  137. $(".tr_chang_"+TR_NUMBER).each(function () {
  138. $(this).find(".billItemUnitPrice").change(function () {
  139. countAmountPrice($(this));
  140. })
  141. $(this).find(".billItemNum").change(function () {
  142. countAmountPrice($(this));
  143. })
  144. });
  145. }else{
  146. //第三方扩展皮肤
  147. layer.alert(data.resultMsg, {
  148. icon: 5,
  149. skin: 'layer-ext-moon' //该皮肤由layer.seaning.com友情扩展。关于皮肤的扩展规则,去这里查阅
  150. });
  151. }
  152. },
  153. error:function(xhr,status,error){
  154. layer.close(index);
  155. }
  156. });
  157. }
  158. /**
  159. * 打开商品列表
  160. */
  161. function add_product() {
  162. isAddOrUpDate = "add";
  163. layer_show("商品列表",url_path + "/admin/salesOrder/to_add_product","1000","500");
  164. }
  165. /**
  166. * 选择商品回调
  167. * @param colorIds
  168. */
  169. function setSelectProduct(colorIds){
  170. var index = layer.load(1, {
  171. shade: [0.5,'#fff'] //0.1透明度的白色背景
  172. });
  173. $("#all_add_product").show();
  174. var colorIdArray = colorIds.split("_");
  175. for(var i=0;i<colorIdArray.length;i++){
  176. var colorId = colorIdArray[i];
  177. if(colorId == ""){
  178. break;
  179. }
  180. var flag = true;
  181. $("#add_product").find("tr").each(function (){
  182. var colId = $(this).find(".color_id").eq(0).val();
  183. if(colId == colorId){
  184. flag = false;
  185. }
  186. });
  187. if(!flag){
  188. continue;
  189. }
  190. $.ajax({
  191. type: "POST",
  192. data: { colorId : colorId},
  193. url: url_path +"/admin/product/get_product",
  194. success: function(data){
  195. if (data.returnCode == 200 && data.returnMsg.productColorList.length > 0 ) {
  196. TR_NUMBER ++;
  197. for(var i=0;i<data.returnMsg.productColorList.length;i++){
  198. var productColor = data.returnMsg.productColorList[i];
  199. var discount = cufteInt(productColor.colorDiscount);
  200. var html = '<tr class="text-c tr_chang_'+ TR_NUMBER +'">'
  201. + '<input type="hidden" class="color_id" id="" value="'+ productColor.colorId +'" >'
  202. + ' <td>'+ cufte(productColor.productName) +'</td>'
  203. + ' <td>'+ cufte(productColor.colorName) +'</td>'
  204. + '<td style="width: 50px;">'
  205. + '<input type="text" class="input-text input-number billItemUnitPrice" value="'+ accDiv(discount,100) +'" style="width: 100%;text-align: center;" name="billItemUnitPrice" id="" placeholder="产品单价" onblur="keyFunDecimal($(this),99999,0.01)" onpaste="keyFunDecimal($(this),999,0.01)">'
  206. + '</td>'
  207. + '<td style="width: 50px;">'
  208. + '<input type="text" class="input-text input-number billItemNum" value="1" style="width: 100%;text-align: center;" name="billItemNum" id="" placeholder="产品数量" onkeyup="keyFun($(this),999,1)" onpaste="keyFun($(this),999,1)">'
  209. + '</td>'
  210. + '<td style="width: 50px;">'
  211. + '<input type="text" class="input-text input-number billItemAmountPrice" value="'+ accDiv(discount,100) +'" style="width: 100%;text-align: center;" name="billItemAmountPrice" id="" placeholder="合计金额" onblur="keyFunDecimal($(this),99999,0.01)" onpaste="keyFunDecimal($(this),999,0.01)">'
  212. + '</td>'
  213. + '<td>'
  214. + '<a href="javascript:void(0)" class="del_product all_down" onclick="updateProduct($(this))" >修改</a>&nbsp;'
  215. + '<a href="javascript:void(0)" class="del_product all_down" onclick="delProduct($(this))" >删除</a>'
  216. + '</td>';
  217. if(isAddOrUpDate == 'update'){
  218. $isUpDateNode.parent().parent().before(html);
  219. $isUpDateNode.parent().parent().remove();
  220. }else{
  221. $("#add_product").append(html);
  222. }
  223. }
  224. $(".tr_chang_"+TR_NUMBER).each(function () {
  225. $(this).find(".billItemUnitPrice").change(function () {
  226. countAmountPrice($(this));
  227. })
  228. $(this).find(".billItemNum").change(function () {
  229. countAmountPrice($(this));
  230. })
  231. });
  232. }else{
  233. html = '<tr class="text-c"><td colspan="12">没有搜索到商品,请重试!</td></tr>';
  234. }
  235. }
  236. });
  237. }
  238. layer.close(index);
  239. }
  240. /**
  241. * 修改商品
  242. */
  243. function updateProduct($this){
  244. $isUpDateNode = $($this);
  245. isAddOrUpDate = 'update';
  246. layer_show("商品列表",url_path + "/admin/salesOrder/to_add_product?isRadio=1","1000","500");
  247. }
  248. /**
  249. * 删除商品
  250. */
  251. function delProduct($this){
  252. $this.parents("tr").remove();
  253. }
  254. /**
  255. * 计算合计金额
  256. */
  257. function countAmountPrice($node) {
  258. var billItemUnitPrice = $node.parent().parent().find(".billItemUnitPrice").val();
  259. var billItemNum = $node.parent().parent().find(".billItemNum").val();
  260. if(!isEmpty(billItemUnitPrice) || !isEmpty(billItemNum)){
  261. return false;
  262. }
  263. var billingAmount = accMul(billItemUnitPrice,billItemNum);
  264. if(!isNaN(billingAmount)){
  265. $node.parent().parent().find(".billItemAmountPrice").val(billingAmount);
  266. }
  267. }
  268. /**
  269. * 计算总金额
  270. */
  271. function calc_amount() {
  272. // 计算价格
  273. var itemBillAmount = 0;
  274. $("#add_product").find("tr").each(function () {
  275. var billItemUnitPrice = Number($(this).find(".billItemUnitPrice").val());
  276. var billItemNum = Number($(this).find(".billItemNum").val());
  277. var billItemAmountPrice = accMul(billItemUnitPrice,billItemNum);
  278. $(this).find(".billItemAmountPrice").val(billItemAmountPrice);
  279. itemBillAmount += billItemAmountPrice;
  280. });
  281. $("#billAmountCopy").val(itemBillAmount);
  282. }