Explorar o código

优化投料bug

huangsanjia %!s(int64=3) %!d(string=hai) anos
pai
achega
897b7d31c4
Modificáronse 2 ficheiros con 138 adicións e 62 borrados
  1. 13 3
      application/admin/controller/Feeding.php
  2. 125 59
      public/assets/js/backend/feeding.js

+ 13 - 3
application/admin/controller/Feeding.php

@@ -198,10 +198,20 @@ class Feeding extends Backend
         $map = [];
         $map['f_name'] = $task['name'];
         $map['name'] = $material;
-        $data = Db::name('formula_material')->where($map)->find();
-        $result['data'] = $data;
+        $data = Db::name('formula_material')->where($map)->select();
+        $result['data'] = '';
         if ($data){
-            $result['total'] = 1;
+            $result['data'] = $data;
+            if (count($data)>1){
+                $str = [];
+                foreach ($data as $key=>$value){
+                    $str[$key] = $value['m_name'];
+                }
+                $result['string'] = implode('或',$str);
+            }else{
+                $result['string'] = $data[0]['m_name'];
+            }
+            $result['total'] = count($data);
         }else{
             $result['total'] = 0;
         }

+ 125 - 59
public/assets/js/backend/feeding.js

@@ -255,72 +255,138 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form','jQuery.print','jquery
                                                             material:wuliao
                                                         },
                                                         success(data) {
-                                                            if (data.total == 1){
-                                                                wuliao = data.data.m_name;
-                                                            }
-                                                            $('#input').html(wuliao);
-                                                            for (var i=0;i<result.data.length;i++){
-                                                                //扫描的物料=table中的物料,,,变红,否则语音提示
-                                                                if(result.data[i].material===wuliao){
-                                                                    if (result.data[i].gy_num == result.process){
-                                                                        $(".material")[i].setAttribute('style','color:red');
-                                                                        $(".nweight")[i].setAttribute('style','color:red');
-                                                                        //语音播报
-                                                                        var msg = new SpeechSynthesisUtterance("应投入物料"+result.data[i].material+"应投入重量"+result.data[i].nweight+"千克");
-                                                                        window.speechSynthesis.speak(msg);
-                                                                        error++;
-                                                                    }else if (result.data[i].gy_num > result.process){
-                                                                        Layer.confirm("此物料不在当前工序,请确认!",{
-                                                                            area: ['60%', '60%'],
-                                                                        });
-                                                                        //语音播报
-                                                                        var msg = new SpeechSynthesisUtterance("此物料不在当前工序,请确认!");
-                                                                        window.speechSynthesis.speak(msg);
-                                                                        error++;
-                                                                    }else {
-                                                                        Layer.confirm("此物料已经投料,请确认此工序是否有此物料!",{
-                                                                            area: ['60%', '60%'],
-                                                                        });
-                                                                        //语音播报
-                                                                        var msg = new SpeechSynthesisUtterance("此物料不在当前工序,请确认!");
-                                                                        window.speechSynthesis.speak(msg);
-                                                                        error++;
+                                                            if (data.total > 0){
+                                                                //查到中文物料,循环比较物料与配方
+                                                                wuliao = data.string;
+                                                                $('#input').html(wuliao);
+                                                                for (var i=0;i<result.data.length;i++){
+                                                                    for (var j=0;j<data.data.length;j++){
+                                                                        //扫描的物料=table中的物料,,,变红,否则语音提示
+                                                                        if(result.data[i].material===data.data[j].m_name){
+                                                                            if (result.data[i].gy_num == result.process){
+                                                                                $(".material")[i].setAttribute('style','color:red');
+                                                                                $(".nweight")[i].setAttribute('style','color:red');
+                                                                                //语音播报
+                                                                                var msg = new SpeechSynthesisUtterance("应投入物料"+result.data[i].material+"应投入重量"+result.data[i].nweight+"千克");
+                                                                                window.speechSynthesis.speak(msg);
+                                                                                error++;
+                                                                            }else if (result.data[i].gy_num > result.process){
+                                                                                Layer.confirm("此物料不在当前工序,请确认!",{
+                                                                                    area: ['60%', '60%'],
+                                                                                });
+                                                                                //语音播报
+                                                                                var msg = new SpeechSynthesisUtterance("此物料不在当前工序,请确认!");
+                                                                                window.speechSynthesis.speak(msg);
+                                                                                error++;
+                                                                            }else {
+                                                                                Layer.confirm("此物料已经投料,请确认此工序是否有此物料!",{
+                                                                                    area: ['60%', '60%'],
+                                                                                });
+                                                                                //语音播报
+                                                                                var msg = new SpeechSynthesisUtterance("此物料不在当前工序,请确认!");
+                                                                                window.speechSynthesis.speak(msg);
+                                                                                error++;
+                                                                            }
+                                                                        }
+                                                                        //替代料变扫描的物料
+                                                                        if(result.data[i].material.indexOf('/')!==-1) {
+                                                                            var arr = result.data[i].material.split('/');
+                                                                            if (arr.indexOf($("#wuliao").val()) !== -1 && result.data[i].gy_num == result.process) {
+                                                                                $(".material")[i].value = wuliao;
+                                                                                $(".material")[i].setAttribute('style', 'color:red');
+                                                                                $(".nweight")[i].setAttribute('style', 'color:red');
+                                                                                error++;
+                                                                            } else if (arr.indexOf($("#wuliao").val()) !== -1) {
+                                                                                Layer.confirm("此物料不在当前工序,请确认!", {
+                                                                                    area: ['60%', '60%'],
+                                                                                });
+                                                                                //语音播报
+                                                                                var msg = new SpeechSynthesisUtterance("此物料不在当前工序,请确认!");
+                                                                                window.speechSynthesis.speak(msg);
+                                                                                error++;
+                                                                            }
+                                                                        }
                                                                     }
-                                                                }
 
+                                                                }
+                                                                if(error===0){
+                                                                    layer.confirm("此物料不在配方中,且没有替代料,请确认!", {//物料不存在提示错误信息
+                                                                        title: ['信息'],
+                                                                        btn: ['确认'],
+                                                                        area: ['60%', '60%'],
+                                                                    });
+                                                                    var synth = window.speechSynthesis;
+                                                                    var msg = new window.SpeechSynthesisUtterance('此物料不在配方中,且没有替代料,请确认!');
+                                                                    window.speechSynthesis.cancel();
+                                                                    synth.speak(msg);
+                                                                }
 
-                                                                //替代料变扫描的物料
-                                                                if(result.data[i].material.indexOf('/')!==-1) {
-                                                                    var arr = result.data[i].material.split('/');
-                                                                    if (arr.indexOf($("#wuliao").val()) !== -1 && result.data[i].gy_num == result.process) {
-                                                                        $(".material")[i].value = wuliao;
-                                                                        $(".material")[i].setAttribute('style', 'color:red');
-                                                                        $(".nweight")[i].setAttribute('style', 'color:red');
-                                                                        error++;
-                                                                    } else if (arr.indexOf($("#wuliao").val()) !== -1) {
-                                                                        Layer.confirm("此物料不在当前工序,请确认!", {
-                                                                            area: ['60%', '60%'],
-                                                                        });
-                                                                        //语音播报
-                                                                        var msg = new SpeechSynthesisUtterance("此物料不在当前工序,请确认!");
-                                                                        window.speechSynthesis.speak(msg);
-                                                                        error++;
+                                                            }else{
+                                                                //没有在数据库查到,直接去比较物料与配方
+                                                                $('#input').html(wuliao);
+                                                                for (var i=0;i<result.data.length;i++){
+                                                                    //扫描的物料=table中的物料,,,变红,否则语音提示
+                                                                    if(result.data[i].material===wuliao){
+                                                                        if (result.data[i].gy_num == result.process){
+                                                                            $(".material")[i].setAttribute('style','color:red');
+                                                                            $(".nweight")[i].setAttribute('style','color:red');
+                                                                            //语音播报
+                                                                            var msg = new SpeechSynthesisUtterance("应投入物料"+result.data[i].material+"应投入重量"+result.data[i].nweight+"千克");
+                                                                            window.speechSynthesis.speak(msg);
+                                                                            error++;
+                                                                        }else if (result.data[i].gy_num > result.process){
+                                                                            Layer.confirm("此物料不在当前工序,请确认!",{
+                                                                                area: ['60%', '60%'],
+                                                                            });
+                                                                            //语音播报
+                                                                            var msg = new SpeechSynthesisUtterance("此物料不在当前工序,请确认!");
+                                                                            window.speechSynthesis.speak(msg);
+                                                                            error++;
+                                                                        }else {
+                                                                            Layer.confirm("此物料已经投料,请确认此工序是否有此物料!",{
+                                                                                area: ['60%', '60%'],
+                                                                            });
+                                                                            //语音播报
+                                                                            var msg = new SpeechSynthesisUtterance("此物料不在当前工序,请确认!");
+                                                                            window.speechSynthesis.speak(msg);
+                                                                            error++;
+                                                                        }
+                                                                    }
+                                                                    //替代料变扫描的物料
+                                                                    if(result.data[i].material.indexOf('/')!==-1) {
+                                                                        var arr = result.data[i].material.split('/');
+                                                                        var spanValue = document.getElementById("input").innerHTML;
+                                                                        if (arr.indexOf(spanValue) !== -1 && result.data[i].gy_num == result.process) {
+                                                                            $(".material")[i].value = wuliao;
+                                                                            $(".material")[i].setAttribute('style', 'color:red');
+                                                                            $(".nweight")[i].setAttribute('style', 'color:red');
+                                                                            var msg = new SpeechSynthesisUtterance("应投入物料"+result.data[i].material+"应投入重量"+result.data[i].nweight+"千克");
+                                                                            window.speechSynthesis.speak(msg);
+                                                                            error++;
+                                                                        } else if (arr.indexOf($("#wuliao").val()) !== -1) {
+                                                                            Layer.confirm("此物料不在当前工序,请确认!", {
+                                                                                area: ['60%', '60%'],
+                                                                            });
+                                                                            //语音播报
+                                                                            var msg = new SpeechSynthesisUtterance("此物料不在当前工序,请确认!");
+                                                                            window.speechSynthesis.speak(msg);
+                                                                            error++;
+                                                                        }
                                                                     }
                                                                 }
-                                                            }
-                                                            if(error===0){
-                                                                layer.confirm("此物料不在配方中,且没有替代料,请确认!", {//物料不存在提示错误信息
-                                                                    title: ['信息'],
-                                                                    btn: ['确认'],
-                                                                    area: ['60%', '60%'],
-                                                                });
-                                                                var synth = window.speechSynthesis;
-                                                                var msg = new window.SpeechSynthesisUtterance('此物料不在配方中,且没有替代料,请确认!');
-                                                                window.speechSynthesis.cancel();
-                                                                synth.speak(msg);
+                                                                if(error===0){
+                                                                    layer.confirm("此物料不在配方中,且没有替代料,请确认!", {//物料不存在提示错误信息
+                                                                        title: ['信息'],
+                                                                        btn: ['确认'],
+                                                                        area: ['60%', '60%'],
+                                                                    });
+                                                                    var synth = window.speechSynthesis;
+                                                                    var msg = new window.SpeechSynthesisUtterance('此物料不在配方中,且没有替代料,请确认!');
+                                                                    window.speechSynthesis.cancel();
+                                                                    synth.speak(msg);
+                                                                }
                                                             }
                                                         }
-
                                                     })
                                                     //清空物料扫描后的值,下次直接重新扫描即可
                                                     $("#wuliao").val('');