#
luxiaotao1123
2021-04-07 86fb7988d3597c0e66a5e063f385a213849253bf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no"/>
    <title>商品选择</title>
    <link rel="stylesheet" href="../../static/layui/css/layui.css" media="all">
    <script type="text/javascript" src="../../static/js/jquery/jquery-3.3.1.min.js"></script>
    <script type="text/javascript" src="../../static/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="../../static/layui/layer_mobile/layer.js" charset="utf-8"></script>
    <script type="text/javascript" src="../../static/js/common.js" charset="utf-8"></script>
    <script type="text/javascript" src="../../static/js/cool.js" charset="utf-8"></script>
    <script type="text/javascript" src="../../static/js/handlebars/handlebars-v4.5.3.js"></script>
    <style>
        html {
            height: 100%;
        }
        body {
            height: 100%;
            background-color: #f1f1f1;
            padding: 5px;
        }
 
        /* 头部搜索栏 */
        .search-box {
            height: 36px;
            padding: 3px 15px;
        }
        .search-box input {
            border: none;
            border-radius: 20px;
            height: 30px;
            box-shadow: 0 0 3px rgba(0,0,0,.3);
            width: 75%;
            padding-left: 15px;
            vertical-align: middle;
        }
        .search-box button {
            border: none;
            background-color: white;
            box-shadow: 0 0 3px rgba(0,0,0,.3);
            height: 33px;
            margin-left: 5px;
            border-radius: 20px;
            width: 15%;
            vertical-align: middle;
        }
        .search-box button:hover {
            background-color: #dedede;
        }
 
        /* 主体卡片 */
        .box-item {
            height: 100px;
            border-bottom: 1px solid #dedede;
            background-color: #fff;
            border-radius: 5px;
            box-shadow: 0 0 3px rgba(0,0,0,.3);
            margin-top: 2px;
        }
        .box-item:hover {
            background-color: #eaeaea;
        }
        .box-item-label {
            font-size: x-large;
            font-weight: bold;
            padding: 10px 0 0 20px;
        }
</style>
</head>
<body>
 
<header>
    <div class="search-box">
        <input type="text" placeholder="请输入商品编码/名称">
        <button>
            <i class="layui-icon">&#xe615;</i>
        </button>
    </div>
</header>
 
<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}}
    <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}}
    <div class="box-item">
        <input name="matId" type="hidden" value="{{this.id}}">
        <div class="box-item-label">{{this.maktx}}</div>
    </div>
    {{/each}}
</script>
</html>