409 lines
17 KiB
PHP
409 lines
17 KiB
PHP
<?php
|
||
|
||
/**
|
||
* @author Any
|
||
* @description KISS
|
||
* @date 2021年10月5日
|
||
* @version 1.0.0
|
||
*
|
||
* _____LOG_____
|
||
*
|
||
*/
|
||
use yii\widgets\LinkPager;
|
||
use app\models\msg\SysMsg;
|
||
|
||
$this->title = '商品列表';
|
||
$this->params['breadcrumbs'][] = $this->title;
|
||
|
||
$status_labels = [
|
||
'0' => '已下架',
|
||
'1' => '已上架',
|
||
'2' => '已售罄',
|
||
];
|
||
$status = \Yii::$app->request->get('status');
|
||
$cat_id = \Yii::$app->request->get('cat_id');
|
||
?>
|
||
<style type="text/css">
|
||
.layui-table-cell {
|
||
height: auto;
|
||
}
|
||
</style>
|
||
<div class="layui-fluid">
|
||
<div class="layui-card">
|
||
<div class="layui-card-header">
|
||
<?= $this->title ?>
|
||
</div>
|
||
<div class="layui-card-header layuiadmin-card-header-auto">
|
||
<div class="layui-form-item">
|
||
<div class="layui-inline">
|
||
<a class=" layui-btn" href="<?=\Yii::$app->urlManager->createUrl(["admin/mall/goods/edit"])?>">添加商品</a>
|
||
</div>
|
||
<div class="layui-inline layui-float-right layui-form">
|
||
|
||
<div class="layui-inline layui-form-item">
|
||
<div class="layui-input-inline">
|
||
<select class="layui-select" name="status">
|
||
<option value="" <?=$status === null ? 'selected' : ''?>>全部状态</option>
|
||
<?php foreach ($status_labels as $key => $val):?>
|
||
<option value="<?=$key?>" <?=$status == $key && $status != null ? 'selected' : ''?>><?=$val?></option>
|
||
<?php endforeach;?>
|
||
</select>
|
||
</div>
|
||
</div>
|
||
<div class="layui-form-item layui-inline">
|
||
<label class="layui-form-label">添加时间</label>
|
||
<div class="layui-inline" id="datetimeRange">
|
||
<div class="layui-input-inline">
|
||
<input type="text" autocomplete="off" name="start_time" id="startTime" class="layui-input" placeholder="开始日期">
|
||
</div>
|
||
<div class="layui-form-mid">-</div>
|
||
<div class="layui-input-inline">
|
||
<input type="text" autocomplete="off" name="end_time" id="endTime" class="layui-input" placeholder="结束日期">
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="layui-inline layui-form-item">
|
||
<label class="layui-form-label">关键词</label>
|
||
<div class="layui-input-block">
|
||
<input type="text" name="keywords" placeholder="搜索标题" autocomplete="off" class="layui-input" value="<?=\Yii::$app->request->get("keywords")?>">
|
||
</div>
|
||
</div>
|
||
<div class="layui-inline">
|
||
<button class="layui-btn layuiadmin-btn-useradmin" lay-submit lay-filter="dtable-search">
|
||
<i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
|
||
</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="layui-card-body">
|
||
<table id="dtable" lay-filter="dtable"></table>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!--工具栏模板-->
|
||
<script type="text/html" id="toolBarTpl">
|
||
<div class="layui-btn-container">
|
||
<!--<button class="layui-btn layui-btn-sm" lay-event="add">添加</button>-->
|
||
<button class="layui-btn layui-btn-sm layui-btn-normal" lay-event="batch_online">批量上架</button>
|
||
<button class="layui-btn layui-btn-sm layui-btn-warm" lay-event="batch_offline">批量下架</button>
|
||
<button class="layui-btn layui-btn-sm layui-btn-danger" lay-event="batch_delete">批量删除</button>
|
||
</div>
|
||
</script>
|
||
<!--行操作列模板-->
|
||
<script type="text/html" id="rowBarTpl">
|
||
<button class="layui-btn layui-btn-xs" lay-event="edit">编辑</button>
|
||
{{# if(d.status == 0){ }}
|
||
<button class="layui-btn layui-btn-xs layui-btn-normal" lay-event="online">上架</button>
|
||
<button class="layui-btn layui-btn-xs layui-btn-danger" lay-event="delete">删除</button>
|
||
{{# } }}
|
||
{{# if(d.status == 1){ }}
|
||
<button class="layui-btn layui-btn-xs layui-btn-warm" lay-event="offline">下架</button>
|
||
{{# } }}
|
||
</script>
|
||
|
||
<script type="text/html" id="nameTpl">
|
||
<img src="{{d.cover_pic}}" style="width:40px;height:30px;margin-right: 4px;">{{d.name}}
|
||
</script>
|
||
<script type="text/html" id="salesTpl">
|
||
{{d.virtual_sales}}+{{d.sales}}
|
||
</script>
|
||
<script type="text/html" id="statusTpl">
|
||
{{# if(d.status == 1){ }}
|
||
<span class="layui-badge layui-bg-green">{{d.status_cn}}</span>
|
||
{{# }else{ }}
|
||
<span class="layui-badge layui-bg-gray">{{d.status_cn}}</span>
|
||
{{# } }}
|
||
</script>
|
||
|
||
<script type="text/html" id="catListTpl">
|
||
{{# layui.each(d.cat_list, function(index, item){ }}
|
||
<span class="layui-badge layui-bg-blue">{{item.name}}</span>
|
||
{{# }); }}
|
||
</script>
|
||
|
||
<script>
|
||
<?php $this->beginBlock('js_script_wrap') ?>
|
||
layui.config({
|
||
base: '/statics/layuiadmin/' //静态资源所在路径
|
||
}).extend({
|
||
index: 'lib/index' //主入口模块
|
||
}).use(['index', 'user', 'table', 'laydate'], function () {
|
||
var $ = layui.$
|
||
, form = layui.form
|
||
, table = layui.table
|
||
, admin = layui.admin
|
||
, laydate = layui.laydate;
|
||
form.render();
|
||
//日期范围
|
||
laydate.render({
|
||
elem: '#startTime'
|
||
,type: 'datetime'
|
||
});
|
||
laydate.render({
|
||
elem: '#endTime'
|
||
,type: 'datetime'
|
||
});
|
||
//search
|
||
form.on('submit(dtable-search)', function (obj) {
|
||
var field = obj.field;
|
||
reload_table_data(field);
|
||
});
|
||
|
||
form.on('select(batch-action)', function (obj) {
|
||
var lay_event = obj.value;
|
||
var check_status = table.checkStatus('dtable');
|
||
var id = [];
|
||
$(check_status.data).each(function(index){
|
||
id.push(check_status.data[index]['id']);
|
||
});
|
||
|
||
var confirm_url = null;
|
||
var confirm_tip = null;
|
||
|
||
if(confirm_url != null){
|
||
layer.confirm(confirm_tip, {
|
||
btn: ['确定','取消']
|
||
}, function(){
|
||
$.ajax(confirm_url,{
|
||
type:"POST",
|
||
dataType:"json",
|
||
data:{
|
||
goods_id:id,
|
||
_csrf:_csrf
|
||
},
|
||
success:function(res){
|
||
if(res.code == 0){
|
||
layer.msg(res.msg, {
|
||
offset: '15px'
|
||
,icon: 1
|
||
,time: 1000
|
||
}, function(){
|
||
location.reload();
|
||
});
|
||
} else {
|
||
layer.msg(res.msg, {
|
||
offset: '15px'
|
||
,icon: 2
|
||
,time: 1000
|
||
}, function(){
|
||
});
|
||
}
|
||
},
|
||
error:function(xhr,type,err){
|
||
layer.msg(xhr.responseText, {
|
||
offset: '15px'
|
||
,icon: 2
|
||
,time: 1000
|
||
}, function(){
|
||
});
|
||
}
|
||
})
|
||
}, function(){
|
||
});
|
||
}
|
||
});
|
||
|
||
//重新加载表格数据
|
||
function reload_table_data(conf){
|
||
table.reload('dtable', {
|
||
url:'<?=\Yii::$app->urlManager->createUrl(['admin/mall/goods/index'])?>'
|
||
,page: true
|
||
,where: conf
|
||
});
|
||
};
|
||
|
||
//执行渲染
|
||
table.render({
|
||
//指定原始表格元素选择器(推荐id选择器)
|
||
elem: '#dtable'
|
||
//容器高度
|
||
//,height: 315
|
||
//容器宽度
|
||
//,width: 720
|
||
//设置表头
|
||
,cols: [[
|
||
{checkbox: true}
|
||
, {field: 'id', title: 'ID', width: 80}
|
||
, {field: 'name', title: '商品名称', templet:'#nameTpl', }
|
||
, {field: 'sort', title: '排序',width: 60 }
|
||
, {field: 'price', title: '售价',width: 100 }
|
||
, {field: 'goods_stock', title: '库存',width: 100 }
|
||
, {field: 'sales', title: '已售(虚拟+实际)', templet:'#salesTpl', width: 160 }
|
||
, {field: 'status_cn', title: '状态', width: 120, templet:'#statusTpl' }
|
||
, {field: 'created_at_cn', title: '添加时间', width: 180}
|
||
, {title: '操作',fixed: 'right', toolbar: '#rowBarTpl', width:200}
|
||
]
|
||
]
|
||
, url:'<?=\Yii::$app->urlManager->createUrl(['admin/mall/goods/index'])?>'
|
||
, page:true
|
||
//指向自定义工具栏模板选择器
|
||
, toolbar:'#toolBarTpl'
|
||
//头部工具栏右侧的图标按钮
|
||
, defaultToolbar:['filter', 'print', 'exports']
|
||
, limit: 20
|
||
, limits:[10,20,30,40,50,60,70,80,90,100]
|
||
, title:'<?=$this->title?>'
|
||
, data:[]
|
||
, done: function(res, curr, count){
|
||
setTimeout(function(){
|
||
$(".layui-table-main tr").each(function (index ,val) {
|
||
$(".layui-table-fixed").each(function () {
|
||
$($(this).find(".layui-table-body tbody tr")[index]).height($(val).height());
|
||
});
|
||
});
|
||
$(".layui-table-header tr").each(function (index ,val) {
|
||
$(".layui-table-fixed").each(function () {
|
||
$($(this).find(".layui-table-header thead tr")[index]).height($(val).height());
|
||
});
|
||
});
|
||
},500);
|
||
}
|
||
});
|
||
//监听工具栏
|
||
table.on('toolbar(dtable)', function(obj){
|
||
var lay_event = obj.event;
|
||
var check_status = table.checkStatus('dtable');
|
||
var id = [];
|
||
$(check_status.data).each(function(index){
|
||
id.push(check_status.data[index]['id']);
|
||
});
|
||
if(id.length == 0){
|
||
return layer.msg("请选择需要操作项");
|
||
}
|
||
|
||
var confirm_url = null;
|
||
var confirm_tip = null;
|
||
if(lay_event == 'batch_online'){
|
||
confirm_url = "<?=\Yii::$app->urlManager->createUrl(['admin/mall/goods/online'])?>";
|
||
confirm_tip = "确定上架选中商品吗";
|
||
}
|
||
if(lay_event == 'batch_offline'){
|
||
confirm_url = "<?=\Yii::$app->urlManager->createUrl(['admin/mall/goods/offline'])?>";
|
||
confirm_tip = "确定将选中商品下架吗";
|
||
}
|
||
if(lay_event == 'batch_delete'){
|
||
confirm_url = "<?=\Yii::$app->urlManager->createUrl(['admin/mall/goods/delete'])?>";
|
||
confirm_tip = "确定将选中商品删除吗";
|
||
}
|
||
|
||
if(confirm_url != null){
|
||
layer.confirm(confirm_tip, {
|
||
btn: ['确定','取消']
|
||
}, function(){
|
||
$.ajax(confirm_url,{
|
||
type:"POST",
|
||
dataType:"json",
|
||
data:{
|
||
goods_id:id,
|
||
_csrf:_csrf
|
||
},
|
||
success:function(res){
|
||
if(res.code == 0){
|
||
layer.msg(res.msg, {
|
||
offset: '15px'
|
||
,icon: 1
|
||
,time: 1000
|
||
}, function(){
|
||
location.reload();
|
||
});
|
||
} else {
|
||
layer.msg(res.msg, {
|
||
offset: '15px'
|
||
,icon: 2
|
||
,time: 1000
|
||
}, function(){
|
||
});
|
||
}
|
||
},
|
||
error:function(xhr,type,err){
|
||
layer.msg(xhr.responseText, {
|
||
offset: '15px'
|
||
,icon: 2
|
||
,time: 1000
|
||
}, function(){
|
||
});
|
||
}
|
||
})
|
||
}, function(){
|
||
});
|
||
}
|
||
});
|
||
|
||
//监听工具条
|
||
table.on('tool(dtable)', function(obj){
|
||
var row_data = obj.data;
|
||
var lay_event = obj.event;
|
||
var id = row_data.id;
|
||
|
||
if(lay_event == 'edit'){
|
||
var url = "<?=\Yii::$app->urlManager->createUrl(['admin/mall/goods/edit'])?>" + "?id=" + id;
|
||
location.href= url;
|
||
return;
|
||
}
|
||
|
||
var confirm_url = null;
|
||
var confirm_tip = null;
|
||
if(lay_event == "delete"){
|
||
confirm_url = "<?=\Yii::$app->urlManager->createUrl(['admin/mall/goods/delete'])?>";
|
||
confirm_tip = "确定删除此商品吗";
|
||
}
|
||
if(lay_event == "online"){
|
||
confirm_url = "<?=\Yii::$app->urlManager->createUrl(['admin/mall/goods/online'])?>";
|
||
confirm_tip = "确定上架此商品吗";
|
||
}
|
||
if(lay_event == "offline"){
|
||
confirm_url = "<?=\Yii::$app->urlManager->createUrl(['admin/mall/goods/offline'])?>";
|
||
confirm_tip = "确定下架此商品吗";
|
||
}
|
||
|
||
if(confirm_url != null){
|
||
layer.confirm(confirm_tip, {
|
||
btn: ['确定','取消']
|
||
}, function(){
|
||
$.ajax(confirm_url,{
|
||
type:"POST",
|
||
dataType:"json",
|
||
data:{
|
||
goods_id:id,
|
||
_csrf:_csrf
|
||
},
|
||
success:function(res){
|
||
if(res.code == 0){
|
||
layer.msg(res.msg, {
|
||
offset: '15px'
|
||
,icon: 1
|
||
,time: 1000
|
||
}, function(){
|
||
location.reload();
|
||
});
|
||
} else {
|
||
layer.msg(res.msg, {
|
||
offset: '15px'
|
||
,icon: 2
|
||
,time: 1000
|
||
}, function(){
|
||
});
|
||
}
|
||
},
|
||
error:function(xhr,type,err){
|
||
layer.msg(xhr.responseText, {
|
||
offset: '15px'
|
||
,icon: 2
|
||
,time: 1000
|
||
}, function(){
|
||
});
|
||
}
|
||
})
|
||
}, function(){
|
||
});
|
||
}
|
||
});
|
||
|
||
});
|
||
<?php $this->endBlock(); ?>
|
||
</script>
|
||
<?php $this->registerJs($this->blocks['js_script_wrap'], \yii\web\View::POS_END); ?>
|
||
|