sale.js 64 KB

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