18315626215 5 years ago
parent
commit
b603f43411

+ 53 - 1
application/admin/controller/commodity/Commodity.php

@@ -86,7 +86,7 @@ class Commodity extends Backend
             $params = $this->request->post("row/a");
             if ($params) {
                 $params = $this->preExcludeFields($params);
-                halt($params);
+                //halt($params);
                 if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
                     $params[$this->dataLimitField] = $this->auth->id;
                 }
@@ -176,6 +176,58 @@ class Commodity extends Backend
         $this->view->assign("ctype", $ctype);
         return $this->view->fetch();
     }
+    //显示规格
     public function commodityInfo ($ids='') {
+        if ($this->request->isPost()) {
+            $data = $this->request->post("row/a");
+            $list['p_name'] = $data['p_name'];
+            $list['c_id'] = $data['c_id'];
+            if ($data['content'] == '') {
+                return $this->error('请至少添加一项颜色',null,$data);
+            }
+            $data['content'] = json_decode($data['content'],true);
+            $id=Db::name('parameter')->insertGetId($list);
+            if ($data['content'] != '') {
+                foreach ($data['content'] as &$v) {
+                    $color['money'] = $v['money'];
+                    $color['kucun'] = $v['kucun'];
+                    $color['name']  = $v['name'];
+                    $color['p_id']  = $id;
+                    $color['color'] = '';
+                    //halt($color);
+                    $addcolor = Db::name('commoditycolor')->insert($color);
+                }
+            }
+            if ($id) {
+              return  $this->success('success',null,$data);
+            }
+        }
+        $parameter = Db::name('parameter')->where('c_id',$ids)->select();
+        foreach ($parameter as &$v) {
+            $v['color'] = Db::name('commoditycolor')->where('p_id',$v['p_id'])->select();
+        }
+        //halt($parameter);
+        if ($parameter) {
+            return $this->fetch('commodityinfo',['parameter' => $parameter, 'c_id' => $ids]);
+        } else {
+            $parameter = [];
+            return $this->fetch('commodityinfo',['parameter' => $parameter, 'c_id' => $ids]);
+        }
+    }
+    //添加颜规格
+    public function addparameter ($ids='') {
+//        if ($this->request->isPost()) {
+//            $data = $this->request->post("row/a");
+//            echo $data['c_name'];die;
+//            $add=Db::name('parameter')->insert($data);
+//            if ($add) {
+//              return  $this->success('success',null,$data);
+//            }
+//        }
+    }
+    //删除颜色
+    public function delcolor () {
+        $id = input('colorid');
+        echo $id;
     }
 }

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

@@ -0,0 +1,18 @@
+<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>

+ 76 - 0
application/admin/view/commodity/commodity/commodityinfo.html

@@ -0,0 +1,76 @@
+<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  data-rule="required" class="form-control" name="row[p_name]" type="text" >
+            <input  data-rule="required" class="form-control" name="row[c_id]" type="hidden"  value="{$c_id}">
+            <dl class="fieldlist" data-name="row[content]" data-template="fieldtpl">
+                <dd>
+                    <ins>颜色名</ins>
+                    <ins>库存</ins>
+                    <ins>价格</ins>
+                </dd>
+                <dd><a href="javascript:;" class="btn btn-sm btn-success btn-append"><i class="fa fa-plus"></i> {:__('Append')}</a></dd>
+                <textarea name="row[content]" class="form-control hide" cols="30" rows="5"></textarea>
+            </dl>
+        </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>
+</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>
+    </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>
+    </tr>
+    {/volist}
+    {/volist}
+</table>
+
+<!--以下是自定义模板的内容-->
+<script id="fieldtpl">
+    <dd class="form-inline">
+        <input type="text" name="<%=name%>[<%=index%>][name]" class="form-control" value="<%=row.id%>" size="10" />
+        <input type="text" name="<%=name%>[<%=index%>][kucun]" class="form-control" value="<%=row.name%>" size="10" />
+        <input type="text" name="<%=name%>[<%=index%>][money]" class="form-control" value="<%=row.name%>" size="10" />
+        <span class="btn btn-sm btn-danger btn-remove"><i class="fa fa-times"></i></span>
+        <span class="btn btn-sm btn-primary btn-dragsort"><i class="fa fa-arrows"></i></span>
+    </dd>
+</script>
+
+<!--<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">-->
+<!--    {volist name="parameter" id="item"}-->
+<!--    <div class="form-group">-->
+<!--        <label class="control-label col-xs-12 col-sm-2">配置:</label>-->
+<!--        <div class="col-xs-12 col-sm-8">-->
+<!--            <input  data-rule="required" class="form-control" name="row[c_name]" type="text" value="{$item.p_name}">-->
+<!--        </div>-->
+<!--    </div>-->
+<!--    {/volist}-->
+<!--    <input  data-rule="required" class="form-control" id="eeeee" name="c_id" type="hidden" value="{$c_id}">-->
+<!--    <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">-->
+<!--&lt;!&ndash;            <a href="commodity/addcolor?c_id={$c_id}" class="btn btn-success btn-edit " title="添加"><i class="fa fa-plus"></i> 添加</a>&ndash;&gt;-->
+<!--            <a href="javascript:;" class="btn btn-success btn-aaaa " data-title="{$c_id}"><i class="fa fa-plus"></i> 添加</a>-->
+<!--        </div>-->
+<!--    </div>-->
+<!--</form>-->

+ 38 - 2
public/assets/js/backend/commodity/commodity.js

@@ -1,5 +1,41 @@
 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');
+        var msg = "配置添加";
+        var options = {
+            shadeClose: false,
+            shade: [0.3, '#393D49'],
+            callback:function(value){
+               loaction.href="commodity/commodity/index"
+            }
+        };
+        Fast.api.open('commodity/commodity/addparameter?c_id='+c_id,msg,options);
+    });
+    $(document).on("click", ".btn-del", 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;
+        // });
+    });
+    Form.api.bindevent($("form[role=form]"), function(data, ret){
+        //这里是表单提交处理成功后的回调函数,接收来自php的返回数据
+        //Fast.api.close(data);//这里是重点
+        Toastr.success("成功");//这个可有可无
+    }, function(data, ret){
+        Toastr.success("失败");
+    });
     var Controller = {
         index: function () {
             // 初始化表格参数配置
@@ -37,7 +73,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                                 {
                                     name: 'detail',
                                     text: __('点击修改商品配置'),
-                                    title: __('购买详情'),
+                                    title: __('配置详情'),
                                     classname: 'btn btn-xs btn-primary btn-dialog',
                                     icon: 'fa fa-list',
                                     url: "commodity/commodity/commodityInfo",