';
$('#dever_modal_body').html(html);
$('#dever_modal_title').html('复制数据');
$("#dever_modal_yes").unbind('click').bind('click', function()
{
set_update('#copy_num', $("#temp_copy_num").val());
set_update('#update_where_id', 0);
submit_action();
});
}
//头部菜单
function topMenu(e)
{
var p = e.parent().parent().parent().find('span');
p.html(e.html());
//更新当前的精细权限
var url = config.host + 'top.update_action?json=1';
var id = e.attr('data-id');
$.post(url, {id:id}, function(t)
{
var href = location.href;
if(location.href.indexOf('where_id') != -1)
{
var temp = location.href.split('where_id');
href = temp[0] + 'where_id=' + t;
}
if(typeof(config.layout) != "undefined" && $(config.layout).length)
{
pjax({url: href, container: config.layout})
}
else
{
location.href = href;
}
})
}
//更新页面的批量载入选择
function loadShow()
{
if($(".show_input").length)
{
$(".show_input input").each(function()
{
if($(this).attr('checked'))
{
inputShow($(this), $(this).attr('show_id'), 'input');
}
})
$(".show_input select").each(function()
{
if($(this).find('option:selected').text())
{
inputShow($(this), $(this).attr('show_id'));
}
})
}
}
function inputShow(e,n,t)
{
$(".show_" + n).hide();
var array = ['input', 'textarea'];
for(var a in array)
{
if ($(".show_" + n).find(array[a]).length) {
var c = $(".show_" + n).find(array[a]).attr('class');
if (c.indexOf('validate[required]') > -1) {
$(".show_" + n).find(array[a]).removeClass('validate[required]').addClass('validates');
}
}
}
if (t == 'input') {
var item = e.parent().find('input');
item.each(function()
{
if($(this).get(0).checked == true)
{
inputShowOne($(this),n);
}
});
} else {
var item = e.parent().find('select');
item.each(function()
{
if($(this).find('option:selected').text())
{
inputShowOne($(this),n);
}
});
}
}
function inputShowOne(e,n)
{
var value = e.val();
var ele = '.show_' + n + '_ajax';
if ($(ele).length) {
$(ele).each(function()
{
var self = $(this);
var url = self.attr('dever-ajax');
$.getJSON(url + value + '&callback=?', function(t) {
self.find('.margin-top').html(t.data);
inputShowOneValiDate(self);
checkbox();
})
})
} else {
ele = '.show_' + n + '_' + value;
inputShowOneValiDate($(ele));
}
}
function inputShowOneValiDate(e)
{
e.show();
var array = ['input', 'textarea'];
for(var a in array)
{
if(e.length && e.attr('class').indexOf('show_no') == -1)
{
e.find(array[a]).each(function()
{
var parent = $(this).parent();
if($(this).attr('class') != 'editor' && $(this).attr('class').indexOf('validates') > -1 && parent.find('label').length && parent.find('label').html().indexOf('选填') == -1)
{
$(this).addClass('validate[required]');
}
})
}
}
}
//批量更新
function list_mul(e)
{
var type = parseInt($("#mul_type").val());
if(type != 1 && type != 2)
{
alert('您还没有选择数据更新方式');
return;
}
var index = layer.confirm('确定进行此项操作吗?', function()
{
$('#method').val('mul');
$('#function').val('msg');
layer.close(index);
$('#form1').attr('target', 'f1').submit();
})
}
//搜索
function list_search(e)
{
$('#method').val('search');
$('#function').val('');
$('#form1').attr('target', '').submit();
}
//更新数据
function update(e, id, project, table, notice)
{
var call = function()
{
var col = e.attr('name').replace('up_col_', '');
var value = e.val();
var old = e.attr('data-old');
var url = config.host + 'database.update_action?json=1';
$.post(url, {where_id:id,col:col,value:value,project:project,table:table}, function(t)
{
var t = eval('('+t+')');
if (t.status == 1) {
e.attr('data-old', value);
notify('操作已成功!您的操作已修改当前选项!', e);
preview();
} else {
msg(t);
e.val(old);
}
})
}
if(notice)
{
var index = layer.confirm(notice, function()
{
layer.close(index);
call();
});
}
else
{
call();
}
}
function notify(msg, e)
{
if (!e) {
layer.msg(msg);
return;
}
layer.tips(msg, e, {
tips: [1, '#3595CC']
});
/*
var notice = new PNotify({
title: '提示信息',
text: msg,
buttons: {
closer: false,
sticker: false
}
});
notice.get().click(function() {
notice.remove();
});
*/
}
//模板选择
function template()
{
if(config.template)
{
$('body').attr('class', 'theme-' + config.template);
}
if($(".selector").length)
{
$(".selector").each(function()
{
if($(this).data('check') == 'checked')
{
selector($(this));
}
})
}
}
//选择器
function selector(e)
{
var value = e.data('value');
var name = e.data('name');
$('#'+name+'_value').val(value);
$('.'+name+'_selector').children().css({'border':'1px solid #ccc'});
e.children().css({'border':'1px solid black'});
if(name == 'update_template')
{
$('body').attr('class', 'theme-' + value);
}
}
//根据e的值,来载入其他数据
function loading(e, data)
{
var value = e.val();
if(e.attr('id') && e.attr('id').indexOf('_temp') != -1)
{
var id = e.attr('id').replace('_temp', '');
if($('#' + id).length)
{
var value = $('#' + id).val();
}
}
if(data.element)
{
if(data.url)
{
data.value = value;
$.getJSON(data.url, data, function(t)
{
$('#update_'+data.element+'_value').val(t.data);
});
}
else
{
$('#update_'+data.element+'_value').val(value);
}
}
else if(data.url)
{
data.value = value;
data.where_id = $('#update_where_id').val();
data.table = $('#table').val();
data.project = $('#project').val();
$.getJSON(data.url, data, function(s)
{
t = s.data;
if(t.indexOf('onblur') != -1)
{
eval(t);
}
else
{
var parent = e.parent().parent();
if(t.indexOf('status') == -1)
{
if(data.type == 1)
{
$('.checking_1,.checking_2,.checking_3,.checking_4').each(function()
{
$(this).remove();
});
}
else
{
$('.checking_-1,.checking_3,.checking_4').each(function()
{
$(this).remove();
});
}
parent.after(t);
checkbox();
}
}
});
}
}
//根据e的值,来载入其他数据,先检测是否选中
function checking(name, e, data)
{
var value = [];
$('.' + name).each(function()
{
if($(this).get(0).checked == true)
{
value.push($(this).val());
}
});
if(data.url)
{
data.value = value.join(',');
data.where_id = $('#update_where_id').val();
data.table = $('#table').val();
data.project = $('#project').val();
if(data.check)
{
data.check_value = false;
$(data.check).each(function()
{
if($(this).get(0).checked == true)
{
data.check_value = $(this).val();
}
});
}
$.getJSON(data.url, data, function(s)
{
t = s.data;
var parent = e.parent().parent().parent();
if(t.indexOf('status') == -1)
{
if(data.type == 1)
{
$('.checking_1,.checking_2,.checking_3,.checking_4').each(function()
{
$(this).remove();
});
}
else
{
$('.checking_-1,.checking_3,.checking_4').each(function()
{
$(this).remove();
});
}
parent.after(t);
checkbox();
}
});
}
}
function autocomplete()
{
if ($("input").length) {
$("input").each(function()
{
$(this).attr('autocomplete', 'new-password');
});
}
if($("input[complete]").length)
{
$("input[complete]").each(function()
{
var cache = {};
var self = $(this);
self.autocomplete(
{
minLength: 2,
source: function( request, response )
{
var term = request.term.split( /,\s*/ );
request.term = term.pop();
if ( request.term in cache ) {
response( cache[ request.term ] );
return;
}
var cate = self.attr('complete_cate');
if (cate) {
request[cate] = $('update_' + cate + '_value').val();
}
$.getJSON(self.attr('complete') + '&callback=?', request, function( data, status, xhr ) {
data = data.data
cache[ term ] = data;
var state = true;
for(var i in data)
{
if(data[i].id <=0)
{
state = false;
}
}
if(state)
{
response( data );
}
});
},
focus: function() {
// prevent value inserted on focus
return false;
},
select: function( event, ui )
{
//log( "Selected: " + ui.item.value + " aka " + ui.item.id );
var value = self.attr('complete_callback');
var id = self.attr('id').replace('_temp', '');
var name = self.attr('name').replace('_temp', '');
//var e = $("#" + id);
var e = self;
var html = '
';
if (!$("#" + id + '_show').length) {
e.parent().append(html);
}
if ($("#" + id + '_show').html().indexOf(ui.item.value) == -1)
{
var link = '';
var attr = '';
var pic = '';
if (ui.item['pic']) {
pic = '';
}
if (ui.item['link']) {
link = ui.item['link'];
attr = ' target="_blank"';
}
var html = '
';
$("#" + id + '_show').append(html);
if (!autocomplete_value[id]) {
autocomplete_value[id] = [];
}
autocomplete_value[id].push(ui.item[value]);
}
ui.item.value = '';
}
});
})
}
}
function autocomplete_del(e, id, value)
{
e.parent().parent().remove();
autocomplete_value[id].remove(value);
var len = autocomplete_value.length;
if (len < 1 && !($('#del_' + name).length)) {
$("#" + id + '_show').append('');
}
}
function searchbox(id, e)
{
var self = e.parent().find("input");
var v = self.val();
var key = self.attr('id').replace('_temp', '');
var request = {};
request.term = v;
var cate = self.attr('searchbox_cate');
if (cate) {
var c = cate.split(',');
for (var i in c) {
if (typeof(c[i]) == 'string' && $('#'+c[i]).length) {
request[c[i]] = $('#'+c[i]).val();
}
}
}
var index = layer.msg('加载中...');
$.getJSON(self.attr('searchbox') + '&callback=?', request, function( data, status, xhr ) {
layer.close(index);
var data = data.data;
if (!data) {
showAlert('没有搜索到数据');
return;
}
var html = '
{cate}
{content}
全选
';
if (data) {
var j = 0;
var c = '';
var s = '';
var cateHtml = '';
var content = '';
for (var i in data) {
if (j == 0) {
c = 'class="layui-this"';
s = 'layui-show';
} else {
c = '';
s = '';
}
cateHtml += '
'+data[i].name+'
';
j++;
var item = '
{head}';
var p = false;
for (var k in data[i].child) {
if (data[i].child[k].name) {
var pic = '';
if (data[i].child[k].pic) {
pic = '
';
p = true;
}
var check = '';
if (searchbox_value[key].indexOf(data[i].child[k].id) != -1) {
check = 'checked';
}
item += '
');
}
item = item.replace('{head}', head);
content += item;
}
if (cateHtml) {
html = html.replace('{cate}', cateHtml);
}
if (content) {
html = html.replace('{content}', content);
}
}
var config = {
type: 1,
shade: 0.3,
title : false,
shadeClose : true,
area : ['800px', '600px'],
content: html
};
layer.open(config);
layui.use('element', function(){
var element = layui.element;
});
});
}
function searchbox_checkall(e, id)
{
$('.' + id).each(function()
{
$(this).get(0).checked = e.get(0).checked;
//$(this).click();
})
}
function searchbox_checkone(e, id, key, value)
{
if (!e.get(0).checked) {
$('#searchbox_check_' + key + '_' + value).remove();
searchbox_value.remove(value);
var len = searchbox_value.length;
var name = key.replace('_value', '');
if (len < 1 && !($('#del_' + name).length)) {
$("#" + key + '_show').append('');
}
} else {
var c = '.' + e.attr('data-class');
searchbox_yes(id, c, false);
}
}
function searchbox_yes(e, c, state)
{
var self = $("#" +e);
$(c).each(function()
{
if ($(this).get(0).checked && $(this).val() && $(this).attr('data-value')) {
var value = self.attr('searchbox_callback');
var id = self.attr('id').replace('_temp', '');
var name = self.attr('name').replace('_temp', '');
var html = '
';
if (!$("#" + id + '_show').length) {
self.parent().append(html);
}
if (!$("#" + id + '_show').find('#searchbox_check_'+id+'_'+$(this).attr('data-value')).length)
{
var link = '';
var attr = '';
var pic = '';
if ($(this).attr('data-pic') && $(this).attr('data-pic') != 'undefined') {
pic = '';
}
if ($(this).attr('data-link')) {
link = $(this).attr('data-link');
attr = ' target="_blank"';
}
var html = '
');
var e = e.parent().parent();
var n = e.next();
var p = e.parent();
var content = n.html();
content = content.replaceAll('_c_', '_c_' + (self.index[key]-1) + '_i_');
content = '
' + content + '
';
p.append(content);
if ($("#" + id).find('.ke-container').length >= 1) {
$("#" + id).find('.ke-container').eq(0).remove();
}
$('#update_' + key +'_c_' + (self.index[key]-1) + '_i_' + 'order_value').val(parseInt($('#update_' + key +'_c_' + (self.index[key]-2) + '_i_' + 'order_value').val())+1);
self.del();
//$("html,body").animate({scrollTop:$('.dever_form_add_child').eq(this.appendIndex).offset().top},500);
self.index[key]++;
image();
loadShow();
autocomplete();
change();
},
add : function(e)
{
var self = this;
var p = e.parent();
var id = 'data-' + this.addIndex;
var name = '新增数据-' + (this.addIndex-1);
p.before('