123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139 |
- /**
- * Created by 837 on 2017/8/12.
- */
- var ctx = $("#ctx").val();
- var product_index = $('#product_index').val();
- // 订单促销活动
- var promotionsIds = [];
- var totalPromotions = [];
- var giftPromotionsIds = [];
- // 用户总优惠券
- var totalCoupons = [];
- // 当前商品可用优惠券
- var selectCoupons = [];
- // 勾选后的优惠金额
- var couponPrice = 0;
- // 添加订单true,修改订单false
- var initFlag = true;
- var orderStatus = 0;
- $(function() {
- /** 发票信息 start * */
- // var invoiceTitle=$("#orderInvoice\\.invoiceTitle").val();
- // if(invoiceTitle !='' && invoiceTitle !=null && invoiceTitle !='null'){
- var type = $("#orderInvoice\\.type").val();
- if (type == '1') {
- $("#invoiceTable").show();
- $("#addTaxInvoiceTable").hide();
- $("#invoice2").attr("checked", true);
- var invoiceTitleType = $("#orderInvoice\\.invoiceTitleType").val();
- if (invoiceTitleType == 0) {
- $('#orderInvoice_companyTitle').attr('disabled', true);
- $('#orderInvoice_companyTitle').attr('value', '');
- $('#orderInvoice_corporationTaxNum').attr('disabled', true);
- $('#orderInvoice_corporationTaxNum').attr('value', '');
- $($(":radio[name='normalTitle_r']").get(1)).attr("checked", 'checked');
- $('#orderInvoice_normalTitle').attr('name', 'orderInvoice.invoiceTitle');
- }
- if (invoiceTitleType == 1) {
- $('#orderInvoice_normalTitle').attr('disabled', true);
- $('#orderInvoice_normalTitle').attr('value', '');
- $('#orderInvoice_normalTitle').attr('name', '');
- $($(":radio[name='normalTitle_r']").get(0)).attr("checked", 'checked');
- $('#orderInvoice_companyTitle').attr('name', 'orderInvoice.invoiceTitle');
- }
- $("#orderInvoice\\.corporationTaxNum").attr('value', '');
- $("#orderInvoice\\.corporationTaxNum").attr('name', '');
- } else if (type == '2') {
- $("#invoiceTable").hide();
- $("#addTaxInvoiceTable").show();
- $("#invoice3").attr("checked", true);
- $("#orderInvoice_normalTitle").attr('disabled', true);
- $("#orderInvoice\\.invoiceTitleType").attr("value", '1');
- $('#orderInvoiceInvoiceTitle3').attr('name', 'orderInvoice.invoiceTitle');
- $($(":radio[name='normalTitle_r']").get(0)).attr("checked", 'checked');
- } else {
- $("#invoiceTable").hide();
- $("#addTaxInvoiceTable").hide();
- $("#invoice1").attr("checked", true);
- $("#orderInvoice_normalTitle").attr('disabled', true);
- $("#orderInvoice\\.invoiceTitleType").attr("value", '1');
- $("#orderInvoice_corporationTaxNum").attr('value', '');
- $("#orderInvoice_corporationTaxNum").attr('name', '');
- $($(":radio[name='normalTitle_r']").get(0)).attr("checked", 'checked');
- }
- //单存在输入时候默认为个人发票类型
- $("#orderInvoice\\.invoiceTitle").on('change', function() {
- $("#orderInvoice\\.type").val("1"); //优化发票修改
- });
- $(":radio[name='normalTitle_r']").click(function() {
- var index = $(":radio[name='normalTitle_r']").index($(this));
- $("#orderInvoice\\.corporationTaxNum").attr('value', '');
- $("#orderInvoice\\.corporationTaxNum").attr('name', '');
- $("#orderInvoiceInvoiceTitle3").attr('value', '');
- $("#orderInvoiceInvoiceTitle3").attr('name', '');
- if (index == 0) {
- //普通发票的 企业抬头被选中了
- $("#orderInvoice\\.invoiceTitleType").val("1");
- $("#orderInvoice_normalTitle").attr('disabled', true);
- $("#orderInvoice_normalTitle").attr('value', '');
- $("#orderInvoice_companyTitle").attr('disabled', false);
- $("#orderInvoice_corporationTaxNum").attr('disabled', false);
- $('#orderInvoice_companyTitle').attr('name', 'orderInvoice.invoiceTitle');
- $('#orderInvoice_corporationTaxNum').attr('name', 'orderInvoice.corporationTaxNum');
- } else {
- //普通发票的 个人抬头被选中了
- $("#orderInvoice\\.invoiceTitleType").val("0");
- $("#orderInvoice_companyTitle").attr('disabled', true);
- $("#orderInvoice_companyTitle").attr('value', '');
- $("#orderInvoice_corporationTaxNum").attr('disabled', true);
- $("#orderInvoice_corporationTaxNum").attr('value', '');
- $("#orderInvoice_normalTitle").attr('disabled', false);
- $('#orderInvoice_companyTitle').attr('name', '');
- $('#orderInvoice_normalTitle').attr('name', 'orderInvoice.invoiceTitle');
- }
- });
- $(":radio[name='invoice']").click(function() {
- var index = $(":radio[name='invoice']").index($(this));
- if (index == 1) { //选中第2个时,div显示
- $("#invoiceTable").hide();
- $("#addTaxInvoiceTable").show();
- $("#orderInvoice\\.type").val("2");
- $('#orderInvoice_corporationTaxNum').attr('name', '');
- $('#orderInvoice\\.corporationTaxNum').attr('name', 'orderInvoice.corporationTaxNum');
- $('#orderInvoice_companyTitle').attr('name', '');
- $('#orderInvoice_normalTitle').attr('name', '');
- $('#orderInvoiceInvoiceTitle3').attr('name', 'orderInvoice.invoiceTitle');
- } else if (index == 0) { //当被选中的不是第1个时,div隐藏
- $("#invoiceTable").hide();
- $("#addTaxInvoiceTable").hide();
- $("#orderInvoice\\.invoiceTitle").val("");
- $("#orderInvoice\\.type").val("0"); //优化发票修改
- } else { //选中增值税发票
- $("#invoiceTable").hide();
- $("#addTaxInvoiceTable").show();
- $("#orderInvoice\\.type").val("2");
- $('#orderInvoice_corporationTaxNum').attr('name', '');
- $('#orderInvoice\\.corporationTaxNum').attr('name', 'orderInvoice.corporationTaxNum');
- $('#orderInvoice_companyTitle').attr('name', '');
- $('#orderInvoice_normalTitle').attr('name', '');
- $('#orderInvoiceInvoiceTitle3').attr('name', 'orderInvoice.invoiceTitle');
- }
- });
- /** 发票信息 end * */
- $("body").on('change', '.shopNote', function() {
- var self = $(this);
- var shopID = self.attr('data-shopid');
- var val = self.val();
- self.next('input[name=shopNote]').val(val + '=' + shopID);
- });
- /** 修改订单初始化 */
- var orderId = $("#orderID").val()*1;
- orderStatus = $("#orderStatus").val()*1;
- if (orderId && orderId > 0) {
- var userId = $("#inputForm").find("[name*='bpOrderUserinfo.userId']").val();
- // 获取用户总优惠券
- getUserCoupons(userId);
- // 修改订单初始化商品列表
- $('#product_index').val(0);
- product_index = 0;
- var productList = [];
- $('.productTable tbody tr:not(.gift)').each(function(index, element) {
- var data = JSON.parse($(this).attr("data-value"));
- data.shopId = data.shopID ? data.shopID : data.shopId;
- data.productId = data.productID ? data.productID : data.productId;
- if (data.productPromotion) {
- data.cmPromotion = {
- id: data.productPromotion.promotionsId,
- isNewRecord: data.productPromotion.isNewRecord,
- name: data.productPromotion.name,
- type: data.productPromotion.type,
- mode: data.productPromotion.mode,
- touchPrice: data.productPromotion.touchPrice,
- reducedPrice: data.productPromotion.reducedPrice,
- status: data.productPromotion.status
- };
- var tempProduct = {
- shopId: data.shopId,
- productId: data.productId,
- price: data.price,
- number: data.num,
- totalTax: data.totalAddedValueTax
- };
- data.productId = data.productID;
- data.shopId = data.shopID;
- var tempId = data.productPromotion.promotionsId;
- if (promotionsIds.indexOf(tempId) >= 0) {
- totalPromotions.forEach(function(item) {
- if (item.id * 1 === tempId) {
- for (var i = 0; i < item.promotionProducts.length; i++) {
- if (item.promotionProducts[i].productId == data.productId) {
- item.promotionProducts.splice(i--, 1);
- }
- }
- item.promotionProducts.push(tempProduct);
- }
- })
- } else {
- promotionsIds.push(tempId);
- var tempPromotions = JSON.parse(JSON.stringify(data.cmPromotion));
- if (tempPromotions.mode * 1 === 1) {
- tempPromotions.reducedPrice = data.price - tempPromotions.touchPrice;
- }
- if (data.cmPromotion.type * 1 === 3) {
- tempPromotions.shopId = data.shopId;
- }
- /*if(data.cmPromotion.mode*1 === 3){
- giftPromotionsIds.push(tempId);
- }*/
- tempPromotions.promotionProducts = [];
- tempPromotions.promotionProducts.push(tempProduct);
- totalPromotions.push(tempPromotions);
- }
- }
- data.productPromotion = null;
- productList.push(data);
- });
- $('.productTable tbody tr.gift').each(function(index, element) {
- var present = JSON.parse($(this).attr("data-value"));
- present.shopId = present.shopID ? present.shopID : present.shopId;
- present.productId = present.productID ? present.productID : present.productId;
- if (present.productType == 1) {
- productList.forEach(function(data) {
- if (present.productId == data.productId) {
- data.presentNum = present.num;
- }
- });
- }
- });
- $('.productTable').each(function(index, element) {
- $(this).prev('.order-rows').remove();
- $(this).remove();
- });
- initFlag = false;
- productList.forEach(function(data) {
- setProductList(data);
- });
- initFlag = true;
- }
- });
- /************************添加会所 start**********************************************************/
- /**
- * 展示会所选择框
- * @param iframe
- */
- function showClubSelect(iframe) {
- top.$.jBox(iframe, {
- iframeScrolling: 'yes',
- width: $(top.document).width() - 100,
- height: $(top.document).height() - 160,
- persistent: true,
- // showScrolling: false,
- title: "选择会所",
- bottomText: '请选择一个会所',
- buttons: {
- "确定": '1',
- "关闭": '-1'
- },
- submit: function(v, h, f) {
- //确定
- var $jboxFrame = top.$('#jbox-iframe');
- var $mainFrame = top.$('#mainFrame');
- if ('1' == v && 1 == $jboxFrame.size() && 1 == $mainFrame.size()) {
- var items = $jboxFrame[0].contentWindow.getCheckedItems();
- // console.log(items);
- if (items.length > 0) {
- //$jboxFrame[0].contentWindow.setBinding(items);
- setSingleSelect(items); //设置选中值
- // initStages();//初始化分期信息---分期功能目前已废弃
- $('.productTable,.order-rows').remove(); //重新选择会所时清空商品
- $('.productTotalFee,.payTotalFee,.payableAmount,.balancePayFee').text('0.00'); //清空金额
- $('#surplusBalance,#surplusBalance').text('0.00');
- $('.productCount').text('0');
- // 设置添加商品显示
- $(".addSecondHandProduct").show();
- return true;
- } else {
- top.$.jBox.tip("请选择...");
- return false;
- }
- }
- return true;
- }
- });
- }
- /**
- * 选择会所后设置用户信息
- * @param items
- */
- function setSingleSelect(items) {
- var info = eval('(' + items[0] + ')');
- $("#curProvince").val(info.province);
- $("#curCity").val(info.city);
- $("#curTown").val(info.town);
- loadProvince(); //加载地址下拉选项
- $("#bpOrderUserinfo\\.address").val(info.address); //设置详细地址
- console.log(info);
- $("#bpOrderUserinfo\\.clubId").val(info.id); //设置会所ID
- $("#bpOrderUserinfo\\.userId").val(info.userID);
- $("#inputForm").find("[name*='bpOrderUserinfo.province']").select2("val", info.province); //设置省份值
- $("#inputForm").find("[name*='bpOrderUserinfo.city']").select2("val", info.city);
- $("#inputForm").find("[name*='bpOrderUserinfo.town']").select2("val", info.town);
- // $("#bpOrderUserinfo\\.name").val(info.name);
- // $("bpOrderUserinfo\\.shouHuoRen").val(info.linkMan);
- // $("bpOrderUserinfo\\.phonee").val(info.contractPhone);
- // $("bpOrderUserinfo\\.mobile").val(info.contractMobile);
- $("#inputForm").find("[name*='bpOrderUserinfo.name']").val(info.name);
- $("#inputForm").find("[name*='bpOrderUserinfo.shouHuoRen']").val(info.linkMan1);
- $("#inputForm").find("[name*='bpOrderUserinfo.phonee']").val(info.contractPhone1);
- $("#inputForm").find("[name*='bpOrderUserinfo.mobile']").val(info.contractMobile1);
- $("#availableBalance").html(info.ableUserMoney);
- //设置添加商品可见(会所添加添加运费订单公用此方法但是添加运费订单不需要添加商品)
- var ui = document.getElementById("shopSelected");
- var ui1 = document.getElementById("shopSelected1");
- if (ui) {
- ui.style.display = "";
- ui1.style.display = "none";
- }
- // 获取用户总优惠券
- getUserCoupons(info.userID);
- }
- function getUserCoupons(userId) {
- totalCoupons = [];
- $.get($("#ctx").val() + "/order/clubCouponList?userId="+userId, function(data) {
- if (data.code * 1 === 0) {
- totalCoupons = data.couponList;
- // 展示可选优惠券列表
- getShownCouponList();
- }
- })
- }
- /************************添加会所 end**********************************************************/
- // 兑换优惠券
- $("#redeemCoupons").on("click", function(){
- var userId = $("#inputForm").find("[name*='bpOrderUserinfo.userId']").val();
- if (userId && userId*1 > 0) {
- var html = '<div style="text-align:center;padding-top:12px;"><input id="couponsCode" name="couponsCode" type="text" maxlength="16" placeholder="请输入16位兑换码"></div>';
- var submit = function (v, h, f) {
- if (f.couponsCode == '' || isNaN(f.couponsCode)) {
- $.jBox.tip("请输入兑换码!", 'error', { focusId: "couponsCode" });
- }
- var bool = new RegExp("^[A-Za-z0-9]{16}$").test(f.couponsCode);
- if (!bool) {
- // 16位数字和字母
- $.jBox.tip("请输入正确的兑换码!", 'error', { focusId: "couponsCode" });
- }else{
- $.post($("#ctx").val() + "/coupon/cmCouponClub/redeem", {'redemptionCode': f.couponsCode, 'userId': userId}, function (data) {
- if (0 === data.code*1) {
- $.jBox.tip(data.msg, 'info');
- // 获取用户总优惠券
- getUserCoupons(userId);
- } else {
- $.jBox.tip(data.msg, 'error');
- }
- }, "JSON");
- }
- };
- $.jBox(html, { title: "兑换优惠券", buttons: { '立即兑换': true }, submit: submit });
- } else {
- alertx('请您先选择会所!');
- }
- });
- /************************商品相关 start**********************************************************/
- //设置商品(正常)
- function editShop(obj) {
- var $tr = obj.parents('tr');
- var data = $tr.attr("data-value");
- data = JSON.parse(data);
- var productID = (data.productId == undefined) ? data.productID : data.productId;
- var secondHandType = (data.secondHandType == undefined) ? 0 : data.secondHandType;
- var discount = (data.discount == undefined) ? 100 : data.discount;
- var productCategory = (data.productCategory == undefined) ? 1 : data.productCategory;
- var includexTax = (data.includexTax == undefined) ? 2 : data.includexTax;
- var invoiceType = (data.invoiceType == undefined) ? 3 : data.invoiceType;
- var taxRate = (data.taxRate == undefined) ? 0 : data.taxRate;
- var addedValueTax = (data.addedValueTax == undefined) ? 0 : data.addedValueTax;
- var totalAddedValueTax = (data.totalAddedValueTax == undefined) ? 0 : data.totalAddedValueTax;
- $.jBox.open("iframe:" + ctx + "/bulkpurchase/purchaseProduct/formOrderProduct?productId=" + productID +
- "&secondHandType=" +
- secondHandType + "&discount=" + discount + "&productCategory=" + productCategory + "&includedTax=" +
- includexTax +
- "&invoiceType=" + invoiceType + "&taxRate=" + taxRate + "&addedValueTax=" + addedValueTax +
- "&totalAddedValueTax" + totalAddedValueTax,
- "设置商品", $(top.document).width() - 240, $(top.document).height() - 200, {
- top: 36,
- persistent: true,
- buttons: {
- "确定": "ok",
- "关闭": true
- },
- // buttons:{"关闭":true},
- bottomText: "设置商品",
- submit: function(v, h, f) {
- if (v == "ok") {
- var $jboxFrame = $('#jbox-iframe');
- var items = $jboxFrame[0].contentWindow.getCheckedItems();
- if (!items) {
- return false;
- } else {
- console.log(items[0]);
- setProductList(items[0], false); //设置商品列表
- // initStages();//初始化分期信息
- }
- return true;
- }
- },
- loaded: function(h) {
- //$(".jbox-content", top.document).css("overflow-y","hidden");
- }
- });
- }
- // 展示可选优惠券列表
- function getShownCouponList(){
- selectCoupons = [];
- var couponProductIds = [];
- var couponProductList = [];
- $('.productTable tbody tr:not(.gift)').each(function(index, element) {
- var data = JSON.parse($(this).attr("data-value"));
- couponProductList.push(data);
- couponProductIds.push(data.productId);
- });
- totalCoupons.forEach(function(coupon){
- var totalAmount = 0;
- var couponType = coupon.couponType*1;
- couponProductList.forEach(function(item){
- var productPrice = item.totalFee * 1;
- if (couponType === 0) {
- if (coupon.productType*1 === 1) {
- //活动券-全商城商品
- totalAmount += productPrice;
- } else if (coupon.productType*1 === 2) {
- //活动券-指定商品
- if (coupon.productIdList.length > 0 && coupon.productIdList.indexOf(item.productId*1) >= 0) {
- totalAmount += productPrice;
- }
- }
- } else if (couponType === 1) {
- //品类券
- if (coupon.categoryType == item.commodityType) {
- totalAmount += productPrice;
- }
- } else if (couponType === 2 || couponType === 4) {
- //用户专享券或新用户券
- totalAmount += productPrice;
- } else if (couponType === 3) {
- //店铺券
- if (coupon.shopId == item.shopId) {
- totalAmount += productPrice;
- }
- }
- });
- if (totalAmount >= coupon.touchPrice) {
- selectCoupons.push(coupon);
- }
- });
- setPageCoupon();
- }
- // 设置页面显示
- function setPageCoupon() {
- var clubCouponId = $("#clubCouponId").val()*1;
- var html = '<li><label><input type="radio" name="clubCouponId" value="0"><span class="couponDesc none">不使用优惠券</span></label></li>';
- selectCoupons.forEach(function(item){
- var checked = '';
- var redemptionCode = '';
- if (clubCouponId === item.clubCouponId) {
- checked = 'checked="checked"';
- }
- if (!isNaN(item.redemptionCode)) {
- redemptionCode = '<span>兑换码:'+item.redemptionCode+'</span>';
- }
- html += '<li><label>';
- html += ' <input type="radio" name="clubCouponId" value="'+item.clubCouponId +'" '+checked+'>';
- html += ' <span class="couponDesc">';
- html += ' <span>'+item.couponName+'</span>';
- html += redemptionCode;
- html += ' <span>'+item.couponDesc+'</span>';
- html += ' <span>有效期:'+item.startDate+' - '+item.endDate+'</span>';
- html += '</span></label></li>';
- });
- $("#couponBox").find(".couponContent").html(html);
- if (clubCouponId > 0) {
- $("#couponBox").find("input[name=clubCouponId][checked=checked]").trigger("change");
- }
- }
- // 勾选优惠券重新计算总价
- $("#couponBox").on("change", "input[name=clubCouponId]", function(){
- couponPrice = 0;
- var clubCouponId = $(this).val()*1;
- selectCoupons.forEach(function(item){
- if(item.clubCouponId*1 === clubCouponId) {
- couponPrice = item.couponAmount;
- $("#clubCouponId").val(clubCouponId);
- $("#couponAmount").val(couponPrice);
- }
- });
- // 重新计算总价
- setOrderFee();
- });
- // 设置商品(二手)
- function orderSecondHandEditShop(obj) {
- var $tr = obj.parents('tr');
- var data = $tr.attr("data-value");
- data = JSON.parse(data);
- var productID = (data.productId == undefined) ? data.productID : data.productId;
- $.jBox.open("iframe:" + ctx + "/bulkpurchase/purchaseProduct/orderSecondHandProductForm?productId=" + productID,
- "设置商品", $(top.document).width() - 240, $(top.document).height() - 200, {
- top: 36,
- persistent: true,
- buttons: {
- "确定": "ok",
- "关闭": true
- },
- bottomText: "设置商品",
- submit: function(v, h, f) {
- if (v == "ok") {
- var $jboxFrame = $('#jbox-iframe');
- var items = $jboxFrame[0].contentWindow.getCheckedItems();
- if (!items) {
- return false;
- } else {
- console.log(items[0]);
- setProductList(items[0], false); //设置商品列表
- }
- return true;
- }
- },
- loaded: function(h) {}
- });
- }
- // 修改商品的时候统计下面的订单商品金额
- function setShopOrderFee(shopId) {
- var totalFee = 0;
- $($('#pTable_' + shopId)).find('.totalFee').each(function(index, element) {
- totalFee += Number($(this).html());
- });
- totalPromotions.forEach(function(item) {
- if (item.shopId == shopId && item.type == 3 && item.mode == 2) {
- var touchPrice = 0;
- item.promotionProducts.forEach(function(product) { //计算促销包含税费
- touchPrice += (product.number * product.price + product.totalTax * 1);
- });
- if (touchPrice >= item.touchPrice) {
- totalFee -= item.reducedPrice;
- }
- }
- });
- $($('#pTable_' + shopId)).prev('div').find('.bmd').html('¥' + totalFee.toFixed(2));
- }
- //删除商品
- function deleteShop(obj) {
- var $tr = obj.parents('tr');
- var $table = $tr.parents('table');
- // 协销赠品
- var productId = $tr.attr("id").split("_")[1];
- $('.productTable tbody tr.gift_' + productId).each(function(index, element) {
- $(this).remove();
- });
- // 促销
- var promotionsId = $tr.find('.tag').attr("data-id");
- var thisTouchPrice = 0;
- totalPromotions.forEach(function(item) {
- if (item.id == promotionsId) {
- for (var i = 0; i < item.promotionProducts.length; i++) {
- if (item.promotionProducts[i].productId == productId) {
- item.promotionProducts.splice(i--, 1);
- }
- }
- item.promotionProducts.forEach(function(p) {
- thisTouchPrice += p.number * p.price;
- });
- if (thisTouchPrice < item.touchPrice) {
- $('.productTable tbody tr.promotion_' + promotionsId).each(function(index, element) {
- $(this).remove();
- });
- }
- }
- });
- $tr.remove();
- if ($table.find('tr').length < 2) {
- //table里面没有商品了 table 也删掉 <2 是因为表头上有一个tr
- $table.prev('.order-rows').remove();
- $table.remove();
- }
- var shopId = $table.attr("id").split("_")[1];
- setShopOrderFee(shopId);
- setOrderFee(); //设置底部订单金额
- // initStages();//初始化分期信息
- //重新显示添加按钮(针对二手商品)
- $(".addSecondHandProduct").show();
- }
- function resetProductList(setData) {
- var productList = [];
- var productIdList = [];
- //var if (promotionsIds.indexOf(tempId)>=0) {
- $('.productTable tbody tr:not(.gift)').each(function(index, element) {
- var data = JSON.parse($(this).attr("data-value"));
- productList.push(data);
- productIdList.push(data.productId);
- });
- $('.productTable').each(function(index, element) {
- $(this).prev('.order-rows').remove();
- $(this).remove();
- });
- promotionsIds = [];
- totalPromotions = [];
- giftPromotionsIds = [];
- if (!setData) { //删除
- productList.forEach(function(data) {
- setProductList(data, false);
- });
- } else {
- if (productIdList.indexOf(setData.productId) >= 0) {
- //设置
- productList.forEach(function(data) {
- if (setData.productId == data.productId) {
- setProductList(setData, false);
- } else {
- setProductList(data, false);
- }
- });
- } else {
- //新增
- productList.forEach(function(data) {
- setProductList(data, false);
- });
- setProductList(setData, false);
- }
- }
- }
- function deleteShopProduct(obj) {
- obj.parents('tr').remove();
- var $table = obj.parents('tr').parents('table');
- if ($table.find('tr').length < 2) {
- //table里面没有商品了 table 也删掉 <2 是因为表头上有一个tr
- $table.prev('.order-rows').remove();
- $table.remove();
- }
- resetProductList();
- if ($('.productTable tbody tr').length === 0) {
- setOrderFee();
- // 展示可选优惠券列表
- getShownCouponList();
- }
- $(".addSecondHandProduct").show();
- }
- function editShopProduct(obj) {
- var $tr = obj.parents('tr');
- var data = $tr.attr("data-value");
- data = JSON.parse(data);
- var userId = $("#inputForm").find("[name*='bpOrderUserinfo.userId']").val();
- var productID = (data.productId == undefined) ? data.productID : data.productId;
- var secondHandType = (data.secondHandType == undefined) ? 0 : data.secondHandType;
- var discount = (data.discount == undefined) ? 100 : data.discount;
- var productCategory = (data.productCategory == undefined) ? 1 : data.productCategory;
- var price = (data.price == undefined) ? 0 : data.price;
- var includedTax = (data.includedTax == undefined) ? 2 : data.includedTax;
- var invoiceType = (data.invoiceType == undefined) ? 3 : data.invoiceType;
- var taxRate = (data.taxRate == undefined) ? 0 : data.taxRate;
- var addedValueTax = (data.addedValueTax == undefined) ? 0 : data.addedValueTax;
- var totalAddedValueTax = (data.totalAddedValueTax == undefined) ? 0 : data.totalAddedValueTax;
- var couponsLogo = (data.couponsLogo == undefined) ? 1 : data.couponsLogo;
- $.jBox.open("iframe:" + ctx + "/bulkpurchase/purchaseProduct/formOrderProduct?productId=" + productID +
- "&secondHandType=" + secondHandType +
- "&discount=" + discount + "&productCategory=" + productCategory + "&price=" + price + "&includedTax=" +
- includedTax + "&userId=" + userId +
- "&invoiceType=" + invoiceType + "&taxRate=" + taxRate + "&addedValueTax=" + addedValueTax +
- "&totalAddedValueTax=" + totalAddedValueTax + "&couponsLogo=" + couponsLogo,
- "设置商品", $(top.document).width() - 240, $(top.document).height() - 200, {
- top: 36,
- persistent: true,
- buttons: {
- "确定": "ok",
- "关闭": true
- },
- bottomText: "设置商品",
- submit: function(v, h, f) {
- if (v == "ok") {
- var $jboxFrame = $('#jbox-iframe');
- var items = $jboxFrame[0].contentWindow.getCheckedItems();
- if (!items) {
- return false;
- } else {
- console.log('设置:' + items[0]);
- resetProductList(items[0]); //设置商品列表
- }
- return true;
- }
- },
- loaded: function(h) {}
- });
- }
- // 展示商品选择框
- function showShopSelect(iframe) {
- var userId = $("#inputForm").find("[name*='bpOrderUserinfo.userId']").val();
- iframe = iframe + "&userId=" + userId;
- top.$.jBox(iframe, {
- iframeScrolling: 'yes',
- width: $(top.document).width() - 100,
- height: $(top.document).height() - 160,
- persistent: true,
- title: "选择商品",
- bottomText: '请从可供选择的项目中选择一个',
- buttons: {
- "确定": '1',
- "关闭": '-1'
- },
- submit: function(v, h, f) {
- //确定
- var $jboxFrame = top.$('#jbox-iframe');
- var $mainFrame = top.$('#mainFrame');
- if ('1' == v && 1 == $jboxFrame.size() && 1 == $mainFrame.size()) {
- var items = $jboxFrame[0].contentWindow.getCheckedItems();
- if (!items) {
- return false;
- } else if (items.length > 0) {
- console.log('添加:' + JSON.stringify(items[0]));
- resetProductList(items[0]); //设置商品列表
- return true;
- } else {
- top.$.jBox.tip("请选择...");
- return false;
- }
- }
- },
- });
- }
- // 展示优惠券详情
- function showCouponDetail(userId, productId) {
- var url = ctx + "/coupon/cmCoupon/productDetails?userId=" + userId + "&productId=" + productId;
- var title = '';
- title = "查看优惠券";
- top.$.jBox("iframe:" + url, {
- iframeScrolling: 'yes',
- width: $(top.document).width() - 600,
- height: $(top.document).height() - 250,
- persistent: true,
- title: title,
- buttons: {"确定": '1'}
- });
- }
- // 展示二手商品选择框
- function showSencondHandSelect(iframe) {
- var userId = $("#inputForm").find("[name*='bpOrderUserinfo.userId']").val();
- iframe = iframe + "&userId=" + userId;
- top.$.jBox(iframe, {
- iframeScrolling: 'yes',
- width: $(top.document).width() - 100,
- height: $(top.document).height() - 160,
- persistent: true,
- title: "选择商品",
- bottomText: '请从可供选择的项目中选择一个',
- buttons: {
- "确定": '1',
- "关闭": '-1'
- },
- submit: function(v, h, f) {
- //确定
- var $jboxFrame = top.$('#jbox-iframe');
- var $mainFrame = top.$('#mainFrame');
- if ('1' == v && 1 == $jboxFrame.size() && 1 == $mainFrame.size()) {
- var items = $jboxFrame[0].contentWindow.getCheckedItems();
- if (!items) {
- return false;
- } else if (items.length > 0) {
- console.log($('.productTable'));
- $(('.producttable')).remove();
- setSeondHandProductList(items[0]); //设置二手商品列表
- // 隐藏商品添加入口
- $(".addSecondHandProduct").hide();
- return true;
- } else {
- top.$.jBox.tip("请选择...");
- return false;
- }
- }
- },
- });
- }
- /**
- * 设置商品列表(正常商品)
- * @param items
- */
- function setProductList(data) {
- console.log("设置" + JSON.stringify(data));
- var userId = $("#inputForm").find("[name*='bpOrderUserinfo.userId']").val();
- var orderStatus = $("#orderStatus").val() ? $("#orderStatus").val()*1 : 0;
- data.productType = 0;
- var shopFee = data.shopFee;
- var cmPromotion = '';
- var ladderPrice = '';
- // 如果存在促销活动
- if (data.cmPromotion) {
- var tempId = data.cmPromotion.id * 1;
- data.promotionsId = data.cmPromotion.id;
- // 没有折扣,才享受促销优惠
- if (data.discount * 1 === 100) {
- var tempProduct = {
- shopId: data.shopId,
- productId: data.productId,
- price: data.price,
- number: data.num,
- totalTax: data.totalAddedValueTax
- };
- if (promotionsIds.indexOf(tempId) >= 0) {
- totalPromotions.forEach(function(item) {
- if (item.id * 1 === tempId) {
- for (var i = 0; i < item.promotionProducts.length; i++) {
- if (item.promotionProducts[i].productId == data.productId) {
- item.promotionProducts.splice(i--, 1);
- }
- }
- item.promotionProducts.push(tempProduct);
- }
- })
- } else {
- promotionsIds.push(tempId);
- var tempPromotions = JSON.parse(JSON.stringify(data.cmPromotion));
- if (tempPromotions.mode == 1) {
- tempPromotions.reducedPrice = data.price - tempPromotions.touchPrice;
- }
- if (data.cmPromotion.type == 3) {
- tempPromotions.shopId = data.shopId;
- }
- tempPromotions.promotionProducts = [];
- tempPromotions.promotionProducts.push(tempProduct);
- totalPromotions.push(tempPromotions);
- }
- if (data.cmPromotion.mode == 1) {
- data.totalFee = (data.cmPromotion.touchPrice * data.num + data.totalAddedValueTax * 1);
- cmPromotion = '<span class="tag" data-id="' + tempId + '"><em style="background:green">' + data
- .cmPromotion.name + '</em>优惠价:' + data.cmPromotion.touchPrice + '</span>';
- } else if (data.cmPromotion.mode == 2) {
- cmPromotion = '<span class="tag" data-id="' + tempId + '"><em style="background:#F60">' + data
- .cmPromotion.name + '</em>满' + data.cmPromotion.touchPrice + '减' + data.cmPromotion.reducedPrice +
- '</span>';
- } else if (data.cmPromotion.mode == 3) {
- cmPromotion = '<span class="tag" data-id="' + tempId + '"><em style="background:purple">' + data
- .cmPromotion.name + '</em>满' + data.cmPromotion.touchPrice + '赠送商品' + '</span>';
- }
- } else {
- cmPromotion = '<span class="red">有折扣,不享受促销优惠</span>'
- }
- } else {
- if (data.ladderPriceFlag * 1 === 1) {
- ladderPrice = '<br><a href="javascript:;" class="ladderPrice"><span>阶梯价格</span></a>';
- if (data.ladderPriceList && data.ladderPriceList.length > 0) {
- var ladder = '<p><span>起订量</span><span>价格</span></p>';
- for (var i = 0; i < data.ladderPriceList.length; i++) {
- ladder += '<p data-num="' + data.ladderPriceList[i].buyNum + '"><span>' + data.ladderPriceList[i]
- .buyNumRangeShow + '</span><span class="price">' + data.ladderPriceList[i].buyPrice +
- '</span></p>';
- }
- ladderPrice = '<br><a href="javascript:;" class="ladderPrice"><span>阶梯价格</span><div class="list">' +
- ladder + '</div></a>'
- }
- }
- }
- var cmCouponBtn = '---';
- if (data.couponsLogo*1 === 2) {
- cmCouponBtn = '<a href="javascript:;" onclick="showCouponDetail('+ userId +','+ data.productId +')">查看</a>';
- }
- var str =
- "<tr id='product_" + data.productId + "' data-value='" + JSON.stringify(data) + "' data-index='" +
- product_index + "'>" +
- "<td>" + data.productId + "</td>" +
- "<td hidden><input type='hidden' name='orderProduct[" + product_index + "].enabledStatus' id='orderProduct" +
- product_index + ".enabledStatus' value='" + JSON.stringify(data) + "'/>" + data.shopId + "</td>" +
- "<td hidden>" + data.shopName + "</td>" +
- "<td class='fix-width'>" + data.name + "</td><td hidden></td>" +
- (data.productCategory == 2 ? "" : ("<td>" + data.shopName + "</td>")) +
- "<td>" + data.num + (data.presentNum > 0 ? "(" + data.presentNum + ")" : "") + "</td>" +
- (data.discount * 1 === 100 && data.cmPromotion && data.cmPromotion.mode == 1 ? ("<td><del>" + data.price +
- "</del>") : ("<td>" + data.price)) +
- (data.includedTax == 1 ? "<label style='color: red'>(含税)</label>" : data.includedTax == 0 && (data
- .invoiceType == 1 || data.invoiceType == 2) ? "<label style='color: red'>(不含税-能开票)</label>" : data
- .includedTax != '' && data.includedTax == 0 && data.invoiceType == 3 ?
- "<label style='color: red'>(不含税-不能开票)</label>" : "") +
- "</td>" +
- "<td>" + data.discount + "</td>" +
- (data.discount * 1 === 100 && data.cmPromotion && data.cmPromotion.mode == 1 ? ("<td><del>" + data
- .discountPrice + "</del></td>") : ("<td>" + data.discountPrice +
- ladderPrice + "</td>")) +
- (data.includedTax != '' && (data.includedTax == 0 && data.invoiceType == 3) ? ("<td>---</td>") : data
- .includedTax == 2 ? ("<td>0%</td>") : ("<td>" + data.taxRate + "%</td>")) +
- (data.includedTax == 1 || (data.includedTax != '' && data.includedTax == 0 && data.invoiceType == 3) ? (
- "<td>---</td>") : data.addedValueTax == null ? ("<td>0</td>") : ("<td>" + data.addedValueTax + "</td>")) +
- (data.includedTax == 1 || (data.includedTax != '' && data.includedTax == 0 && data.invoiceType == 3) ? (
- "<td>---</td>") : data.totalAddedValueTax == null ? ("<td>0</td>") : ("<td>" + data.totalAddedValueTax +
- "</td>")) +
- "<td class='totalFee'>" + Number(data.totalFee).toFixed(2) + "</td>" +
- // "<td>"+ Math.round(shopFee*100)/100 +"</td>"+
- "<td>" + (data.buyAgainFlag == 1 ? "是" : "否") + "</td>" +
- ((data.productCategory == 2) ? "" : "<td>" + cmPromotion + "</td>") +
- ((data.productCategory == 2) ? "" : "<td>" + cmCouponBtn + "</td>") +
- "<td>" + (orderStatus != 0 ? "" : (data.productCategory == 2) ?
- "<a href='javascript:void(0);' onclick='orderSecondHandEditShop($(this))'>设置</a> <a href='javascript:void(0);' onclick='deleteShopProduct($(this))'>删除商品</a>" :
- "<a href='javascript:void(0);' onclick='editShopProduct($(this))'>设置</a> <a href='javascript:void(0);' onclick='deleteShopProduct($(this))'>删除商品</a>"
- ) +
- "</td>" +
- "</tr>";
- appendProductList(str, data, cmPromotion);
- }
- function appendProductList(str, data, cmPromotion) {
- //把表中存在的删除
- var removeBeforeSoon = false; //是这一次移除
- var removeEle;
- $('.productTable tbody tr:not(.gift)').each(function(index, element) {
- if ($(this).find("td:nth-child(1)").html() == data.productId) {
- removeEle = $(this).parent();
- $(this).remove();
- removeBeforeSoon = true;
- }
- });
- if (removeBeforeSoon) {
- //走到这里 说明是修改
- removeEle.append(str);
- } else {
- //这里就是新加了 //先看有没有这个 当前这个商品的供应商的table
- if ($('#pTable_' + data.shopId).length != 0) {
- $('#pTable_' + data.shopId + ' tbody').append(str);
- } else {
- appendShopOrderHead(data, str, cmPromotion);
- }
- }
- setShopOrderFee(data.shopId);
- setOrderFee(); //设置底部订单金额
- product_index++;
- // 设置赠品
- setGiftHtmlList(data, cmPromotion);
- // 展示可选优惠券列表
- getShownCouponList();
- }
- function appendShopOrderHead(data, str, cmPromotion) {
- var html = '<div class="order-rows">' +
- '<br><p>' +
- '<span class="fix-right-margin"><label>下单时间:</label></span>' +
- '<span class="fix-right-margin"><label>子订单号(ID):</label></span>' +
- '<span class="fix-right-margin"><label>子订单金额:</label><span class="bmd"></span></span>' +
- '</p>' +
- '<p> <label>供应商:</label>' + data.shopName + (data.cmPromotion && data.cmPromotion.type == 3 ? cmPromotion :
- '') + '</p>' +
- '<p><span><label>留言:</label>' +
- "<input id='shopID_" + data.shopId + "' type='text' class='shopNote' data-shopid='" + data.shopId + "'>" +
- '<input type="hidden" name="shopNote">' +
- '</span></p>' +
- '</div>' + '<table id="pTable_' + data.shopId +
- '" class="productTable table table-striped table-bordered table-condensed">' +
- '<thead>' +
- '<tr>' +
- '<th>商品ID</th>' +
- '<th hidden></th>' +
- '<th hidden></th>' +
- '<th class="fix-width">商品名称</th><th hidden></th>' +
- ((data.productCategory == 2) ? '' : '<th>供应商名称</th>') +
- '<th>数量(赠品数)</th>' +
- '<th>单价</th>' +
- '<th>折扣</th>' +
- '<th>折后单价</th>' +
- '<th>税率</th>' +
- '<th>单个税费</th>' +
- '<th>税费</th>' +
- '<th>总价</th>' +
- /*'<th>应付供应商</th>' +*/
- '<th>能否复购</th>' +
- ((data.productCategory == 2) ? '' : '<th>促销活动</th>') +
- ((data.productCategory == 2) ? "" : "<td>优惠券</td>") +
- '<th>操作</th>' +
- '</tr>' +
- '</thead>' +
- '<tbody>' + str + '</tbody></table>';
- $('#product_index').before(html);
- }
- function setGiftHtmlList(data, cmPromotion) {
- console.log("设置赠品" + JSON.stringify(data));
- if (data.presentNum > 0) {
- // 已经添加的,重新添加
- $('.productTable tbody tr.gift_' + data.productId).each(function(index, element) {
- $(this).remove();
- });
- var present = JSON.parse(JSON.stringify(data));
- present.productType = 1;
- present.num = data.presentNum;
- present.price = 0;
- present.discountPrice = 0;
- present.orderProductId = '';
- present.orderProductID = '';
- var giftStr = "<tr id='product_gift_" + present.productId + "' class='gift gift_" + present.productId +
- "' data-value='" + JSON.stringify(present) + "' data-index='" + product_index + "'>" +
- "<td>" + present.productId + "</td>" +
- "<td hidden><input type='hidden' name='orderProduct[" + product_index +
- "].enabledStatus' id='orderProduct" + product_index + ".enabledStatus' value='" + JSON.stringify(present) +
- "'/>" + present.shopId + "</td>" +
- "<td hidden>" + present.shopName + "</td>" +
- "<td class='fix-width'><i class='red'>协商赠品:</i>" + present.name + "</td><td hidden></td>" +
- "<td>" + present.num + "</td>" +
- "<td>0</td>" +
- "<td>100</td>" +
- "<td>0</td>" +
- "<td>0</td>" +
- "<td>0</td>" +
- "<td>0</td>" +
- "<td>0</td>" +
- /*"<td>"+ Math.round(present.shopFee*100)/100 +"</td>"+*/
- "<td>否</td>" +
- "<td></td>" +
- "<td></td>" +
- "</tr>";
- product_index++;
- appendGiftsList(present, giftStr, cmPromotion);
- }
- if (data.cmPromotion && data.cmPromotion.mode == 3) {
- var thisTouchPrice = 0;
- totalPromotions.forEach(function(item) {
- if (data.cmPromotion.id == item.id) {
- item.promotionProducts.forEach(function(p) {
- thisTouchPrice += (p.number * p.price + p.totalTax * 1);
- });
- }
- });
- if (thisTouchPrice >= data.cmPromotion.touchPrice) {
- if (giftPromotionsIds.indexOf(data.cmPromotion.id) < 0) {
- // 已经添加的,重新添加
- $('.productTable tbody tr.promotion_' + cmPromotion.id).each(function(index, element) {
- $(this).remove();
- });
- // 记录赠品促销
- giftPromotionsIds.push(data.cmPromotion.id);
- // 获取赠品
- var getGiftPath = $('#ctx').val() + '/product/cmPromotions/getGifts';
- $.getJSON(getGiftPath, {
- id: data.cmPromotion.id
- }, function(res) {
- if (res && res.length > 0) {
- res.forEach(function(gift) {
- gift.productType = 2;
- gift.price = 0;
- gift.discountPrice = 0;
- gift.promotionsId = data.cmPromotion.id;
- gift.orderProductId = '';
- gift.orderProductID = '';
- if ($("#product_promotion_" + gift.productId).length > 0) {
- var pageGift = JSON.parse($("#product_promotion_" + gift.productId)
- .attr("data-value"));
- gift.num = gift.num * 1 + pageGift.num * 1;
- $("#product_promotion_" + gift.productId).remove();
- }
- var giftStr = "<tr id='product_promotion_" + gift.productId +
- "' class='gift promotions promotion_" + data.cmPromotion.id +
- "' data-value='" + JSON.stringify(gift) + "' gift-index='" +
- product_index + "'>" +
- "<td>" + gift.productId + "</td>" +
- "<td hidden><input type='hidden' name='orderProduct[" + product_index +
- "].enabledStatus' id='orderProduct" + product_index +
- ".enabledStatus' value='" + JSON.stringify(gift) + "'/>" + gift.shopId +
- "</td>" +
- "<td hidden>" + gift.shopName + "</td>" +
- "<td class='fix-width'><i class='red'>促销赠品:</i>" + gift.name +
- "</td><td hidden></td>" +
- "<td>" + gift.num + "</td>" +
- "<td>0</td>" +
- "<td>100</td>" +
- "<td>0</td>" +
- "<td>0</td>" +
- "<td>0</td>" +
- "<td>0</td>" +
- "<td>0</td>" +
- /*"<td>"+ Math.round(gift.shopFee*100)/100 +"</td>"+*/
- "<td>否</td>" +
- "<td></td>" +
- "<td></td>" +
- "</tr>";
- product_index++;
- appendGiftsList(gift, giftStr, cmPromotion);
- });
- }
- });
- }
- }
- }
- // 重新设置底部订单金额
- setOrderFee();
- // 重新设置返佣订单选项
- showRebateCheck();
- }
- function appendGiftsList(gift, giftStr, cmPromotion) {
- if ($('#pTable_' + gift.shopId).length != 0) {
- $('#pTable_' + gift.shopId + ' tbody').append(giftStr);
- } else {
- appendShopOrderHead(gift, giftStr, cmPromotion);
- }
- // 重新设置底部订单金额
- setOrderFee();
- }
- /**
- * 设置商品列表(二手商品)
- * @param items
- */
- function setSeondHandProductList(data) {
- console.log(data);
- data.productType = 0;
- var productID = (data.productId == undefined) ? data.productID : data.productId;
- //把表中存在的删除
- var removeBeforeSoon = false; //是这一次移除
- var removeEle;
- $('.productTable tbody tr').each(function(index, element) {
- if ($(this).find("td:nth-child(1)").html() == productID) {
- removeEle = $(this).parent();
- $(this).remove();
- removeBeforeSoon = true;
- }
- });
- var buyAgain = "<td>否</td>";
- var str = '';
- var shopFee = data.shopFee;
- str +=
- "<tr id='product_" + productID + "' data-value='" + JSON.stringify(data) + "' data-index='" + product_index +
- "'>" +
- "<td>" + productID + "</td>" +
- "<td hidden>" + data.shopId + "</td>" +
- "<td hidden>" + data.shopName + "</td>" +
- "<td class='fix-width'>" + data.name + "</td>" +
- "<td class='fix-width' hidden>" + "<input type='hidden' name='orderProduct[" + product_index +
- "].enabledStatus' id='orderProduct" + product_index + ".enabledStatus'/>" + data.shopName + "</td>" +
- "<td>" + data.num + "(" + data.presentNum + ")" + "</td>" +
- "<td>" + data.price + "</td>" +
- "<td>" + data.discount + "</td>" +
- "<td>" + data.discountPrice + "</td>" +
- "<td>" + data.taxRate + "</td>" +
- "<td>" + data.addedValueTax + "</td>" +
- "<td>" + data.totalAddedValueTax + "</td>" +
- "<td class='totalFee'>" + data.totalFee + "</td>" +
- /*"<td>"+ Math.round(shopFee*100)/100 +"</td>"+*/
- // 以下三个应付不显示,但是内容值参与计算并保存---关闭控制入口移动到财务管理中控制20181201
- // "<td>"+ data.shopFee+"</td>"+
- // "<td>"+ data.otherFee +"</td>"+
- // "<td>"+ data.cmFee +"</td>"+
- buyAgain +
- "<td>" +
- "<a href='javascript:void(0);' onclick='orderSecondHandEditShop($(this))'>设置</a> " +
- "<a href='javascript:void(0);' onclick='deleteShop($(this))'>删除商品</a>" +
- "</td>" +
- "</tr>";
- if (removeBeforeSoon) {
- removeEle.append(str);
- //走到这里 说明是修改
- } else {
- //这里就是新加了
- //先看有没有这个 当前这个商品的供应商的table
- if ($('#pTable_' + data.shopId).length != 0) {
- $('#pTable_' + data.shopId + ' tbody').append(str);
- } else {
- var html = '<div class="order-rows">' +
- '<span class="fix-right-margin"><label>下单时间:</label></span>' +
- '<span class="fix-right-margin"><label>子订单号(ID):</label></span>' +
- '<span class="fix-right-margin"><label>子订单金额:</label><span class="bmd"></span></span>' +
- '<br>' +
- '<span><label>留言:</label>' +
- "<input id='shopID_" + data.shopId + "' type='text' class='shopNote' data-shopid='" + data.shopId +
- "'>" +
- '<input type="hidden" name="shopNote">' +
- '</span>' +
- '</div>' + '<table id="pTable_' + data.shopId +
- '" class="productTable table table-striped table-bordered table-condensed">' +
- '<thead>' +
- '<tr>' +
- '<th>商品ID</th>' +
- '<th hidden></th>' +
- '<th hidden></th>' +
- '<th class="fix-width">商品名称</th>' +
- '<th class="fix-width" hidden>供应商名称</th>' +
- '<th>数量(赠品数)</th>' +
- '<th>单价</th>' +
- '<th>折扣</th>' +
- '<th>折后单价</th>' +
- '<th>税率</th>' +
- '<th>单个税费</th>' +
- '<th>税费</th>' +
- '<th>总价</th>' +
- /*'<th>应付供应商</th>' +*/
- '<th>能否复购</th>' +
- '<th>操作</th>' +
- '</tr>' +
- '</thead>' +
- '<tbody>' + str + '</tbody></table>';
- $('#product_index').before(html);
- }
- }
- setShopOrderFee(data.shopId);
- setOrderFee(); //设置底部订单金额
- product_index++;
- }
- //设置订单金额信息
- function setOrderFee() { //不考虑经理折扣、运费,此时 商品总金额=订单总额=应付总额
- var productTotalFee = 0, //商品总金额
- productCount = 0, // 商品总数
- presentCount = 0, //协商赠送商品数
- giftCount = 0, //促销赠品数
- orderTotalFee = 0, //订单总额
- reducedPrice = 0, //促销满减
- payTotalFee = 0; //应付总额
- var couponPrice = $("#couponAmount").val() ? $("#couponAmount").val()*1 : 0;
- $('.productTable tbody tr:not(.gift)').each(function(index, element) {
- var obj = JSON.parse($(this).attr("data-value"));
- productTotalFee = ((Number(productTotalFee) * 100 + Number(obj.num * obj.price) * 100 + Number(obj
- .totalAddedValueTax) * 100) / 100).toFixed(2);
- productCount = Number(productCount) + Number(obj.num);
- presentCount = Number(presentCount) + Number(obj.presentNum);
- orderTotalFee = ((Number(orderTotalFee) * 100 + Number(obj.totalFee) * 100) / 100).toFixed(2);
- payTotalFee = ((Number(payTotalFee) * 100 + Number(obj.totalFee) * 100) / 100).toFixed(2);
- });
- $('.productTable tbody tr.promotions').each(function(index, element) {
- var obj = JSON.parse($(this).attr("data-value"));
- giftCount = Number(giftCount) + Number(obj.num);
- });
- // 计算促销折扣
- totalPromotions.forEach(function(item) {
- if (item.mode == 2) {
- var touchPrice = 0;
- item.promotionProducts.forEach(function(product) {
- touchPrice += (product.number * product.price + product.totalTax * 1);
- });
- if (touchPrice >= item.touchPrice) {
- reducedPrice += item.reducedPrice;
- payTotalFee -= item.reducedPrice;
- }
- }
- });
- // 优惠券折扣
- if (couponPrice > 0) {
- orderTotalFee -= couponPrice;
- payTotalFee -= couponPrice;
- }
- $(".productTotalFee").text((productTotalFee * 1).toFixed(2));
- $(".promotionFullReduction").text((reducedPrice*1).toFixed(2));
- $(".couponPrice").text((couponPrice*1).toFixed(2));
- $(".productCount").text(productCount);
- $(".presentCount").text(presentCount + giftCount);
- $(".presentCount1").text(presentCount + giftCount);
- $("#presentCount").val(presentCount);
- $("#promotionalGiftsCount").val(giftCount);
- $(".orderTotalFee").text(orderTotalFee);
- $(".payTotalFee").text(payTotalFee);
- $("#discount").val('0.00');
- setProductTotalFee(); //重新设置经理折扣
- }
- // 修改数量
- function changenum(index) {
- var $num = $("#num" + index);
- var numVal = $num.val();
- var $checkItem = $("#check-item" + index);
- var orderProductStr = $($checkItem).val();
- var obj = JSON.parse(orderProductStr);
- if (numVal != null && numVal != "" && typeof(numVal) != "undefined") {
- if (parseInt(numVal) + "" != numVal || parseInt(numVal) < 1) {
- alertx("数量必须大于0,并且是一个整数");
- $num.val(obj["num"]);
- return;
- }
- obj["num"] = numVal;
- setLadderPrice(obj, numVal, index);
- var result = JSON.stringify(obj);
- $($checkItem).val(result);
- //重新计算税费
- taxRateVal(index);
- } else {
- $num.val(obj["num"]);
- alertx("您输入的数量有误,请重新输入");
- }
- }
- //加减数量
- function presentNum(index, type) {
- var $num = $("#num" + index);
- var numVal = $num.val();
- if (numVal != null && numVal != "" && typeof(numVal) != "undefined") {
- if (type == 'del') {
- numVal = parseInt(numVal) - 1;
- } else if (type == 'add') {
- numVal = parseInt(numVal) + 1;
- }
- if (numVal < 1) {
- alertx("商品数量不能小于0")
- } else {
- $num.val(numVal);
- //重新设置选中json对象值
- var $checkItem = $("#check-item" + index);
- var orderProductStr = $($checkItem).val();
- var obj = JSON.parse(orderProductStr);
- obj["num"] = numVal;
- setLadderPrice(obj, numVal, index);
- var result = JSON.stringify(obj);
- $($checkItem).val(result);
- //重新计算税费
- taxRateVal(index);
- }
- }
- }
- function setLadderPrice(obj, numVal, index) {
- if (obj["ladderPriceFlag"] * 1 === 1) {
- var ladderList = obj["ladderPriceList"];
- var resultLadder = 0;
- for (var i = 0; i < ladderList.length; i++) {
- if (numVal >= ladderList[i]["buyNum"]) {
- resultLadder = i;
- }
- }
- obj["price"] = ladderList[resultLadder]["buyPrice"];
- obj["discountPrice"] = ladderList[resultLadder]["buyPrice"];
- $("#check-item" + index).parents("tr").find("#price" + index).val(ladderList[resultLadder]["buyPrice"]);
- $("#check-item" + index).parents("tr").find("#priceLabel" + index).text(ladderList[resultLadder]["buyPrice"]);
- $("#check-item" + index).parents("tr").find("#discountPrice" + index).val(ladderList[resultLadder]["buyPrice"]);
- }
- }
- function showView(index) {
- var $num = $("#num" + index);
- //重置数量
- $num.val(1);
- alertx("二手仪器购买数量只能为1");
- }
- // 商品折扣比例
- function discountPriceVal(index) {
- var discount = $("#discount" + index).val(); //折扣
- discount = Number(discount);
- var $checkItem = $("#check-item" + index);
- var orderProductStr = $($checkItem).val();
- var obj = JSON.parse(orderProductStr);
- if (!isNaN(discount)) {
- if (discount.length > 8 || discount.length < 0) {
- $("#discount" + index).val(obj["discount"]);
- alertx("折扣最大为5位小数");
- } else if (discount > 100 || discount < 0) {
- $("#discount" + index).val(obj["discount"]);
- alertx("输入的折扣有误")
- } else {
- var price = $("#price" + index).val(); //当前价格
- price = Number(price);
- //折后单价=折扣*当前价格/100
- var discountPrice = ((discount * 100000 * price) / (100 * 100000)).toFixed(2);
- $("#discountPrice" + index).val(discountPrice);
- $("#discount" + index).val(discount);
- var $checkItem = eval('(' + $("#check-item" + index).val() + ')');
- $checkItem["discount"] = discount + ""; //重新设置折扣
- $checkItem["discountPrice"] = discountPrice + ""; //重新设置折扣单价
- $("#check-item" + index).val(JSON.stringify($checkItem));
- //重新计算税费
- taxRateVal(index)
- }
- } else {
- alertx("商品折扣只能输入数字");
- $("#discount" + index).val(obj.discount);
- }
- }
- //输入折扣单价重新计算折扣
- function countDiscount(index) {
- var price = Number($("#price" + index).val()); //拿到单价
- var discountPrice = Number($("#discountPrice" + index).val()); //拿到折后单价
- //判断必须小于等于商品单价
- if (discountPrice > price) {
- alertx("折后单价不能大于当前单价");
- $("#discountPrice" + index).val(price); //清楚输入值设置为原始单价
- $("#discount" + index).val(100);
- return;
- }
- var discount = ((discountPrice / price).toFixed(7) * 100);
- //设置折扣
- $("#discount" + index).val(discount);
- //重新计算税费和总价
- var $checkItem = $("#check-item" + index);
- var orderProductStr = $($checkItem).val();
- var obj = JSON.parse(orderProductStr);
- if (!isNaN(discount)) {
- if (discount > 100 || discount < 0) {
- $("#discount" + index).val(obj["discount"]);
- alertx("输入的折扣有误")
- } else {
- var $checkItem = eval('(' + $("#check-item" + index).val() + ')');
- $checkItem["discount"] = discount + ""; //重新设置折扣
- $checkItem["discountPrice"] = discountPrice + ""; //重新设置折扣单价
- $("#check-item" + index).val(JSON.stringify($checkItem));
- //重新计算税费
- taxRateVal(index)
- }
- }
- }
- //计算税费
- function taxRateVal(index) {
- var $checkItem = eval('(' + $("#check-item" + index).val() + ')');
- var taxRateLabel = Number($("#taxRateLabel").val());
- var taxRate = isNaN(taxRateLabel) ? Number($("#taxRate" + index).val()) : taxRateLabel; //税率
- var supplierTaxRate = Number($checkItem["supplierTaxRate"]); //供应商税率
- var numVal = $("#num" + index).val(); //商品数量
- var presentNum = $("#presentNum" + index).val(); //商品赠品数量-计算税费需要包含赠品
- if (presentNum == "" || presentNum == "undefined") {
- presentNum = 0;
- $("#presentNum" + index).val(0);
- }
- var totalNumVal = numVal * 1 + presentNum * 1; //统计赠品和购买商品数量
- var discountPrice = $("#discountPrice" + index).val(); //折后单价
- var $checkItem = eval('(' + $("#check-item" + index).val() + ')');
- if ($checkItem["name"] == '' || $checkItem["name"] == null || $checkItem["name"] == 'null' || typeof($checkItem[
- "name"]) == "undefined") {
- $checkItem["name"] = $checkItem.purchaseProductName + "";
- }
- var mode = $("#mode" + index).val(); //是否参与优惠活动
- var touchPrice = $("#touchPrice" + index).val(); //优惠价/满减满赠设定价
- var reducedPrice = $("#reducedPrice" + index).val(); //减免价格
- var name = $("#promotionName" + index).val(); //促销活动名称
- var promotionsId = $("#promotionsId" + index).val(); //促销活动id
- var discount = $("#discount" + index).val(); //百分比折扣
- var productId = $checkItem["productId"]; //商品id 11
- var includedTax = $checkItem["includedTax"] == undefined ? 2 : $checkItem["includedTax"]; //是否含税 11
- var invoiceType = $checkItem["invoiceType"] == undefined ? 3 : $checkItem["invoiceType"]; //发票类型 11
- var ctx = $("#ctx" + index).val(); //ctx
- var costCheckFlag = $checkItem["costCheckFlag"] == undefined ? 1 : $checkItem[
- "costCheckFlag"]; //成本价选中标志:1固定成本 2比例成 11
- var costPrice = $checkItem["costPrice"] == undefined ? 0.0 : $checkItem["costPrice"]; //成本价 11
- var costProportional = $checkItem["costProportional"] == undefined ? 90 : $checkItem[
- "costProportional"]; //比例成本百分比90% 11
- var oldProductFlag = $checkItem["oldProductFlag"] == undefined ? 0 : $checkItem["oldProductFlag"]; //旧商品标志,0否1是
- var obj1 = document.getElementById("priceLabel" + index); //选择商品页面商品单价
- var obj2 = document.getElementById("price"); //设置商品页面商品单价
- var price = obj1 != null ? obj1 : obj2 != null ? obj2 : null;
- if (includedTax != '' && includedTax == 0 && invoiceType == 3) {
- //不含税不能开票商品,税率置为0
- taxRate = 0;
- }
- //税率校验
- if (isNaN(taxRate) || taxRate < 0 || taxRate > 100) {
- alertx("机构税率只能为[0,100]之间的数");
- return;
- }
- if (isNaN(supplierTaxRate) || supplierTaxRate < 0 || supplierTaxRate > 100) {
- alertx("供应商税率只能为[0,100]之间的数");
- return;
- }
- // 含税商品以及不含税不能发票商品,不需要计算税费
- if (includedTax == '1' || (includedTax == '0' && invoiceType == '3')) {
- //计算总价(税费为0)=折后单价*数量
- if (discount == 100 && mode == 1) {
- var totalFee = parseFloat(((touchPrice * 100000 * numVal) / 100000).toFixed(2));
- if (price != null) {
- price.style.cssText = "text-decoration: line-through";
- }
- document.getElementById("discountPrice" + index).style.cssText =
- "width: 80px;text-decoration: line-through";
- } else {
- var totalFee = parseFloat(((discountPrice * 100000 * numVal) / 100000).toFixed(2));
- if (price != null) {
- price.style.cssText = "";
- }
- document.getElementById("discountPrice" + index).style.cssText = "width: 80px;";
- }
- if (discount != 100) {
- if (promotionsId != 0) {
- $("#promotion" + index).html("<label style=\"color:red;float: left\">有折扣,不享受促销优惠</label>");
- } else {
- $("#promotion" + index).html("");
- }
- $("#presentNum" + index).attr("readonly", null);
- } else {
- if (mode == 1) {
- $("#promotion" + index).html(
- "<label style=\"float: left;cursor: default\"><a href=\"javascript:void(0);\" onclick=\"showPromotionDetail('iframe:" +
- ctx + "/bulkpurchase/purchaseProduct/promotionDetail?promotionId=" + promotionsId + "','" +
- name + "')\"><label style=\"background: green;color: white;\">" + name + "</label>\n" +
- "<label>优惠价:" + touchPrice + "</label></a></label>")
- } else if (mode == 2) {
- $("#promotion" + index).html(
- "<label style=\"float: left\"><a href=\"javascript:void(0);\" onclick=\"showPromotionDetail('iframe:" +
- ctx + "/bulkpurchase/purchaseProduct/promotionDetail?promotionId=" + promotionsId + "','" +
- name + "')\"><label style=\"background: #F60;color: white;\" >" + name + "</label>\n" +
- "<label>满" + touchPrice + ",减" + reducedPrice + "</label></a></label>");
- } else if (mode == 3) {
- $("#promotion" + index).html(
- "<label style=\"float: left\"><a href=\"javascript:void(0);\" onclick=\"showPromotionDetail('iframe:" +
- ctx + "/bulkpurchase/purchaseProduct/promotionDetail?promotionId=" + promotionsId + "','" +
- name + "')\"><label style=\"background: purple;color: white;\" >" + name + "</label>\n" +
- "<label>满" + touchPrice + ",赠送商品</label></a></label>");
- }
- if (promotionsId != null && promotionsId != '' && promotionsId != 0) {
- $("#presentNum" + index).val(0);
- $("#presentNum" + index).attr("readonly", "readonly");
- } else {
- if (productId >= 6060 && productId <= 6069) {
- $("#presentNum" + index).attr("readonly", "readonly");
- } else {
- $("#presentNum" + index).attr("readonly", null);
- }
- }
- }
- $("#totalFee" + index).val(totalFee);
- $("#supplierTaxRate" + index).val(supplierTaxRate);
- $checkItem["taxRate"] = taxRate + ""; //重新设置税率
- $checkItem["supplierTaxRate"] = supplierTaxRate + ""; //重新设置供应商税率
- $checkItem["num"] = numVal + ""; //重新设置数量
- $checkItem["addedValueTax"] = 0; //重新设置单个机构税费
- $checkItem["totalAddedValueTax"] = 0; //重新设置机构总税费
- $checkItem["singleShouldPayTotalTax"] = 0; //重新设置单个供应商税费
- $checkItem["shouldPayTotalTax"] = 0; //重新设置供应商总税费
- $checkItem["totalFee"] = totalFee + ""; //重新设置总价
- $checkItem["payTotalFee"] = totalFee + ""; //重新设置应付
- $checkItem["costPrice"] = costPrice + ""; //重新设置成本
- // console.log("data" + index + ":" + JSON.stringify($checkItem));
- $("#check-item" + index).val(JSON.stringify($checkItem));
- } else {
- //不含税可开发票商品,需要计算税费
- if (taxRate == 0) {
- //机构税率为0,机构税费则为0
- $("#taxRate" + index).val(0);
- $("#addedValueTax" + index).val(0); //设置单个税费
- $("#totalAddedValueTax" + index).val(0); //设置总税费
- //计算总价(税费为0)=折后单价*数量
- if (discount == 100 && mode == 1) {
- //参与单品优惠价
- //计算总价
- var totalFee = parseFloat(((touchPrice * 100000 * numVal) / 100000).toFixed(2));
- //计算成本价
- if (costCheckFlag == 2 && costProportional != null) {
- costPrice = parseFloat((((touchPrice * costProportional) / 100).toFixed(2)));
- }
- if (price != null) {
- price.style.cssText = "text-decoration: line-through";
- }
- document.getElementById("discountPrice" + index).style.cssText =
- "width: 80px;text-decoration: line-through";
- } else {
- var totalFee = parseFloat(((discountPrice * 100000 * numVal) / 100000).toFixed(2));
- //计算成本价
- if (costCheckFlag == 2 && costProportional != null) {
- costPrice = parseFloat((((discountPrice * costProportional) / 100).toFixed(2)));
- }
- if (price != null) {
- price.style.cssText = "";
- }
- document.getElementById("discountPrice" + index).style.cssText = "width: 80px;";
- }
- if (discount != 100) {
- if (promotionsId != 0) {
- $("#promotion" + index).html("<label style=\"color:red;float: left\">有折扣,不享受促销优惠</label>");
- } else {
- $("#promotion" + index).html("");
- }
- $("#presentNum" + index).attr("readonly", null);
- } else {
- if (mode == 1) {
- $("#promotion" + index).html(
- "<label style=\"float: left;cursor: default\"><a href=\"javascript:void(0);\" onclick=\"showPromotionDetail('iframe:" +
- ctx + "/bulkpurchase/purchaseProduct/promotionDetail?promotionId=" + promotionsId + "','" +
- name + "')\"><label style=\"background: green;color: white;\">" + name + "</label>\n" +
- "<label>优惠价:" + touchPrice + "</label></a></label>")
- } else if (mode == 2) {
- $("#promotion" + index).html(
- "<label style=\"float: left\"><a href=\"javascript:void(0);\" onclick=\"showPromotionDetail('iframe:" +
- ctx + "/bulkpurchase/purchaseProduct/promotionDetail?promotionId=" + promotionsId + "','" +
- name + "')\"><label style=\"background: #F60;color: white;\" >" + name + "</label>\n" +
- "<label>满" + touchPrice + ",减" + reducedPrice + "</label></a></label>");
- } else if (mode == 3) {
- $("#promotion" + index).html(
- "<label style=\"float: left\"><a href=\"javascript:void(0);\" onclick=\"showPromotionDetail('iframe:" +
- ctx + "/bulkpurchase/purchaseProduct/promotionDetail?promotionId=" + promotionsId + "','" +
- name + "')\"><label style=\"background: purple;color: white;\" >" + name + "</label>\n" +
- "<label>满" + touchPrice + ",赠送商品</label></a></label>");
- }
- if (promotionsId != null && promotionsId != '' && promotionsId != 0) {
- $("#presentNum" + index).val(0);
- $("#presentNum" + index).attr("readonly", "readonly");
- } else {
- if (productId >= 6060 && productId <= 6069) {
- $("#presentNum" + index).attr("readonly", "readonly");
- } else {
- $("#presentNum" + index).attr("readonly", null);
- }
- }
- }
- var singleShouldPayTotalTax = 0;
- var shouldPayTotalTax = 0;
- if (supplierTaxRate > 0) {
- //供应商税费(单) = 成本价 * 供应商税率 * 0.01
- singleShouldPayTotalTax = (costPrice * supplierTaxRate * 0.01).toFixed(2);
- //供应商税费(总) = 供应商税费(单)*数量
- shouldPayTotalTax = (singleShouldPayTotalTax * numVal).toFixed(2);
- }
- $("#totalFee" + index).val(totalFee);
- $("#supplierTaxRate" + index).val(supplierTaxRate);
- $checkItem["taxRate"] = 0; //重新设置税率
- $checkItem["supplierTaxRate"] = supplierTaxRate + ""; //重新设置供应商税率
- $checkItem["num"] = numVal + ""; //重新设置数量
- $checkItem["addedValueTax"] = 0; //重新设置单个税费
- $checkItem["totalAddedValueTax"] = 0; //重新设置机构总税费
- $checkItem["singleShouldPayTotalTax"] = singleShouldPayTotalTax + "" //重新设置供应商单个税费
- $checkItem["shouldPayTotalTax"] = shouldPayTotalTax + ""; //重新设置供应商总税费
- $checkItem["totalFee"] = totalFee + ""; //重新设置总价
- $checkItem["payTotalFee"] = totalFee + ""; //重新设置应付
- $checkItem["costPrice"] = costPrice + ""; //重新设置成本
- $("#taxRateLabel").val(taxRate);
- $("#addedValueTaxLabel").val(0)
- $("#totalAddedValueTaxLabel").val(0)
- // console.log("data" + index + ":" + JSON.stringify($checkItem));
- $("#check-item" + index).val(JSON.stringify($checkItem));
- } else if (taxRate > 100) {
- alertx("税率不能大于100%");
- $("#taxRate" + index).val($checkItem['taxRate']);
- return;
- } else {
- // var r = /^\+?[1-9][0-9]*$/;
- if ((typeof taxRate === 'number') && (taxRate <= 100)) {
- //折扣为100且参与单品优惠活动时,根据优惠价计算数据
- if (discount == 100 && mode == 1) {
- $("#taxRate" + index).val(taxRate);
- // if (r.test(taxRate) && taxRate <= 100) {
- //单个税费=优惠价*税率【税率 (4舍5入保留2位小数)】
- var addedValueTax = (touchPrice * taxRate * 0.01).toFixed(2);
- //商品总额=折后单价*数量【[折后单价(真实值) x 数量](4舍5入保留2位小数)】
- var totalTax = (touchPrice * numVal).toFixed(2);
- //税费=商品总额*税率【税率:(4舍5入保留2位小数)】
- var totalAddedValueTax = (totalTax * taxRate * 0.01).toFixed(2);
- //计算成本价
- if (costCheckFlag == 2 && costProportional != null) {
- costPrice = (((parseFloat(touchPrice) + parseFloat(addedValueTax)) * costProportional) / 100)
- .toFixed(2);
- }
- //计算总价(存在折扣)【总价=[折后单价 x 数量](4舍5入保留2位小数) + 税费 】
- var totalFee = ((parseFloat((touchPrice * numVal).toFixed(2)) * 100 + parseFloat(
- totalAddedValueTax) * 100) / 100).toFixed(2);
- if (price != null) {
- price.style.cssText = "text-decoration: line-through";
- }
- document.getElementById("discountPrice" + index).style.cssText =
- "width: 80px;text-decoration: line-through";
- } else {
- $("#taxRate" + index).val(taxRate);
- // if (r.test(taxRate) && taxRate <= 100) {
- //单个税费=折后单价*税率【税率 (4舍5入保留2位小数)】
- var addedValueTax = (discountPrice * taxRate * 0.01).toFixed(2);
- //商品总额=折后单价*数量【[折后单价(真实值) x 数量](4舍5入保留2位小数)】
- var totalTax = (discountPrice * numVal).toFixed(2);
- //机构税费=商品总额*税率【税率:(4舍5入保留2位小数)】
- var totalAddedValueTax = (totalTax * taxRate * 0.01).toFixed(2);
- //计算成本价
- if (costCheckFlag == 2 && costProportional != null) {
- costPrice = ((((parseFloat(discountPrice) + parseFloat(addedValueTax))) * costProportional) /
- 100).toFixed(2);
- }
- //计算总价(存在折扣)【总价=[折后单价 x 数量](4舍5入保留2位小数) + 税费 】
- var totalFee = ((parseFloat((discountPrice * numVal).toFixed(2)) * 100 + parseFloat(
- totalAddedValueTax) * 100) / 100).toFixed(2);
- $("#totalFee" + index).val(totalFee);
- if (price != null) {
- price.style.cssText = "";
- }
- document.getElementById("discountPrice" + index).style.cssText = "width: 80px;";
- }
- if (discount != 100) {
- $("#promotion" + index).html("<label style=\"color:red;float: left\">有折扣,不享受促销优惠</label>")
- $("#presentNum" + index).attr("readonly", null);
- } else {
- if (mode == 1) {
- $("#promotion" + index).html(
- "<label style=\"float: left;cursor: default\"><a href=\"javascript:void(0);\" onclick=\"showPromotionDetail('iframe:" +
- ctx + "/bulkpurchase/purchaseProduct/promotionDetail?promotionId=" + promotionsId +
- "','" + name + "')\"><label style=\"background: green;color: white;\">" + name +
- "</label>\n" +
- "<label>优惠价:" + touchPrice + "</label></a></label>")
- } else if (mode == 2) {
- $("#promotion" + index).html(
- "<label style=\"float: left\"><a href=\"javascript:void(0);\" onclick=\"showPromotionDetail('iframe:" +
- ctx + "/bulkpurchase/purchaseProduct/promotionDetail?promotionId=" + promotionsId +
- "','" + name + "')\"><label style=\"background: #F60;color: white;\" >" + name +
- "</label>\n" +
- "<label>满" + touchPrice + ",减" + reducedPrice + "</label></a></label>");
- } else if (mode == 3) {
- $("#promotion" + index).html(
- "<label style=\"float: left\"><a href=\"javascript:void(0);\" onclick=\"showPromotionDetail('iframe:" +
- ctx + "/bulkpurchase/purchaseProduct/promotionDetail?promotionId=" + promotionsId +
- "','" + name + "')\"><label style=\"background: purple;color: white;\" >" + name +
- "</label>\n" +
- "<label>满" + touchPrice + ",赠送商品</label></a></label>");
- }
- if (promotionsId != null && promotionsId != '' && promotionsId != 0) {
- $("#presentNum" + index).val(0);
- $("#presentNum" + index).attr("readonly", "readonly");
- } else {
- $("#presentNum" + index).attr("readonly", null);
- }
- }
- var singleShouldPayTotalTax = 0;
- var shouldPayTotalTax = 0;
- //(未知商品/不含税可开发票的旧商品)将机构税率赋值给供应商税率
- if (includedTax == '2' || includedTax == '' || (includedTax == '0' && (invoiceType == '1' ||
- invoiceType == '2') && oldProductFlag == '1')) {
- supplierTaxRate = taxRate;
- }
- if (supplierTaxRate > 0) {
- //供应商税费(单) = 成本价 * 供应商税率 * 0.01
- singleShouldPayTotalTax = (costPrice * supplierTaxRate * 0.01).toFixed(3);
- //供应商税费(总) = 供应商税费(单)*数量
- shouldPayTotalTax = (singleShouldPayTotalTax * numVal).toFixed(2);
- }
- $("#addedValueTax" + index).val(addedValueTax);
- $("#totalAddedValueTax" + index).val(totalAddedValueTax);
- $("#totalFee" + index).val(totalFee);
- $("#supplierTaxRate" + index).val(supplierTaxRate);
- $checkItem["num"] = numVal + ""; //重新设置数量
- $checkItem["taxRate"] = taxRate + ""; //重新设置税率
- $checkItem["supplierTaxRate"] = supplierTaxRate + ""; //重新设置供应商税率
- $checkItem["addedValueTax"] = addedValueTax + ""; //重新设置单个税费
- $checkItem["totalAddedValueTax"] = totalAddedValueTax + ""; //重新设置总税费
- $checkItem["singleShouldPayTotalTax"] = singleShouldPayTotalTax + "" //重新设置供应商单个税费
- $checkItem["shouldPayTotalTax"] = shouldPayTotalTax + ""; //重新设置供应商总税费
- $checkItem["totalFee"] = totalFee + ""; //重新设置总价
- $checkItem["payTotalFee"] = totalFee + ""; //重新设置应付
- $checkItem["costPrice"] = costPrice + ""; //重新设置成本
- $("#taxRateLabel").val(taxRate);
- $("#addedValueTaxLabel").val(addedValueTax)
- $("#totalAddedValueTaxLabel").val(totalAddedValueTax)
- // console.log("data" + index + ":" + JSON.stringify($checkItem));
- $("#check-item" + index).val(JSON.stringify($checkItem));
- } else {
- alertx("税率只能为[0,100]之间的数");
- $("#taxRate" + index).val($checkItem['taxRate']);
- return;
- }
- }
- }
- singeGiveNum(index);
- shopFee(index); //优化功能开启刷新应付供应商
- otherFee(index);
- }
- // 添加赠品数
- function giveNum(i) {
- var $giveNum = $("#presentNum" + i).val();
- if ($giveNum == "" || $giveNum == "undefined") {
- $giveNum = 0;
- $("#presentNum" + i).val(0);
- }
- var giveNum = Number($giveNum);
- var $checkItem = eval('(' + $("#check-item" + i).val() + ')');
- if (!isNaN(giveNum)) {
- if ((typeof giveNum === 'number') && (giveNum % 1 === 0)) {
- $checkItem["presentNum"] = giveNum + ""; //重新设置赠品数
- $("#presentNum" + i).val(giveNum);
- $("#check-item" + i).val(JSON.stringify($checkItem));
- if (0 != giveNum) {
- cmFee(i);
- }
- //重新税费(因为赠品也需要计算税费)
- taxRateVal(i);
- } else {
- alertx("赠品数只能输入整数");
- $("#presentNum" + i).val($checkItem.presentNum);
- }
- } else {
- alertx("赠品数只能输入数字");
- $("#presentNum" + i).val($checkItem.presentNum);
- }
- }
- // 单纯获取赠品数(不计算税费)
- function singeGiveNum(i) {
- var $giveNum = $("#presentNum" + i).val();
- if ($giveNum == null || $giveNum == "" || $giveNum == "undefined") {
- $giveNum = 0;
- $("#presentNum" + i).val(0);
- }
- var giveNum = Number($giveNum);
- var $checkItem = eval('(' + $("#check-item" + i).val() + ')');
- if (giveNum != 'undefined' && !isNaN(giveNum)) {
- if ((typeof giveNum === 'number') && (giveNum % 1 === 0)) {
- $checkItem["presentNum"] = giveNum + ""; //重新设置赠品数
- $("#presentNum" + i).val(giveNum);
- $("#check-item" + i).val(JSON.stringify($checkItem));
- if (0 != giveNum) {
- cmFee(i);
- }
- } else {
- alertx("赠品数只能输入整数");
- $("#presentNum" + i).val($checkItem.presentNum);
- }
- } else {
- alertx("赠品数只能输入数字");
- $("#presentNum" + i).val($checkItem.presentNum);
- }
- }
- /**
- * @param obj
- * jquery控制input只能输入数字和两位小数
- */
- function num(obj) {
- obj.value = obj.value.replace(/[^\d.]/g, ""); //清除"数字"和"."以外的字符
- obj.value = obj.value.replace(/^\./g, ""); //验证第一个字符是数字
- obj.value = obj.value.replace(/\.{2,}/g, "."); //只保留第一个, 清除多余的
- obj.value = obj.value.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
- obj.value = obj.value.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3'); //只能输入两个小数
- }
- // 添加供应应付商金额
- function shopFee(i) {
- var $shopFee = $("#shopFee1" + i).val();
- var shopFee = Number($shopFee);
- var $checkItem = eval('(' + $("#check-item" + i).val() + ')');
- if (!isNaN(shopFee)) {
- $checkItem["shopFee1"] = shopFee + "";
- $("#shopFee1" + i).val(shopFee);
- $("#check-item" + i).val(JSON.stringify($checkItem));
- cmFee(i);
- } else {
- alertx("应付供应商只能输入数字");
- $("#shopFee1" + i).val($checkItem.shopFee1);
- }
- }
- // 添加复购属性
- function buyAgain(i) {
- var options = $("#buyAgainFlag" + i + " option:selected");
- var buyAgainFlag = options.val();
- if (null != buyAgainFlag && undefined != buyAgainFlag) {
- var $checkItem = eval('(' + $("#check-item" + i).val() + ')');
- $checkItem["buyAgainFlag"] = buyAgainFlag + "";
- $("#buyAgainFlag" + i).val(buyAgainFlag);
- $("#check-item" + i).val(JSON.stringify($checkItem));
- } else {
- var $checkItem = eval('(' + $("#check-item" + i).val() + ')');
- $checkItem["buyAgainFlag"] = "1";
- $("#buyAgainFlag" + i).val(buyAgainFlag);
- $("#check-item" + i).val(JSON.stringify($checkItem));
- }
- }
- // 添加第三方应付商金额
- function otherFee(i) {
- var $otherFee = $("#otherFee1" + i).val();
- var otherFee = Number($otherFee);
- var $checkItem = eval('(' + $("#check-item" + i).val() + ')');
- if (!isNaN(otherFee)) {
- $checkItem["otherFee1"] = otherFee + "";
- $("#otherFee1" + i).val(otherFee);
- $("#check-item" + i).val(JSON.stringify($checkItem));
- cmFee(i);
- } else {
- alertx("应付第三方只能输入数字");
- $("#otherFee1" + i).val($checkItem.otherFee1);
- }
- }
- // 添加采美应付金额
- function cmFee(i) {
- var discountPrice = $("#discountPrice" + i).val(); //折后单价
- var shopFee1 = $("#shopFee1" + i).val(); //应付供应商
- var otherFee1 = $("#otherFee1" + i).val() //应付第三方
- if ((shopFee1 != "" && shopFee1 != null) && (otherFee1 != "" && otherFee1 != null)) {
- var shopFee = Number(shopFee1);
- var otherFee = Number(otherFee1);
- var $checkItem = eval('(' + $("#check-item" + i).val() + ')');
- var num = parseInt($checkItem.num);
- var presentNum = parseInt($checkItem.presentNum);
- var cmFee = ((discountPrice * 100000 - shopFee * 100000 - otherFee * 100000) / 100000).toFixed(6);
- $("#cmFee1" + i).val(cmFee);
- $checkItem["cmFee1"] = cmFee + "";
- //设置总的应付
- var _shopFee = (shopFee * (num + presentNum)).toFixed(6); //供应商
- var _otherFee = (otherFee * num).toFixed(6); //供应商
- var _cmFee = ((discountPrice * num * 100000 - _shopFee * 100000 - _otherFee * 100000) / 100000).toFixed(6);
- $checkItem["shopFee"] = _shopFee + "";
- $checkItem["otherFee"] = _otherFee + "";
- $checkItem["cmFee"] = _cmFee + "";
- $("#check-item" + i).val(JSON.stringify($checkItem));
- }
- }
- //经理折扣后计算
- function setProductTotalFee() {
- var discount = Number($("#discount").val()); //经理折扣金额
- if (isNaN(discount)) {
- discount = Number($("#discountFee").val());
- }
- var trs = $('.productTable tbody').find('tr:not(.gift)');
- if (trs.length == 0) { //没有添加商品的情况
- $("#discount").val('0.00');
- $(".payableAmount").text(0);
- alertx("请先添加商品");
- return;
- }
- //经理折扣 -> 改变订单总额 -> 改变分期免息金额
- var productTotalFee = Number($(".productTotalFee").html()), //商品总金额
- productCount = Number($(".productCount").html()), // 订单商品总数
- presentCount = Number($("#presentCount").val()), //赠送商品数
- giftCount = Number($("#promotionalGiftsCount").val()), //促销赠品
- orderTotalFee = Number($(".orderTotalFee").html()), //订单总额
- reducedPrice = 0, //促销满减
- payTotalFee = ((orderTotalFee * 100 - discount * 100) / 100).toFixed(2); //应付总额=订单总额-折扣金额-减抵扣余额(待开发)
- if (payTotalFee < 0) {
- $("#discount").attr('value', '0');
- $("#discountFee").attr('value', '0');
- alertx("订单金额不能小于0");
- setProductTotalFee();
- return;
- }
- //计算运费
- var freePostFlag = $("#freePostFlag").val();
- var freight = 0;
- if (freePostFlag == "1") {
- freight = Number($("#freight").val());
- }
- payTotalFee = (Number(payTotalFee) + freight).toFixed(2);
- // 计算促销折扣
- totalPromotions.forEach(function(item) {
- if (item.mode == 2) {
- var touchPrice = 0;
- item.promotionProducts.forEach(function(product) {
- touchPrice += (product.number * product.price + product.totalTax * 1);
- });
- if (touchPrice >= item.touchPrice) {
- reducedPrice += item.reducedPrice;
- payTotalFee -= item.reducedPrice;
- }
- }
- });
- //计算余额抵扣
- //计算应付金额
- var payableAmount = payTotalFee; //应付订单金额
- var balancePayFee = Number($("#balancePayFee").val()); //当前使用金额
- var surplusBalance = 0.00; //剩余金额
- var availableBalanceStatus = $("#useBalancePayFee").is(':checked'); //账户余额
- var availableBalance = Number($("#availableBalance").html());
- if (availableBalanceStatus == true) {
- if ((availableBalance + balancePayFee - payTotalFee).toFixed(2) > 0) { //余额大于订单总额 全额抵扣
- surplusBalance = (Number(availableBalance) + balancePayFee - Number(payTotalFee)).toFixed(2);
- balancePayFee = payTotalFee;
- payableAmount = 0.00;
- availableBalance = surplusBalance;
- } else {
- payableAmount = (Number(payTotalFee) - Number(availableBalance) - balancePayFee).toFixed(2);
- balancePayFee = (Number(availableBalance) + balancePayFee).toFixed(2);
- surplusBalance = 0.00;
- availableBalance = surplusBalance;
- }
- } else {
- availableBalance = availableBalance + balancePayFee;
- surplusBalance = availableBalance;
- balancePayFee = 0.00;
- }
- trs.each(function(index, element) {
- var obj = JSON.parse($(this).attr("data-value"));
- var _taxRate = Number(obj.taxRate); //税率
- var _totalFee = Number(obj.totalFee); //总价
- var _shopFee1 = isNaN(Number(obj.shopFee1)) ? Number(obj.singleShopFee) : Number(obj.shopFee1);
- var _shopFee = (_shopFee1 * (Number(obj.num) + Number(obj.presentNum))).toFixed(6); //供应商
- var _otherFee1 = isNaN(Number(obj.otherFee1)) ? Number(obj.singleOtherFee) : Number(obj.otherFee1);
- var _otherFee = (_otherFee1 * Number(obj.num)).toFixed(6); //第三方
- //采美
- var _cmFee = ((Number(obj.discountPrice) * Number(obj.num) * 100000 - _shopFee * 100000 - _otherFee *
- 100000) / 100000).toFixed(6);
- //订单的单个商品 应付金额= 单个总价 。(四舍五入后,保留两位小数,--此处不平摊经理折扣)
- var _payTotalFee = (Number(obj.totalFee)).toFixed(2);
- //【旧】订单的单个商品 税费=订单的单个商品应付金额-[订单的单个商品应付金额/(1+税率)](最后保留2位小数+四舍五入)
- //var _totalAddedValueTax=((_payTotalFee*100000-((_payTotalFee/((1+_taxRate/100).toFixed(6))).toFixed(6))*100000)/100000).toFixed(2);
- var _totalAddedValueTax = obj.totalAddedValueTax;
- //差额(单个商品的经理折扣)=总价-应付金额 如果没有特别要求默认保留6位小数(此处结果为0)
- var _difAmount = ((_totalFee * 100000 - _payTotalFee * 100000) / 100000).toFixed(6);
- //总盈利(经理折扣后)=第三方+采美-差额
- var _totalProfit = ((_otherFee * 100000 + _cmFee * 100000 - _difAmount * 100000) / 100000).toFixed(6);
- //盈利比=总盈利÷(第三方+采美)
- var _profitability = 0;
- if (_otherFee != 0 && _cmFee != 0) {
- _profitability = (_totalProfit / ((_otherFee * 100000 + _cmFee * 100000) / 100000).toFixed(6))
- .toFixed(6);
- }
- //订单的每种商品 应付第三方(经理折扣后)=盈利比x第三方(经理折扣前)
- _otherFee = (_profitability * _otherFee).toFixed(6);
- //订单的单个商品 应付采美=应付金额-应付供应商-应付第三方-税费
- _cmFee = ((_payTotalFee * 100000 - _shopFee * 100000 - _otherFee * 100000 - _totalAddedValueTax *
- 100000) / 100000).toFixed(6);
- obj["shopFee"] = _shopFee + "";
- obj["otherFee"] = _otherFee + "";
- obj["cmFee"] = _cmFee + "";
- obj["shouldPayFee"] = _payTotalFee + "";
- obj["presentNum"] = obj.presentNum + "";
- if (obj["name"] == '' || obj["name"] == null || obj["name"] == 'null' || typeof(obj["name"]) ==
- "undefined") {
- obj["name"] = obj.purchaseProductName + "";
- }
- $(this).attr("data-value", JSON.stringify(obj));
- var index = $(this).attr("data-index");
- $('#orderProduct' + index + '\\.enabledStatus').val(JSON.stringify(obj));
- });
- if (initFlag) {
- $(".productTotalFee").html(productTotalFee);
- $(".productCount").html(productCount);
- $(".presentCount").text(presentCount + giftCount);
- $(".orderTotalFee").html(orderTotalFee);
- $(".payTotalFee").html((payTotalFee * 1).toFixed(2));
- $(".promotionFullReduction").text(reducedPrice);
- $(".payableAmount").html((payableAmount * 1).toFixed(2));
- $("#balancePayFee").val(balancePayFee);
- $(".balancePayFee").html(balancePayFee);
- $("#surplusBalance").html(surplusBalance);
- $("#availableBalance").html(availableBalance);
- $("#productTotalFee").val(productTotalFee);
- $("#promotionFullReduction").val(reducedPrice);
- $("#productCount").val(productCount);
- $("#presentCount").val(presentCount);
- $("#promotionalGiftsCount").val(giftCount);
- $("#orderTotalFee").val(orderTotalFee);
- $("#payTotalFee").val(payTotalFee);
- $("#inputForm").find("[name*='bpOrderUserinfo.ableUserMoney']").val(availableBalance);
- $("#payableAmount").val(payableAmount);
- }
- initStagesFee(); //初始化分期相关金额
- }
- // 展示商品促销活动详情
- function showPromotionDetail(iframe, title) {
- top.$.jBox(iframe, {
- iframeScrolling: 'yes',
- width: $(top.document).width() - 800,
- height: $(top.document).height() - 200,
- persistent: true,
- title: title,
- buttons: {
- "关闭": '-1'
- },
- submit: function(v, h, f) {
- //确定
- var $jboxFrame = top.$('#jbox-iframe');
- var $mainFrame = top.$('#mainFrame');
- if ('1' == v && 1 == $jboxFrame.size() && 1 == $mainFrame.size()) {
- var items = $jboxFrame[0].contentWindow.getCheckedItems();
- if (!items) {
- return false;
- } else if (items.length > 0) {
- console.log($('.productTable'));
- $(('.producttable')).remove();
- setProductList(items[0], false); //设置商品列表
- // initStages();//初始化分期信息
- return true;
- } else {
- top.$.jBox.tip("请选择...");
- return false;
- }
- }
- },
- });
- }
- /**
- * 改变返佣标识
- */
- function updateRebateFlag() {
- var rebateFlag = $("#rebateCheckBox").is(':checked');
- if (rebateFlag) {
- $("#rebateFlag").val(1);
- } else {
- $("#rebateFlag").val(0);
- }
- }
- /**
- * 修改返佣选项是否可见
- */
- function showRebateCheck() {
- var length = $(".productTable").length;
- var rebateDiv = document.getElementById("rebateDiv");
- if (rebateDiv != null) {
- if (length != 0 && length != 1) {
- $("#rebateCheckBox").attr("checked", false);
- $("#rebateFlag").val(0);
- rebateDiv.style.cssText = "display:none";
- } else {
- rebateDiv.style.cssText = "";
- }
- }
- }
- /************************商品相关 end**********************************************************/
|