123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713 |
- $(function () {
- openWebSocket();
- queryAssistantInfo();
- var cwQrcode = new Image();
- var cwLogo2 = new Image();
- cwQrcode.src = "http://8.135.102.238:8080/statics/img/cw_qrcode.png";
- cwLogo2.src = "http://8.135.102.238:8080/statics/img/cw_logo2.png";
- vm.queryGoods();
- });
- window.onbeforeunload = function(){
- closeWebSocket();
- }
- function debounce(fn,delay){
- var timer=null
- return function(){
- console.log(timer);
- if(timer){
- clearTimeout(timer)
- }
- timer = setTimeout(fn,delay)
- }
- }
- function calculateGoodsPrice(r){
- var rMap = r.map;
- var barCode = r.goodsDetails.prodBarcode;
- var brand = r.goodsDetails.brand;
- console.log(rMap);
- if(rMap.yhq){
- for(var i in rMap.yhq){
- vm.coupons.set(i,rMap.yhq[i]);
- }
- }
- // 是否有满减活动
- if(rMap.mj){
- if(rMap.mj[barCode] && !vm.mj.get(barCode)){
- // 该商品是否已经有过满减活动
- vm.mj.set(barCode,rMap.mj[barCode]);
- }else if(rMap.mj[brand] && !vm.mj.get(brand)){
- // 该品牌是否已经有过满减活动
- vm.mj.set(brand,rMap.mj[brand]);
- }
- }
- if(rMap.mysy){
- // 买的条码, 买的数量,送的条码,送的数量
- var mysy = {
- buyNum:rMap.mysy.buyNum,
- giftBarcode:rMap.mysy.giftBarcode,
- sendNum:rMap.mysy.sendNum
- };
- if(rMap.mysy.brand){
- vm.brandGetOneFree.set(rMap.mysy.productBrand,mysy);
- }else{
- vm.barcodeGetOneFree.set(rMap.mysy.barcode , mysy);
- }
- }
- if(rMap.mz){
- if(rMap.mz[barCode] && !vm.mz.get(barCode)){
- // 该商品是否已经有过满赠活动
- vm.mz.set(barCode,rMap.mz[barCode]);
- }else if(rMap.mz[brand] && !vm.mz.get(brand)){
- // 该品牌是否已经有过满赠活动
- vm.mz.set(brand,rMap.mz[brand]);
- }
- }
- if(rMap.drjbj){
- if(!vm.halfPrice.get(rMap.drjbj.barcode)){
- vm.halfPrice.set(rMap.drjbj.barcode,1);
- }
- }
- // if(rMap.zhjsp){
- // // 遍历该商品所有可能的组合价商品类型
- // for(var data in rMap.zhjsp){
- // if(!vm.zhjsp.get(data)){
- // // 分割组合价商品的条码,并以 条码:0 放入map中
- // var barCodeArray = data.toString().split(":");
- // var dataMap = new Map();
- // console.log(rMap.zhjsp[data]);
- // // dataMap.set();
- // for(var j = 0 ; j < barCodeArray.length ; j ++){
- // dataMap.set(barCodeArray[j],0);
- // }
- // vm.combinationPrice.set(data,rMap.zhjsp[data][0].combinedPrice)
- //
- // vm.zhjsp.set(data,dataMap);
- // }
- // }
- //
- // }
- // calculateGoodsByMj(r.goodsDetails,"add");
- calculateGoodsByMysy(r.goodsDetails,"add");
- calculateGoodsByMz(r.goodsDetails,"add");
- calculateGoodsByHalfPrice(r.goodsDetails,"add");
- // calculateGoodsByZhjsp(r);
- }
- // ==================== 满减==========================
- // 满减
- function calculateGoodsByMj(goodsDetails,type){
- if(vm.mj.get(goodsDetails.prodBarcode)){
- fullReduction(goodsDetails,goodsDetails.prodBarcode);
- }else if(vm.mj.get(goodsDetails.brand)){
- fullReduction(goodsDetails,goodsDetails.brand);
- }
- }
- // 满减的计算内容
- function fullReduction(goodsDetails,key){
- // 获取满减条件金额
- var qualifiedAmount = vm.mj.get(key).qualifiedAmount;
- // 获取已累积金额
- var money = vm.accumulatedAmount.get(key);
- if(isNaN(money)){
- money = goodsDetails.retailPrice;
- }else{
- money = money + goodsDetails.retailPrice;
- }
- if(money >= qualifiedAmount){
- vm.reduceMoney += vm.mj.get(key).deductionAmount; // 达到满减金额,获取扣减的额度
- vm.mj.delete(key); // 获取后删除该商品的满减
- vm.accumulatedAmount.delete(key); // 删除满减的金额
- }else{
- vm.accumulatedAmount.set(key,money);
- }
- }
- // ============================= 第二件半价==========================
- function calculateGoodsByHalfPrice(goodsDetails,type){
- var half = vm.halfPrice.get(goodsDetails.prodBarcode);
- if(half){
- var discountPrice = goodsDetails.retailPrice / 2;
- if(type == "add"){
- // 等于一的话,不满足条件
- if(half == 1){
- vm.halfPrice.set(goodsDetails.prodBarcode,2);
- }else if(half == 2){
- goodsDetails.actualPaymentAmount = discountPrice;
- goodsDetails.discountedPrice = discountPrice;
- vm.halfPrice.set(goodsDetails.prodBarcode,1);
- }
- }else if(type == "minus"){
- if(half == 2){
- goodsDetails.actualPaymentAmount = goodsDetails.actualPaymentAmount ;
- vm.halfPrice.set(goodsDetails.prodBarcode,1);
- }else if(half == 1){
- goodsDetails.actualPaymentAmount = goodsDetails.actualPaymentAmount - discountPrice;
- goodsDetails.discountedPrice = discountPrice;
- vm.halfPrice.set(goodsDetails.prodBarcode,2);
- }
- }
- }
- }
- // ============================= 满赠 ==============================
- // 满赠
- function calculateGoodsByMz(goodsDetails,type){
- // 判断当前支付金额是否满足满赠金额,若满足,直接修改金额为1
- var mzGoods = vm.mz.get(goodsDetails.prodBarcode);
- if(mzGoods){
- var mzPrice = mzGoods.qualifiedAmount;
- if(mzPrice < vm.actualPrice && !mzGoods.useMz){
- mzGoods.useMz = true;
- goodsDetails.actualPaymentAmount = 1;
- goodsDetails.discountedPrice = goodsDetails.retailPrice - 1;
- }
- }
- // // 1.满赠的商品是不是自己,遍历满赠商品数组
- // isSend(vm.fullGiftCode,goodsDetails,"满赠");
- //
- // if(vm.mz.get(goodsDetails.prodBarcode)){
- // fullGift(goodsDetails,goodsDetails.prodBarcode);
- // }else if(vm.mz.get(goodsDetails.brand)){
- // fullGift(goodsDetails,goodsDetails.brand);
- // }
- }
- function fullGift(goodsDetails,key){
- // 获取满赠条件金额
- var qualifiedAmount = vm.mz.get(key).qualifiedAmount;
- // 获取已累积金额
- var money = vm.accumulatedAmountForFullGift.get(key);
- if(isNaN(money)){
- money = goodsDetails.retailPrice;
- }else{
- money = money + goodsDetails.retailPrice;
- }
- // 达到满赠的要求
- if(money >= qualifiedAmount){
- // 将满赠的商品放入数组中,重置金额
- vm.fullGiftCode.push(vm.mz.get(key).giftBarcode);
- vm.mz.delete(key); // 获取后删除该商品的满减
- vm.accumulatedAmountForFullGift.delete(key); // 删除满减的金额
- // 2.购物车的商品里面是否有满赠的商品
- shopCartContain(vm.fullGiftCode,goodsDetails,"满赠");
- }else{
- vm.accumulatedAmountForFullGift.set(key,money);
- }
- }
- // 买一送一
- function calculateGoodsByMysy(goodsDetails,type){
- var mysy = vm.barcodeGetOneFree.get(goodsDetails.prodBarcode);
- var brandMysy = vm.brandGetOneFree.get(goodsDetails.brand);
- if(mysy){
- var buyNum = mysy.buyNum;
- if(type == "add"){
- // 证明是买一送一,并且达到买一送一的条件
- if(buyNum == 1 && vm.boughtNum.get(goodsDetails.prodBarcode)){
- // 设置赠品的单价
- goodsDetails.discountedPrice = goodsDetails.retailPrice;
- goodsDetails.actualPaymentAmount = 0;
- // goodsDetails.activity = "买1送1";
- // 清除该商品买一送一条件
- vm.boughtNum.delete(goodsDetails.prodBarcode);
- return ;
- }
- // 如果不是买一送一,而是买n送n,先获取购物车已有该类型商品数量
- var boughtNum = vm.boughtNum.get(goodsDetails.prodBarcode);
- // 如果没有,置为1
- if(!boughtNum){
- vm.boughtNum.set(goodsDetails.prodBarcode , 1);
- return ;
- }
- // 走到这里,证明购买过该类型商品,且数量不是买一送一的
- // 如果相等,证明达到送的条件
- if(buyNum === boughtNum){
- goodsDetails.discountedPrice = goodsDetails.retailPrice;
- goodsDetails.actualPaymentAmount = 0;
- // goodsDetails.activity = "买"+buyNum+"送1";
- // 清除该商品买一送一条件
- vm.boughtNum.delete(goodsDetails.prodBarcode);
- console.log(vm.boughtNum);
- }else{
- // 如果不相等,已经购买数量+1
- vm.boughtNum.set(goodsDetails.prodBarcode , boughtNum+1);
- }
- }else if (type == "minus"){
- // 获取该产品要买n送1 的n
- // 获取已经购买的数量
- var boughtNum = goodsDetails.sellVolume;
- // 减一后,不满足买一送一条件,重新计算金额
- // 如果不等于0,要减去价格
- var remainder = 0;
- if(boughtNum > buyNum+1){
- remainder = buyNum - (boughtNum % (buyNum+1)) ;
- }else{
- remainder = buyNum - ((buyNum+1) %boughtNum ) ;
- }
- if(boughtNum % (buyNum+1) != 0){
- // console.log("我要减去价格,也要减去数量,减去数量=" + goodsDetails.sellVolume);
- goodsDetails.actualPaymentAmount = goodsDetails.retailPrice;
- goodsDetails.discountedPrice = 0;
- // 如果等于0,只用减去数量跟优惠价,并恢复活动
- }else{
- // console.log("我不用减去价格,只要减去数量");
- goodsDetails.discountedPrice = goodsDetails.retailPrice;
- goodsDetails.actualPaymentAmount = 0;
- }
- goodsDetails.sellVolume = 1;
- vm.boughtNum.set(goodsDetails.prodBarcode,remainder);
- }
- }
- if(brandMysy){
- var buyNum = brandMysy.buyNum;
- if(type == "add"){
- // 如果不是买一送一,而是买n送n,先获取购物车已有该类型商品数量
- var boughtNum = vm.boughtNum.get(goodsDetails.brand);
- // 如果没有,置为1
- if(!boughtNum){
- vm.boughtNum.set(goodsDetails.brand , 1);
- return ;
- }
- // 走到这里,证明购买过该类型商品,且数量不是买一送一的
- // 如果相等,证明达到送的条件
- if(buyNum === boughtNum + 1){
- var mysyNum = vm.freeBardcode.get(brandMysy.giftBarcode);
- if(!mysyNum){
- mysyNum = 0;
- }
- vm.freeBardcode.set(brandMysy.giftBarcode,mysyNum + 1);
- vm.boughtNum.set(goodsDetails.brand,0);
- }else{
- // 如果不相等,已经购买数量+1
- vm.boughtNum.set(goodsDetails.brand , boughtNum+1);
- }
- }else if (type == "minus"){
- var mysyNum = vm.boughtNum.get(goodsDetails.brand);
- if(mysyNum == 0){
- if(vm.freeBardcode.get(brandMysy.giftBarcode) == 0){
- vm.freeBardcode.set(brandMysy.giftBarcode,-1);
- }else{
- vm.freeBardcode.set(brandMysy.giftBarcode,vm.freeBardcode.get(brandMysy.giftBarcode) - 1);
- }
- vm.boughtNum.set(goodsDetails.brand,buyNum - 1);
- }else{
- vm.boughtNum.set(goodsDetails.brand,mysyNum - 1);
- }
- // var freeNum = vm.freeBardcode.get(brandMysy.giftBarcode);
- // if(freeNum > 0){
- // vm.freeBardcode.set(brandMysy.giftBarcode,freeNum - 1);
- //
- // }
- }
- }
- // 判断当前商品是否为赠品
- // isSend(vm.mysy,goodsDetails,"买一送一");
- // 判断购物车里面是否有商品为赠品
- // shopCartContain(vm.mysy,goodsDetails,"买一送一");
- }
- // 判断当前商品是否为赠品
- function isSend(activity,goodsDetails,activityName){
- if(activity.indexOf(goodsDetails.prodBarcode) >= 0){
- // 如果符合条件,把赠送的条码给删除(一次性)
- var index = activity.indexOf(goodsDetails.prodBarcode);
- activity.splice(index,1);
- // 设置赠品的单价
- goodsDetails.discountedPrice = goodsDetails.retailPrice - 1;
- goodsDetails.actualPaymentAmount = 1;
- }
- }
- // 判断购物车里面是否有商品为赠品
- function shopCartContain(activity,goodsDetails,activityName){
- if(vm.goodsList && vm.goodsList.length > 0 ){
- for(var i = 0 ; i < vm.goodsList.length ; i ++){
- // 如果有商品为赠品,则把价格置位0并跳出循环
- if(activity.indexOf(vm.goodsList[i].prodBarcode) >= 0 && vm.goodsList[i].actualPaymentAmount != 0){
- // 如果符合条件,把赠送的条码给删除(一次性)
- var index = vm.mysy.indexOf(goodsDetails.prodBarcode);
- activity.splice(index,1);
- vm.goodsList[i].discountedPrice = vm.goodsList[i].retailPrice;
- vm.goodsList[i].actualPaymentAmount = 0;
- vm.goodsList[i].activity = activityName;
- vm.discountedPrice = vm.discountedPrice + vm.goodsList[i].retailPrice ;
- vm.actualPrice = vm.actualPrice - vm.goodsList[i].retailPrice ;
- break;
- }
- }
- }
- }
- // ======================= 组合价商品 ============================
- // 组合价商品
- function calculateGoodsByZhjsp(r){
- var barCode = r.goodsDetails.prodBarcode;
- if(r.map.zhjsp){
- // 将有组合的商品设置为1 ps:{"flag" => 0, "4005808550739" => 1, "4305615120454" => 0}
- vm.zhjsp.forEach(function(value,key,map){
- // 将组合价中组合的产品出现的次数+1
- value.forEach(function(v, k ,m){
- if(k === barCode)
- m.set(k,v+1);
- });
- var flag = 1;
- // 判断是否有商品成功组合
- value.forEach(function(v, k ,m){
- if(v === 0)
- flag = 0;
- });
- if(flag === 1){
- var combinationPrice = vm.combinationPrice.get(key);
- var barCodeArr = key.toString().split(":");
- // 扫码的商品条码 barCode
- for(var i = 0 ; i < barCodeArr.length ; i ++){
- var oldCode = barCodeArr[i];
- if(oldCode === barCode){
- continue;
- }
- if(vm.compareCombinationPrice.get(oldCode) && vm.compareCombinationPrice.get(oldCode) > combinationPrice){
- // 获取原组合关系
- var relationshipKey = vm.combinationRelationship.get(oldCode);
- // 将价格设置回原来的价格
- var keyArr = relationshipKey.toString().split(":");
- // 遍历原来的组合
- for(var j = 0 ; j < keyArr.length ; j ++){
- // 遍历购物车中原来的商品,替换价格
- for(var k = 0 ; k < vm.goodsList.length ; k ++){
- if(vm.goodsList[k].prodBarcode === keyArr[j] && vm.goodsList[k].activity == "组合价"){
- vm.discountedPrice = vm.discountedPrice - vm.goodsList[k].discountedPrice ;
- vm.actualPrice = vm.actualPrice + vm.goodsList[k].discountedPrice ;
- vm.goodsList[k].discountedPrice = 0 ; // 优惠价格
- vm.goodsList[k].actualPaymentAmount = vm.goodsList[k].retailPrice; // 实际支付价格
- vm.goodsList[k].isCombination = 0;
- vm.goodsList[k].activity = "";
- vm.compareCombinationPrice.delete(vm.goodsList[k].prodBarcode);
- vm.combinationRelationship.delete(vm.goodsList[k].prodBarcode);
- }
- }
- }
- }
- }
- for( var i = 0 ; i < barCodeArr.length ; i ++ ){
- // 如果是扫描的产品,直接退出,因为购物车中无该产品
- if(barCodeArr[i] == barCode){
- r.goodsDetails.isCombination = 1;
- r.goodsDetails.discountedPrice = r.goodsDetails.retailPrice - combinationPrice; // 优惠价格
- r.goodsDetails.actualPaymentAmount = combinationPrice; // 实际支付价格
- r.goodsDetails.activity = "组合价";
- vm.compareCombinationPrice.set(barCode,r.goodsDetails.actualPaymentAmount);
- vm.combinationRelationship.set(barCode,key);
- continue;
- }
- for(var j = 0 ; j < vm.goodsList.length ; j ++){
- if(vm.goodsList[j].prodBarcode === barCodeArr[i] && !vm.goodsList[j].isCombination){
- vm.goodsList[j].discountedPrice = vm.goodsList[j].retailPrice ; // 优惠价格
- vm.goodsList[j].actualPaymentAmount = 0; // 实际支付价格
- vm.goodsList[j].isCombination = 1;
- vm.goodsList[j].activity = "组合价";
- vm.discountedPrice = vm.discountedPrice + vm.goodsList[j].retailPrice ; // 总的优惠金额
- vm.actualPrice = vm.actualPrice - vm.goodsList[j].retailPrice ; // 总的实际支付金额
- vm.compareCombinationPrice.set(vm.goodsList[j].prodBarcode,vm.goodsList[j].actualPaymentAmount);
- vm.combinationRelationship.set(vm.goodsList[j].prodBarcode,barCode,key);
- break;
- }
- }
- }
- // 扣减
- var updateMap = map.get(key);
- updateMap.forEach(function(v, k ,m){
- m.set(k,v-1);
- });
- }
- });
- }
- console.log(vm.compareCombinationPrice);
- }
- const delay = (function () {
- let timer = 0;
- return function (callback, ms) {
- clearTimeout(timer);
- timer = setTimeout(callback.ms)
- }
- });
- let vm = new Vue({
- el: '#rrapp',
- data: {
- showList: true,
- goodsDetail:false,
- title: null,
- goods:{},
- orderSn:"",
- orderSn1:"",
- sysNotice: {},
- goodsList:[],
- orderInfo:[],
- userInfo:{},
- //user信息绑定集合
- userInfoBinding: {},
- sysUserInfo:{},
- storeName:null,
- prodBarcode:null,
- sessionId:null,
- pickUpCodeList:[],
- goodsDetailList:[],
- orderEntity:{},
- orderProcessRecord:{},
- tax:0,
- currentOrderNo:null,
- pickUpCode:null,
- customname:'',
- customidcard:'',
- machineCode:'',
- storeId:null,
- index:0,
- max:0,
- totalPrice:0,
- discountedPrice:0,
- actualPrice:0,
- ruleValidate: {
- name: [
- {required: true, message: '名称不能为空', trigger: 'blur'}
- ]
- },
- q: {
- name: ''
- },
- firstPrint:false,
- // 第二件半价
- halfPrice:new Map(),
- // 买一送一
- mysy: [],
- freeBardcode : new Map(),
- modifyShopcart:false, // 是否需要修改购物车中商品信息
- brandGetOneFree : new Map(),
- barcodeGetOneFree: new Map(),
- boughtNum: new Map(),
- // 组合价
- zhjsp: new Map(),
- combinationPrice: new Map(), // 组合价商品的组合价
- compareCombinationPrice: new Map(), // 用于比较组合价
- combinationRelationship: new Map(), // 组合价格的组合关系
- // 满减
- mj: new Map(),
- accumulatedAmount: new Map(), // 累积金额(满减使用的)
- reduceMoney:0, // 满减金额
- showReduceMoney:0, // 用于展示的满减金额
- // 满赠
- useMz:false,
- mz: new Map(),
- accumulatedAmountForFullGift: new Map(), // 累积金额(满赠使用的)
- fullGiftCode:[],// 满赠商品条码
- // 优惠券
- coupons: new Map(),
- // 挂起订单集合
- pendingOrderMap: new Map(),
- // 挂起订单的key 在1~3循环
- pendingIndex:1,
- pendingOrderKeys:[],
- // 存储商品信息
- goodsMap:new Map(),
- response: "",
- // 支付码
- parCode : "",
- // 总件数
- totalCount:0,
- searchGoodsList: [],
- timer: null,
- searchGoods: [],
- // 卡回执标志
- delayResponse:false,
- canRefund:true
- },
- watch: {
- prodBarcode (){
- if(vm.timer){
- clearTimeout(vm.timer);
- }
- if(!vm.prodBarcode){
- this.searchGoodsList = [];
- return ;
- }
- vm.timer = null;
- vm.timer = setTimeout(() => {
- vm.queryGoods();
- }, 1000*15);
- let result = [];
- for(let i=0; i<vm.searchGoods.length; i++){
- if(vm.searchGoods[i].name.indexOf(vm.prodBarcode) > -1){
- if(result.length <= 9){
- result.push(vm.searchGoods[i]);
- }else{
- break;
- }
- }
- }
- vm.searchGoodsList = result;
- }
- },
- methods: {
- myDebounce:debounce(function(){
- toPayOrder();
- },2000),
- debounceRefund:debounce(function(){
- toRefund();
- // alert(123113131);
- },2000),
- queryGoods: function(){
- vm.storeId = sessionStorage.getItem("storeId");
- $.get("../goods/queryGoodsName?storeId="+vm.storeId+"&goodsName=", function (r) {
- if (r.code == 0) {
- vm.searchGoods = r.goodsList;
- } else {
- alert(r.msg);
- }
- });
- },
- searchQuery: function (prodBarcode){
- vm.prodBarcode = prodBarcode;
- vm.query();
- },
- queryOrderStatus:function(){
- $.get("../order/queryOrderStatus/"+vm.orderSn, function (r) {
- alert(r.msg);
- });
- },
- queryInveResponse:function(){
- $.get("../order/queryInveResponse/"+vm.orderSn1, function(r){
- console.log(r.resultMessage);
- let resultString = "";
- if(r.resultMessage != null && r.resultMessage.length > 0){
- for(let i = 0 ; i < r.resultMessage.length; i ++){
- resultString += i+':'+r.resultMessage[i] + '\r\n';
- }
- }
- alert(resultString);
- }) ;
- },
- query: function () {
- vm.storeId = sessionStorage.getItem("storeId");
- var thisGoods = {};
- var overflowLi = this.$refs.overflowLi;
- $.get("../goods/details/"+vm.prodBarcode+"/"+vm.storeId, function (r) {
- if (r.code == 0) {
- r.goodsDetails.sellVolume = 1;
- vm.goodsMap.set(r.goodsDetails.goodsSn,JSON.parse(JSON.stringify(r.goodsDetails)));
- vm.prodBarcode = '';
- calculateGoodsPrice(r);
- handle(r.goodsDetails,"add");
- //此时必须异步执行滚动条滑动至底部
- setTimeout(()=>{
- overflowLi.scrollTop = overflowLi.scrollHeight;
- },0)
- } else {
- alert(r.msg);
- }
- });
- },
- add:function(value){
- // 增加数量
- for(var i = 0 ; i < this.goodsList.length ; i++){
- if(this.goodsList[i].id == value){
- var goodsDetails = JSON.parse(JSON.stringify(vm.goodsMap.get(this.goodsList[i].goodsSn)));
- calculateGoodsByMj(goodsDetails,"add");
- calculateGoodsByMysy(goodsDetails,"add");
- calculateGoodsByHalfPrice(goodsDetails,"add");
- // calculateGoodsByMz(goodsDetails,"add");
- handle(goodsDetails,"add");
- break;
- }
- }
- },
- minus:function(value){
- // 减少数量
- for(var i = 0 ; i < this.goodsList.length ; i++){
- if(this.goodsList[i].id == value){
- // 获取当前购物车的数量
- var g = JSON.parse(JSON.stringify(this.goodsList[i]));
- console.log(g);
- var goodsDetails = JSON.parse(JSON.stringify(vm.goodsMap.get(this.goodsList[i].goodsSn)));
- if(g.sellVolume === 1){
- alert("数量至少为1个");
- return ;
- }
- // 如果不为空,证明减的是买A送B中的B,这时候要还原赠送资格跟B的扣减
- var freeMap = vm.freeBardcode.get(goodsDetails.prodBarcode);
- if((freeMap || freeMap == 0) && g.actualPaymentAmount == 0){
- vm.freeBardcode.set(goodsDetails.prodBarcode,freeMap + 1);
- goodsDetails.sellVolume = -1;
- goodsDetails.actualPaymentAmount = 0;
- goodsDetails.discountedPrice = -goodsDetails.retailPrice;
- goodsDetails.goodstaxes = - goodsDetails.goodstaxes;
- goodsDetails.retailPrice = - goodsDetails.retailPrice;
- }else{
- goodsDetails.sellVolume = g.sellVolume;
- calculateGoodsByMj(goodsDetails,"minus");
- calculateGoodsByMysy(goodsDetails,"minus");
- calculateGoodsByHalfPrice(goodsDetails,"minus");
- // calculateGoodsByMz(goodsDetails,"minus");
- goodsDetails.sellVolume = -1;
- goodsDetails.actualPaymentAmount = -goodsDetails.actualPaymentAmount;
- goodsDetails.discountedPrice = -goodsDetails.discountedPrice;
- goodsDetails.goodstaxes = - goodsDetails.goodstaxes;
- goodsDetails.retailPrice = - goodsDetails.retailPrice;
- }
- handle(goodsDetails,"minus");
- break;
- }
- }
- },
- deleteItem:function(value){
- console.log(value);
- // 删除这条记录
- for(var i = 0 ; i < this.goodsList.length ; i++){
- if(this.goodsList[i].id == value){
- if(this.goodsList.length == 1){
- vm.goods = {};
- vm.goodsDetail = false;
- }
- if(vm.mz.get(this.goodsList[i].prodBarcode)){
- vm.mz.get(this.goodsList[i].prodBarcode).useMz = false ;
- }
- if(vm.brandGetOneFree.get(this.goodsList[i].brand)){
- var giftBarcode = vm.brandGetOneFree.get(this.goodsList[i].brand).giftBarcode;
- var muilty = vm.brandGetOneFree.get(this.goodsList[i].brand).buyNum;
- var sellNum = this.goodsList[i].sellVolume;;
- vm.freeBardcode.set(giftBarcode,sellNum/muilty);
- for(var j = 0 ; j < vm.goodsList.length ; j++){
- var shopcartGoods = vm.goodsList[j];
- var shopcartFree = vm.freeBardcode.get(shopcartGoods.prodBarcode);
- if(shopcartFree /*&& shopcartGoods.actualPaymentAmount*/){
- shopcartGoods.actualPaymentAmount = shopcartGoods.actualPaymentAmount + (shopcartGoods.retailPrice * shopcartGoods.sellVolume);
- shopcartGoods.discountedPrice = shopcartGoods.discountedPrice - (shopcartGoods.retailPrice * shopcartGoods.sellVolume);
- vm.discountedPrice = vm.discountedPrice - (shopcartGoods.retailPrice * shopcartGoods.sellVolume);
- vm.actualPrice = vm.actualPrice + (shopcartGoods.retailPrice * shopcartGoods.sellVolume);
- vm.freeBardcode.set(shopcartGoods.prodBarcode, 0);// 重置回0
- }
- }
- }
- if(vm.halfPrice.get(this.goodsList[i].prodBarcode)){
- vm.halfPrice.set(this.goodsList[i].prodBarcode,1);
- }
- var goods = this.goodsList[i];
- console.log(goods);
- console.log(vm.totalPrice);
- if(vm.freeBardcode.get(goods.prodBarcode) || vm.freeBardcode.get(goods.prodBarcode) == 0){
- var nnum = (((goods.retailPrice * goods.sellVolume) - goods.actualPaymentAmount)/goods.retailPrice);
- vm.freeBardcode.set(goods.prodBarcode, nnum);
- }
- vm.totalPrice = vm.totalPrice - (goods.retailPrice * goods.sellVolume);
- vm.totalCount = vm.totalCount - (goods.sellVolume);
- vm.discountedPrice = vm.discountedPrice - goods.discountedPrice;
- vm.actualPrice = vm.actualPrice - goods.actualPaymentAmount;
- vm.boughtNum.delete(goods.prodBarcode);
- vm.totalPrice = Math.round(vm.totalPrice * 100) / 100;
- vm.discountedPrice = Math.round(vm.discountedPrice * 100) / 100;
- vm.actualPrice = Math.round(vm.actualPrice * 100) / 100;
- vm.showReduceMoney = Math.round(vm.showReduceMoney * 100) / 100;
- this.goodsList.splice(i,1);
- break;
- }
- }
- this.index = value;
- },
- clearGoodsList:function(){
- confirm('确认清空吗?', function () {
- vm.goodsList = [];
- vm.customClearData();
- alert("清空成功");
- })
- },
- pendingOrder:function(){
- if(this.goodsList.length == 0){
- alert("购物车中没有商品");
- return;
- }
- console.log(vm.pendingOrderMap.size);
- if(vm.pendingOrderMap.size >= 3){
- alert("订单挂起最多支持3单");
- return;
- }
- var pendingObject = {
- 'goodsList':this.goodsList,
- 'totalPrice':vm.totalPrice,
- 'totalCount':vm.totalCount,
- 'discountedPrice':vm.discountedPrice,
- 'actualPrice':vm.actualPrice
- }
- vm.pendingOrderMap.set(vm.pendingIndex,pendingObject);
- vm.pendingOrderKeys.push(vm.pendingIndex);
- var newIndex = ++vm.pendingIndex;
- vm.pendingIndex = newIndex > 3?1: newIndex;
- vm.goodsList = [];
- vm.customClearData();
- },
- toResumePending:function(){
- if(vm.pendingOrderMap.size == 0){
- alert("当前没有挂起的订单");
- return ;
- }
- $('#pendignOrderModal').modal('show')
- },
- resumePending:function(key){
- if(vm.pendingOrderMap.size == 0){
- alert("当前没有挂起的订单");
- return ;
- }
- if(vm.goodsList.length > 0){
- alert("购物车中已有商品,不允许恢复!")
- return ;
- }
- var pendingObject = vm.pendingOrderMap.get(key);
- console.log(pendingObject);
- vm.goodsList = pendingObject.goodsList;
- vm.totalPrice = pendingObject.totalPrice;
- vm.totalCount = pendingObject.totalCount;
- vm.discountedPrice = pendingObject.discountedPrice;
- vm.actualPrice = pendingObject.actualPrice;
- // 清除恢复的数据
- vm.pendingOrderMap.delete(key);
- removeByValue(vm.pendingOrderKeys,key);
- $('#pendignOrderModal').modal('hide')
- },
- toOrderSubmit:function(){
- if(this.goodsList.length == 0){
- alert("请选择商品");
- return;
- }
- $('#myModal').modal('show')
- // 每次点击提交订单的时候清空姓名和身份证信息和手机号
- // vm.$refs.customName.value = "";
- // vm.$refs.customIDCard.value = "";
- // vm.$refs.customPhone.value = "";
- if(vm.$refs.couponSn)
- vm.$refs.couponSn.value = "";
- this.userInfo.couponSn = "";
- },
- submitOrder:function(){
- vm.parCode = this.$refs.payCode.currentValue
- vm.myDebounce();
- },customClearData: function(){
- vm.totalPrice = 0;
- vm.totalCount = 0;
- vm.discountedPrice = 0;
- vm.actualPrice = 0;
- vm.goods={};
- vm.goodsDetail = false;
- // 第二件半价
- vm.halfPrice = new Map();
- // 买一送一
- vm.mysy = [];
- vm.freeBardcode = new Map();
- vm.brandGetOneFree = new Map();
- vm.barcodeGetOneFree = new Map();
- vm.brandGetOneFree = new Map();
- vm.boughtNum = new Map();
- // 组合价
- vm.zhjsp = new Map();
- vm.combinationPrice = new Map(); // 组合价商品的组合价
- // 满减
- vm.mj = new Map();
- vm.accumulatedAmount = new Map();// 累积金额(满减使用的)
- vm.reduceMoney = 0; // 满减金额
- vm.showReduceMoney = 0; // 用于展示的满减金额
- // 满赠
- vm.mz = new Map();
- vm.accumulatedAmountForFullGift = new Map(); // 累积金额(满赠使用的)
- vm.fullGiftCode = [];// 满赠商品条码
- // 优惠券
- vm.coupons = new Map();
- },
- queryIDCardInfo: function(){
- $.get("../order/queryIDCardInfo/"+vm.$refs.customPhone.value, function (r){
- if(r.code === 0){
- var data = r.userEntity;
- vm.$refs.customName.value = data.username;
- vm.$refs.customIDCard.value = data.idNo;
- }else{
- alert(r.msg);
- }
- });
- },
- getIDCardInfo: function(){
- $.post("http://127.0.0.1:8000/idcard/read", function (r){
- if(r.code == "0"){
- vm.$refs.customName.value = r.rows[0].data.name;
- vm.$refs.customIDCard.value = r.rows[0].data.id_no;
- }else if(r.code=="-1"){
- alert(r.msg);
- return;
- }else{
- alert("请连接设备或设备有问题,请联系管理员!");
- }
- });
- },
- customPhoneBlur:function (){
- let customPhone = this.$refs.customPhone.value;
- if(customPhone){
- for(let key in this.userInfoBinding){
- if(customPhone == key){
- let userInfoBindingValue = this.userInfoBinding[key];
- this.$refs.customName.value = userInfoBindingValue.substring(0, userInfoBindingValue.length-18);
- this.$refs.customIDCard.value = userInfoBindingValue.substring(userInfoBindingValue.length-18);
- break;
- }
- }
- }
- },
- submitCustomInfo:function(){
- this.userInfo.customName = this.$refs.customName.value ;
- this.userInfo.customIDCard = this.$refs.customIDCard.value ;
- this.userInfo.customPhone = this.$refs.customPhone.value;
- if(this.$refs.couponSn)
- this.userInfo.couponSn = this.$refs.couponSn.value;
- 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)$/;
- if(!this.userInfo.customName){
- alert("姓名不能为空!");
- return ;
- }
- if(!idcardReg.test(this.userInfo.customIDCard)){
- alert("请输入正确的身份证号");
- return ;
- }
- if(!(/^1[3456789]\d{9}$/.test(this.userInfo.customPhone))){
- alert("手机号码有误,请重填");
- return ;
- }
- //将手机号与姓名身份证号进行绑定,下次填写手机号即可
- let userInfoBindingKey = this.userInfo.customPhone;
- let userInfoBindingValue = this.userInfo.customName+this.userInfo.customIDCard;
- this.userInfoBinding[userInfoBindingKey] = userInfoBindingValue;
- if(this.userInfo.couponSn && this.userInfo.couponSn != ""){
- var coupon = vm.coupons.get(this.userInfo.couponSn);
- if(coupon == null){
- alert("请输入正确的优惠券码");
- return ;
- }
- }
- $("#Send").attr("data-dismiss","modal");
- $('#payModal').modal('show');
- $("#payCode").keydown(function(e){
- if(e.keyCode==13){
- $("#submitOrder").click();
- event.preventDefault();
- }
- });
- $('body').on('hidden.bs.modal', '.modal', function () {
- $(this).removeData();
- });
- },
- queryOrderDetail:function(orderSn,pickUpCode){
- var storeId = sessionStorage.getItem("storeId");
- $.get("../order/orderDetail/"+orderSn, function (r) {
- if (r.code == 0) {
- vm.orderProcessRecord = r.resultObj.orderProcessRecordEntity;
- vm.orderEntity = r.resultObj.orderEntity;
- vm.goodsDetailList = r.resultObj.goodsList;
- vm.currentOrderNo = r.resultObj.orderEntity.id;
- vm.pickUpCode = pickUpCode;
- vm.tax = r.resultObj.tax;
- vm.response = r.resultObj.response;
- if(vm.orderProcessRecord.eleOrderStartTime){
- vm.orderProcessRecord.eleOrderStartTime = parsedate(vm.orderProcessRecord.eleOrderStartTime);
- }
- if(vm.orderProcessRecord.paymentStartTime){
- vm.orderProcessRecord.paymentStartTime = parsedate(vm.orderProcessRecord.paymentStartTime);
- }
- if(vm.orderProcessRecord.waybillStartTime){
- vm.orderProcessRecord.waybillStartTime = parsedate(vm.orderProcessRecord.waybillStartTime);
- }
- if(vm.orderProcessRecord.customsSuccTime){
- vm.orderProcessRecord.customsSuccTime = parsedate(vm.orderProcessRecord.customsSuccTime);
- }
- if(vm.orderProcessRecord.addOrderStartTime){
- vm.orderProcessRecord.addOrderStartTime = parsedate(vm.orderProcessRecord.addOrderStartTime);
- }
- }
- });
- },
- resendNotice:function(){
- confirm('确认重发重置吗?', function () {
- $.get("../order/resendOrderToCCNET/"+vm.orderEntity.orderSn+"/notice", function (r) {
- alert(r.msg);
- });
- })
- },
- resendWaybill:function(){
- confirm('确认重发运单吗?', function () {
- $.get("../order/resendOrderToCCNET/"+vm.orderEntity.orderSn+"/waybill", function (r) {
- alert(r.msg);
- });
- })
- },
- resendPayment:function(){
- confirm('确认重发支付单吗?', function () {
- $.get("../order/resendOrderToCCNET/"+vm.orderEntity.orderSn+"/payment", function (r) {
- alert(r.msg);
- });
- })
- },
- resendOrder:function(){
- confirm('确认重发电子订单吗?', function () {
- $.get("../order/resendOrderToCCNET/"+vm.orderEntity.orderSn+"/clsOrder", function (r) {
- alert(r.msg);
- });
- })
- },
- forceSendToOms:function(){
- confirm('确认强制推送清关吗?', function () {
- $.get("../order/resendOrderToCCNET/"+vm.orderEntity.orderSn+"/forceSend", function (r) {
- alert(r.msg);
- });
- })
- },
- verification:function(){
- if(vm.orderProcessRecord.isCustomsSend != 1){
- alert("请等待清关完成");
- return ;
- }
- confirm('确认核销吗?', function () {
- $.ajax({
- type: "POST",
- url: "../order/printMsgAndChangeCode",
- contentType: "application/json",
- data: JSON.stringify({'id':vm.currentOrderNo,'sessionId':vm.sessionId}),
- success: function (r) {
- if (r.ticket != null) {
- // printArea(r.ticket);
- var content = getPrintContentOrder(r.ticket);
- printArea(content);
- }else{
- alert("打印小票失败");
- }
- }
- });
- })
- },
- refundOrder:function(){
- vm.debounceRefund();
- },
- //确认提货
- confirmDelivery: function(){
- confirm('确认提货吗?', function () {
- $.get("../pickupcode/confirmDelivery/"+vm.orderEntity.orderSn, function (r) {
- alert(r.msg);
- });
- })
- },
- retrySendOrder:function(){
- },
- getInfo: function (id) {
- $.get("../sys/notice/info/" + id, function (r) {
- vm.sysNotice = r.sysNotice;
- });
- },
- reload: function (event) {
- vm.showList = false;
- vm.showViewList = true;
- vm.showSaveSupplierGoods = true;
- var page = $("#jqGrid").jqGrid('getGridParam', 'page');
- $("#jqGrid").jqGrid('setGridParam', {
- postData: {
- storeId: vm.q.storeId,
- goodsName: vm.q.goodsName,
- goodsSn: vm.q.goodsSn,
- productSn: vm.q.productSn, category: vm.q.category, categoryTwo: vm.q.categoryTwo, goodsBizType:vm.q.goodsBizType,
- thirdPartyMerchCode: vm.q.thirdPartyMerchCode
- },
- page: page
- }).trigger("reloadGrid");
- vm.handleReset('formValidate');
- },
- handleSubmit: function (name) {
- handleSubmitValidate(this, name, function () {
- vm.saveOrUpdate()
- });
- },
- handleReset: function (name) {
- handleResetForm(this, name);
- },
- logout: function () {
- confirm('注:您确定要安全退出本次登录吗?', function () {
- dialogLoading(true);
- setTimeout(function () {
- toUrl('../logout?_' + $.now());
- }, 500);
- });
- }
- }
- });
- function getPrintContent(ticket) {
- var content = "<div style=\"width: 300px;font-family: 微软雅黑;font-size: 15px;\">";
- // // 打印ogo
- // content += "<div style=\"text-align: center;width: 100%;height: 50px;\">";
- // // content += "<img src='./../../statics/img/cw_logo.png' />";
- // // content += "2222222222";
- // content += "<img src='/statics/img/cw_logo.png' style='width: 100%;height: 100%;' />";
- // content += "</div>";
- //小票头
- content += "<div style=\"text-align: center;width: 100%;font-weight:bold;font-size: 15px;\">";
- content += ticket.shopName
- content += "</div>";
- content += "<div style=\"width: 100%;overflow:hidden;white-space: nowrap;\">--------------------------------------------------</div>";
- content += "<div style=\"width: 100%;margin:5px 0px;\">";
- /*content += "收银机号:" + ticket.salesNo;
- content += "</div>";
- content += "<div style=\"width: 100%;\">";*/
- content += "收银员:" + ticket.userName;
- content += "</div>";
- content += "<div style=\"width: 100%;font-size: 30px;margin:15px 0 10px 5px;\">";
- content += "取货码:" + ticket.code;
- content += "</div>";
- content += "<div style=\"width: 100%;margin:5px 0px;\">";
- content += "订单编号:" + ticket.orderNo;
- content += "</div>";
- content += "<div style=\"width: 100%;margin:5px 0px;\">";
- content += "打印日期:" + ticket.time;
- content += "</div>";
- content += "<div style=\"width: 100%;margin:5px 0px;font-size: 13px;\">";
- content += "该取货单号只有当天有效"
- content += "</div>";
- content += "</div>";
- return content;
- }
- var printAreaCount = 0;
- function printArea(content) {
- var idPrefix = "printArea_";
- removePrintArea(idPrefix + printAreaCount);
- ++printAreaCount;
- var iframeId = idPrefix + printAreaCount;
- var iframeStyle = 'width:0px;height:0px;left:0px;top:0px;';
- iframe = document.createElement('IFRAME');
- $(iframe).attr({
- style: iframeStyle,
- id: iframeId
- });
- document.body.appendChild(iframe);
- var doc = iframe.contentWindow.document;
- // doc.open();
- doc.write('<div class="">' + content
- + '</div>');
- doc.close();
- var frameWindow = iframe.contentWindow;
- frameWindow.focus();
- frameWindow.print();
- alert('打印小票完成');
- }
- function printArea2(content) {
- var idPrefix = "printArea_";
- removePrintArea(idPrefix + printAreaCount);
- printAreaCount++;
- var iframeId = idPrefix + printAreaCount;
- var iframeStyle = 'width:0px;height:0px;left:0px;top:0px;';
- iframe = document.createElement('IFRAME');
- $(iframe).attr({
- style: iframeStyle,
- id: iframeId
- });
- document.body.appendChild(iframe);
- var doc = iframe.contentWindow.document;
- doc.open();
- doc.write('<div class="">' + content
- + '</div>');
- doc.close();
- var frameWindow = iframe.contentWindow;
- frameWindow.focus();
- frameWindow.print();
- frameWindow.print();
- frameWindow.close();
- }
- var removePrintArea = function (id) {
- $("iframe#" + id).remove();
- };
- var webSocket;
- function openWebSocket() {
- var storeId = sessionStorage.getItem("storeId");
- if ("WebSocket" in window) {
- console.log("当前浏览器支持WebSocket");
- //实现化WebSocket对象
- //指定要连接的服务器地址与端口建立连接
- //注意ws、wss使用不同的端口。我使用自签名的证书测试,
- //无法使用wss,浏览器打开WebSocket时报错
- //ws对应http、wss对应https。
- webSocket = new WebSocket("ws://183.62.225.124:8080/ws/server/"+storeId);
- // webSocket = new WebSocket("ws://8.135.102.238:8080//ws/server/"+storeId);
- // webSocket = new WebSocket("ws://127.0.0.1:8080//ws/server/"+163);
- // webSocket = new WebSocket("wss://cb.k1net.cn/ws/server/"+storeId);
- if (webSocket.readyState === webSocket.CONNECTING) {
- console.log('1.连接正在打开......');
- }
- // ---------- WebSocket 对象注册事件 ----------
- //连接打开事件
- webSocket.onopen = function () {
- if (webSocket.readyState === webSocket.OPEN) {
- console.log('2.连接已打开');
- }
- console.log('2.向服务端发送测试消息......');
- // webSocket.send("2.client发测试消息:Client sent test msg。");
- };
- //收到消息事件
- webSocket.onmessage = function (msg) {
- var data = Object.assign({}, JSON.parse(msg.data));
- console.log('3.接收到服务端信息......data:'+data);
- vm.sessionId = data.sessionId;
- vm.pickUpCodeList = [];
- if(data.pickUpCodeList.length > 0){
- for(var i = 0 ; i < data.pickUpCodeList.length ; i++){
- // console.log(data.pickUpCodeList[i].storeId);
- if(data.pickUpCodeList[i].storeId === storeId){
- vm.pickUpCodeList.push(data.pickUpCodeList[i]);
- }
- }
- }
- vm.delayResponse = data.delayResponse;
- };
- //连接关闭事件
- webSocket.onclose = function () {
- if (!webSocket) {
- console.log('4.Socket连接已关闭');
- }
- };
- //发生了错误事件
- webSocket.onerror = function () {
- console.log("5.Socket发生了错误");
- }
- } else {
- console.log("当前浏览器不支持WebSocket");
- return false;
- }
- }
- function sendMessage() {
- if(webSocket && webSocket.readyState === webSocket.OPEN) {
- webSocket.send("client manual send message.")
- } else {
- console.log('6.未创建WebSocket连接');
- }
- }
- function closeWebSocket() {
- if (webSocket != null) {
- webSocket.close();
- webSocket = null;
- }
- console.log("关闭WebSocket");
- }
- //窗口关闭时,关闭连接
- window.unload = function () {
- webSocket.close();
- };
- function parsedate(value){
- var date = new Date(value);
- var year = date.getFullYear();
- var month = date.getMonth()+1; //月份+1
- var day = date.getDate();
- var hour = date.getHours();
- var minutes = date.getMinutes();
- var second = date.getSeconds();
- return year+"-"+month+"-"+day+" "+hour+":"+minutes +":"+second;
- }
- function getPrintContentOrder(ticket) {
- var content = "<div style=\"width: 270px;font-family: 微软雅黑;font-size: 8px;\">";
- // 打印ogo
- content += "<div style=\"text-align: center;width: 100%;height: 260px;\">";
- content += "<img src='/statics/img/cw_logo2.png' style='width: 100%;height: 100%;' />";
- content += "</div>";
- //小票头
- content += "<div style=\"text-align: center;width: 100%;font-weight:bold;font-size: 13px;\">";
- content += ticket.ticketHead.title;
- content += "</div>";
- /*content += "<div style=\"width: 100%;\">";
- content += "会员:" + ticket.ticketHead.memberId;
- content += "</div>";*/
- content += "<div style=\"width: 100%;font-size: 25px;\">";
- content += "取货码:" + vm.pickUpCode;
- content += "</div>";
- content += "<div style=\"width: 100%;\">";
- content += "订单号:" + ticket.ticketHead.orderId;
- content += "</div>";
- content += "<div style=\"width: 100%;\">";
- content += "交易时间:" + ticket.ticketHead.tradeTime;
- content += "</div>";
- content += "<div style=\"width: 100%;overflow:hidden;white-space: nowrap;\">-------------------------------------------------------</div>";
- //商品信息
- content += "<table style=\"width: 100%;\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
- content += "<tr>";
- content += "<td style=\"width: 40%;text-align: left;font-size: 10px;font-weight: bold;\">商品名称</td>";
- content += "<td style=\"width: 17%;text-align: right;font-size: 10px;font-weight: bold;\">单价</td>";
- content += "<td style=\"width: 17%;text-align: right;font-size: 10px;font-weight: bold;\">优惠</td>";
- // content += "<td style=\"width: 16%;text-align: right;font-size: 10px;font-weight: bold;\">税费</td>";
- content += "<td style=\"width: 15%;text-align: right;font-size: 10px;font-weight: bold;\">数量</td>";
- content += "<td style=\"width: 18%;text-align: right;font-size: 10px;font-weight: bold;\">小计</td>";
- content += "</tr>";
- content += "</table>";
- content += "<div style=\"width: 100%;overflow:hidden;white-space: nowrap;\">-------------------------------------------------------</div>";
- content += "<table style=\"width: 100%;\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
- for (var i=0;i< ticket.goods.length;i++){
- content += "<tr>";
- content += "<td style=\"width: 40%;text-align: left;font-size: 8px;padding-top: 8px;\">";
- content += "<table style=\"width: 100%;\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
- content += "<tr>";
- content += "<td style=\"text-align: left;font-size: 8px;vertical-align:top;\">#</td>";
- content += "<td style=\"text-align: left;font-size: 8px;\">" + ticket.goods[i].gname + "</td>";
- content += "</tr>";
- content += "</table>";
- content += "</td>";
- content += "<td style=\"width: 17%;text-align: right;font-size: 8px;vertical-align:bottom;padding-top: 8px;\">" + ticket.goods[i].uprice + "</td>";
- content += "<td style=\"width: 17%;text-align: right;font-size: 8px;vertical-align:bottom;padding-top: 8px;\">" + ticket.goods[i].discountPrice + "</td>";
- // content += "<td style=\"width: 17%;text-align: right;font-size: 8px;vertical-align:bottom;padding-top: 8px;\">" + ticket.goods[i].taxation + "</td>";
- content += "<td style=\"width: 15%;text-align: center;font-size: 8px;vertical-align:bottom;padding-top: 8px;\">" + ticket.goods[i].num + "</td>";
- content += "<td style=\"width: 18%;text-align: right;font-size: 8px;vertical-align:bottom;padding-top: 8px;\">" + ticket.goods[i].subtotal + "</td>";
- content += "</tr>";
- }
- content += "</table>";
- content += "<div style=\"width: 100%;overflow:hidden;white-space: nowrap;\">--------------------------------------------------</div>";
- //收银信息
- content += "<div style=\"width: 100%;\">";
- content += "<span style=\"float: left;width: 50%;text-align: left;\">商品合计:</span>";
- content += "<span style=\"float: left;width: 17%;text-align: left;\">" + ticket.cashInfo.goodsTotal + "件</span>";
- content += "<span style=\"float: right;width: 33%;text-align: right;\">" + ticket.cashInfo.total + "元</span>";
- content += "</div>";
- content += "<div style=\"width: 100%;\">";
- content += "<span style=\"float: left;width: 50%;text-align: left;\">税费合计:</span>";
- content += "<span style=\"float: left;width: 17%;text-align: left;\">" + ticket.cashInfo.goodsTotal + "件</span>";
- content += "<span style=\"float: right;width: 33%;text-align: right;\">" + ticket.cashInfo.taxTotal + "元</span>";
- content += "</div>";
- content += "<div style=\"width: 100%;\">";
- content += "<span style=\"float: left;width: 50%;text-align: left;\">优惠合计:</span>";
- content += "<span style=\"float: right;width: 50%;text-align: right;\">" + ticket.cashInfo.oddChange + "元</span>";
- content += "</div>";
- content += "<div style=\"width: 100%;\">";
- content += "<span style=\"float: left;width: 50%;text-align: left;\">实收:</span>";
- content += "<span style=\"float: right;width: 50%;text-align: right;\">" + ticket.cashInfo.receipts + "元</span>";
- content += "</div>";
- content += "<div style=\"width: 100%;\">";
- content += "<span style=\"float: left;width: 50%;text-align: left;\">优惠券:</span>";
- content += "<span style=\"float: right;width: 50%;text-align: right;\">" + ticket.cashInfo.coupon + "元</span>";
- content += "</div>";
- // content += "<div style=\"width: 100%;\">";
- // content += "<span style=\"float: left;width: 50%;text-align: left;\">运费:</span>";
- // content += "<span style=\"float: right;width: 50%;text-align: right;\">" + ticket.cashInfo.freight + "元</span>";
- // content += "</div>";
- content += "<div style=\"width: 100%;\">";
- content += "<span style=\"float: left;width: 50%;text-align: left;\">支付渠道:</span>";
- // 后期改成从系统中取
- content += "<span style=\"float: right;width: 50%;text-align: right;\">" + "支付宝支付" + "</span>";
- content += "</div>";
- content += "<div style=\"width: 100%;overflow:hidden;white-space: nowrap;\">--------------------------------------------------</div>";
- //海关清单信息
- content += "<div style=\"width: 100%;\">";
- content += "订单号:" + ticket.cusListing.orderId;
- content += "</div>";
- content += "<div style=\"width: 100%;\">";
- content += "运单编号:" + ticket.cusListing.waybillId;
- content += "</div>";
- content += "<div style=\"width: 100%;\">";
- content += "海关清单号:" + ticket.cusListing.invtNo;
- content += "</div>";
- content += "<div style=\"width: 100%;\">";
- content += "收货人:" + ticket.cusListing.consignee;
- content += "</div>";
- content += "<div style=\"width: 100%;\">";
- content += "收货人电话:" + ticket.cusListing.consigneeTel;
- content += "</div>";
- content += "<div style=\"width: 100%;\">";
- content += "始发地: 仓库地址 : 广东省深圳市南山区前海保税港区W104" ;
- content += "</div>";
- content += "<div style=\"width: 100%;\">";
- content += "交货地:" + ticket.cusListing.deliveryAddress;
- content += "</div>";
- content += "<div style=\"width: 100%;overflow:hidden;white-space: nowrap;\">--------------------------------------------------</div>";
- content += "<div style=\"width: 100%;text-align: center;\">";
- content += "购买跨境商品须知:"
- content += "</div>";
- content += "<div style=\"width: 100%;\">";
- content += "1、凡购买跨境商品均不提供发票;<br> 2、单笔限购5000元,年交易限额2.6万元; <br> 3、所有订单经海关放行后方可提货; <br> 4、凭小票领取您的订单商品; <br> 5、非产品质量问题,跨境商品不支持无理由退换货,请及时检查。 "
- content += "</div>";
- content += "<div style=\"width: 100%;overflow:hidden;white-space: nowrap;\">--------------------------------------------------</div>";
- content += "<div style=\"width: 100%;\">";
- // content += ticket.ticketFoot.summary;
- content += "</div>";
- content += "<div style=\"width: 100%;\">";
- // content += "客服电话:" + ticket.ticketFoot.serviceTel;
- content += "</div>";
- content += "<div style=\"width: 100%;\">";
- // content += "网址:" + ticket.ticketFoot.url1;
- content += "</div>";
- content += "<div style=\"width: 100%;\">";
- content += ticket.ticketFoot.welcome;
- content += "</div>";
- content += "<div style=\"width: 100%;\">";
- content += "惠州市惠城区港惠购物中心负一层";
- content += "</div>";
- content += "<div style=\"width: 100%;\">";
- content += "请保管好收银小票。";
- content += "</div>";
- // 打印二维码
- content += "<div style=\"text-align: center;width: 100%;height: 250px;\">";
- content += "<img src='/statics/img/cw_qrcode.png' style='width: 100%;height: 100%;' />";
- content += "</div>";
- content += "<div style=\"width: 100%;text-align: center;\">";
- content += "关注CW大药房客服号,获取更多优惠信息"
- content += "</div>";
- return content;
- }
- function queryAssistantInfo(){
- $.get("../sys/user/info", function (r) {
- if(r.code == 0){
- vm.sysUserInfo = r.user;
- $.get("../store/getStoresByMerch?merchSn="+r.user.merchSn+"&_=1590374349985",function(result){
- if(result.code == 0){
- for(var i = 0 ;i < result.list.length; i++){
- if(result.list[i].id == r.user.storeId){
- vm.storeName = result.list[i].storeName;
- break;
- }
- }
- }
- });
- }
- });
- }
- function removeByValue(arr, val) {
- var index = arr.indexOf(val);
- if (index > -1) {
- arr.splice(index, 1);
- }
- }
- function handle(goodsDetails,operatorType){
- vm.goodsDetail = true;
- // goodsDetails.sellVolume = 1;
- goodsDetails.id = vm.index;
- if(!vm.goodsList[vm.index]){
- vm.index = vm.max;
- }
- vm.max++;
- goodsDetails.goodsDesc = "";
- // 判断当前商品是否是赠品
- var freeMap = vm.freeBardcode.get(goodsDetails.prodBarcode);
- if(freeMap && "minus" != operatorType){
- goodsDetails.actualPaymentAmount = 0;
- goodsDetails.discountedPrice = goodsDetails.retailPrice;
- vm.freeBardcode.set(goodsDetails.prodBarcode,freeMap - 1);
- }else{
- if(!freeMap && freeMap != 0 ){
- // 判断购物车中是否有赠品 这个操作只有是非赠品才能进来
- for(var i = 0 ; i < vm.goodsList.length ; i++){
- var shopcartGoods = vm.goodsList[i];
- var shopcartFree = vm.freeBardcode.get(shopcartGoods.prodBarcode);
- if(shopcartFree /*&& shopcartGoods.actualPaymentAmount*/){
- // if("minus" != operatorType){
- var shopcartSellNum = shopcartGoods.sellVolume;
- if(shopcartFree > shopcartSellNum){
- shopcartGoods.actualPaymentAmount = 0;
- shopcartGoods.discountedPrice = shopcartGoods.retailPrice * shopcartFree;
- vm.discountedPrice = vm.discountedPrice + shopcartGoods.discountedPrice ;
- vm.actualPrice = vm.actualPrice + shopcartGoods.actualPaymentAmount ;
- vm.freeBardcode.set(shopcartGoods.prodBarcode,shopcartFree - 1);//
- }else if(shopcartFree == -1 ){
- // g.actualPaymentAmount == 0){
- shopcartGoods.actualPaymentAmount = shopcartGoods.retailPrice + shopcartGoods.actualPaymentAmount;
- shopcartGoods.discountedPrice = shopcartGoods.discountedPrice - shopcartGoods.retailPrice;
- vm.discountedPrice = vm.discountedPrice + shopcartGoods.discountedPrice ;
- vm.actualPrice = vm.actualPrice + shopcartGoods.actualPaymentAmount ;
- vm.freeBardcode.set(shopcartGoods.prodBarcode,0);// 重置回0
- }else{
- if(shopcartGoods.actualPaymentAmount > 0){
- shopcartGoods.actualPaymentAmount = shopcartGoods.actualPaymentAmount - (shopcartGoods.retailPrice * shopcartFree);
- shopcartGoods.discountedPrice = shopcartGoods.discountedPrice + (shopcartGoods.retailPrice * shopcartFree);
- vm.actualPrice = vm.actualPrice - (shopcartGoods.retailPrice * shopcartFree) ;
- vm.discountedPrice = vm.discountedPrice + (shopcartGoods.retailPrice * shopcartFree) ;
- vm.freeBardcode.set(shopcartGoods.prodBarcode, shopcartFree - 1);// 重置回0
- }
- }
- // }
- }
- }
- }
- }
- goodsDetails.discountedPrice = Math.round(goodsDetails.discountedPrice * 100) / 100;
- goodsDetails.actualPaymentAmount = Math.round(goodsDetails.actualPaymentAmount * 100) / 100;
- var data = Object.assign({}, JSON.parse(JSON.stringify(goodsDetails)));
- var isPush = true;
- // 判断当前商品是否添加过
- for(var i = 0 ; i < vm.goodsList.length ; i++){
- if(vm.goodsList[i].goodsSn == data.goodsSn){
- var goodsDetails = vm.goodsList[i];
- if(data.actualPaymentAmount < 0 && goodsDetails.actualPaymentAmount == 0){
- // goodsDetails.goodstaxes = Math.round((parseFloat(goodsDetails.goodstaxes) - parseFloat(data.goodstaxes)) * 100)/100;
- // goodsDetails.discountedPrice = Math.round((parseFloat(goodsDetails.discountedPrice) - parseFloat(data.discountedPrice)) * 100)/100;
- goodsDetails.actualPaymentAmount = 0;
- }else{
- // 税 goodstaxes,优惠金额 discountedPrice,实际支付 actualPaymentAmount,数量 sellVolume 45636917
- goodsDetails.actualPaymentAmount = Math.round((parseFloat(goodsDetails.actualPaymentAmount) + parseFloat(data.actualPaymentAmount)) * 100)/100;
- }
- goodsDetails.discountedPrice = Math.round((parseFloat(goodsDetails.discountedPrice) + parseFloat(data.discountedPrice)) * 100)/100;
- goodsDetails.goodstaxes = Math.round((parseFloat(goodsDetails.goodstaxes) + parseFloat(data.goodstaxes)) * 100)/100;
- goodsDetails.sellVolume = Math.round((parseFloat(goodsDetails.sellVolume) + parseFloat(data.sellVolume)) * 100)/100;
- goodsDetails.activity = data.activity;
- isPush = false;
- break;
- }
- }
- // for(var i = 0 ; i < vm.goodsList.length ; i++){
- // if(vm.goodsList[i].goodsSn == data.goodsSn){
- // var goodsDetails = vm.goodsList[i];
- // // 税 goodstaxes,优惠金额 discountedPrice,实际支付 actualPaymentAmount,数量 sellVolume 45636917
- // goodsDetails.goodstaxes = Math.round((parseFloat(goodsDetails.goodstaxes) + parseFloat(data.goodstaxes)) * 100)/100;
- // goodsDetails.discountedPrice = Math.round((parseFloat(goodsDetails.discountedPrice) + parseFloat(data.discountedPrice)) * 100)/100;
- // goodsDetails.actualPaymentAmount = Math.round((parseFloat(goodsDetails.actualPaymentAmount) + parseFloat(data.actualPaymentAmount)) * 100)/100;
- // goodsDetails.sellVolume = Math.round((parseFloat(goodsDetails.sellVolume) + parseFloat(data.sellVolume)) * 100)/100;
- // goodsDetails.activity = data.activity;
- // isPush = false;
- // break;
- // }
- // }
- if(isPush){
- vm.goodsList.push(data);
- vm.index = vm.index + 1;
- }
- vm.totalPrice = (vm.totalPrice + data.retailPrice);
- if("minus" == operatorType){
- vm.totalCount = vm.totalCount - 1;
- }else{
- vm.totalCount = vm.totalCount + 1;
- }
- if(vm.reduceMoney > 0){
- vm.discountedPrice = vm.discountedPrice + data.discountedPrice + vm.reduceMoney;
- vm.actualPrice = vm.actualPrice + data.actualPaymentAmount - vm.reduceMoney;
- vm.showReduceMoney = vm.showReduceMoney + vm.reduceMoney;
- vm.reduceMoney = 0;
- }else{
- vm.discountedPrice = vm.discountedPrice + data.discountedPrice ;
- vm.actualPrice = vm.actualPrice + data.actualPaymentAmount ;
- }
- if(data.sellVolume < 0){
- data.sellVolume = - data.sellVolume;
- data.retailPrice = - data.retailPrice;
- data.goodstaxes = -data.goodstaxes;
- }
- vm.goods = data;
- // 处理精度
- vm.totalPrice = Math.round(vm.totalPrice * 100) / 100;
- vm.discountedPrice = Math.round(vm.discountedPrice * 100) / 100;
- vm.actualPrice = Math.round(vm.actualPrice * 100) / 100;
- vm.showReduceMoney = Math.round(vm.showReduceMoney * 100) / 100;
- }
- function toPayOrder(payCode){
- $('#payCode').unbind('keydown').keydown(function(event){});
- vm.machineCode = sessionStorage.getItem("machineCode");
- console.log(vm.machineCode);
- var param = {'userInfo':vm.userInfo,'payCode':vm.parCode,'goodsList':vm.goodsList,'sessionId':vm.sessionId,'machineCode':vm.machineCode};
- console.log(JSON.stringify(param));
- vm.parCode = "";
- $.ajax({
- type: "POST",
- url: "../order/orderConfirm",
- contentType: "application/json",
- data: JSON.stringify(param),
- success: function (r) {
- console.log(r);
- if (r.code == 0) {
- if (r.resultObj != null) {
- $(".form-group input[type=text]").each(function(){
- this.value = '';
- })
- // 打印取货码小票
- var content = getPrintContent(r.resultObj);
- console.log(content);
- printArea2(content);
- vm.goodsList = [];
- vm.customname = '' ;
- vm.customidcard = '';
- vm.customClearData();
- }else{
- // alert("打印小票失败");
- }
- } else {
- alert(r.msg);
- }
- }
- });
- }
- function toRefund(){
- confirm('确认退款吗?', function () {
- vm.canRefund = false;
- $.ajax({
- type: "POST",
- url: "../order/orderRefund",
- contentType: "application/json",
- data: JSON.stringify({'orderId':vm.currentOrderNo,'sessionId':vm.sessionId}),
- success: function (r) {
- if (r.code == 0) {
- vm.canRefund = true;
- alert("退款成功")
- }else{
- alert("退款失败,请联系管理员");
- }
- }
- });
- })
- }
|