sale.js 69 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730
  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. orderSn1:"",
  431. sysNotice: {},
  432. goodsList:[],
  433. orderInfo:[],
  434. userInfo:{},
  435. //user信息绑定集合
  436. userInfoBinding: {},
  437. sysUserInfo:{},
  438. storeName:null,
  439. prodBarcode:null,
  440. sessionId:null,
  441. pickUpCodeList:[],
  442. goodsDetailList:[],
  443. orderEntity:{},
  444. orderProcessRecord:{},
  445. tax:0,
  446. currentOrderNo:null,
  447. pickUpCode:null,
  448. customname:'',
  449. customidcard:'',
  450. machineCode:'',
  451. storeId:null,
  452. index:0,
  453. max:0,
  454. totalPrice:0,
  455. discountedPrice:0,
  456. actualPrice:0,
  457. ruleValidate: {
  458. name: [
  459. {required: true, message: '名称不能为空', trigger: 'blur'}
  460. ]
  461. },
  462. q: {
  463. name: ''
  464. },
  465. firstPrint:false,
  466. // 第二件半价
  467. halfPrice:new Map(),
  468. // 买一送一
  469. mysy: [],
  470. freeBardcode : new Map(),
  471. modifyShopcart:false, // 是否需要修改购物车中商品信息
  472. brandGetOneFree : new Map(),
  473. barcodeGetOneFree: new Map(),
  474. boughtNum: new Map(),
  475. // 组合价
  476. zhjsp: new Map(),
  477. combinationPrice: new Map(), // 组合价商品的组合价
  478. compareCombinationPrice: new Map(), // 用于比较组合价
  479. combinationRelationship: new Map(), // 组合价格的组合关系
  480. // 满减
  481. mj: new Map(),
  482. accumulatedAmount: new Map(), // 累积金额(满减使用的)
  483. reduceMoney:0, // 满减金额
  484. showReduceMoney:0, // 用于展示的满减金额
  485. // 满赠
  486. useMz:false,
  487. mz: new Map(),
  488. accumulatedAmountForFullGift: new Map(), // 累积金额(满赠使用的)
  489. fullGiftCode:[],// 满赠商品条码
  490. // 优惠券
  491. coupons: new Map(),
  492. // 挂起订单集合
  493. pendingOrderMap: new Map(),
  494. // 挂起订单的key 在1~3循环
  495. pendingIndex:1,
  496. pendingOrderKeys:[],
  497. // 存储商品信息
  498. goodsMap:new Map(),
  499. response: "",
  500. // 支付码
  501. parCode : "",
  502. // 总件数
  503. totalCount:0,
  504. searchGoodsList: [],
  505. timer: null,
  506. searchGoods: [],
  507. // 卡回执标志
  508. delayResponse:false
  509. },
  510. watch: {
  511. prodBarcode (){
  512. if(vm.timer){
  513. clearTimeout(vm.timer);
  514. }
  515. if(!vm.prodBarcode){
  516. this.searchGoodsList = [];
  517. return ;
  518. }
  519. vm.timer = null;
  520. vm.timer = setTimeout(() => {
  521. vm.queryGoods();
  522. }, 1000*15);
  523. let result = [];
  524. for(let i=0; i<vm.searchGoods.length; i++){
  525. if(vm.searchGoods[i].name.indexOf(vm.prodBarcode) > -1){
  526. if(result.length <= 9){
  527. result.push(vm.searchGoods[i]);
  528. }else{
  529. break;
  530. }
  531. }
  532. }
  533. vm.searchGoodsList = result;
  534. }
  535. },
  536. methods: {
  537. myDebounce:debounce(function(){
  538. toPayOrder();
  539. },2000),
  540. debounceRefund:debounce(function(){
  541. toRefund();
  542. },5000),
  543. queryGoods: function(){
  544. vm.storeId = sessionStorage.getItem("storeId");
  545. $.get("../goods/queryGoodsName?storeId="+vm.storeId+"&goodsName=", function (r) {
  546. if (r.code == 0) {
  547. vm.searchGoods = r.goodsList;
  548. } else {
  549. alert(r.msg);
  550. }
  551. });
  552. },
  553. searchQuery: function (prodBarcode){
  554. vm.prodBarcode = prodBarcode;
  555. vm.query();
  556. },
  557. queryOrderStatus:function(){
  558. $.get("../order/queryOrderStatus/"+vm.orderSn, function (r) {
  559. alert(r.msg);
  560. });
  561. },
  562. queryInveResponse:function(){
  563. $.get("../order/queryInveResponse/"+vm.orderSn1, function(r){
  564. console.log(r.resultMessage);
  565. let resultString = "";
  566. if(r.resultMessage != null && r.resultMessage.length > 0){
  567. for(let i = 0 ; i < r.resultMessage.length; i ++){
  568. resultString += i+':'+r.resultMessage[i] + '\r\n';
  569. }
  570. }
  571. alert(resultString);
  572. }) ;
  573. },
  574. query: function () {
  575. vm.storeId = sessionStorage.getItem("storeId");
  576. var thisGoods = {};
  577. var overflowLi = this.$refs.overflowLi;
  578. $.get("../goods/details/"+vm.prodBarcode+"/"+vm.storeId, function (r) {
  579. if (r.code == 0) {
  580. r.goodsDetails.sellVolume = 1;
  581. vm.goodsMap.set(r.goodsDetails.goodsSn,JSON.parse(JSON.stringify(r.goodsDetails)));
  582. vm.prodBarcode = '';
  583. calculateGoodsPrice(r);
  584. handle(r.goodsDetails,"add");
  585. //此时必须异步执行滚动条滑动至底部
  586. setTimeout(()=>{
  587. overflowLi.scrollTop = overflowLi.scrollHeight;
  588. },0)
  589. } else {
  590. alert(r.msg);
  591. }
  592. });
  593. },
  594. add:function(value){
  595. // 增加数量
  596. for(var i = 0 ; i < this.goodsList.length ; i++){
  597. if(this.goodsList[i].id == value){
  598. var goodsDetails = JSON.parse(JSON.stringify(vm.goodsMap.get(this.goodsList[i].goodsSn)));
  599. calculateGoodsByMj(goodsDetails,"add");
  600. calculateGoodsByMysy(goodsDetails,"add");
  601. calculateGoodsByHalfPrice(goodsDetails,"add");
  602. // calculateGoodsByMz(goodsDetails,"add");
  603. handle(goodsDetails,"add");
  604. break;
  605. }
  606. }
  607. },
  608. minus:function(value){
  609. // 减少数量
  610. for(var i = 0 ; i < this.goodsList.length ; i++){
  611. if(this.goodsList[i].id == value){
  612. // 获取当前购物车的数量
  613. var g = JSON.parse(JSON.stringify(this.goodsList[i]));
  614. console.log(g);
  615. var goodsDetails = JSON.parse(JSON.stringify(vm.goodsMap.get(this.goodsList[i].goodsSn)));
  616. if(g.sellVolume === 1){
  617. alert("数量至少为1个");
  618. return ;
  619. }
  620. // 如果不为空,证明减的是买A送B中的B,这时候要还原赠送资格跟B的扣减
  621. var freeMap = vm.freeBardcode.get(goodsDetails.prodBarcode);
  622. if((freeMap || freeMap == 0) && g.actualPaymentAmount == 0){
  623. vm.freeBardcode.set(goodsDetails.prodBarcode,freeMap + 1);
  624. goodsDetails.sellVolume = -1;
  625. goodsDetails.actualPaymentAmount = 0;
  626. goodsDetails.discountedPrice = -goodsDetails.retailPrice;
  627. goodsDetails.goodstaxes = - goodsDetails.goodstaxes;
  628. goodsDetails.retailPrice = - goodsDetails.retailPrice;
  629. }else{
  630. goodsDetails.sellVolume = g.sellVolume;
  631. calculateGoodsByMj(goodsDetails,"minus");
  632. calculateGoodsByMysy(goodsDetails,"minus");
  633. calculateGoodsByHalfPrice(goodsDetails,"minus");
  634. // calculateGoodsByMz(goodsDetails,"minus");
  635. goodsDetails.sellVolume = -1;
  636. goodsDetails.actualPaymentAmount = -goodsDetails.actualPaymentAmount;
  637. goodsDetails.discountedPrice = -goodsDetails.discountedPrice;
  638. goodsDetails.goodstaxes = - goodsDetails.goodstaxes;
  639. goodsDetails.retailPrice = - goodsDetails.retailPrice;
  640. }
  641. handle(goodsDetails,"minus");
  642. break;
  643. }
  644. }
  645. },
  646. deleteItem:function(value){
  647. console.log(value);
  648. // 删除这条记录
  649. for(var i = 0 ; i < this.goodsList.length ; i++){
  650. if(this.goodsList[i].id == value){
  651. if(this.goodsList.length == 1){
  652. vm.goods = {};
  653. vm.goodsDetail = false;
  654. }
  655. if(vm.mz.get(this.goodsList[i].prodBarcode)){
  656. vm.mz.get(this.goodsList[i].prodBarcode).useMz = false ;
  657. }
  658. if(vm.brandGetOneFree.get(this.goodsList[i].brand)){
  659. var giftBarcode = vm.brandGetOneFree.get(this.goodsList[i].brand).giftBarcode;
  660. var muilty = vm.brandGetOneFree.get(this.goodsList[i].brand).buyNum;
  661. var sellNum = this.goodsList[i].sellVolume;;
  662. vm.freeBardcode.set(giftBarcode,sellNum/muilty);
  663. for(var j = 0 ; j < vm.goodsList.length ; j++){
  664. var shopcartGoods = vm.goodsList[j];
  665. var shopcartFree = vm.freeBardcode.get(shopcartGoods.prodBarcode);
  666. if(shopcartFree /*&& shopcartGoods.actualPaymentAmount*/){
  667. shopcartGoods.actualPaymentAmount = shopcartGoods.actualPaymentAmount + (shopcartGoods.retailPrice * shopcartGoods.sellVolume);
  668. shopcartGoods.discountedPrice = shopcartGoods.discountedPrice - (shopcartGoods.retailPrice * shopcartGoods.sellVolume);
  669. vm.discountedPrice = vm.discountedPrice - (shopcartGoods.retailPrice * shopcartGoods.sellVolume);
  670. vm.actualPrice = vm.actualPrice + (shopcartGoods.retailPrice * shopcartGoods.sellVolume);
  671. vm.freeBardcode.set(shopcartGoods.prodBarcode, 0);// 重置回0
  672. }
  673. }
  674. }
  675. if(vm.halfPrice.get(this.goodsList[i].prodBarcode)){
  676. vm.halfPrice.set(this.goodsList[i].prodBarcode,1);
  677. }
  678. var goods = this.goodsList[i];
  679. console.log(goods);
  680. console.log(vm.totalPrice);
  681. if(vm.freeBardcode.get(goods.prodBarcode) || vm.freeBardcode.get(goods.prodBarcode) == 0){
  682. var nnum = (((goods.retailPrice * goods.sellVolume) - goods.actualPaymentAmount)/goods.retailPrice);
  683. vm.freeBardcode.set(goods.prodBarcode, nnum);
  684. }
  685. vm.totalPrice = vm.totalPrice - (goods.retailPrice * goods.sellVolume);
  686. vm.totalCount = vm.totalCount - (goods.sellVolume);
  687. vm.discountedPrice = vm.discountedPrice - goods.discountedPrice;
  688. vm.actualPrice = vm.actualPrice - goods.actualPaymentAmount;
  689. vm.boughtNum.delete(goods.prodBarcode);
  690. vm.totalPrice = Math.round(vm.totalPrice * 100) / 100;
  691. vm.discountedPrice = Math.round(vm.discountedPrice * 100) / 100;
  692. vm.actualPrice = Math.round(vm.actualPrice * 100) / 100;
  693. vm.showReduceMoney = Math.round(vm.showReduceMoney * 100) / 100;
  694. this.goodsList.splice(i,1);
  695. break;
  696. }
  697. }
  698. this.index = value;
  699. },
  700. clearGoodsList:function(){
  701. this.goodsList = [];
  702. vm.customClearData();
  703. },
  704. pendingOrder:function(){
  705. if(this.goodsList.length == 0){
  706. alert("购物车中没有商品");
  707. return;
  708. }
  709. console.log(vm.pendingOrderMap.size);
  710. if(vm.pendingOrderMap.size >= 3){
  711. alert("订单挂起最多支持3单");
  712. return;
  713. }
  714. var pendingObject = {
  715. 'goodsList':this.goodsList,
  716. 'totalPrice':vm.totalPrice,
  717. 'totalCount':vm.totalCount,
  718. 'discountedPrice':vm.discountedPrice,
  719. 'actualPrice':vm.actualPrice
  720. }
  721. vm.pendingOrderMap.set(vm.pendingIndex,pendingObject);
  722. vm.pendingOrderKeys.push(vm.pendingIndex);
  723. var newIndex = ++vm.pendingIndex;
  724. vm.pendingIndex = newIndex > 3?1: newIndex;
  725. vm.clearGoodsList();
  726. },
  727. toResumePending:function(){
  728. if(vm.pendingOrderMap.size == 0){
  729. alert("当前没有挂起的订单");
  730. return ;
  731. }
  732. $('#pendignOrderModal').modal('show')
  733. },
  734. resumePending:function(key){
  735. if(vm.pendingOrderMap.size == 0){
  736. alert("当前没有挂起的订单");
  737. return ;
  738. }
  739. if(vm.goodsList.length > 0){
  740. alert("购物车中已有商品,不允许恢复!")
  741. return ;
  742. }
  743. var pendingObject = vm.pendingOrderMap.get(key);
  744. console.log(pendingObject);
  745. vm.goodsList = pendingObject.goodsList;
  746. vm.totalPrice = pendingObject.totalPrice;
  747. vm.totalCount = pendingObject.totalCount;
  748. vm.discountedPrice = pendingObject.discountedPrice;
  749. vm.actualPrice = pendingObject.actualPrice;
  750. // 清除恢复的数据
  751. vm.pendingOrderMap.delete(key);
  752. removeByValue(vm.pendingOrderKeys,key);
  753. $('#pendignOrderModal').modal('hide')
  754. },
  755. toOrderSubmit:function(){
  756. if(this.goodsList.length == 0){
  757. alert("请选择商品");
  758. return;
  759. }
  760. $('#myModal').modal('show')
  761. // 每次点击提交订单的时候清空姓名和身份证信息和手机号
  762. // vm.$refs.customName.value = "";
  763. // vm.$refs.customIDCard.value = "";
  764. // vm.$refs.customPhone.value = "";
  765. if(vm.$refs.couponSn)
  766. vm.$refs.couponSn.value = "";
  767. this.userInfo.couponSn = "";
  768. },
  769. submitOrder:function(){
  770. vm.parCode = this.$refs.payCode.currentValue
  771. vm.myDebounce();
  772. },customClearData: function(){
  773. vm.totalPrice = 0;
  774. vm.totalCount = 0;
  775. vm.discountedPrice = 0;
  776. vm.actualPrice = 0;
  777. vm.goods={};
  778. vm.goodsDetail = false;
  779. // 第二件半价
  780. vm.halfPrice = new Map();
  781. // 买一送一
  782. vm.mysy = [];
  783. vm.freeBardcode = new Map();
  784. vm.brandGetOneFree = new Map();
  785. vm.barcodeGetOneFree = new Map();
  786. vm.brandGetOneFree = new Map();
  787. vm.boughtNum = new Map();
  788. // 组合价
  789. vm.zhjsp = new Map();
  790. vm.combinationPrice = new Map(); // 组合价商品的组合价
  791. // 满减
  792. vm.mj = new Map();
  793. vm.accumulatedAmount = new Map();// 累积金额(满减使用的)
  794. vm.reduceMoney = 0; // 满减金额
  795. vm.showReduceMoney = 0; // 用于展示的满减金额
  796. // 满赠
  797. vm.mz = new Map();
  798. vm.accumulatedAmountForFullGift = new Map(); // 累积金额(满赠使用的)
  799. vm.fullGiftCode = [];// 满赠商品条码
  800. // 优惠券
  801. vm.coupons = new Map();
  802. },
  803. queryIDCardInfo: function(){
  804. $.get("../order/queryIDCardInfo/"+vm.$refs.customPhone.value, function (r){
  805. if(r.code === 0){
  806. var data = r.userEntity;
  807. vm.$refs.customName.value = data.username;
  808. vm.$refs.customIDCard.value = data.idNo;
  809. }else{
  810. alert(r.msg);
  811. }
  812. });
  813. },
  814. getIDCardInfo: function(){
  815. $.post("http://127.0.0.1:8000/idcard/read", function (r){
  816. // var dataR = JSON.parse(r);
  817. // console.log(dataR)
  818. if(r.code == "0"){
  819. // if(!r.info){
  820. // alert("请连接设备或设备有问题,请联系管理员!");
  821. // return ;
  822. // }
  823. // var data = JSON.parse(r.info);
  824. // if(data.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{
  828. // alert(data.msg);
  829. // return ;
  830. // }
  831. }else if(r.code=="-1"){
  832. alert(r.msg);
  833. return;
  834. }else{
  835. alert("请连接设备或设备有问题,请联系管理员!");
  836. }
  837. });
  838. },
  839. customPhoneBlur:function (){
  840. let customPhone = this.$refs.customPhone.value;
  841. if(customPhone){
  842. for(let key in this.userInfoBinding){
  843. if(customPhone == key){
  844. let userInfoBindingValue = this.userInfoBinding[key];
  845. this.$refs.customName.value = userInfoBindingValue.substring(0, userInfoBindingValue.length-18);
  846. this.$refs.customIDCard.value = userInfoBindingValue.substring(userInfoBindingValue.length-18);
  847. break;
  848. }
  849. }
  850. }
  851. },
  852. submitCustomInfo:function(){
  853. this.userInfo.customName = this.$refs.customName.value ;
  854. this.userInfo.customIDCard = this.$refs.customIDCard.value ;
  855. this.userInfo.customPhone = this.$refs.customPhone.value;
  856. if(this.$refs.couponSn)
  857. this.userInfo.couponSn = this.$refs.couponSn.value;
  858. 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)$/;
  859. if(!this.userInfo.customName){
  860. alert("姓名不能为空!");
  861. return ;
  862. }
  863. if(!idcardReg.test(this.userInfo.customIDCard)){
  864. alert("请输入正确的身份证号");
  865. return ;
  866. }
  867. if(!(/^1[3456789]\d{9}$/.test(this.userInfo.customPhone))){
  868. alert("手机号码有误,请重填");
  869. return ;
  870. }
  871. //将手机号与姓名身份证号进行绑定,下次填写手机号即可
  872. let userInfoBindingKey = this.userInfo.customPhone;
  873. let userInfoBindingValue = this.userInfo.customName+this.userInfo.customIDCard;
  874. this.userInfoBinding[userInfoBindingKey] = userInfoBindingValue;
  875. if(this.userInfo.couponSn && this.userInfo.couponSn != ""){
  876. var coupon = vm.coupons.get(this.userInfo.couponSn);
  877. if(coupon == null){
  878. alert("请输入正确的优惠券码");
  879. return ;
  880. }
  881. }
  882. $("#Send").attr("data-dismiss","modal");
  883. $('#payModal').modal('show');
  884. $("#payCode").keydown(function(e){
  885. if(e.keyCode==13){
  886. $("#submitOrder").click();
  887. event.preventDefault();
  888. }
  889. });
  890. $('body').on('hidden.bs.modal', '.modal', function () {
  891. $(this).removeData();
  892. });
  893. },
  894. queryOrderDetail:function(orderSn,pickUpCode){
  895. var storeId = sessionStorage.getItem("storeId");
  896. $.get("../order/orderDetail/"+orderSn, function (r) {
  897. if (r.code == 0) {
  898. vm.orderProcessRecord = r.resultObj.orderProcessRecordEntity;
  899. vm.orderEntity = r.resultObj.orderEntity;
  900. vm.goodsDetailList = r.resultObj.goodsList;
  901. vm.currentOrderNo = r.resultObj.orderEntity.id;
  902. vm.pickUpCode = pickUpCode;
  903. vm.tax = r.resultObj.tax;
  904. vm.response = r.resultObj.response;
  905. if(vm.orderProcessRecord.eleOrderStartTime){
  906. vm.orderProcessRecord.eleOrderStartTime = parsedate(vm.orderProcessRecord.eleOrderStartTime);
  907. }
  908. if(vm.orderProcessRecord.paymentStartTime){
  909. vm.orderProcessRecord.paymentStartTime = parsedate(vm.orderProcessRecord.paymentStartTime);
  910. }
  911. if(vm.orderProcessRecord.waybillStartTime){
  912. vm.orderProcessRecord.waybillStartTime = parsedate(vm.orderProcessRecord.waybillStartTime);
  913. }
  914. if(vm.orderProcessRecord.customsSuccTime){
  915. vm.orderProcessRecord.customsSuccTime = parsedate(vm.orderProcessRecord.customsSuccTime);
  916. }
  917. if(vm.orderProcessRecord.addOrderStartTime){
  918. vm.orderProcessRecord.addOrderStartTime = parsedate(vm.orderProcessRecord.addOrderStartTime);
  919. }
  920. }
  921. });
  922. },
  923. resendNotice:function(){
  924. confirm('确认重发重置吗?', function () {
  925. $.get("../order/resendOrderToCCNET/"+vm.orderEntity.orderSn+"/notice", function (r) {
  926. alert(r.msg);
  927. });
  928. })
  929. },
  930. resendWaybill:function(){
  931. confirm('确认重发运单吗?', function () {
  932. $.get("../order/resendOrderToCCNET/"+vm.orderEntity.orderSn+"/waybill", function (r) {
  933. alert(r.msg);
  934. });
  935. })
  936. },
  937. resendPayment:function(){
  938. confirm('确认重发支付单吗?', function () {
  939. $.get("../order/resendOrderToCCNET/"+vm.orderEntity.orderSn+"/payment", function (r) {
  940. alert(r.msg);
  941. });
  942. })
  943. },
  944. verification:function(){
  945. if(vm.orderProcessRecord.isCustomsSend != 1){
  946. alert("请等待清关完成");
  947. return ;
  948. }
  949. confirm('确认核销吗?', function () {
  950. $.ajax({
  951. type: "POST",
  952. url: "../order/printMsgAndChangeCode",
  953. contentType: "application/json",
  954. data: JSON.stringify({'id':vm.currentOrderNo,'sessionId':vm.sessionId}),
  955. success: function (r) {
  956. if (r.ticket != null) {
  957. // printArea(r.ticket);
  958. var content = getPrintContentOrder(r.ticket);
  959. printArea(content);
  960. }else{
  961. alert("打印小票失败");
  962. }
  963. }
  964. });
  965. })
  966. },
  967. refundOrder:function(){
  968. vm.debounceRefund();
  969. // confirm('确认退款吗?', function () {
  970. // $.ajax({
  971. // type: "POST",
  972. // url: "../order/orderRefund",
  973. // contentType: "application/json",
  974. // data: JSON.stringify({'orderId':vm.currentOrderNo,'sessionId':vm.sessionId}),
  975. // success: function (r) {
  976. // if (r.code == 0) {
  977. // alert("退款成功")
  978. // }else{
  979. // alert("退款失败,请联系管理员");
  980. // }
  981. // }
  982. // });
  983. // })
  984. },
  985. //确认提货
  986. confirmDelivery: function(){
  987. confirm('确认提货吗?', function () {
  988. $.get("../pickupcode/confirmDelivery/"+vm.orderEntity.orderSn, function (r) {
  989. alert(r.msg);
  990. });
  991. })
  992. },
  993. retrySendOrder:function(){
  994. },
  995. getInfo: function (id) {
  996. $.get("../sys/notice/info/" + id, function (r) {
  997. vm.sysNotice = r.sysNotice;
  998. });
  999. },
  1000. reload: function (event) {
  1001. vm.showList = false;
  1002. vm.showViewList = true;
  1003. vm.showSaveSupplierGoods = true;
  1004. var page = $("#jqGrid").jqGrid('getGridParam', 'page');
  1005. $("#jqGrid").jqGrid('setGridParam', {
  1006. postData: {
  1007. storeId: vm.q.storeId,
  1008. goodsName: vm.q.goodsName,
  1009. goodsSn: vm.q.goodsSn,
  1010. productSn: vm.q.productSn, category: vm.q.category, categoryTwo: vm.q.categoryTwo, goodsBizType:vm.q.goodsBizType,
  1011. thirdPartyMerchCode: vm.q.thirdPartyMerchCode
  1012. },
  1013. page: page
  1014. }).trigger("reloadGrid");
  1015. vm.handleReset('formValidate');
  1016. },
  1017. handleSubmit: function (name) {
  1018. handleSubmitValidate(this, name, function () {
  1019. vm.saveOrUpdate()
  1020. });
  1021. },
  1022. handleReset: function (name) {
  1023. handleResetForm(this, name);
  1024. },
  1025. logout: function () {
  1026. confirm('注:您确定要安全退出本次登录吗?', function () {
  1027. dialogLoading(true);
  1028. setTimeout(function () {
  1029. toUrl('../logout?_' + $.now());
  1030. }, 500);
  1031. });
  1032. }
  1033. }
  1034. });
  1035. function getPrintContent(ticket) {
  1036. var content = "<div style=\"width: 300px;font-family: 微软雅黑;font-size: 15px;\">";
  1037. // // 打印ogo
  1038. // content += "<div style=\"text-align: center;width: 100%;height: 50px;\">";
  1039. // // content += "<img src='./../../statics/img/cw_logo.png' />";
  1040. // // content += "2222222222";
  1041. // content += "<img src='/statics/img/cw_logo.png' style='width: 100%;height: 100%;' />";
  1042. // content += "</div>";
  1043. //小票头
  1044. content += "<div style=\"text-align: center;width: 100%;font-weight:bold;font-size: 15px;\">";
  1045. content += ticket.shopName
  1046. content += "</div>";
  1047. content += "<div style=\"width: 100%;overflow:hidden;white-space: nowrap;\">--------------------------------------------------</div>";
  1048. content += "<div style=\"width: 100%;margin:5px 0px;\">";
  1049. /*content += "收银机号:" + ticket.salesNo;
  1050. content += "</div>";
  1051. content += "<div style=\"width: 100%;\">";*/
  1052. content += "收银员:" + ticket.userName;
  1053. content += "</div>";
  1054. content += "<div style=\"width: 100%;font-size: 30px;margin:15px 0 10px 5px;\">";
  1055. content += "取货码:" + ticket.code;
  1056. content += "</div>";
  1057. content += "<div style=\"width: 100%;margin:5px 0px;\">";
  1058. content += "订单编号:" + ticket.orderNo;
  1059. content += "</div>";
  1060. content += "<div style=\"width: 100%;margin:5px 0px;\">";
  1061. content += "打印日期:" + ticket.time;
  1062. content += "</div>";
  1063. content += "<div style=\"width: 100%;margin:5px 0px;font-size: 13px;\">";
  1064. content += "该取货单号只有当天有效"
  1065. content += "</div>";
  1066. content += "</div>";
  1067. return content;
  1068. }
  1069. var printAreaCount = 0;
  1070. function printArea(content) {
  1071. var idPrefix = "printArea_";
  1072. removePrintArea(idPrefix + printAreaCount);
  1073. ++printAreaCount;
  1074. var iframeId = idPrefix + printAreaCount;
  1075. var iframeStyle = 'width:0px;height:0px;left:0px;top:0px;';
  1076. iframe = document.createElement('IFRAME');
  1077. $(iframe).attr({
  1078. style: iframeStyle,
  1079. id: iframeId
  1080. });
  1081. document.body.appendChild(iframe);
  1082. var doc = iframe.contentWindow.document;
  1083. // doc.open();
  1084. doc.write('<div class="">' + content
  1085. + '</div>');
  1086. doc.close();
  1087. var frameWindow = iframe.contentWindow;
  1088. frameWindow.focus();
  1089. frameWindow.print();
  1090. alert('打印小票完成');
  1091. /*if(!vm.firstPrint){
  1092. setTimeout(function() {
  1093. // frameWindow.close();
  1094. frameWindow.focus();
  1095. frameWindow.print();
  1096. frameWindow.print();
  1097. alert('打印小票完成');
  1098. },250);
  1099. vm.firstPrint = true;
  1100. }else{
  1101. // frameWindow.close();
  1102. frameWindow.focus();
  1103. frameWindow.print();
  1104. frameWindow.print();
  1105. alert('打印小票完成');
  1106. }*/
  1107. }
  1108. function printArea2(content) {
  1109. var idPrefix = "printArea_";
  1110. removePrintArea(idPrefix + printAreaCount);
  1111. printAreaCount++;
  1112. var iframeId = idPrefix + printAreaCount;
  1113. var iframeStyle = 'width:0px;height:0px;left:0px;top:0px;';
  1114. iframe = document.createElement('IFRAME');
  1115. $(iframe).attr({
  1116. style: iframeStyle,
  1117. id: iframeId
  1118. });
  1119. document.body.appendChild(iframe);
  1120. var doc = iframe.contentWindow.document;
  1121. doc.open();
  1122. doc.write('<div class="">' + content
  1123. + '</div>');
  1124. doc.close();
  1125. var frameWindow = iframe.contentWindow;
  1126. frameWindow.focus();
  1127. frameWindow.print();
  1128. frameWindow.print();
  1129. frameWindow.close();
  1130. }
  1131. var removePrintArea = function (id) {
  1132. $("iframe#" + id).remove();
  1133. };
  1134. var webSocket;
  1135. function openWebSocket() {
  1136. var storeId = sessionStorage.getItem("storeId");
  1137. if ("WebSocket" in window) {
  1138. console.log("当前浏览器支持WebSocket");
  1139. //实现化WebSocket对象
  1140. //指定要连接的服务器地址与端口建立连接
  1141. //注意ws、wss使用不同的端口。我使用自签名的证书测试,
  1142. //无法使用wss,浏览器打开WebSocket时报错
  1143. //ws对应http、wss对应https。
  1144. webSocket = new WebSocket("ws://183.3.221.143:8080/ws/server/"+storeId);
  1145. // webSocket = new WebSocket("ws://8.135.102.238:8080//ws/server/"+storeId);
  1146. // webSocket = new WebSocket("ws://127.0.0.1:8080//ws/server/"+storeId);
  1147. // webSocket = new WebSocket("wss://cb.k1net.cn/ws/server/"+storeId);
  1148. if (webSocket.readyState === webSocket.CONNECTING) {
  1149. console.log('1.连接正在打开......');
  1150. }
  1151. // ---------- WebSocket 对象注册事件 ----------
  1152. //连接打开事件
  1153. webSocket.onopen = function () {
  1154. if (webSocket.readyState === webSocket.OPEN) {
  1155. console.log('2.连接已打开');
  1156. }
  1157. console.log('2.向服务端发送测试消息......');
  1158. // webSocket.send("2.client发测试消息:Client sent test msg。");
  1159. };
  1160. //收到消息事件
  1161. webSocket.onmessage = function (msg) {
  1162. var data = Object.assign({}, JSON.parse(msg.data));
  1163. console.log('3.接收到服务端信息......data:'+data);
  1164. vm.sessionId = data.sessionId;
  1165. vm.pickUpCodeList = [];
  1166. if(data.pickUpCodeList.length > 0){
  1167. for(var i = 0 ; i < data.pickUpCodeList.length ; i++){
  1168. console.log(data.pickUpCodeList[i].storeId);
  1169. if(data.pickUpCodeList[i].storeId === storeId){
  1170. vm.pickUpCodeList.push(data.pickUpCodeList[i]);
  1171. }
  1172. }
  1173. }
  1174. vm.delayResponse = data.delayResponse;
  1175. };
  1176. //连接关闭事件
  1177. webSocket.onclose = function () {
  1178. if (!webSocket) {
  1179. console.log('4.Socket连接已关闭');
  1180. }
  1181. };
  1182. //发生了错误事件
  1183. webSocket.onerror = function () {
  1184. console.log("5.Socket发生了错误");
  1185. }
  1186. } else {
  1187. console.log("当前浏览器不支持WebSocket");
  1188. return false;
  1189. }
  1190. }
  1191. function sendMessage() {
  1192. if(webSocket && webSocket.readyState === webSocket.OPEN) {
  1193. webSocket.send("client manual send message.")
  1194. } else {
  1195. console.log('6.未创建WebSocket连接');
  1196. }
  1197. }
  1198. function closeWebSocket() {
  1199. if (webSocket != null) {
  1200. webSocket.close();
  1201. webSocket = null;
  1202. }
  1203. console.log("关闭WebSocket");
  1204. }
  1205. //窗口关闭时,关闭连接
  1206. window.unload = function () {
  1207. webSocket.close();
  1208. };
  1209. function parsedate(value){
  1210. var date = new Date(value);
  1211. var year = date.getFullYear();
  1212. var month = date.getMonth()+1; //月份+1
  1213. var day = date.getDate();
  1214. var hour = date.getHours();
  1215. var minutes = date.getMinutes();
  1216. var second = date.getSeconds();
  1217. return year+"-"+month+"-"+day+" "+hour+":"+minutes +":"+second;
  1218. }
  1219. function getPrintContentOrder(ticket) {
  1220. var content = "<div style=\"width: 270px;font-family: 微软雅黑;font-size: 8px;\">";
  1221. // 打印ogo
  1222. content += "<div style=\"text-align: center;width: 100%;height: 260px;\">";
  1223. content += "<img src='/statics/img/cw_logo2.png' style='width: 100%;height: 100%;' />";
  1224. content += "</div>";
  1225. //小票头
  1226. content += "<div style=\"text-align: center;width: 100%;font-weight:bold;font-size: 13px;\">";
  1227. content += ticket.ticketHead.title;
  1228. content += "</div>";
  1229. /*content += "<div style=\"width: 100%;\">";
  1230. content += "会员:" + ticket.ticketHead.memberId;
  1231. content += "</div>";*/
  1232. content += "<div style=\"width: 100%;font-size: 25px;\">";
  1233. content += "取货码:" + vm.pickUpCode;
  1234. content += "</div>";
  1235. content += "<div style=\"width: 100%;\">";
  1236. content += "订单号:" + ticket.ticketHead.orderId;
  1237. content += "</div>";
  1238. content += "<div style=\"width: 100%;\">";
  1239. content += "交易时间:" + ticket.ticketHead.tradeTime;
  1240. content += "</div>";
  1241. content += "<div style=\"width: 100%;overflow:hidden;white-space: nowrap;\">-------------------------------------------------------</div>";
  1242. //商品信息
  1243. content += "<table style=\"width: 100%;\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
  1244. content += "<tr>";
  1245. content += "<td style=\"width: 40%;text-align: left;font-size: 10px;font-weight: bold;\">商品名称</td>";
  1246. content += "<td style=\"width: 17%;text-align: right;font-size: 10px;font-weight: bold;\">单价</td>";
  1247. content += "<td style=\"width: 17%;text-align: right;font-size: 10px;font-weight: bold;\">优惠</td>";
  1248. // content += "<td style=\"width: 16%;text-align: right;font-size: 10px;font-weight: bold;\">税费</td>";
  1249. content += "<td style=\"width: 15%;text-align: right;font-size: 10px;font-weight: bold;\">数量</td>";
  1250. content += "<td style=\"width: 18%;text-align: right;font-size: 10px;font-weight: bold;\">小计</td>";
  1251. content += "</tr>";
  1252. content += "</table>";
  1253. content += "<div style=\"width: 100%;overflow:hidden;white-space: nowrap;\">-------------------------------------------------------</div>";
  1254. content += "<table style=\"width: 100%;\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
  1255. for (var i=0;i< ticket.goods.length;i++){
  1256. content += "<tr>";
  1257. content += "<td style=\"width: 40%;text-align: left;font-size: 8px;padding-top: 8px;\">";
  1258. content += "<table style=\"width: 100%;\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
  1259. content += "<tr>";
  1260. content += "<td style=\"text-align: left;font-size: 8px;vertical-align:top;\">#</td>";
  1261. content += "<td style=\"text-align: left;font-size: 8px;\">" + ticket.goods[i].gname + "</td>";
  1262. content += "</tr>";
  1263. content += "</table>";
  1264. content += "</td>";
  1265. content += "<td style=\"width: 17%;text-align: right;font-size: 8px;vertical-align:bottom;padding-top: 8px;\">" + ticket.goods[i].uprice + "</td>";
  1266. content += "<td style=\"width: 17%;text-align: right;font-size: 8px;vertical-align:bottom;padding-top: 8px;\">" + ticket.goods[i].discountPrice + "</td>";
  1267. // content += "<td style=\"width: 17%;text-align: right;font-size: 8px;vertical-align:bottom;padding-top: 8px;\">" + ticket.goods[i].taxation + "</td>";
  1268. content += "<td style=\"width: 15%;text-align: center;font-size: 8px;vertical-align:bottom;padding-top: 8px;\">" + ticket.goods[i].num + "</td>";
  1269. content += "<td style=\"width: 18%;text-align: right;font-size: 8px;vertical-align:bottom;padding-top: 8px;\">" + ticket.goods[i].subtotal + "</td>";
  1270. content += "</tr>";
  1271. }
  1272. content += "</table>";
  1273. content += "<div style=\"width: 100%;overflow:hidden;white-space: nowrap;\">--------------------------------------------------</div>";
  1274. //收银信息
  1275. content += "<div style=\"width: 100%;\">";
  1276. content += "<span style=\"float: left;width: 50%;text-align: left;\">商品合计:</span>";
  1277. content += "<span style=\"float: left;width: 17%;text-align: left;\">" + ticket.cashInfo.goodsTotal + "件</span>";
  1278. content += "<span style=\"float: right;width: 33%;text-align: right;\">" + ticket.cashInfo.total + "元</span>";
  1279. content += "</div>";
  1280. content += "<div style=\"width: 100%;\">";
  1281. content += "<span style=\"float: left;width: 50%;text-align: left;\">税费合计:</span>";
  1282. content += "<span style=\"float: left;width: 17%;text-align: left;\">" + ticket.cashInfo.goodsTotal + "件</span>";
  1283. content += "<span style=\"float: right;width: 33%;text-align: right;\">" + ticket.cashInfo.taxTotal + "元</span>";
  1284. content += "</div>";
  1285. content += "<div style=\"width: 100%;\">";
  1286. content += "<span style=\"float: left;width: 50%;text-align: left;\">优惠合计:</span>";
  1287. content += "<span style=\"float: right;width: 50%;text-align: right;\">" + ticket.cashInfo.oddChange + "元</span>";
  1288. content += "</div>";
  1289. content += "<div style=\"width: 100%;\">";
  1290. content += "<span style=\"float: left;width: 50%;text-align: left;\">实收:</span>";
  1291. content += "<span style=\"float: right;width: 50%;text-align: right;\">" + ticket.cashInfo.receipts + "元</span>";
  1292. content += "</div>";
  1293. content += "<div style=\"width: 100%;\">";
  1294. content += "<span style=\"float: left;width: 50%;text-align: left;\">优惠券:</span>";
  1295. content += "<span style=\"float: right;width: 50%;text-align: right;\">" + ticket.cashInfo.coupon + "元</span>";
  1296. content += "</div>";
  1297. // content += "<div style=\"width: 100%;\">";
  1298. // content += "<span style=\"float: left;width: 50%;text-align: left;\">运费:</span>";
  1299. // content += "<span style=\"float: right;width: 50%;text-align: right;\">" + ticket.cashInfo.freight + "元</span>";
  1300. // content += "</div>";
  1301. content += "<div style=\"width: 100%;\">";
  1302. content += "<span style=\"float: left;width: 50%;text-align: left;\">支付渠道:</span>";
  1303. // 后期改成从系统中取
  1304. content += "<span style=\"float: right;width: 50%;text-align: right;\">" + "支付宝支付" + "</span>";
  1305. content += "</div>";
  1306. content += "<div style=\"width: 100%;overflow:hidden;white-space: nowrap;\">--------------------------------------------------</div>";
  1307. //海关清单信息
  1308. content += "<div style=\"width: 100%;\">";
  1309. content += "订单号:" + ticket.cusListing.orderId;
  1310. content += "</div>";
  1311. content += "<div style=\"width: 100%;\">";
  1312. content += "运单编号:" + ticket.cusListing.waybillId;
  1313. content += "</div>";
  1314. content += "<div style=\"width: 100%;\">";
  1315. content += "海关清单号:" + ticket.cusListing.invtNo;
  1316. content += "</div>";
  1317. content += "<div style=\"width: 100%;\">";
  1318. content += "收货人:" + ticket.cusListing.consignee;
  1319. content += "</div>";
  1320. content += "<div style=\"width: 100%;\">";
  1321. content += "收货人电话:" + ticket.cusListing.consigneeTel;
  1322. content += "</div>";
  1323. content += "<div style=\"width: 100%;\">";
  1324. content += "始发地: 仓库地址 : 广东省深圳市南山区前海保税港区W104" ;
  1325. content += "</div>";
  1326. content += "<div style=\"width: 100%;\">";
  1327. content += "交货地:" + ticket.cusListing.deliveryAddress;
  1328. content += "</div>";
  1329. content += "<div style=\"width: 100%;overflow:hidden;white-space: nowrap;\">--------------------------------------------------</div>";
  1330. content += "<div style=\"width: 100%;text-align: center;\">";
  1331. content += "购买跨境商品须知:"
  1332. content += "</div>";
  1333. content += "<div style=\"width: 100%;\">";
  1334. content += "1、凡购买跨境商品均不提供发票;<br> 2、单笔限购5000元,年交易限额2.6万元; <br> 3、所有订单经海关放行后方可提货; <br> 4、凭小票领取您的订单商品; <br> 5、非产品质量问题,跨境商品不支持无理由退换货,请及时检查。 "
  1335. content += "</div>";
  1336. content += "<div style=\"width: 100%;overflow:hidden;white-space: nowrap;\">--------------------------------------------------</div>";
  1337. content += "<div style=\"width: 100%;\">";
  1338. // content += ticket.ticketFoot.summary;
  1339. content += "</div>";
  1340. content += "<div style=\"width: 100%;\">";
  1341. // content += "客服电话:" + ticket.ticketFoot.serviceTel;
  1342. content += "</div>";
  1343. content += "<div style=\"width: 100%;\">";
  1344. // content += "网址:" + ticket.ticketFoot.url1;
  1345. content += "</div>";
  1346. content += "<div style=\"width: 100%;\">";
  1347. content += ticket.ticketFoot.welcome;
  1348. content += "</div>";
  1349. content += "<div style=\"width: 100%;\">";
  1350. content += "惠州市惠城区港惠购物中心负一层";
  1351. content += "</div>";
  1352. content += "<div style=\"width: 100%;\">";
  1353. content += "请保管好收银小票。";
  1354. content += "</div>";
  1355. // 打印二维码
  1356. content += "<div style=\"text-align: center;width: 100%;height: 250px;\">";
  1357. content += "<img src='/statics/img/cw_qrcode.png' style='width: 100%;height: 100%;' />";
  1358. content += "</div>";
  1359. content += "<div style=\"width: 100%;text-align: center;\">";
  1360. content += "关注CW大药房客服号,获取更多优惠信息"
  1361. content += "</div>";
  1362. return content;
  1363. }
  1364. function queryAssistantInfo(){
  1365. $.get("../sys/user/info", function (r) {
  1366. if(r.code == 0){
  1367. vm.sysUserInfo = r.user;
  1368. $.get("../store/getStoresByMerch?merchSn="+r.user.merchSn+"&_=1590374349985",function(result){
  1369. if(result.code == 0){
  1370. for(var i = 0 ;i < result.list.length; i++){
  1371. if(result.list[i].id == r.user.storeId){
  1372. vm.storeName = result.list[i].storeName;
  1373. break;
  1374. }
  1375. }
  1376. }
  1377. });
  1378. }
  1379. });
  1380. }
  1381. function removeByValue(arr, val) {
  1382. var index = arr.indexOf(val);
  1383. if (index > -1) {
  1384. arr.splice(index, 1);
  1385. }
  1386. }
  1387. function handle(goodsDetails,operatorType){
  1388. vm.goodsDetail = true;
  1389. // goodsDetails.sellVolume = 1;
  1390. goodsDetails.id = vm.index;
  1391. if(!vm.goodsList[vm.index]){
  1392. vm.index = vm.max;
  1393. }
  1394. vm.max++;
  1395. goodsDetails.goodsDesc = "";
  1396. // 判断当前商品是否是赠品
  1397. var freeMap = vm.freeBardcode.get(goodsDetails.prodBarcode);
  1398. if(freeMap && "minus" != operatorType){
  1399. goodsDetails.actualPaymentAmount = 0;
  1400. goodsDetails.discountedPrice = goodsDetails.retailPrice;
  1401. vm.freeBardcode.set(goodsDetails.prodBarcode,freeMap - 1);
  1402. }else{
  1403. if(!freeMap && freeMap != 0 ){
  1404. // 判断购物车中是否有赠品 这个操作只有是非赠品才能进来
  1405. for(var i = 0 ; i < vm.goodsList.length ; i++){
  1406. var shopcartGoods = vm.goodsList[i];
  1407. var shopcartFree = vm.freeBardcode.get(shopcartGoods.prodBarcode);
  1408. if(shopcartFree /*&& shopcartGoods.actualPaymentAmount*/){
  1409. // if("minus" != operatorType){
  1410. var shopcartSellNum = shopcartGoods.sellVolume;
  1411. if(shopcartFree > shopcartSellNum){
  1412. shopcartGoods.actualPaymentAmount = 0;
  1413. shopcartGoods.discountedPrice = shopcartGoods.retailPrice * shopcartFree;
  1414. vm.discountedPrice = vm.discountedPrice + shopcartGoods.discountedPrice ;
  1415. vm.actualPrice = vm.actualPrice + shopcartGoods.actualPaymentAmount ;
  1416. vm.freeBardcode.set(shopcartGoods.prodBarcode,shopcartFree - 1);//
  1417. }else if(shopcartFree == -1 ){
  1418. // g.actualPaymentAmount == 0){
  1419. shopcartGoods.actualPaymentAmount = shopcartGoods.retailPrice + shopcartGoods.actualPaymentAmount;
  1420. shopcartGoods.discountedPrice = shopcartGoods.discountedPrice - shopcartGoods.retailPrice;
  1421. vm.discountedPrice = vm.discountedPrice + shopcartGoods.discountedPrice ;
  1422. vm.actualPrice = vm.actualPrice + shopcartGoods.actualPaymentAmount ;
  1423. vm.freeBardcode.set(shopcartGoods.prodBarcode,0);// 重置回0
  1424. }else{
  1425. if(shopcartGoods.actualPaymentAmount > 0){
  1426. shopcartGoods.actualPaymentAmount = shopcartGoods.actualPaymentAmount - (shopcartGoods.retailPrice * shopcartFree);
  1427. shopcartGoods.discountedPrice = shopcartGoods.discountedPrice + (shopcartGoods.retailPrice * shopcartFree);
  1428. vm.actualPrice = vm.actualPrice - (shopcartGoods.retailPrice * shopcartFree) ;
  1429. vm.discountedPrice = vm.discountedPrice + (shopcartGoods.retailPrice * shopcartFree) ;
  1430. vm.freeBardcode.set(shopcartGoods.prodBarcode, shopcartFree - 1);// 重置回0
  1431. }
  1432. }
  1433. // }
  1434. }
  1435. }
  1436. }
  1437. }
  1438. goodsDetails.discountedPrice = Math.round(goodsDetails.discountedPrice * 100) / 100;
  1439. goodsDetails.actualPaymentAmount = Math.round(goodsDetails.actualPaymentAmount * 100) / 100;
  1440. var data = Object.assign({}, JSON.parse(JSON.stringify(goodsDetails)));
  1441. var isPush = true;
  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. if(data.actualPaymentAmount < 0 && goodsDetails.actualPaymentAmount == 0){
  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 = 0;
  1450. }else{
  1451. // 税 goodstaxes,优惠金额 discountedPrice,实际支付 actualPaymentAmount,数量 sellVolume 45636917
  1452. goodsDetails.actualPaymentAmount = Math.round((parseFloat(goodsDetails.actualPaymentAmount) + parseFloat(data.actualPaymentAmount)) * 100)/100;
  1453. }
  1454. goodsDetails.discountedPrice = Math.round((parseFloat(goodsDetails.discountedPrice) + parseFloat(data.discountedPrice)) * 100)/100;
  1455. goodsDetails.goodstaxes = Math.round((parseFloat(goodsDetails.goodstaxes) + parseFloat(data.goodstaxes)) * 100)/100;
  1456. goodsDetails.sellVolume = Math.round((parseFloat(goodsDetails.sellVolume) + parseFloat(data.sellVolume)) * 100)/100;
  1457. goodsDetails.activity = data.activity;
  1458. isPush = false;
  1459. break;
  1460. }
  1461. }
  1462. // for(var i = 0 ; i < vm.goodsList.length ; i++){
  1463. // if(vm.goodsList[i].goodsSn == data.goodsSn){
  1464. // var goodsDetails = vm.goodsList[i];
  1465. // // 税 goodstaxes,优惠金额 discountedPrice,实际支付 actualPaymentAmount,数量 sellVolume 45636917
  1466. // goodsDetails.goodstaxes = Math.round((parseFloat(goodsDetails.goodstaxes) + parseFloat(data.goodstaxes)) * 100)/100;
  1467. // goodsDetails.discountedPrice = Math.round((parseFloat(goodsDetails.discountedPrice) + parseFloat(data.discountedPrice)) * 100)/100;
  1468. // goodsDetails.actualPaymentAmount = Math.round((parseFloat(goodsDetails.actualPaymentAmount) + parseFloat(data.actualPaymentAmount)) * 100)/100;
  1469. // goodsDetails.sellVolume = Math.round((parseFloat(goodsDetails.sellVolume) + parseFloat(data.sellVolume)) * 100)/100;
  1470. // goodsDetails.activity = data.activity;
  1471. // isPush = false;
  1472. // break;
  1473. // }
  1474. // }
  1475. if(isPush){
  1476. vm.goodsList.push(data);
  1477. vm.index = vm.index + 1;
  1478. }
  1479. vm.totalPrice = (vm.totalPrice + data.retailPrice);
  1480. if("minus" == operatorType){
  1481. vm.totalCount = vm.totalCount - 1;
  1482. }else{
  1483. vm.totalCount = vm.totalCount + 1;
  1484. }
  1485. if(vm.reduceMoney > 0){
  1486. vm.discountedPrice = vm.discountedPrice + data.discountedPrice + vm.reduceMoney;
  1487. vm.actualPrice = vm.actualPrice + data.actualPaymentAmount - vm.reduceMoney;
  1488. vm.showReduceMoney = vm.showReduceMoney + vm.reduceMoney;
  1489. vm.reduceMoney = 0;
  1490. }else{
  1491. vm.discountedPrice = vm.discountedPrice + data.discountedPrice ;
  1492. vm.actualPrice = vm.actualPrice + data.actualPaymentAmount ;
  1493. }
  1494. if(data.sellVolume < 0){
  1495. data.sellVolume = - data.sellVolume;
  1496. data.retailPrice = - data.retailPrice;
  1497. data.goodstaxes = -data.goodstaxes;
  1498. }
  1499. vm.goods = data;
  1500. // 处理精度
  1501. vm.totalPrice = Math.round(vm.totalPrice * 100) / 100;
  1502. vm.discountedPrice = Math.round(vm.discountedPrice * 100) / 100;
  1503. vm.actualPrice = Math.round(vm.actualPrice * 100) / 100;
  1504. vm.showReduceMoney = Math.round(vm.showReduceMoney * 100) / 100;
  1505. }
  1506. function toPayOrder(payCode){
  1507. $('#payCode').unbind('keydown').keydown(function(event){});
  1508. vm.machineCode = sessionStorage.getItem("machineCode");
  1509. console.log(vm.machineCode);
  1510. var param = {'userInfo':vm.userInfo,'payCode':vm.parCode,'goodsList':vm.goodsList,'sessionId':vm.sessionId,'machineCode':vm.machineCode};
  1511. console.log(JSON.stringify(param));
  1512. vm.parCode = "";
  1513. $.ajax({
  1514. type: "POST",
  1515. url: "../order/orderConfirm",
  1516. contentType: "application/json",
  1517. data: JSON.stringify(param),
  1518. success: function (r) {
  1519. console.log(r);
  1520. if (r.code == 0) {
  1521. if (r.resultObj != null) {
  1522. $(".form-group input[type=text]").each(function(){
  1523. this.value = '';
  1524. })
  1525. // 打印取货码小票
  1526. var content = getPrintContent(r.resultObj);
  1527. console.log(content);
  1528. printArea2(content);
  1529. vm.goodsList = [];
  1530. vm.customname = '' ;
  1531. vm.customidcard = '';
  1532. vm.customClearData();
  1533. }else{
  1534. // alert("打印小票失败");
  1535. }
  1536. } else {
  1537. alert(r.msg);
  1538. }
  1539. }
  1540. });
  1541. }
  1542. function toRefund(){
  1543. confirm('确认退款吗?', function () {
  1544. $.ajax({
  1545. type: "POST",
  1546. url: "../order/orderRefund",
  1547. contentType: "application/json",
  1548. data: JSON.stringify({'orderId':vm.currentOrderNo,'sessionId':vm.sessionId}),
  1549. success: function (r) {
  1550. if (r.code == 0) {
  1551. alert("退款成功")
  1552. }else{
  1553. alert("退款失败,请联系管理员");
  1554. }
  1555. }
  1556. });
  1557. })
  1558. }