orderForm.js 100 KB

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