12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586 |
- $(function () {
- openWebSocket();
- queryAssistantInfo();
- });
- window.onbeforeunload = function(){
- closeWebSocket();
- }
- function debounce(fn,delay){
- console.log("进来了");
- 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);
- }
- let vm = new Vue({
- el: '#rrapp',
- data: {
- showList: true,
- goodsDetail:false,
- title: null,
- goods:{},
- 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 : "",
- },
- methods: {
- myDebounce:debounce(function(){
- toPayOrder();
- },2000),
- query: function () {
- vm.storeId = sessionStorage.getItem("storeId");;
- var thisGoods = {};
- $.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");
- } 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.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(){
- this.goodsList = [];
- vm.customClearData();
- },
- pendingOrder:function(){
- if(this.goodsList.length == 0){
- alert("购物车中没有商品");
- return;
- }
- console.log(vm.pendingOrderMap.size);
- if(vm.pendingOrderMap.size >= 3){
- alert("订单挂起最多支持3单");
- return;
- }
- vm.pendingOrderMap.set(vm.pendingIndex,this.goodsList);
- vm.pendingOrderKeys.push(vm.pendingIndex);
- var newIndex = ++vm.pendingIndex;
- vm.pendingIndex = newIndex > 3?1: newIndex;
- vm.clearGoodsList();
- },
- 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 ;
- }
- vm.goodsList = vm.pendingOrderMap.get(key);
- // 清除恢复的数据
- 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.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){
- // var dataR = JSON.parse(r);
- // console.log(dataR)
- if(r.code == "0"){
- // if(!r.info){
- // alert("请连接设备或设备有问题,请联系管理员!");
- // return ;
- // }
- // var data = JSON.parse(r.info);
- // if(data.code=="0"){
- vm.$refs.customName.value = r.rows[0].data.name;
- vm.$refs.customIDCard.value = r.rows[0].data.id_no;
- // }else{
- // alert(data.msg);
- // return ;
- // }
- }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);
- }
- }
- });
- },
- 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(){
- confirm('确认退款吗?', function () {
- $.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) {
- alert("退款成功")
- }else{
- alert("退款失败,请联系管理员");
- }
- }
- });
- })
- },
- 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: 250px;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;
- if(!vm.firstPrint){
- setTimeout(function() {
- // frameWindow.close();
- frameWindow.focus();
- frameWindow.print();
- frameWindow.print();
- alert('打印小票完成');
- },250);
- vm.firstPrint = true;
- }else{
- // frameWindow.close();
- frameWindow.focus();
- frameWindow.print();
- 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://127.0.0.1:8080//ws/server/"+storeId);
- 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.pickUpCodeList = vm.pickUpCodeList.concat(data.pickUpCodeList);
- // console.log(vm.pickUpCodeList);
- // webSocket.send("2.client发测试消息:Client sent test msg。");
- };
- //连接关闭事件
- 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: 250px;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(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);
- }
- }
- });
- }
|