1
0

sale.js 83 KB

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