sale.js 69 KB

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