sale.js 85 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095
  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. let goodsDetails = JSON.parse(JSON.stringify(vm.goodsList[i]));
  670. console.log("加法 goods detail =====>" + JSON.stringify(goodsDetails));
  671. /*calculateGoodsByMj(goodsDetails,"add");
  672. calculateGoodsByMysy(goodsDetails,"add");
  673. calculateGoodsByHalfPrice(goodsDetails,"add");*/
  674. // calculateGoodsByMz(goodsDetails,"add");
  675. handleSellVolume(goodsDetails, "add");
  676. // handle(goodsDetails,"add");
  677. break;
  678. }
  679. }
  680. },
  681. minus:function(value){
  682. // 减少数量
  683. for(var i = 0 ; i < this.goodsList.length ; i++){
  684. if(this.goodsList[i].id == value){
  685. // 获取当前购物车的数量
  686. let goodsDetails = JSON.parse(JSON.stringify(vm.goodsList[i]));
  687. console.log("减法 goods detail =====>" + JSON.stringify(goodsDetails));
  688. if(goodsDetails.sellVolume === 1){
  689. alert("数量至少为1个");
  690. return ;
  691. }
  692. // 如果不为空,证明减的是买A送B中的B,这时候要还原赠送资格跟B的扣减
  693. /*var freeMap = vm.freeBardcode.get(goodsDetails.prodBarcode);
  694. if((freeMap || freeMap == 0) && g.actualPaymentAmount == 0){
  695. vm.freeBardcode.set(goodsDetails.prodBarcode,freeMap + 1);
  696. goodsDetails.sellVolume = -1;
  697. goodsDetails.actualPaymentAmount = 0;
  698. goodsDetails.discountedPrice = -goodsDetails.retailPrice;
  699. goodsDetails.goodstaxes = - goodsDetails.goodstaxes;
  700. goodsDetails.retailPrice = - goodsDetails.retailPrice;
  701. }else{
  702. goodsDetails.sellVolume = g.sellVolume;
  703. calculateGoodsByMj(goodsDetails,"minus");
  704. calculateGoodsByMysy(goodsDetails,"minus");
  705. calculateGoodsByHalfPrice(goodsDetails,"minus");
  706. // calculateGoodsByMz(goodsDetails,"minus");
  707. goodsDetails.sellVolume = -1;
  708. goodsDetails.actualPaymentAmount = -goodsDetails.actualPaymentAmount;
  709. goodsDetails.discountedPrice = -goodsDetails.discountedPrice;
  710. goodsDetails.goodstaxes = - goodsDetails.goodstaxes;
  711. goodsDetails.retailPrice = - goodsDetails.retailPrice;
  712. }*/
  713. handleSellVolume(goodsDetails, "minus");
  714. // handle(goodsDetails,"minus");
  715. break;
  716. }
  717. }
  718. },
  719. selectItem:function(value) {
  720. console.log(value);
  721. },
  722. deleteItem:function(value){
  723. console.log(value);
  724. // 删除这条记录
  725. for(var i = 0 ; i < this.goodsList.length ; i++){
  726. if(this.goodsList[i].id == value){
  727. if(this.goodsList.length == 1){
  728. vm.goods = {};
  729. vm.goodsDetail = false;
  730. }
  731. if(vm.mz.get(this.goodsList[i].prodBarcode)){
  732. vm.mz.get(this.goodsList[i].prodBarcode).useMz = false ;
  733. }
  734. if(vm.brandGetOneFree.get(this.goodsList[i].brand)){
  735. var giftBarcode = vm.brandGetOneFree.get(this.goodsList[i].brand).giftBarcode;
  736. var muilty = vm.brandGetOneFree.get(this.goodsList[i].brand).buyNum;
  737. var sellNum = this.goodsList[i].sellVolume;;
  738. vm.freeBardcode.set(giftBarcode,sellNum/muilty);
  739. for(var j = 0 ; j < vm.goodsList.length ; j++){
  740. var shopcartGoods = vm.goodsList[j];
  741. var shopcartFree = vm.freeBardcode.get(shopcartGoods.prodBarcode);
  742. if(shopcartFree /*&& shopcartGoods.actualPaymentAmount*/){
  743. shopcartGoods.actualPaymentAmount = shopcartGoods.actualPaymentAmount + (shopcartGoods.retailPrice * shopcartGoods.sellVolume);
  744. shopcartGoods.discountedPrice = shopcartGoods.discountedPrice - (shopcartGoods.retailPrice * shopcartGoods.sellVolume);
  745. vm.discountedPrice = vm.discountedPrice - (shopcartGoods.retailPrice * shopcartGoods.sellVolume);
  746. vm.actualPrice = vm.actualPrice + (shopcartGoods.retailPrice * shopcartGoods.sellVolume);
  747. vm.freeBardcode.set(shopcartGoods.prodBarcode, 0);// 重置回0
  748. }
  749. }
  750. }
  751. if(vm.halfPrice.get(this.goodsList[i].prodBarcode)){
  752. vm.halfPrice.set(this.goodsList[i].prodBarcode,1);
  753. }
  754. var goods = this.goodsList[i];
  755. console.log(goods);
  756. console.log(vm.totalPrice);
  757. if(vm.freeBardcode.get(goods.prodBarcode) || vm.freeBardcode.get(goods.prodBarcode) == 0){
  758. var nnum = (((goods.retailPrice * goods.sellVolume) - goods.actualPaymentAmount)/goods.retailPrice);
  759. vm.freeBardcode.set(goods.prodBarcode, nnum);
  760. }
  761. vm.totalPrice = vm.totalPrice - (goods.retailPrice * goods.sellVolume);
  762. vm.totalCount = vm.totalCount - (goods.sellVolume);
  763. vm.discountedPrice = vm.discountedPrice - goods.discountedPrice;
  764. vm.actualPrice = vm.actualPrice - goods.actualPaymentAmount;
  765. vm.boughtNum.delete(goods.prodBarcode);
  766. vm.totalPrice = Math.round(vm.totalPrice * 100) / 100;
  767. vm.discountedPrice = Math.round(vm.discountedPrice * 100) / 100;
  768. vm.actualPrice = Math.round(vm.actualPrice * 100) / 100;
  769. vm.showReduceMoney = Math.round(vm.showReduceMoney * 100) / 100;
  770. this.goodsList.splice(i,1);
  771. break;
  772. }
  773. }
  774. this.index = value;
  775. },
  776. clearGoodsList:function(){
  777. confirm('确认清空吗?', function () {
  778. alert("清空成功");
  779. })
  780. },
  781. pendingOrder:function(){
  782. if(this.goodsList.length == 0){
  783. alert("购物车中没有商品");
  784. return;
  785. }
  786. console.log(vm.pendingOrderMap.size);
  787. if(vm.pendingOrderMap.size >= 3){
  788. alert("订单挂起最多支持3单");
  789. return;
  790. }
  791. var pendingObject = {
  792. 'goodsList':this.goodsList,
  793. 'totalPrice':vm.totalPrice,
  794. 'totalCount':vm.totalCount,
  795. 'discountedPrice':vm.discountedPrice,
  796. 'actualPrice':vm.actualPrice
  797. }
  798. vm.pendingOrderMap.set(vm.pendingIndex,pendingObject);
  799. vm.pendingOrderKeys.push(vm.pendingIndex);
  800. var newIndex = ++vm.pendingIndex;
  801. vm.pendingIndex = newIndex > 3?1: newIndex;
  802. vm.goodsList = [];
  803. vm.customClearData();
  804. },
  805. toResumePending:function(){
  806. if(vm.pendingOrderMap.size == 0){
  807. alert("当前没有挂起的订单");
  808. return ;
  809. }
  810. $('#pendignOrderModal').modal('show')
  811. },
  812. resumePending:function(key){
  813. if(vm.pendingOrderMap.size == 0){
  814. alert("当前没有挂起的订单");
  815. return ;
  816. }
  817. if(vm.goodsList.length > 0){
  818. alert("购物车中已有商品,不允许恢复!")
  819. return ;
  820. }
  821. var pendingObject = vm.pendingOrderMap.get(key);
  822. console.log(pendingObject);
  823. vm.goodsList = pendingObject.goodsList;
  824. vm.totalPrice = pendingObject.totalPrice;
  825. vm.totalCount = pendingObject.totalCount;
  826. vm.discountedPrice = pendingObject.discountedPrice;
  827. vm.actualPrice = pendingObject.actualPrice;
  828. // 清除恢复的数据
  829. vm.pendingOrderMap.delete(key);
  830. removeByValue(vm.pendingOrderKeys,key);
  831. $('#pendignOrderModal').modal('hide')
  832. },
  833. toOrderSubmit:function(){
  834. if(this.goodsList.length == 0){
  835. alert("请选择商品");
  836. return;
  837. }
  838. $('#myModal').modal('show')
  839. // 每次点击提交订单的时候清空姓名和身份证信息和手机号
  840. vm.$refs.customName.value = "";
  841. vm.$refs.customIDCard.value = "";
  842. vm.$refs.customPhone.value = "";
  843. vm.$refs.couponBarCode.value = "";
  844. if(vm.$refs.couponSn)
  845. vm.$refs.couponSn.value = "";
  846. this.userInfo.couponSn = "";
  847. },
  848. // 点击计算优惠价按钮,弹出输入框
  849. calculateOrderPrice : function () {
  850. if (this.calGoodsList.length == 0) {
  851. alert("请选择商品");
  852. return;
  853. }
  854. $("#calculateOrderPriceDialog").modal('show');
  855. },
  856. // 计算优惠价格,返回订单详情数据
  857. calculateOrderPriceSubmit : function () {
  858. console.log("11111");
  859. console.log("点击计算=====>" + JSON.stringify(vm.goodsList));
  860. var couponBarCode = vm.$refs.couponBarCode;
  861. if (couponBarCode === null || couponBarCode === '') {
  862. alert("无会员码,不能参加积分抵扣活动!\n计算中...");
  863. }
  864. calculateOrderPrice();
  865. },
  866. // 提交订单
  867. submitOrder:function(){
  868. vm.parCode = this.$refs.payCode.currentValue
  869. vm.myDebounce();
  870. },customClearData: function(){
  871. vm.totalPrice = 0;
  872. vm.totalCount = 0;
  873. vm.discountedPrice = 0;
  874. vm.actualPrice = 0;
  875. vm.goods={};
  876. vm.goodsDetail = false;
  877. // 第二件半价
  878. vm.halfPrice = new Map();
  879. // 买一送一
  880. vm.mysy = [];
  881. vm.freeBardcode = new Map();
  882. vm.brandGetOneFree = new Map();
  883. vm.barcodeGetOneFree = new Map();
  884. vm.brandGetOneFree = new Map();
  885. vm.boughtNum = new Map();
  886. // 组合价
  887. vm.zhjsp = new Map();
  888. vm.combinationPrice = new Map(); // 组合价商品的组合价
  889. // 满减
  890. vm.mj = new Map();
  891. vm.accumulatedAmount = new Map();// 累积金额(满减使用的)
  892. vm.reduceMoney = 0; // 满减金额
  893. vm.showReduceMoney = 0; // 用于展示的满减金额
  894. // 满赠
  895. vm.mz = new Map();
  896. vm.accumulatedAmountForFullGift = new Map(); // 累积金额(满赠使用的)
  897. vm.fullGiftCode = [];// 满赠商品条码
  898. // 优惠券
  899. vm.coupons = new Map();
  900. },
  901. queryIDCardInfo: function(){
  902. $.get("../order/queryIDCardInfo/"+vm.$refs.customPhone.value, function (r){
  903. if(r.code === 0){
  904. var data = r.userEntity;
  905. vm.$refs.customName.value = data.username;
  906. vm.$refs.customIDCard.value = data.idNo;
  907. }else{
  908. alert(r.msg);
  909. }
  910. });
  911. },
  912. sendDiva: function(){
  913. // document.getElementsByClassName('sendShow').style.display='none';
  914. $('.sendShow').hide();
  915. },
  916. sendDivb: function(){
  917. // document.getElementsByClassName('sendShow').style.display='block';
  918. $('.sendShow').show();
  919. },
  920. getIDCardInfo: function(){
  921. $.post("http://127.0.0.1:8000/idcard/read", function (r){
  922. if(r.code == "0"){
  923. vm.$refs.customName.value = r.rows[0].data.name;
  924. vm.$refs.customIDCard.value = r.rows[0].data.id_no;
  925. }else if(r.code=="-1"){
  926. alert(r.msg);
  927. return;
  928. }else{
  929. alert("请连接设备或设备有问题,请联系管理员!");
  930. }
  931. });
  932. },
  933. customPhoneBlur:function (){
  934. let customPhone = this.$refs.customPhone.value;
  935. if(customPhone){
  936. for(let key in this.userInfoBinding){
  937. if(customPhone == key){
  938. let userInfoBindingValue = this.userInfoBinding[key];
  939. this.$refs.customName.value = userInfoBindingValue.substring(0, userInfoBindingValue.length-18);
  940. this.$refs.customIDCard.value = userInfoBindingValue.substring(userInfoBindingValue.length-18);
  941. break;
  942. }
  943. }
  944. }
  945. },
  946. // 填写并验证顾客信息
  947. submitCustomInfo:function(){
  948. this.userInfo.customName = this.$refs.customName.value ;
  949. this.userInfo.customIDCard = this.$refs.customIDCard.value ;
  950. this.userInfo.customPhone = this.$refs.customPhone.value;
  951. this.userInfo.couponBarCode = this.$refs.couponBarCode.value;
  952. var status = $('input:radio:checked').val();
  953. var cmbCity = $('#cmbCity').val();
  954. var cmbProvince = $('#cmbProvince').val();
  955. var cmbArea = $('#cmbArea').val();
  956. var addrUser = $('#addrUser').val();
  957. // console.log('城市三级联动的值:'+cmbProvince+'|'+cmbCity+'|'+cmbArea+'|'+addrUser);
  958. if (status == 0) {
  959. if (cmbCity =="请选择"){
  960. alert("请选择省!");
  961. return ;
  962. }
  963. if (cmbProvince =="请选择"){
  964. alert("请选择市!");
  965. return ;
  966. }
  967. if (cmbArea =="请选择"){
  968. alert("请选择区!");
  969. return ;
  970. }
  971. if (addrUser == "") {
  972. alert("请填写详细地址!");
  973. return ;
  974. }
  975. }
  976. if(this.$refs.couponSn)
  977. this.userInfo.couponSn = this.$refs.couponSn.value;
  978. 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)$/;
  979. if(!this.userInfo.customName){
  980. alert("姓名不能为空!");
  981. return ;
  982. }
  983. if(!idcardReg.test(this.userInfo.customIDCard)){
  984. alert("请输入正确的身份证号");
  985. return ;
  986. }
  987. if(!(/^1[3456789]\d{9}$/.test(this.userInfo.customPhone))){
  988. alert("手机号码有误,请重填");
  989. return ;
  990. }
  991. //将手机号与姓名身份证号进行绑定,下次填写手机号即可
  992. let userInfoBindingKey = this.userInfo.customPhone;
  993. let userInfoBindingValue = this.userInfo.customName+this.userInfo.customIDCard;
  994. this.userInfoBinding[userInfoBindingKey] = userInfoBindingValue;
  995. if(this.userInfo.couponSn && this.userInfo.couponSn != ""){
  996. var coupon = vm.coupons.get(this.userInfo.couponSn);
  997. if(coupon == null){
  998. alert("请输入正确的优惠券码");
  999. return ;
  1000. }
  1001. }
  1002. $("#Send").attr("data-dismiss","modal");
  1003. $('#payModal').modal('show');
  1004. $("#payCode").keydown(function(e){
  1005. if(e.keyCode==13){
  1006. $("#submitOrder").click();
  1007. event.preventDefault();
  1008. }
  1009. });
  1010. $('body').on('hidden.bs.modal', '.modal', function () {
  1011. $(this).removeData();
  1012. });
  1013. },
  1014. queryOrderDetail:function(orderSn,pickUpCode){
  1015. var storeId = sessionStorage.getItem("storeId");
  1016. $.get("../order/orderDetail/"+orderSn, function (r) {
  1017. if (r.code == 0) {
  1018. vm.orderProcessRecord = r.resultObj.orderProcessRecordEntity;
  1019. vm.orderEntity = r.resultObj.orderEntity;
  1020. vm.goodsDetailList = r.resultObj.goodsList;
  1021. vm.currentOrderNo = r.resultObj.orderEntity.id;
  1022. vm.pickUpCode = pickUpCode;
  1023. vm.tax = r.resultObj.tax;
  1024. vm.response = r.resultObj.response;
  1025. if(vm.orderProcessRecord.eleOrderStartTime){
  1026. vm.orderProcessRecord.eleOrderStartTime = parsedate(vm.orderProcessRecord.eleOrderStartTime);
  1027. }
  1028. if(vm.orderProcessRecord.paymentStartTime){
  1029. vm.orderProcessRecord.paymentStartTime = parsedate(vm.orderProcessRecord.paymentStartTime);
  1030. }
  1031. if(vm.orderProcessRecord.waybillStartTime){
  1032. vm.orderProcessRecord.waybillStartTime = parsedate(vm.orderProcessRecord.waybillStartTime);
  1033. }
  1034. if(vm.orderProcessRecord.customsSuccTime){
  1035. vm.orderProcessRecord.customsSuccTime = parsedate(vm.orderProcessRecord.customsSuccTime);
  1036. }
  1037. if(vm.orderProcessRecord.addOrderStartTime){
  1038. vm.orderProcessRecord.addOrderStartTime = parsedate(vm.orderProcessRecord.addOrderStartTime);
  1039. }
  1040. }
  1041. });
  1042. },
  1043. resendNotice:function(){
  1044. confirm('确认重发重置吗?', function () {
  1045. $.get("../order/resendOrderToCCNET/"+vm.orderEntity.orderSn+"/notice", function (r) {
  1046. alert(r.msg);
  1047. });
  1048. })
  1049. },
  1050. resendWaybill:function(){
  1051. confirm('确认重发运单吗?', function () {
  1052. $.get("../order/resendOrderToCCNET/"+vm.orderEntity.orderSn+"/waybill", function (r) {
  1053. alert(r.msg);
  1054. });
  1055. })
  1056. },
  1057. resendPayment:function(){
  1058. confirm('确认重发支付单吗?', function () {
  1059. $.get("../order/resendOrderToCCNET/"+vm.orderEntity.orderSn+"/payment", function (r) {
  1060. alert(r.msg);
  1061. });
  1062. })
  1063. },
  1064. resendOrder:function(){
  1065. confirm('确认重发电子订单吗?', function () {
  1066. $.get("../order/resendOrderToCCNET/"+vm.orderEntity.orderSn+"/clsOrder", function (r) {
  1067. alert(r.msg);
  1068. });
  1069. })
  1070. },
  1071. forceSendToOms:function(){
  1072. confirm('确认强制推送清关吗?', function () {
  1073. $.get("../order/resendOrderToCCNET/"+vm.orderEntity.orderSn+"/forceSend", function (r) {
  1074. alert(r.msg);
  1075. });
  1076. })
  1077. },
  1078. resendorder:function(){
  1079. confirm('确认重发订单吗?', function () {
  1080. $.get("../order/resendOrderToCCNET/"+vm.orderEntity.orderSn+"/resendOrder", function (r) {
  1081. alert(r.msg);
  1082. });
  1083. })
  1084. },
  1085. verification:function(){
  1086. if(vm.orderProcessRecord.isCustomsSend != 1){
  1087. alert("请等待清关完成");
  1088. return ;
  1089. }
  1090. confirm('确认核销吗?', function () {
  1091. $.ajax({
  1092. type: "POST",
  1093. url: "../order/printMsgAndChangeCode",
  1094. contentType: "application/json",
  1095. data: JSON.stringify({'id':vm.currentOrderNo,'sessionId':vm.sessionId}),
  1096. success: function (r) {
  1097. if (r.ticket != null) {
  1098. // printArea(r.ticket);
  1099. console.log("核销打印前,订单号: " + vm.currentOrderNo);
  1100. var content = getPrintContentOrder(r.ticket, printArea);
  1101. console.log("核销打印后,小票码: " + vm.pickUpCode + ",订单号: " + r.ticket.ticketHead.orderId);
  1102. }else{
  1103. alert("打印小票失败");
  1104. }
  1105. }
  1106. });
  1107. })
  1108. },
  1109. verEwbtion:function(){
  1110. confirm('确认打印快递单吗?', function () {
  1111. $.ajax({
  1112. type: "POST",
  1113. url: "../order/printMsgChangeEwb",
  1114. contentType: "application/json",
  1115. data: JSON.stringify({'id':vm.currentOrderNo,'sessionId':vm.sessionId}),
  1116. success: function (r) {
  1117. if (r.ticket != null) {
  1118. var content = getPrintContentOrder(r.ticket, printArea);
  1119. }else{
  1120. alert("打印快递单失败");
  1121. }
  1122. }
  1123. });
  1124. })
  1125. },
  1126. // 退款方法
  1127. refundOrder:function(){
  1128. vm.debounceRefund();
  1129. },
  1130. //确认提货
  1131. confirmDelivery: function(){
  1132. confirm('确认提货吗?', function () {
  1133. $.get("../pickupcode/confirmDelivery/"+vm.orderEntity.orderSn, function (r) {
  1134. alert(r.msg);
  1135. });
  1136. })
  1137. },
  1138. retrySendOrder:function(){
  1139. },
  1140. getInfo: function (id) {
  1141. $.get("../sys/notice/info/" + id, function (r) {
  1142. vm.sysNotice = r.sysNotice;
  1143. });
  1144. },
  1145. reload: function (event) {
  1146. vm.showList = false;
  1147. vm.showViewList = true;
  1148. vm.showSaveSupplierGoods = true;
  1149. var page = $("#jqGrid").jqGrid('getGridParam', 'page');
  1150. $("#jqGrid").jqGrid('setGridParam', {
  1151. postData: {
  1152. storeId: vm.q.storeId,
  1153. goodsName: vm.q.goodsName,
  1154. goodsSn: vm.q.goodsSn,
  1155. productSn: vm.q.productSn, category: vm.q.category, categoryTwo: vm.q.categoryTwo, goodsBizType:vm.q.goodsBizType,
  1156. thirdPartyMerchCode: vm.q.thirdPartyMerchCode
  1157. },
  1158. page: page
  1159. }).trigger("reloadGrid");
  1160. vm.handleReset('formValidate');
  1161. },
  1162. handleSubmit: function (name) {
  1163. handleSubmitValidate(this, name, function () {
  1164. vm.saveOrUpdate()
  1165. });
  1166. },
  1167. handleReset: function (name) {
  1168. handleResetForm(this, name);
  1169. },
  1170. logout: function () {
  1171. confirm('注:您确定要安全退出本次登录吗?', function () {
  1172. dialogLoading(true);
  1173. setTimeout(function () {
  1174. toUrl('../logout?_' + $.now());
  1175. }, 500);
  1176. });
  1177. }
  1178. }
  1179. });
  1180. function getPrintContent(ticket) {
  1181. var content = "<div style=\"width: 300px;font-family: 微软雅黑;font-size: 15px;\">";
  1182. // // 打印ogo
  1183. // content += "<div style=\"text-align: center;width: 100%;height: 50px;\">";
  1184. // // content += "<img src='./../../statics/img/cw_logo.png' />";
  1185. // // content += "2222222222";
  1186. // content += "<img src='/statics/img/cw_logo.png' style='width: 100%;height: 100%;' />";
  1187. // content += "</div>";
  1188. //小票头
  1189. content += "<div style=\"text-align: center;width: 100%;font-weight:bold;font-size: 15px;\">";
  1190. content += ticket.shopName
  1191. content += "</div>";
  1192. content += "<div style=\"width: 100%;overflow:hidden;white-space: nowrap;\">--------------------------------------------------</div>";
  1193. content += "<div style=\"width: 100%;margin:5px 0px;\">";
  1194. /*content += "收银机号:" + ticket.salesNo;
  1195. content += "</div>";
  1196. content += "<div style=\"width: 100%;\">";*/
  1197. content += "收银员:" + ticket.userName;
  1198. content += "</div>";
  1199. content += "<div style=\"text-align: center;width: 100%;font-size: 30px;margin:15px 0 10px 5px;\">";
  1200. content += "小票码" ;
  1201. content += "</div>";
  1202. content += "<div style=\"text-align: center;width: 100%;font-size: 50px;margin:15px 0 10px 5px;\">";
  1203. content += ticket.code;
  1204. content += "</div>";
  1205. content += "<div style=\"width: 100%;margin:5px 0px;\">";
  1206. content += "订单编号:" + ticket.orderNo;
  1207. content += "</div>";
  1208. content += "<div style=\"width: 100%;margin:5px 0px;\">";
  1209. content += "手机号:" + ticket.phone;
  1210. content += "</div>";
  1211. content += "<div style=\"width: 100%;margin:5px 0px;\">";
  1212. content += "打印日期:" + ticket.time;
  1213. content += "</div>";
  1214. content += "<div style=\"width: 100%;margin:5px 0px;font-size: 13px;\">";
  1215. content += "该取货单号只有当天有效!"
  1216. content += "</div>";
  1217. content += "<div style=\"width: 100%;margin:5px 0px;font-size: 13px;\">";
  1218. content += "请妥善保管好小票,以免造成个人信息泄露!"
  1219. content += "</div>";
  1220. content += "</div>";
  1221. return content;
  1222. }
  1223. var printAreaCount = 0;
  1224. var printArea = function printArea(content) {
  1225. var idPrefix = "printArea_";
  1226. removePrintArea(idPrefix + printAreaCount);
  1227. ++printAreaCount;
  1228. var iframeId = idPrefix + printAreaCount;
  1229. var iframeStyle = 'width:0px;height:0px;left:0px;top:0px;';
  1230. iframe = document.createElement('IFRAME');
  1231. $(iframe).attr({
  1232. style: iframeStyle,
  1233. id: iframeId
  1234. });
  1235. document.body.appendChild(iframe);
  1236. var doc = iframe.contentWindow.document;
  1237. // doc.open();
  1238. doc.write('<div class="">' + content
  1239. + '</div>');
  1240. doc.close();
  1241. var frameWindow = iframe.contentWindow;
  1242. $(iframe).load(function(){
  1243. frameWindow.focus();
  1244. frameWindow.print();
  1245. alert('打印小票完成');
  1246. });
  1247. }
  1248. function printArea2(content) {
  1249. var idPrefix = "printArea_";
  1250. removePrintArea(idPrefix + printAreaCount);
  1251. printAreaCount++;
  1252. var iframeId = idPrefix + printAreaCount;
  1253. var iframeStyle = 'width:0px;height:0px;left:0px;top:0px;';
  1254. iframe = document.createElement('IFRAME');
  1255. $(iframe).attr({
  1256. style: iframeStyle,
  1257. id: iframeId
  1258. });
  1259. document.body.appendChild(iframe);
  1260. var doc = iframe.contentWindow.document;
  1261. doc.open();
  1262. doc.write('<div class="">' + content
  1263. + '</div>');
  1264. doc.close();
  1265. var frameWindow = iframe.contentWindow;
  1266. frameWindow.focus();
  1267. frameWindow.print();
  1268. frameWindow.print();
  1269. frameWindow.close();
  1270. }
  1271. var removePrintArea = function (id) {
  1272. $("iframe#" + id).remove();
  1273. };
  1274. var webSocket;
  1275. function openWebSocket() {
  1276. var storeId = sessionStorage.getItem("storeId");
  1277. if ("WebSocket" in window) {
  1278. console.log("当前浏览器支持WebSocket");
  1279. //实现化WebSocket对象
  1280. //指定要连接的服务器地址与端口建立连接
  1281. //注意ws、wss使用不同的端口。我使用自签名的证书测试,
  1282. //无法使用wss,浏览器打开WebSocket时报错
  1283. //ws对应http、wss对应https。
  1284. //kmall测试环境
  1285. //webSocket = new WebSocket("ws://183.62.225.124:8080/ws/server/"+storeId);
  1286. //kmall正式环境
  1287. //webSocket = new WebSocket("ws://8.135.102.238:8080/ws/server/"+storeId);
  1288. //kmall本地环境
  1289. webSocket = new WebSocket("ws://127.0.0.1:8089/ws/server/"+storeId);
  1290. // webSocket = new WebSocket("wss://cb.k1net.cn/ws/server/"+storeId);
  1291. if (webSocket.readyState === webSocket.CONNECTING) {
  1292. console.log('1.连接正在打开......');
  1293. }
  1294. // ---------- WebSocket 对象注册事件 ----------
  1295. //连接打开事件
  1296. webSocket.onopen = function () {
  1297. if (webSocket.readyState === webSocket.OPEN) {
  1298. console.log('2.连接已打开');
  1299. }
  1300. console.log('2.向服务端发送测试消息......');
  1301. // webSocket.send("2.client发测试消息:Client sent test msg。");
  1302. };
  1303. //收到消息事件
  1304. webSocket.onmessage = function (msg) {
  1305. var data = Object.assign({}, JSON.parse(msg.data));
  1306. console.log('3.接收到服务端信息......data:'+data);
  1307. vm.sessionId = data.sessionId;
  1308. vm.pickUpCodeList = [];
  1309. if(data.pickUpCodeList.length > 0){
  1310. for(var i = 0 ; i < data.pickUpCodeList.length ; i++){
  1311. // console.log(data.pickUpCodeList[i].storeId);
  1312. if(data.pickUpCodeList[i].storeId === storeId){
  1313. vm.pickUpCodeList.push(data.pickUpCodeList[i]);
  1314. }
  1315. }
  1316. }
  1317. vm.delayResponse = data.delayResponse;
  1318. };
  1319. //连接关闭事件
  1320. webSocket.onclose = function () {
  1321. if (!webSocket) {
  1322. console.log('4.Socket连接已关闭');
  1323. }
  1324. };
  1325. //发生了错误事件
  1326. webSocket.onerror = function () {
  1327. console.log("5.Socket发生了错误");
  1328. }
  1329. } else {
  1330. console.log("当前浏览器不支持WebSocket");
  1331. return false;
  1332. }
  1333. }
  1334. function sendMessage() {
  1335. if(webSocket && webSocket.readyState === webSocket.OPEN) {
  1336. webSocket.send("client manual send message.")
  1337. } else {
  1338. console.log('6.未创建WebSocket连接');
  1339. }
  1340. }
  1341. function closeWebSocket() {
  1342. if (webSocket != null) {
  1343. webSocket.close();
  1344. webSocket = null;
  1345. }
  1346. console.log("关闭WebSocket");
  1347. }
  1348. //窗口关闭时,关闭连接
  1349. window.unload = function () {
  1350. webSocket.close();
  1351. };
  1352. function parsedate(value){
  1353. var date = new Date(value);
  1354. var year = date.getFullYear();
  1355. var month = date.getMonth()+1; //月份+1
  1356. var day = date.getDate();
  1357. var hour = date.getHours();
  1358. var minutes = date.getMinutes();
  1359. var second = date.getSeconds();
  1360. return year+"-"+month+"-"+day+" "+hour+":"+minutes +":"+second;
  1361. }
  1362. function getPrintContentOrder(ticket, callback) {
  1363. var content = "<div style=\"width: 270px;font-family: 微软雅黑;font-size: 8px;\">";
  1364. // 打印ogo
  1365. content += "<div style=\"text-align: center;width: 100%;height: 260px;\">";
  1366. content += "<img src='/statics/img/cw_logo2.png' style='width: 100%;height: 100%;' />";
  1367. content += "</div>";
  1368. //小票头
  1369. content += "<div style=\"text-align: center;width: 100%;font-weight:bold;font-size: 13px;\">";
  1370. content += ticket.ticketHead.title;
  1371. content += "</div>";
  1372. /*content += "<div style=\"width: 100%;\">";
  1373. content += "会员:" + ticket.ticketHead.memberId;
  1374. content += "</div>";*/
  1375. content += "<div style=\"width: 100%;font-size: 25px;\">";
  1376. content += "小票码:" + vm.pickUpCode;
  1377. content += "</div>";
  1378. content += "<div style=\"width: 100%;\">";
  1379. content += "订单号:" + ticket.ticketHead.orderId;
  1380. content += "</div>";
  1381. content += "<div style=\"width: 100%;\">";
  1382. content += "交易时间:" + ticket.ticketHead.tradeTime;
  1383. content += "</div>";
  1384. content += "<div style=\"width: 100%;overflow:hidden;white-space: nowrap;\">-------------------------------------------------------</div>";
  1385. //商品信息
  1386. content += "<table style=\"width: 100%;\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
  1387. content += "<tr>";
  1388. content += "<td style=\"width: 40%;text-align: left;font-size: 10px;font-weight: bold;\">商品名称</td>";
  1389. content += "<td style=\"width: 17%;text-align: right;font-size: 10px;font-weight: bold;\">单价</td>";
  1390. content += "<td style=\"width: 17%;text-align: right;font-size: 10px;font-weight: bold;\">优惠</td>";
  1391. // content += "<td style=\"width: 16%;text-align: right;font-size: 10px;font-weight: bold;\">税费</td>";
  1392. content += "<td style=\"width: 15%;text-align: right;font-size: 10px;font-weight: bold;\">数量</td>";
  1393. content += "<td style=\"width: 18%;text-align: right;font-size: 10px;font-weight: bold;\">小计</td>";
  1394. content += "</tr>";
  1395. content += "</table>";
  1396. content += "<div style=\"width: 100%;overflow:hidden;white-space: nowrap;\">-------------------------------------------------------</div>";
  1397. content += "<table style=\"width: 100%;\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
  1398. for (var i=0;i< ticket.goods.length;i++){
  1399. content += "<tr>";
  1400. content += "<td style=\"width: 40%;text-align: left;font-size: 8px;padding-top: 8px;\">";
  1401. content += "<table style=\"width: 100%;\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
  1402. content += "<tr>";
  1403. content += "<td style=\"text-align: left;font-size: 8px;vertical-align:top;\">#</td>";
  1404. content += "<td style=\"text-align: left;font-size: 8px;\">" + ticket.goods[i].gname + "</td>";
  1405. content += "</tr>";
  1406. content += "</table>";
  1407. content += "</td>";
  1408. content += "<td style=\"width: 17%;text-align: right;font-size: 8px;vertical-align:bottom;padding-top: 8px;\">" + ticket.goods[i].uprice + "</td>";
  1409. content += "<td style=\"width: 17%;text-align: right;font-size: 8px;vertical-align:bottom;padding-top: 8px;\">" + ticket.goods[i].discountPrice + "</td>";
  1410. // content += "<td style=\"width: 17%;text-align: right;font-size: 8px;vertical-align:bottom;padding-top: 8px;\">" + ticket.goods[i].taxation + "</td>";
  1411. content += "<td style=\"width: 15%;text-align: center;font-size: 8px;vertical-align:bottom;padding-top: 8px;\">" + ticket.goods[i].num + "</td>";
  1412. content += "<td style=\"width: 18%;text-align: right;font-size: 8px;vertical-align:bottom;padding-top: 8px;\">" + ticket.goods[i].subtotal + "</td>";
  1413. content += "</tr>";
  1414. }
  1415. content += "</table>";
  1416. content += "<div style=\"width: 100%;overflow:hidden;white-space: nowrap;\">--------------------------------------------------</div>";
  1417. //收银信息
  1418. content += "<div style=\"width: 100%;\">";
  1419. content += "<span style=\"float: left;width: 50%;text-align: left;\">商品合计:</span>";
  1420. content += "<span style=\"float: left;width: 17%;text-align: left;\">" + ticket.cashInfo.goodsTotal + "件</span>";
  1421. content += "<span style=\"float: right;width: 33%;text-align: right;\">" + ticket.cashInfo.total + "元</span>";
  1422. content += "</div>";
  1423. content += "<div style=\"width: 100%;\">";
  1424. content += "<span style=\"float: left;width: 50%;text-align: left;\">税费合计:</span>";
  1425. content += "<span style=\"float: left;width: 17%;text-align: left;\">" + ticket.cashInfo.goodsTotal + "件</span>";
  1426. content += "<span style=\"float: right;width: 33%;text-align: right;\">" + ticket.cashInfo.taxTotal + "元</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.oddChange + "元</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.receipts + "元</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.coupon + "元</span>";
  1439. content += "</div>";
  1440. // content += "<div style=\"width: 100%;\">";
  1441. // content += "<span style=\"float: left;width: 50%;text-align: left;\">运费:</span>";
  1442. // content += "<span style=\"float: right;width: 50%;text-align: right;\">" + ticket.cashInfo.freight + "元</span>";
  1443. // content += "</div>";
  1444. content += "<div style=\"width: 100%;\">";
  1445. content += "<span style=\"float: left;width: 50%;text-align: left;\">支付渠道:</span>";
  1446. // 后期改成从系统中取
  1447. content += "<span style=\"float: right;width: 50%;text-align: right;\">" + ticket.cashInfo.paymentMode + "</span>";
  1448. content += "</div>";
  1449. content += "<div style=\"width: 100%;overflow:hidden;white-space: nowrap;\">--------------------------------------------------</div>";
  1450. //海关清单信息
  1451. // content += "<div style=\"width: 100%;\">";
  1452. // content += "订单号:" + ticket.cusListing.orderId;
  1453. // content += "</div>";
  1454. // content += "<div style=\"width: 100%;\">";
  1455. // content += "运单编号:" + ticket.cusListing.waybillId;
  1456. // content += "</div>";
  1457. content += "<div style=\"width: 100%;\">";
  1458. content += "海关清单号:" + ticket.cusListing.invtNo;
  1459. content += "</div>";
  1460. // content += "<div style=\"width: 100%;\">";
  1461. // content += "收货人:" + ticket.cusListing.consignee;
  1462. // content += "</div>";
  1463. // content += "<div style=\"width: 100%;\">";
  1464. // content += "收货人电话:" + ticket.cusListing.consigneeTel;
  1465. // content += "</div>";
  1466. // content += "<div style=\"width: 100%;\">";
  1467. // content += "始发地: 仓库地址 : 广东省深圳市南山区前海保税港区W104" ;
  1468. // content += "</div>";
  1469. // content += "<div style=\"width: 100%;\">";
  1470. // content += "交货地:" + ticket.cusListing.deliveryAddress;
  1471. // content += "</div>";
  1472. content += "<div style=\"width: 100%;overflow:hidden;white-space: nowrap;\">--------------------------------------------------</div>";
  1473. content += "<div style=\"width: 100%;text-align: center;\">";
  1474. content += "购买跨境商品须知:"
  1475. content += "</div>";
  1476. content += "<div style=\"width: 100%;\">";
  1477. content += "1、凡购买跨境商品均不提供发票;<br> 2、单笔限购5000元,年交易限额2.6万元; <br> 3、所有订单经海关放行后方可提货; <br> 4、凭小票领取您的订单商品; <br> 5、非产品质量问题,跨境商品不支持无理由退换货,请及时检查。 "
  1478. content += "</div>";
  1479. content += "<div style=\"width: 100%;overflow:hidden;white-space: nowrap;\">--------------------------------------------------</div>";
  1480. content += "<div style=\"width: 100%;\">";
  1481. // content += ticket.ticketFoot.summary;
  1482. content += "</div>";
  1483. content += "<div style=\"width: 100%;\">";
  1484. // content += "客服电话:" + ticket.ticketFoot.serviceTel;
  1485. content += "</div>";
  1486. content += "<div style=\"width: 100%;\">";
  1487. // content += "网址:" + ticket.ticketFoot.url1;
  1488. content += "</div>";
  1489. content += "<div style=\"width: 100%;\">";
  1490. content += "欢迎再次惠顾 --服务电话:" + ticket.ticketMailInfo.shopTel;
  1491. content += "</div>";
  1492. if(ticket.cusListing.deliveryAddress.indexOf("港惠") != -1){
  1493. content += "<div style=\"width: 100%;\">";
  1494. content += "惠州市惠城区港惠购物中心负一层";
  1495. content += "</div>";
  1496. }else if(ticket.cusListing.deliveryAddress.indexOf("永旺") != -1){
  1497. content += "<div style=\"width: 100%;\">";
  1498. content += "惠州市惠城区东湖西路东湖8区裙楼永旺惠州购物中心二楼CW大药房";
  1499. content += "</div>";
  1500. }else{
  1501. content += "<div style=\"width: 100%;\">";
  1502. content += "惠州市惠城区港惠购物中心负一层";
  1503. content += "</div>";
  1504. }
  1505. content += "<div style=\"width: 100%;\">";
  1506. content += "请保管好收银小票。";
  1507. content += "</div>";
  1508. // 打印二维码
  1509. content += "<div style=\"text-align: center;width: 100%;height: 250px;\">";
  1510. content += `<img src='${ticket.ticketMailInfo.storeImgUrl}' style='width: 100%;height: 100%;' />`;
  1511. content += "</div>";
  1512. content += "<div style=\"width: 100%;text-align: center;\">";
  1513. content += "关注CW大药房客服号,获取更多优惠信息"
  1514. content += "</div>";
  1515. content += "<div style=\"width: 100%;overflow:hidden;white-space: nowrap;\">--------------------------------------------------</div>";
  1516. content += "<div style=\"width: 100%;height: 50px;\"></div>";
  1517. // var strategies = {
  1518. // "best": function(data){
  1519. // return render_of_best(data);
  1520. // },
  1521. // "yto": function(data){
  1522. // return render_of_yto(data);
  1523. // }
  1524. // };
  1525. //
  1526. // var renderMailInfo = function(exprCode, data){
  1527. // return strategies[exprCode](data);
  1528. // };
  1529. //
  1530. // renderMailInfo('best', ticket);
  1531. // 面单打印
  1532. content += `
  1533. <div style="width: 100%; height: 82px; border: 1px solid black;">
  1534. <div style="width: 100%;height: 78px; overflow: hidden">
  1535. <img src='${ticket.ticketMailInfo.exprLogoUrl}' style='max-width:180px;' />
  1536. </div>
  1537. </div>
  1538. <!-- 面单条码 -->
  1539. <div style="width: 100%;height: 98px; border-width: 0 1px 1px 1px; border-style: solid; border-color: black;">
  1540. <div style="width: 200px; height: 88px;">
  1541. <img src='data:image/png;base64,${ticket.ticketMailInfo.exprNoBase64Img}' style='max-width:199px;' />
  1542. </div>
  1543. </div>
  1544. <div style="width: 100%; border-width: 0 1px 1px 1px; border-style: solid; border-color: black;">
  1545. <div style="padding: 5px 10px 5px 10px">
  1546. <div style="width: 65px; display: inline; font-weight: bolder;">
  1547. 收件人
  1548. </div>
  1549. <div style="width: 100px; display: inline;">
  1550. <span style="font-weight: bold">${ticket.cusListing.consignee}</span> <span style="font-weight: bold">${ticket.cusListing.consigneeTel}</span>
  1551. </div>
  1552. <div style="width: 100%">
  1553. ${ticket.ticketMailInfo.consigneeProvince} ${ticket.ticketMailInfo.consigneeCity} ${ticket.ticketMailInfo.consigneeDistrict} ${ticket.ticketMailInfo.consigneeAddress}
  1554. </div>
  1555. </div>
  1556. </div>
  1557. <div style="width: 100%; border-width: 0 1px 1px 1px; border-style: solid; border-color: black;">
  1558. <div style="padding: 5px 10px 5px 10px">
  1559. <div style="width: 65px; display: inline; font-weight: bolder">
  1560. 发件人
  1561. </div>
  1562. <div style="width: 100px; display: inline;">
  1563. <span style="font-weight: bold">${ticket.ticketMailInfo.shopTel}</span> <span style="font-weight: bold">CW澳洲大药房</span>
  1564. </div>
  1565. <div style="width: 100%">
  1566. 仓库地址:${ticket.ticketMailInfo.senderProvince} ${ticket.ticketMailInfo.senderCity} ${ticket.ticketMailInfo.senderDistrict} ${ticket.ticketMailInfo.senderAddress}
  1567. </div>
  1568. </div>
  1569. </div>
  1570. `;
  1571. let box = "<div style='width: 100%; position: relative;'>";
  1572. for (let i = 0;i < ticket.goods.length; i++){
  1573. let topBorder = 0, bottomBorder = 0;
  1574. // if (i === 0) {
  1575. // topBorder = "1px";
  1576. // }
  1577. if (i === ticket.goods.length - 1) {
  1578. bottomBorder = "1px";
  1579. }
  1580. let paddingBottom = "5px";
  1581. if (i === ticket.goods.length - 1) {
  1582. paddingBottom = "35px";
  1583. }
  1584. box += `
  1585. <div
  1586. style="width: 100%; border-width: ${topBorder} 1px ${bottomBorder} 1px; border-style: solid; border-color: black; font-weight: bold;">
  1587. <div style="text-align: left;width: 70%; line-height: 1.5; padding: 5px 10px ${paddingBottom} 10px ">
  1588. ${ticket.goods[i].gname} *${ticket.goods[i].num}
  1589. </div>
  1590. </div>`;
  1591. }
  1592. let markBox = `<div style="position: absolute; bottom: 5px; right: 5px; font-weight: bold; font-size: 10pt; color: #9b9b9b">已验视</div>`;
  1593. box += markBox;
  1594. box += "</div>";
  1595. content += box;
  1596. if (typeof callback === "function") {
  1597. callback(content);
  1598. }
  1599. return content;
  1600. }
  1601. function queryAssistantInfo(){
  1602. $.get("../sys/user/info", function (r) {
  1603. if(r.code == 0){
  1604. vm.sysUserInfo = r.user;
  1605. $.get("../store/getStoresByMerch?merchSn="+r.user.merchSn+"&_=1590374349985",function(result){
  1606. if(result.code == 0){
  1607. for(var i = 0 ;i < result.list.length; i++){
  1608. if(result.list[i].id == r.user.storeId){
  1609. vm.storeName = result.list[i].storeName;
  1610. break;
  1611. }
  1612. }
  1613. }
  1614. });
  1615. }
  1616. });
  1617. }
  1618. function removeByValue(arr, val) {
  1619. var index = arr.indexOf(val);
  1620. if (index > -1) {
  1621. arr.splice(index, 1);
  1622. }
  1623. }
  1624. function handle(goodsDetails,operatorType){
  1625. vm.goodsDetail = true;
  1626. // goodsDetails.sellVolume = 1;
  1627. console.log("goodsDetails=====>" + JSON.stringify(goodsDetails));
  1628. goodsDetails.id = vm.index;
  1629. console.log("vm.index====>" + vm.index);
  1630. if(!vm.goodsList[vm.index]){
  1631. vm.index = vm.max;
  1632. }
  1633. console.log("vm.goodsList[vm.index]=====>" + vm.goodsList[vm.index]);
  1634. vm.max++;
  1635. goodsDetails.goodsDesc = "";
  1636. // 判断当前商品是否是赠品
  1637. /*var freeMap = vm.freeBardcode.get(goodsDetails.prodBarcode);
  1638. if(freeMap && "minus" != operatorType){
  1639. goodsDetails.actualPaymentAmount = 0;
  1640. goodsDetails.discountedPrice = goodsDetails.retailPrice;
  1641. vm.freeBardcode.set(goodsDetails.prodBarcode,freeMap - 1);
  1642. }else{
  1643. if(!freeMap && freeMap != 0 ){
  1644. // 判断购物车中是否有赠品 这个操作只有是非赠品才能进来
  1645. for(var i = 0 ; i < vm.goodsList.length ; i++){
  1646. var shopcartGoods = vm.goodsList[i];
  1647. var shopcartFree = vm.freeBardcode.get(shopcartGoods.prodBarcode);
  1648. if(shopcartFree /!*&& shopcartGoods.actualPaymentAmount*!/){
  1649. // if("minus" != operatorType){
  1650. var shopcartSellNum = shopcartGoods.sellVolume;
  1651. if(shopcartFree > shopcartSellNum){
  1652. shopcartGoods.actualPaymentAmount = 0;
  1653. shopcartGoods.discountedPrice = shopcartGoods.retailPrice * shopcartFree;
  1654. vm.discountedPrice = vm.discountedPrice + shopcartGoods.discountedPrice ;
  1655. vm.actualPrice = vm.actualPrice + shopcartGoods.actualPaymentAmount ;
  1656. vm.freeBardcode.set(shopcartGoods.prodBarcode,shopcartFree - 1);//
  1657. }else if(shopcartFree == -1 ){
  1658. // g.actualPaymentAmount == 0){
  1659. shopcartGoods.actualPaymentAmount = shopcartGoods.retailPrice + shopcartGoods.actualPaymentAmount;
  1660. shopcartGoods.discountedPrice = shopcartGoods.discountedPrice - shopcartGoods.retailPrice;
  1661. vm.discountedPrice = vm.discountedPrice + shopcartGoods.discountedPrice ;
  1662. vm.actualPrice = vm.actualPrice + shopcartGoods.actualPaymentAmount ;
  1663. vm.freeBardcode.set(shopcartGoods.prodBarcode,0);// 重置回0
  1664. }else{
  1665. if(shopcartGoods.actualPaymentAmount > 0){
  1666. shopcartGoods.actualPaymentAmount = shopcartGoods.actualPaymentAmount - (shopcartGoods.retailPrice * shopcartFree);
  1667. shopcartGoods.discountedPrice = shopcartGoods.discountedPrice + (shopcartGoods.retailPrice * shopcartFree);
  1668. vm.actualPrice = vm.actualPrice - (shopcartGoods.retailPrice * shopcartFree) ;
  1669. vm.discountedPrice = vm.discountedPrice + (shopcartGoods.retailPrice * shopcartFree) ;
  1670. vm.freeBardcode.set(shopcartGoods.prodBarcode, shopcartFree - 1);// 重置回0
  1671. }
  1672. }
  1673. // }
  1674. }
  1675. }
  1676. }
  1677. }*/
  1678. goodsDetails.discountedPrice = Math.round(goodsDetails.discountedPrice * 100) / 100;
  1679. goodsDetails.actualPaymentAmount = Math.round(goodsDetails.actualPaymentAmount * 100) / 100;
  1680. var data = Object.assign({}, JSON.parse(JSON.stringify(goodsDetails)));
  1681. var isPush = true;
  1682. // 判断当前商品是否添加过
  1683. for(var i = 0 ; i < vm.goodsList.length ; i++){
  1684. if(vm.goodsList[i].goodsSn == data.goodsSn){
  1685. var goodsDetails = vm.goodsList[i];
  1686. if(data.actualPaymentAmount < 0 && goodsDetails.actualPaymentAmount == 0){
  1687. // goodsDetails.goodstaxes = Math.round((parseFloat(goodsDetails.goodstaxes) - parseFloat(data.goodstaxes)) * 100)/100;
  1688. // goodsDetails.discountedPrice = Math.round((parseFloat(goodsDetails.discountedPrice) - parseFloat(data.discountedPrice)) * 100)/100;
  1689. goodsDetails.actualPaymentAmount = 0;
  1690. }else{
  1691. // 税 goodstaxes,优惠金额 discountedPrice,实际支付 actualPaymentAmount,数量 sellVolume 45636917
  1692. goodsDetails.actualPaymentAmount = Math.round((parseFloat(goodsDetails.actualPaymentAmount) + parseFloat(data.actualPaymentAmount)) * 100)/100;
  1693. }
  1694. goodsDetails.discountedPrice = Math.round((parseFloat(goodsDetails.discountedPrice) + parseFloat(data.discountedPrice)) * 100)/100;
  1695. goodsDetails.goodstaxes = Math.round((parseFloat(goodsDetails.goodstaxes) + parseFloat(data.goodstaxes)) * 100)/100;
  1696. goodsDetails.sellVolume = Math.round((parseFloat(goodsDetails.sellVolume) + parseFloat(data.sellVolume)) * 100)/100;
  1697. goodsDetails.activity = data.activity;
  1698. isPush = false;
  1699. break;
  1700. }
  1701. }
  1702. // for(var i = 0 ; i < vm.goodsList.length ; i++){
  1703. // if(vm.goodsList[i].goodsSn == data.goodsSn){
  1704. // var goodsDetails = vm.goodsList[i];
  1705. // // 税 goodstaxes,优惠金额 discountedPrice,实际支付 actualPaymentAmount,数量 sellVolume 45636917
  1706. // goodsDetails.goodstaxes = Math.round((parseFloat(goodsDetails.goodstaxes) + parseFloat(data.goodstaxes)) * 100)/100;
  1707. // goodsDetails.discountedPrice = Math.round((parseFloat(goodsDetails.discountedPrice) + parseFloat(data.discountedPrice)) * 100)/100;
  1708. // goodsDetails.actualPaymentAmount = Math.round((parseFloat(goodsDetails.actualPaymentAmount) + parseFloat(data.actualPaymentAmount)) * 100)/100;
  1709. // goodsDetails.sellVolume = Math.round((parseFloat(goodsDetails.sellVolume) + parseFloat(data.sellVolume)) * 100)/100;
  1710. // goodsDetails.activity = data.activity;
  1711. // isPush = false;
  1712. // break;
  1713. // }
  1714. // }
  1715. if(isPush){
  1716. vm.goodsList.push(data);
  1717. vm.index = vm.index + 1;
  1718. }
  1719. vm.totalPrice = (vm.totalPrice + data.retailPrice);
  1720. if("minus" == operatorType){
  1721. vm.totalCount = vm.totalCount - 1;
  1722. }else{
  1723. vm.totalCount = vm.totalCount + 1;
  1724. }
  1725. if(vm.reduceMoney > 0){
  1726. vm.discountedPrice = vm.discountedPrice + data.discountedPrice + vm.reduceMoney;
  1727. vm.actualPrice = vm.actualPrice + data.actualPaymentAmount - vm.reduceMoney;
  1728. vm.showReduceMoney = vm.showReduceMoney + vm.reduceMoney;
  1729. vm.reduceMoney = 0;
  1730. }else{
  1731. vm.discountedPrice = vm.discountedPrice + data.discountedPrice ;
  1732. vm.actualPrice = vm.actualPrice + data.actualPaymentAmount ;
  1733. }
  1734. if(data.sellVolume < 0){
  1735. data.sellVolume = - data.sellVolume;
  1736. data.retailPrice = - data.retailPrice;
  1737. data.goodstaxes = -data.goodstaxes;
  1738. }
  1739. vm.goods = data;
  1740. // 处理精度
  1741. vm.totalPrice = Math.round(vm.totalPrice * 100) / 100;
  1742. vm.discountedPrice = Math.round(vm.discountedPrice * 100) / 100;
  1743. vm.actualPrice = Math.round(vm.actualPrice * 100) / 100;
  1744. vm.showReduceMoney = Math.round(vm.showReduceMoney * 100) / 100;
  1745. console.log("goodsDetails after=====>" + JSON.stringify(vm.goodsList));
  1746. }
  1747. // 下单处理
  1748. function toPayOrder(payCode){
  1749. $('#payCode').unbind('keydown').keydown(function(event){});
  1750. vm.machineCode = sessionStorage.getItem("machineCode");
  1751. var status = $('input:radio:checked').val();
  1752. var cmbCity = $('#cmbCity').val();
  1753. var cmbProvince = $('#cmbProvince').val();
  1754. var cmbArea = $('#cmbArea').val();
  1755. var addrUser = $('#addrUser').val();
  1756. addrUser = cmbProvince+cmbCity+cmbArea+addrUser;
  1757. // console.log('单选按钮值:'+status);
  1758. // console.log('城市三级联动的值:'+cmbProvince+'|'+cmbCity+'|'+cmbArea+'|'+addrUser);
  1759. console.log(vm.machineCode);
  1760. var param = {'userInfo':vm.userInfo,
  1761. 'payCode':vm.parCode,
  1762. 'goodsList':vm.goodsList,
  1763. 'sessionId':vm.sessionId,
  1764. 'machineCode':vm.machineCode,
  1765. 'cmbProvince':cmbProvince,
  1766. 'cmbCity':cmbCity,
  1767. 'cmbArea':cmbArea,
  1768. 'addrUser':addrUser,
  1769. 'status':status,
  1770. };
  1771. console.log(JSON.stringify(param));
  1772. vm.parCode = "";
  1773. $.ajax({
  1774. type: "POST",
  1775. url: "../order/orderConfirm",
  1776. contentType: "application/json",
  1777. data: JSON.stringify(param),
  1778. success: function (r) {
  1779. console.log(r);
  1780. if (r.code == 0) {
  1781. if (r.resultObj != null) {
  1782. $(".form-group input[type=text]").each(function(){
  1783. this.value = '';
  1784. })
  1785. // 打印小票码小票
  1786. var content = getPrintContent(r.resultObj);
  1787. console.log(content);
  1788. printArea2(content);
  1789. vm.goodsList = [];
  1790. vm.customname = '' ;
  1791. vm.customidcard = '';
  1792. vm.customClearData();
  1793. }else{
  1794. // alert("打印小票失败");
  1795. }
  1796. } else {
  1797. alert(r.msg);
  1798. }
  1799. }
  1800. });
  1801. }
  1802. // 调用后端接口进行退款
  1803. function toRefund(){
  1804. confirm('确认退款吗?', function () {
  1805. vm.canRefund = false;
  1806. $.ajax({
  1807. type: "POST",
  1808. url: "../order/orderRefund",
  1809. contentType: "application/json",
  1810. data: JSON.stringify({'orderId':vm.currentOrderNo,'sessionId':vm.sessionId}),
  1811. success: function (r) {
  1812. if (r.code == 0) {
  1813. vm.canRefund = true;
  1814. alert("退款成功")
  1815. } else if (r.code == 500) {
  1816. vm.canRefund = true;
  1817. alert(r.msg)
  1818. } else {
  1819. alert("退款失败,请联系管理员");
  1820. }
  1821. }
  1822. });
  1823. })
  1824. }
  1825. /**
  1826. * 计算当前购物栏商品优惠价格
  1827. */
  1828. calculateOrderPrice = function() {
  1829. let param = {
  1830. 'storeId': sessionStorage.getItem("storeId"),
  1831. 'memberCode': vm.$refs.couponBarCode.value,
  1832. 'goodsList' : vm.goodsList
  1833. };
  1834. console.log("请求参数===>" + JSON.stringify(param));
  1835. $.ajax({
  1836. type: "POST",
  1837. url: "../order/calculateOrderDiscountPrice",
  1838. contentType: "application/json",
  1839. data: JSON.stringify(param),
  1840. success: function (r) {
  1841. if (r.code === 0) {
  1842. let calGoodsList = r.data.goodsDetailsDtos;
  1843. // 更新购物栏中数据
  1844. console.log("返回====>" + JSON.stringify(r));
  1845. console.log("计算前数据===>" + JSON.stringify(vm.goodsList));
  1846. vm.goodsList.clear();
  1847. calGoodsList.forEach(goods => vm.goodsList.push(goods));
  1848. vm.actualPrice = r.data.orderTotalPrice;
  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. }
  1860. /**
  1861. * 处理加减按钮操作
  1862. * @param currentGoodsDetail 当前操作的商品详情
  1863. * @param type 类型,add:加 minus:减
  1864. */
  1865. handleSellVolume = function (currentGoodsDetail, type) {
  1866. console.log("处理前商品详情=====>" + JSON.stringify(currentGoodsDetail));
  1867. // 当前未被处理的商品数量
  1868. let number = currentGoodsDetail.sellVolume;
  1869. // 当前商品应支付金额
  1870. let currentActualPaymentAmount = new BigNumber(currentGoodsDetail.actualPaymentAmount);
  1871. // 当前商品税款
  1872. let currentGoodsTax = new BigNumber(currentGoodsDetail.goodstaxes);
  1873. // 当前商品零售价
  1874. let retailPrice = new BigNumber(currentGoodsDetail.retailPrice);
  1875. // 单个商品时的税款
  1876. let singleTax = currentGoodsTax.divide(number);
  1877. // 单个商品时的应支付金额
  1878. let singleActualPaymentAmount = currentActualPaymentAmount.divide(number);
  1879. // 当前总价
  1880. let currentTotalPrice = new BigNumber(vm.totalPrice);
  1881. // 当前实际支付价
  1882. let currentActualPrice = new BigNumber(vm.actualPrice);
  1883. if ('add' === type) {
  1884. currentGoodsDetail.sellVolume += 1;
  1885. currentGoodsDetail.goodstaxes = currentGoodsTax.add(singleTax).toString();
  1886. currentGoodsDetail.actualPaymentAmount = currentActualPaymentAmount.add(singleActualPaymentAmount).toString();
  1887. vm.totalCount += 1;
  1888. vm.totalPrice = currentTotalPrice.add(retailPrice).toString();
  1889. vm.actualPrice = currentActualPrice.add(singleActualPaymentAmount).toString();
  1890. } else {
  1891. currentGoodsDetail.sellVolume -= 1;
  1892. currentGoodsDetail.goodstaxes = currentGoodsTax.subtract(singleTax).toString();
  1893. currentGoodsDetail.actualPaymentAmount = currentActualPaymentAmount.subtract(singleActualPaymentAmount).toString();
  1894. vm.totalCount -= 1;
  1895. vm.totalPrice = currentTotalPrice.subtract(retailPrice).toString();
  1896. vm.actualPrice = currentActualPrice.subtract(singleActualPaymentAmount).toString();
  1897. }
  1898. for (let i = 0; i < vm.goodsList.length; i++) {
  1899. let goods = vm.goodsList[i];
  1900. if (currentGoodsDetail.prodBarcode === goods.prodBarcode && currentGoodsDetail.goodsSn === goods.goodsSn) {
  1901. let splice = vm.goodsList.splice(i, 1, currentGoodsDetail);
  1902. console.log("被删除的元素====>" + JSON.stringify(splice));
  1903. }
  1904. }
  1905. console.log("处理后商品详情=====>" + JSON.stringify(currentGoodsDetail))
  1906. }