sale.js 70 KB

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