orderForm.js 110 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436
  1. /**
  2. * Created by 837 on 2017/8/12.
  3. */
  4. var ctx = $("#ctx").val();
  5. var product_index = $('#product_index').val();
  6. // 订单促销活动
  7. var promotionsIds = [];
  8. var totalPromotions = [];
  9. var giftPromotionsIds = [];
  10. // 用户总优惠券
  11. var totalCoupons = [];
  12. // 当前商品可用优惠券
  13. var selectCoupons = [];
  14. // 勾选后的优惠金额
  15. var couponPrice = 0;
  16. // 添加订单true,修改订单false
  17. var initFlag = true;
  18. var orderStatus = 0;
  19. var machineTypes = [];
  20. $(function () {
  21. /** 发票信息 start * */
  22. // var invoiceTitle=$("#orderInvoice\\.invoiceTitle").val();
  23. // if(invoiceTitle !='' && invoiceTitle !=null && invoiceTitle !='null'){
  24. var type = $("#orderInvoice\\.type").val();
  25. if (type == '1') {
  26. $("#invoiceTable").show();
  27. $("#addTaxInvoiceTable").hide();
  28. $("#invoice2").attr("checked", true);
  29. var invoiceTitleType = $("#orderInvoice\\.invoiceTitleType").val();
  30. if (invoiceTitleType == 0) {
  31. $('#orderInvoice_companyTitle').attr('disabled', true);
  32. $('#orderInvoice_companyTitle').attr('value', '');
  33. $('#orderInvoice_corporationTaxNum').attr('disabled', true);
  34. $('#orderInvoice_corporationTaxNum').attr('value', '');
  35. $($(":radio[name='normalTitle_r']").get(1)).attr("checked", 'checked');
  36. $('#orderInvoice_normalTitle').attr('name', 'orderInvoice.invoiceTitle');
  37. }
  38. if (invoiceTitleType == 1) {
  39. $('#orderInvoice_normalTitle').attr('disabled', true);
  40. $('#orderInvoice_normalTitle').attr('value', '');
  41. $('#orderInvoice_normalTitle').attr('name', '');
  42. $($(":radio[name='normalTitle_r']").get(0)).attr("checked", 'checked');
  43. $('#orderInvoice_companyTitle').attr('name', 'orderInvoice.invoiceTitle');
  44. }
  45. $("#orderInvoice\\.corporationTaxNum").attr('value', '');
  46. $("#orderInvoice\\.corporationTaxNum").attr('name', '');
  47. } else if (type == '2') {
  48. $("#invoiceTable").hide();
  49. $("#addTaxInvoiceTable").show();
  50. $("#invoice3").attr("checked", true);
  51. $("#orderInvoice_normalTitle").attr('disabled', true);
  52. $("#orderInvoice\\.invoiceTitleType").attr("value", '1');
  53. $('#orderInvoiceInvoiceTitle3').attr('name', 'orderInvoice.invoiceTitle');
  54. $($(":radio[name='normalTitle_r']").get(0)).attr("checked", 'checked');
  55. } else {
  56. $("#invoiceTable").hide();
  57. $("#addTaxInvoiceTable").hide();
  58. $("#invoice1").attr("checked", true);
  59. $("#orderInvoice_normalTitle").attr('disabled', true);
  60. $("#orderInvoice\\.invoiceTitleType").attr("value", '1');
  61. $("#orderInvoice_corporationTaxNum").attr('value', '');
  62. $("#orderInvoice_corporationTaxNum").attr('name', '');
  63. $($(":radio[name='normalTitle_r']").get(0)).attr("checked", 'checked');
  64. }
  65. //单存在输入时候默认为个人发票类型
  66. $("#orderInvoice\\.invoiceTitle").on('change', function () {
  67. $("#orderInvoice\\.type").val("1"); //优化发票修改
  68. });
  69. $(":radio[name='normalTitle_r']").click(function () {
  70. var index = $(":radio[name='normalTitle_r']").index($(this));
  71. $("#orderInvoice\\.corporationTaxNum").attr('value', '');
  72. $("#orderInvoice\\.corporationTaxNum").attr('name', '');
  73. $("#orderInvoiceInvoiceTitle3").attr('value', '');
  74. $("#orderInvoiceInvoiceTitle3").attr('name', '');
  75. if (index == 0) {
  76. //普通发票的 企业抬头被选中了
  77. $("#orderInvoice\\.invoiceTitleType").val("1");
  78. $("#orderInvoice_normalTitle").attr('disabled', true);
  79. $("#orderInvoice_normalTitle").attr('value', '');
  80. $("#orderInvoice_companyTitle").attr('disabled', false);
  81. $("#orderInvoice_corporationTaxNum").attr('disabled', false);
  82. $('#orderInvoice_companyTitle').attr('name', 'orderInvoice.invoiceTitle');
  83. $('#orderInvoice_corporationTaxNum').attr('name', 'orderInvoice.corporationTaxNum');
  84. } else {
  85. //普通发票的 个人抬头被选中了
  86. $("#orderInvoice\\.invoiceTitleType").val("0");
  87. $("#orderInvoice_companyTitle").attr('disabled', true);
  88. $("#orderInvoice_companyTitle").attr('value', '');
  89. $("#orderInvoice_corporationTaxNum").attr('disabled', true);
  90. $("#orderInvoice_corporationTaxNum").attr('value', '');
  91. $("#orderInvoice_normalTitle").attr('disabled', false);
  92. $('#orderInvoice_companyTitle').attr('name', '');
  93. $('#orderInvoice_normalTitle').attr('name', 'orderInvoice.invoiceTitle');
  94. }
  95. });
  96. $(":radio[name='invoice']").click(function () {
  97. var index = $(":radio[name='invoice']").index($(this));
  98. if (index == 1) { //选中第2个时,div显示
  99. $("#invoiceTable").hide();
  100. $("#addTaxInvoiceTable").show();
  101. $("#orderInvoice\\.type").val("2");
  102. $('#orderInvoice_corporationTaxNum').attr('name', '');
  103. $('#orderInvoice\\.corporationTaxNum').attr('name', 'orderInvoice.corporationTaxNum');
  104. $('#orderInvoice_companyTitle').attr('name', '');
  105. $('#orderInvoice_normalTitle').attr('name', '');
  106. $('#orderInvoiceInvoiceTitle3').attr('name', 'orderInvoice.invoiceTitle');
  107. } else if (index == 0) { //当被选中的不是第1个时,div隐藏
  108. $("#invoiceTable").hide();
  109. $("#addTaxInvoiceTable").hide();
  110. $("#orderInvoice\\.invoiceTitle").val("");
  111. $("#orderInvoice\\.type").val("0"); //优化发票修改
  112. } else { //选中增值税发票
  113. $("#invoiceTable").hide();
  114. $("#addTaxInvoiceTable").show();
  115. $("#orderInvoice\\.type").val("2");
  116. $('#orderInvoice_corporationTaxNum').attr('name', '');
  117. $('#orderInvoice\\.corporationTaxNum').attr('name', 'orderInvoice.corporationTaxNum');
  118. $('#orderInvoice_companyTitle').attr('name', '');
  119. $('#orderInvoice_normalTitle').attr('name', '');
  120. $('#orderInvoiceInvoiceTitle3').attr('name', 'orderInvoice.invoiceTitle');
  121. }
  122. });
  123. /** 发票信息 end * */
  124. $("body").on('change', '.shopNote', function () {
  125. var self = $(this);
  126. var shopID = self.attr('data-shopid');
  127. var val = self.val();
  128. self.next('input[name=shopNote]').val(val + '=' + shopID);
  129. });
  130. /** 修改订单初始化 */
  131. var orderId = $("#orderID").val() * 1;
  132. orderStatus = $("#orderStatus").val() * 1;
  133. if (orderId && orderId > 0) {
  134. var userId = $("#inputForm").find("[name*='bpOrderUserinfo.userId']").val();
  135. // 获取用户总优惠券
  136. getUserCoupons(userId);
  137. // 修改订单初始化商品列表
  138. $('#product_index').val(0);
  139. product_index = 0;
  140. var productList = [];
  141. $('.productTable tbody tr:not(.gift)').each(function (index, element) {
  142. var data = JSON.parse($(this).attr("data-value"));
  143. data.shopId = data.shopID ? data.shopID : data.shopId;
  144. data.productId = data.productID ? data.productID : data.productId;
  145. if (data.productPromotion) {
  146. data.cmPromotion = {
  147. id: data.productPromotion.promotionsId,
  148. isNewRecord: data.productPromotion.isNewRecord,
  149. name: data.productPromotion.name,
  150. type: data.productPromotion.type,
  151. mode: data.productPromotion.mode,
  152. touchPrice: data.productPromotion.touchPrice,
  153. reducedPrice: data.productPromotion.reducedPrice,
  154. status: data.productPromotion.status,
  155. discount: data.productPromotion.discount
  156. };
  157. var tempProduct = {
  158. shopId: data.shopId,
  159. productId: data.productId,
  160. price: data.price,
  161. number: data.num,
  162. totalTax: data.totalAddedValueTax
  163. };
  164. data.productId = data.productID;
  165. data.shopId = data.shopID;
  166. var tempId = data.productPromotion.promotionsId;
  167. if (promotionsIds.indexOf(tempId) >= 0) {
  168. totalPromotions.forEach(function (item) {
  169. if (item.id * 1 === tempId) {
  170. for (var i = 0; i < item.promotionProducts.length; i++) {
  171. if (item.promotionProducts[i].productId == data.productId) {
  172. item.promotionProducts.splice(i--, 1);
  173. }
  174. }
  175. item.promotionProducts.push(tempProduct);
  176. }
  177. })
  178. } else {
  179. promotionsIds.push(tempId);
  180. var tempPromotions = JSON.parse(JSON.stringify(data.cmPromotion));
  181. if (tempPromotions.mode * 1 === 1) {
  182. tempPromotions.reducedPrice = data.price - tempPromotions.touchPrice;
  183. }
  184. if (data.cmPromotion.type * 1 === 3) {
  185. tempPromotions.shopId = data.shopId;
  186. }
  187. /*if(data.cmPromotion.mode*1 === 3){
  188. giftPromotionsIds.push(tempId);
  189. }*/
  190. tempPromotions.promotionProducts = [];
  191. tempPromotions.promotionProducts.push(tempProduct);
  192. totalPromotions.push(tempPromotions);
  193. }
  194. }
  195. data.productPromotion = null;
  196. productList.push(data);
  197. });
  198. $('.productTable tbody tr.gift').each(function (index, element) {
  199. var present = JSON.parse($(this).attr("data-value"));
  200. present.shopId = present.shopID ? present.shopID : present.shopId;
  201. present.productId = present.productID ? present.productID : present.productId;
  202. if (present.productType == 1) {
  203. productList.forEach(function (data) {
  204. if (present.productId == data.productId) {
  205. data.presentNum = present.num;
  206. }
  207. });
  208. }
  209. });
  210. $('.productTable').each(function (index, element) {
  211. $(this).prev('.order-rows').remove();
  212. $(this).remove();
  213. });
  214. initFlag = false;
  215. productList.forEach(function (data) {
  216. setProductList(data);
  217. });
  218. setOrderFee(); //设置底部订单金额
  219. initFlag = true;
  220. }
  221. });
  222. /************************添加会所 start**********************************************************/
  223. /**
  224. * 展示会所选择框
  225. * @param iframe
  226. */
  227. function showClubSelect(iframe) {
  228. top.$.jBox(iframe, {
  229. iframeScrolling: 'yes',
  230. width: $(top.document).width() - 100,
  231. height: $(top.document).height() - 160,
  232. persistent: true,
  233. // showScrolling: false,
  234. title: "选择会所",
  235. bottomText: '请选择一个会所',
  236. buttons: {
  237. "确定": '1',
  238. "关闭": '-1'
  239. },
  240. submit: function (v, h, f) {
  241. //确定
  242. var $jboxFrame = top.$('#jbox-iframe');
  243. var $mainFrame = top.$('#mainFrame');
  244. if ('1' == v && 1 == $jboxFrame.size() && 1 == $mainFrame.size()) {
  245. var items = $jboxFrame[0].contentWindow.getCheckedItems();
  246. // console.log(items);
  247. if (items.length > 0) {
  248. //$jboxFrame[0].contentWindow.setBinding(items);
  249. setSingleSelect(items); //设置选中值
  250. // initStages();//初始化分期信息---分期功能目前已废弃
  251. $('.productTable,.order-rows').remove(); //重新选择会所时清空商品
  252. $('.productTotalFee,.payTotalFee,.payableAmount,.balancePayFee').text('0.00'); //清空金额
  253. $('#surplusBalance,#surplusBalance').text('0.00');
  254. $('.productCount').text('0');
  255. // 设置添加商品显示
  256. $(".addSecondHandProduct").show();
  257. return true;
  258. } else {
  259. top.$.jBox.tip("请选择...");
  260. return false;
  261. }
  262. }
  263. return true;
  264. }
  265. });
  266. }
  267. /**
  268. * 选择会所后设置用户信息
  269. * @param items
  270. */
  271. function setSingleSelect(items) {
  272. var info = eval('(' + items[0] + ')');
  273. $("#curProvince").val(info.province);
  274. $("#curCity").val(info.city);
  275. $("#curTown").val(info.town);
  276. loadProvince(); //加载地址下拉选项
  277. $("#bpOrderUserinfo\\.address").val(info.address); //设置详细地址
  278. console.log(info);
  279. $("#bpOrderUserinfo\\.clubId").val(info.id); //设置会所ID
  280. $("#bpOrderUserinfo\\.userId").val(info.userID);
  281. $("#bpOrderUserinfo\\.firstClubType").val(info.firstClubType ? info.firstClubType :'');
  282. $("#inputForm").find("[name*='bpOrderUserinfo.province']").select2("val", info.province); //设置省份值
  283. $("#inputForm").find("[name*='bpOrderUserinfo.city']").select2("val", info.city);
  284. $("#inputForm").find("[name*='bpOrderUserinfo.town']").select2("val", info.town);
  285. $("#inputForm").find("[name*='bpOrderUserinfo.name']").val(info.name);
  286. $("#inputForm").find("[name*='bpOrderUserinfo.shouHuoRen']").val(info.linkMan1 ? info.linkMan1 : info.linkMan);
  287. $("#inputForm").find("[name*='bpOrderUserinfo.phonee']").val(info.contractPhone1 ? info.contractPhone1 : info.contractPhone);
  288. $("#inputForm").find("[name*='bpOrderUserinfo.mobile']").val(info.contractMobile1 ? info.contractMobile1 : info.contractMobile);
  289. $("#svipFlagLabel").text(1 == info.svipFlag ? '(超级会员)' : '');
  290. $("#availableBalance").html(info.ableUserMoney);
  291. //设置添加商品可见(会所添加添加运费订单公用此方法但是添加运费订单不需要添加商品)
  292. var ui = document.getElementById("shopSelected");
  293. var ui1 = document.getElementById("shopSelected1");
  294. if (ui) {
  295. ui.style.display = "";
  296. ui1.style.display = "none";
  297. }
  298. // 获取用户总优惠券
  299. getUserCoupons(info.userID);
  300. }
  301. function getUserCoupons(userId) {
  302. totalCoupons = [];
  303. $.get($("#ctx").val() + "/order/clubCouponList?userId=" + userId, function (data) {
  304. if (data.code * 1 === 0) {
  305. totalCoupons = data.couponList;
  306. // 展示可选优惠券列表
  307. getShownCouponList();
  308. }
  309. })
  310. }
  311. /************************添加会所 end**********************************************************/
  312. // 兑换优惠券
  313. $("#redeemCoupons").on("click", function () {
  314. var userId = $("#inputForm").find("[name*='bpOrderUserinfo.userId']").val();
  315. if (userId && userId * 1 > 0) {
  316. var html = '<div style="text-align:center;padding-top:12px;"><input id="couponsCode" name="couponsCode" type="text" maxlength="16" placeholder="请输入16位兑换码"></div>';
  317. var submit = function (v, h, f) {
  318. if (f.couponsCode == '' || isNaN(f.couponsCode)) {
  319. $.jBox.tip("请输入兑换码!", 'error', {focusId: "couponsCode"});
  320. }
  321. var bool = new RegExp("^[A-Za-z0-9]{16}$").test(f.couponsCode);
  322. if (!bool) {
  323. // 16位数字和字母
  324. $.jBox.tip("请输入正确的兑换码!", 'error', {focusId: "couponsCode"});
  325. } else {
  326. $.post($("#ctx").val() + "/coupon/cmCouponClub/redeem", {
  327. 'redemptionCode': f.couponsCode,
  328. 'userId': userId
  329. }, function (data) {
  330. if (0 === data.code * 1) {
  331. $.jBox.tip(data.msg, 'info');
  332. // 获取用户总优惠券
  333. getUserCoupons(userId);
  334. } else {
  335. $.jBox.tip(data.msg, 'error');
  336. }
  337. }, "JSON");
  338. }
  339. };
  340. $.jBox(html, {title: "兑换优惠券", buttons: {'立即兑换': true}, submit: submit});
  341. } else {
  342. alertx('请您先选择会所!');
  343. }
  344. });
  345. /************************商品相关 start**********************************************************/
  346. //设置商品(正常)
  347. function editShop(obj) {
  348. var $tr = obj.parents('tr');
  349. var data = $tr.attr("data-value");
  350. data = JSON.parse(data);
  351. var productID = (data.productId == undefined) ? data.productID : data.productId;
  352. var secondHandType = (data.secondHandType == undefined) ? 0 : data.secondHandType;
  353. var discount = (data.discount == undefined) ? 100 : data.discount;
  354. var productCategory = (data.productCategory == undefined) ? 1 : data.productCategory;
  355. var includexTax = (data.includexTax == undefined) ? 2 : data.includexTax;
  356. var invoiceType = (data.invoiceType == undefined) ? 3 : data.invoiceType;
  357. var taxRate = (data.taxRate == undefined) ? 0 : data.taxRate;
  358. var addedValueTax = (data.addedValueTax == undefined) ? 0 : data.addedValueTax;
  359. var totalAddedValueTax = (data.totalAddedValueTax == undefined) ? 0 : data.totalAddedValueTax;
  360. $.jBox.open("iframe:" + ctx + "/bulkpurchase/purchaseProduct/formOrderProduct?productId=" + productID +
  361. "&secondHandType=" +
  362. secondHandType + "&discount=" + discount + "&productCategory=" + productCategory + "&includedTax=" +
  363. includexTax +
  364. "&invoiceType=" + invoiceType + "&taxRate=" + taxRate + "&addedValueTax=" + addedValueTax +
  365. "&totalAddedValueTax" + totalAddedValueTax,
  366. "设置商品", $(top.document).width() - 240, $(top.document).height() - 200, {
  367. top: 36,
  368. persistent: true,
  369. buttons: {
  370. "确定": "ok",
  371. "关闭": true
  372. },
  373. // buttons:{"关闭":true},
  374. bottomText: "设置商品",
  375. submit: function (v, h, f) {
  376. if (v == "ok") {
  377. var $jboxFrame = $('#jbox-iframe');
  378. var items = $jboxFrame[0].contentWindow.getCheckedItems();
  379. if (!items) {
  380. return false;
  381. } else {
  382. console.log(items[0]);
  383. setProductList(items[0], false); //设置商品列表
  384. // initStages();//初始化分期信息
  385. setOrderFee(); //设置底部订单金额
  386. }
  387. return true;
  388. }
  389. },
  390. loaded: function (h) {
  391. //$(".jbox-content", top.document).css("overflow-y","hidden");
  392. }
  393. });
  394. }
  395. // 展示可选优惠券列表
  396. function getShownCouponList() {
  397. selectCoupons = [];
  398. var couponProductIds = [];
  399. var couponProductList = [];
  400. $('.productTable tbody tr:not(.gift)').each(function (index, element) {
  401. var data = JSON.parse($(this).attr("data-value"));
  402. couponProductList.push(data);
  403. couponProductIds.push(data.productId);
  404. });
  405. totalCoupons.forEach(function (coupon) {
  406. var totalAmount = 0;
  407. var couponType = coupon.couponType * 1;
  408. couponProductList.forEach(function (item) {
  409. var productPrice = item.totalFee * 1;
  410. if (couponType === 0) {
  411. if (coupon.productType * 1 === 1) {
  412. //活动券-全商城商品
  413. totalAmount += productPrice;
  414. } else if (coupon.productType * 1 === 2) {
  415. //活动券-指定商品
  416. if (coupon.productIdList.length > 0 && coupon.productIdList.indexOf(item.productId * 1) >= 0) {
  417. totalAmount += productPrice;
  418. }
  419. }
  420. } else if (couponType === 1) {
  421. //品类券
  422. if (coupon.categoryType == item.commodityType) {
  423. totalAmount += productPrice;
  424. }
  425. } else if (couponType === 2 || couponType === 4) {
  426. //用户专享券或新用户券
  427. totalAmount += productPrice;
  428. } else if (couponType === 3) {
  429. //店铺券
  430. if (coupon.shopId == item.shopId) {
  431. totalAmount += productPrice;
  432. }
  433. }
  434. });
  435. if (totalAmount >= coupon.touchPrice) {
  436. selectCoupons.push(coupon);
  437. }
  438. });
  439. setPageCoupon();
  440. }
  441. // 设置页面显示
  442. function setPageCoupon() {
  443. var clubCouponId = $("#clubCouponId").val() * 1;
  444. var html = '<li><label><input type="radio" name="clubCouponId" id="bsy" value="0"><span class="couponDesc none">不使用优惠券</span></label></li>';
  445. selectCoupons.forEach(function (item) {
  446. var checked = '';
  447. var redemptionCode = '';
  448. if (clubCouponId === item.clubCouponId) {
  449. checked = 'checked="checked"';
  450. }
  451. if (!isNaN(item.redemptionCode)) {
  452. redemptionCode = '<span>兑换码:' + item.redemptionCode + '</span>';
  453. }
  454. html += '<li><label>';
  455. html += ' <input type="radio" name="clubCouponId" value="' + item.clubCouponId + '" ' + checked + '>';
  456. html += ' <span class="couponDesc">';
  457. html += ' <span>' + item.couponName + '</span>';
  458. html += redemptionCode;
  459. html += ' <span>' + item.couponDesc + '</span>';
  460. html += ' <span>有效期:' + item.receiveDate + ' - ' + item.useEndDate + '</span>';
  461. html += '</span></label></li>';
  462. });
  463. $("#couponBox").find(".couponContent").html(html);
  464. if (clubCouponId > 0) {
  465. $("#couponBox").find("input[name=clubCouponId][checked=checked]").trigger("change");
  466. }
  467. }
  468. // 勾选优惠券重新计算总价
  469. $("#couponBox").on("change", "input[name=clubCouponId]", function () {
  470. couponPrice = 0;
  471. var clubCouponId = $(this).val() * 1;
  472. selectCoupons.forEach(function (item) {
  473. if (item.clubCouponId * 1 === clubCouponId) {
  474. couponPrice = item.couponAmount;
  475. $("#clubCouponId").val(clubCouponId);
  476. $("#couponAmount").val(couponPrice);
  477. } else if (clubCouponId == 0) {
  478. couponPrice = 0;
  479. $("#clubCouponId").val('');
  480. $("#couponAmount").val(couponPrice);
  481. }
  482. });
  483. // 重新计算总价
  484. setOrderFee();
  485. });
  486. // 设置商品(二手)
  487. function orderSecondHandEditShop(obj) {
  488. var $tr = obj.parents('tr');
  489. var data = $tr.attr("data-value");
  490. data = JSON.parse(data);
  491. var productID = (data.productId == undefined) ? data.productID : data.productId;
  492. $.jBox.open("iframe:" + ctx + "/bulkpurchase/purchaseProduct/orderSecondHandProductForm?productId=" + productID,
  493. "设置商品", $(top.document).width() - 240, $(top.document).height() - 200, {
  494. top: 36,
  495. persistent: true,
  496. buttons: {
  497. "确定": "ok",
  498. "关闭": true
  499. },
  500. bottomText: "设置商品",
  501. submit: function (v, h, f) {
  502. if (v == "ok") {
  503. var $jboxFrame = $('#jbox-iframe');
  504. var items = $jboxFrame[0].contentWindow.getCheckedItems();
  505. if (!items) {
  506. return false;
  507. } else {
  508. console.log(items[0]);
  509. setProductList(items[0], false); //设置商品列表
  510. setOrderFee(); //设置底部订单金额
  511. }
  512. return true;
  513. }
  514. },
  515. loaded: function (h) {
  516. }
  517. });
  518. }
  519. // 修改商品的时候统计下面的订单商品金额
  520. function setShopOrderFee(shopId) {
  521. var totalFee = 0;
  522. $($('#pTable_' + shopId)).find('.totalFee').each(function (index, element) {
  523. totalFee += Number($(this).html());
  524. });
  525. totalPromotions.forEach(function (item) {
  526. if (item.shopId == shopId && item.type == 3 && item.mode == 2) {
  527. var touchPrice = 0;
  528. item.promotionProducts.forEach(function (product) { //计算促销包含税费
  529. touchPrice += (product.number * product.price + product.totalTax * 1);
  530. });
  531. if (touchPrice >= item.touchPrice) {
  532. totalFee -= item.reducedPrice;
  533. }
  534. }
  535. });
  536. $($('#pTable_' + shopId)).prev('div').find('.bmd').html('¥' + totalFee.toFixed(2));
  537. }
  538. //删除商品
  539. function deleteShop(obj) {
  540. var $tr = obj.parents('tr');
  541. var $table = $tr.parents('table');
  542. // 协销赠品
  543. var productId = $tr.attr("id").split("_")[1];
  544. $('.productTable tbody tr.gift_' + productId).each(function (index, element) {
  545. $(this).remove();
  546. });
  547. // 促销
  548. var promotionsId = $tr.find('.tag').attr("data-id");
  549. var thisTouchPrice = 0;
  550. totalPromotions.forEach(function (item) {
  551. if (item.id == promotionsId) {
  552. for (var i = 0; i < item.promotionProducts.length; i++) {
  553. if (item.promotionProducts[i].productId == productId) {
  554. item.promotionProducts.splice(i--, 1);
  555. }
  556. }
  557. item.promotionProducts.forEach(function (p) {
  558. thisTouchPrice += p.number * p.price;
  559. });
  560. if (thisTouchPrice < item.touchPrice) {
  561. $('.productTable tbody tr.promotion_' + promotionsId).each(function (index, element) {
  562. $(this).remove();
  563. });
  564. }
  565. }
  566. });
  567. $tr.remove();
  568. if ($table.find('tr').length < 2) {
  569. //table里面没有商品了 table 也删掉 <2 是因为表头上有一个tr
  570. $table.prev('.order-rows').remove();
  571. $table.remove();
  572. }
  573. var shopId = $table.attr("id").split("_")[1];
  574. setShopOrderFee(shopId);
  575. setOrderFee(); //设置底部订单金额
  576. // initStages();//初始化分期信息
  577. //重新显示添加按钮(针对二手商品)
  578. $(".addSecondHandProduct").show();
  579. }
  580. function resetProductList(setData, ind) {
  581. var productList = [];
  582. var productIdList = [];
  583. var skuIds = [];
  584. //var if (promotionsIds.indexOf(tempId)>=0) {
  585. $('.productTable tbody tr:not(.gift)').each(function (index, element) {
  586. var data = JSON.parse($(this).attr("data-value"));
  587. productList.push(data);
  588. if (data.skuStr) {
  589. var strings = data.skuStr.split("/");
  590. var skuId = strings[0];
  591. skuId = skuId * 1;
  592. skuIds.push(skuId);
  593. } else {
  594. var skuId = "";
  595. if (data.skuList) {
  596. skuId = data.skuList[0].skuId;
  597. } else {
  598. skuId = data.skuId;
  599. }
  600. skuId = skuId * 1;
  601. skuIds.push(skuId);
  602. }
  603. productIdList.push(data.productId);
  604. });
  605. $('.productTable').each(function (index, element) {
  606. $(this).prev('.order-rows').remove();
  607. $(this).remove();
  608. });
  609. promotionsIds = [];
  610. totalPromotions = [];
  611. giftPromotionsIds = [];
  612. if (!setData) { //删除
  613. productList.forEach(function (data) {
  614. setProductList(data, false);
  615. });
  616. } else {
  617. if (ind) {
  618. productList.forEach(function (data) {
  619. setProductList(data, false);
  620. });
  621. }
  622. var skuId;
  623. if (setData.skuStr) {
  624. var strings = setData.skuStr.split("/");
  625. skuId = strings[0];
  626. } else {
  627. skuId = setData.skuList[0].skuId;
  628. }
  629. skuId = skuId * 1;
  630. if (skuIds.indexOf(skuId) >= 0) {
  631. //设置
  632. productList.forEach(function (data) {
  633. if (setData.skuId == data.skuId) {
  634. setProductList(setData, false, ind);
  635. } else {
  636. setProductList(data, false, ind);
  637. }
  638. });
  639. } else {
  640. //新增
  641. productList.forEach(function (data) {
  642. setProductList(data, false, ind);
  643. });
  644. setProductList(setData, false, ind);
  645. }
  646. }
  647. setOrderFee(); //设置底部订单金额
  648. }
  649. function deleteShopProduct(obj) {
  650. console.log('machineTypes',machineTypes)
  651. var skuId = obj.parents('tr').find('.orderProductSkuId').text();
  652. obj.parents('tr').remove();
  653. console.log('skuId======',skuId)
  654. machineTypes = machineTypes.filter(item => item.skuId !== skuId*1);
  655. console.log('machineTypes======',machineTypes)
  656. var $table = obj.parents('tr').parents('table');
  657. if ($table.find('tr').length < 2) {
  658. //table里面没有商品了 table 也删掉 <2 是因为表头上有一个tr
  659. $table.prev('.order-rows').remove();
  660. $table.remove();
  661. }
  662. resetProductList();
  663. if ($('.productTable tbody tr').length === 0) {
  664. setOrderFee();
  665. // 展示可选优惠券列表
  666. getShownCouponList();
  667. }
  668. $(".addSecondHandProduct").show();
  669. }
  670. function editShopProduct(obj) {
  671. var $tr = obj.parents('tr');
  672. var data = $tr.attr("data-value");
  673. data = JSON.parse(data);
  674. var userId = $("#inputForm").find("[name*='bpOrderUserinfo.userId']").val();
  675. var productID = (data.productId == undefined) ? data.productID : data.productId;
  676. var skuId = (data.skuId == undefined) ? data.skuId : data.skuId;
  677. var secondHandType = (data.secondHandType == undefined) ? 0 : data.secondHandType;
  678. var discount = (data.discount == undefined) ? 100 : data.discount;
  679. var productCategory = (data.productCategory == undefined) ? 1 : data.productCategory;
  680. var price = (data.price == undefined) ? 0 : data.price;
  681. var includedTax = (data.includedTax == undefined) ? 2 : data.includedTax;
  682. var invoiceType = (data.invoiceType == undefined) ? 3 : data.invoiceType;
  683. var taxRate = (data.taxRate == undefined) ? 0 : data.taxRate;
  684. var addedValueTax = (data.addedValueTax == undefined) ? 0 : data.addedValueTax;
  685. var totalAddedValueTax = (data.totalAddedValueTax == undefined) ? 0 : data.totalAddedValueTax;
  686. var couponsLogo = (data.couponsLogo == undefined) ? 1 : data.couponsLogo;
  687. var svipReduction = (data.svipReduction == undefined) ? 0 : data.svipReduction;
  688. var svipTaxReduction = (data.svipTaxReduction == undefined) ? 0 : data.svipTaxReduction;
  689. $.jBox.open("iframe:" + ctx + "/bulkpurchase/purchaseProduct/formOrderProduct?productId=" + productID +
  690. "&secondHandType=" + secondHandType +
  691. "&discount=" + discount + "&productCategory=" + productCategory + "&price=" + price + "&includedTax=" +
  692. includedTax + "&userId=" + userId +
  693. "&invoiceType=" + invoiceType + "&taxRate=" + taxRate + "&addedValueTax=" + addedValueTax +
  694. "&totalAddedValueTax=" + totalAddedValueTax + "&couponsLogo=" + couponsLogo + "&svipReduction=" + svipReduction +
  695. "&svipTaxReduction=" + svipTaxReduction,
  696. "设置商品", $(top.document).width() - 240, $(top.document).height() - 200, {
  697. top: 36,
  698. persistent: true,
  699. buttons: {
  700. "确定": "ok",
  701. "关闭": true
  702. },
  703. bottomText: "设置商品",
  704. submit: function (v, h, f) {
  705. if (v == "ok") {
  706. var $jboxFrame = $('#jbox-iframe');
  707. var items = $jboxFrame[0].contentWindow.getCheckedItems();
  708. if (!items) {
  709. return false;
  710. } else {
  711. console.log('设置:' + items[0]);
  712. resetProductList(items[0], skuId); //设置商品列表
  713. }
  714. return true;
  715. }
  716. },
  717. loaded: function (h) {
  718. }
  719. });
  720. }
  721. // 展示商品选择框
  722. function showShopSelect(iframe) {
  723. var userId = $("#inputForm").find("[name*='bpOrderUserinfo.userId']").val();
  724. iframe = iframe + "&userId=" + userId;
  725. top.$.jBox(iframe, {
  726. iframeScrolling: 'yes',
  727. width: $(top.document).width() - 100,
  728. height: $(top.document).height() - 160,
  729. persistent: true,
  730. title: "选择商品",
  731. bottomText: '请从可供选择的项目中选择一个',
  732. buttons: {
  733. "确定": '1',
  734. "关闭": '-1'
  735. },
  736. submit: function (v, h, f) {
  737. //确定
  738. var $jboxFrame = top.$('#jbox-iframe');
  739. var $mainFrame = top.$('#mainFrame');
  740. if ('1' == v && 1 == $jboxFrame.size() && 1 == $mainFrame.size()) {
  741. var items = $jboxFrame[0].contentWindow.getCheckedItems();
  742. if (!items) {
  743. return false;
  744. } else if (items.length > 0) {
  745. console.log('添加:' + JSON.stringify(items[0]));
  746. resetProductList(items[0], 0); //设置商品列表
  747. return true;
  748. } else {
  749. top.$.jBox.tip("请选择...");
  750. return false;
  751. }
  752. }
  753. },
  754. });
  755. }
  756. // 展示优惠券详情
  757. function showCouponDetail(userId, productId) {
  758. var url = ctx + "/coupon/cmCoupon/productDetails?userId=" + userId + "&productId=" + productId;
  759. var title = '';
  760. title = "查看优惠券";
  761. top.$.jBox("iframe:" + url, {
  762. iframeScrolling: 'yes',
  763. width: $(top.document).width() - 600,
  764. height: $(top.document).height() - 250,
  765. persistent: true,
  766. title: title,
  767. buttons: {"确定": '1'}
  768. });
  769. }
  770. // 展示二手商品选择框
  771. function showSencondHandSelect(iframe) {
  772. var userId = $("#inputForm").find("[name*='bpOrderUserinfo.userId']").val();
  773. iframe = iframe + "&userId=" + userId;
  774. top.$.jBox(iframe, {
  775. iframeScrolling: 'yes',
  776. width: $(top.document).width() - 100,
  777. height: $(top.document).height() - 160,
  778. persistent: true,
  779. title: "选择商品",
  780. bottomText: '请从可供选择的项目中选择一个',
  781. buttons: {
  782. "确定": '1',
  783. "关闭": '-1'
  784. },
  785. submit: function (v, h, f) {
  786. //确定
  787. var $jboxFrame = top.$('#jbox-iframe');
  788. var $mainFrame = top.$('#mainFrame');
  789. if ('1' == v && 1 == $jboxFrame.size() && 1 == $mainFrame.size()) {
  790. var items = $jboxFrame[0].contentWindow.getCheckedItems();
  791. if (!items) {
  792. return false;
  793. } else if (items.length > 0) {
  794. console.log($('.productTable'));
  795. $(('.producttable')).remove();
  796. setSeondHandProductList(items[0]); //设置二手商品列表
  797. // 隐藏商品添加入口
  798. $(".addSecondHandProduct").hide();
  799. return true;
  800. } else {
  801. top.$.jBox.tip("请选择...");
  802. return false;
  803. }
  804. }
  805. },
  806. });
  807. }
  808. /**
  809. * 设置商品列表(正常商品)
  810. * @param items
  811. */
  812. function setProductList(data, flag, ind) {
  813. console.log("设置" + JSON.stringify(data));
  814. var skuStr = "";
  815. var skuIdStr = "";
  816. var price = "";
  817. if (data.skuList) {
  818. skuStr = "<td>" + data.skuList[0].unit + "</td>";
  819. skuIdStr = "<td class='orderProductSkuId'>" + data.skuList[0].skuId + "</td>";
  820. price = data.skuList[0].price;
  821. } else {
  822. skuStr = "<td>" + data.unit + "</td>";
  823. skuIdStr = "<td class='orderProductSkuId'>" + data.skuId + "</td>";
  824. price = data.price;
  825. }
  826. //未选择sku,默认sku[0],选择了sku,skustr不为空
  827. if (data.skuStr) {
  828. var strings = data.skuStr.split("/");
  829. var skuId = strings[0];
  830. var index = strings[1] * 1;
  831. skuStr = "<td>" + data.skuList[index].unit + "</td>";
  832. skuIdStr = "<td>" + skuId + "</td>";
  833. //price
  834. price = data.skuList[index].price;
  835. }
  836. var userId = $("#inputForm").find("[name*='bpOrderUserinfo.userId']").val();
  837. var orderStatus = $("#orderStatus").val() ? $("#orderStatus").val() * 1 : 0;
  838. data.productType = 0;
  839. var shopFee = data.shopFee;
  840. var cmPromotion = '';
  841. var ladderPrice = '';
  842. // 如果存在促销活动
  843. if (data.cmPromotion) {
  844. // debugger;
  845. var tempId = data.cmPromotion.id * 1;
  846. data.promotionsId = data.cmPromotion.id;
  847. // 没有折扣,才享受促销优惠
  848. if (data.discount * 1 === 100) {
  849. var tempProduct = {
  850. shopId: data.shopId,
  851. productId: data.productId,
  852. //有skuid后不能直传price,从选中项中取
  853. price: price,
  854. number: data.num,
  855. totalTax: data.totalAddedValueTax
  856. };
  857. if (promotionsIds.indexOf(tempId) >= 0) {
  858. totalPromotions.forEach(function (item) {
  859. if (item.id * 1 === tempId) {
  860. for (var i = 0; i < item.promotionProducts.length; i++) {
  861. if (item.promotionProducts[i].productId == data.productId) {
  862. item.promotionProducts.splice(i--, 1);
  863. }
  864. }
  865. item.promotionProducts.push(tempProduct);
  866. }
  867. })
  868. } else {
  869. promotionsIds.push(tempId);
  870. var tempPromotions = JSON.parse(JSON.stringify(data.cmPromotion));
  871. if (tempPromotions.mode == 1) {
  872. tempPromotions.reducedPrice = data.price - tempPromotions.touchPrice;
  873. }
  874. if (data.cmPromotion.type == 3) {
  875. tempPromotions.shopId = data.shopId;
  876. }
  877. tempPromotions.promotionProducts = [];
  878. tempPromotions.promotionProducts.push(tempProduct);
  879. totalPromotions.push(tempPromotions);
  880. }
  881. if (data.cmPromotion.mode == 1) {
  882. data.totalFee = (data.cmPromotion.touchPrice * data.num + data.totalAddedValueTax * 1);
  883. cmPromotion = '<span class="tag" data-id="' + tempId + '"><em style="background:green">' + data
  884. .cmPromotion.name + '</em>优惠价:' + data.cmPromotion.touchPrice + '</span>';
  885. } else if (data.cmPromotion.mode == 2) {
  886. cmPromotion = '<span class="tag" data-id="' + tempId + '"><em style="background:#F60">' + data
  887. .cmPromotion.name + '</em>满' + data.cmPromotion.touchPrice + '减' + data.cmPromotion.reducedPrice +
  888. '</span>';
  889. } else if (data.cmPromotion.mode == 3) {
  890. cmPromotion = '<span class="tag" data-id="' + tempId + '"><em style="background:purple">' + data
  891. .cmPromotion.name + '</em>满' + data.cmPromotion.touchPrice + '赠送商品' + '</span>';
  892. }
  893. } else {
  894. cmPromotion = '<span class="red">有折扣,不享受促销优惠</span>'
  895. }
  896. } else {
  897. if (data.ladderPriceFlag * 1 === 1) {
  898. ladderPrice = '<br><a href="javascript:;" class="ladderPrice"><span>阶梯价格</span></a>';
  899. if (data.ladderPriceList && data.ladderPriceList.length > 0) {
  900. var ladder = '<p><span>起订量</span><span>价格</span></p>';
  901. for (var i = 0; i < data.ladderPriceList.length; i++) {
  902. ladder += '<p data-num="' + data.ladderPriceList[i].buyNum + '"><span>' + data.ladderPriceList[i]
  903. .buyNum + '</span><span class="price">' + data.ladderPriceList[i].buyPrice +
  904. '</span></p>';
  905. }
  906. ladderPrice = '<br><a href="javascript:;" class="ladderPrice"><span>阶梯价格</span><div class="list">' +
  907. ladder + '</div></a>'
  908. }
  909. }
  910. }
  911. var cmCouponBtn = '---';
  912. if (data.couponsLogo * 1 === 2) {
  913. cmCouponBtn = '<a href="javascript:;" onclick="showCouponDetail(' + userId + ',' + data.productId + ')">查看</a>';
  914. }
  915. var str =
  916. "<tr id='product_" + data.productId + "' data-value='" + JSON.stringify(data) + "' data-index='" +
  917. product_index + "'>" +
  918. "<td>" + data.productId + "</td>" +
  919. skuIdStr +
  920. "<td hidden><input type='hidden' name='orderProduct[" + product_index + "].enabledStatus' id='orderProduct" +
  921. product_index + ".enabledStatus' value='" + JSON.stringify(data) + "'/>" + data.shopId + "</td>" +
  922. "<td hidden>" + data.shopName + "</td>" +
  923. "<td class='fix-width'>" + data.name + "</td><td hidden></td>" +
  924. (data.productCategory == 2 ? "" : ("<td>" + data.shopName + "</td>")) +
  925. skuStr +
  926. "<td>" + data.num + (data.presentNum > 0 ? "(" + data.presentNum + ")" : "") + "</td>" +
  927. //价格
  928. (data.svipPriceFlag == 1 ? "<td>" + data.discountPrice :
  929. (data.discount * 1 === 100 && data.cmPromotion && data.cmPromotion.mode == 1 ? ("<td><del>" + price +
  930. "</del>") : ("<td>" + price))) +
  931. ((data.svipPriceFlag == 1 || (data.includedTax != null && data.includedTax != '' && data.includedTax != 2)) ? "<label style='color: red'>(" : "") +
  932. (data.svipPriceFlag == 1 ? "超级会员价" : "") +
  933. ((data.svipPriceFlag == 1 && (data.includedTax != null && data.includedTax != '' && data.includedTax != 2)) ? "," : "") +
  934. (data.includedTax == 1 ? "含税" : data.includedTax == 0 && (data
  935. .invoiceType == 1 || data.invoiceType == 2) ? "不含税-能开票" : data
  936. .includedTax != '' && data.includedTax == 0 && data.invoiceType == 3 ?
  937. "不含税-不能开票" : "") +
  938. ((data.svipPriceFlag == 1 || (data.includedTax != null && data.includedTax != '' && data.includedTax != 2)) ? ")</label>" : "") +
  939. "</td>" +
  940. "<td>" + data.discount + "</td>" +
  941. (data.discount * 1 === 100 && data.cmPromotion && data.cmPromotion.mode == 1 ? ("<td><del>" + data
  942. .discountPrice + "</del></td>") : ("<td>" + data.discountPrice +
  943. ladderPrice + "</td>")) +
  944. (data.includedTax != '' && (data.includedTax == 0 && data.invoiceType == 3) ? ("<td>---</td>") : data
  945. .includedTax == 2 ? ("<td>0%</td>") : ("<td>" + data.taxRate + "%</td>")) +
  946. (data.includedTax == 1 || (data.includedTax != '' && data.includedTax == 0 && data.invoiceType == 3) ? (
  947. "<td>---</td>") : data.addedValueTax == null ? ("<td>0</td>") : ("<td>" + data.addedValueTax + "</td>")) +
  948. (data.includedTax == 1 || (data.includedTax != '' && data.includedTax == 0 && data.invoiceType == 3) ? (
  949. "<td>---</td>") : data.totalAddedValueTax == null ? ("<td>0</td>") : ("<td>" + data.totalAddedValueTax +
  950. "</td>")) +
  951. "<td class='totalFee'>" + Number(data.totalFee).toFixed(2) + "</td>" +
  952. // "<td>"+ Math.round(shopFee*100)/100 +"</td>"+
  953. "<td>" + (data.buyAgainFlag == 1 ? "是" : "否") + "</td>" +
  954. ((data.productCategory == 2) ? "" : "<td>" + cmPromotion + "</td>") +
  955. ((data.productCategory == 2) ? "" : "<td>" + cmCouponBtn + "</td>") +
  956. "<td>" + (orderStatus != 0 ? "" : (data.productCategory == 2) ?
  957. "<a href='javascript:void(0);' onclick='orderSecondHandEditShop($(this))'>设置</a>&nbsp;&nbsp;<a href='javascript:void(0);' onclick='deleteShopProduct($(this))'>删除商品</a>" :
  958. "<a href='javascript:void(0);' onclick='editShopProduct($(this))'>设置</a>&nbsp;&nbsp;<a href='javascript:void(0);' onclick='deleteShopProduct($(this))'>删除商品</a>"
  959. ) +
  960. "</td>" +
  961. "</tr>";
  962. appendProductList(str, data, cmPromotion, ind);
  963. var firstClubType = $("#inputForm").find("[name*='bpOrderUserinfo.firstClubType']").val();
  964. const hasSku = machineTypes.find(item => item.skuId === data.skuId)
  965. !hasSku && machineTypes.push({ machineType : data.machineType , skuId: data.skuId })
  966. console.log('machineTypes',machineTypes)
  967. if(firstClubType !== '1' && machineTypes.find(item => item.machineType === '3')){
  968. $('#checkedTips').show();
  969. }else{
  970. $('#checkedTips').hide();
  971. }
  972. }
  973. function appendProductList(str, data, cmPromotion, ind) {
  974. // debugger
  975. //把表中存在的删除
  976. var removeBeforeSoon = false; //是这一次移除
  977. var removeEle;
  978. var skuId;
  979. if (data.skuStr) {
  980. var strings = data.skuStr.split("/");
  981. skuId = strings[0];
  982. } else {
  983. if (data.skuList) {
  984. skuId = data.skuList[0].skuId;
  985. } else {
  986. skuId = data.skuId;
  987. }
  988. }
  989. skuId = skuId * 1;
  990. $('.productTable tbody tr:not(.gift)').each(function (index, element) {
  991. if ($(this).find("td:nth-child(2)").html() == skuId) {
  992. removeEle = $(this).parent();
  993. $(this).remove();
  994. removeBeforeSoon = true;
  995. }
  996. });
  997. if (removeBeforeSoon) {
  998. //走到这里 说明是修改
  999. removeEle.append(str);
  1000. } else {
  1001. //这里就是新加了 //先看有没有这个 当前这个商品的供应商的table
  1002. if ($('#pTable_' + data.shopId).length != 0) {
  1003. $('#pTable_' + data.shopId + ' tbody').append(str);
  1004. } else {
  1005. appendShopOrderHead(data, str, cmPromotion);
  1006. }
  1007. }
  1008. setShopOrderFee(data.shopId);
  1009. // setOrderFee(); //设置底部订单金额
  1010. product_index++;
  1011. // 设置赠品
  1012. setGiftHtmlList(data, cmPromotion);
  1013. // 展示可选优惠券列表
  1014. getShownCouponList();
  1015. }
  1016. function appendShopOrderHead(data, str, cmPromotion) {
  1017. var html = '<div class="order-rows">' +
  1018. '<br><p>' +
  1019. '<span class="fix-right-margin"><label>下单时间:</label></span>' +
  1020. '<span class="fix-right-margin"><label>子订单号(ID):</label></span>' +
  1021. '<span class="fix-right-margin"><label>子订单金额:</label><span class="bmd"></span></span>' +
  1022. '</p>' +
  1023. '<p> <label>供应商:</label>' + data.shopName + (data.cmPromotion && data.cmPromotion.type == 3 ? cmPromotion :
  1024. '') + '</p>' +
  1025. '<p><span><label>留言:</label>' +
  1026. "<input id='shopID_" + data.shopId + "' type='text' class='shopNote' data-shopid='" + data.shopId + "'>" +
  1027. '<input type="hidden" name="shopNote">' +
  1028. '</span></p>' +
  1029. '</div>' + '<table id="pTable_' + data.shopId +
  1030. '" class="productTable table table-striped table-bordered table-condensed">' +
  1031. '<thead>' +
  1032. '<tr>' +
  1033. '<th>商品ID</th>' +
  1034. '<th>skuId</th>' +
  1035. '<th hidden></th>' +
  1036. '<th hidden></th>' +
  1037. '<th class="fix-width">商品名称</th><th hidden></th>' +
  1038. ((data.productCategory == 2) ? '' : '<th>供应商名称</th>') +
  1039. '<th>规格</th>' +
  1040. '<th>数量(赠品数)</th>' +
  1041. '<th>单价</th>' +
  1042. '<th>折扣</th>' +
  1043. '<th>折后单价</th>' +
  1044. '<th>税率</th>' +
  1045. '<th>单个税费</th>' +
  1046. '<th>税费</th>' +
  1047. '<th>总价</th>' +
  1048. /*'<th>应付供应商</th>' +*/
  1049. '<th>能否复购</th>' +
  1050. ((data.productCategory == 2) ? '' : '<th>促销活动</th>') +
  1051. ((data.productCategory == 2) ? "" : "<td>优惠券</td>") +
  1052. '<th>操作</th>' +
  1053. '</tr>' +
  1054. '</thead>' +
  1055. '<tbody>' + str + '</tbody></table>';
  1056. $('#product_index').before(html);
  1057. }
  1058. function setGiftHtmlList(data, cmPromotion) {
  1059. console.log("设置赠品" + JSON.stringify(data));
  1060. if (data.presentNum > 0) {
  1061. // 已经添加的,重新添加
  1062. $('.productTable tbody tr.gift_' + data.skuId).each(function (index, element) {
  1063. $(this).remove();
  1064. });
  1065. // debugger;
  1066. var skuStr = "赠品";
  1067. if (data.skuStr) {
  1068. var strings = data.skuStr.split("/");
  1069. var index = strings[1] * 1;
  1070. skuStr = data.skuList[index].unit;
  1071. } else {
  1072. skuStr = data.skuList[0].unit;
  1073. }
  1074. var present = JSON.parse(JSON.stringify(data));
  1075. present.productType = 1;
  1076. present.num = data.presentNum;
  1077. present.price = 0;
  1078. present.discountPrice = 0;
  1079. present.orderProductId = '';
  1080. present.orderProductID = '';
  1081. var giftStr = "<tr id='product_gift_" + present.productId + "' class='gift gift_" + present.productId +
  1082. "' data-value='" + JSON.stringify(present) + "' data-index='" + product_index + "'>" +
  1083. "<td>" + present.productId + "</td>" +
  1084. "<td>" + present.skuId + "</td>" +
  1085. "<td hidden><input type='hidden' name='orderProduct[" + product_index +
  1086. "].enabledStatus' id='orderProduct" + product_index + ".enabledStatus' value='" + JSON.stringify(present) +
  1087. "'/>" + present.shopId + "</td>" +
  1088. "<td hidden>" + present.shopName + "</td>" +
  1089. "<td class='fix-width'><i class='red'>协商赠品:</i>" + present.name + "</td><td hidden></td>" +
  1090. "<td>" + present.shopName + "</td>" +
  1091. "<td>" + skuStr + "</td>" +
  1092. "<td>" + present.num + "</td>" +
  1093. "<td>0</td>" +
  1094. "<td>100</td>" +
  1095. "<td>0</td>" +
  1096. "<td>0</td>" +
  1097. "<td>0</td>" +
  1098. "<td>0</td>" +
  1099. "<td>0</td>" +
  1100. /*"<td>"+ Math.round(present.shopFee*100)/100 +"</td>"+*/
  1101. "<td>否</td>" +
  1102. "<td></td>" +
  1103. "<td></td>" +
  1104. "</tr>";
  1105. product_index++;
  1106. appendGiftsList(present, giftStr, cmPromotion);
  1107. }
  1108. if (data.cmPromotion && data.cmPromotion.mode == 3) {
  1109. var thisTouchPrice = 0;
  1110. totalPromotions.forEach(function (item) {
  1111. if (data.cmPromotion.id == item.id) {
  1112. item.promotionProducts.forEach(function (p) {
  1113. thisTouchPrice += (p.number * p.price + p.totalTax * 1);
  1114. });
  1115. }
  1116. });
  1117. //本单总价>=满赠条件金额
  1118. if (thisTouchPrice >= data.cmPromotion.touchPrice) {
  1119. if (giftPromotionsIds.indexOf(data.cmPromotion.id) < 0) {
  1120. // 已经添加的,重新添加
  1121. $('.productTable tbody tr.promotion_' + cmPromotion.id).each(function (index, element) {
  1122. $(this).remove();
  1123. });
  1124. // 记录赠品促销
  1125. giftPromotionsIds.push(data.cmPromotion.id);
  1126. // 获取赠品
  1127. var getGiftPath = $('#ctx').val() + '/product/cmPromotions/getGifts';
  1128. $.getJSON(getGiftPath, {
  1129. id: data.cmPromotion.id
  1130. }, function (res) {
  1131. if (res && res.length > 0) {
  1132. res.forEach(function (gift) {
  1133. gift.productType = 2;
  1134. gift.price = 0;
  1135. gift.discountPrice = 0;
  1136. gift.promotionsId = data.cmPromotion.id;
  1137. gift.orderProductId = '';
  1138. gift.orderProductID = '';
  1139. if ($("#product_promotion_" + gift.productId).length > 0) {
  1140. var pageGift = JSON.parse($("#product_promotion_" + gift.productId)
  1141. .attr("data-value"));
  1142. if (gift.discounts * 1 === 1) {
  1143. var b = Math.floor(thisTouchPrice / data.cmPromotion.touchPrice);
  1144. gift.num = gift.num * 1 * b + pageGift.num * 1;
  1145. } else {
  1146. gift.num = gift.num * 1 + pageGift.num * 1;
  1147. }
  1148. $("#product_promotion_" + gift.productId).remove();
  1149. }
  1150. if (gift.discounts * 1 === 1) {
  1151. var b = Math.floor(thisTouchPrice / data.cmPromotion.touchPrice);
  1152. gift.num = gift.num * 1 * b;
  1153. } else {
  1154. gift.num = gift.num * 1;
  1155. }
  1156. var giftStr = "<tr id='product_promotion_" + gift.productId +
  1157. "' class='gift promotions promotion_" + data.cmPromotion.id +
  1158. "' data-value='" + JSON.stringify(gift) + "' gift-index='" +
  1159. product_index + "'>" +
  1160. "<td>" + gift.productId + "</td>" +
  1161. "<td>" + 0 + "</td>" +
  1162. "<td hidden><input type='hidden' name='orderProduct[" + product_index +
  1163. "].enabledStatus' id='orderProduct" + product_index +
  1164. ".enabledStatus' value='" + JSON.stringify(gift) + "'/>" + gift.shopId +
  1165. "</td>" +
  1166. "<td class='fix-width'><i class='red'>促销赠品:</i>" + gift.name +
  1167. "<td>" + gift.shopName + "</td>" +
  1168. "</td><td hidden></td>" +
  1169. "<td>赠品</td>" +
  1170. "<td>" + gift.num + "</td>" +
  1171. "<td>0</td>" +
  1172. "<td>100</td>" +
  1173. "<td>0</td>" +
  1174. "<td>0</td>" +
  1175. "<td>0</td>" +
  1176. "<td>0</td>" +
  1177. "<td>0</td>" +
  1178. /*"<td>"+ Math.round(gift.shopFee*100)/100 +"</td>"+*/
  1179. "<td>否</td>" +
  1180. "<td></td>" +
  1181. "<td></td>" +
  1182. "</tr>";
  1183. product_index++;
  1184. appendGiftsList(gift, giftStr, cmPromotion);
  1185. });
  1186. }
  1187. });
  1188. }
  1189. }
  1190. }
  1191. // 重新设置底部订单金额
  1192. // setOrderFee();
  1193. // 重新设置返佣订单选项
  1194. showRebateCheck();
  1195. }
  1196. function appendGiftsList(gift, giftStr, cmPromotion) {
  1197. if ($('#pTable_' + gift.shopId).length != 0) {
  1198. $('#pTable_' + gift.shopId + ' tbody').append(giftStr);
  1199. } else {
  1200. appendShopOrderHead(gift, giftStr, cmPromotion);
  1201. }
  1202. // 重新设置底部订单金额
  1203. setOrderFee();
  1204. }
  1205. /**
  1206. * 设置商品列表(二手商品)
  1207. * @param items
  1208. */
  1209. function setSeondHandProductList(data) {
  1210. console.log(data);
  1211. data.productType = 0;
  1212. var productID = (data.productId == undefined) ? data.productID : data.productId;
  1213. //把表中存在的删除
  1214. var removeBeforeSoon = false; //是这一次移除
  1215. var removeEle;
  1216. $('.productTable tbody tr').each(function (index, element) {
  1217. if ($(this).find("td:nth-child(1)").html() == productID) {
  1218. removeEle = $(this).parent();
  1219. $(this).remove();
  1220. removeBeforeSoon = true;
  1221. }
  1222. });
  1223. var buyAgain = "<td>否</td>";
  1224. var str = '';
  1225. var shopFee = data.shopFee;
  1226. str +=
  1227. "<tr id='product_" + productID + "' data-value='" + JSON.stringify(data) + "' data-index='" + product_index +
  1228. "'>" +
  1229. "<td>" + productID + "</td>" +
  1230. "<td hidden>" + data.shopId + "</td>" +
  1231. "<td hidden>" + data.shopName + "</td>" +
  1232. "<td class='fix-width'>" + data.name + "</td>" +
  1233. "<td class='fix-width' hidden>" + "<input type='hidden' name='orderProduct[" + product_index +
  1234. "].enabledStatus' id='orderProduct" + product_index + ".enabledStatus'/>" + data.shopName + "</td>" +
  1235. "<td>" + data.num + "(" + data.presentNum + ")" + "</td>" +
  1236. "<td>" + data.price + "</td>" +
  1237. "<td>" + data.discount + "</td>" +
  1238. "<td>" + data.discountPrice + "</td>" +
  1239. "<td>" + data.taxRate + "</td>" +
  1240. "<td>" + data.addedValueTax + "</td>" +
  1241. "<td>" + data.totalAddedValueTax + "</td>" +
  1242. "<td class='totalFee'>" + data.totalFee + "</td>" +
  1243. /*"<td>"+ Math.round(shopFee*100)/100 +"</td>"+*/
  1244. // 以下三个应付不显示,但是内容值参与计算并保存---关闭控制入口移动到财务管理中控制20181201
  1245. // "<td>"+ data.shopFee+"</td>"+
  1246. // "<td>"+ data.otherFee +"</td>"+
  1247. // "<td>"+ data.cmFee +"</td>"+
  1248. buyAgain +
  1249. "<td>" +
  1250. "<a href='javascript:void(0);' onclick='orderSecondHandEditShop($(this))'>设置</a>&nbsp;&nbsp;" +
  1251. "<a href='javascript:void(0);' onclick='deleteShop($(this))'>删除商品</a>" +
  1252. "</td>" +
  1253. "</tr>";
  1254. if (removeBeforeSoon) {
  1255. removeEle.append(str);
  1256. //走到这里 说明是修改
  1257. } else {
  1258. //这里就是新加了
  1259. //先看有没有这个 当前这个商品的供应商的table
  1260. if ($('#pTable_' + data.shopId).length != 0) {
  1261. $('#pTable_' + data.shopId + ' tbody').append(str);
  1262. } else {
  1263. var html = '<div class="order-rows">' +
  1264. '<span class="fix-right-margin"><label>下单时间:</label></span>' +
  1265. '<span class="fix-right-margin"><label>子订单号(ID):</label></span>' +
  1266. '<span class="fix-right-margin"><label>子订单金额:</label><span class="bmd"></span></span>' +
  1267. '<br>' +
  1268. '<span><label>留言:</label>' +
  1269. "<input id='shopID_" + data.shopId + "' type='text' class='shopNote' data-shopid='" + data.shopId +
  1270. "'>" +
  1271. '<input type="hidden" name="shopNote">' +
  1272. '</span>' +
  1273. '</div>' + '<table id="pTable_' + data.shopId +
  1274. '" class="productTable table table-striped table-bordered table-condensed">' +
  1275. '<thead>' +
  1276. '<tr>' +
  1277. '<th>商品ID</th>' +
  1278. '<th hidden></th>' +
  1279. '<th hidden></th>' +
  1280. '<th class="fix-width">商品名称</th>' +
  1281. '<th class="fix-width" hidden>供应商名称</th>' +
  1282. '<th>数量(赠品数)</th>' +
  1283. '<th>单价</th>' +
  1284. '<th>折扣</th>' +
  1285. '<th>折后单价</th>' +
  1286. '<th>税率</th>' +
  1287. '<th>单个税费</th>' +
  1288. '<th>税费</th>' +
  1289. '<th>总价</th>' +
  1290. /*'<th>应付供应商</th>' +*/
  1291. '<th>能否复购</th>' +
  1292. '<th>操作</th>' +
  1293. '</tr>' +
  1294. '</thead>' +
  1295. '<tbody>' + str + '</tbody></table>';
  1296. $('#product_index').before(html);
  1297. }
  1298. }
  1299. setShopOrderFee(data.shopId);
  1300. setOrderFee(); //设置底部订单金额
  1301. product_index++;
  1302. }
  1303. //设置订单金额信息
  1304. function setOrderFee() {
  1305. //不考虑经理折扣、运费,此时 商品总金额=订单总额=应付总额
  1306. var productTotalFee = 0, //商品总金额
  1307. productCount = 0, // 商品总数
  1308. presentCount = 0, //协商赠送商品数
  1309. giftCount = 0, //促销赠品数
  1310. orderTotalFee = 0, //订单总额
  1311. reducedPrice = 0, //促销满减
  1312. payTotalFee = 0, //应付总额
  1313. svipFullReduction = 0; //超级会员优惠
  1314. var couponPrice = $("#couponAmount").val() ? $("#couponAmount").val() * 1 : 0;
  1315. $('.productTable tbody tr:not(.gift)').each(function (index, element) {
  1316. var obj = JSON.parse($(this).attr("data-value"));
  1317. productTotalFee = ((Number(productTotalFee) * 100 + Number(obj.num * obj.price) * 100 + Number(obj
  1318. .totalAddedValueTax) * 100) / 100 + Number(obj.svipTaxReduction)).toFixed(2);
  1319. productCount = Number(productCount) + Number(obj.num);
  1320. presentCount = Number(presentCount) + Number(obj.presentNum);
  1321. orderTotalFee = ((Number(orderTotalFee) * 100 + Number(obj.totalFee) * 100) / 100).toFixed(2);
  1322. payTotalFee = ((Number(payTotalFee) * 100 + Number(obj.totalFee) * 100) / 100).toFixed(2);
  1323. svipFullReduction = ((Number(svipFullReduction) * 100 + Number(obj.svipReduction) * obj.num * 100) / 100).toFixed(2);
  1324. });
  1325. $('.productTable tbody tr.promotions').each(function (index, element) {
  1326. var obj = JSON.parse($(this).attr("data-value"));
  1327. giftCount = Number(giftCount) + Number(obj.num);
  1328. });
  1329. // 计算促销折扣
  1330. totalPromotions.forEach(function (item) {
  1331. console.log(totalPromotions);
  1332. if (item.mode == 2) {
  1333. var touchPrice = 0;
  1334. item.promotionProducts.forEach(function (product) {
  1335. touchPrice += (product.number * product.price + product.totalTax * 1);
  1336. });
  1337. if (touchPrice >= item.touchPrice) {
  1338. if (item.discount * 1 === 1) {
  1339. var b = Math.floor(touchPrice / item.touchPrice);
  1340. reducedPrice += (b * item.reducedPrice);
  1341. payTotalFee -= reducedPrice;
  1342. } else {
  1343. reducedPrice += item.reducedPrice;
  1344. payTotalFee -= item.reducedPrice;
  1345. }
  1346. }
  1347. }
  1348. });
  1349. // 优惠券折扣
  1350. if (couponPrice > 0) {
  1351. orderTotalFee -= couponPrice;
  1352. payTotalFee -= couponPrice;
  1353. }
  1354. $(".productTotalFee").text((productTotalFee * 1).toFixed(2));
  1355. $(".promotionFullReduction").text((reducedPrice * 1).toFixed(2));
  1356. $(".couponPrice").text((couponPrice * 1).toFixed(2));
  1357. $(".productCount").text(productCount);
  1358. $(".presentCount").text(presentCount + giftCount);
  1359. $(".presentCount1").text(presentCount + giftCount);
  1360. $("#presentCount").val(presentCount);
  1361. $("#promotionalGiftsCount").val(giftCount);
  1362. $(".orderTotalFee").text(orderTotalFee);
  1363. $(".payTotalFee").text(payTotalFee);
  1364. $(".svipFullReduction").text(svipFullReduction);
  1365. $("#svipFullReduction").val(svipFullReduction);
  1366. $("#discount").val('0.00');
  1367. setProductTotalFee(); //重新设置经理折扣
  1368. }
  1369. // 修改数量
  1370. function changenum(index) {
  1371. var $num = $("#num" + index);
  1372. var numVal = $num.val();
  1373. var $checkItem = $("#check-item" + index);
  1374. var orderProductStr = $($checkItem).val();
  1375. var obj = JSON.parse(orderProductStr);
  1376. if (numVal != null && numVal != "" && typeof (numVal) != "undefined") {
  1377. if (parseInt(numVal) + "" != numVal || parseInt(numVal) < 1) {
  1378. alertx("数量必须大于0,并且是一个整数");
  1379. $num.val(obj["num"]);
  1380. return;
  1381. }
  1382. obj["num"] = numVal;
  1383. setLadderPrice(obj, numVal, index);
  1384. var result = JSON.stringify(obj);
  1385. $($checkItem).val(result);
  1386. //重新计算税费
  1387. taxRateVal(index);
  1388. } else {
  1389. $num.val(obj["num"]);
  1390. alertx("您输入的数量有误,请重新输入");
  1391. }
  1392. }
  1393. //加减数量
  1394. function presentNum(index, type) {
  1395. var $num = $("#num" + index);
  1396. var numVal = $num.val();
  1397. if (numVal != null && numVal != "" && typeof (numVal) != "undefined") {
  1398. if (type == 'del') {
  1399. numVal = parseInt(numVal) - 1;
  1400. } else if (type == 'add') {
  1401. numVal = parseInt(numVal) + 1;
  1402. }
  1403. if (numVal < 1) {
  1404. alertx("商品数量不能小于0")
  1405. } else {
  1406. $num.val(numVal);
  1407. //重新设置选中json对象值
  1408. var $checkItem = $("#check-item" + index);
  1409. var orderProductStr = $($checkItem).val();
  1410. var obj = JSON.parse(orderProductStr);
  1411. obj["num"] = numVal;
  1412. setLadderPrice(obj, numVal, index);
  1413. var result = JSON.stringify(obj);
  1414. $($checkItem).val(result);
  1415. //重新计算税费
  1416. taxRateVal(index);
  1417. }
  1418. }
  1419. }
  1420. function setLadderPrice(obj, numVal, index) {
  1421. if (obj["ladderPriceFlag"] * 1 === 1) {
  1422. // debugger;
  1423. var ladderList = obj["ladderPriceList"];
  1424. var resultLadder = 0;
  1425. for (var i = 0; i < ladderList.length; i++) {
  1426. if (numVal >= ladderList[i]["buyNum"]) {
  1427. resultLadder = i;
  1428. }
  1429. }
  1430. obj["price"] = ladderList[resultLadder]["buyPrice"];
  1431. obj["discountPrice"] = ladderList[resultLadder]["buyPrice"];
  1432. $("#check-item" + index).parents("tr").find("#price" + index).val(ladderList[resultLadder]["buyPrice"]);
  1433. $("#check-item" + index).parents("tr").find("#priceLabel" + index).text(ladderList[resultLadder]["buyPrice"]);
  1434. $("#check-item" + index).parents("tr").find("#discountPrice" + index).val(ladderList[resultLadder]["buyPrice"]);
  1435. if (numVal < ladderList[0]["buyNum"]) {
  1436. var old = $("#oldPrice" + index).val();
  1437. $("#check-item" + index).parents("tr").find("#price" + index).val(old);
  1438. $("#check-item" + index).parents("tr").find("#priceLabel" + index).text(old);
  1439. $("#check-item" + index).parents("tr").find("#discountPrice" + index).val(old);
  1440. }
  1441. }
  1442. }
  1443. function showView(index) {
  1444. var $num = $("#num" + index);
  1445. //重置数量
  1446. $num.val(1);
  1447. alertx("二手仪器购买数量只能为1");
  1448. }
  1449. // 商品折扣比例
  1450. function discountPriceVal(index) {
  1451. var discount = $("#discount" + index).val(); //折扣
  1452. discount = Number(discount);
  1453. var $checkItem = $("#check-item" + index);
  1454. var orderProductStr = $($checkItem).val();
  1455. var obj = JSON.parse(orderProductStr);
  1456. if (!isNaN(discount)) {
  1457. if (discount.length > 8 || discount.length < 0) {
  1458. $("#discount" + index).val(obj["discount"]);
  1459. alertx("折扣最大为5位小数");
  1460. } else if (discount > 100 || discount < 0) {
  1461. $("#discount" + index).val(obj["discount"]);
  1462. alertx("输入的折扣有误")
  1463. } else {
  1464. var svipPriceFlag = $("#svipPriceFlag" + index).val();
  1465. var price;
  1466. if (1 == svipPriceFlag) {
  1467. price = Number($("#svipDiscountPrice" + index).text());// 拿到超级会员价
  1468. } else {
  1469. price = Number($("#price" + index).val()); //拿到单价
  1470. }
  1471. //折后单价=折扣*当前价格/100
  1472. var discountPrice = ((discount * 100000 * price) / (100 * 100000)).toFixed(2);
  1473. $("#discountPrice" + index).val(discountPrice);
  1474. $("#discount" + index).val(discount);
  1475. var $checkItem = eval('(' + $("#check-item" + index).val() + ')');
  1476. $checkItem["discount"] = discount + ""; //重新设置折扣
  1477. $checkItem["discountPrice"] = discountPrice + ""; //重新设置折扣单价
  1478. $("#check-item" + index).val(JSON.stringify($checkItem));
  1479. //重新计算税费
  1480. taxRateVal(index)
  1481. }
  1482. } else {
  1483. alertx("商品折扣只能输入数字");
  1484. $("#discount" + index).val(obj.discount);
  1485. }
  1486. }
  1487. //输入折扣单价重新计算折扣
  1488. function countDiscount(index) {
  1489. var svipPriceFlag = $("#svipPriceFlag" + index).val(); //是否使用超级会员价
  1490. var price;
  1491. if (1 == svipPriceFlag) {
  1492. price = Number($("#svipDiscountPrice" + index).text());// 拿到超级会员价
  1493. } else {
  1494. price = Number($("#price" + index).val()); //拿到单价
  1495. }
  1496. var discountPrice = Number($("#discountPrice" + index).val()); //拿到折后单价
  1497. //判断必须小于等于商品单价
  1498. if (discountPrice > price) {
  1499. alertx("折后单价不能大于当前单价");
  1500. $("#discountPrice" + index).val(price); //清楚输入值设置为原始单价
  1501. $("#discount" + index).val(100);
  1502. return;
  1503. }
  1504. var discount = ((discountPrice / price).toFixed(7) * 100);
  1505. //设置折扣
  1506. $("#discount" + index).val(discount);
  1507. //重新计算税费和总价
  1508. var $checkItem = $("#check-item" + index);
  1509. var orderProductStr = $($checkItem).val();
  1510. var obj = JSON.parse(orderProductStr);
  1511. if (!isNaN(discount)) {
  1512. if (discount > 100 || discount < 0) {
  1513. $("#discount" + index).val(obj["discount"]);
  1514. alertx("输入的折扣有误")
  1515. } else {
  1516. var $checkItem = eval('(' + $("#check-item" + index).val() + ')');
  1517. $checkItem["discount"] = discount + ""; //重新设置折扣
  1518. $checkItem["discountPrice"] = discountPrice + ""; //重新设置折扣单价
  1519. $("#check-item" + index).val(JSON.stringify($checkItem));
  1520. //重新计算税费
  1521. taxRateVal(index)
  1522. }
  1523. }
  1524. }
  1525. //计算税费
  1526. function taxRateVal(index) {
  1527. var $checkItem = eval('(' + $("#check-item" + index).val() + ')');
  1528. var taxRateLabel = Number($("#taxRateLabel").val());
  1529. var taxRate = isNaN(taxRateLabel) ? Number($("#taxRate" + index).val()) : taxRateLabel; //税率
  1530. var supplierTaxRate = Number($checkItem["supplierTaxRate"]); //供应商税率
  1531. var numVal = $("#num" + index).val(); //商品数量
  1532. var presentNum = $("#presentNum" + index).val(); //商品赠品数量-计算税费需要包含赠品
  1533. if (presentNum == "" || presentNum == "undefined") {
  1534. presentNum = 0;
  1535. $("#presentNum" + index).val(0);
  1536. }
  1537. var totalNumVal = numVal * 1 + presentNum * 1; //统计赠品和购买商品数量
  1538. var discountPrice = $("#discountPrice" + index).val(); //折后单价
  1539. var $checkItem = eval('(' + $("#check-item" + index).val() + ')');
  1540. if ($checkItem["name"] == '' || $checkItem["name"] == null || $checkItem["name"] == 'null' || typeof ($checkItem[
  1541. "name"]) == "undefined") {
  1542. $checkItem["name"] = $checkItem.purchaseProductName + "";
  1543. }
  1544. var mode = $("#mode" + index).val(); //是否参与优惠活动
  1545. var touchPrice = $("#touchPrice" + index).val(); //优惠价/满减满赠设定价
  1546. var reducedPrice = $("#reducedPrice" + index).val(); //减免价格
  1547. var name = $("#promotionName" + index).val(); //促销活动名称
  1548. var promotionsId = $("#promotionsId" + index).val(); //促销活动id
  1549. var discount = $("#discount" + index).val(); //百分比折扣
  1550. var productId = $checkItem["productId"]; //商品id 11
  1551. var includedTax = $checkItem["includedTax"] == undefined ? 2 : $checkItem["includedTax"]; //是否含税 11
  1552. var invoiceType = $checkItem["invoiceType"] == undefined ? 3 : $checkItem["invoiceType"]; //发票类型 11
  1553. var ctx = $("#ctx" + index).val(); //ctx
  1554. var costCheckFlag = $checkItem["costCheckFlag"] == undefined ? 1 : $checkItem[
  1555. "costCheckFlag"]; //成本价选中标志:1固定成本 2比例成 11
  1556. var costPrice = $checkItem["costPrice"] == undefined ? 0.0 : $checkItem["costPrice"]; //成本价 11
  1557. var shopPercent = $checkItem["shopPercent"] == undefined ? 90 : $checkItem[
  1558. "shopPercent"]; //比例成本百分比90% 11
  1559. var oldProductFlag = $checkItem["oldProductFlag"] == undefined ? 0 : $checkItem["oldProductFlag"]; //旧商品标志,0否1是
  1560. var obj1 = document.getElementById("priceLabel" + index); //选择商品页面商品单价
  1561. var obj2 = document.getElementById("price"); //设置商品页面商品单价
  1562. var price = obj1 != null ? obj1 : obj2 != null ? obj2 : null;
  1563. var svipDiscountPriceObj = document.getElementById("svipDiscountPrice" + index);
  1564. var svipReduction = $("#svipReduction" + index).val() == undefined ? 0 : $("#svipReduction" + index).val();
  1565. var svipPriceFlag = $("#svipPriceFlag" + index).val() == undefined ? 0 : $("#svipPriceFlag" + index).val();
  1566. var svipTaxReduction = $("#svipTaxReduction" + index).val() == undefined ? 0 : $("#svipTaxReduction" + index).val();
  1567. if (includedTax != '' && includedTax == 0 && invoiceType == 3) {
  1568. //不含税不能开票商品,税率置为0
  1569. taxRate = 0;
  1570. }
  1571. //税率校验
  1572. if (isNaN(taxRate) || taxRate < 0 || taxRate > 100) {
  1573. alertx("机构税率只能为[0,100]之间的数");
  1574. return;
  1575. }
  1576. if (isNaN(supplierTaxRate) || supplierTaxRate < 0 || supplierTaxRate > 100) {
  1577. alertx("供应商税率只能为[0,100]之间的数");
  1578. return;
  1579. }
  1580. // 含税商品以及不含税不能发票商品,不需要计算税费
  1581. if (includedTax == '1' || (includedTax == '0' && invoiceType == '3')) {
  1582. //计算总价(税费为0)=折后单价*数量
  1583. if (discount == 100 && mode == 1) {
  1584. var totalFee = parseFloat(((touchPrice * 100000 * numVal) / 100000).toFixed(2));
  1585. if (price != null) {
  1586. price.style.cssText = "text-decoration: line-through";
  1587. }
  1588. document.getElementById("discountPrice" + index).style.cssText =
  1589. "width: 80px;text-decoration: line-through";
  1590. } else {
  1591. var totalFee = parseFloat(((discountPrice * 100000 * numVal) / 100000).toFixed(2));
  1592. if (price != null) {
  1593. price.style.cssText = "";
  1594. }
  1595. document.getElementById("discountPrice" + index).style.cssText = "width: 80px;";
  1596. }
  1597. if (discount != 100) {
  1598. if (promotionsId != 0) {
  1599. $("#promotion" + index).html("<label style=\"color:red;float: left\">有折扣,不享受促销优惠</label>");
  1600. } else {
  1601. $("#promotion" + index).html("");
  1602. }
  1603. $("#presentNum" + index).attr("readonly", null);
  1604. } else {
  1605. if (mode == 1) {
  1606. $("#promotion" + index).html(
  1607. "<label style=\"float: left;cursor: default\"><a href=\"javascript:void(0);\" onclick=\"showPromotionDetail('iframe:" +
  1608. ctx + "/bulkpurchase/purchaseProduct/promotionDetail?promotionId=" + promotionsId + "','" +
  1609. name + "')\"><label style=\"background: green;color: white;\">" + name + "</label>\n" +
  1610. "<label>优惠价:" + touchPrice + "</label></a></label>")
  1611. } else if (mode == 2) {
  1612. $("#promotion" + index).html(
  1613. "<label style=\"float: left\"><a href=\"javascript:void(0);\" onclick=\"showPromotionDetail('iframe:" +
  1614. ctx + "/bulkpurchase/purchaseProduct/promotionDetail?promotionId=" + promotionsId + "','" +
  1615. name + "')\"><label style=\"background: #F60;color: white;\" >" + name + "</label>\n" +
  1616. "<label>满" + touchPrice + ",减" + reducedPrice + "</label></a></label>");
  1617. } else if (mode == 3) {
  1618. $("#promotion" + index).html(
  1619. "<label style=\"float: left\"><a href=\"javascript:void(0);\" onclick=\"showPromotionDetail('iframe:" +
  1620. ctx + "/bulkpurchase/purchaseProduct/promotionDetail?promotionId=" + promotionsId + "','" +
  1621. name + "')\"><label style=\"background: purple;color: white;\" >" + name + "</label>\n" +
  1622. "<label>满" + touchPrice + ",赠送商品</label></a></label>");
  1623. }
  1624. if (promotionsId != null && promotionsId != '' && promotionsId != 0) {
  1625. $("#presentNum" + index).val(0);
  1626. $("#presentNum" + index).attr("readonly", "readonly");
  1627. } else {
  1628. if (productId >= 6060 && productId <= 6069) {
  1629. $("#presentNum" + index).attr("readonly", "readonly");
  1630. } else {
  1631. $("#presentNum" + index).attr("readonly", null);
  1632. }
  1633. }
  1634. }
  1635. $("#totalFee" + index).val(totalFee);
  1636. $("#supplierTaxRate" + index).val(supplierTaxRate);
  1637. $checkItem["taxRate"] = taxRate + ""; //重新设置税率
  1638. $checkItem["supplierTaxRate"] = supplierTaxRate + ""; //重新设置供应商税率
  1639. $checkItem["num"] = numVal + ""; //重新设置数量
  1640. $checkItem["addedValueTax"] = 0; //重新设置单个机构税费
  1641. $checkItem["totalAddedValueTax"] = 0; //重新设置机构总税费
  1642. $checkItem["singleShouldPayTotalTax"] = 0; //重新设置单个供应商税费
  1643. $checkItem["shouldPayTotalTax"] = 0; //重新设置供应商总税费
  1644. $checkItem["totalFee"] = totalFee + ""; //重新设置总价
  1645. $checkItem["payTotalFee"] = totalFee + ""; //重新设置应付
  1646. $checkItem["costPrice"] = costPrice + ""; //重新设置成本
  1647. $checkItem["svipReduction"] = svipReduction + ""; //重新设置超级会员优惠
  1648. $("#svipReduction0").val(svipReduction);
  1649. $checkItem["svipTaxReduction"] = svipTaxReduction + ""; //重新设置超级会员税费优惠
  1650. $("#svipTaxReduction").val(svipTaxReduction);
  1651. // console.log("data" + index + ":" + JSON.stringify($checkItem));
  1652. $("#check-item" + index).val(JSON.stringify($checkItem));
  1653. } else {
  1654. //不含税可开发票商品,需要计算税费
  1655. if (taxRate == 0) {
  1656. //机构税率为0,机构税费则为0
  1657. $("#taxRate" + index).val(0);
  1658. $("#addedValueTax" + index).val(0); //设置单个税费
  1659. $("#totalAddedValueTax" + index).val(0); //设置总税费
  1660. //计算总价(税费为0)=折后单价*数量
  1661. if (discount == 100 && mode == 1) {
  1662. //参与单品优惠价
  1663. //计算总价
  1664. var totalFee = parseFloat(((touchPrice * 100000 * numVal) / 100000).toFixed(2));
  1665. //计算成本价
  1666. if (costCheckFlag == 2 && shopPercent != null) {
  1667. costPrice = parseFloat((((touchPrice * shopPercent) / 100).toFixed(2)));
  1668. }
  1669. if (price != null) {
  1670. price.style.cssText = "text-decoration: line-through";
  1671. }
  1672. document.getElementById("discountPrice" + index).style.cssText =
  1673. "width: 80px;text-decoration: line-through";
  1674. } else {
  1675. var totalFee = parseFloat(((discountPrice * 100000 * numVal) / 100000).toFixed(2));
  1676. //计算成本价
  1677. if (costCheckFlag == 2 && shopPercent != null) {
  1678. costPrice = parseFloat((((discountPrice * shopPercent) / 100).toFixed(2)));
  1679. }
  1680. if (price != null) {
  1681. price.style.cssText = "";
  1682. }
  1683. document.getElementById("discountPrice" + index).style.cssText = "width: 80px;";
  1684. }
  1685. if (discount != 100) {
  1686. if (promotionsId != 0) {
  1687. $("#promotion" + index).html("<label style=\"color:red;float: left\">有折扣,不享受促销优惠</label>");
  1688. } else {
  1689. $("#promotion" + index).html("");
  1690. }
  1691. $("#presentNum" + index).attr("readonly", null);
  1692. } else {
  1693. if (mode == 1) {
  1694. $("#promotion" + index).html(
  1695. "<label style=\"float: left;cursor: default\"><a href=\"javascript:void(0);\" onclick=\"showPromotionDetail('iframe:" +
  1696. ctx + "/bulkpurchase/purchaseProduct/promotionDetail?promotionId=" + promotionsId + "','" +
  1697. name + "')\"><label style=\"background: green;color: white;\">" + name + "</label>\n" +
  1698. "<label>优惠价:" + touchPrice + "</label></a></label>")
  1699. } else if (mode == 2) {
  1700. $("#promotion" + index).html(
  1701. "<label style=\"float: left\"><a href=\"javascript:void(0);\" onclick=\"showPromotionDetail('iframe:" +
  1702. ctx + "/bulkpurchase/purchaseProduct/promotionDetail?promotionId=" + promotionsId + "','" +
  1703. name + "')\"><label style=\"background: #F60;color: white;\" >" + name + "</label>\n" +
  1704. "<label>满" + touchPrice + ",减" + reducedPrice + "</label></a></label>");
  1705. } else if (mode == 3) {
  1706. $("#promotion" + index).html(
  1707. "<label style=\"float: left\"><a href=\"javascript:void(0);\" onclick=\"showPromotionDetail('iframe:" +
  1708. ctx + "/bulkpurchase/purchaseProduct/promotionDetail?promotionId=" + promotionsId + "','" +
  1709. name + "')\"><label style=\"background: purple;color: white;\" >" + name + "</label>\n" +
  1710. "<label>满" + touchPrice + ",赠送商品</label></a></label>");
  1711. }
  1712. if (promotionsId != null && promotionsId != '' && promotionsId != 0) {
  1713. $("#presentNum" + index).val(0);
  1714. $("#presentNum" + index).attr("readonly", "readonly");
  1715. } else {
  1716. if (productId >= 6060 && productId <= 6069) {
  1717. $("#presentNum" + index).attr("readonly", "readonly");
  1718. } else {
  1719. $("#presentNum" + index).attr("readonly", null);
  1720. }
  1721. }
  1722. }
  1723. var singleShouldPayTotalTax = 0;
  1724. var shouldPayTotalTax = 0;
  1725. if (supplierTaxRate > 0) {
  1726. //供应商税费(单) = 成本价 * 供应商税率 * 0.01
  1727. singleShouldPayTotalTax = (costPrice * supplierTaxRate * 0.01).toFixed(2);
  1728. //供应商税费(总) = 供应商税费(单)*数量
  1729. shouldPayTotalTax = (singleShouldPayTotalTax * numVal).toFixed(2);
  1730. }
  1731. $("#totalFee" + index).val(totalFee);
  1732. $("#supplierTaxRate" + index).val(supplierTaxRate);
  1733. $checkItem["taxRate"] = 0; //重新设置税率
  1734. $checkItem["supplierTaxRate"] = supplierTaxRate + ""; //重新设置供应商税率
  1735. $checkItem["num"] = numVal + ""; //重新设置数量
  1736. $checkItem["addedValueTax"] = 0; //重新设置单个税费
  1737. $checkItem["totalAddedValueTax"] = 0; //重新设置机构总税费
  1738. $checkItem["singleShouldPayTotalTax"] = singleShouldPayTotalTax + "" //重新设置供应商单个税费
  1739. $checkItem["shouldPayTotalTax"] = shouldPayTotalTax + ""; //重新设置供应商总税费
  1740. $checkItem["totalFee"] = totalFee + ""; //重新设置总价
  1741. $checkItem["payTotalFee"] = totalFee + ""; //重新设置应付
  1742. $checkItem["costPrice"] = costPrice + ""; //重新设置成本
  1743. $("#taxRateLabel").val(taxRate);
  1744. $("#addedValueTaxLabel").val(0)
  1745. $("#totalAddedValueTaxLabel").val(0)
  1746. if (svipPriceFlag == 1) {
  1747. // 折扣价重新计算超级会员优惠
  1748. var svipDiscountPrice = $("#svipDiscountPrice" + index).text();
  1749. var originalPrice = $("#price" + index).val();
  1750. svipReduction = originalPrice - svipDiscountPrice;
  1751. }
  1752. $checkItem["svipReduction"] = svipReduction + ""; //重新设置超级会员优惠
  1753. $("#svipReduction0").val(svipReduction);
  1754. $checkItem["svipTaxReduction"] = svipTaxReduction + ""; //重新设置超级会员税费优惠
  1755. $("#svipTaxReduction").val(svipTaxReduction);
  1756. // console.log("data" + index + ":" + JSON.stringify($checkItem));
  1757. $("#check-item" + index).val(JSON.stringify($checkItem));
  1758. } else if (taxRate > 100) {
  1759. alertx("税率不能大于100%");
  1760. $("#taxRate" + index).val($checkItem['taxRate']);
  1761. return;
  1762. } else {
  1763. // var r = /^\+?[1-9][0-9]*$/;
  1764. if ((typeof taxRate === 'number') && (taxRate <= 100)) {
  1765. //折扣为100且参与单品优惠活动时,根据优惠价计算数据
  1766. if (discount == 100 && mode == 1) {
  1767. $("#taxRate" + index).val(taxRate);
  1768. // if (r.test(taxRate) && taxRate <= 100) {
  1769. //单个税费=优惠价*税率【税率 (4舍5入保留2位小数)】
  1770. var addedValueTax = (touchPrice * taxRate * 0.01).toFixed(2);
  1771. //商品总额=折后单价*数量【[折后单价(真实值) x 数量](4舍5入保留2位小数)】
  1772. var totalTax = (touchPrice * numVal).toFixed(2);
  1773. //税费=商品总额*税率【税率:(4舍5入保留2位小数)】
  1774. var totalAddedValueTax = (totalTax * taxRate * 0.01).toFixed(2);
  1775. //计算成本价
  1776. if (costCheckFlag == 2 && shopPercent != null) {
  1777. costPrice = (((parseFloat(touchPrice) + parseFloat(addedValueTax)) * shopPercent) / 100)
  1778. .toFixed(2);
  1779. }
  1780. //计算总价(存在折扣)【总价=[折后单价 x 数量](4舍5入保留2位小数) + 税费 】
  1781. var totalFee = ((parseFloat((touchPrice * numVal).toFixed(2)) * 100 + parseFloat(
  1782. totalAddedValueTax) * 100) / 100).toFixed(2);
  1783. if (price != null) {
  1784. price.style.cssText = "text-decoration: line-through";
  1785. }
  1786. document.getElementById("discountPrice" + index).style.cssText =
  1787. "width: 80px;text-decoration: line-through";
  1788. } else {
  1789. $("#taxRate" + index).val(taxRate);
  1790. // if (r.test(taxRate) && taxRate <= 100) {
  1791. //单个税费=折后单价*税率【税率 (4舍5入保留2位小数)】
  1792. var addedValueTax = (discountPrice * taxRate * 0.01).toFixed(2);
  1793. //商品总额=折后单价*数量【[折后单价(真实值) x 数量](4舍5入保留2位小数)】
  1794. var totalTax = (discountPrice * numVal).toFixed(2);
  1795. //机构税费=商品总额*税率【税率:(4舍5入保留2位小数)】
  1796. var totalAddedValueTax = (totalTax * taxRate * 0.01).toFixed(2);
  1797. //计算成本价
  1798. if (costCheckFlag == 2 && shopPercent != null) {
  1799. costPrice = ((((parseFloat(discountPrice) + parseFloat(addedValueTax))) * shopPercent) /
  1800. 100).toFixed(2);
  1801. }
  1802. //计算总价(存在折扣)【总价=[折后单价 x 数量](4舍5入保留2位小数) + 税费 】
  1803. var totalFee = ((parseFloat((discountPrice * numVal).toFixed(2)) * 100 + parseFloat(
  1804. totalAddedValueTax) * 100) / 100).toFixed(2);
  1805. $("#totalFee" + index).val(totalFee);
  1806. if (price != null) {
  1807. price.style.cssText = "";
  1808. }
  1809. document.getElementById("discountPrice" + index).style.cssText = "width: 80px;";
  1810. }
  1811. if (discount != 100) {
  1812. $("#promotion" + index).html("<label style=\"color:red;float: left\">有折扣,不享受促销优惠</label>")
  1813. $("#presentNum" + index).attr("readonly", null);
  1814. } else {
  1815. if (mode == 1) {
  1816. $("#promotion" + index).html(
  1817. "<label style=\"float: left;cursor: default\"><a href=\"javascript:void(0);\" onclick=\"showPromotionDetail('iframe:" +
  1818. ctx + "/bulkpurchase/purchaseProduct/promotionDetail?promotionId=" + promotionsId +
  1819. "','" + name + "')\"><label style=\"background: green;color: white;\">" + name +
  1820. "</label>\n" +
  1821. "<label>优惠价:" + touchPrice + "</label></a></label>")
  1822. } else if (mode == 2) {
  1823. $("#promotion" + index).html(
  1824. "<label style=\"float: left\"><a href=\"javascript:void(0);\" onclick=\"showPromotionDetail('iframe:" +
  1825. ctx + "/bulkpurchase/purchaseProduct/promotionDetail?promotionId=" + promotionsId +
  1826. "','" + name + "')\"><label style=\"background: #F60;color: white;\" >" + name +
  1827. "</label>\n" +
  1828. "<label>满" + touchPrice + ",减" + reducedPrice + "</label></a></label>");
  1829. } else if (mode == 3) {
  1830. $("#promotion" + index).html(
  1831. "<label style=\"float: left\"><a href=\"javascript:void(0);\" onclick=\"showPromotionDetail('iframe:" +
  1832. ctx + "/bulkpurchase/purchaseProduct/promotionDetail?promotionId=" + promotionsId +
  1833. "','" + name + "')\"><label style=\"background: purple;color: white;\" >" + name +
  1834. "</label>\n" +
  1835. "<label>满" + touchPrice + ",赠送商品</label></a></label>");
  1836. }
  1837. if (promotionsId != null && promotionsId != '' && promotionsId != 0) {
  1838. $("#presentNum" + index).val(0);
  1839. $("#presentNum" + index).attr("readonly", "readonly");
  1840. } else {
  1841. $("#presentNum" + index).attr("readonly", null);
  1842. }
  1843. }
  1844. var singleShouldPayTotalTax = 0;
  1845. var shouldPayTotalTax = 0;
  1846. //(未知商品/不含税可开发票的旧商品)将机构税率赋值给供应商税率
  1847. if (includedTax == '2' || includedTax == '' || (includedTax == '0' && (invoiceType == '1' ||
  1848. invoiceType == '2') && oldProductFlag == '1')) {
  1849. supplierTaxRate = taxRate;
  1850. }
  1851. if (supplierTaxRate > 0) {
  1852. //供应商税费(单) = 成本价 * 供应商税率 * 0.01
  1853. singleShouldPayTotalTax = (costPrice * supplierTaxRate * 0.01).toFixed(3);
  1854. //供应商税费(总) = 供应商税费(单)*数量
  1855. shouldPayTotalTax = (singleShouldPayTotalTax * numVal).toFixed(2);
  1856. }
  1857. if (svipPriceFlag == 1) {
  1858. // 折扣价重新计算超级会员优惠
  1859. var svipDiscountPrice = $("#svipDiscountPrice" + index).text();
  1860. var originalPrice = $("#price" + index).val();
  1861. svipReduction = ((originalPrice - svipDiscountPrice) + (originalPrice - svipDiscountPrice) * taxRate / 100).toFixed(2);
  1862. svipTaxReduction = ((originalPrice - svipDiscountPrice) * taxRate / 100).toFixed(2);
  1863. }
  1864. $checkItem["svipReduction"] = svipReduction + ""; //重新设置超级会员优惠
  1865. $("#svipReduction0").val(svipReduction);
  1866. $checkItem["svipTaxReduction"] = svipTaxReduction + ""; //重新设置超级会员税费优惠
  1867. $("#svipTaxReduction").val(svipTaxReduction);
  1868. $("#addedValueTax" + index).val(addedValueTax);
  1869. $("#totalAddedValueTax" + index).val(totalAddedValueTax);
  1870. $("#totalFee" + index).val(totalFee);
  1871. $("#supplierTaxRate" + index).val(supplierTaxRate);
  1872. $checkItem["num"] = numVal + ""; //重新设置数量
  1873. $checkItem["taxRate"] = taxRate + ""; //重新设置税率
  1874. $checkItem["supplierTaxRate"] = supplierTaxRate + ""; //重新设置供应商税率
  1875. $checkItem["addedValueTax"] = addedValueTax + ""; //重新设置单个税费
  1876. $checkItem["totalAddedValueTax"] = totalAddedValueTax + ""; //重新设置总税费
  1877. $checkItem["singleShouldPayTotalTax"] = singleShouldPayTotalTax + "" //重新设置供应商单个税费
  1878. $checkItem["shouldPayTotalTax"] = shouldPayTotalTax + ""; //重新设置供应商总税费
  1879. $checkItem["totalFee"] = totalFee + ""; //重新设置总价
  1880. $checkItem["payTotalFee"] = totalFee + ""; //重新设置应付
  1881. $checkItem["costPrice"] = costPrice + ""; //重新设置成本
  1882. $("#taxRateLabel").val(taxRate);
  1883. $("#addedValueTaxLabel").val(addedValueTax)
  1884. $("#totalAddedValueTaxLabel").val(totalAddedValueTax)
  1885. // console.log("data" + index + ":" + JSON.stringify($checkItem));
  1886. $("#check-item" + index).val(JSON.stringify($checkItem));
  1887. } else {
  1888. alertx("税率只能为[0,100]之间的数");
  1889. $("#taxRate" + index).val($checkItem['taxRate']);
  1890. return;
  1891. }
  1892. }
  1893. }
  1894. if (svipPriceFlag == 1) {
  1895. if (price != null) {
  1896. price.style.cssText = "text-decoration: line-through";
  1897. svipDiscountPriceObj.style.cssText = "display:''";
  1898. }
  1899. }
  1900. singeGiveNum(index);
  1901. shopFee(index); //优化功能开启刷新应付供应商
  1902. otherFee(index);
  1903. }
  1904. // 添加赠品数
  1905. function giveNum(i) {
  1906. var $giveNum = $("#presentNum" + i).val();
  1907. if ($giveNum == "" || $giveNum == "undefined") {
  1908. $giveNum = 0;
  1909. $("#presentNum" + i).val(0);
  1910. }
  1911. var giveNum = Number($giveNum);
  1912. var $checkItem = eval('(' + $("#check-item" + i).val() + ')');
  1913. if (!isNaN(giveNum)) {
  1914. if ((typeof giveNum === 'number') && (giveNum % 1 === 0)) {
  1915. $checkItem["presentNum"] = giveNum + ""; //重新设置赠品数
  1916. $("#presentNum" + i).val(giveNum);
  1917. $("#check-item" + i).val(JSON.stringify($checkItem));
  1918. if (0 != giveNum) {
  1919. cmFee(i);
  1920. }
  1921. //重新税费(因为赠品也需要计算税费)
  1922. taxRateVal(i);
  1923. } else {
  1924. alertx("赠品数只能输入整数");
  1925. $("#presentNum" + i).val($checkItem.presentNum);
  1926. }
  1927. } else {
  1928. alertx("赠品数只能输入数字");
  1929. $("#presentNum" + i).val($checkItem.presentNum);
  1930. }
  1931. }
  1932. // 单纯获取赠品数(不计算税费)
  1933. function singeGiveNum(i) {
  1934. var $giveNum = $("#presentNum" + i).val();
  1935. if ($giveNum == null || $giveNum == "" || $giveNum == "undefined") {
  1936. $giveNum = 0;
  1937. $("#presentNum" + i).val(0);
  1938. }
  1939. var giveNum = Number($giveNum);
  1940. var $checkItem = eval('(' + $("#check-item" + i).val() + ')');
  1941. if (giveNum != 'undefined' && !isNaN(giveNum)) {
  1942. if ((typeof giveNum === 'number') && (giveNum % 1 === 0)) {
  1943. $checkItem["presentNum"] = giveNum + ""; //重新设置赠品数
  1944. $("#presentNum" + i).val(giveNum);
  1945. $("#check-item" + i).val(JSON.stringify($checkItem));
  1946. if (0 != giveNum) {
  1947. cmFee(i);
  1948. }
  1949. } else {
  1950. alertx("赠品数只能输入整数");
  1951. $("#presentNum" + i).val($checkItem.presentNum);
  1952. }
  1953. } else {
  1954. alertx("赠品数只能输入数字");
  1955. $("#presentNum" + i).val($checkItem.presentNum);
  1956. }
  1957. }
  1958. /**
  1959. * @param obj
  1960. * jquery控制input只能输入数字和两位小数
  1961. */
  1962. function num(obj) {
  1963. obj.value = obj.value.replace(/[^\d.]/g, ""); //清除"数字"和"."以外的字符
  1964. obj.value = obj.value.replace(/^\./g, ""); //验证第一个字符是数字
  1965. obj.value = obj.value.replace(/\.{2,}/g, "."); //只保留第一个, 清除多余的
  1966. obj.value = obj.value.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
  1967. obj.value = obj.value.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3'); //只能输入两个小数
  1968. }
  1969. // 添加供应应付商金额
  1970. function shopFee(i) {
  1971. var $shopFee = $("#shopFee1" + i).val();
  1972. var shopFee = Number($shopFee);
  1973. var $checkItem = eval('(' + $("#check-item" + i).val() + ')');
  1974. if (!isNaN(shopFee)) {
  1975. $checkItem["shopFee1"] = shopFee + "";
  1976. $("#shopFee1" + i).val(shopFee);
  1977. $("#check-item" + i).val(JSON.stringify($checkItem));
  1978. cmFee(i);
  1979. } else {
  1980. alertx("应付供应商只能输入数字");
  1981. $("#shopFee1" + i).val($checkItem.shopFee1);
  1982. }
  1983. }
  1984. // 添加复购属性
  1985. function buyAgain(i) {
  1986. var options = $("#buyAgainFlag" + i + " option:selected");
  1987. var buyAgainFlag = options.val();
  1988. if (null != buyAgainFlag && undefined != buyAgainFlag) {
  1989. var $checkItem = eval('(' + $("#check-item" + i).val() + ')');
  1990. $checkItem["buyAgainFlag"] = buyAgainFlag + "";
  1991. $("#buyAgainFlag" + i).val(buyAgainFlag);
  1992. $("#check-item" + i).val(JSON.stringify($checkItem));
  1993. } else {
  1994. var $checkItem = eval('(' + $("#check-item" + i).val() + ')');
  1995. $checkItem["buyAgainFlag"] = "1";
  1996. $("#buyAgainFlag" + i).val(buyAgainFlag);
  1997. $("#check-item" + i).val(JSON.stringify($checkItem));
  1998. }
  1999. }
  2000. // 添加第三方应付商金额
  2001. function otherFee(i) {
  2002. var $otherFee = $("#otherFee1" + i).val();
  2003. var otherFee = Number($otherFee);
  2004. var $checkItem = eval('(' + $("#check-item" + i).val() + ')');
  2005. if (!isNaN(otherFee)) {
  2006. $checkItem["otherFee1"] = otherFee + "";
  2007. $("#otherFee1" + i).val(otherFee);
  2008. $("#check-item" + i).val(JSON.stringify($checkItem));
  2009. cmFee(i);
  2010. } else {
  2011. alertx("应付第三方只能输入数字");
  2012. $("#otherFee1" + i).val($checkItem.otherFee1);
  2013. }
  2014. }
  2015. // 添加采美应付金额
  2016. function cmFee(i) {
  2017. var discountPrice = $("#discountPrice" + i).val(); //折后单价
  2018. var shopFee1 = $("#shopFee1" + i).val(); //应付供应商
  2019. var otherFee1 = $("#otherFee1" + i).val() //应付第三方
  2020. if ((shopFee1 != "" && shopFee1 != null) && (otherFee1 != "" && otherFee1 != null)) {
  2021. var shopFee = Number(shopFee1);
  2022. var otherFee = Number(otherFee1);
  2023. var $checkItem = eval('(' + $("#check-item" + i).val() + ')');
  2024. var num = parseInt($checkItem.num);
  2025. var presentNum = parseInt($checkItem.presentNum);
  2026. var cmFee = ((discountPrice * 100000 - shopFee * 100000 - otherFee * 100000) / 100000).toFixed(6);
  2027. $("#cmFee1" + i).val(cmFee);
  2028. $checkItem["cmFee1"] = cmFee + "";
  2029. //设置总的应付
  2030. var _shopFee = (shopFee * (num + presentNum)).toFixed(6); //供应商
  2031. var _otherFee = (otherFee * num).toFixed(6); //供应商
  2032. var _cmFee = ((discountPrice * num * 100000 - _shopFee * 100000 - _otherFee * 100000) / 100000).toFixed(6);
  2033. $checkItem["shopFee"] = _shopFee + "";
  2034. $checkItem["otherFee"] = _otherFee + "";
  2035. $checkItem["cmFee"] = _cmFee + "";
  2036. $("#check-item" + i).val(JSON.stringify($checkItem));
  2037. }
  2038. }
  2039. //经理折扣后计算
  2040. function setProductTotalFee() {
  2041. var discount = Number($("#discount").val()); //经理折扣金额
  2042. if (isNaN(discount)) {
  2043. discount = Number($("#discountFee").val());
  2044. }
  2045. if ($('.productTable').length == 0) {
  2046. // 非添加订单页面
  2047. $("#discount").val('0.00');
  2048. $(".payableAmount").text(0);
  2049. return;
  2050. }
  2051. var trs = $('.productTable tbody').find('tr:not(.gift)');
  2052. if (trs.length == 0) { //没有添加商品的情况
  2053. $("#discount").val('0.00');
  2054. $(".payableAmount").text(0);
  2055. alertx("请先添加商品");
  2056. return;
  2057. }
  2058. //经理折扣 -> 改变订单总额 -> 改变分期免息金额
  2059. var productTotalFee = Number($(".productTotalFee").html()), //商品总金额
  2060. productCount = Number($(".productCount").html()), // 订单商品总数
  2061. presentCount = Number($("#presentCount").val()), //赠送商品数
  2062. giftCount = Number($("#promotionalGiftsCount").val()), //促销赠品
  2063. orderTotalFee = Number($(".orderTotalFee").html()), //订单总额
  2064. reducedPrice = 0, //促销满减
  2065. payTotalFee = ((orderTotalFee * 100 - discount * 100) / 100).toFixed(2); //应付总额=订单总额-折扣金额-减抵扣余额(待开发)
  2066. if (payTotalFee < 0) {
  2067. $("#discount").attr('value', '0');
  2068. $("#discountFee").attr('value', '0');
  2069. alertx("订单金额不能小于0");
  2070. setProductTotalFee();
  2071. return;
  2072. }
  2073. //计算运费
  2074. var freePostFlag = $("#freePostFlag").val();
  2075. var freight = 0;
  2076. if (freePostFlag == "1") {
  2077. freight = Number($("#freight").val());
  2078. }
  2079. payTotalFee = (Number(payTotalFee) + freight).toFixed(2);
  2080. // 计算促销折扣
  2081. totalPromotions.forEach(function (item) {
  2082. if (item.mode == 2) {
  2083. var touchPrice = 0;
  2084. item.promotionProducts.forEach(function (product) {
  2085. touchPrice += (product.number * product.price + product.totalTax * 1);
  2086. });
  2087. if (touchPrice >= item.touchPrice) {
  2088. if (item.discount * 1 === 1) {
  2089. var b = Math.floor(touchPrice / item.touchPrice);
  2090. reducedPrice += (b * item.reducedPrice);
  2091. payTotalFee -= reducedPrice;
  2092. } else {
  2093. reducedPrice += item.reducedPrice;
  2094. payTotalFee -= item.reducedPrice;
  2095. }
  2096. }
  2097. }
  2098. });
  2099. //计算余额抵扣
  2100. //计算应付金额
  2101. var payableAmount = payTotalFee; //应付订单金额
  2102. var balancePayFee = Number($("#balancePayFee").val()); //当前使用金额
  2103. var surplusBalance = 0.00; //剩余金额
  2104. var availableBalanceStatus = $("#useBalancePayFee").is(':checked'); //账户余额
  2105. var availableBalance = Number($("#availableBalance").html());
  2106. if (availableBalanceStatus == true) {
  2107. if ((availableBalance + balancePayFee - payTotalFee).toFixed(2) > 0) { //余额大于订单总额 全额抵扣
  2108. surplusBalance = (Number(availableBalance) + balancePayFee - Number(payTotalFee)).toFixed(2);
  2109. balancePayFee = payTotalFee;
  2110. payableAmount = 0.00;
  2111. availableBalance = surplusBalance;
  2112. } else {
  2113. payableAmount = (Number(payTotalFee) - Number(availableBalance) - balancePayFee).toFixed(2);
  2114. balancePayFee = (Number(availableBalance) + balancePayFee).toFixed(2);
  2115. surplusBalance = 0.00;
  2116. availableBalance = surplusBalance;
  2117. }
  2118. } else {
  2119. availableBalance = availableBalance + balancePayFee;
  2120. surplusBalance = availableBalance;
  2121. balancePayFee = 0.00;
  2122. }
  2123. trs.each(function (index, element) {
  2124. var obj = JSON.parse($(this).attr("data-value"));
  2125. var _taxRate = Number(obj.taxRate); //税率
  2126. var _totalFee = Number(obj.totalFee); //总价
  2127. var _shopFee1 = isNaN(Number(obj.shopFee1)) ? Number(obj.singleShopFee) : Number(obj.shopFee1);
  2128. var _shopFee = (_shopFee1 * (Number(obj.num) + Number(obj.presentNum))).toFixed(6); //供应商
  2129. var _otherFee1 = isNaN(Number(obj.otherFee1)) ? Number(obj.singleOtherFee) : Number(obj.otherFee1);
  2130. var _otherFee = (_otherFee1 * Number(obj.num)).toFixed(6); //第三方
  2131. //采美
  2132. var _cmFee = ((Number(obj.discountPrice) * Number(obj.num) * 100000 - _shopFee * 100000 - _otherFee *
  2133. 100000) / 100000).toFixed(6);
  2134. //订单的单个商品 应付金额= 单个总价 。(四舍五入后,保留两位小数,--此处不平摊经理折扣)
  2135. var _payTotalFee = (Number(obj.totalFee)).toFixed(2);
  2136. //【旧】订单的单个商品 税费=订单的单个商品应付金额-[订单的单个商品应付金额/(1+税率)](最后保留2位小数+四舍五入)
  2137. //var _totalAddedValueTax=((_payTotalFee*100000-((_payTotalFee/((1+_taxRate/100).toFixed(6))).toFixed(6))*100000)/100000).toFixed(2);
  2138. var _totalAddedValueTax = obj.totalAddedValueTax;
  2139. //差额(单个商品的经理折扣)=总价-应付金额 如果没有特别要求默认保留6位小数(此处结果为0)
  2140. var _difAmount = ((_totalFee * 100000 - _payTotalFee * 100000) / 100000).toFixed(6);
  2141. //总盈利(经理折扣后)=第三方+采美-差额
  2142. var _totalProfit = ((_otherFee * 100000 + _cmFee * 100000 - _difAmount * 100000) / 100000).toFixed(6);
  2143. //盈利比=总盈利÷(第三方+采美)
  2144. var _profitability = 0;
  2145. if (_otherFee != 0 && _cmFee != 0) {
  2146. _profitability = (_totalProfit / ((_otherFee * 100000 + _cmFee * 100000) / 100000).toFixed(6))
  2147. .toFixed(6);
  2148. }
  2149. //订单的每种商品 应付第三方(经理折扣后)=盈利比x第三方(经理折扣前)
  2150. _otherFee = (_profitability * _otherFee).toFixed(6);
  2151. //订单的单个商品 应付采美=应付金额-应付供应商-应付第三方-税费
  2152. _cmFee = ((_payTotalFee * 100000 - _shopFee * 100000 - _otherFee * 100000 - _totalAddedValueTax *
  2153. 100000) / 100000).toFixed(6);
  2154. obj["shopFee"] = _shopFee + "";
  2155. obj["otherFee"] = _otherFee + "";
  2156. obj["cmFee"] = _cmFee + "";
  2157. obj["shouldPayFee"] = _payTotalFee + "";
  2158. obj["presentNum"] = obj.presentNum + "";
  2159. if (obj["name"] == '' || obj["name"] == null || obj["name"] == 'null' || typeof (obj["name"]) ==
  2160. "undefined") {
  2161. obj["name"] = obj.purchaseProductName + "";
  2162. }
  2163. $(this).attr("data-value", JSON.stringify(obj));
  2164. var index = $(this).attr("data-index");
  2165. $('#orderProduct' + index + '\\.enabledStatus').val(JSON.stringify(obj));
  2166. });
  2167. if (initFlag) {
  2168. $(".productTotalFee").html(productTotalFee);
  2169. $(".productCount").html(productCount);
  2170. $(".presentCount").text(presentCount + giftCount);
  2171. $(".orderTotalFee").html(orderTotalFee);
  2172. $(".payTotalFee").html((payTotalFee * 1).toFixed(2));
  2173. $(".promotionFullReduction").text(reducedPrice);
  2174. $(".payableAmount").html((payableAmount * 1).toFixed(2));
  2175. $("#balancePayFee").val(balancePayFee);
  2176. $(".balancePayFee").html(balancePayFee);
  2177. $("#surplusBalance").html(surplusBalance);
  2178. $("#availableBalance").html(availableBalance);
  2179. $("#productTotalFee").val(productTotalFee);
  2180. $("#promotionFullReduction").val(reducedPrice);
  2181. $("#productCount").val(productCount);
  2182. $("#presentCount").val(presentCount);
  2183. $("#promotionalGiftsCount").val(giftCount);
  2184. $("#orderTotalFee").val(orderTotalFee);
  2185. $("#payTotalFee").val(payTotalFee);
  2186. $("#inputForm").find("[name*='bpOrderUserinfo.ableUserMoney']").val(availableBalance);
  2187. $("#payableAmount").val(payableAmount);
  2188. }
  2189. initStagesFee(); //初始化分期相关金额
  2190. }
  2191. // 展示商品促销活动详情
  2192. function showPromotionDetail(iframe, title) {
  2193. top.$.jBox(iframe, {
  2194. iframeScrolling: 'yes',
  2195. width: $(top.document).width() - 800,
  2196. height: $(top.document).height() - 200,
  2197. persistent: true,
  2198. title: title,
  2199. buttons: {
  2200. "关闭": '-1'
  2201. },
  2202. submit: function (v, h, f) {
  2203. //确定
  2204. var $jboxFrame = top.$('#jbox-iframe');
  2205. var $mainFrame = top.$('#mainFrame');
  2206. if ('1' == v && 1 == $jboxFrame.size() && 1 == $mainFrame.size()) {
  2207. var items = $jboxFrame[0].contentWindow.getCheckedItems();
  2208. if (!items) {
  2209. return false;
  2210. } else if (items.length > 0) {
  2211. console.log($('.productTable'));
  2212. $(('.producttable')).remove();
  2213. setProductList(items[0], false); //设置商品列表
  2214. // initStages();//初始化分期信息
  2215. return true;
  2216. } else {
  2217. top.$.jBox.tip("请选择...");
  2218. return false;
  2219. }
  2220. }
  2221. },
  2222. });
  2223. }
  2224. /**
  2225. * 改变返佣标识
  2226. */
  2227. function updateRebateFlag() {
  2228. var rebateFlag = $("#rebateFlag").val() * 1;
  2229. console.log(rebateFlag);
  2230. if (1 === rebateFlag) {
  2231. // $("#rebateFlag").val(1);
  2232. //选中返佣订单后不可用优惠券
  2233. // $("#couponBox").find("input[name=clubCouponId]").prop('checked', 'checked');
  2234. checkRebateFee(rebateFlag);
  2235. $("#couponBox").find("input[name=clubCouponId]").prop('checked', '');
  2236. $("#couponBox").find("input[name=clubCouponId]").attr("disabled", true);
  2237. $("#couponBox").find("#bsy").prop('checked', 'checked');
  2238. $("#freePostFlag").attr("value", "-1");
  2239. $("#freeDesc").find(".select2-chosen").text("到付");
  2240. $("#useBalancePayFee").prop('checked', '');
  2241. setFreight();
  2242. $("#freePostFlag").attr("disabled", true);
  2243. $("#useBalancePayFee").attr("disabled", true);
  2244. $("#couponAmount").val(0);
  2245. $("#seen").find("#orderSeen2").prop('checked', 'checked');
  2246. setOrderFee();
  2247. } else {
  2248. // $("#rebateFlag").val(0);
  2249. // $("#couponBox").find("input[name=clubCouponId]").prop('checked', '');
  2250. checkRebateFee(rebateFlag);
  2251. $("#couponBox").find("input[name=clubCouponId]").prop('checked', '');
  2252. $("#couponBox").find("input[name=clubCouponId]").attr("disabled", false);
  2253. $("#freePostFlag").attr("value", "0");
  2254. $("#freeDesc").find(".select2-chosen").text("包邮");
  2255. $("#useBalancePayFee").prop('checked', '');
  2256. setFreight();
  2257. $("#freePostFlag").attr("disabled", false);
  2258. $("#useBalancePayFee").attr("disabled", false);
  2259. $("#couponAmount").val(0);
  2260. $("#seen").find("#orderSeen1").prop('checked', 'checked');
  2261. // 重新计算总价
  2262. setOrderFee();
  2263. }
  2264. }
  2265. function updateRebateFlags() {
  2266. var rebateFlag = $("#rebateCheckBox").is(':checked');
  2267. if (rebateFlag) {
  2268. $("#rebateFlag").val(1);
  2269. //选中返佣订单后不可用优惠券
  2270. // $("#couponBox").find("input[name=clubCouponId]").prop('checked', 'checked');
  2271. $("#couponBox").find("input[name=clubCouponId]").prop('checked', '');
  2272. $("#couponBox").find("input[name=clubCouponId]").attr("disabled", true);
  2273. $("#couponBox").find("#bsy").prop('checked', 'checked');
  2274. $("#freePostFlag").attr("value", "-1");
  2275. $("#freeDesc").find(".select2-chosen").text("到付");
  2276. $("#useBalancePayFee").prop('checked', '');
  2277. setFreight();
  2278. $("#freePostFlag").attr("disabled", true);
  2279. $("#useBalancePayFee").attr("disabled", true);
  2280. $("#couponAmount").val(0);
  2281. $("#seen").find("#orderSeen2").prop('checked', 'checked');
  2282. setOrderFee();
  2283. } else {
  2284. $("#rebateFlag").val(0);
  2285. // $("#couponBox").find("input[name=clubCouponId]").prop('checked', '');
  2286. $("#couponBox").find("input[name=clubCouponId]").prop('checked', '');
  2287. $("#couponBox").find("input[name=clubCouponId]").attr("disabled", false);
  2288. $("#freePostFlag").attr("value", "0");
  2289. $("#freeDesc").find(".select2-chosen").text("包邮");
  2290. $("#useBalancePayFee").prop('checked', '');
  2291. setFreight();
  2292. $("#freePostFlag").attr("disabled", false);
  2293. $("#useBalancePayFee").attr("disabled", false);
  2294. $("#couponAmount").val(0);
  2295. $("#seen").find("#orderSeen1").prop('checked', 'checked');
  2296. // 重新计算总价
  2297. setOrderFee();
  2298. }
  2299. }
  2300. function checkRebateFee(rebateFlag) {
  2301. if (2 === rebateFlag) {
  2302. $("#rebateFee").show();
  2303. } else {
  2304. $("#rebateFee").hide();
  2305. }
  2306. }
  2307. /**
  2308. * 修改返佣选项是否可见
  2309. */
  2310. function showRebateCheck() {
  2311. var length = $(".productTable").length;
  2312. var rebateDiv = document.getElementById("rebateDiv");
  2313. if (rebateDiv != null) {
  2314. if (length != 0 && length != 1) {
  2315. $("#rebateCheckBox").attr("checked", false);
  2316. $("#rebateFlag").val(0);
  2317. rebateDiv.style.cssText = "display:none";
  2318. } else {
  2319. rebateDiv.style.cssText = "";
  2320. }
  2321. }
  2322. }
  2323. /************************商品相关 end**********************************************************/