WIN-2308041133\Administrator 5 days ago
parent
commit
48ca71c033
1 changed files with 140 additions and 119 deletions
  1. 140 119
      app/admin/view/store/store_product/index.php

+ 140 - 119
app/admin/view/store/store_product/index.php

@@ -3,24 +3,24 @@
 <div class="layui-fluid" style="background: #fff;margin-top: -10px;">
     <div class="layui-tab layui-tab-brief" lay-filter="tab">
         <ul class="layui-tab-title">
-            <li lay-id="list" {eq name='type' value='1'}class="layui-this" {/eq} >
-                <a href="{eq name='type' value='1'}javascript:;{else}{:Url('index',['type'=>1])}{/eq}">出售中商品({$onsale})</a>
+            <li lay-id="list" {eq name='type' value='1'}class="layui-this" {/eq}>
+            <a href="{eq name='type' value='1'}javascript:;{else}{:Url('index',['type'=>1])}{/eq}">出售中商品({$onsale})</a>
             </li>
             <li lay-id="list" {eq name='type' value='2'}class="layui-this" {/eq}>
-                <a href="{eq name='type' value='2'}javascript:;{else}{:Url('index',['type'=>2])}{/eq}">仓库中商品({$forsale})</a>
+            <a href="{eq name='type' value='2'}javascript:;{else}{:Url('index',['type'=>2])}{/eq}">仓库中商品({$forsale})</a>
             </li>
             <li lay-id="list" {eq name='type' value='4'}class="layui-this" {/eq}>
-                <a href="{eq name='type' value='4'}javascript:;{else}{:Url('index',['type'=>4])}{/eq}">已经售馨商品({$outofstock})</a>
+            <a href="{eq name='type' value='4'}javascript:;{else}{:Url('index',['type'=>4])}{/eq}">已经售馨商品({$outofstock})</a>
             </li>
             <li lay-id="list" {eq name='type' value='5'}class="layui-this" {/eq}>
-                <a href="{eq name='type' value='5'}javascript:;{else}{:Url('index',['type'=>5])}{/eq}">警戒库存({$policeforce})</a>
+            <a href="{eq name='type' value='5'}javascript:;{else}{:Url('index',['type'=>5])}{/eq}">警戒库存({$policeforce})</a>
             </li>
             <li lay-id="list" {eq name='type' value='6'}class="layui-this" {/eq}>
-                <a href="{eq name='type' value='6'}javascript:;{else}{:Url('index',['type'=>6])}{/eq}">商品回收站({$recycle})</a>
+            <a href="{eq name='type' value='6'}javascript:;{else}{:Url('index',['type'=>6])}{/eq}">商品回收站({$recycle})</a>
             </li>
         </ul>
     </div>
-    <div class="layui-row layui-col-space15"  id="app">
+    <div class="layui-row layui-col-space15" id="app">
         <div class="layui-col-md12">
             <div class="layui-card">
                 <div class="layui-card-body">
@@ -48,7 +48,7 @@
                                 <div class="layui-input-inline">
                                     <button class="layui-btn layui-btn-sm layui-btn-normal" lay-submit="search" lay-filter="search">
                                         <i class="layui-icon layui-icon-search"></i>搜索</button>
-                                    <button class="layui-btn layui-btn-primary layui-btn-sm export"  lay-submit="export" lay-filter="export">
+                                    <button class="layui-btn layui-btn-primary layui-btn-sm export" lay-submit="export" lay-filter="export">
                                         <i class="fa fa-floppy-o" style="margin-right: 3px;"></i>导出</button>
                                 </div>
                             </div>
@@ -72,9 +72,12 @@
                         <a class="layui-btn layui-btn-sm" href="{:Url('create')}">添加商品</a>
                         {/if}
                         {/case}
-                            {case value="2"}
-                                <button class="layui-btn layui-btn-sm" data-type="show">批量上架</button>
-                            {/case}
+                        {case value="2"}
+                        <button class="layui-btn layui-btn-sm" data-type="show">批量上架</button>
+                        {/case}
+                        {case value="6"}
+                        <!-- 在这里也可以根据需要添加判断 -->
+                        {/case}
                         {/switch}
                     </div>
                     <table class="layui-hide" id="List" lay-filter="List"></table>
@@ -84,7 +87,7 @@
                     </script>
                     <!--上架|下架-->
                     <script type="text/html" id="checkboxstatus">
-                        <input type='checkbox' name='id' lay-skin='switch' value="{{d.id}}" lay-filter='is_show' lay-text='上架|下架'  {{ d.is_show == 1 ? 'checked' : '' }}>
+                        <input type='checkbox' name='id' lay-skin='switch' value="{{d.id}}" lay-filter='is_show' lay-text='上架|下架' {{ d.is_show == 1 ? 'checked' : '' }}>
                     </script>
                     <!--收藏-->
                     <script type="text/html" id="like">
@@ -98,7 +101,7 @@
                     <script type="text/html" id="store_name">
                         <h4>{{d.store_name}}</h4>
                         <p>价格:<font color="red">{{d.price}}</font> </p>
-                        {{# if(d.cate_name!=''){ }}
+                        {{# if(d.cate_name != ''){ }}
                         <p>分类:{{d.cate_name}}</p>
                         {{# } }}
                     </script>
@@ -131,7 +134,6 @@
                             </li>
                         </ul>
                     </script>
-                    </script>
                 </div>
             </div>
         </div>
@@ -139,203 +141,222 @@
 </div>
 <script src="{__ADMIN_PATH}js/layuiList.js"></script>
 <script>
-    var type=<?=$type?>;
-    //实例化form
+    var type = <?=$type?>;
+    var mer_id = <?=$mer_id?>; // 从后端传递的mer_id值
+
+    // 实例化form
     layList.form.render();
-    //加载列表
-    layList.tableList('List',"{:Url('product_ist',['type'=>$type])}",function (){
-        var join=new Array();
-        switch (parseInt(type)){
-            case 1:case 3:case 4:case 5:
-                join=[
-                    {field: 'id', title: 'ID', sort: true,event:'id',width:'6%'},
-                    {field: 'image', title: '商品图片',templet:'#image',width:'10%'},
-                    {field: 'store_name', title: '商品名称',templet:'#store_name'},
-                    {field: 'ficti', title: '虚拟销量',edit:'ficti',width:'8%'},
-                    {field: 'mer_name', title: '门店',edit:'mer_name',width:'8%'},
-                    {field: 'stock', title: '库存',width:'8%'},
-                    {field: 'sort', title: '排序',edit:'sort',width:'6%'},
-                    {field: 'sales', title: '销量',sort: true,event:'sales',width:'8%'},
-                    {field: 'status', title: '状态',templet:"#checkboxstatus",width:'8%'},
-                    {field: 'right', title: '操作',align:'center',toolbar:'#act',width:'14%'},
+    // 加载列表
+    layList.tableList('List', "{:Url('product_ist',['type'=>$type])}", function () {
+        var join = new Array();
+        switch (parseInt(type)) {
+            case 1:
+            case 3:
+            case 4:
+            case 5:
+                join = [
+                    {field: 'id', title: 'ID', sort: true, event: 'id', width: '6%'},
+                    {field: 'image', title: '商品图片', templet: '#image', width: '10%'},
+                    {field: 'store_name', title: '商品名称', templet: '#store_name'},
+                    {field: 'ficti', title: '虚拟销量', edit: 'ficti', width: '8%'},
+                    {field: 'mer_name', title: '门店', edit: 'mer_name', width: '8%'},
+                    {field: 'stock', title: '库存', width: '8%'},
+                    {field: 'sort', title: '排序', edit: 'sort', width: '6%'},
+                    {field: 'sales', title: '销量', sort: true, event: 'sales', width: '8%'},
+                    {field: 'status', title: '状态', templet: "#checkboxstatus", width: '8%'},
+                    {field: 'right', title: '操作', align: 'center', toolbar: '#act', width: '14%'},
                 ];
                 break;
             case 2:
-                join=[
-                    {type:'checkbox'},
-                    {field: 'id', title: 'ID', sort: true,event:'id',width:'6%'},
-                    {field: 'image', title: '商品图片',templet:'#image',width:'10%'},
-                    {field: 'store_name', title: '商品名称',templet:'#store_name'},
-                    {field: 'price', title: '价格',edit:'price',width:'8%'},
-                    {field: 'ficti', title: '虚拟销量',edit:'ficti',width:'8%'},
-                    {field: 'mer_name', title: '门店',edit:'mer_name',width:'8%'},
-                    {field: 'stock', title: '库存',width:'6%'},
-                    {field: 'sort', title: '排序',edit:'sort',width:'6%'},
-                    {field: 'sales', title: '销量',sort: true,event:'sales',width:'6%'},
-                    {field: 'status', title: '状态',templet:"#checkboxstatus",width:'8%'},
-                    {field: 'right', title: '操作',align:'center',toolbar:'#act',width:'14%'},
+                join = [
+                    {type: 'checkbox'},
+                    {field: 'id', title: 'ID', sort: true, event: 'id', width: '6%'},
+                    {field: 'image', title: '商品图片', templet: '#image', width: '10%'},
+                    {field: 'store_name', title: '商品名称', templet: '#store_name'},
+                    {field: 'price', title: '价格', edit: 'price', width: '8%'},
+                    {field: 'ficti', title: '虚拟销量', edit: 'ficti', width: '8%'},
+                    {field: 'mer_name', title: '门店', edit: 'mer_name', width: '8%'},
+                    {field: 'stock', title: '库存', width: '6%'},
+                    {field: 'sort', title: '排序', edit: 'sort', width: '6%'},
+                    {field: 'sales', title: '销量', sort: true, event: 'sales', width: '6%'},
+                    {field: 'status', title: '状态', templet: "#checkboxstatus", width: '8%'},
+                    {field: 'right', title: '操作', align: 'center', toolbar: '#act', width: '14%'},
                 ];
                 break;
             case 6:
-                join=[
-                    {field: 'id', title: '商品ID', sort: true,event:'id'},
-                    {field: 'image', title: '商品图片',templet:'#image'},
-                    {field: 'store_name', title: '商品名称',templet:'#store_name'},
-                    {field: 'price', title: '商品价格',edit:'price'},
-                    {field: 'ficti', title: '虚拟销量',edit:'ficti'},
-                    {field: 'mer_name', title: '门店',edit:'mer_name',width:'8%'},
+                join = [
+                    {field: 'id', title: '商品ID', sort: true, event: 'id'},
+                    {field: 'image', title: '商品图片', templet: '#image'},
+                    {field: 'store_name', title: '商品名称', templet: '#store_name'},
+                    {field: 'price', title: '商品价格', edit: 'price'},
+                    {field: 'ficti', title: '虚拟销量', edit: 'ficti'},
+                    {field: 'mer_name', title: '门店', edit: 'mer_name', width: '8%'},
                     {field: 'stock', title: '库存'},
-                    {field: 'sort', title: '排序',edit:'sort'},
-                    {field: 'sales', title: '销量',sort: true,event:'sales'},
-//                    {field: 'status', title: '状态',templet:"#checkboxstatus"},
-                    {field: 'right', title: '操作',align:'center',toolbar:'#act',width:'14%'},
+                    {field: 'sort', title: '排序', edit: 'sort'},
+                    {field: 'sales', title: '销量', sort: true, event: 'sales'},
+                    {field: 'right', title: '操作', align: 'center', toolbar: '#act', width: '14%'},
                 ];
                 break;
         }
         return join;
-    })
-    //excel下载
-    layList.search('export',function(where){
+    });
+
+    // excel下载
+    layList.search('export', function (where) {
         where.excel = 1;
-        location.href=layList.U({c:'store.store_product',a:'product_ist',q:where});
-    })
-    //下拉框
+        location.href = layList.U({c: 'store.store_product', a: 'product_ist', q: where});
+    });
+
+    // 下拉框
     $(document).click(function (e) {
         $('.layui-nav-child').hide();
-    })
-    function dropdown(that){
+    });
+
+    function dropdown(that) {
         var oEvent = arguments.callee.caller.arguments[0] || event;
         oEvent.stopPropagation();
         var offset = $(that).offset();
-        var top=offset.top-$(window).scrollTop();
+        var top = offset.top - $(window).scrollTop();
         var index = $(that).parents('tr').data('index');
         $('.layui-nav-child').each(function (key) {
             if (key != index) {
                 $(this).hide();
             }
-        })
-        if($(document).height() < top+$(that).next('ul').height()){
+        });
+        if ($(document).height() < top + $(that).next('ul').height()) {
             $(that).next('ul').css({
                 'padding': 10,
-                'top': - ($(that).parent('td').height() / 2 + $(that).height() + $(that).next('ul').height()/2),
+                'top': - ($(that).parent('td').height() / 2 + $(that).height() + $(that).next('ul').height() / 2),
                 'min-width': 'inherit',
                 'position': 'absolute'
             }).toggle();
-        }else{
+        } else {
             $(that).next('ul').css({
                 'padding': 10,
-                'top':$(that).parent('td').height() / 2 + $(that).height(),
+                'top': $(that).parent('td').height() / 2 + $(that).height(),
                 'min-width': 'inherit',
                 'position': 'absolute'
             }).toggle();
         }
     }
-    //快速编辑
+
+    // 快速编辑
     layList.edit(function (obj) {
-        var id=obj.data.id,value=obj.value;
+        var id = obj.data.id, value = obj.value;
         switch (obj.field) {
             case 'price':
-                action.set_product('price',id,value);
+                action.set_product('price', id, value);
                 break;
             case 'stock':
-                action.set_product('stock',id,value);
+                action.set_product('stock', id, value);
                 break;
             case 'sort':
-                action.set_product('sort',id,value);
+                action.set_product('sort', id, value);
                 break;
             case 'ficti':
-                action.set_product('ficti',id,value);
+                action.set_product('ficti', id, value);
                 break;
         }
     });
-    //上下加商品
-    layList.switch('is_show',function (odj,value) {
-        if(odj.elem.checked==true){
-            layList.baseGet(layList.Url({c:'store.store_product',a:'set_show',p:{is_show:1,id:value}}),function (res) {
+
+    // 上下加商品
+    layList.switch('is_show', function (odj, value) {
+        if (odj.elem.checked == true) {
+            layList.baseGet(layList.Url({c: 'store.store_product', a: 'set_show', p: {is_show: 1, id: value}}), function (res) {
                 layList.msg(res.msg, function () {
                     layList.reload();
                 });
             });
-        }else{
-            layList.baseGet(layList.Url({c:'store.store_product',a:'set_show',p:{is_show:0,id:value}}),function (res) {
+        } else {
+            layList.baseGet(layList.Url({c: 'store.store_product', a: 'set_show', p: {is_show: 0, id: value}}), function (res) {
                 layList.msg(res.msg, function () {
                     layList.reload();
                 });
             });
         }
     });
-    //点击事件绑定
-    layList.tool(function (event,data,obj) {
+
+    // 点击事件绑定
+    layList.tool(function (event, data, obj) {
         switch (event) {
             case 'delstor':
-                var url=layList.U({c:'store.store_product',a:'delete',q:{id:data.id}});
-                if(data.is_del) var code = {title:"操作提示",text:"确定恢复商品操作吗?",type:'info',confirm:'是的,恢复该商品'};
-                else var code = {title:"操作提示",text:"确定将该商品移入回收站吗?",type:'info',confirm:'是的,移入回收站'};
-                $eb.$swal('delete',function(){
-                    $eb.axios.get(url).then(function(res){
-                        if(res.status == 200 && res.data.code == 200) {
-                            $eb.$swal('success',res.data.msg);
+                var url = layList.U({c: 'store.store_product', a: 'delete', q: {id: data.id}});
+                if (data.is_del) var code = {title: "操作提示", text: "确定恢复商品操作吗?", type: 'info', confirm: '是的,恢复该商品'};
+                else var code = {title: "操作提示", text: "确定将该商品移入回收站吗?", type: 'info', confirm: '是的,移入回收站'};
+                $eb.$swal('delete', function () {
+                    $eb.axios.get(url).then(function (res) {
+                        if (res.status == 200 && res.data.code == 200) {
+                            $eb.$swal('success', res.data.msg);
                             obj.del();
                             location.reload();
-                        }else
-                            return Promise.reject(res.data.msg || '删除失败')
-                    }).catch(function(err){
-                        $eb.$swal('error',err);
+                        } else {
+                            return Promise.reject(res.data.msg || '删除失败');
+                        }
+                    }).catch(function (err) {
+                        $eb.$swal('error', err);
                     });
-                },code)
+                }, code);
                 break;
             case 'open_image':
                 $eb.openImage(data.image);
                 break;
             case 'edit':
-                location.href = layList.U({a:'create',q:{id:data.id}});
+                if (mer_id <= 0) { // 在前端也进行判断
+                    location.href = layList.U({a: 'create', q: {id: data.id}});
+                } else {
+                    layList.msg('您没有权限编辑此商品');
+                }
                 break;
             case 'attr':
-                $eb.createModalFrame(data.store_name+'-属性',layList.U({a:'attr',q:{id:data.id}}),{h:600,w:800})
+                $eb.createModalFrame(data.store_name + '-属性', layList.U({a: 'attr', q: {id: data.id}}), {h: 600, w: 800});
                 break;
         }
-    })
-    //排序
+    });
+
+    // 排序
     layList.sort(function (obj) {
         var type = obj.type;
-        switch (obj.field){
+        switch (obj.field) {
             case 'id':
-                layList.reload({order: layList.order(type,'p.id')},true,null,obj);
+                layList.reload({order: layList.order(type, 'p.id')}, true, null, obj);
                 break;
             case 'sales':
-                layList.reload({order: layList.order(type,'p.sales')},true,null,obj);
+                layList.reload({order: layList.order(type, 'p.sales')}, true, null, obj);
                 break;
         }
     });
-    //查询
-    layList.search('search',function(where){
-        layList.reload(where,true);
+
+    // 查询
+    layList.search('search', function (where) {
+        layList.reload(where, true);
     });
-    //自定义方法
-    var action={
-        set_product:function(field,id,value){
-            layList.baseGet(layList.Url({c:'store.store_product',a:'set_product',q:{field:field,id:id,value:value}}),function (res) {
+
+    // 自定义方法
+    var action = {
+        set_product: function (field, id, value) {
+            layList.baseGet(layList.Url({c: 'store.store_product', a: 'set_product', q: {field: field, id: id, value: value}}), function (res) {
                 layList.msg(res.msg);
             });
         },
-        show:function(){
-            var ids=layList.getCheckData().getIds('id');
-            if(ids.length){
-                layList.basePost(layList.Url({c:'store.store_product',a:'product_show'}),{ids:ids},function (res) {
+        show: function () {
+            var ids = layList.getCheckData().getIds('id');
+            if (ids.length) {
+                layList.basePost(layList.Url({c: 'store.store_product', a: 'product_show'}), {ids: ids}, function (res) {
                     layList.msg(res.msg);
                     layList.reload();
                 });
-            }else{
+            } else {
                 layList.msg('请选择要上架的商品');
             }
         }
     };
-    //多选事件绑定
+
+    // 多选事件绑定
     $('.layui-btn-container').find('button').each(function () {
-        var type=$(this).data('type');
-        $(this).on('click',function(){
+        var type = $(this).data('type');
+        $(this).on('click', function () {
             action[type] && action[type]();
-        })
+        });
     });
 </script>
 {/block}