sale.js 64 KB

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