|
@@ -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}
|