招标
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

96 lines
2.7 KiB

<?php
/**
*
* ListCreate.php
* User: ChenLong
* DateTime: 2020/3/18 14:07
*/
namespace sdModule\makeAdminBasics\htmlUnit;
use sdModule\makeAdminBasics\Basics;
class ListDelete implements ListUnitInterface
{
/**
* @return string
*/
public function event()
{
return 'del';
}
/**
* @param string $template
*/
public function register(string $template = Js::LIST_HEAD_TEMPLATE)
{
$code = "<button type=\"button\" lay-event=\"{$this->event()}\" class=\"layui-btn layui-btn-sm layui-btn-danger\"><i class=\"layui-icon layui-icon-delete\"></i>{:lang('batch deletion')}</button>";
JsFacade::loadTemplate($this->event(), $code, $this->js(), $template);
$code = "<button type=\"button\" lay-event=\"{$this->event()}\" class=\"layui-btn layui-btn-xs layui-btn-danger\"><i class=\"layui-icon layui-icon-delete\"></i>{:lang('delete')}</button>";
JsFacade::loadTemplate($this->event(), $code,
Basics::indentAndLineFeed(4, Basics::BEFORE) . "del(obj.data[primary]);", Js::LIST_LINE_TEMPLATE);
JsFacade::layUICode($this->commonJs());
}
/**
* @return string
*/
private function js()
{
return <<<JS
let checkStatus = table.checkStatus('test');
if (checkStatus.data.length) {
let id = [];
for (let i in checkStatus.data) {
if (checkStatus.data.hasOwnProperty(i) && checkStatus.data[i].hasOwnProperty(primary)) {
id.push(checkStatus.data[i][primary])
}
}
del(id);
}
JS;
}
/**
* @return string
*/
private function commonJs()
{
return <<<JS
function del(id){
layer.confirm('{:lang("confirm delete")}?', {icon:3,title:'{:lang("warning")}',btn:['{:lang("confirm")}', '{:lang("cancel")}']}, function (index) {
let load = custom.loading();
$.ajax({
url: '{:url("del")}'
, type: 'post'
, data: {id:id}
, success:function (res) {
layer.close(load);
if (res.code === 200) {
layNotice.success('{:lang("success")}');
table.reload('test');
}else{
layNotice.warning(res.msg);
}
}
, error:function (err) {
console.log(err);
}
});
})
}
JS;
}
}