orderForm.js 104 KB

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