505 lines
21 KiB
PHP
505 lines
21 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' => '已启用',
|
||
];
|
||
$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="cat_id">
|
||
<option value="" <?= $cat_id === null ? 'selected' : '' ?>>全部分类</option>
|
||
<?php foreach ($cat_list as $index => $item): ?>
|
||
<option value="<?= $item['id'] ?>" <?= $cat_id == $item['id'] && $cat_id != null ? 'selected' : '' ?>><?= $item['name'] ?></option>
|
||
<?php endforeach; ?>
|
||
</select>
|
||
</div>
|
||
</div>
|
||
<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">
|
||
<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 class="layui-inline">
|
||
<button class="layui-btn layuiadmin-btn-useradmin" lay-submit lay-filter="dtable-export"
|
||
title="导出">
|
||
<i class="layui-icon layui-icon-export 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>-->
|
||
<?php if (!$isWarehouseKeeper): ?>
|
||
<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>
|
||
<?php endif; ?>
|
||
</div>
|
||
</script>
|
||
<!--行操作列模板-->
|
||
<script type="text/html" id="rowBarTpl">
|
||
<?php if (!$isWarehouseKeeper): ?>
|
||
<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>
|
||
{{# } }}
|
||
<?php endif; ?>
|
||
</script>
|
||
|
||
<script type="text/html" id="nameTpl">
|
||
<img src="{{d.cover_pic}}" style="width:40px;height:40px;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 type="text/html" id="catListTpl1">
|
||
{{# layui.each(d.cat1_list, function(index, item){ }}
|
||
<span class="layui-badge layui-bg-blue">{{item.name}}</span>
|
||
{{# }); }}
|
||
</script>
|
||
|
||
|
||
<script type="text/html" id="catListTpl2">
|
||
{{# layui.each(d.cat2_list, function(index, item){ }}
|
||
<span class="layui-badge layui-bg-blue">{{item.name}}</span>
|
||
{{# }); }}
|
||
</script>
|
||
|
||
|
||
<script type="text/html" id="catListTpl3">
|
||
{{# layui.each(d.cat3_list, function(index, item){ }}
|
||
<span class="layui-badge layui-bg-blue">{{item.name}}</span>
|
||
{{# }); }}
|
||
</script>
|
||
|
||
|
||
<script type="text/html" id="catListTpl4">
|
||
{{# layui.each(d.cat4_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'
|
||
});
|
||
//export
|
||
form.on('submit(dtable-export)', function (data) {
|
||
var formData = data.field;
|
||
formData._csrf = _csrf;
|
||
$.ajax({
|
||
type: "post",
|
||
url: "<?= \Yii::$app->urlManager->createUrl(["/admin/mall/goods/export"]) ?>",
|
||
data: formData,
|
||
dataType: "json",
|
||
success: function (data) {
|
||
if (data.code == 0) {
|
||
var href = "<?= \Yii::$app->urlManager->createUrl(["/admin/mall/goods/export-file"]) ?>" + "?tmp_file_id=" + data.data.tmp_file_id;
|
||
var dl_id = "dl_" + (new Date()).getTime();
|
||
var a_html = '<a href="' + href + '" id="' + dl_id + '" class="dl-tmp-file" target="_blank" ></a>';
|
||
$("body").append(a_html);
|
||
setTimeout(function () {
|
||
var dl_eles = document.body.querySelectorAll(".dl-tmp-file");
|
||
dl_eles[0].click();
|
||
setTimeout(function () {
|
||
document.body.removeChild(dl_eles[0]);
|
||
}, 1000);
|
||
}, 1000);
|
||
} else {
|
||
layer.msg(data.msg, {
|
||
offset: '15px'
|
||
, icon: 2
|
||
, time: 1000
|
||
}, function () {
|
||
});
|
||
}
|
||
}
|
||
});
|
||
return false;
|
||
});
|
||
|
||
//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', width: 180}
|
||
// , {field: 'attr_info', title: '规格', width: 120}
|
||
, {field: 'cat_list', title: '冠军级别', width: 120, templet: '#catListTpl'}
|
||
, {field: 'cat1_list', title: '冠军分类', width: 120, templet: '#catListTpl1'}
|
||
, {field: 'cat2_list', title: '签约价格', width: 120, templet: '#catListTpl2'}
|
||
, {field: 'cat3_list', title: '冠军性别', width: 120, templet: '#catListTpl3'}
|
||
, {field: 'cat4_list', title: '业务类型', width: 120, templet: '#catListTpl4'}
|
||
, {field: 'price', title: '签约价格', width: 100}
|
||
, {field: 'sort', title: '排序', width: 60}
|
||
, {field: 'date_at_cn', title: '出生日期', width: 120}
|
||
|
||
// , {field: 'goods_stock', title: '库存', width: 100}
|
||
// , {field: 'available_stock', title: '可用库存', width: 100}
|
||
// , {field: 'w_im_wh_num', title: '待入库数量', width: 100}
|
||
// , {field: 'w_ex_wh_num', title: '待出库数量', width: 100}
|
||
// , {field: 'sort', title: '排序', width: 60}
|
||
// , {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: 180}
|
||
]
|
||
]
|
||
, url: '<?=\Yii::$app->urlManager->createUrl(['admin/mall/goods/index'])?>'
|
||
, page: true
|
||
//指向自定义工具栏模板选择器
|
||
, toolbar: '#toolBarTpl'
|
||
//头部工具栏右侧的图标按钮
|
||
, defaultToolbar: ['filter', 'print']
|
||
, 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); ?>
|
||
|