#
luxiaotao1123
2021-04-07 86fb7988d3597c0e66a5e063f385a213849253bf
src/main/webapp/views/pda/selectMat.html
@@ -72,53 +72,107 @@
<header>
    <div class="search-box">
        <input type="text">
        <input type="text" placeholder="请输入商品编码/名称">
        <button>
            <i class="layui-icon">&#xe615;</i>
        </button>
    </div>
</header>
<main>
    <div class="box-item">
        <div class="box-item-label">尼龙头螺丝盒装</div>
    </div>
    <div class="box-item">
        <div class="box-item-label">尼龙头螺丝盒装</div>
    </div>
    <div class="box-item">
        <div class="box-item-label">尼龙头螺丝盒装</div>
    </div>
    <div class="box-item">
        <div class="box-item-label">尼龙头螺丝盒装</div>
    </div>
    <div class="box-item">
        <div class="box-item-label">尼龙头螺丝盒装</div>
    </div>
    <div class="box-item">
        <div class="box-item-label">尼龙头螺丝盒装</div>
    </div>
<main id="main-contain">
</main>
</body>
<script>
    $(function () {
        showTag();
    })
    $(document).on('click','.box-item', function () {
        var tagId = $(this).children('input').get(0).value;
        showTag(tagId);
    })
    // 展示归类
    function showTag(parentId){
        $.ajax({
            url: baseUrl + "/tag/list/pda/auth",
            headers: {'token': localStorage.getItem('token')},
            data: {
                parentId: parentId
            },
            method: 'POST',
            success: function (res) {
                if (res.code === 200) {
                    if (res.data != null && res.data.length > 0) {
                        console.log(res.data)
                        var tplDom = $("#tagTpl");
                        var tpl = tplDom.html();
                        var template = Handlebars.compile(tpl);
                        var html = template(res);
                        $('#main-contain').html(html);
                    } else {
                        var tagId = parentId;
                        showMat(tagId);
                    }
                } else if (res.code === 403) {
                    top.location.href = baseUrl + "/pda";
                } else {
                    parent.layer.msg(res.msg, {icon: 2});
                }
            }
        })
    }
    // 展示商品
    function showMat(tagId) {
        if (isEmpty(tagId)) {
            return;
        }
        $.ajax({
            url: baseUrl + "/mat/list/pda/auth",
            headers: {'token': localStorage.getItem('token')},
            data: {
                tagId: tagId
            },
            method: 'POST',
            success: function (res) {
                if (res.code === 200) {
                    if (res.data != null && res.data.length > 0) {
                        console.log(res.data)
                        var tplDom = $("#matTpl");
                        var tpl = tplDom.html();
                        var template = Handlebars.compile(tpl);
                        var html = template(res);
                        $('#main-contain').html(html);
                    } else {
                    }
                } else if (res.code === 403) {
                    top.location.href = baseUrl + "/pda";
                } else {
                    parent.layer.msg(res.msg, {icon: 2});
                }
            }
        })
    }
</script>
<script type="text/template" id="tagTpl">
    {{#each data}}
    <option value="{{this}}">{{this}}</option>
    <div class="box-item">
        <input name="tagId" type="hidden" value="{{this.id}}">
        <div class="box-item-label">{{this.name}}</div>
    </div>
    {{/each}}
</script>
<script type="text/template" id="matTpl">
    {{#each data}}
    <option value="{{this}}">{{this}}</option>
    <div class="box-item">
        <input name="matId" type="hidden" value="{{this.id}}">
        <div class="box-item-label">{{this.maktx}}</div>
    </div>
    {{/each}}
</script>
</html>