sale.js 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125
  1. $(function () {
  2. openWebSocket();
  3. queryAssistantInfo();
  4. });
  5. window.onbeforeunload = function(){
  6. closeWebSocket();
  7. }
  8. function calculateGoodsPrice(r){
  9. var rMap = r.map;
  10. var barCode = r.goodsDetails.prodBarcode;
  11. var brand = r.goodsDetails.brand;
  12. console.log(rMap);
  13. if(rMap.yhq){
  14. for(var i in rMap.yhq){
  15. vm.coupons.set(i,rMap.yhq[i]);
  16. }
  17. }
  18. // 是否有满减活动
  19. if(rMap.mj){
  20. if(rMap.mj[barCode] && !vm.mj.get(barCode)){
  21. // 该商品是否已经有过满减活动
  22. vm.mj.set(barCode,rMap.mj[barCode]);
  23. }else if(rMap.mj[brand] && !vm.mj.get(brand)){
  24. // 该品牌是否已经有过满减活动
  25. vm.mj.set(brand,rMap.mj[brand]);
  26. }
  27. }
  28. if(rMap.mysy){
  29. vm.mysy.push(rMap.mysy[barCode]);
  30. }
  31. if(rMap.mz){
  32. if(rMap.mz[barCode] && !vm.mz.get(barCode)){
  33. // 该商品是否已经有过满赠活动
  34. vm.mz.set(barCode,rMap.mz[barCode]);
  35. }else if(rMap.mz[brand] && !vm.mz.get(brand)){
  36. // 该品牌是否已经有过满赠活动
  37. vm.mz.set(brand,rMap.mz[brand]);
  38. }
  39. }
  40. if(rMap.zhjsp){
  41. // 遍历该商品所有可能的组合价商品类型
  42. for(var data in rMap.zhjsp){
  43. if(!vm.zhjsp.get(data)){
  44. // 分割组合价商品的条码,并以 条码:0 放入map中
  45. var barCodeArray = data.toString().split(":");
  46. var dataMap = new Map();
  47. console.log(rMap.zhjsp[data]);
  48. // dataMap.set();
  49. for(var j = 0 ; j < barCodeArray.length ; j ++){
  50. dataMap.set(barCodeArray[j],0);
  51. }
  52. vm.combinationPrice.set(data,rMap.zhjsp[data][0].combinedPrice)
  53. vm.zhjsp.set(data,dataMap);
  54. }
  55. }
  56. }
  57. calculateGoodsByMj(r.goodsDetails);
  58. calculateGoodsByMysy(r.goodsDetails);
  59. calculateGoodsByMz(r.goodsDetails);
  60. calculateGoodsByZhjsp(r);
  61. }
  62. // ==================== 满减==========================
  63. // 满减
  64. function calculateGoodsByMj(goodsDetails){
  65. if(vm.mj.get(goodsDetails.prodBarcode)){
  66. fullReduction(goodsDetails,goodsDetails.prodBarcode);
  67. }else if(vm.mj.get(goodsDetails.brand)){
  68. fullReduction(goodsDetails,goodsDetails.brand);
  69. }
  70. }
  71. // 满减的计算内容
  72. function fullReduction(goodsDetails,key){
  73. // 获取满减条件金额
  74. var qualifiedAmount = vm.mj.get(key).qualifiedAmount;
  75. // 获取已累积金额
  76. var money = vm.accumulatedAmount.get(key);
  77. if(isNaN(money)){
  78. money = goodsDetails.retailPrice;
  79. }else{
  80. money = money + goodsDetails.retailPrice;
  81. }
  82. if(money >= qualifiedAmount){
  83. vm.reduceMoney += vm.mj.get(key).deductionAmount; // 达到满减金额,获取扣减的额度
  84. vm.mj.delete(key); // 获取后删除该商品的满减
  85. vm.accumulatedAmount.delete(key); // 删除满减的金额
  86. }else{
  87. vm.accumulatedAmount.set(key,money);
  88. }
  89. }
  90. // ============================= 满赠 ==============================
  91. // 满赠
  92. function calculateGoodsByMz(goodsDetails){
  93. // 1.满赠的商品是不是自己,遍历满赠商品数组
  94. isSend(vm.fullGiftCode,goodsDetails,"满赠");
  95. if(vm.mz.get(goodsDetails.prodBarcode)){
  96. fullGift(goodsDetails,goodsDetails.prodBarcode);
  97. }else if(vm.mz.get(goodsDetails.brand)){
  98. fullGift(goodsDetails,goodsDetails.brand);
  99. }
  100. }
  101. function fullGift(goodsDetails,key){
  102. // 获取满赠条件金额
  103. var qualifiedAmount = vm.mz.get(key).qualifiedAmount;
  104. // 获取已累积金额
  105. var money = vm.accumulatedAmountForFullGift.get(key);
  106. if(isNaN(money)){
  107. money = goodsDetails.retailPrice;
  108. }else{
  109. money = money + goodsDetails.retailPrice;
  110. }
  111. // 达到满赠的要求
  112. if(money >= qualifiedAmount){
  113. // 将满赠的商品放入数组中,重置金额
  114. vm.fullGiftCode.push(vm.mz.get(key).giftBarcode);
  115. vm.mz.delete(key); // 获取后删除该商品的满减
  116. vm.accumulatedAmountForFullGift.delete(key); // 删除满减的金额
  117. // 2.购物车的商品里面是否有满赠的商品
  118. shopCartContain(vm.fullGiftCode,goodsDetails,"满赠");
  119. }else{
  120. vm.accumulatedAmountForFullGift.set(key,money);
  121. }
  122. }
  123. // 买一送一
  124. function calculateGoodsByMysy(goodsDetails){
  125. // 判断当前商品是否为赠品
  126. isSend(vm.mysy,goodsDetails,"买一送一");
  127. // 判断购物车里面是否有商品为赠品
  128. shopCartContain(vm.mysy,goodsDetails,"买一送一");
  129. }
  130. // 判断当前商品是否为赠品
  131. function isSend(activity,goodsDetails,activityName){
  132. if(activity.indexOf(goodsDetails.prodBarcode) >= 0){
  133. // 如果符合条件,把赠送的条码给删除(一次性)
  134. var index = activity.indexOf(goodsDetails.prodBarcode);
  135. activity.splice(index,1);
  136. // 设置赠品的单价
  137. goodsDetails.discountedPrice = goodsDetails.retailPrice;
  138. goodsDetails.actualPaymentAmount = 0;
  139. goodsDetails.activity = activityName;
  140. }
  141. }
  142. // 判断购物车里面是否有商品为赠品
  143. function shopCartContain(activity,goodsDetails,activityName){
  144. if(vm.goodsList && vm.goodsList.length > 0 ){
  145. for(var i = 0 ; i < vm.goodsList.length ; i ++){
  146. // 如果有商品为赠品,则把价格置位0并跳出循环
  147. if(activity.indexOf(vm.goodsList[i].prodBarcode) >= 0 && vm.goodsList[i].actualPaymentAmount != 0){
  148. // 如果符合条件,把赠送的条码给删除(一次性)
  149. var index = vm.mysy.indexOf(goodsDetails.prodBarcode);
  150. activity.splice(index,1);
  151. vm.goodsList[i].discountedPrice = vm.goodsList[i].retailPrice;
  152. vm.goodsList[i].actualPaymentAmount = 0;
  153. vm.goodsList[i].activity = activityName;
  154. vm.discountedPrice = vm.discountedPrice + vm.goodsList[i].retailPrice ;
  155. vm.actualPrice = vm.actualPrice - vm.goodsList[i].retailPrice ;
  156. break;
  157. }
  158. }
  159. }
  160. }
  161. // ======================= 组合价商品 ============================
  162. // 组合价商品
  163. function calculateGoodsByZhjsp(r){
  164. var barCode = r.goodsDetails.prodBarcode;
  165. if(r.map.zhjsp){
  166. // 将有组合的商品设置为1 ps:{"flag" => 0, "4005808550739" => 1, "4305615120454" => 0}
  167. vm.zhjsp.forEach(function(value,key,map){
  168. // 将组合价中组合的产品出现的次数+1
  169. value.forEach(function(v, k ,m){
  170. if(k === barCode)
  171. m.set(k,v+1);
  172. });
  173. var flag = 1;
  174. // 判断是否有商品成功组合
  175. value.forEach(function(v, k ,m){
  176. if(v === 0)
  177. flag = 0;
  178. });
  179. if(flag === 1){
  180. var combinationPrice = vm.combinationPrice.get(key);
  181. var barCodeArr = key.toString().split(":");
  182. // 扫码的商品条码 barCode
  183. for(var i = 0 ; i < barCodeArr.length ; i ++){
  184. var oldCode = barCodeArr[i];
  185. if(oldCode === barCode){
  186. continue;
  187. }
  188. if(vm.compareCombinationPrice.get(oldCode) && vm.compareCombinationPrice.get(oldCode) > combinationPrice){
  189. // 获取原组合关系
  190. var relationshipKey = vm.combinationRelationship.get(oldCode);
  191. // 将价格设置回原来的价格
  192. var keyArr = relationshipKey.toString().split(":");
  193. // 遍历原来的组合
  194. for(var j = 0 ; j < keyArr.length ; j ++){
  195. // 遍历购物车中原来的商品,替换价格
  196. for(var k = 0 ; k < vm.goodsList.length ; k ++){
  197. if(vm.goodsList[k].prodBarcode === keyArr[j] && vm.goodsList[k].activity == "组合价"){
  198. vm.discountedPrice = vm.discountedPrice - vm.goodsList[k].discountedPrice ;
  199. vm.actualPrice = vm.actualPrice + vm.goodsList[k].discountedPrice ;
  200. vm.goodsList[k].discountedPrice = 0 ; // 优惠价格
  201. vm.goodsList[k].actualPaymentAmount = vm.goodsList[k].retailPrice; // 实际支付价格
  202. vm.goodsList[k].isCombination = 0;
  203. vm.goodsList[k].activity = "";
  204. vm.compareCombinationPrice.delete(vm.goodsList[k].prodBarcode);
  205. vm.combinationRelationship.delete(vm.goodsList[k].prodBarcode);
  206. }
  207. }
  208. }
  209. }
  210. }
  211. for( var i = 0 ; i < barCodeArr.length ; i ++ ){
  212. // 如果是扫描的产品,直接退出,因为购物车中无该产品
  213. if(barCodeArr[i] == barCode){
  214. r.goodsDetails.isCombination = 1;
  215. r.goodsDetails.discountedPrice = r.goodsDetails.retailPrice - combinationPrice; // 优惠价格
  216. r.goodsDetails.actualPaymentAmount = combinationPrice; // 实际支付价格
  217. r.goodsDetails.activity = "组合价";
  218. vm.compareCombinationPrice.set(barCode,r.goodsDetails.actualPaymentAmount);
  219. vm.combinationRelationship.set(barCode,key);
  220. continue;
  221. }
  222. for(var j = 0 ; j < vm.goodsList.length ; j ++){
  223. if(vm.goodsList[j].prodBarcode === barCodeArr[i] && !vm.goodsList[j].isCombination){
  224. vm.goodsList[j].discountedPrice = vm.goodsList[j].retailPrice ; // 优惠价格
  225. vm.goodsList[j].actualPaymentAmount = 0; // 实际支付价格
  226. vm.goodsList[j].isCombination = 1;
  227. vm.goodsList[j].activity = "组合价";
  228. vm.discountedPrice = vm.discountedPrice + vm.goodsList[j].retailPrice ; // 总的优惠金额
  229. vm.actualPrice = vm.actualPrice - vm.goodsList[j].retailPrice ; // 总的实际支付金额
  230. vm.compareCombinationPrice.set(vm.goodsList[j].prodBarcode,vm.goodsList[j].actualPaymentAmount);
  231. vm.combinationRelationship.set(vm.goodsList[j].prodBarcode,barCode,key);
  232. break;
  233. }
  234. }
  235. }
  236. // 扣减
  237. var updateMap = map.get(key);
  238. updateMap.forEach(function(v, k ,m){
  239. m.set(k,v-1);
  240. });
  241. }
  242. });
  243. }
  244. console.log(vm.compareCombinationPrice);
  245. }
  246. let vm = new Vue({
  247. el: '#rrapp',
  248. data: {
  249. showList: true,
  250. goodsDetail:false,
  251. title: null,
  252. goods:{},
  253. sysNotice: {},
  254. goodsList:[],
  255. orderInfo:[],
  256. userInfo:{},
  257. //user信息绑定集合
  258. userInfoBinding: {},
  259. sysUserInfo:{},
  260. storeName:null,
  261. prodBarcode:null,
  262. sessionId:null,
  263. pickUpCodeList:[],
  264. goodsDetailList:[],
  265. orderEntity:{},
  266. orderProcessRecord:{},
  267. tax:0,
  268. currentOrderNo:null,
  269. customname:'',
  270. customidcard:'',
  271. machineCode:'',
  272. storeId:null,
  273. index:0,
  274. max:0,
  275. totalPrice:0,
  276. discountedPrice:0,
  277. actualPrice:0,
  278. ruleValidate: {
  279. name: [
  280. {required: true, message: '名称不能为空', trigger: 'blur'}
  281. ]
  282. },
  283. q: {
  284. name: ''
  285. },
  286. // 买一送一
  287. mysy: [],
  288. // 组合价
  289. zhjsp: new Map(),
  290. combinationPrice: new Map(), // 组合价商品的组合价
  291. compareCombinationPrice: new Map(), // 用于比较组合价
  292. combinationRelationship: new Map(), // 组合价格的组合关系
  293. // 满减
  294. mj: new Map(),
  295. accumulatedAmount: new Map(), // 累积金额(满减使用的)
  296. reduceMoney:0, // 满减金额
  297. showReduceMoney:0, // 用于展示的满减金额
  298. // 满赠
  299. mz: new Map(),
  300. accumulatedAmountForFullGift: new Map(), // 累积金额(满赠使用的)
  301. fullGiftCode:[],// 满赠商品条码
  302. // 优惠券
  303. coupons: new Map(),
  304. // 挂起订单集合
  305. pendingOrderMap: new Map(),
  306. // 挂起订单的key 在1~3循环
  307. pendingIndex:1,
  308. pendingOrderKeys:[],
  309. },
  310. methods: {
  311. query: function () {
  312. vm.storeId = sessionStorage.getItem("storeId");;
  313. var thisGoods = {};
  314. $.get("../goods/details/"+vm.prodBarcode+"/"+vm.storeId, function (r) {
  315. if (r.code == 0) {
  316. vm.prodBarcode = '';
  317. // r.goodsDetails.discountedPrice = 0;
  318. // r.goodsDetails.actualPaymentAmount = r.goodsDetails.retailPrice;
  319. calculateGoodsPrice(r);
  320. vm.goodsDetail = true;
  321. // thisGoods.name = r.goodsDetails.name;// thisGoods.primaryPicUrl = r.goodsDetails.primaryPicUrl; // thisGoods.retailPrice = r.goodsDetails.retailPrice;// thisGoods.specification = r.goodsDetails.specification; // thisGoods.prodBarcode = r.goodsDetails.prodBarcode;// thisGoods.stockNum = r.goodsDetails.stockNum;// thisGoods.goodsDesc = r.goodsDetails.goodsDesc;// thisGoods.sellVolume = 1;// thisGoods.id = vm.index++;
  322. r.goodsDetails.sellVolume = 1;
  323. r.goodsDetails.id = vm.index++;
  324. if(!vm.goodsList[vm.index]){
  325. vm.index = vm.max;
  326. }
  327. vm.max++;
  328. r.goodsDetails.goodsDesc = "";
  329. r.goodsDetails.discountedPrice = Math.round(r.goodsDetails.discountedPrice * 100) / 100;
  330. r.goodsDetails.actualPaymentAmount = Math.round(r.goodsDetails.actualPaymentAmount * 100) / 100;
  331. // r.goodsDetails.primaryPicUrl = "";
  332. var data = Object.assign({}, JSON.parse(JSON.stringify(r.goodsDetails)));
  333. vm.goodsList.push(data);
  334. vm.goods = r.goodsDetails;
  335. vm.totalPrice = (vm.totalPrice + r.goodsDetails.retailPrice);
  336. if(vm.reduceMoney > 0){
  337. vm.discountedPrice = vm.discountedPrice + r.goodsDetails.discountedPrice + vm.reduceMoney;
  338. vm.actualPrice = vm.actualPrice + r.goodsDetails.actualPaymentAmount - vm.reduceMoney;
  339. vm.showReduceMoney = vm.showReduceMoney + vm.reduceMoney;
  340. vm.reduceMoney = 0;
  341. }else{
  342. vm.discountedPrice = vm.discountedPrice + r.goodsDetails.discountedPrice ;
  343. vm.actualPrice = vm.actualPrice + r.goodsDetails.actualPaymentAmount ;
  344. }
  345. // 处理精度
  346. vm.totalPrice = Math.round(vm.totalPrice * 100) / 100;
  347. vm.discountedPrice = Math.round(vm.discountedPrice * 100) / 100;
  348. vm.actualPrice = Math.round(vm.actualPrice * 100) / 100;
  349. vm.showReduceMoney = Math.round(vm.showReduceMoney * 100) / 100;
  350. } else {
  351. alert(r.msg);
  352. }
  353. });
  354. },
  355. add:function(value){
  356. // 增加数量
  357. for(var i = 0 ; i < this.goodsList.length ; i++){
  358. if(this.goodsList[i].id == value){
  359. var goods = this.goodsList[i];
  360. goods.sellVolume = goods.sellVolume + 1;
  361. vm.totalPrice = vm.totalPrice + goods.retailPrice;
  362. break;
  363. }
  364. }
  365. },
  366. minus:function(value){
  367. // 减少数量
  368. for(var i = 0 ; i < this.goodsList.length ; i++){
  369. if(this.goodsList[i].id == value){
  370. var goods = this.goodsList[i];
  371. if(goods.sellVolume === 1){
  372. alert("数量至少为1个");
  373. return ;
  374. }
  375. goods.sellVolume = goods.sellVolume - 1;
  376. vm.totalPrice = vm.totalPrice - goods.retailPrice;
  377. break;
  378. }
  379. }
  380. },
  381. deleteItem:function(value){
  382. console.log(value);
  383. // 删除这条记录
  384. for(var i = 0 ; i < this.goodsList.length ; i++){
  385. if(this.goodsList[i].id == value){
  386. var goods = this.goodsList[i];
  387. vm.totalPrice = vm.totalPrice - (goods.retailPrice * goods.sellVolume);
  388. this.goodsList.splice(i,1);
  389. break;
  390. }
  391. }
  392. this.index = value;
  393. },
  394. clearGoodsList:function(){
  395. this.goodsList = [];
  396. vm.customClearData();
  397. },
  398. pendingOrder:function(){
  399. if(this.goodsList.length == 0){
  400. alert("购物车中没有商品");
  401. return;
  402. }
  403. console.log(vm.pendingOrderMap.size);
  404. if(vm.pendingOrderMap.size >= 3){
  405. alert("订单挂起最多支持3单");
  406. return;
  407. }
  408. vm.pendingOrderMap.set(vm.pendingIndex,this.goodsList);
  409. vm.pendingOrderKeys.push(vm.pendingIndex);
  410. var newIndex = ++vm.pendingIndex;
  411. vm.pendingIndex = newIndex > 3?1: newIndex;
  412. vm.clearGoodsList();
  413. },
  414. toResumePending:function(){
  415. if(vm.pendingOrderMap.size == 0){
  416. alert("当前没有挂起的订单");
  417. return ;
  418. }
  419. $('#pendignOrderModal').modal('show')
  420. },
  421. resumePending:function(key){
  422. if(vm.pendingOrderMap.size == 0){
  423. alert("当前没有挂起的订单");
  424. return ;
  425. }
  426. if(vm.goodsList.length > 0){
  427. alert("购物车中已有商品,不允许恢复!")
  428. return ;
  429. }
  430. vm.goodsList = vm.pendingOrderMap.get(key);
  431. // 清除恢复的数据
  432. vm.pendingOrderMap.delete(key);
  433. removeByValue(vm.pendingOrderKeys,key);
  434. $('#pendignOrderModal').modal('hide')
  435. },
  436. toOrderSubmit:function(){
  437. if(this.goodsList.length == 0){
  438. alert("请选择商品");
  439. return;
  440. }
  441. $('#myModal').modal('show')
  442. // 每次点击提交订单的时候清空姓名和身份证信息和手机号
  443. vm.$refs.customName.value = "";
  444. vm.$refs.customIDCard.value = "";
  445. vm.$refs.customPhone.value = "";
  446. if(vm.$refs.couponSn)
  447. vm.$refs.couponSn.value = "";
  448. this.userInfo.couponSn = "";
  449. },
  450. submitOrder:function(){
  451. $('#payCode').unbind('keydown').keydown(function(event){});
  452. vm.machineCode = sessionStorage.getItem("machineCode");
  453. console.log(vm.machineCode);
  454. var param = {'userInfo':vm.userInfo,'payCode':this.$refs.payCode.currentValue,'goodsList':vm.goodsList,'sessionId':vm.sessionId,'machineCode':vm.machineCode};
  455. console.log(JSON.stringify(param));
  456. this.$refs.payCode.currentValue = '';
  457. $.ajax({
  458. type: "POST",
  459. url: "../order/orderConfirm",
  460. contentType: "application/json",
  461. data: JSON.stringify(param),
  462. success: function (r) {
  463. console.log(r);
  464. if (r.code == 0) {
  465. if (r.resultObj != null) {
  466. $(".form-group input[type=text]").each(function(){
  467. this.value = '';
  468. })
  469. // 打印取货码小票
  470. var content = getPrintContent(r.resultObj);
  471. printArea2(content);
  472. vm.goodsList = [];
  473. vm.customname = '' ;
  474. vm.customidcard = '';
  475. vm.customClearData();
  476. // alert('打印小票完成');
  477. }else{
  478. // alert("打印小票失败");
  479. }
  480. } else {
  481. alert(r.msg);
  482. }
  483. }
  484. });
  485. },customClearData: function(){
  486. vm.totalPrice = 0;
  487. vm.discountedPrice = 0;
  488. vm.actualPrice = 0;
  489. // 买一送一
  490. vm.mysy = [];
  491. // 组合价
  492. vm.zhjsp = new Map();
  493. vm.combinationPrice = new Map(); // 组合价商品的组合价
  494. // 满减
  495. vm.mj = new Map();
  496. vm.accumulatedAmount = new Map();// 累积金额(满减使用的)
  497. vm.reduceMoney = 0; // 满减金额
  498. vm.showReduceMoney = 0; // 用于展示的满减金额
  499. // 满赠
  500. vm.mz = new Map();
  501. vm.accumulatedAmountForFullGift = new Map(); // 累积金额(满赠使用的)
  502. vm.fullGiftCode = [];// 满赠商品条码
  503. // 优惠券
  504. vm.coupons = new Map();
  505. },
  506. queryIDCardInfo: function(){
  507. $.get("../order/queryIDCardInfo/"+vm.$refs.customPhone.value, function (r){
  508. if(r.code === 0){
  509. var data = r.userEntity;
  510. vm.$refs.customName.value = data.username;
  511. vm.$refs.customIDCard.value = data.idNo;
  512. }else{
  513. alert(r.msg);
  514. }
  515. });
  516. },
  517. getIDCardInfo: function(){
  518. $.post("http://127.0.0.1:8000/idcard/read", function (r){
  519. // var dataR = JSON.parse(r);
  520. // console.log(dataR)
  521. console.log(r)
  522. console.log(r.code)
  523. if(r.code == "0"){
  524. // if(!r.info){
  525. // alert("请连接设备或设备有问题,请联系管理员!");
  526. // return ;
  527. // }
  528. // var data = JSON.parse(r.info);
  529. // if(data.code=="0"){
  530. vm.$refs.customName.value = r.rows[0].data.name;
  531. vm.$refs.customIDCard.value = r.rows[0].data.id_no;
  532. // }else{
  533. // alert(data.msg);
  534. // return ;
  535. // }
  536. }else if(r.code=="-1"){
  537. alert(r.msg);
  538. return;
  539. }else{
  540. alert("请连接设备或设备有问题,请联系管理员!");
  541. }
  542. });
  543. },
  544. customPhoneBlur:function (){
  545. let customPhone = this.$refs.customPhone.value;
  546. if(customPhone){
  547. for(let key in this.userInfoBinding){
  548. if(customPhone == key){
  549. let userInfoBindingValue = this.userInfoBinding[key];
  550. this.$refs.customName.value = userInfoBindingValue.substring(0, userInfoBindingValue.length-18);
  551. this.$refs.customIDCard.value = userInfoBindingValue.substring(userInfoBindingValue.length-18);
  552. break;
  553. }
  554. }
  555. }
  556. },
  557. submitCustomInfo:function(){
  558. this.userInfo.customName = this.$refs.customName.value ;
  559. this.userInfo.customIDCard = this.$refs.customIDCard.value ;
  560. this.userInfo.customPhone = this.$refs.customPhone.value;
  561. if(this.$refs.couponSn)
  562. this.userInfo.couponSn = this.$refs.couponSn.value;
  563. 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)$/;
  564. if(!this.userInfo.customName){
  565. alert("姓名不能为空!");
  566. return ;
  567. }
  568. if(!idcardReg.test(this.userInfo.customIDCard)){
  569. alert("请输入正确的身份证号");
  570. return ;
  571. }
  572. if(!(/^1[3456789]\d{9}$/.test(this.userInfo.customPhone))){
  573. alert("手机号码有误,请重填");
  574. return ;
  575. }
  576. //将手机号与姓名身份证号进行绑定,下次填写手机号即可
  577. let userInfoBindingKey = this.userInfo.customPhone;
  578. let userInfoBindingValue = this.userInfo.customName+this.userInfo.customIDCard;
  579. this.userInfoBinding[userInfoBindingKey] = userInfoBindingValue;
  580. console.log(this.userInfo.couponSn);
  581. if(this.userInfo.couponSn && this.userInfo.couponSn != ""){
  582. var coupon = vm.coupons.get(this.userInfo.couponSn);
  583. if(coupon == null){
  584. alert("请输入正确的优惠券码");
  585. return ;
  586. }
  587. }
  588. $("#Send").attr("data-dismiss","modal");
  589. $('#payModal').modal('show');
  590. $("#payCode").keydown(function(e){
  591. if(e.keyCode==13){
  592. $("#submitOrder").click();
  593. event.preventDefault();
  594. }
  595. });
  596. $('body').on('hidden.bs.modal', '.modal', function () {
  597. $(this).removeData();
  598. });
  599. },
  600. queryOrderDetail:function(orderSn){
  601. var storeId = sessionStorage.getItem("storeId");;
  602. $.get("../order/orderDetail/"+orderSn, function (r) {
  603. if (r.code == 0) {
  604. vm.orderProcessRecord = r.resultObj.orderProcessRecordEntity;
  605. vm.orderEntity = r.resultObj.orderEntity;
  606. vm.goodsDetailList = r.resultObj.goodsList;
  607. vm.currentOrderNo = r.resultObj.orderEntity.id;
  608. vm.tax = r.resultObj.tax;
  609. if(vm.orderProcessRecord.eleOrderStartTime){
  610. vm.orderProcessRecord.eleOrderStartTime = parsedate(vm.orderProcessRecord.eleOrderStartTime);
  611. }
  612. if(vm.orderProcessRecord.paymentStartTime){
  613. vm.orderProcessRecord.paymentStartTime = parsedate(vm.orderProcessRecord.paymentStartTime);
  614. }
  615. if(vm.orderProcessRecord.waybillStartTime){
  616. vm.orderProcessRecord.waybillStartTime = parsedate(vm.orderProcessRecord.waybillStartTime);
  617. }
  618. if(vm.orderProcessRecord.customsSuccTime){
  619. vm.orderProcessRecord.customsSuccTime = parsedate(vm.orderProcessRecord.customsSuccTime);
  620. }
  621. if(vm.orderProcessRecord.addOrderStartTime){
  622. vm.orderProcessRecord.addOrderStartTime = parsedate(vm.orderProcessRecord.addOrderStartTime);
  623. }
  624. }
  625. });
  626. },
  627. verification:function(){
  628. if(vm.orderProcessRecord.isCustomsSend != 1){
  629. alert("请等待清关完成");
  630. return ;
  631. }
  632. confirm('确认核销吗?', function () {
  633. $.ajax({
  634. type: "POST",
  635. url: "../order/printMsgAndChangeCode",
  636. contentType: "application/json",
  637. data: JSON.stringify({'id':vm.currentOrderNo,'sessionId':vm.sessionId}),
  638. success: function (r) {
  639. if (r.ticket != null) {
  640. // printArea(r.ticket);
  641. var content = getPrintContentOrder(r.ticket);
  642. printArea(content);
  643. alert('打印小票完成');
  644. }else{
  645. alert("打印小票失败");
  646. }
  647. }
  648. });
  649. })
  650. },
  651. refundOrder:function(){
  652. confirm('确认退款吗?', function () {
  653. $.ajax({
  654. type: "POST",
  655. url: "../order/orderRefund",
  656. contentType: "application/json",
  657. data: JSON.stringify({'orderId':9000,'sessionId':vm.sessionId}),
  658. success: function (r) {
  659. if (r.code == 0) {
  660. alert("退款成功")
  661. }else{
  662. alert("退款失败,请联系管理员");
  663. }
  664. }
  665. });
  666. })
  667. },
  668. retrySendOrder:function(){
  669. },
  670. getInfo: function (id) {
  671. $.get("../sys/notice/info/" + id, function (r) {
  672. vm.sysNotice = r.sysNotice;
  673. });
  674. },
  675. reload: function (event) {
  676. vm.showList = false;
  677. vm.showViewList = true;
  678. vm.showSaveSupplierGoods = true;
  679. var page = $("#jqGrid").jqGrid('getGridParam', 'page');
  680. $("#jqGrid").jqGrid('setGridParam', {
  681. postData: {
  682. storeId: vm.q.storeId,
  683. goodsName: vm.q.goodsName,
  684. goodsSn: vm.q.goodsSn,
  685. productSn: vm.q.productSn, category: vm.q.category, categoryTwo: vm.q.categoryTwo, goodsBizType:vm.q.goodsBizType,
  686. thirdPartyMerchCode: vm.q.thirdPartyMerchCode
  687. },
  688. page: page
  689. }).trigger("reloadGrid");
  690. vm.handleReset('formValidate');
  691. },
  692. handleSubmit: function (name) {
  693. handleSubmitValidate(this, name, function () {
  694. vm.saveOrUpdate()
  695. });
  696. },
  697. handleReset: function (name) {
  698. handleResetForm(this, name);
  699. },
  700. logout: function () {
  701. confirm('注:您确定要安全退出本次登录吗?', function () {
  702. dialogLoading(true);
  703. setTimeout(function () {
  704. toUrl('../logout?_' + $.now());
  705. }, 500);
  706. });
  707. }
  708. }
  709. });
  710. function getPrintContent(ticket) {
  711. var content = "<div style=\"width: 250px;font-family: 微软雅黑;font-size: 15px;\">";
  712. //小票头
  713. content += "<div style=\"text-align: center;width: 100%;font-weight:bold;font-size: 15px;\">";
  714. content += ticket.shopName
  715. content += "</div>";
  716. content += "<div style=\"width: 100%;overflow:hidden;white-space: nowrap;\">--------------------------------------------------</div>";
  717. content += "<div style=\"width: 100%;margin:5px 0px;\">";
  718. /*content += "收银机号:" + ticket.salesNo;
  719. content += "</div>";
  720. content += "<div style=\"width: 100%;\">";*/
  721. content += "收银员:" + ticket.userName;
  722. content += "</div>";
  723. content += "<div style=\"width: 100%;font-size: 30px;margin:15px 0 10px 5px;\">";
  724. content += "取货码:" + ticket.code;
  725. content += "</div>";
  726. content += "<div style=\"width: 100%;margin:5px 0px;\">";
  727. content += "订单编号:" + ticket.orderNo;
  728. content += "</div>";
  729. content += "<div style=\"width: 100%;margin:5px 0px;\">";
  730. content += "打印日期:" + ticket.time;
  731. content += "</div>";
  732. content += "<div style=\"width: 100%;margin:5px 0px;font-size: 13px;\">";
  733. content += "该取货单号只有当天有效"
  734. content += "</div>";
  735. return content;
  736. }
  737. var printAreaCount = 0;
  738. function printArea(content) {
  739. var idPrefix = "printArea_";
  740. removePrintArea(idPrefix + printAreaCount);
  741. printAreaCount++;
  742. var iframeId = idPrefix + printAreaCount;
  743. var iframeStyle = 'width:0px;height:0px;left:0px;top:0px;';
  744. iframe = document.createElement('IFRAME');
  745. $(iframe).attr({
  746. style: iframeStyle,
  747. id: iframeId
  748. });
  749. document.body.appendChild(iframe);
  750. var doc = iframe.contentWindow.document;
  751. doc.open();
  752. //$(document).find("link").filter(function () {
  753. //return $(this).attr("rel").toLowerCase() == "stylesheet";
  754. //}).each(
  755. //function () {
  756. //doc.write('<link type="text/css" rel="stylesheet" href="'
  757. //+ $(this).attr("href") + '" >');
  758. //});
  759. doc.write('<div class="">' + content
  760. + '</div>');
  761. doc.close();
  762. var frameWindow = iframe.contentWindow;
  763. frameWindow.close();
  764. frameWindow.focus();
  765. // frameWindow.print();
  766. frameWindow.print();
  767. }
  768. function printArea2(content) {
  769. var idPrefix = "printArea_";
  770. removePrintArea(idPrefix + printAreaCount);
  771. printAreaCount++;
  772. var iframeId = idPrefix + printAreaCount;
  773. var iframeStyle = 'width:0px;height:0px;left:0px;top:0px;';
  774. iframe = document.createElement('IFRAME');
  775. $(iframe).attr({
  776. style: iframeStyle,
  777. id: iframeId
  778. });
  779. document.body.appendChild(iframe);
  780. var doc = iframe.contentWindow.document;
  781. doc.open();
  782. //$(document).find("link").filter(function () {
  783. //return $(this).attr("rel").toLowerCase() == "stylesheet";
  784. //}).each(
  785. //function () {
  786. //doc.write('<link type="text/css" rel="stylesheet" href="'
  787. //+ $(this).attr("href") + '" >');
  788. //});
  789. doc.write('<div class="">' + content
  790. + '</div>');
  791. doc.close();
  792. var frameWindow = iframe.contentWindow;
  793. frameWindow.focus();
  794. frameWindow.print();
  795. frameWindow.print();
  796. frameWindow.close();
  797. }
  798. var removePrintArea = function (id) {
  799. $("iframe#" + id).remove();
  800. };
  801. var webSocket;
  802. function openWebSocket() {
  803. var storeId = sessionStorage.getItem("storeId");
  804. if ("WebSocket" in window) {
  805. console.log("当前浏览器支持WebSocket");
  806. //实现化WebSocket对象
  807. //指定要连接的服务器地址与端口建立连接
  808. //注意ws、wss使用不同的端口。我使用自签名的证书测试,
  809. //无法使用wss,浏览器打开WebSocket时报错
  810. //ws对应http、wss对应https。
  811. // webSocket = new WebSocket("ws://183.62.225.124:8080/ws/server/"+storeId);
  812. webSocket = new WebSocket("ws://127.0.0.1:8080//ws/server/"+storeId);
  813. // webSocket = new WebSocket("wss://cb.k1net.cn/ws/server/"+storeId);
  814. if (webSocket.readyState === webSocket.CONNECTING) {
  815. console.log('1.连接正在打开......');
  816. }
  817. // ---------- WebSocket 对象注册事件 ----------
  818. //连接打开事件
  819. webSocket.onopen = function () {
  820. if (webSocket.readyState === webSocket.OPEN) {
  821. console.log('2.连接已打开');
  822. }
  823. console.log('2.向服务端发送测试消息......');
  824. // webSocket.send("2.client发测试消息:Client sent test msg。");
  825. };
  826. //收到消息事件
  827. webSocket.onmessage = function (msg) {
  828. var data = Object.assign({}, JSON.parse(msg.data));
  829. console.log('3.接收到服务端信息......data:'+data);
  830. vm.sessionId = data.sessionId;
  831. vm.pickUpCodeList = [];
  832. if(data.pickUpCodeList.length > 0){
  833. for(var i = 0 ; i < data.pickUpCodeList.length ; i++){
  834. console.log(data.pickUpCodeList[i].storeId);
  835. if(data.pickUpCodeList[i].storeId === storeId){
  836. vm.pickUpCodeList.push(data.pickUpCodeList[i]);
  837. }
  838. }
  839. }
  840. // vm.pickUpCodeList = vm.pickUpCodeList.concat(data.pickUpCodeList);
  841. // console.log(vm.pickUpCodeList);
  842. // webSocket.send("2.client发测试消息:Client sent test msg。");
  843. };
  844. //连接关闭事件
  845. webSocket.onclose = function () {
  846. if (!webSocket) {
  847. console.log('4.Socket连接已关闭');
  848. }
  849. };
  850. //发生了错误事件
  851. webSocket.onerror = function () {
  852. console.log("5.Socket发生了错误");
  853. }
  854. } else {
  855. console.log("当前浏览器不支持WebSocket");
  856. return false;
  857. }
  858. }
  859. function sendMessage() {
  860. if(webSocket && webSocket.readyState === webSocket.OPEN) {
  861. webSocket.send("client manual send message.")
  862. } else {
  863. console.log('6.未创建WebSocket连接');
  864. }
  865. }
  866. function closeWebSocket() {
  867. if (webSocket != null) {
  868. webSocket.close();
  869. webSocket = null;
  870. }
  871. console.log("关闭WebSocket");
  872. }
  873. //窗口关闭时,关闭连接
  874. window.unload = function () {
  875. webSocket.close();
  876. };
  877. function parsedate(value){
  878. var date = new Date(value);
  879. var year = date.getFullYear();
  880. var month = date.getMonth()+1; //月份+1
  881. var day = date.getDate();
  882. var hour = date.getHours();
  883. var minutes = date.getMinutes();
  884. var second = date.getSeconds();
  885. return year+"-"+month+"-"+day+" "+hour+":"+minutes +":"+second;
  886. }
  887. function getPrintContentOrder(ticket) {
  888. var content = "<div style=\"width: 250px;font-family: 微软雅黑;font-size: 8px;\">";
  889. //小票头
  890. content += "<div style=\"text-align: center;width: 100%;font-weight:bold;font-size: 13px;\">";
  891. content += ticket.ticketHead.title;
  892. content += "</div>";
  893. /*content += "<div style=\"width: 100%;\">";
  894. content += "会员:" + ticket.ticketHead.memberId;
  895. content += "</div>";*/
  896. content += "<div style=\"width: 100%;\">";
  897. content += "订单号:" + ticket.ticketHead.orderId;
  898. content += "</div>";
  899. content += "<div style=\"width: 100%;\">";
  900. content += "交易时间:" + ticket.ticketHead.tradeTime;
  901. content += "</div>";
  902. content += "<div style=\"width: 100%;overflow:hidden;white-space: nowrap;\">--------------------------------------------------</div>";
  903. //商品信息
  904. content += "<table style=\"width: 100%;\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
  905. content += "<tr>";
  906. content += "<td style=\"width: 50%;text-align: left;font-size: 10px;font-weight: bold;\">商品名称</td>";
  907. content += "<td style=\"width: 17%;text-align: right;font-size: 10px;font-weight: bold;\">单价</td>";
  908. content += "<td style=\"width: 15%;text-align: right;font-size: 10px;font-weight: bold;\">数量</td>";
  909. content += "<td style=\"width: 18%;text-align: right;font-size: 10px;font-weight: bold;\">小计</td>";
  910. content += "</tr>";
  911. content += "</table>";
  912. content += "<div style=\"width: 100%;overflow:hidden;white-space: nowrap;\">--------------------------------------------------</div>";
  913. content += "<table style=\"width: 100%;\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
  914. for (var i=0;i< ticket.goods.length;i++){
  915. content += "<tr>";
  916. content += "<td style=\"width: 50%;text-align: left;font-size: 8px;padding-top: 8px;\">";
  917. content += "<table style=\"width: 100%;\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
  918. content += "<tr>";
  919. content += "<td style=\"text-align: left;font-size: 8px;vertical-align:top;\">#</td>";
  920. content += "<td style=\"text-align: left;font-size: 8px;\">" + ticket.goods[i].gname + "</td>";
  921. content += "</tr>";
  922. content += "</table>";
  923. content += "</td>";
  924. content += "<td style=\"width: 17%;text-align: right;font-size: 8px;vertical-align:bottom;padding-top: 8px;\">" + ticket.goods[i].uprice + "</td>";
  925. content += "<td style=\"width: 15%;text-align: right;font-size: 8px;vertical-align:bottom;padding-top: 8px;\">" + ticket.goods[i].num + "</td>";
  926. content += "<td style=\"width: 18%;text-align: right;font-size: 8px;vertical-align:bottom;padding-top: 8px;\">" + ticket.goods[i].subtotal + "元</td>";
  927. content += "</tr>";
  928. }
  929. content += "</table>";
  930. content += "<div style=\"width: 100%;overflow:hidden;white-space: nowrap;\">--------------------------------------------------</div>";
  931. //收银信息
  932. content += "<div style=\"width: 100%;\">";
  933. content += "<span style=\"float: left;width: 50%;text-align: left;\">商品合计:</span>";
  934. content += "<span style=\"float: left;width: 17%;text-align: left;\">" + ticket.cashInfo.goodsTotal + "件</span>";
  935. content += "<span style=\"float: right;width: 33%;text-align: right;\">" + ticket.cashInfo.total + "元</span>";
  936. content += "</div>";
  937. content += "<div style=\"width: 100%;\">";
  938. content += "<span style=\"float: left;width: 50%;text-align: left;\">实收:</span>";
  939. content += "<span style=\"float: right;width: 50%;text-align: right;\">" + ticket.cashInfo.receipts + "元</span>";
  940. content += "</div>";
  941. content += "<div style=\"width: 100%;\">";
  942. content += "<span style=\"float: left;width: 50%;text-align: left;\">找零:</span>";
  943. content += "<span style=\"float: right;width: 50%;text-align: right;\">" + ticket.cashInfo.oddChange + "元</span>";
  944. content += "</div>";
  945. content += "<div style=\"width: 100%;\">";
  946. content += "<span style=\"float: left;width: 50%;text-align: left;\">优惠券:</span>";
  947. content += "<span style=\"float: right;width: 50%;text-align: right;\">" + ticket.cashInfo.coupon + "元</span>";
  948. content += "</div>";
  949. content += "<div style=\"width: 100%;\">";
  950. content += "<span style=\"float: left;width: 50%;text-align: left;\">运费:</span>";
  951. content += "<span style=\"float: right;width: 50%;text-align: right;\">" + ticket.cashInfo.freight + "元</span>";
  952. content += "</div>";
  953. content += "<div style=\"width: 100%;\">";
  954. content += "<span style=\"float: left;width: 50%;text-align: left;\">支付渠道:</span>";
  955. content += "<span style=\"float: right;width: 50%;text-align: right;\">" + ticket.cashInfo.paymentMode + "</span>";
  956. content += "</div>";
  957. content += "<div style=\"width: 100%;overflow:hidden;white-space: nowrap;\">--------------------------------------------------</div>";
  958. //海关清单信息
  959. content += "<div style=\"width: 100%;\">";
  960. content += "订单号:" + ticket.cusListing.orderId;
  961. content += "</div>";
  962. content += "<div style=\"width: 100%;\">";
  963. content += "运单编号:" + ticket.cusListing.waybillId;
  964. content += "</div>";
  965. content += "<div style=\"width: 100%;\">";
  966. content += "海关清单号:" + ticket.cusListing.invtNo;
  967. content += "</div>";
  968. content += "<div style=\"width: 100%;\">";
  969. content += "收货人:" + ticket.cusListing.consignee;
  970. content += "</div>";
  971. content += "<div style=\"width: 100%;\">";
  972. content += "收货人电话:" + ticket.cusListing.consigneeTel;
  973. content += "</div>";
  974. content += "<div style=\"width: 100%;\">";
  975. content += "始发地:" + ticket.cusListing.originAddress;
  976. content += "</div>";
  977. content += "<div style=\"width: 100%;\">";
  978. content += "交货地:" + ticket.cusListing.deliveryAddress;
  979. content += "</div>";
  980. content += "<div style=\"width: 100%;overflow:hidden;white-space: nowrap;\">--------------------------------------------------</div>";
  981. content += "<div style=\"width: 100%;\">";
  982. content += ticket.ticketFoot.summary;
  983. content += "</div>";
  984. content += "<div style=\"width: 100%;\">";
  985. content += "客服电话:" + ticket.ticketFoot.serviceTel;
  986. content += "</div>";
  987. content += "<div style=\"width: 100%;\">";
  988. content += "网址:" + ticket.ticketFoot.url1;
  989. content += "</div>";
  990. content += "<div style=\"width: 100%;\">";
  991. content += ticket.ticketFoot.welcome;
  992. content += "</div>";
  993. return content;
  994. }
  995. function queryAssistantInfo(){
  996. $.get("../sys/user/info", function (r) {
  997. if(r.code == 0){
  998. vm.sysUserInfo = r.user;
  999. $.get("../store/getStoresByMerch?merchSn="+r.user.merchSn+"&_=1590374349985",function(result){
  1000. if(result.code == 0){
  1001. for(var i = 0 ;i < result.list.length; i++){
  1002. if(result.list[i].id == r.user.storeId){
  1003. vm.storeName = result.list[i].storeName;
  1004. break;
  1005. }
  1006. }
  1007. }
  1008. });
  1009. }
  1010. });
  1011. }
  1012. function removeByValue(arr, val) {
  1013. var index = arr.indexOf(val);
  1014. if (index > -1) {
  1015. arr.splice(index, 1);
  1016. }
  1017. }