orderForm.js 97 KB

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