123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315 |
- /* add = 添加 update = 修改*/
- var isAddOrUpDate = "add";
- var $isUpDateNode; //当isAddOrUpDate = update 的时候才会有值
- var TR_NUMBER = 0; //用于在添加产品的时候,一个区别值;
- $(function(){
- var loadIndex = 0;
- $("#form-order-add").Validform({
- tiptype: function (msg, o, cssctl) {
- if (o.type == 3) {//失败
- layer.msg(msg, {icon: 5, time: 3000});
- $(window).scrollTop(o.obj.offset().top - 40);
- }
- },
- datatype: {//自定义验证类型
- },
- ignoreHidden: true,
- tipSweep: true, //若为true,则只在表单提交时验证
- ajaxPost: true, //异步提交
- beforeCheck: function (curform) { //验证通过之前执行的函数
- var flag = false;
- },
- beforeSubmit: function (curform) { //验证通过之后执行的函数
- var billAmountCopy = Number($("#billAmountCopy").val());
- if(!isEmpty(billAmountCopy)){
- vailErrorMsg($("#billAmountCopy"),"开票金额为空!");
- return false;
- }
- if(Number(billAmountCopy) <= 0){
- vailErrorMsg($("#billAmountCopy"),"开票金额不能小于等于0!");
- return false;
- }
- // 计算价格
- var itemBillAmount = 0;
- $("#add_product").find("tr").each(function () {
- var billItemUnitPrice = Number($(this).find(".billItemUnitPrice").val());
- var billItemNum = Number($(this).find(".billItemNum").val());
- var billItemAmountPrice = accMul(billItemUnitPrice,billItemNum);
- $(this).find(".billItemAmountPrice").val(billItemAmountPrice);
- itemBillAmount += billItemAmountPrice;
- });
- if(billAmountCopy != itemBillAmount){
- vailErrorMsg($("#billAmountCopy"),"开票总金额与商品总金额不符!",3000);
- return false;
- }
- $("#billAmount").val(accMul(billAmountCopy,100));
- var flag = false;
- /*封装订单项*/
- var orderItemArray = new Array();
- $("#add_product").find("tr").each(function(){
- var billingItem = new Object();
- billingItem.colorId = $(this).find(".color_id").val();
- billingItem.billItemNum = $(this).find(".billItemNum").val();
- var unitPrice = $(this).find(".billItemUnitPrice").val();
- var amountPrice = $(this).find(".billItemAmountPrice").val();
- billingItem.billItemUnitPrice = accMul(unitPrice,100);
- billingItem.billItemAmountPrice = accMul(amountPrice,100);
- orderItemArray.push(billingItem);
- flag = true;
- });
- if(!flag){
- vailErrorMsg($(".add-order-button"),"必须要有一个产品");
- return false;
- }
- $("#orderItemString").val(JSON.stringify(orderItemArray));
- loadIndex = layer.load(1, {
- shade: [0.5,'#fff'] //0.1透明度的白色背景
- });
- },
- callback: function (data) {//异步回调函数
- if (data) {
- var index = layer.alert(data.resultMsg, function (index) {
- if (data.resultCode == 200) {
- location.href = url_path + "/admin/ei_billing/billing_list";
- }else {
- layer.close(index);
- }
- });
- if(loadIndex != 0 ){
- layer.close(loadIndex);
- }
- }
- return false;
- }
- });
- });
- /**
- * 查询发票余额
- */
- function select_amount() {
- var platId = $("#platId").val();
- var billOrderNo = $("#billOrderNo").val();
- if(!isEmpty(billOrderNo)){
- vailErrorMsg($("#billOrderNo"),"订单号不能为空!",3000);
- return false;
- }
- var index = layer.load(1, {
- shade: [0.5,'#fff'] //0.1透明度的白色背景
- });
- $.ajax({
- type: "POST",
- data: {
- platId : platId,
- billOrderNo : billOrderNo
- },
- url: url_path +"/admin/ei_billing/select_billing_amount",
- success: function(data){
- layer.close(index);
- if (data.returnCode == 200 ) {
- layer.msg("已成功获取订单信息", {icon: 1, time: 2000});
- var billing = data.returnMsg.billing;
- $("#billAmountCopy").val(accDiv(billing.billAmount,100));
- $("#billCompanyName").val(billing.billCompanyName);
- $("#billTaxNumber").val(billing.billTaxNumber);
- $("#all_add_product").show();
- TR_NUMBER ++;
- for(var i=0;i<billing.billingItemList.length;i++){
- var billingItem = billing.billingItemList[i];
- var html = '<tr class="text-c tr_chang_'+ TR_NUMBER +'">'
- + '<input type="hidden" class="color_id" id="" value="'+ billingItem.colorId +'" >'
- + ' <td>'+ cufte(billingItem.billItemProductName) +'</td>'
- + ' <td>'+ cufte(billingItem.billItemColorName) +'</td>'
- + '<td style="width: 50px;">'
- + '<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)">'
- + '</td>'
- + '<td style="width: 50px;">'
- + '<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)">'
- + '</td>'
- + '<td style="width: 50px;">'
- + '<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)">'
- + '</td>'
- + '<td>'
- + '<a href="javascript:void(0)" class="del_product all_down" onclick="updateProduct($(this))" >修改</a> '
- + '<a href="javascript:void(0)" class="del_product all_down" onclick="delProduct($(this))" >删除</a>'
- + '</td>';
- $("#add_product").append(html);
- }
- $(".tr_chang_"+TR_NUMBER).each(function () {
- $(this).find(".billItemUnitPrice").change(function () {
- countAmountPrice($(this));
- })
- $(this).find(".billItemNum").change(function () {
- countAmountPrice($(this));
- })
- });
- }else{
- //第三方扩展皮肤
- layer.alert(data.resultMsg, {
- icon: 5,
- skin: 'layer-ext-moon' //该皮肤由layer.seaning.com友情扩展。关于皮肤的扩展规则,去这里查阅
- });
- }
- },
- error:function(xhr,status,error){
- layer.close(index);
- }
- });
- }
- /**
- * 打开商品列表
- */
- function add_product() {
- isAddOrUpDate = "add";
- layer_show("商品列表",url_path + "/admin/salesOrder/to_add_product","1000","500");
- }
- /**
- * 选择商品回调
- * @param colorIds
- */
- function setSelectProduct(colorIds){
- var index = layer.load(1, {
- shade: [0.5,'#fff'] //0.1透明度的白色背景
- });
- $("#all_add_product").show();
- var colorIdArray = colorIds.split("_");
- for(var i=0;i<colorIdArray.length;i++){
- var colorId = colorIdArray[i];
- if(colorId == ""){
- break;
- }
- var flag = true;
- $("#add_product").find("tr").each(function (){
- var colId = $(this).find(".color_id").eq(0).val();
- if(colId == colorId){
- flag = false;
- }
- });
- if(!flag){
- continue;
- }
- $.ajax({
- type: "POST",
- data: { colorId : colorId},
- url: url_path +"/admin/product/get_product",
- success: function(data){
- if (data.returnCode == 200 && data.returnMsg.productColorList.length > 0 ) {
- TR_NUMBER ++;
- for(var i=0;i<data.returnMsg.productColorList.length;i++){
- var productColor = data.returnMsg.productColorList[i];
- var discount = cufteInt(productColor.colorDiscount);
- var html = '<tr class="text-c tr_chang_'+ TR_NUMBER +'">'
- + '<input type="hidden" class="color_id" id="" value="'+ productColor.colorId +'" >'
- + ' <td>'+ cufte(productColor.productName) +'</td>'
- + ' <td>'+ cufte(productColor.colorName) +'</td>'
- + '<td style="width: 50px;">'
- + '<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)">'
- + '</td>'
- + '<td style="width: 50px;">'
- + '<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)">'
- + '</td>'
- + '<td style="width: 50px;">'
- + '<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)">'
- + '</td>'
- + '<td>'
- + '<a href="javascript:void(0)" class="del_product all_down" onclick="updateProduct($(this))" >修改</a> '
- + '<a href="javascript:void(0)" class="del_product all_down" onclick="delProduct($(this))" >删除</a>'
- + '</td>';
- if(isAddOrUpDate == 'update'){
- $isUpDateNode.parent().parent().before(html);
- $isUpDateNode.parent().parent().remove();
- }else{
- $("#add_product").append(html);
- }
- }
- $(".tr_chang_"+TR_NUMBER).each(function () {
- $(this).find(".billItemUnitPrice").change(function () {
- countAmountPrice($(this));
- })
- $(this).find(".billItemNum").change(function () {
- countAmountPrice($(this));
- })
- });
- }else{
- html = '<tr class="text-c"><td colspan="12">没有搜索到商品,请重试!</td></tr>';
- }
- }
- });
- }
- layer.close(index);
- }
- /**
- * 修改商品
- */
- function updateProduct($this){
- $isUpDateNode = $($this);
- isAddOrUpDate = 'update';
- layer_show("商品列表",url_path + "/admin/salesOrder/to_add_product?isRadio=1","1000","500");
- }
- /**
- * 删除商品
- */
- function delProduct($this){
- $this.parents("tr").remove();
- }
- /**
- * 计算合计金额
- */
- function countAmountPrice($node) {
- var billItemUnitPrice = $node.parent().parent().find(".billItemUnitPrice").val();
- var billItemNum = $node.parent().parent().find(".billItemNum").val();
- if(!isEmpty(billItemUnitPrice) || !isEmpty(billItemNum)){
- return false;
- }
- var billingAmount = accMul(billItemUnitPrice,billItemNum);
- if(!isNaN(billingAmount)){
- $node.parent().parent().find(".billItemAmountPrice").val(billingAmount);
- }
- }
- /**
- * 计算总金额
- */
- function calc_amount() {
- // 计算价格
- var itemBillAmount = 0;
- $("#add_product").find("tr").each(function () {
- var billItemUnitPrice = Number($(this).find(".billItemUnitPrice").val());
- var billItemNum = Number($(this).find(".billItemNum").val());
- var billItemAmountPrice = accMul(billItemUnitPrice,billItemNum);
- $(this).find(".billItemAmountPrice").val(billItemAmountPrice);
- itemBillAmount += billItemAmountPrice;
- });
- $("#billAmountCopy").val(itemBillAmount);
- }
|