let form, table, laydate, objParam, tag, active, element; let tableIns; let pageNum = 1; // 定义分页 let labelsArr = [['demo', 'demo2', 'demo3', 'demo4'], ['demo', 'demo2', 'demo3', 'demo4', 'demo5'], ['demo3', 'demo4', 'demo5', 'demo6']]; let labelArr = []; function setParams(obj) { objParam = JSON.parse(obj); setSearch(objParam.type); if (objParam.type === 1) { // 工程数量跳转 labelArr = labelsArr[0]; } else if (objParam.type === 2) { // 需求计划详情跳转 labelArr = labelsArr[1]; } else if (objParam.type === 3 || objParam.type === 4 || objParam.type === 5 || objParam.type === 6) { // 派车详情 labelArr = labelsArr[2]; } setFilter(objParam.type); setFilterData(objParam.type); layui.config({ base: "../../lib/layui-v2.9.18/layui/modules/", //此处路径请自行处理, 可以使用绝对路径 }).extend({ tag: 'tag' }).use(["form", "table", 'laydate', 'tag', 'element'], function () { form = layui.form; table = layui.table; laydate = layui.laydate; tag = layui.tag; element = layui.element; //全局设置 tag.set({ skin: 'layui-btn layui-btn-primary layui-btn-sm layui-btn-radius',//标签样式 tagText: '添加标签' //标签添加按钮提示文本 }); // 触发事件 active = { // 新增demo2标签 tagAdd: function (nameValue, index) { tag.add('delDemo', { text: nameValue, id: index }) }, // 删除demo2标签 tagDelete: function (index) { tag.delete('delDemo', index); } }; $.each(labelArr, function (index, item) { tag.on('click(' + item + ')', function () { let name = replaceChinese($(this).html()); let index = $(this).attr('lay-id'); let indexArr = index.split('-'); $('#' + item + ' button').each(function () { let flag = $(this).hasClass('checkBtn'); if (flag) { $(this).removeClass('checkBtn'); } }); $('#' + item + ' button').each(function () { let layId = $(this).attr('lay-id'); if (layId === index) { $(this).addClass('checkBtn'); } }); let flag = false, isAll = false, isRepeat = false, delLabelIdArr = []; if (name === '全部') { isAll = true; } $('#delDemo button').each(function () { let layId = $(this).attr('lay-id'); let layIdArr = layId.split('-'); if (isAll && indexArr[0] === layIdArr[0]) { // 选择的是全部 delLabelIdArr.push(layId); } else if (!isAll && indexArr[0] === layIdArr[0]) { isRepeat = true; delLabelIdArr.push(layId); } else if (!isAll && index === layId) { // 选择的不是全部,并且标签相同 flag = true return false; } }) if (isAll && delLabelIdArr.length > 0) { $.each(delLabelIdArr, function (index, item) { active.tagDelete(item); }) } else if (!isAll && delLabelIdArr.length > 0 && isRepeat) { $.each(delLabelIdArr, function (index, item) { active.tagDelete(item); }) active.tagAdd(name, index); } else if (!isAll && flag && isRepeat) { return layer.msg('选中标签已存在', { icon: 7 }); } else if (!isAll && !flag && !isRepeat) { active.tagAdd(name, index); } }); }); // 已选条件删除 tag.on('delete(delDemo)', function (data) { let index = $('#delDemo button').eq(data.index).attr('lay-id'); $('.tag-item').each(function () { let layId = $(this).attr('lay-id'); if (layId === index) { $(this).removeClass('checkBtn'); } }); }); setInitCheckData(); if (objParam.type === 1) { // 工程数量跳转 loadScript("../../js/welcome/data_datail_pro_list.js"); } else if (objParam.type === 2) { // 需求计划详情跳转 loadScript("../../js/welcome/data_datail_plan_list.js"); } else if (objParam.type === 3 || objParam.type === 4 || objParam.type === 5 || objParam.type === 6) { // 派车详情 loadScript("../../js/welcome/data_datail_dispatch_list.js"); } setTimeout(() => { if (objParam.type === 1 || objParam.type === 2) { let height = $('div#demo.layui-btn-container.tag').height(); if (height > 30) { $('#open').removeAttr('style'); $('#demo button').css('margin-bottom', '5px'); $('#demo').css({ 'height': '30px', 'overflow': 'hidden', 'text-overflow': 'ellipsis' }) } } }, 100); }); } // 动态加载js function loadScript(url) { var script = document.createElement('script'); script.type = 'text/javascript'; script.src = url; document.body.appendChild(script); } // 保留中文汉字和数字 function replaceChinese(value) { // let str = value.match(/[\u4e00-\u9fa5]|\d|[a-z][A-Z]/g).join(""); let str = value.replace('ဆ', ''); return str; } // 清空筛选 function clearFilter() { $('.tag-item').each(function () { $(this).removeClass('checkBtn'); }); $('#delDemo button').each(function () { let layId = $(this).attr('lay-id'); active.tagDelete(layId); }) } // 1.收起数据 function showData(type) { if (type === 1) { $('#open').removeAttr('style'); $('#close').css('display', 'none'); $('#demo').css({ 'height': '30px', 'overflow': 'hidden', 'text-overflow': 'ellipsis' }) } else { $('#open').css('display', 'none'); $('#close').removeAttr('style'); $('#demo').removeAttr('style'); } } // 设置筛选条件 function setFilter(type) { let html = "" if (type === 1) { // 工程详情 html += "
分公司:
" + "派车状态:
" + "年份:
" + "月份:
" + "分公司:
" + "派车状态:
" + "付款状态:
" + "年份:
" + "月份:
" + "类型:
" + "年份:
" + "月份:
" + "付款状态:
" + "