wupengfei 2 år sedan
förälder
incheckning
904612ab3e

+ 2 - 1
.idea/workspace.xml

@@ -3,6 +3,7 @@
   <component name="ChangeListManager">
     <list default="true" id="1a36929e-c054-4875-a943-593a74e55fa4" name="Default Changelist" comment="">
       <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/application/operate/controller/SupplierGoods.php" beforeDir="false" afterPath="$PROJECT_DIR$/application/operate/controller/SupplierGoods.php" afterDir="false" />
       <change beforePath="$PROJECT_DIR$/application/operate/view/supplier_goods/form.html" beforeDir="false" afterPath="$PROJECT_DIR$/application/operate/view/supplier_goods/form.html" afterDir="false" />
     </list>
     <option name="SHOW_DIALOG" value="false" />
@@ -291,7 +292,7 @@
       <workItem from="1681348081818" duration="22448000" />
       <workItem from="1681434523223" duration="19578000" />
       <workItem from="1681463431612" duration="3188000" />
-      <workItem from="1681692707179" duration="17060000" />
+      <workItem from="1681692707179" duration="17949000" />
     </task>
     <servers />
   </component>

+ 1 - 1
application/operate/controller/SupplierGoods.php

@@ -171,7 +171,7 @@ class SupplierGoods extends Controller
         $this->supplier_list = \app\common\model\Supplier::getSupplierName(0);
        // $this->company_list = \app\common\model\Company::getCompanyName();
         $all_cate  = \app\common\model\SupplierCate::where(['is_deleted'=>0])->order('sort desc ,id desc')->select();
-        $this->cate_tree = make_tree($all_cate);
+        $this->goods_cate = make_tree($all_cate);
         $this->assign('waitSecond','1');
         $this->assign("jumpUrl",$_SERVER["HTTP_REFERER"]);
     }

+ 139 - 43
application/operate/view/supplier_goods/form.html

@@ -41,48 +41,44 @@
                     </div>
 
                     <div class="layui-form-item layui-row layui-col-space15">
-                        <label class="layui-col-xs9 relative">
-                            <span class="color-green">分类</span>
+                        <label class="layui-col-xs9 relative" style="width: 100%;">
+                            <span class="color-green">商品分类</span>
                         </label>
-                        <div class="layui-inline" style="top: -15px;margin-bottom: -25px">
-                            <div class="layui-input-inline">
-                                <select name="first_classify" lay-filter ="first_classify">
-                                    <option value="0">请选择</option>
-                                    {if !empty($cate_tree)}
-                                    {foreach $cate_tree as $ck=>$cv}
-                                    {if  isset($vo.first_classify) && $vo.first_classify == $cv['id'] }
-                                    <option selected data-cl_key="{$ck}" value="{$cv['id']}">{$cv['title']}</option>
+                        <div style="width: 100%">
+                            <div style="width: 15%;float: left;">
+                                <select class="layui-select"  id="first_classify" name="first_classify" lay-filter="first_classify" lay-search>
+                                    <option selected data-first_key="-1" selected value="0">请选择</option>
+                                    {if !empty($goods_cate)}
+                                    {foreach $goods_cate as $ck=>$cv}
+                                    {if isset_full_check($vo,'first_classify',$cv['id'])}
+                                    <option selected data-first_key="{$ck}" value="{$cv['id']}">{$cv['title']}</option>
                                     {else}
-                                    <option data-cl_key="{$ck}" value="{$cv['id']}">{$cv['title']}</option>
+                                    <option data-first_key="{$ck}" value="{$cv['id']}">{$cv['title']}</option>
                                     {/if}
                                     {/foreach}
                                     {/if}
                                 </select>
                             </div>
-                            <div class="layui-input-inline">
-                                <select name="second_classify" lay-filter ="second_classify">
-                                    <option value="0">请选择</option>
-                                    {if !empty($cate_tree)}
-                                        {foreach $cate_tree as $ck=>$cv}
-                                            {if isset($vo.first_classify) && $vo.first_classify == $cv['id'] }
-                                                {if isset($cv['children'])}
-                                                    {foreach $cv['children'] as $cln}
-                                                        {if isset($vo.second_classify) && $vo.second_classify == $cln['id'] }
-                                                            <option selected  value="{$cln['id']}">{$cln['title']}</option>
-                                                        {else}
-                                                            <option  value="{$cln['id']}">{$cln['title']}</option>
-                                                        {/if}
-                                                    {/foreach}
-                                                {/if}
-                                            {/if}
-                                        {/foreach}
-                                    {/if}
+                            <div style="width: 15%;float: left">
+                                <select class="layui-select"  id="second_classify" name="second_classify" lay-filter="second_classify" lay-search>
+
                                 </select>
                             </div>
-                        </div>
-                    </div>
+                            <div style="width: 15%;float: left">
+                                <select class="layui-select"  id="third_classify" name="third_classify" lay-filter="third_classify" lay-search>
 
+                                </select>
+                            </div>
+                            <div style="width: 12%;float: left">
+                                <select class="layui-select"  id="fourth_classify" name="fourth_classify" lay-filter="fourth_classify" lay-search>
 
+                                </select>
+                            </div>
+                            <input type="hidden" id="first"  value="{$vo.first_classify|default='-1'}"/>
+                            <input type="hidden" id="second" value="{$vo.second_classify|default='-1'}"/>
+                            <input type="hidden" id="third"  value="{$vo.third_classify|default='-1'}"/>
+                        </div>
+                    </div>
 
 
                     <div class="layui-form-item layui-row layui-col-space15" >
@@ -344,22 +340,122 @@
     });
 
 
-    // 分类选择监听
-    form.on('select(first_classify)', function(data){
-        var cl_html = '<option value="0">请选择</option>';
-        if(data.value == 0) {
-            $("select[name='second_classify']").html(cl_html);
+    // 四级分类联动 start
+    var sel_second  = {:isset($vo['second_classify']) ? $vo['second_classify']:0};
+    var sel_third   = {:isset($vo['third_classify']) ? $vo['third_classify']:0};
+    var sel_fourth   = {:isset($vo['fourth_classify']) ? $vo['fourth_classify']:0};
+    var goods_spec  = {:json_encode($goods_cate)};
+    first(1);
+    function first(source){
+        // 将其他选择框置空
+        var first_key = $("select[name='first_classify']").find("option:selected").data("first_key")
+        $("#first").val(first_key);
+        $("select[name='second_classify']").html('');
+        $("select[name='third_classify']").html('');
+        $("select[name='fourth_classify']").html('');
+        // 没有下级不继续
+        if(first_key == -1 || !("children" in goods_spec[first_key])){
+            $("#second").val(-1);
+            $("#third").val(-1);
+            window.form.render();
+            return true;
         }else{
-            var cl_key =  data.elem[data.elem.selectedIndex].dataset.cl_key;
-            var goods_spec = {:json_encode($cate_tree)};
-            $.each(goods_spec[cl_key]['children'],function (ck,cv) {
-                cl_html +='<option value="'+cv.id+'">'+cv.title+'</option>';
+            var second_html = '<option data-second_key="-1" selected value="0">请选择分类</option>';
+            var to_each =  goods_spec[first_key]['children'];
+            $.each(to_each,function (ck,cv) {
+                if(source == 1 && sel_second == cv.id){
+                    second_html +='<option selected data-second_key="'+ck+'" value="'+cv.id+'">'+cv.title+'</option>';
+                    $("#second").val(ck);
+                }else{
+                    second_html +='<option data-second_key="'+ck+'" value="'+cv.id+'">'+cv.title+'</option>';
+                }
             })
-            $("select[name='second_classify']").html(cl_html);
+            $("select[name='second_classify']").html(second_html);
+            window.form.render();
+            second(source);
         }
-        window.form.render();
-    });
+    }
+    function second(source){
+        var first_key  = $("select[name='first_classify']").find("option:selected").data("first_key");
+        var second_key  = $("select[name='second_classify']").find("option:selected").data("second_key");
+        // 将其他选择框置空
+        $("#second").val(second_key);
+        $("select[name='third_classify']").html('');
+        $("select[name='fourth_classify']").html('');
+        // 没有下级不继续
+        if(second_key == -1 ||  !("children" in  goods_spec[first_key]['children'][second_key])){
+            $("#third").val(-1);
+            window.form.render();
+            return true;
+        }
+        var to_each = goods_spec[first_key]['children'][second_key]['children'];
+        var third_html = '<option data-third_key="-1" selected value="0">请选择分类</option>';
+        $.each(to_each,function (ck,cv) {
+            if(source == 1 && sel_third == cv.id){
+                third_html +='<option selected data-third_key="'+ck+'" value="'+cv.id+'">'+cv.title+'</option>';
+                $("#third").val(ck);
+            }else{
+                third_html +='<option data-third_key="'+ck+'" value="'+cv.id+'">'+cv.title+'</option>';
+            }
 
+        })
+        $("select[name='third_classify']").html(third_html);
+        $("select[name='fourth_classify']").html('');
+        window.form.render();
+        third(source);
+    }
+    function third(source){
+        var first_key  = $("select[name='first_classify']").find("option:selected").data("first_key");
+        var second_key = $("select[name='second_classify']").find("option:selected").data("second_key");
+        var third_key  = $("select[name='third_classify']").find("option:selected").data("third_key");
+        // 将其他选择框置空
+        $("#third").val(third_key);
+        $("select[name='fourth_classify']").html('');
+        // 没有下级不继续
+        if(third_key == -1 || !("children" in  goods_spec[first_key]['children'][second_key]['children'][third_key])){
+            window.form.render();
+            return true;
+        }
+        var to_each = goods_spec[first_key]['children'][second_key]['children'][third_key]['children'];
+        var fourth_html = '<option data-froth_key="-1" selected value="0">请选择分类</option>';
+        $.each(to_each,function (ck,cv) {
+            if(source == 1 && sel_fourth == cv.id){
+                fourth_html +='<option selected data-froth_key="'+ck+'" value="'+cv.id+'">'+cv.title+'</option>';
+            }else{
+                fourth_html +='<option data-froth_key="'+ck+'" value="'+cv.id+'">'+cv.title+'</option>';
+            }
+        })
+        $("select[name='fourth_classify']").html(fourth_html);
+        window.form.render();
+    }
+    // 一级分类监听
+    form.on('select(first_classify)', function(data){
+        var first_key =  data.elem[data.elem.selectedIndex].dataset.first_key;
+        //与之前选择的一样不处理
+        if($("#first").val() == first_key){
+            return true;
+        }
+        first(2);
+    })
+    // 二级分类监听
+    form.on('select(second_classify)', function(data){
+        var second_key  = data.elem[data.elem.selectedIndex].dataset.second_key;
+        //与之前选择的一样不处理
+        if($("#second").val() == second_key){
+            return true;
+        }
+        second(2)
+    })
+    // 三级分类监听
+    form.on('select(third_classify)', function(data){
+        var third_key  =  data.elem[data.elem.selectedIndex].dataset.third_key;
+        //与之前选择的一样不处理
+        if($("#third").val() == third_key){
+            return true;
+        }
+        third(2)
+    })
+    // 四级分类end
 
 </script>
 {/block}