430 lines
20 KiB
PHP
430 lines
20 KiB
PHP
<?php
|
||
|
||
/**
|
||
* @author Any
|
||
* @description KISS
|
||
* @date 2020-11-5
|
||
* @version 1.0.0
|
||
*
|
||
* _____LOG_____
|
||
*
|
||
*/
|
||
use yii\widgets\LinkPager;
|
||
use app\models\User;
|
||
|
||
$this->title = '云盒管理';
|
||
$this->params['breadcrumbs'][] = $this->title;
|
||
$status_labels = User::statusLabels();
|
||
$status = \Yii::$app->request->get('status');
|
||
?>
|
||
<div class="layui-fluid">
|
||
<div class="layui-card">
|
||
<div class="layui-card-header">
|
||
<?= $this->title ?>
|
||
</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-danger" lay-event="forbidden">批量封禁</button>-->
|
||
<!-- <button class="layui-btn layui-btn-sm" lay-event="cancel_forbidden">批量取消封禁</button>-->
|
||
<!--<button class="layui-btn layui-btn-sm layui-btn-danger" lay-event="hangup">批量挂起</button>-->
|
||
<!--<button class="layui-btn layui-btn-sm" lay-event="cancel_hangup">批量取消挂起</button>-->
|
||
<!-- <button class="layui-btn layui-btn-sm layui-btn-danger layui-hide" lay-event="account_logout">批量账号注销</button>-->
|
||
</div>
|
||
</script>
|
||
<!--行操作列模板-->
|
||
<script type="text/html" id="rowBarTpl">
|
||
<!-- <a href="javascript:;" class="layui-btn layui-btn-normal layui-btn-xs layui-hide" lay-event="recharge" >余额充值</a>-->
|
||
<!-- <a href="javascript:;" class="layui-btn layui-btn-normal layui-btn-xs layui-hide" lay-event="rechargeintegral" >积分充值</a>-->
|
||
<a href="javascript:;" class="layui-btn layui-btn-xs layui-btn-primary" lay-event="get_opendoor_qrcode">获取开门二维码</a>
|
||
<a href="{{d.qr_img}}" class="layui-btn layui-btn-xs layui-btn-primary" download="{{d.sn}}.png">下载二维码</a>
|
||
<a href="javascript:;" class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delete_data" >删除</a>
|
||
</script>
|
||
<!--行操作列模板-->
|
||
<script type="text/html" id="yesBarTpl">
|
||
<a href="javascript:;" class="layui-btn layui-btn-xs" lay-event="yes_data" >选择</a>
|
||
</script>
|
||
|
||
<script id="getopendoorqrcode_html" type="text/html">
|
||
<div class="layui-form getopendoorqrcode-panel">
|
||
<div class="layui-card">
|
||
<div class="layui-card-header layui-hide"></div>
|
||
<div class="layui-card-body">
|
||
<div class="layui-form-item">
|
||
<div class="layui-inline">
|
||
<label class="layui-form-label">过期时间</label>
|
||
<div class="layui-input-inline">
|
||
<input type="text" name="opendoor_qrcode_endtime" class="layui-input" id="opendoor_qrcode_endtime" placeholder="yyyy-MM-dd HH:mm:ss" autocomplete="off" readonly>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="layui-card-footer layui-text-center layui-mt-15 layui-mb-15">
|
||
<a class="layui-btn layui-btn-sm confirm-btn" lay-submit="" lay-filter="layui-getopendoorqrcode-submit" href="javascript:;">确定</a>
|
||
<a class="layui-btn layui-btn-sm layui-btn-primary cancel-btn" href="javascript:;">取消</a>
|
||
</div>
|
||
</div>
|
||
</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
|
||
, laydate = layui.laydate
|
||
, admin = layui.admin;
|
||
|
||
form.render();
|
||
|
||
//search
|
||
form.on('submit(dtable-search)', function (obj) {
|
||
var field = obj.field;
|
||
reload_table_data(field);
|
||
});
|
||
|
||
//重新加载表格数据
|
||
function reload_table_data(conf){
|
||
table.reload('dtable', {
|
||
url:'<?=\Yii::$app->urlManager->createUrl(['admin/xt-open/list-data'])?>?module=getDoor'
|
||
,page: true
|
||
,where: conf
|
||
});
|
||
};
|
||
|
||
//执行渲染
|
||
table.render({
|
||
//指定原始表格元素选择器(推荐id选择器)
|
||
elem: '#dtable'
|
||
//容器高度
|
||
//,height: 315
|
||
//容器宽度
|
||
//,width: 720
|
||
//设置表头
|
||
,cols: [[
|
||
{checkbox: true}
|
||
, {field: 'id', title: 'ID'}
|
||
, {field: 'name', title: '名称'}
|
||
, {field: 'sn', title: '编号'}
|
||
, {field: 'code', title: '编码'}
|
||
, {field: 'villageName', title: '小区名'}
|
||
, {field: 'villageId', title: 'villageId'}
|
||
, {field: 'buildingName', title: '楼栋名称'}
|
||
, {field: 'buildingId', title: 'buildingId'}
|
||
, {field: 'unitName', title: '单元名称'}
|
||
, {field: 'unitId', title: 'unitId'}
|
||
, {title: '操作',fixed: 'right', toolbar: '#rowBarTpl', width: 300}
|
||
]
|
||
]
|
||
, url:'<?=\Yii::$app->urlManager->createUrl(['admin/xt-open/list-data'])?>?module=getDoor'
|
||
, 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:[]
|
||
});
|
||
//监听工具栏
|
||
table.on('toolbar(dtable)', function(obj){
|
||
var lay_event = obj.event;
|
||
var confirm_url = null;
|
||
var confirm_tip = null;
|
||
if(lay_event != 'add'){
|
||
return layer.msg('请求错误');
|
||
}
|
||
var html = `
|
||
<div style='padding:10px'>
|
||
<div class="layui-form-item">
|
||
<label class="layui-form-label">编号SN</label>
|
||
<div class="layui-input-block">
|
||
<input type="text" name="sn" placeholder="输入云盒编号" autocomplete="off" class="layui-input">
|
||
</div>
|
||
</div>
|
||
<div class="layui-form-item">
|
||
<label class="layui-form-label">门名称</label>
|
||
<div class="layui-input-block">
|
||
<input type="text" name="name" placeholder="输入门名称" autocomplete="off" class="layui-input">
|
||
</div>
|
||
</div>
|
||
<div class="layui-form-item">
|
||
<label class="layui-form-label">门类型</label>
|
||
<div class="layui-input-block">
|
||
<input type="radio" name="type" value="1" title="小区">小区
|
||
<input type="radio" name="type" value="2" title="楼栋">楼栋
|
||
<input type="radio" name="type" value="3" title="单元" checked="">单元
|
||
</div>
|
||
</div>
|
||
</div>
|
||
`;
|
||
layer.open({
|
||
type: 1,
|
||
title: "添加门禁",
|
||
closeBtn: 1,
|
||
shadeClose: true,
|
||
skin: 'yourclass',
|
||
area:['380px','280px'],
|
||
content: html,
|
||
btn:['下一步','取消'],
|
||
yes:function(){
|
||
var sn = $("input[name='sn']").val()
|
||
var name = $("input[name='name']").val()
|
||
var type = $("input[name='type']:checked").val()
|
||
if(sn == ''){
|
||
return layer.msg('请填写sn')
|
||
}
|
||
if(name == ''){
|
||
return layer.msg('请填写门名称')
|
||
}
|
||
var arr_type = {
|
||
1:'getVillage',
|
||
2:'getBuilding',
|
||
3:'getUnit',
|
||
}
|
||
var arr_type_ = {
|
||
1:'villageId',
|
||
2:'buildingId',
|
||
3:'unitId',
|
||
}
|
||
layer.closeAll();
|
||
var html = `
|
||
<table class="layui-hide" id="test"></table>
|
||
`
|
||
|
||
layer.open({
|
||
type: 1,
|
||
title: "选择位置",
|
||
closeBtn: 1,
|
||
shadeClose: true,
|
||
skin: 'yourclass',
|
||
area:['60%','80%'],
|
||
content: html,
|
||
success:function(){
|
||
//执行渲染
|
||
table.render({
|
||
//指定原始表格元素选择器(推荐id选择器)
|
||
elem: '#test'
|
||
//容器高度
|
||
//,height: 315
|
||
//容器宽度
|
||
//,width: 720
|
||
//设置表头
|
||
,cols: [[
|
||
{checkbox: true}
|
||
, {field: 'id', title: 'ID'}
|
||
, {field: 'name', title: '名称'}
|
||
, {field: 'villageName', title: '小区名'}
|
||
, {field: 'buildingName', title: '楼栋名称'}
|
||
, {field: 'unitName', title: '单元名称'}
|
||
, {title: '操作',fixed: 'right', templet:function(d){
|
||
console.log(name)
|
||
var temp_ = {
|
||
'sn': sn,
|
||
'name': name,
|
||
'type': type,
|
||
}
|
||
temp_[arr_type_[type]] = d.id;
|
||
var data = JSON.stringify(temp_)
|
||
return `<a href="javascript:;" class="layui-btn layui-btn-xs yes_btn" data='`+data+`' >选择</a>`;
|
||
}, width: 240}
|
||
]
|
||
]
|
||
, url:'<?=\Yii::$app->urlManager->createUrl(['admin/xt-open/list-data'])?>?module='+arr_type[type]
|
||
, 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(){
|
||
$('.yes_btn').click(function(){
|
||
var data = $(this).attr('data')
|
||
$.ajax('<?=\Yii::$app->urlManager->createUrl(['admin/xt-open/add-data'])?>',{
|
||
type:"POST",
|
||
dataType:"json",
|
||
data:{
|
||
data:data,
|
||
module:'addDoor',
|
||
_csrf:_csrf
|
||
},
|
||
success:function(res){
|
||
layer.msg(res.msg, {
|
||
offset: '15px'
|
||
,icon: 1
|
||
,time: 3000
|
||
}, function(){
|
||
location.reload();
|
||
});
|
||
},
|
||
error:function(xhr,type,err){
|
||
layer.msg(xhr.responseText, {
|
||
offset: '15px'
|
||
,icon: 2
|
||
,time: 1000
|
||
}, function(){
|
||
});
|
||
}
|
||
})
|
||
})
|
||
|
||
}
|
||
});
|
||
}
|
||
});
|
||
|
||
|
||
console.log(arr_type[type])
|
||
|
||
}
|
||
});
|
||
});
|
||
|
||
//监听工具条
|
||
table.on('tool(dtable)', function(obj){
|
||
var row_data = obj.data;
|
||
var lay_event = obj.event;
|
||
var id = row_data.id;
|
||
var sn = row_data.sn;
|
||
var module = '';
|
||
var confirm_url = null;
|
||
var confirm_tip = null;
|
||
if(lay_event == 'delete_data'){
|
||
confirm_tip = '你确定将此项删除吗?';
|
||
confirm_url = '<?=\Yii::$app->urlManager->createUrl(['admin/xt-open/delete-data'])?>';
|
||
module = 'deleteDoor';
|
||
}
|
||
if(lay_event == 'get_opendoor_qrcode'){
|
||
var content = $("#getopendoorqrcode_html").html();
|
||
return layer.open({
|
||
type: 1,
|
||
title:'选择参数',
|
||
offset:'50px',
|
||
area: ['560px', '220px'], //宽高
|
||
content: content,
|
||
success:function(layero, index){
|
||
//console.log(layero, index);
|
||
// 日期时间选择器
|
||
laydate.render({
|
||
elem: '#opendoor_qrcode_endtime',
|
||
type: 'datetime'
|
||
});
|
||
|
||
form.render();
|
||
form.on('submit(layui-getopendoorqrcode-submit)', function (obj) {
|
||
var data = obj.field;
|
||
data.sn = sn;
|
||
data._csrf = _csrf;
|
||
console.log(data)
|
||
var url = '<?=\Yii::$app->urlManager->createUrl(["admin/xt-open/get-opendoor-qrcode"])?>';
|
||
$.ajax(url,{
|
||
type:"POST",
|
||
dataType:"json",
|
||
data:data,
|
||
success:function(res){
|
||
if(res.code == 0){
|
||
layer.close(index);
|
||
console.log(res)
|
||
previewImg(res.data)
|
||
} 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(){
|
||
});
|
||
}
|
||
})
|
||
});
|
||
$('.recharge-panel').on('click','.confirm-btn',function(){
|
||
})
|
||
$('.recharge-panel').on('click','.cancel-btn',function(){
|
||
layer.close(index);
|
||
});
|
||
}
|
||
});
|
||
|
||
}
|
||
if(confirm_url != null){
|
||
layer.confirm(confirm_tip, {
|
||
btn: ['确定','取消']
|
||
}, function(){
|
||
$.ajax(confirm_url,{
|
||
type:"POST",
|
||
dataType:"json",
|
||
data:{
|
||
id:id,
|
||
module:module,
|
||
_csrf:_csrf
|
||
},
|
||
success:function(res){
|
||
layer.msg(res.msg, {
|
||
offset: '15px'
|
||
,icon: 1
|
||
,time: 1000
|
||
}, function(){
|
||
location.reload();
|
||
});
|
||
},
|
||
error:function(xhr,type,err){
|
||
layer.msg(xhr.responseText, {
|
||
offset: '15px'
|
||
,icon: 2
|
||
,time: 1000
|
||
}, function(){
|
||
});
|
||
}
|
||
})
|
||
}, function(){
|
||
});
|
||
}
|
||
});
|
||
});
|
||
function previewImg(obj) {
|
||
var imgHtml = "<img src='" + obj + "' width='200px' height='200px'/>";
|
||
//弹出层
|
||
layer.open({
|
||
type: 1,
|
||
shade: 0.8,
|
||
offset: 'auto',
|
||
area: [200 + 'px', 250 + 'px'],
|
||
shadeClose: true,
|
||
scrollbar: false,
|
||
title: "图片预览", //不显示标题
|
||
content: imgHtml, //捕获的元素,注意:最好该指定的元素要存放在body最外层,否则可能被其它的相对元素所影响
|
||
cancel: function () {
|
||
//layer.msg('捕获就是从页面已经存在的元素上,包裹layer的结构', { time: 5000, icon: 6 });
|
||
}
|
||
});
|
||
}
|
||
<?php $this->endBlock(); ?>
|
||
</script>
|
||
<?php $this->registerJs($this->blocks['js_script_wrap'], \yii\web\View::POS_END); ?>
|