sale.js 70 KB

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