orderForm.js 97 KB

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