admin
2019-07-11 3824cbcaec6e6c67418d5280a53e9c2fedeef6f9
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
<!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">
<!--[if lt IE 9]>
      <script src="js/html5shiv.js"></script>
      <script src="js/respond.min.js"></script>
    <![endif]-->
</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="fenlei-yijiguanli.html">分类管理</a></li>
        <li class="active">添加分类</li>
      </ol>
    </div>
    <table class="table">
      <tbody>
        <tr>
          <td><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="input1" placeholder="必填">
                </div>
              </div>
            </form></td>
        </tr>
      </tbody>
    </table>
    <table class="table">
      <tbody>
        <tr>
          <td><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="input4" placeholder="">
                </div>
              </div>
            </form></td>
        </tr>
      </tbody>
    </table>
    <table class="table">
      <tbody>
        <tr>
          <td><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="input2" onkeyup="value=value.replace(/[^\d]/g,'')" placeholder="必填,且只能为数字">
                </div>
              </div>
            </form></td>
        </tr>
      </tbody>
    </table>
    <table class="table">
      <tbody>
        <tr>
          <td><form class="form-horizontal" role="form">
              <div class="form-group">
                <label for="input2" class="changdu1 control-label">分类图标</label>
                <div class="col-sm-5">
                  <input type="text" class="form-control" id="input3" placeholder="">
                  <input type="file" id="exampleInputFile"  enctype="multipart/form-data">
                </div>
                <!--<a type="file" class="btn btn-default">选择文件</a>-->
              </div>
            </form></td>
        </tr>
      </tbody>
    </table>
    <div class="button0">
      <div class="button">
        <button type="button" class="btn btn-primary save">保存</button>
      </div>
      <div class="button"> <a href="fenlei-yijiguanli.html?page=1" class="btn btn-default" role="button">取消</a> </div>
    </div>
  </div>
</div>
<script src="js/jquery.min.js"></script> 
<script src="js/bootstrap.min.js"></script>
<script src="js/nav.js"></script>
<script src="js/common.js"></script>
<script src="layer/layer.js"></script>
<script>
        $(function(){
            $(".save").bind("click",function(){
                    var name = $("#input1").val();
                    var orderby = $("#input2").val();
                    var picture = $("#input3").val();
                    
                    if(name.length <= 0){
                        layer.msg("名称不能为空!");
                         return;
                    }
                    if(orderby.length <= 0){
                        layer.msg("排序不能为空!");
                         return;
                    }
                    var iconFile = $("input[type='file']")[0].files[0];
                    if(iconFile == null){
                            if(picture.length <= 0){
                                layer.msg("图片不能为空!");
                                 return;
                        }
                    }
                    if(iconFile != null ){
                        var formData = new FormData();
                        var filename = $("input[type='file']").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) {
                                $("#input3").val(data.data);
                                save();
                            },
                            error : function(responseStr) { 
                                console.log("error");
                                alert("error");
                            } 
                        });
                    }else{
                            save();
                    }
            });
        });
        
        function save(){
                var name = $("#input1").val();
                var orderby = $("#input2").val();
                var picture = $("#input3").val();
                var searchKey = $("#input4").val();
                if(searchKey.length == 0){
                    searchKey=name;
                }
            $.post("api/v1/goodsclass/addGoodsClass",{"name":name,"picture":picture,"orderby":orderby,"key":searchKey},function(data){
                        if(data.code==0){
                            layer.alert('保存成功!', {
                              icon: 1,
                              skin: 'layer-ext-seaing',
                              yes:function(){
                                  location.href="fenlei-yijiguanli.html?page=1";
                              }
                            });
                        }else{
                            layer.alert('保存失败!', {
                                      icon: 2,
                                      skin: 'layer-ext-seaing' 
                            });
                        }
                    },'json')
        }
</script>    
</body>
</html>