index.blade.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  1. @extends('layouts.app')
  2. @section('content')
  3. <div id="nav2">
  4. @component('store.menu')@endcomponent
  5. @component('store.blindReceive.menu')@endcomponent
  6. </div>
  7. <div class="container">
  8. <audio src="{{asset('sound/warning_otherBarcode.mp3')}}" controls="controls" preload id="soundWarning" hidden>
  9. </audio>
  10. <audio src="{{asset('sound/ding.mp3')}}" controls="controls" preload id="soundDing" hidden>
  11. </audio>
  12. <div class="row mt-2">
  13. <div class="col-12" id="scanColumn">
  14. <div class="card" :class="borderByMode">
  15. <div class="card-body">
  16. <div class="row">
  17. <div class="col-12">
  18. <p class="text-muted" style="font-size: 0.5em" v-if="inputMode=='regular'">常规:可输入效期,相同条码记录不会合并</p>
  19. <p class="text-muted" style="font-size: 0.5em" v-if="inputMode=='increasing'">逐一扫描:处理单一重复商品,每扫一次对应隔口总数量自动递增,扫到不同条码会提示</p>
  20. <p class="text-muted" style="font-size: 0.5em" v-if="inputMode=='multiIncreasing'">边扫边分:处理多种商品,自动将扫到的不同条码数量递增到各自隔口号</p>
  21. <ul class="nav nav-tabs mb-4 mt-n3">
  22. <li class="nav-item"><a href="#" class="nav-link" :class="inputMode=='regular'?'active':''"
  23. @click="inputMode='regular';changeToManualInputAmount();cleanInputs();inputting.fromIncreasing=false">常规</a></li>
  24. <li class="nav-item"><a href="#" class="nav-link" :class="inputMode=='increasing'?'active':''"
  25. @click="inputMode='increasing';changeToScanInputAmount();cleanInputs();inputting.fromIncreasing=true;">逐一扫描</a></li>
  26. <li class="nav-item"><a href="#" class="nav-link" :class="inputMode=='multiIncreasing'?'active':''"
  27. @click="inputMode='multiIncreasing';changeToScanInputAmount();cleanInputs();inputting.fromIncreasing=true">边扫边分</a></li>
  28. </ul>
  29. </div>
  30. <div class="col-6">
  31. <div v-if="inputMode=='regular'">
  32. <div class="btn btn-sm btn-outline-primary"
  33. v-if="!isManualInputtingBarcode" @click="changeToManualInputBarcode">手动输入</div>
  34. <div class="btn btn-sm btn-outline-danger"
  35. @click="changeToScanInputBarcode" v-if="isManualInputtingBarcode">扫描输入</div>
  36. </div>
  37. <input type="text" id="barcode" class="form-control" :disabled="status.barcodeDisable" placeholder="扫入条码" @focusin="focusOutDocument" @focusout="focusDocument" v-model="inputting.barcode">
  38. <div v-if="inputMode=='regular'">
  39. <div class="card-title">
  40. 生产日期:
  41. </div>
  42. <input type="date" class="form-control mb-2" v-model="inputting.produce_date" @focusin="focusOutDocument" @focusout="focusDocument" @keyup="oninputEnter">
  43. </div>
  44. <div v-if="inputMode=='regular'">
  45. <div class="card-title">
  46. 失效日期:
  47. </div>
  48. <input type="date" class="form-control mb-2" v-model="inputting.valid_date" @focusin="focusOutDocument" @focusout="focusDocument" @keyup="oninputEnter">
  49. </div>
  50. <div v-if="inputMode=='regular'" class="mt-0">
  51. <div class="card-title">
  52. 唯一码:
  53. </div>
  54. <input type="text" class="form-control mb-2" v-model="inputting.unique_code" @focusin="focusOutDocument" @focusout="focusDocument" @keyup="oninputEnter">
  55. </div>
  56. </div>
  57. <div class="col-6">
  58. <div class="card-title" id="amountLabel">
  59. 手动输入数量:
  60. </div>
  61. <div class="input-group mt-n2 mb-2">
  62. <input type="number" id="amount" class="form-control" placeholder="" :disabled="status.amountDisable"
  63. v-model="inputting.amount" @focusin="focusOutDocument" @focusout="focusDocument" @keyup="oninputEnter"
  64. style='height: 40px;font-size: 1.6em;color:blue;font-weight: bolder;padding: 3px;text-align: center'>
  65. </div>
  66. <div class="card-title">
  67. 格口号:
  68. </div>
  69. <input type="number" id="bin" class="form-control mt-n2 mb-2"
  70. v-model="inputting.bin"
  71. :disabled="status.binDisable" @focusin="focusOutDocument" @focusout="focusDocument" @keyup="oninputEnter"
  72. style='height: 100px;font-size: 5em;color:red;font-weight: bolder;padding: 3px;text-align: center'>
  73. <div v-if="inputMode=='regular'" class="mt-4">
  74. <div class="card-title">
  75. 批次号:
  76. </div>
  77. <input type="text" class="form-control mb-2" v-model="inputting.batch_number" @focusin="focusOutDocument" @focusout="focusDocument" @keyup="oninputEnter">
  78. </div>
  79. </div>
  80. <div class="col-12" v-if="commitButtonVisible && inputMode=='regular'" >
  81. <button class="btn btn-success btn form-control" @click="commitGoods">确定</button>
  82. </div>
  83. </div>
  84. <p class="card-text text-muted mt-3 mb-n3 text-center">
  85. 已完成:
  86. </p>
  87. <hr>
  88. <table class="table table-sm table-striped" v-if="goodses.length>0">
  89. <tr>
  90. <th>隔口号</th>
  91. <th>数量</th>
  92. <th>条码</th>
  93. <th>生产日期</th>
  94. <th>失效日期</th>
  95. <th>批次号</th>
  96. <th>唯一码</th>
  97. <th>操作</th>
  98. </tr>
  99. <tr v-for="goods in goodses">
  100. <td>@{{ goods.bin }}</td>
  101. <td>@{{ goods.amount }}</td>
  102. <td>@{{ goods.barcode }}</td>
  103. <td>@{{ goods.produce_date }}</td>
  104. <td>@{{ goods.valid_date }}</td>
  105. <td>@{{ goods.batch_number }}</td>
  106. <td>@{{ goods.unique_code }}</td>
  107. <td><button class="btn btn-outline-danger btn-sm" @click="removeGoods($event,goods.barcode)">删</button></td>
  108. </tr>
  109. </table>
  110. <hr>
  111. <span class="btn btn-outline-dark btn form-control" style="cursor: pointer" @click="submitExcelData">结束并生成Excel</span>
  112. </div>
  113. </div>
  114. </div>
  115. </div>
  116. </div>
  117. @endsection
  118. @section('lastScript')
  119. <script>
  120. new Vue({
  121. el: '#app',
  122. data:{
  123. focusing:'document',
  124. commitButtonVisible:false,
  125. isManualInputtingBarcode:false,
  126. isManualInputtingAmount:true,
  127. lastScannedBarcode:'',
  128. inputMode:'regular',//regular,increasing,multiIncreasing
  129. inputting:{
  130. barcode:'',amount:'',bin:'',produce_date:'',valid_date:'',batch_number:'',fromIncreasing:false,unique_code:''
  131. },
  132. status:{
  133. scanEndInputted:false,binDisable:false,barcodeDisable:true,amountDisable:false,
  134. },
  135. goodses:[],//{barcode,amount,bin,produce_date,valid_date,batch_number}
  136. },
  137. mounted() {
  138. this.scanListening();
  139. },
  140. methods: {
  141. changeToManualInputAmount:function(){
  142. this.status.amountDisable=false;
  143. this.isManualInputtingAmount=true;
  144. $('#amountLabel').text('输入数量:');
  145. // $('#amount').attr('placeholder','数字');
  146. },
  147. changeToScanInputAmount:function(){
  148. this.status.amountDisable=true;
  149. this.isManualInputtingAmount=false;
  150. $('#amountLabel').text('自动扫入数量:');
  151. // $('#amount').attr('placeholder','自动');
  152. },
  153. changeToManualInputBarcode:function(){
  154. this.status.barcodeDisable=false;
  155. this.isManualInputtingBarcode=true;
  156. $('#barcode').attr('placeholder','手工输入条码');
  157. },
  158. changeToScanInputBarcode:function(){
  159. let data = this;
  160. this.isManualInputtingBarcode=false;
  161. this.inputting.barcode='';
  162. let $barcode = $('#barcode');
  163. this.status.barcodeDisable=false;
  164. setTimeout(function () {
  165. $barcode.focus();
  166. data.status.barcodeDisable=true;
  167. },20);
  168. $barcode.attr('placeholder','扫入条码');
  169. },
  170. oninputEnter:function(e){
  171. if (e.key === 'Enter') {
  172. this.focusDocument();
  173. }
  174. },
  175. focusDocument: function () {
  176. this.focusing = 'document';
  177. this.showCommitButton();
  178. },
  179. focusOutDocument: function () {
  180. this.focusing = '';
  181. this.autoFillBin();
  182. },
  183. scanListening: function () {
  184. let data = this;
  185. $(document).on('keypress', function (e) {
  186. if(data.focusing!=='document'){return}
  187. if(data.isManualInputtingBarcode){return}
  188. if (e.keyCode !== 13) {
  189. if(data.status.scanEndInputted){
  190. data.lastScannedBarcode=data.inputting.barcode;
  191. data.inputting.barcode='';
  192. data.status.scanEndInputted=false;
  193. }
  194. data.inputting.barcode += String.fromCharCode(e.keyCode);
  195. } else {
  196. if(data.inputting.barcode.length<=1){
  197. window.tempTip.setDuration(4500);
  198. window.tempTip.show('未扫入条码,请检查扫码枪设置,尝试调至“直接键盘输出”模式');
  199. return;
  200. }
  201. data.status.scanEndInputted = true;
  202. data.showCommitButton();
  203. data.autoFillBin();
  204. switch(data.inputMode){
  205. case 'increasing': data.commitGoodsOnIncreasingMode();break;
  206. case 'multiIncreasing': data.commitGoodsOnMultiIncreasingMode();break;
  207. }
  208. }
  209. });
  210. },
  211. commitGoodsOnIncreasingMode: function () {
  212. let data = this;
  213. function doIt(){
  214. let repeatedBarcode=data.repeatedIncreasingBarcodeFromSaved();
  215. function increase(){
  216. data.inputting.bin=repeatedBarcode.bin;
  217. repeatedBarcode.amount++;
  218. data.inputting.amount=repeatedBarcode.amount;
  219. window.tempTip.setDuration(500);
  220. window.tempTip.showSuccess(repeatedBarcode.amount);
  221. data.focusDocument();
  222. data.audioDing();
  223. }
  224. if(!repeatedBarcode){
  225. data.focusOutDocument();
  226. data.alertVibrate();
  227. window.tempTip.setInputType('number');
  228. window.tempTip.inputVal('该商品第一件递增请输入隔口号:',function(bin){
  229. if(bin===''){
  230. window.tempTip.setDuration(1500);
  231. window.tempTip.show('未输入隔口号,请重新扫描');
  232. data.alertVibrate();
  233. data.focusDocument();return}
  234. data.inputting.bin=bin;
  235. data.inputting.amount=1;
  236. data.goodses.unshift(JSON.parse(JSON.stringify(data.inputting)));
  237. data.status.binDisable=true;
  238. window.tempTip.setDuration(500);
  239. window.tempTip.showSuccess('保存成功');
  240. data.focusDocument();
  241. data.audioDing();
  242. })
  243. }else{
  244. increase();
  245. }
  246. }
  247. if(data.lastScannedBarcode!==data.inputting.barcode && data.lastScannedBarcode){
  248. data.audioWarning_otherBarcode();
  249. data.focusOutDocument();
  250. window.tempTip.confirm('扫到其它条码,是否切换至新条码并记录?',doIt,function () {
  251. data.inputting.barcode=data.lastScannedBarcode;
  252. // data.cleanInputs();
  253. data.focusDocument();
  254. })
  255. }else{
  256. doIt()
  257. }
  258. },
  259. commitGoodsOnMultiIncreasingMode: function () {
  260. let data = this;
  261. let repeatedBarcode=this.repeatedIncreasingBarcodeFromSaved();
  262. function increase(){
  263. data.inputting.bin=repeatedBarcode.bin;
  264. repeatedBarcode.amount++;
  265. data.inputting.amount=repeatedBarcode.amount;
  266. window.tempTip.setDuration(500);
  267. window.tempTip.showSuccess(repeatedBarcode.amount);
  268. data.focusDocument();
  269. data.audioDing();
  270. }
  271. if(!repeatedBarcode){
  272. data.focusOutDocument();
  273. data.alertVibrate();
  274. window.tempTip.setInputType('number');
  275. window.tempTip.inputVal('该商品第一件递增请输入隔口号:',function(bin){
  276. if(bin===''){
  277. window.tempTip.setDuration(1500);
  278. window.tempTip.show('未输入隔口号,请重新扫描');
  279. data.alertVibrate();
  280. data.focusDocument();return}
  281. data.inputting.bin=bin;
  282. data.inputting.amount=1;
  283. data.goodses.unshift(JSON.parse(JSON.stringify(data.inputting)));
  284. data.status.binDisable=true;
  285. window.tempTip.setDuration(500);
  286. window.tempTip.showSuccess('保存成功');
  287. data.focusDocument();
  288. data.audioDing();
  289. })
  290. }else{
  291. increase();
  292. }
  293. },
  294. audioWarning_otherBarcode: function () {
  295. let audio = document.getElementById('soundWarning');
  296. audio.currentTime = 0;//重新播放
  297. if(audio.paused){
  298. audio.play();// 播放
  299. }
  300. this.alertVibrate();
  301. },
  302. audioDing: function () {
  303. let audio = document.getElementById('soundDing');
  304. audio.currentTime = 0;//重新播放
  305. audio.play();// 播放
  306. function startVibrate(duration) {
  307. if (navigator.vibrate) {
  308. navigator.vibrate(duration);
  309. } else if (navigator.webkitVibrate) {
  310. navigator.webkitVibrate(duration);
  311. }
  312. }
  313. startVibrate(500);
  314. },
  315. alertVibrate: function () {
  316. function startVibrate(duration) {
  317. if (navigator.vibrate) {
  318. navigator.vibrate(duration);
  319. } else if (navigator.webkitVibrate) {
  320. navigator.webkitVibrate(duration);
  321. }
  322. }
  323. let vibrateInterval = setInterval(function() {
  324. startVibrate(150);
  325. }, 50);
  326. setTimeout(function() {
  327. clearInterval(vibrateInterval)
  328. }, 2000);
  329. },
  330. autoFillBin: function () {
  331. let data = this;
  332. let isNotRepeatingBarcode=this.goodses.every(function(goods){
  333. if(goods.barcode===data.inputting.barcode){
  334. data.inputting.bin=goods.bin;
  335. data.status.binDisable=true;
  336. return false;
  337. }
  338. return true;
  339. });
  340. if(isNotRepeatingBarcode){
  341. data.status.binDisable=false;
  342. }
  343. },
  344. repeatedIncreasingBarcodeFromSaved: function () {
  345. let data = this;
  346. let repeatedGoods=null;
  347. data.goodses.every(function(goods){
  348. if(goods.barcode===data.inputting.barcode && goods.fromIncreasing){
  349. repeatedGoods=goods;
  350. return false;
  351. }
  352. return true;
  353. });
  354. return repeatedGoods;
  355. },
  356. commitGoods: function () {
  357. let data = this;
  358. window.tempTip.setDuration(3500);
  359. if(!data.inputting.barcode){window.tempTip.show('请扫入条码');return;}
  360. else if(!data.inputting.amount){window.tempTip.show('请输入数量');return;}
  361. //else if(!data.inputting.bin){window.tempTip.show('请输入隔口号');return;}
  362. data.recordOrPlusGoods();
  363. window.tempTip.setDuration(1500);
  364. window.tempTip.showSuccess('成功提交:' + data.inputting.barcode);
  365. data.cleanInputs();
  366. data.audioDing();
  367. },
  368. cleanInputs: function () {
  369. this.changeToScanInputBarcode();
  370. this.inputting.barcode='';
  371. this.inputting.amount='';
  372. this.inputting.bin='';
  373. this.inputting.produce_date='';
  374. this.inputting.valid_date='';
  375. this.inputting.batch_number='';
  376. this.inputting.unique_code='';
  377. this.commitButtonVisible=false;
  378. this.status.binDisable=false;
  379. this.lastScannedBarcode='';
  380. },
  381. recordOrPlusGoods: function () {
  382. let data = this;
  383. if(this.inputMode==='regular'){
  384. data.goodses.unshift(JSON.parse(JSON.stringify(data.inputting)));
  385. return;
  386. }
  387. let isNotRepeating=data.goodses.every(function(goods){
  388. if(goods.barcode===data.inputting.barcode){
  389. goods.amount=parseInt(goods.amount)+parseInt(data.inputting.amount);
  390. return false;
  391. }
  392. return true;
  393. });
  394. if(isNotRepeating){
  395. data.goodses.unshift(JSON.parse(JSON.stringify(data.inputting)));
  396. }
  397. },
  398. removeGoods: function ($e,barcode) {
  399. if(!confirm('确定要删除条码为'+barcode+'的记录吗'))return;
  400. let data = this;
  401. data.goodses.every(function(goods,i){
  402. if(goods.barcode===barcode){
  403. data.goodses.splice(i,1)
  404. return false;
  405. }
  406. return true;
  407. })
  408. },
  409. showCommitButton: function () {
  410. let data = this;
  411. if(data.inputting.barcode && data.inputting.amount /*&& data.inputting.bin*/){
  412. data.commitButtonVisible=true;
  413. }else{
  414. if (this.inputMode==='regular' && this.status.barcodeDisable && !this.inputting.amount && this.inputting.barcode){
  415. this.focusing = '';
  416. document.getElementById('amount').focus();
  417. }
  418. }
  419. },
  420. submitExcelData: function () {
  421. let data = this;
  422. data.focusOutDocument();
  423. if(data.goodses.length===0){
  424. window.tempTip.show('请先录入数据再提交EXCEL');return;
  425. }
  426. window.tempTip.confirm('请检查表格,确定全部完成。提交后数据将全部清空,不能后退',
  427. function () {
  428. window.tempTip.setInputType('input');
  429. window.tempTip.setIndex(999999);
  430. window.tempTip.inputVal('请输入文件名:',function(val){
  431. if(val===''){
  432. window.tempTip.setDuration(2500);
  433. window.tempTip.show('失败!文件名不能为空,请重新点击生成');
  434. return;
  435. }
  436. window.tempTip.setDuration(15500);
  437. window.tempTip.waitingTip('提交Excel中...');
  438. let expireHandler = setTimeout(function () {
  439. window.tempTip.cancelWaitingTip();
  440. window.tempTip.setDuration(1500);
  441. window.tempTip.show('响应超时! 请检查网络,确保可以连接后再重试。');
  442. },9000);
  443. let url='{{url("store/blindReceive/excels/apiStore")}}';
  444. axios.post(url,{'goodses':data.goodses,'filename':val})
  445. .then(function(response){
  446. if(response.data.result==='success'){
  447. data.goodses=[];
  448. data.cleanInputs();
  449. window.tempTip.cancelWaitingTip();
  450. window.tempTip.setDuration(1500);
  451. window.tempTip.showSuccess('成功生成EXCEL,可在列表页查看');
  452. data.focusDocument();
  453. }else{
  454. window.tempTip.setDuration(1500);
  455. window.tempTip.show('生成EXCEL失败:'+response.data.fail_info);
  456. console.log(response);
  457. data.focusDocument();
  458. data.alertVibrate()
  459. }
  460. clearInterval(expireHandler);
  461. })
  462. .catch(function (err) {
  463. window.tempTip.setDuration(3500);
  464. window.tempTip.show('网络或系统错误,请将以下信息提交给开发者:'+err);
  465. clearInterval(expireHandler);
  466. data.alertVibrate();
  467. });
  468. });
  469. },function () {
  470. data.focusDocument();
  471. })
  472. }
  473. },
  474. computed: {
  475. borderByMode: function () {
  476. return {
  477. // 'border-info':this.inputMode==='regular',
  478. 'border-success':this.inputMode==='increasing',
  479. 'border-danger':this.inputMode==='multiIncreasing'
  480. }
  481. }
  482. }
  483. });
  484. </script>
  485. @endsection