Administrator
2018-11-05 2d950dce7919a2bc39464f9d264f7b96b69f6d1e
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
<!DOCTYPE html>
<html lang="zh-cn">
 
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>添加推荐版块</title>
        <link href="css/bootstrap.min.css" rel="stylesheet">
        <link href="css/maincontent.css" rel="stylesheet">
        <link href="css/tablestyle.css" rel="stylesheet">
        <style>
            .form-group {
                margin-bottom: 30px;
            }
            
            .checkbox input[type=checkbox] {
                top: 6px;
            }
        </style>
    </head>
 
    <body>
        <nav class="navbar navbar-default navbar-fixed-top">
        </nav>
        <div id="mainbody">
            <div id="sidebar">
                <dl>
                </dl>
            </div>
            <div id="neirong">
                <div class="erjidh">
                    <ol class="breadcrumb">
                        <li>
                            <a href="guanli-bankuai.html">版块栏目</a>
                        </li>
                        <li class="active">添加推荐版块</li>
                    </ol>
                </div>
                <div class="header">
                    <h4 class="shujutitle">板块设置</h4>
                    <div class="fenge"></div>
                </div>
                <form class="form-horizontal" role="form">
                    <div class="form-group">
                        <label for="input1" class="changdu1 control-label">名称</label>
                        <div class="col-sm-7">
                            <input type="text" class="form-control" id="name" placeholder="必须填写">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="input2" class="changdu1 control-label">最多数量</label>
                        <div class="col-sm-7">
                            <input type="text" class="form-control" id="counts" placeholder="必须填写">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="input2" class="changdu1 control-label">是否显示</label>
                        <div class="col-sm-7">
                            <div class="checkbox">
                                <label>
                      <input type="checkbox" id="show" value="#">
                </label>
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="input6" class="changdu1 control-label">图片地址</label>
                        <div class="col-sm-7">
                            <input type="text" class="form-control" id="picurl" placeholder="">
                            <input type="file" id="exampleInputFile"  enctype="multipart/form-data" accept="image/*">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="input6" class="changdu1 control-label">图片跳转</label>
                        <div class="col-sm-7">
                            <input type="text" class="form-control" id="jumpurl" placeholder="">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="input6" class="changdu1 control-label">排序权重</label>
                        <div class="col-sm-7">
                            <input type="text" class="form-control" id="orderby" placeholder="">
                        </div>
                    </div>
                    <div class="header">
                        <h4 class="shujutitle">详情设置</h4>
                        <div class="fenge"></div>
                    </div>
                    <div class="form-group">
                        <label for="input6" class="changdu1 control-label">详情图片地址</label>
                        <div class="col-sm-7">
                            <input type="text" class="form-control" id="dpicurl" placeholder="">
                            <input type="file"  enctype="multipart/form-data" accept="image/*">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="input6" class="changdu1 control-label">详情样式</label>
                        <div class="col-sm-7" id="container">
                        </div>
                    </div>
                    <div class="button0">
                        <div class="button">
                            <button type="button" class="btn btn-primary save">保存</button>
                        </div>
                        <div class="button">
                            <input type="reset" class="btn btn-default" value="重置" />
                        </div>
                    </div>
                </form>
 
            </div>
        </div>
 
        <script src="//cdn.bootcss.com/jquery/1.10.1/jquery.min.js"></script>
        <script src="js/bootstrap.min.js"></script>
        <script src="js/nav.js"></script>
        <script src="layer/layer.js"></script>
        <script type="text/javascript" src="js/ueditor.config.js"></script>
        <script type="text/javascript" src="js/ueditor.all.js"></script>
        <script type="text/javascript">
            var ue = UE.getEditor('container', {
                elementPathEnabled:false
            });
        </script>
        <script>
            $(function() {
                $(".save").click(function() {
                    
                    var picture = $("#picurl").val();
                    var iconFile = $("input[type='file']")[0].files[0];
                    if(iconFile == null){
                            if(picture.length <= 0){
                                layer.msg("图片不能为空!");
                                 return;
                        }
                    }
                    
                    var index = layer.load(0, {
                        'shade': false
                    });
                    
                    if(iconFile != null){
                    var formData = new FormData();
                        var filename = $("input[type='file']").eq(0).val();
                        formData.append("file",iconFile);
                        formData.append("name",filename);    
                    $.ajax({
                        url : "api/v1/upload/uploadImg",
                        type : 'POST', 
                        data : formData, 
                        dataType : "json",
                        // 告诉jQuery不要去处理发送的数据
                            processData : false, 
                            // 告诉jQuery不要去设置Content-Type请求头
                            contentType : false,
                            beforeSend:function(){
                                console.log("正在进行,请稍候");
                            },
                            success : function(data,responseStr) {
                                $("#picurl").val(data.data);
                                save();
                            },
                            error : function(responseStr) { 
                                layer.close(index);
                                alert("error");
                            } 
                        });
                    }else{
                            save();
                    }
                });
 
            });
            
            function save(){
                var iconFile2 = $("input[type='file']")[1].files[0];
                if(iconFile2 != null){
                    var formData = new FormData();
                        var filename = $("input[type='file']").eq(1).val();
                        formData.append("file",iconFile2);
                        formData.append("name",filename);    
                    $.ajax({
                        url : "api/v1/upload/uploadImg",
                        type : 'POST', 
                        data : formData, 
                        dataType : "json",
                        // 告诉jQuery不要去处理发送的数据
                            processData : false, 
                            // 告诉jQuery不要去设置Content-Type请求头
                            contentType : false,
                            beforeSend:function(){
                                console.log("正在进行,请稍候");
                            },
                            success : function(data,responseStr) {
                                $("#dpicurl").val(data.data);
                            }
                        });
                    }
                
                var content= UE.getEditor('container').getContent();                
                $.post('api/v1/section/addSection', {
                        'name': $("#name").val(),
                        'orderby': $("#orderby").val(),
                        'show': $("#show").is(":checked") ? true : false,
                        'picUrl': $("#picurl").val(),
                        'jumpUrl': $("#jumpurl").val(),
                        'counts': $("#counts").val(),
                        'detail.picUrl':$("#dpicurl").val(),
                        'htmlCode':content
                    }, function(data) {
                        if(data.code == "0") {
                            layer.alert('保存成功!', {
                                icon: 1,
                                skin: 'layer-ext-seaing',
                                yes:function(){
                                    location.href="guanli-bankuai.html?page=1";
                                }
                            });
                        } else {
                            layer.alert('保存失败!', {
                                icon: 2,
                                skin: 'layer-ext-seaing'
                            });
                        }
                        layer.close(index);
                    }, 'json');
            }
        </script>
    </body>
 
</html>