sale.js 68 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693
  1. $(function () {
  2. openWebSocket();
  3. queryAssistantInfo();
  4. vm.queryGoods();
  5. });
  6. window.onbeforeunload = function(){
  7. closeWebSocket();
  8. }
  9. function debounce(fn,delay){
  10. console.log("进来了");
  11. var timer=null
  12. return function(){
  13. console.log(timer);
  14. if(timer){
  15. clearTimeout(timer)
  16. }
  17. timer = setTimeout(fn,delay)
  18. }
  19. }
  20. function calculateGoodsPrice(r){
  21. var rMap = r.map;
  22. var barCode = r.goodsDetails.prodBarcode;
  23. var brand = r.goodsDetails.brand;
  24. console.log(rMap);
  25. if(rMap.yhq){
  26. for(var i in rMap.yhq){
  27. vm.coupons.set(i,rMap.yhq[i]);
  28. }
  29. }
  30. // 是否有满减活动
  31. if(rMap.mj){
  32. if(rMap.mj[barCode] && !vm.mj.get(barCode)){
  33. // 该商品是否已经有过满减活动
  34. vm.mj.set(barCode,rMap.mj[barCode]);
  35. }else if(rMap.mj[brand] && !vm.mj.get(brand)){
  36. // 该品牌是否已经有过满减活动
  37. vm.mj.set(brand,rMap.mj[brand]);
  38. }
  39. }
  40. if(rMap.mysy){
  41. // 买的条码, 买的数量,送的条码,送的数量
  42. var mysy = {
  43. buyNum:rMap.mysy.buyNum,
  44. giftBarcode:rMap.mysy.giftBarcode,
  45. sendNum:rMap.mysy.sendNum
  46. };
  47. if(rMap.mysy.brand){
  48. vm.brandGetOneFree.set(rMap.mysy.productBrand,mysy);
  49. }else{
  50. vm.barcodeGetOneFree.set(rMap.mysy.barcode , mysy);
  51. }
  52. }
  53. if(rMap.mz){
  54. if(rMap.mz[barCode] && !vm.mz.get(barCode)){
  55. // 该商品是否已经有过满赠活动
  56. vm.mz.set(barCode,rMap.mz[barCode]);
  57. }else if(rMap.mz[brand] && !vm.mz.get(brand)){
  58. // 该品牌是否已经有过满赠活动
  59. vm.mz.set(brand,rMap.mz[brand]);
  60. }
  61. }
  62. if(rMap.drjbj){
  63. if(!vm.halfPrice.get(rMap.drjbj.barcode)){
  64. vm.halfPrice.set(rMap.drjbj.barcode,1);
  65. }
  66. }
  67. // if(rMap.zhjsp){
  68. // // 遍历该商品所有可能的组合价商品类型
  69. // for(var data in rMap.zhjsp){
  70. // if(!vm.zhjsp.get(data)){
  71. // // 分割组合价商品的条码,并以 条码:0 放入map中
  72. // var barCodeArray = data.toString().split(":");
  73. // var dataMap = new Map();
  74. // console.log(rMap.zhjsp[data]);
  75. // // dataMap.set();
  76. // for(var j = 0 ; j < barCodeArray.length ; j ++){
  77. // dataMap.set(barCodeArray[j],0);
  78. // }
  79. // vm.combinationPrice.set(data,rMap.zhjsp[data][0].combinedPrice)
  80. //
  81. // vm.zhjsp.set(data,dataMap);
  82. // }
  83. // }
  84. //
  85. // }
  86. // calculateGoodsByMj(r.goodsDetails,"add");
  87. calculateGoodsByMysy(r.goodsDetails,"add");
  88. calculateGoodsByMz(r.goodsDetails,"add");
  89. calculateGoodsByHalfPrice(r.goodsDetails,"add");
  90. // calculateGoodsByZhjsp(r);
  91. }
  92. // ==================== 满减==========================
  93. // 满减
  94. function calculateGoodsByMj(goodsDetails,type){
  95. if(vm.mj.get(goodsDetails.prodBarcode)){
  96. fullReduction(goodsDetails,goodsDetails.prodBarcode);
  97. }else if(vm.mj.get(goodsDetails.brand)){
  98. fullReduction(goodsDetails,goodsDetails.brand);
  99. }
  100. }
  101. // 满减的计算内容
  102. function fullReduction(goodsDetails,key){
  103. // 获取满减条件金额
  104. var qualifiedAmount = vm.mj.get(key).qualifiedAmount;
  105. // 获取已累积金额
  106. var money = vm.accumulatedAmount.get(key);
  107. if(isNaN(money)){
  108. money = goodsDetails.retailPrice;
  109. }else{
  110. money = money + goodsDetails.retailPrice;
  111. }
  112. if(money >= qualifiedAmount){
  113. vm.reduceMoney += vm.mj.get(key).deductionAmount; // 达到满减金额,获取扣减的额度
  114. vm.mj.delete(key); // 获取后删除该商品的满减
  115. vm.accumulatedAmount.delete(key); // 删除满减的金额
  116. }else{
  117. vm.accumulatedAmount.set(key,money);
  118. }
  119. }
  120. // ============================= 第二件半价==========================
  121. function calculateGoodsByHalfPrice(goodsDetails,type){
  122. var half = vm.halfPrice.get(goodsDetails.prodBarcode);
  123. if(half){
  124. var discountPrice = goodsDetails.retailPrice / 2;
  125. if(type == "add"){
  126. // 等于一的话,不满足条件
  127. if(half == 1){
  128. vm.halfPrice.set(goodsDetails.prodBarcode,2);
  129. }else if(half == 2){
  130. goodsDetails.actualPaymentAmount = discountPrice;
  131. goodsDetails.discountedPrice = discountPrice;
  132. vm.halfPrice.set(goodsDetails.prodBarcode,1);
  133. }
  134. }else if(type == "minus"){
  135. if(half == 2){
  136. goodsDetails.actualPaymentAmount = goodsDetails.actualPaymentAmount ;
  137. vm.halfPrice.set(goodsDetails.prodBarcode,1);
  138. }else if(half == 1){
  139. goodsDetails.actualPaymentAmount = goodsDetails.actualPaymentAmount - discountPrice;
  140. goodsDetails.discountedPrice = discountPrice;
  141. vm.halfPrice.set(goodsDetails.prodBarcode,2);
  142. }
  143. }
  144. }
  145. }
  146. // ============================= 满赠 ==============================
  147. // 满赠
  148. function calculateGoodsByMz(goodsDetails,type){
  149. // 判断当前支付金额是否满足满赠金额,若满足,直接修改金额为1
  150. var mzGoods = vm.mz.get(goodsDetails.prodBarcode);
  151. if(mzGoods){
  152. var mzPrice = mzGoods.qualifiedAmount;
  153. if(mzPrice < vm.actualPrice && !mzGoods.useMz){
  154. mzGoods.useMz = true;
  155. goodsDetails.actualPaymentAmount = 1;
  156. goodsDetails.discountedPrice = goodsDetails.retailPrice - 1;
  157. }
  158. }
  159. // // 1.满赠的商品是不是自己,遍历满赠商品数组
  160. // isSend(vm.fullGiftCode,goodsDetails,"满赠");
  161. //
  162. // if(vm.mz.get(goodsDetails.prodBarcode)){
  163. // fullGift(goodsDetails,goodsDetails.prodBarcode);
  164. // }else if(vm.mz.get(goodsDetails.brand)){
  165. // fullGift(goodsDetails,goodsDetails.brand);
  166. // }
  167. }
  168. function fullGift(goodsDetails,key){
  169. // 获取满赠条件金额
  170. var qualifiedAmount = vm.mz.get(key).qualifiedAmount;
  171. // 获取已累积金额
  172. var money = vm.accumulatedAmountForFullGift.get(key);
  173. if(isNaN(money)){
  174. money = goodsDetails.retailPrice;
  175. }else{
  176. money = money + goodsDetails.retailPrice;
  177. }
  178. // 达到满赠的要求
  179. if(money >= qualifiedAmount){
  180. // 将满赠的商品放入数组中,重置金额
  181. vm.fullGiftCode.push(vm.mz.get(key).giftBarcode);
  182. vm.mz.delete(key); // 获取后删除该商品的满减
  183. vm.accumulatedAmountForFullGift.delete(key); // 删除满减的金额
  184. // 2.购物车的商品里面是否有满赠的商品
  185. shopCartContain(vm.fullGiftCode,goodsDetails,"满赠");
  186. }else{
  187. vm.accumulatedAmountForFullGift.set(key,money);
  188. }
  189. }
  190. // 买一送一
  191. function calculateGoodsByMysy(goodsDetails,type){
  192. var mysy = vm.barcodeGetOneFree.get(goodsDetails.prodBarcode);
  193. var brandMysy = vm.brandGetOneFree.get(goodsDetails.brand);
  194. if(mysy){
  195. var buyNum = mysy.buyNum;
  196. if(type == "add"){
  197. // 证明是买一送一,并且达到买一送一的条件
  198. if(buyNum == 1 && vm.boughtNum.get(goodsDetails.prodBarcode)){
  199. // 设置赠品的单价
  200. goodsDetails.discountedPrice = goodsDetails.retailPrice;
  201. goodsDetails.actualPaymentAmount = 0;
  202. // goodsDetails.activity = "买1送1";
  203. // 清除该商品买一送一条件
  204. vm.boughtNum.delete(goodsDetails.prodBarcode);
  205. return ;
  206. }
  207. // 如果不是买一送一,而是买n送n,先获取购物车已有该类型商品数量
  208. var boughtNum = vm.boughtNum.get(goodsDetails.prodBarcode);
  209. // 如果没有,置为1
  210. if(!boughtNum){
  211. vm.boughtNum.set(goodsDetails.prodBarcode , 1);
  212. return ;
  213. }
  214. // 走到这里,证明购买过该类型商品,且数量不是买一送一的
  215. // 如果相等,证明达到送的条件
  216. if(buyNum === boughtNum){
  217. goodsDetails.discountedPrice = goodsDetails.retailPrice;
  218. goodsDetails.actualPaymentAmount = 0;
  219. // goodsDetails.activity = "买"+buyNum+"送1";
  220. // 清除该商品买一送一条件
  221. vm.boughtNum.delete(goodsDetails.prodBarcode);
  222. console.log(vm.boughtNum);
  223. }else{
  224. // 如果不相等,已经购买数量+1
  225. vm.boughtNum.set(goodsDetails.prodBarcode , boughtNum+1);
  226. }
  227. }else if (type == "minus"){
  228. // 获取该产品要买n送1 的n
  229. // 获取已经购买的数量
  230. var boughtNum = goodsDetails.sellVolume;
  231. // 减一后,不满足买一送一条件,重新计算金额
  232. // 如果不等于0,要减去价格
  233. var remainder = 0;
  234. if(boughtNum > buyNum+1){
  235. remainder = buyNum - (boughtNum % (buyNum+1)) ;
  236. }else{
  237. remainder = buyNum - ((buyNum+1) %boughtNum ) ;
  238. }
  239. if(boughtNum % (buyNum+1) != 0){
  240. // console.log("我要减去价格,也要减去数量,减去数量=" + goodsDetails.sellVolume);
  241. goodsDetails.actualPaymentAmount = goodsDetails.retailPrice;
  242. goodsDetails.discountedPrice = 0;
  243. // 如果等于0,只用减去数量跟优惠价,并恢复活动
  244. }else{
  245. // console.log("我不用减去价格,只要减去数量");
  246. goodsDetails.discountedPrice = goodsDetails.retailPrice;
  247. goodsDetails.actualPaymentAmount = 0;
  248. }
  249. goodsDetails.sellVolume = 1;
  250. vm.boughtNum.set(goodsDetails.prodBarcode,remainder);
  251. }
  252. }
  253. if(brandMysy){
  254. var buyNum = brandMysy.buyNum;
  255. if(type == "add"){
  256. // 如果不是买一送一,而是买n送n,先获取购物车已有该类型商品数量
  257. var boughtNum = vm.boughtNum.get(goodsDetails.brand);
  258. // 如果没有,置为1
  259. if(!boughtNum){
  260. vm.boughtNum.set(goodsDetails.brand , 1);
  261. return ;
  262. }
  263. // 走到这里,证明购买过该类型商品,且数量不是买一送一的
  264. // 如果相等,证明达到送的条件
  265. if(buyNum === boughtNum + 1){
  266. var mysyNum = vm.freeBardcode.get(brandMysy.giftBarcode);
  267. if(!mysyNum){
  268. mysyNum = 0;
  269. }
  270. vm.freeBardcode.set(brandMysy.giftBarcode,mysyNum + 1);
  271. vm.boughtNum.set(goodsDetails.brand,0);
  272. }else{
  273. // 如果不相等,已经购买数量+1
  274. vm.boughtNum.set(goodsDetails.brand , boughtNum+1);
  275. }
  276. }else if (type == "minus"){
  277. var mysyNum = vm.boughtNum.get(goodsDetails.brand);
  278. if(mysyNum == 0){
  279. if(vm.freeBardcode.get(brandMysy.giftBarcode) == 0){
  280. vm.freeBardcode.set(brandMysy.giftBarcode,-1);
  281. }else{
  282. vm.freeBardcode.set(brandMysy.giftBarcode,vm.freeBardcode.get(brandMysy.giftBarcode) - 1);
  283. }
  284. vm.boughtNum.set(goodsDetails.brand,buyNum - 1);
  285. }else{
  286. vm.boughtNum.set(goodsDetails.brand,mysyNum - 1);
  287. }
  288. // var freeNum = vm.freeBardcode.get(brandMysy.giftBarcode);
  289. // if(freeNum > 0){
  290. // vm.freeBardcode.set(brandMysy.giftBarcode,freeNum - 1);
  291. //
  292. // }
  293. }
  294. }
  295. // 判断当前商品是否为赠品
  296. // isSend(vm.mysy,goodsDetails,"买一送一");
  297. // 判断购物车里面是否有商品为赠品
  298. // shopCartContain(vm.mysy,goodsDetails,"买一送一");
  299. }
  300. // 判断当前商品是否为赠品
  301. function isSend(activity,goodsDetails,activityName){
  302. if(activity.indexOf(goodsDetails.prodBarcode) >= 0){
  303. // 如果符合条件,把赠送的条码给删除(一次性)
  304. var index = activity.indexOf(goodsDetails.prodBarcode);
  305. activity.splice(index,1);
  306. // 设置赠品的单价
  307. goodsDetails.discountedPrice = goodsDetails.retailPrice - 1;
  308. goodsDetails.actualPaymentAmount = 1;
  309. }
  310. }
  311. // 判断购物车里面是否有商品为赠品
  312. function shopCartContain(activity,goodsDetails,activityName){
  313. if(vm.goodsList && vm.goodsList.length > 0 ){
  314. for(var i = 0 ; i < vm.goodsList.length ; i ++){
  315. // 如果有商品为赠品,则把价格置位0并跳出循环
  316. if(activity.indexOf(vm.goodsList[i].prodBarcode) >= 0 && vm.goodsList[i].actualPaymentAmount != 0){
  317. // 如果符合条件,把赠送的条码给删除(一次性)
  318. var index = vm.mysy.indexOf(goodsDetails.prodBarcode);
  319. activity.splice(index,1);
  320. vm.goodsList[i].discountedPrice = vm.goodsList[i].retailPrice;
  321. vm.goodsList[i].actualPaymentAmount = 0;
  322. vm.goodsList[i].activity = activityName;
  323. vm.discountedPrice = vm.discountedPrice + vm.goodsList[i].retailPrice ;
  324. vm.actualPrice = vm.actualPrice - vm.goodsList[i].retailPrice ;
  325. break;
  326. }
  327. }
  328. }
  329. }
  330. // ======================= 组合价商品 ============================
  331. // 组合价商品
  332. function calculateGoodsByZhjsp(r){
  333. var barCode = r.goodsDetails.prodBarcode;
  334. if(r.map.zhjsp){
  335. // 将有组合的商品设置为1 ps:{"flag" => 0, "4005808550739" => 1, "4305615120454" => 0}
  336. vm.zhjsp.forEach(function(value,key,map){
  337. // 将组合价中组合的产品出现的次数+1
  338. value.forEach(function(v, k ,m){
  339. if(k === barCode)
  340. m.set(k,v+1);
  341. });
  342. var flag = 1;
  343. // 判断是否有商品成功组合
  344. value.forEach(function(v, k ,m){
  345. if(v === 0)
  346. flag = 0;
  347. });
  348. if(flag === 1){
  349. var combinationPrice = vm.combinationPrice.get(key);
  350. var barCodeArr = key.toString().split(":");
  351. // 扫码的商品条码 barCode
  352. for(var i = 0 ; i < barCodeArr.length ; i ++){
  353. var oldCode = barCodeArr[i];
  354. if(oldCode === barCode){
  355. continue;
  356. }
  357. if(vm.compareCombinationPrice.get(oldCode) && vm.compareCombinationPrice.get(oldCode) > combinationPrice){
  358. // 获取原组合关系
  359. var relationshipKey = vm.combinationRelationship.get(oldCode);
  360. // 将价格设置回原来的价格
  361. var keyArr = relationshipKey.toString().split(":");
  362. // 遍历原来的组合
  363. for(var j = 0 ; j < keyArr.length ; j ++){
  364. // 遍历购物车中原来的商品,替换价格
  365. for(var k = 0 ; k < vm.goodsList.length ; k ++){
  366. if(vm.goodsList[k].prodBarcode === keyArr[j] && vm.goodsList[k].activity == "组合价"){
  367. vm.discountedPrice = vm.discountedPrice - vm.goodsList[k].discountedPrice ;
  368. vm.actualPrice = vm.actualPrice + vm.goodsList[k].discountedPrice ;
  369. vm.goodsList[k].discountedPrice = 0 ; // 优惠价格
  370. vm.goodsList[k].actualPaymentAmount = vm.goodsList[k].retailPrice; // 实际支付价格
  371. vm.goodsList[k].isCombination = 0;
  372. vm.goodsList[k].activity = "";
  373. vm.compareCombinationPrice.delete(vm.goodsList[k].prodBarcode);
  374. vm.combinationRelationship.delete(vm.goodsList[k].prodBarcode);
  375. }
  376. }
  377. }
  378. }
  379. }
  380. for( var i = 0 ; i < barCodeArr.length ; i ++ ){
  381. // 如果是扫描的产品,直接退出,因为购物车中无该产品
  382. if(barCodeArr[i] == barCode){
  383. r.goodsDetails.isCombination = 1;
  384. r.goodsDetails.discountedPrice = r.goodsDetails.retailPrice - combinationPrice; // 优惠价格
  385. r.goodsDetails.actualPaymentAmount = combinationPrice; // 实际支付价格
  386. r.goodsDetails.activity = "组合价";
  387. vm.compareCombinationPrice.set(barCode,r.goodsDetails.actualPaymentAmount);
  388. vm.combinationRelationship.set(barCode,key);
  389. continue;
  390. }
  391. for(var j = 0 ; j < vm.goodsList.length ; j ++){
  392. if(vm.goodsList[j].prodBarcode === barCodeArr[i] && !vm.goodsList[j].isCombination){
  393. vm.goodsList[j].discountedPrice = vm.goodsList[j].retailPrice ; // 优惠价格
  394. vm.goodsList[j].actualPaymentAmount = 0; // 实际支付价格
  395. vm.goodsList[j].isCombination = 1;
  396. vm.goodsList[j].activity = "组合价";
  397. vm.discountedPrice = vm.discountedPrice + vm.goodsList[j].retailPrice ; // 总的优惠金额
  398. vm.actualPrice = vm.actualPrice - vm.goodsList[j].retailPrice ; // 总的实际支付金额
  399. vm.compareCombinationPrice.set(vm.goodsList[j].prodBarcode,vm.goodsList[j].actualPaymentAmount);
  400. vm.combinationRelationship.set(vm.goodsList[j].prodBarcode,barCode,key);
  401. break;
  402. }
  403. }
  404. }
  405. // 扣减
  406. var updateMap = map.get(key);
  407. updateMap.forEach(function(v, k ,m){
  408. m.set(k,v-1);
  409. });
  410. }
  411. });
  412. }
  413. console.log(vm.compareCombinationPrice);
  414. }
  415. const delay = (function () {
  416. let timer = 0;
  417. return function (callback, ms) {
  418. clearTimeout(timer);
  419. timer = setTimeout(callback.ms)
  420. }
  421. });
  422. let vm = new Vue({
  423. el: '#rrapp',
  424. data: {
  425. showList: true,
  426. goodsDetail:false,
  427. title: null,
  428. goods:{},
  429. orderSn:"",
  430. sysNotice: {},
  431. goodsList:[],
  432. orderInfo:[],
  433. userInfo:{},
  434. //user信息绑定集合
  435. userInfoBinding: {},
  436. sysUserInfo:{},
  437. storeName:null,
  438. prodBarcode:null,
  439. sessionId:null,
  440. pickUpCodeList:[],
  441. goodsDetailList:[],
  442. orderEntity:{},
  443. orderProcessRecord:{},
  444. tax:0,
  445. currentOrderNo:null,
  446. pickUpCode:null,
  447. customname:'',
  448. customidcard:'',
  449. machineCode:'',
  450. storeId:null,
  451. index:0,
  452. max:0,
  453. totalPrice:0,
  454. discountedPrice:0,
  455. actualPrice:0,
  456. ruleValidate: {
  457. name: [
  458. {required: true, message: '名称不能为空', trigger: 'blur'}
  459. ]
  460. },
  461. q: {
  462. name: ''
  463. },
  464. firstPrint:false,
  465. // 第二件半价
  466. halfPrice:new Map(),
  467. // 买一送一
  468. mysy: [],
  469. freeBardcode : new Map(),
  470. modifyShopcart:false, // 是否需要修改购物车中商品信息
  471. brandGetOneFree : new Map(),
  472. barcodeGetOneFree: new Map(),
  473. boughtNum: new Map(),
  474. // 组合价
  475. zhjsp: new Map(),
  476. combinationPrice: new Map(), // 组合价商品的组合价
  477. compareCombinationPrice: new Map(), // 用于比较组合价
  478. combinationRelationship: new Map(), // 组合价格的组合关系
  479. // 满减
  480. mj: new Map(),
  481. accumulatedAmount: new Map(), // 累积金额(满减使用的)
  482. reduceMoney:0, // 满减金额
  483. showReduceMoney:0, // 用于展示的满减金额
  484. // 满赠
  485. useMz:false,
  486. mz: new Map(),
  487. accumulatedAmountForFullGift: new Map(), // 累积金额(满赠使用的)
  488. fullGiftCode:[],// 满赠商品条码
  489. // 优惠券
  490. coupons: new Map(),
  491. // 挂起订单集合
  492. pendingOrderMap: new Map(),
  493. // 挂起订单的key 在1~3循环
  494. pendingIndex:1,
  495. pendingOrderKeys:[],
  496. // 存储商品信息
  497. goodsMap:new Map(),
  498. response: "",
  499. // 支付码
  500. parCode : "",
  501. // 总件数
  502. totalCount:0,
  503. searchGoodsList: [],
  504. timer: null,
  505. searchGoods: []
  506. },
  507. watch: {
  508. prodBarcode (){
  509. if(vm.timer){
  510. clearTimeout(vm.timer);
  511. }
  512. if(!vm.prodBarcode){
  513. this.searchGoodsList = [];
  514. return ;
  515. }
  516. vm.timer = null;
  517. vm.timer = setTimeout(() => {
  518. vm.queryGoods();
  519. }, 1000*15);
  520. let result = [];
  521. for(let i=0; i<vm.searchGoods.length; i++){
  522. if(vm.searchGoods[i].name.indexOf(vm.prodBarcode) > -1){
  523. if(result.length <= 9){
  524. result.push(vm.searchGoods[i]);
  525. }else{
  526. break;
  527. }
  528. }
  529. }
  530. vm.searchGoodsList = result;
  531. }
  532. },
  533. methods: {
  534. myDebounce:debounce(function(){
  535. toPayOrder();
  536. },2000),
  537. queryGoods: function(){
  538. $.get("../goods/queryGoodsName?goodsName=", function (r) {
  539. if (r.code == 0) {
  540. vm.searchGoods = r.goodsList;
  541. } else {
  542. alert(r.msg);
  543. }
  544. });
  545. },
  546. searchQuery: function (prodBarcode){
  547. vm.prodBarcode = prodBarcode;
  548. vm.query();
  549. },
  550. queryOrderStatus:function(){
  551. $.get("../order/queryOrderStatus/"+vm.orderSn, function (r) {
  552. alert(r.msg);
  553. });
  554. },
  555. query: function () {
  556. vm.storeId = sessionStorage.getItem("storeId");
  557. var thisGoods = {};
  558. var overflowLi = this.$refs.overflowLi;
  559. $.get("../goods/details/"+vm.prodBarcode+"/"+vm.storeId, function (r) {
  560. if (r.code == 0) {
  561. r.goodsDetails.sellVolume = 1;
  562. vm.goodsMap.set(r.goodsDetails.goodsSn,JSON.parse(JSON.stringify(r.goodsDetails)));
  563. vm.prodBarcode = '';
  564. calculateGoodsPrice(r);
  565. handle(r.goodsDetails,"add");
  566. //此时必须异步执行滚动条滑动至底部
  567. setTimeout(()=>{
  568. overflowLi.scrollTop = overflowLi.scrollHeight;
  569. },0)
  570. } else {
  571. alert(r.msg);
  572. }
  573. });
  574. },
  575. add:function(value){
  576. // 增加数量
  577. for(var i = 0 ; i < this.goodsList.length ; i++){
  578. if(this.goodsList[i].id == value){
  579. var goodsDetails = JSON.parse(JSON.stringify(vm.goodsMap.get(this.goodsList[i].goodsSn)));
  580. calculateGoodsByMj(goodsDetails,"add");
  581. calculateGoodsByMysy(goodsDetails,"add");
  582. calculateGoodsByHalfPrice(goodsDetails,"add");
  583. // calculateGoodsByMz(goodsDetails,"add");
  584. handle(goodsDetails,"add");
  585. break;
  586. }
  587. }
  588. },
  589. minus:function(value){
  590. // 减少数量
  591. for(var i = 0 ; i < this.goodsList.length ; i++){
  592. if(this.goodsList[i].id == value){
  593. // 获取当前购物车的数量
  594. var g = JSON.parse(JSON.stringify(this.goodsList[i]));
  595. console.log(g);
  596. var goodsDetails = JSON.parse(JSON.stringify(vm.goodsMap.get(this.goodsList[i].goodsSn)));
  597. if(g.sellVolume === 1){
  598. alert("数量至少为1个");
  599. return ;
  600. }
  601. // 如果不为空,证明减的是买A送B中的B,这时候要还原赠送资格跟B的扣减
  602. var freeMap = vm.freeBardcode.get(goodsDetails.prodBarcode);
  603. if((freeMap || freeMap == 0) && g.actualPaymentAmount == 0){
  604. vm.freeBardcode.set(goodsDetails.prodBarcode,freeMap + 1);
  605. goodsDetails.sellVolume = -1;
  606. goodsDetails.actualPaymentAmount = 0;
  607. goodsDetails.discountedPrice = -goodsDetails.retailPrice;
  608. goodsDetails.goodstaxes = - goodsDetails.goodstaxes;
  609. goodsDetails.retailPrice = - goodsDetails.retailPrice;
  610. }else{
  611. goodsDetails.sellVolume = g.sellVolume;
  612. calculateGoodsByMj(goodsDetails,"minus");
  613. calculateGoodsByMysy(goodsDetails,"minus");
  614. calculateGoodsByHalfPrice(goodsDetails,"minus");
  615. // calculateGoodsByMz(goodsDetails,"minus");
  616. goodsDetails.sellVolume = -1;
  617. goodsDetails.actualPaymentAmount = -goodsDetails.actualPaymentAmount;
  618. goodsDetails.discountedPrice = -goodsDetails.discountedPrice;
  619. goodsDetails.goodstaxes = - goodsDetails.goodstaxes;
  620. goodsDetails.retailPrice = - goodsDetails.retailPrice;
  621. }
  622. handle(goodsDetails,"minus");
  623. break;
  624. }
  625. }
  626. },
  627. deleteItem:function(value){
  628. console.log(value);
  629. // 删除这条记录
  630. for(var i = 0 ; i < this.goodsList.length ; i++){
  631. if(this.goodsList[i].id == value){
  632. if(this.goodsList.length == 1){
  633. vm.goods = {};
  634. vm.goodsDetail = false;
  635. }
  636. if(vm.mz.get(this.goodsList[i].prodBarcode)){
  637. vm.mz.get(this.goodsList[i].prodBarcode).useMz = false ;
  638. }
  639. if(vm.brandGetOneFree.get(this.goodsList[i].brand)){
  640. var giftBarcode = vm.brandGetOneFree.get(this.goodsList[i].brand).giftBarcode;
  641. var muilty = vm.brandGetOneFree.get(this.goodsList[i].brand).buyNum;
  642. var sellNum = this.goodsList[i].sellVolume;;
  643. vm.freeBardcode.set(giftBarcode,sellNum/muilty);
  644. for(var j = 0 ; j < vm.goodsList.length ; j++){
  645. var shopcartGoods = vm.goodsList[j];
  646. var shopcartFree = vm.freeBardcode.get(shopcartGoods.prodBarcode);
  647. if(shopcartFree /*&& shopcartGoods.actualPaymentAmount*/){
  648. shopcartGoods.actualPaymentAmount = shopcartGoods.actualPaymentAmount + (shopcartGoods.retailPrice * shopcartGoods.sellVolume);
  649. shopcartGoods.discountedPrice = shopcartGoods.discountedPrice - (shopcartGoods.retailPrice * shopcartGoods.sellVolume);
  650. vm.discountedPrice = vm.discountedPrice - (shopcartGoods.retailPrice * shopcartGoods.sellVolume);
  651. vm.actualPrice = vm.actualPrice + (shopcartGoods.retailPrice * shopcartGoods.sellVolume);
  652. vm.freeBardcode.set(shopcartGoods.prodBarcode, 0);// 重置回0
  653. }
  654. }
  655. }
  656. if(vm.halfPrice.get(this.goodsList[i].prodBarcode)){
  657. vm.halfPrice.set(this.goodsList[i].prodBarcode,1);
  658. }
  659. var goods = this.goodsList[i];
  660. console.log(goods);
  661. console.log(vm.totalPrice);
  662. if(vm.freeBardcode.get(goods.prodBarcode) || vm.freeBardcode.get(goods.prodBarcode) == 0){
  663. var nnum = (((goods.retailPrice * goods.sellVolume) - goods.actualPaymentAmount)/goods.retailPrice);
  664. vm.freeBardcode.set(goods.prodBarcode, nnum);
  665. }
  666. vm.totalPrice = vm.totalPrice - (goods.retailPrice * goods.sellVolume);
  667. vm.totalCount = vm.totalCount - (goods.sellVolume);
  668. vm.discountedPrice = vm.discountedPrice - goods.discountedPrice;
  669. vm.actualPrice = vm.actualPrice - goods.actualPaymentAmount;
  670. vm.boughtNum.delete(goods.prodBarcode);
  671. vm.totalPrice = Math.round(vm.totalPrice * 100) / 100;
  672. vm.discountedPrice = Math.round(vm.discountedPrice * 100) / 100;
  673. vm.actualPrice = Math.round(vm.actualPrice * 100) / 100;
  674. vm.showReduceMoney = Math.round(vm.showReduceMoney * 100) / 100;
  675. this.goodsList.splice(i,1);
  676. break;
  677. }
  678. }
  679. this.index = value;
  680. },
  681. clearGoodsList:function(){
  682. this.goodsList = [];
  683. vm.customClearData();
  684. },
  685. pendingOrder:function(){
  686. if(this.goodsList.length == 0){
  687. alert("购物车中没有商品");
  688. return;
  689. }
  690. console.log(vm.pendingOrderMap.size);
  691. if(vm.pendingOrderMap.size >= 3){
  692. alert("订单挂起最多支持3单");
  693. return;
  694. }
  695. var pendingObject = {
  696. 'goodsList':this.goodsList,
  697. 'totalPrice':vm.totalPrice,
  698. 'totalCount':vm.totalCount,
  699. 'discountedPrice':vm.discountedPrice,
  700. 'actualPrice':vm.actualPrice
  701. }
  702. vm.pendingOrderMap.set(vm.pendingIndex,pendingObject);
  703. vm.pendingOrderKeys.push(vm.pendingIndex);
  704. var newIndex = ++vm.pendingIndex;
  705. vm.pendingIndex = newIndex > 3?1: newIndex;
  706. vm.clearGoodsList();
  707. },
  708. toResumePending:function(){
  709. if(vm.pendingOrderMap.size == 0){
  710. alert("当前没有挂起的订单");
  711. return ;
  712. }
  713. $('#pendignOrderModal').modal('show')
  714. },
  715. resumePending:function(key){
  716. if(vm.pendingOrderMap.size == 0){
  717. alert("当前没有挂起的订单");
  718. return ;
  719. }
  720. if(vm.goodsList.length > 0){
  721. alert("购物车中已有商品,不允许恢复!")
  722. return ;
  723. }
  724. var pendingObject = vm.pendingOrderMap.get(key);
  725. console.log(pendingObject);
  726. vm.goodsList = pendingObject.goodsList;
  727. vm.totalPrice = pendingObject.totalPrice;
  728. vm.totalCount = pendingObject.totalCount;
  729. vm.discountedPrice = pendingObject.discountedPrice;
  730. vm.actualPrice = pendingObject.actualPrice;
  731. // 清除恢复的数据
  732. vm.pendingOrderMap.delete(key);
  733. removeByValue(vm.pendingOrderKeys,key);
  734. $('#pendignOrderModal').modal('hide')
  735. },
  736. toOrderSubmit:function(){
  737. if(this.goodsList.length == 0){
  738. alert("请选择商品");
  739. return;
  740. }
  741. $('#myModal').modal('show')
  742. // 每次点击提交订单的时候清空姓名和身份证信息和手机号
  743. // vm.$refs.customName.value = "";
  744. // vm.$refs.customIDCard.value = "";
  745. // vm.$refs.customPhone.value = "";
  746. if(vm.$refs.couponSn)
  747. vm.$refs.couponSn.value = "";
  748. this.userInfo.couponSn = "";
  749. },
  750. submitOrder:function(){
  751. vm.parCode = this.$refs.payCode.currentValue
  752. vm.myDebounce();
  753. },customClearData: function(){
  754. vm.totalPrice = 0;
  755. vm.totalCount = 0;
  756. vm.discountedPrice = 0;
  757. vm.actualPrice = 0;
  758. vm.goods={};
  759. vm.goodsDetail = false;
  760. // 第二件半价
  761. vm.halfPrice = new Map();
  762. // 买一送一
  763. vm.mysy = [];
  764. vm.freeBardcode = new Map();
  765. vm.brandGetOneFree = new Map();
  766. vm.barcodeGetOneFree = new Map();
  767. vm.brandGetOneFree = new Map();
  768. vm.boughtNum = new Map();
  769. // 组合价
  770. vm.zhjsp = new Map();
  771. vm.combinationPrice = new Map(); // 组合价商品的组合价
  772. // 满减
  773. vm.mj = new Map();
  774. vm.accumulatedAmount = new Map();// 累积金额(满减使用的)
  775. vm.reduceMoney = 0; // 满减金额
  776. vm.showReduceMoney = 0; // 用于展示的满减金额
  777. // 满赠
  778. vm.mz = new Map();
  779. vm.accumulatedAmountForFullGift = new Map(); // 累积金额(满赠使用的)
  780. vm.fullGiftCode = [];// 满赠商品条码
  781. // 优惠券
  782. vm.coupons = new Map();
  783. },
  784. queryIDCardInfo: function(){
  785. $.get("../order/queryIDCardInfo/"+vm.$refs.customPhone.value, function (r){
  786. if(r.code === 0){
  787. var data = r.userEntity;
  788. vm.$refs.customName.value = data.username;
  789. vm.$refs.customIDCard.value = data.idNo;
  790. }else{
  791. alert(r.msg);
  792. }
  793. });
  794. },
  795. getIDCardInfo: function(){
  796. $.post("http://127.0.0.1:8000/idcard/read", function (r){
  797. // var dataR = JSON.parse(r);
  798. // console.log(dataR)
  799. if(r.code == "0"){
  800. // if(!r.info){
  801. // alert("请连接设备或设备有问题,请联系管理员!");
  802. // return ;
  803. // }
  804. // var data = JSON.parse(r.info);
  805. // if(data.code=="0"){
  806. vm.$refs.customName.value = r.rows[0].data.name;
  807. vm.$refs.customIDCard.value = r.rows[0].data.id_no;
  808. // }else{
  809. // alert(data.msg);
  810. // return ;
  811. // }
  812. }else if(r.code=="-1"){
  813. alert(r.msg);
  814. return;
  815. }else{
  816. alert("请连接设备或设备有问题,请联系管理员!");
  817. }
  818. });
  819. },
  820. customPhoneBlur:function (){
  821. let customPhone = this.$refs.customPhone.value;
  822. if(customPhone){
  823. for(let key in this.userInfoBinding){
  824. if(customPhone == key){
  825. let userInfoBindingValue = this.userInfoBinding[key];
  826. this.$refs.customName.value = userInfoBindingValue.substring(0, userInfoBindingValue.length-18);
  827. this.$refs.customIDCard.value = userInfoBindingValue.substring(userInfoBindingValue.length-18);
  828. break;
  829. }
  830. }
  831. }
  832. },
  833. submitCustomInfo:function(){
  834. this.userInfo.customName = this.$refs.customName.value ;
  835. this.userInfo.customIDCard = this.$refs.customIDCard.value ;
  836. this.userInfo.customPhone = this.$refs.customPhone.value;
  837. if(this.$refs.couponSn)
  838. this.userInfo.couponSn = this.$refs.couponSn.value;
  839. var idcardReg = /^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$|^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/;
  840. if(!this.userInfo.customName){
  841. alert("姓名不能为空!");
  842. return ;
  843. }
  844. if(!idcardReg.test(this.userInfo.customIDCard)){
  845. alert("请输入正确的身份证号");
  846. return ;
  847. }
  848. if(!(/^1[3456789]\d{9}$/.test(this.userInfo.customPhone))){
  849. alert("手机号码有误,请重填");
  850. return ;
  851. }
  852. //将手机号与姓名身份证号进行绑定,下次填写手机号即可
  853. let userInfoBindingKey = this.userInfo.customPhone;
  854. let userInfoBindingValue = this.userInfo.customName+this.userInfo.customIDCard;
  855. this.userInfoBinding[userInfoBindingKey] = userInfoBindingValue;
  856. if(this.userInfo.couponSn && this.userInfo.couponSn != ""){
  857. var coupon = vm.coupons.get(this.userInfo.couponSn);
  858. if(coupon == null){
  859. alert("请输入正确的优惠券码");
  860. return ;
  861. }
  862. }
  863. $("#Send").attr("data-dismiss","modal");
  864. $('#payModal').modal('show');
  865. $("#payCode").keydown(function(e){
  866. if(e.keyCode==13){
  867. $("#submitOrder").click();
  868. event.preventDefault();
  869. }
  870. });
  871. $('body').on('hidden.bs.modal', '.modal', function () {
  872. $(this).removeData();
  873. });
  874. },
  875. queryOrderDetail:function(orderSn,pickUpCode){
  876. var storeId = sessionStorage.getItem("storeId");
  877. $.get("../order/orderDetail/"+orderSn, function (r) {
  878. if (r.code == 0) {
  879. vm.orderProcessRecord = r.resultObj.orderProcessRecordEntity;
  880. vm.orderEntity = r.resultObj.orderEntity;
  881. vm.goodsDetailList = r.resultObj.goodsList;
  882. vm.currentOrderNo = r.resultObj.orderEntity.id;
  883. vm.pickUpCode = pickUpCode;
  884. vm.tax = r.resultObj.tax;
  885. vm.response = r.resultObj.response;
  886. if(vm.orderProcessRecord.eleOrderStartTime){
  887. vm.orderProcessRecord.eleOrderStartTime = parsedate(vm.orderProcessRecord.eleOrderStartTime);
  888. }
  889. if(vm.orderProcessRecord.paymentStartTime){
  890. vm.orderProcessRecord.paymentStartTime = parsedate(vm.orderProcessRecord.paymentStartTime);
  891. }
  892. if(vm.orderProcessRecord.waybillStartTime){
  893. vm.orderProcessRecord.waybillStartTime = parsedate(vm.orderProcessRecord.waybillStartTime);
  894. }
  895. if(vm.orderProcessRecord.customsSuccTime){
  896. vm.orderProcessRecord.customsSuccTime = parsedate(vm.orderProcessRecord.customsSuccTime);
  897. }
  898. if(vm.orderProcessRecord.addOrderStartTime){
  899. vm.orderProcessRecord.addOrderStartTime = parsedate(vm.orderProcessRecord.addOrderStartTime);
  900. }
  901. }
  902. });
  903. },
  904. resendNotice:function(){
  905. confirm('确认重发重置吗?', function () {
  906. $.get("../order/resendOrderToCCNET/"+vm.orderEntity.orderSn+"/notice", function (r) {
  907. alert(r.msg);
  908. });
  909. })
  910. },
  911. resendWaybill:function(){
  912. confirm('确认重发运单吗?', function () {
  913. $.get("../order/resendOrderToCCNET/"+vm.orderEntity.orderSn+"/waybill", function (r) {
  914. alert(r.msg);
  915. });
  916. })
  917. },
  918. resendPayment:function(){
  919. confirm('确认重发支付单吗?', function () {
  920. $.get("../order/resendOrderToCCNET/"+vm.orderEntity.orderSn+"/payment", function (r) {
  921. alert(r.msg);
  922. });
  923. })
  924. },
  925. verification:function(){
  926. if(vm.orderProcessRecord.isCustomsSend != 1){
  927. alert("请等待清关完成");
  928. return ;
  929. }
  930. confirm('确认核销吗?', function () {
  931. $.ajax({
  932. type: "POST",
  933. url: "../order/printMsgAndChangeCode",
  934. contentType: "application/json",
  935. data: JSON.stringify({'id':vm.currentOrderNo,'sessionId':vm.sessionId}),
  936. success: function (r) {
  937. if (r.ticket != null) {
  938. // printArea(r.ticket);
  939. var content = getPrintContentOrder(r.ticket);
  940. printArea(content);
  941. }else{
  942. alert("打印小票失败");
  943. }
  944. }
  945. });
  946. })
  947. },
  948. refundOrder:function(){
  949. confirm('确认退款吗?', function () {
  950. $.ajax({
  951. type: "POST",
  952. url: "../order/orderRefund",
  953. contentType: "application/json",
  954. data: JSON.stringify({'orderId':vm.currentOrderNo,'sessionId':vm.sessionId}),
  955. success: function (r) {
  956. if (r.code == 0) {
  957. alert("退款成功")
  958. }else{
  959. alert("退款失败,请联系管理员");
  960. }
  961. }
  962. });
  963. })
  964. },
  965. //确认提货
  966. confirmDelivery: function(){
  967. confirm('确认提货吗?', function () {
  968. $.get("../pickupcode/confirmDelivery/"+vm.orderEntity.orderSn, function (r) {
  969. alert(r.msg);
  970. });
  971. })
  972. },
  973. retrySendOrder:function(){
  974. },
  975. getInfo: function (id) {
  976. $.get("../sys/notice/info/" + id, function (r) {
  977. vm.sysNotice = r.sysNotice;
  978. });
  979. },
  980. reload: function (event) {
  981. vm.showList = false;
  982. vm.showViewList = true;
  983. vm.showSaveSupplierGoods = true;
  984. var page = $("#jqGrid").jqGrid('getGridParam', 'page');
  985. $("#jqGrid").jqGrid('setGridParam', {
  986. postData: {
  987. storeId: vm.q.storeId,
  988. goodsName: vm.q.goodsName,
  989. goodsSn: vm.q.goodsSn,
  990. productSn: vm.q.productSn, category: vm.q.category, categoryTwo: vm.q.categoryTwo, goodsBizType:vm.q.goodsBizType,
  991. thirdPartyMerchCode: vm.q.thirdPartyMerchCode
  992. },
  993. page: page
  994. }).trigger("reloadGrid");
  995. vm.handleReset('formValidate');
  996. },
  997. handleSubmit: function (name) {
  998. handleSubmitValidate(this, name, function () {
  999. vm.saveOrUpdate()
  1000. });
  1001. },
  1002. handleReset: function (name) {
  1003. handleResetForm(this, name);
  1004. },
  1005. logout: function () {
  1006. confirm('注:您确定要安全退出本次登录吗?', function () {
  1007. dialogLoading(true);
  1008. setTimeout(function () {
  1009. toUrl('../logout?_' + $.now());
  1010. }, 500);
  1011. });
  1012. }
  1013. }
  1014. });
  1015. function getPrintContent(ticket) {
  1016. var content = "<div style=\"width: 300px;font-family: 微软雅黑;font-size: 15px;\">";
  1017. // // 打印ogo
  1018. // content += "<div style=\"text-align: center;width: 100%;height: 50px;\">";
  1019. // // content += "<img src='./../../statics/img/cw_logo.png' />";
  1020. // // content += "2222222222";
  1021. // content += "<img src='/statics/img/cw_logo.png' style='width: 100%;height: 100%;' />";
  1022. // content += "</div>";
  1023. //小票头
  1024. content += "<div style=\"text-align: center;width: 100%;font-weight:bold;font-size: 15px;\">";
  1025. content += ticket.shopName
  1026. content += "</div>";
  1027. content += "<div style=\"width: 100%;overflow:hidden;white-space: nowrap;\">--------------------------------------------------</div>";
  1028. content += "<div style=\"width: 100%;margin:5px 0px;\">";
  1029. /*content += "收银机号:" + ticket.salesNo;
  1030. content += "</div>";
  1031. content += "<div style=\"width: 100%;\">";*/
  1032. content += "收银员:" + ticket.userName;
  1033. content += "</div>";
  1034. content += "<div style=\"width: 100%;font-size: 30px;margin:15px 0 10px 5px;\">";
  1035. content += "取货码:" + ticket.code;
  1036. content += "</div>";
  1037. content += "<div style=\"width: 100%;margin:5px 0px;\">";
  1038. content += "订单编号:" + ticket.orderNo;
  1039. content += "</div>";
  1040. content += "<div style=\"width: 100%;margin:5px 0px;\">";
  1041. content += "打印日期:" + ticket.time;
  1042. content += "</div>";
  1043. content += "<div style=\"width: 100%;margin:5px 0px;font-size: 13px;\">";
  1044. content += "该取货单号只有当天有效"
  1045. content += "</div>";
  1046. content += "</div>";
  1047. return content;
  1048. }
  1049. var printAreaCount = 0;
  1050. function printArea(content) {
  1051. var idPrefix = "printArea_";
  1052. removePrintArea(idPrefix + printAreaCount);
  1053. ++printAreaCount;
  1054. var iframeId = idPrefix + printAreaCount;
  1055. var iframeStyle = 'width:0px;height:0px;left:0px;top:0px;';
  1056. iframe = document.createElement('IFRAME');
  1057. $(iframe).attr({
  1058. style: iframeStyle,
  1059. id: iframeId
  1060. });
  1061. document.body.appendChild(iframe);
  1062. var doc = iframe.contentWindow.document;
  1063. // doc.open();
  1064. doc.write('<div class="">' + content
  1065. + '</div>');
  1066. doc.close();
  1067. var frameWindow = iframe.contentWindow;
  1068. frameWindow.focus();
  1069. frameWindow.print();
  1070. alert('打印小票完成');
  1071. /*if(!vm.firstPrint){
  1072. setTimeout(function() {
  1073. // frameWindow.close();
  1074. frameWindow.focus();
  1075. frameWindow.print();
  1076. frameWindow.print();
  1077. alert('打印小票完成');
  1078. },250);
  1079. vm.firstPrint = true;
  1080. }else{
  1081. // frameWindow.close();
  1082. frameWindow.focus();
  1083. frameWindow.print();
  1084. frameWindow.print();
  1085. alert('打印小票完成');
  1086. }*/
  1087. }
  1088. function printArea2(content) {
  1089. var idPrefix = "printArea_";
  1090. removePrintArea(idPrefix + printAreaCount);
  1091. printAreaCount++;
  1092. var iframeId = idPrefix + printAreaCount;
  1093. var iframeStyle = 'width:0px;height:0px;left:0px;top:0px;';
  1094. iframe = document.createElement('IFRAME');
  1095. $(iframe).attr({
  1096. style: iframeStyle,
  1097. id: iframeId
  1098. });
  1099. document.body.appendChild(iframe);
  1100. var doc = iframe.contentWindow.document;
  1101. doc.open();
  1102. doc.write('<div class="">' + content
  1103. + '</div>');
  1104. doc.close();
  1105. var frameWindow = iframe.contentWindow;
  1106. frameWindow.focus();
  1107. frameWindow.print();
  1108. frameWindow.print();
  1109. frameWindow.close();
  1110. }
  1111. var removePrintArea = function (id) {
  1112. $("iframe#" + id).remove();
  1113. };
  1114. var webSocket;
  1115. function openWebSocket() {
  1116. var storeId = sessionStorage.getItem("storeId");
  1117. if ("WebSocket" in window) {
  1118. console.log("当前浏览器支持WebSocket");
  1119. //实现化WebSocket对象
  1120. //指定要连接的服务器地址与端口建立连接
  1121. //注意ws、wss使用不同的端口。我使用自签名的证书测试,
  1122. //无法使用wss,浏览器打开WebSocket时报错
  1123. //ws对应http、wss对应https。
  1124. // webSocket = new WebSocket("ws://183.62.225.124:8080/ws/server/"+storeId);
  1125. webSocket = new WebSocket("ws://127.0.0.1:8070//ws/server/"+storeId);
  1126. // webSocket = new WebSocket("wss://cb.k1net.cn/ws/server/"+storeId);
  1127. if (webSocket.readyState === webSocket.CONNECTING) {
  1128. console.log('1.连接正在打开......');
  1129. }
  1130. // ---------- WebSocket 对象注册事件 ----------
  1131. //连接打开事件
  1132. webSocket.onopen = function () {
  1133. if (webSocket.readyState === webSocket.OPEN) {
  1134. console.log('2.连接已打开');
  1135. }
  1136. console.log('2.向服务端发送测试消息......');
  1137. // webSocket.send("2.client发测试消息:Client sent test msg。");
  1138. };
  1139. //收到消息事件
  1140. webSocket.onmessage = function (msg) {
  1141. var data = Object.assign({}, JSON.parse(msg.data));
  1142. console.log('3.接收到服务端信息......data:'+data);
  1143. vm.sessionId = data.sessionId;
  1144. vm.pickUpCodeList = [];
  1145. if(data.pickUpCodeList.length > 0){
  1146. for(var i = 0 ; i < data.pickUpCodeList.length ; i++){
  1147. console.log(data.pickUpCodeList[i].storeId);
  1148. if(data.pickUpCodeList[i].storeId === storeId){
  1149. vm.pickUpCodeList.push(data.pickUpCodeList[i]);
  1150. }
  1151. }
  1152. }
  1153. // vm.pickUpCodeList = vm.pickUpCodeList.concat(data.pickUpCodeList);
  1154. // console.log(vm.pickUpCodeList);
  1155. // webSocket.send("2.client发测试消息:Client sent test msg。");
  1156. };
  1157. //连接关闭事件
  1158. webSocket.onclose = function () {
  1159. if (!webSocket) {
  1160. console.log('4.Socket连接已关闭');
  1161. }
  1162. };
  1163. //发生了错误事件
  1164. webSocket.onerror = function () {
  1165. console.log("5.Socket发生了错误");
  1166. }
  1167. } else {
  1168. console.log("当前浏览器不支持WebSocket");
  1169. return false;
  1170. }
  1171. }
  1172. function sendMessage() {
  1173. if(webSocket && webSocket.readyState === webSocket.OPEN) {
  1174. webSocket.send("client manual send message.")
  1175. } else {
  1176. console.log('6.未创建WebSocket连接');
  1177. }
  1178. }
  1179. function closeWebSocket() {
  1180. if (webSocket != null) {
  1181. webSocket.close();
  1182. webSocket = null;
  1183. }
  1184. console.log("关闭WebSocket");
  1185. }
  1186. //窗口关闭时,关闭连接
  1187. window.unload = function () {
  1188. webSocket.close();
  1189. };
  1190. function parsedate(value){
  1191. var date = new Date(value);
  1192. var year = date.getFullYear();
  1193. var month = date.getMonth()+1; //月份+1
  1194. var day = date.getDate();
  1195. var hour = date.getHours();
  1196. var minutes = date.getMinutes();
  1197. var second = date.getSeconds();
  1198. return year+"-"+month+"-"+day+" "+hour+":"+minutes +":"+second;
  1199. }
  1200. function getPrintContentOrder(ticket) {
  1201. var content = "<div style=\"width: 300px;font-family: 微软雅黑;font-size: 8px;\">";
  1202. // 打印ogo
  1203. content += "<div style=\"text-align: center;width: 100%;height: 260px;\">";
  1204. content += "<img src='/statics/img/cw_logo2.png' style='width: 100%;height: 100%;' />";
  1205. content += "</div>";
  1206. //小票头
  1207. content += "<div style=\"text-align: center;width: 100%;font-weight:bold;font-size: 13px;\">";
  1208. content += ticket.ticketHead.title;
  1209. content += "</div>";
  1210. /*content += "<div style=\"width: 100%;\">";
  1211. content += "会员:" + ticket.ticketHead.memberId;
  1212. content += "</div>";*/
  1213. content += "<div style=\"width: 100%;font-size: 25px;\">";
  1214. content += "取货码:" + vm.pickUpCode;
  1215. content += "</div>";
  1216. content += "<div style=\"width: 100%;\">";
  1217. content += "订单号:" + ticket.ticketHead.orderId;
  1218. content += "</div>";
  1219. content += "<div style=\"width: 100%;\">";
  1220. content += "交易时间:" + ticket.ticketHead.tradeTime;
  1221. content += "</div>";
  1222. content += "<div style=\"width: 100%;overflow:hidden;white-space: nowrap;\">--------------------------------------------------</div>";
  1223. //商品信息
  1224. content += "<table style=\"width: 100%;\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
  1225. content += "<tr>";
  1226. content += "<td style=\"width: 40%;text-align: left;font-size: 10px;font-weight: bold;\">商品名称</td>";
  1227. content += "<td style=\"width: 17%;text-align: right;font-size: 10px;font-weight: bold;\">单价</td>";
  1228. content += "<td style=\"width: 17%;text-align: right;font-size: 10px;font-weight: bold;\">优惠</td>";
  1229. // content += "<td style=\"width: 16%;text-align: right;font-size: 10px;font-weight: bold;\">税费</td>";
  1230. content += "<td style=\"width: 15%;text-align: right;font-size: 10px;font-weight: bold;\">数量</td>";
  1231. content += "<td style=\"width: 18%;text-align: right;font-size: 10px;font-weight: bold;\">小计</td>";
  1232. content += "</tr>";
  1233. content += "</table>";
  1234. content += "<div style=\"width: 100%;overflow:hidden;white-space: nowrap;\">--------------------------------------------------</div>";
  1235. content += "<table style=\"width: 100%;\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
  1236. for (var i=0;i< ticket.goods.length;i++){
  1237. content += "<tr>";
  1238. content += "<td style=\"width: 40%;text-align: left;font-size: 8px;padding-top: 8px;\">";
  1239. content += "<table style=\"width: 100%;\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
  1240. content += "<tr>";
  1241. content += "<td style=\"text-align: left;font-size: 8px;vertical-align:top;\">#</td>";
  1242. content += "<td style=\"text-align: left;font-size: 8px;\">" + ticket.goods[i].gname + "</td>";
  1243. content += "</tr>";
  1244. content += "</table>";
  1245. content += "</td>";
  1246. content += "<td style=\"width: 17%;text-align: right;font-size: 8px;vertical-align:bottom;padding-top: 8px;\">" + ticket.goods[i].uprice + "</td>";
  1247. content += "<td style=\"width: 17%;text-align: right;font-size: 8px;vertical-align:bottom;padding-top: 8px;\">" + ticket.goods[i].discountPrice + "</td>";
  1248. // content += "<td style=\"width: 17%;text-align: right;font-size: 8px;vertical-align:bottom;padding-top: 8px;\">" + ticket.goods[i].taxation + "</td>";
  1249. content += "<td style=\"width: 15%;text-align: center;font-size: 8px;vertical-align:bottom;padding-top: 8px;\">" + ticket.goods[i].num + "</td>";
  1250. content += "<td style=\"width: 18%;text-align: right;font-size: 8px;vertical-align:bottom;padding-top: 8px;\">" + ticket.goods[i].subtotal + "</td>";
  1251. content += "</tr>";
  1252. }
  1253. content += "</table>";
  1254. content += "<div style=\"width: 100%;overflow:hidden;white-space: nowrap;\">--------------------------------------------------</div>";
  1255. //收银信息
  1256. content += "<div style=\"width: 100%;\">";
  1257. content += "<span style=\"float: left;width: 50%;text-align: left;\">商品合计:</span>";
  1258. content += "<span style=\"float: left;width: 17%;text-align: left;\">" + ticket.cashInfo.goodsTotal + "件</span>";
  1259. content += "<span style=\"float: right;width: 33%;text-align: right;\">" + ticket.cashInfo.total + "元</span>";
  1260. content += "</div>";
  1261. content += "<div style=\"width: 100%;\">";
  1262. content += "<span style=\"float: left;width: 50%;text-align: left;\">税费合计:</span>";
  1263. content += "<span style=\"float: left;width: 17%;text-align: left;\">" + ticket.cashInfo.goodsTotal + "件</span>";
  1264. content += "<span style=\"float: right;width: 33%;text-align: right;\">" + ticket.cashInfo.taxTotal + "元</span>";
  1265. content += "</div>";
  1266. content += "<div style=\"width: 100%;\">";
  1267. content += "<span style=\"float: left;width: 50%;text-align: left;\">优惠合计:</span>";
  1268. content += "<span style=\"float: right;width: 50%;text-align: right;\">" + ticket.cashInfo.oddChange + "元</span>";
  1269. content += "</div>";
  1270. content += "<div style=\"width: 100%;\">";
  1271. content += "<span style=\"float: left;width: 50%;text-align: left;\">实收:</span>";
  1272. content += "<span style=\"float: right;width: 50%;text-align: right;\">" + ticket.cashInfo.receipts + "元</span>";
  1273. content += "</div>";
  1274. content += "<div style=\"width: 100%;\">";
  1275. content += "<span style=\"float: left;width: 50%;text-align: left;\">优惠券:</span>";
  1276. content += "<span style=\"float: right;width: 50%;text-align: right;\">" + ticket.cashInfo.coupon + "元</span>";
  1277. content += "</div>";
  1278. // content += "<div style=\"width: 100%;\">";
  1279. // content += "<span style=\"float: left;width: 50%;text-align: left;\">运费:</span>";
  1280. // content += "<span style=\"float: right;width: 50%;text-align: right;\">" + ticket.cashInfo.freight + "元</span>";
  1281. // content += "</div>";
  1282. content += "<div style=\"width: 100%;\">";
  1283. content += "<span style=\"float: left;width: 50%;text-align: left;\">支付渠道:</span>";
  1284. // 后期改成从系统中取
  1285. content += "<span style=\"float: right;width: 50%;text-align: right;\">" + "支付宝支付" + "</span>";
  1286. content += "</div>";
  1287. content += "<div style=\"width: 100%;overflow:hidden;white-space: nowrap;\">--------------------------------------------------</div>";
  1288. //海关清单信息
  1289. content += "<div style=\"width: 100%;\">";
  1290. content += "订单号:" + ticket.cusListing.orderId;
  1291. content += "</div>";
  1292. content += "<div style=\"width: 100%;\">";
  1293. content += "运单编号:" + ticket.cusListing.waybillId;
  1294. content += "</div>";
  1295. content += "<div style=\"width: 100%;\">";
  1296. content += "海关清单号:" + ticket.cusListing.invtNo;
  1297. content += "</div>";
  1298. content += "<div style=\"width: 100%;\">";
  1299. content += "收货人:" + ticket.cusListing.consignee;
  1300. content += "</div>";
  1301. content += "<div style=\"width: 100%;\">";
  1302. content += "收货人电话:" + ticket.cusListing.consigneeTel;
  1303. content += "</div>";
  1304. content += "<div style=\"width: 100%;\">";
  1305. content += "始发地: 仓库地址 : 广东省深圳市南山区前海保税港区W104" ;
  1306. content += "</div>";
  1307. content += "<div style=\"width: 100%;\">";
  1308. content += "交货地:" + ticket.cusListing.deliveryAddress;
  1309. content += "</div>";
  1310. content += "<div style=\"width: 100%;overflow:hidden;white-space: nowrap;\">--------------------------------------------------</div>";
  1311. content += "<div style=\"width: 100%;text-align: center;\">";
  1312. content += "购买跨境商品须知:"
  1313. content += "</div>";
  1314. content += "<div style=\"width: 100%;\">";
  1315. content += "1、凡购买跨境商品均不提供发票;<br> 2、单笔限购5000元,年交易限额2.6万元; <br> 3、所有订单经海关放行后方可提货; <br> 4、凭小票领取您的订单商品; <br> 5、非产品质量问题,跨境商品不支持无理由退换货,请及时检查。 "
  1316. content += "</div>";
  1317. content += "<div style=\"width: 100%;overflow:hidden;white-space: nowrap;\">--------------------------------------------------</div>";
  1318. content += "<div style=\"width: 100%;\">";
  1319. // content += ticket.ticketFoot.summary;
  1320. content += "</div>";
  1321. content += "<div style=\"width: 100%;\">";
  1322. // content += "客服电话:" + ticket.ticketFoot.serviceTel;
  1323. content += "</div>";
  1324. content += "<div style=\"width: 100%;\">";
  1325. // content += "网址:" + ticket.ticketFoot.url1;
  1326. content += "</div>";
  1327. content += "<div style=\"width: 100%;\">";
  1328. content += ticket.ticketFoot.welcome;
  1329. content += "</div>";
  1330. content += "<div style=\"width: 100%;\">";
  1331. content += "惠州市惠城区港惠购物中心负一层";
  1332. content += "</div>";
  1333. content += "<div style=\"width: 100%;\">";
  1334. content += "请保管好收银小票。";
  1335. content += "</div>";
  1336. // 打印二维码
  1337. content += "<div style=\"text-align: center;width: 100%;height: 250px;\">";
  1338. content += "<img src='/statics/img/cw_qrcode.png' style='width: 100%;height: 100%;' />";
  1339. content += "</div>";
  1340. content += "<div style=\"width: 100%;text-align: center;\">";
  1341. content += "关注CW大药房客服号,获取更多优惠信息"
  1342. content += "</div>";
  1343. return content;
  1344. }
  1345. function queryAssistantInfo(){
  1346. $.get("../sys/user/info", function (r) {
  1347. if(r.code == 0){
  1348. vm.sysUserInfo = r.user;
  1349. $.get("../store/getStoresByMerch?merchSn="+r.user.merchSn+"&_=1590374349985",function(result){
  1350. if(result.code == 0){
  1351. for(var i = 0 ;i < result.list.length; i++){
  1352. if(result.list[i].id == r.user.storeId){
  1353. vm.storeName = result.list[i].storeName;
  1354. break;
  1355. }
  1356. }
  1357. }
  1358. });
  1359. }
  1360. });
  1361. }
  1362. function removeByValue(arr, val) {
  1363. var index = arr.indexOf(val);
  1364. if (index > -1) {
  1365. arr.splice(index, 1);
  1366. }
  1367. }
  1368. function handle(goodsDetails,operatorType){
  1369. vm.goodsDetail = true;
  1370. // goodsDetails.sellVolume = 1;
  1371. goodsDetails.id = vm.index;
  1372. if(!vm.goodsList[vm.index]){
  1373. vm.index = vm.max;
  1374. }
  1375. vm.max++;
  1376. goodsDetails.goodsDesc = "";
  1377. // 判断当前商品是否是赠品
  1378. var freeMap = vm.freeBardcode.get(goodsDetails.prodBarcode);
  1379. if(freeMap && "minus" != operatorType){
  1380. goodsDetails.actualPaymentAmount = 0;
  1381. goodsDetails.discountedPrice = goodsDetails.retailPrice;
  1382. vm.freeBardcode.set(goodsDetails.prodBarcode,freeMap - 1);
  1383. }else{
  1384. if(!freeMap && freeMap != 0 ){
  1385. // 判断购物车中是否有赠品 这个操作只有是非赠品才能进来
  1386. for(var i = 0 ; i < vm.goodsList.length ; i++){
  1387. var shopcartGoods = vm.goodsList[i];
  1388. var shopcartFree = vm.freeBardcode.get(shopcartGoods.prodBarcode);
  1389. if(shopcartFree /*&& shopcartGoods.actualPaymentAmount*/){
  1390. // if("minus" != operatorType){
  1391. var shopcartSellNum = shopcartGoods.sellVolume;
  1392. if(shopcartFree > shopcartSellNum){
  1393. shopcartGoods.actualPaymentAmount = 0;
  1394. shopcartGoods.discountedPrice = shopcartGoods.retailPrice * shopcartFree;
  1395. vm.discountedPrice = vm.discountedPrice + shopcartGoods.discountedPrice ;
  1396. vm.actualPrice = vm.actualPrice + shopcartGoods.actualPaymentAmount ;
  1397. vm.freeBardcode.set(shopcartGoods.prodBarcode,shopcartFree - 1);//
  1398. }else if(shopcartFree == -1 ){
  1399. // g.actualPaymentAmount == 0){
  1400. shopcartGoods.actualPaymentAmount = shopcartGoods.retailPrice + shopcartGoods.actualPaymentAmount;
  1401. shopcartGoods.discountedPrice = shopcartGoods.discountedPrice - shopcartGoods.retailPrice;
  1402. vm.discountedPrice = vm.discountedPrice + shopcartGoods.discountedPrice ;
  1403. vm.actualPrice = vm.actualPrice + shopcartGoods.actualPaymentAmount ;
  1404. vm.freeBardcode.set(shopcartGoods.prodBarcode,0);// 重置回0
  1405. }else{
  1406. if(shopcartGoods.actualPaymentAmount > 0){
  1407. shopcartGoods.actualPaymentAmount = shopcartGoods.actualPaymentAmount - (shopcartGoods.retailPrice * shopcartFree);
  1408. shopcartGoods.discountedPrice = shopcartGoods.discountedPrice + (shopcartGoods.retailPrice * shopcartFree);
  1409. vm.actualPrice = vm.actualPrice - (shopcartGoods.retailPrice * shopcartFree) ;
  1410. vm.discountedPrice = vm.discountedPrice + (shopcartGoods.retailPrice * shopcartFree) ;
  1411. vm.freeBardcode.set(shopcartGoods.prodBarcode, shopcartFree - 1);// 重置回0
  1412. }
  1413. }
  1414. // }
  1415. }
  1416. }
  1417. }
  1418. }
  1419. goodsDetails.discountedPrice = Math.round(goodsDetails.discountedPrice * 100) / 100;
  1420. goodsDetails.actualPaymentAmount = Math.round(goodsDetails.actualPaymentAmount * 100) / 100;
  1421. var data = Object.assign({}, JSON.parse(JSON.stringify(goodsDetails)));
  1422. var isPush = true;
  1423. // 判断当前商品是否添加过
  1424. for(var i = 0 ; i < vm.goodsList.length ; i++){
  1425. if(vm.goodsList[i].goodsSn == data.goodsSn){
  1426. var goodsDetails = vm.goodsList[i];
  1427. if(data.actualPaymentAmount < 0 && goodsDetails.actualPaymentAmount == 0){
  1428. // goodsDetails.goodstaxes = Math.round((parseFloat(goodsDetails.goodstaxes) - parseFloat(data.goodstaxes)) * 100)/100;
  1429. // goodsDetails.discountedPrice = Math.round((parseFloat(goodsDetails.discountedPrice) - parseFloat(data.discountedPrice)) * 100)/100;
  1430. goodsDetails.actualPaymentAmount = 0;
  1431. }else{
  1432. // 税 goodstaxes,优惠金额 discountedPrice,实际支付 actualPaymentAmount,数量 sellVolume 45636917
  1433. goodsDetails.actualPaymentAmount = Math.round((parseFloat(goodsDetails.actualPaymentAmount) + parseFloat(data.actualPaymentAmount)) * 100)/100;
  1434. }
  1435. goodsDetails.discountedPrice = Math.round((parseFloat(goodsDetails.discountedPrice) + parseFloat(data.discountedPrice)) * 100)/100;
  1436. goodsDetails.goodstaxes = Math.round((parseFloat(goodsDetails.goodstaxes) + parseFloat(data.goodstaxes)) * 100)/100;
  1437. goodsDetails.sellVolume = Math.round((parseFloat(goodsDetails.sellVolume) + parseFloat(data.sellVolume)) * 100)/100;
  1438. goodsDetails.activity = data.activity;
  1439. isPush = false;
  1440. break;
  1441. }
  1442. }
  1443. // for(var i = 0 ; i < vm.goodsList.length ; i++){
  1444. // if(vm.goodsList[i].goodsSn == data.goodsSn){
  1445. // var goodsDetails = vm.goodsList[i];
  1446. // // 税 goodstaxes,优惠金额 discountedPrice,实际支付 actualPaymentAmount,数量 sellVolume 45636917
  1447. // goodsDetails.goodstaxes = Math.round((parseFloat(goodsDetails.goodstaxes) + parseFloat(data.goodstaxes)) * 100)/100;
  1448. // goodsDetails.discountedPrice = Math.round((parseFloat(goodsDetails.discountedPrice) + parseFloat(data.discountedPrice)) * 100)/100;
  1449. // goodsDetails.actualPaymentAmount = Math.round((parseFloat(goodsDetails.actualPaymentAmount) + parseFloat(data.actualPaymentAmount)) * 100)/100;
  1450. // goodsDetails.sellVolume = Math.round((parseFloat(goodsDetails.sellVolume) + parseFloat(data.sellVolume)) * 100)/100;
  1451. // goodsDetails.activity = data.activity;
  1452. // isPush = false;
  1453. // break;
  1454. // }
  1455. // }
  1456. if(isPush){
  1457. vm.goodsList.push(data);
  1458. vm.index = vm.index + 1;
  1459. }
  1460. vm.totalPrice = (vm.totalPrice + data.retailPrice);
  1461. if("minus" == operatorType){
  1462. vm.totalCount = vm.totalCount - 1;
  1463. }else{
  1464. vm.totalCount = vm.totalCount + 1;
  1465. }
  1466. if(vm.reduceMoney > 0){
  1467. vm.discountedPrice = vm.discountedPrice + data.discountedPrice + vm.reduceMoney;
  1468. vm.actualPrice = vm.actualPrice + data.actualPaymentAmount - vm.reduceMoney;
  1469. vm.showReduceMoney = vm.showReduceMoney + vm.reduceMoney;
  1470. vm.reduceMoney = 0;
  1471. }else{
  1472. vm.discountedPrice = vm.discountedPrice + data.discountedPrice ;
  1473. vm.actualPrice = vm.actualPrice + data.actualPaymentAmount ;
  1474. }
  1475. if(data.sellVolume < 0){
  1476. data.sellVolume = - data.sellVolume;
  1477. data.retailPrice = - data.retailPrice;
  1478. data.goodstaxes = -data.goodstaxes;
  1479. }
  1480. vm.goods = data;
  1481. // 处理精度
  1482. vm.totalPrice = Math.round(vm.totalPrice * 100) / 100;
  1483. vm.discountedPrice = Math.round(vm.discountedPrice * 100) / 100;
  1484. vm.actualPrice = Math.round(vm.actualPrice * 100) / 100;
  1485. vm.showReduceMoney = Math.round(vm.showReduceMoney * 100) / 100;
  1486. }
  1487. function toPayOrder(payCode){
  1488. $('#payCode').unbind('keydown').keydown(function(event){});
  1489. vm.machineCode = sessionStorage.getItem("machineCode");
  1490. console.log(vm.machineCode);
  1491. var param = {'userInfo':vm.userInfo,'payCode':vm.parCode,'goodsList':vm.goodsList,'sessionId':vm.sessionId,'machineCode':vm.machineCode};
  1492. console.log(JSON.stringify(param));
  1493. vm.parCode = "";
  1494. $.ajax({
  1495. type: "POST",
  1496. url: "../order/orderConfirm",
  1497. contentType: "application/json",
  1498. data: JSON.stringify(param),
  1499. success: function (r) {
  1500. console.log(r);
  1501. if (r.code == 0) {
  1502. if (r.resultObj != null) {
  1503. $(".form-group input[type=text]").each(function(){
  1504. this.value = '';
  1505. })
  1506. // 打印取货码小票
  1507. var content = getPrintContent(r.resultObj);
  1508. console.log(content);
  1509. printArea2(content);
  1510. vm.goodsList = [];
  1511. vm.customname = '' ;
  1512. vm.customidcard = '';
  1513. vm.customClearData();
  1514. }else{
  1515. // alert("打印小票失败");
  1516. }
  1517. } else {
  1518. alert(r.msg);
  1519. }
  1520. }
  1521. });
  1522. }