18315626215 před 5 roky
rodič
revize
bf84fb7da2

+ 41 - 2
application/admin/controller/commodity/Commodity.php

@@ -227,7 +227,46 @@ class Commodity extends Backend
     }
     //删除颜色
     public function delcolor () {
-        $id = input('colorid');
-        echo $id;
+        $id=input('colorid');
+        $data = Db::name('commoditycolor')->where("colorid",$id)->find();
+        $parameter = Db::name('commoditycolor')->where('p_id',$data['p_id'])->select();
+        $count = count($parameter);
+        if ($count==1) {
+            $delparamter = Db::name("parameter")->where('p_id',$data['p_id'])->delete(); //如果颜色只剩一个了,那么规格也被删除
+        }
+        $del=Db::name('commoditycolor')->where('colorid',$id)->delete();
+        if ($del) {
+            return json(['msg' => "删除成功", 'code' => '200']);
+        } else {
+            return json(['msg' => "删除失败", 'code' => '100']);
+        }
+    }
+    //添加颜色
+    public function addcolor ($ids='') {
+        if ($this->request->isPost()) {
+            $data = $this->request->post("row/a");
+            $add = Db::name('commoditycolor')->insert($data);
+            if ($add) {
+                return  $this->success('success',null,$data);
+            }
+        }
+        $id=input('p_id');
+        return $this->fetch('addcolor',['p_id'=>$id]);
+    }
+    //修改颜色
+    public function editcolor () {
+        if ($this->request->isPost()) {
+            $data = $this->request->post("row/a");
+
+            $edit = Db::name('commoditycolor')->where('colorid',$data['colorid'])->update($data);
+            if ($edit) {
+                return  $this->success('success',null,$data);
+            } else {
+                return  $this->error('修改失败或请至少修改一项',null,$data);
+            }
+        }
+        $id=input('colorid');
+        $data=Db::name('commoditycolor')->where('colorid',$id)->find();
+        return $this->fetch('editcolor', ['data'=>$data]);
     }
 }

+ 43 - 0
application/admin/view/commodity/commodity/addcolor.html

@@ -0,0 +1,43 @@
+<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">颜色:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-name" data-rule="required" class="form-control" name="row[name]" type="text">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">价格:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-money" data-rule="required" class="form-control" name="row[money]" type="text">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">库存:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-kucun" data-rule="required" class="form-control" name="row[kucun]" type="text">
+            <input id="c-p_id" data-rule="required" class="form-control" name="row[p_id]" type="hidden" value="{$p_id}">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">图片:</label>
+        <div class="col-xs-12 col-sm-8">
+            <div class="input-group">
+                <input id="c-color" data-rule="required" class="form-control" size="50" name="row[color]" type="text" value="">
+                <div class="input-group-addon no-border no-padding">
+                    <span><button type="button" id="plupload-image" class="btn btn-danger plupload" data-input-id="c-color" data-mimetype="image/gif,image/jpeg,image/png,image/jpg,image/bmp" data-multiple="false" data-preview-id="p-image"><i class="fa fa-upload"></i> {:__('Upload')}</button></span>
+                    <span><button type="button" id="fachoose-image" class="btn btn-primary fachoose" data-input-id="c-color" data-mimetype="image/*" data-multiple="false"><i class="fa fa-list"></i> {:__('Choose')}</button></span>
+                </div>
+                <span class="msg-box n-right" for="c-image"></span>
+            </div>
+            <ul class="row list-inline plupload-preview" id="p-image"></ul>
+        </div>
+    </div>
+    <div class="form-group layer-footer">
+        <label class="control-label col-xs-12 col-sm-2"></label>
+        <div class="col-xs-12 col-sm-8">
+            <button type="submit" class="btn btn-success btn-embossed disabled" >{:__('OK')}</button>
+            <button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
+        </div>
+    </div>
+
+</form>

+ 0 - 18
application/admin/view/commodity/commodity/addparameter.html

@@ -1,18 +0,0 @@
-<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
-
-    <div class="form-group">
-        <label class="control-label col-xs-12 col-sm-2">规格名:</label>
-        <div class="col-xs-12 col-sm-8">
-            <input id="c-p_name" data-rule="required" class="form-control" name="row[p_name]" type="text">
-            <input   class="form-control" name="row[c_id]" type="hidden" value="{$c_id}">
-        </div>
-    </div>
-    <div class="form-group layer-footer">
-        <label class="control-label col-xs-12 col-sm-2"></label>
-        <div class="col-xs-12 col-sm-8">
-            <button type="submit" class="btn btn-success btn-embossed disabled" >{:__('OK')}</button>
-            <button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
-        </div>
-    </div>
-
-</form>

+ 16 - 15
application/admin/view/commodity/commodity/commodityinfo.html

@@ -16,29 +16,30 @@
         </div>
     </div>
 <!--    <a href="commodity/addparameter?c_id={$c_id}" class="btn btn-success btn-edit " title="添加" style="margin-left: 600px"><i class="fa fa-plus"></i> 添加</a>-->
-    <button type="submit" class="btn btn-success btn-embossed disabled" style="margin-left: 600px">{:__('OK')}</button>
+    <button type="submit" class="btn btn-success btn-embossed " style="margin-left: 600px">{:__('OK')}</button>
 </form>
 <hr>
 <table  id="table" class="table table-striped table-bordered table-hover table-nowrap" style="width: 650px;margin-left: 70px">
     <tr style="height: 50px">
-        <td style="border: none">规格</td>
-        <td style="border: none">颜色</td>
-        <td style="border: none">库存</td>
-        <td style="border: none">价格</td>
-        <td style="border: none">图片</td>
-        <td style="border: none;margin-right: 50px">操作</td>
+        <td >规格</td>
+        <td >颜色</td>
+        <td>库存</td>
+        <td >价格</td>
+        <td >图片</td>
+        <td style="margin-right: 50px">操作</td>
     </tr>
     {volist name="parameter" id="item"}
     {volist name="$item.color" id="v"}
     <tr style="height: 50px;border: 1px" bgcolor="#f0f8ff" >
-        <td style="border: 1px">{$item.p_name}</td>
-        <td style="border: 1px">{$v.name}</td>
-        <td style="border: 1px">{$v.kucun}</td>
-        <td style="border: 1px">{$v.money}</td>
-        <td style="border: 1px"><img src="{$v.color}" style="width: 40px;height: 40px"/></td>
-        <td style="border: 1px">
-            <a href="" class="btn btn-success btn-add {:$auth->check('student/student/add')?'':'hide'}"><i class="fa fa-plus"></i> </a>
-            <a href="javascript:;" class="btn-del" style="width: 10px;height: 5px;color: red" ><i class="fa fa-trash"></i></a>
+        <td >{$item.p_name}</td>
+        <td >{$v.name}</td>
+        <td >{$v.kucun}</td>
+        <td >{$v.money}</td>
+        <td ><img src="{$v.color}" style="width: 40px;height: 40px"/></td>
+        <td >
+            <a href="javascript:;" class="btn btn-success btn-editt btn-disabled " data-title="{$v.colorid}" ><i class="fa fa-pencil"></i> </a>
+            <a href="javascript:;" class="btn btn-success btn-addd " data-title="{$item.p_id}"><i class="fa fa-plus"></i> </a>
+            <a href="javascript:;" class="btn btn-danger btn-dell btn-disabled "  data-title="{$v.colorid}"><i class="fa fa-trash"></i></a>
         </td>
     </tr>
     {/volist}

+ 44 - 0
application/admin/view/commodity/commodity/editcolor.html

@@ -0,0 +1,44 @@
+<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="" title="fff">
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">颜色:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-name" data-rule="required" class="form-control" name="row[name]" type="text" value="{$data.name}">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">价格:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-money" data-rule="required" class="form-control" name="row[money]" type="text" value="{$data.money}">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">库存:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-kucun" data-rule="required" class="form-control" name="row[kucun]" type="text" value="{$data.kucun}">
+            <input id="c-p_id" data-rule="required" class="form-control" name="row[p_id]" type="hidden" value="{$data.p_id}">
+            <input id="c-colorid" data-rule="required" class="form-control" name="row[colorid]" type="hidden" value="{$data.colorid}">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">图片:</label>
+        <div class="col-xs-12 col-sm-8">
+            <div class="input-group">
+                <input id="c-color" data-rule="required" class="form-control" size="50" name="row[color]" type="text" value="{$data.color}">
+                <div class="input-group-addon no-border no-padding">
+                    <span><button type="button" id="plupload-image" class="btn btn-danger plupload" data-input-id="c-color" data-mimetype="image/gif,image/jpeg,image/png,image/jpg,image/bmp" data-multiple="false" data-preview-id="p-image"><i class="fa fa-upload"></i> {:__('Upload')}</button></span>
+                    <span><button type="button" id="fachoose-image" class="btn btn-primary fachoose" data-input-id="c-color" data-mimetype="image/*" data-multiple="false"><i class="fa fa-list"></i> {:__('Choose')}</button></span>
+                </div>
+                <span class="msg-box n-right" for="c-image"></span>
+            </div>
+            <ul class="row list-inline plupload-preview" id="p-image"></ul>
+        </div>
+    </div>
+    <div class="form-group layer-footer">
+        <label class="control-label col-xs-12 col-sm-2"></label>
+        <div class="col-xs-12 col-sm-8">
+            <button type="submit" class="btn btn-success btn-embossed disabled" >{:__('OK')}</button>
+            <button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
+        </div>
+    </div>
+
+</form>

+ 55 - 23
public/assets/js/backend/commodity/commodity.js

@@ -1,37 +1,69 @@
 define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
-    $(document).on("click", ".btn-aaaa", function () {
-        // var url = 'commodity/commodity/addcolor';//弹出窗口 add.html页面的(fastadmin封装layer模态框将以iframe的方式将add输出到index页面的模态框里)
-        // Fast.api.open(url, __('Add'));
-        var c_id=$(this).attr('data-title');
+    // $(document).on("click", ".btn-aaaa", function () {
+    //     // var url = 'commodity/commodity/addcolor';//弹出窗口 add.html页面的(fastadmin封装layer模态框将以iframe的方式将add输出到index页面的模态框里)
+    //     // Fast.api.open(url, __('Add'));
+    //     var c_id=$(this).attr('data-title');
+    //     var msg = "配置添加";
+    //     var options = {
+    //         shadeClose: false,
+    //         shade: [0.3, '#393D49'],
+    //         callback:function(value){
+    //             location.replace(location.href);
+    //         }
+    //     };
+    //     Fast.api.open('commodity/commodity/addparameter?c_id='+c_id,msg,options);
+    // });
+    $(document).on("click", ".btn-dell", function () {
+        var colorid = $(this).attr('data-title')
+        //alert(colorid)
+        layer.confirm('确定删除吗?', {btn: ['是','否'] },
+            function () {
+                Fast.api.ajax({
+                    url: 'commodity/commodity/delcolor',
+                    data: {colorid: colorid},
+                    type: "POST"
+                    , success: function (data, ret) {
+                        //成功的回调
+                        layer.msg(ret.msg)
+                        location.replace(location.href);
+                        return false;
+                    },
+                    error: function (data, ret) {
+                        return false;
+                    }
+                })
+            }
+        )
+
+    });
+    $(document).on("click", ".btn-addd", function () {
+        var p_id = $(this).attr('data-title')
         var msg = "配置添加";
         var options = {
             shadeClose: false,
             shade: [0.3, '#393D49'],
             callback:function(value){
-               loaction.href="commodity/commodity/index"
+                $(".btn-refresh").trigger('click')
             }
         };
-        Fast.api.open('commodity/commodity/addparameter?c_id='+c_id,msg,options);
+        Fast.api.open('commodity/commodity/addcolor?p_id='+p_id,msg,options);
+
     });
-    $(document).on("click", ".btn-del", function () {
+    $(document).on("click", ".btn-editt", function () {
         var colorid = $(this).attr('data-title')
-        layer.confirm('确定删除吗?', {btn: ['是','否'] })
-        // Fast.api.ajax({
-        //     url:'commodity/commodity'+colorid,
-        //     data:{name:"名称"}
-        // }, function(data, ret){
-        //     //成功的回调
-        //     alert(ret.msg);
-        //     return false;
-        // }, function(data, ret){
-        //     //失败的回调
-        //     alert(ret.msg);
-        //     return false;
-        // });
+        var msg = "配置添加";
+        var options = {
+            shadeClose: false,
+            shade: [0.3, '#393D49'],
+            callback:function(value){
+                $(".btn-refresh").trigger('click')
+            }
+        };
+        Fast.api.open('commodity/commodity/editcolor?colorid='+colorid,msg,options);
     });
     Form.api.bindevent($("form[role=form]"), function(data, ret){
         //这里是表单提交处理成功后的回调函数,接收来自php的返回数据
-        //Fast.api.close(data);//这里是重点
+        Fast.api.close(data);//这里是重点
         Toastr.success("成功");//这个可有可无
     }, function(data, ret){
         Toastr.success("失败");
@@ -78,7 +110,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                                     icon: 'fa fa-list',
                                     url: "commodity/commodity/commodityInfo",
                                     callback: function (data) {
-                                        Layer.alert("接收到回传数据:" + JSON.stringify(data), {title: "回传数据"});
+                                        $(".btn-refresh").trigger('click')
                                     },
                                     visible: function (row) {
                                         //返回true时按钮显示,返回false隐藏
@@ -116,7 +148,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
             bindevent: function () {
                 Form.api.bindevent($("form[role=form]"));
             }
-        }
+        },
     };
     return Controller;
 });