|
@@ -858,10 +858,13 @@ function autocomplete()
|
|
|
link = ui.item['link'];
|
|
|
attr = ' target="_blank"';
|
|
|
}
|
|
|
- var html = '<tr><td width="90%"><input type="checkbox" checked name="'+name+'[]" value="'+ui.item[value]+'"/> '+pic+'<a href="'+link+'" '+attr+' title="'+ui.item.value+'">'+ui.item.value+'</td><td width="10%"><a href="javascript:;" onclick="autocomplete_del($(this), \''+id+'\', \''+ui.item[value]+'\')">[删除]</a></td></tr>';
|
|
|
+ var html = '<tr><td width="90%"><input type="checkbox" checked name="'+name+'[]" value="'+ui.item[value]+'"/> '+pic+'<a href="'+link+'" '+attr+' title="'+ui.item.value+'">'+ui.item.value+'</td><td width="10%"><a href="javascript:;" onclick="autocomplete_del($(this), \''+id+'\', \''+ui.item[value]+'\', \''+name+'\')">[删除]</a></td></tr>';
|
|
|
$("#" + id + '_show').append(html);
|
|
|
|
|
|
- autocomplete_value.push(ui.item[value]);
|
|
|
+ if (!autocomplete_value[id]) {
|
|
|
+ autocomplete_value[id] = [];
|
|
|
+ }
|
|
|
+ autocomplete_value[id].push(ui.item[value]);
|
|
|
}
|
|
|
|
|
|
ui.item.value = '';
|
|
@@ -874,43 +877,186 @@ function autocomplete()
|
|
|
function autocomplete_del(e, id, value)
|
|
|
{
|
|
|
e.parent().parent().remove();
|
|
|
- autocomplete_value.remove(value);
|
|
|
+ autocomplete_value[id].remove(value);
|
|
|
+ var len = autocomplete_value.length;
|
|
|
+ if (len < 1 && !($('#del_' + name).length)) {
|
|
|
+ $("#" + id + '_show').append('<input type="hidden" name="'+name+'[]" id="del_'+name+'" value="-1" />');
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
|
-function searchbox(e)
|
|
|
+function searchbox(id, e)
|
|
|
{
|
|
|
var self = e.prev("input");
|
|
|
var v = self.val();
|
|
|
-
|
|
|
- var html = '<div style="margin-top: 10px;width: 60%; overflow: auto;max-height: 500px;"><table class="table table-small-font table-bordered"><tr><td width="90%"><input type="checkbox" checked /><a href="" >test</td><td width="10%"><a href="javascript:;">[删除]</a></td></tr></table></div>';
|
|
|
- var config = {
|
|
|
- type: 0,
|
|
|
- shade: 0,
|
|
|
- shadeClose : true,
|
|
|
- content: html
|
|
|
- };
|
|
|
-
|
|
|
- config.area = '500px';
|
|
|
- layer.open(config);
|
|
|
-
|
|
|
-
|
|
|
+ var key = self.attr('id').replace('_temp', '');
|
|
|
+
|
|
|
var request = {};
|
|
|
request.term = v;
|
|
|
|
|
|
var cate = self.attr('searchbox_cate');
|
|
|
if (cate) {
|
|
|
- request[cate] = $('update_' + cate + '_value').val();
|
|
|
+ var c = split(',');
|
|
|
+ for (var i in c) {
|
|
|
+ request[c[i]] = $('update_' + c[i] + '_value').val();
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
$.getJSON(self.attr('searchbox') + '&callback=?', request, function( data, status, xhr ) {
|
|
|
- console.log(data);
|
|
|
+ var data = data.data;
|
|
|
+ if (!data) {
|
|
|
+ showAlert('没有搜索到数据');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ var html = '<div class="layui-tab layui-tab-brief" style="width: 500px;" overflow><ul class="layui-tab-title" style="height: 60px; overflow: auto;">{cate}</ul><div class="layui-tab-content" style="padding-top: 0px;">{content}</div><div style="margin-left:10px"><input type="checkbox" onclick="searchbox_checkall($(this), \'searchbox_'+id+'\')"/> 全选<button type="button" onclick="searchbox_yes(\''+self.attr('id')+'\', \'.searchbox_'+id+'\', true)" class="btn btn-primary layui-btn layuiadmin-btn-list" style="margin-left:10px;margin-top: -2px;"><i class="fa fa-save"></i> 确定</button></div></div>';
|
|
|
+
|
|
|
+ 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 += '<li '+c+'>'+data[i].name+'</li>';
|
|
|
+ j++;
|
|
|
+
|
|
|
+ var item = '<div class="layui-tab-item '+s+'"><div style="margin-top: 10px;overflow: auto;max-height: 500px;"><table class="table table-small-font table-bordered">{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 = '<td><img src="'+data[i].child[k].pic+'" width="100"></td>';
|
|
|
+ p = true;
|
|
|
+ }
|
|
|
+ var check = '';
|
|
|
+ if (searchbox_value[key].indexOf(data[i].child[k].id) != -1) {
|
|
|
+ check = 'checked';
|
|
|
+ }
|
|
|
+ item += '<tr><td width="10%"><input '+check+' type="checkbox" onclick="searchbox_checkone($(this), \''+self.attr('id')+'\', \''+key+'\', '+data[i].child[k].id+', \''+key+'\')" class="searchbox_'+id+' searchbox_'+id+'_'+data[i].id+'" data-class="searchbox_'+id+'_'+data[i].id+'" data-pic="'+data[i].child[k].pic+'" data-name="'+data[i].child[k].name+'" data-value="'+data[i].child[k].id+'" data-link="'+data[i].child[k].link+'" value="'+data[i].child[k].id+'"/></td>'+pic+'<td><a href="" >'+data[i].child[k].name+'</td></tr>';
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ item += '</table></div></div>';
|
|
|
+
|
|
|
+ var head = '<tr><td width="10%"><input type="checkbox" class="searchbox_'+id+'" onclick="searchbox_checkall($(this), \'searchbox_'+id+'_'+data[i].id+'\')"/></td><td>标题</td></tr>';
|
|
|
+ if (p) {
|
|
|
+ head = head.replace('</td><td>', '</td><td>图片</td><td>');
|
|
|
+ }
|
|
|
+
|
|
|
+ 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 : ['500px', 'auto'],
|
|
|
+ content: html
|
|
|
+ };
|
|
|
+
|
|
|
+ layer.open(config);
|
|
|
});
|
|
|
}
|
|
|
|
|
|
-function searchbox_del(e, id, value)
|
|
|
+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('<input type="hidden" name="'+name+'[]" id="del_'+name+'" value="-1" />');
|
|
|
+ }
|
|
|
+ } 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 = '<div style="margin-top: 10px;width: 60%; overflow: auto;max-height: 500px;"><table id="'+id+'_show" class="table table-small-font table-bordered"></table></div>';
|
|
|
+ if (!$("#" + id + '_show').length) {
|
|
|
+ e.parent().append(html);
|
|
|
+ }
|
|
|
+ if ($("#" + id + '_show').html().indexOf($(this).attr('data-name')) == -1)
|
|
|
+ {
|
|
|
+ var link = '';
|
|
|
+ var attr = '';
|
|
|
+ var pic = '';
|
|
|
+ if ($(this).attr('data-pic')) {
|
|
|
+ pic = '<a href="javascript:;"><img src="'+$(this).attr('data-pic')+'" width="100"></a>';
|
|
|
+ }
|
|
|
+ if ($(this).attr('data-link')) {
|
|
|
+ link = $(this).attr('data-link');
|
|
|
+ attr = ' target="_blank"';
|
|
|
+ }
|
|
|
+
|
|
|
+ var html = '<tr id="searchbox_check_'+id+'_'+$(this).attr('data-value')+'"><td width="90%"><input type="checkbox" checked name="'+name+'[]" value="'+$(this).attr('data-value')+'"/> '+pic+'<a href="'+link+'" '+attr+' title="'+$(this).attr('data-name')+'">'+$(this).attr('data-name')+'</td><td width="10%"><a href="javascript:;" onclick="searchbox_del($(this), \''+id+'\', \''+$(this).attr('data-value')+'\', \''+name+'\')">[删除]</a></td></tr>';
|
|
|
+
|
|
|
+ $("#" + id + '_show').append(html);
|
|
|
+
|
|
|
+ if (!searchbox_value[id]) {
|
|
|
+ searchbox_value[id] = [];
|
|
|
+ }
|
|
|
+ searchbox_value[id].push($(this).attr('data-value'));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ if (state == true) {
|
|
|
+ layer.closeAll();
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+function searchbox_del(e, id, value, name)
|
|
|
{
|
|
|
e.parent().parent().remove();
|
|
|
searchbox_value.remove(value);
|
|
|
+ var len = searchbox_value.length;
|
|
|
+ if (len < 1 && !($('#del_' + name).length)) {
|
|
|
+ $("#" + id + '_show').append('<input type="hidden" name="'+name+'[]" id="del_'+name+'" value="-1" />');
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
//后台通用的提示
|