'use strict'; $(() => { autoFlashHeight(); const StatusConst = (function(){ const result = [ { field: 'gxby_status', title: '工序报验', type: 'enum', range: thirdParty.gxby}, // { field: 'gxby_date', title: '完工日期', type: 'time'}, { field: 'dagl_status', title: '档案管理', type: 'enum', range: thirdParty.dagl}, ]; return result; })(); const CheckConst = [ { key: 'kaigong', name: '开工', checks: [{ key: 'file_count', name: '资料个数', operate: [{ key: '=', name: '=' }, { key: '>', name: '>'}] }, { key: 'file_name', name: '资料名称', multi: 1, operate: [{ key: '=', name: '=' }, { key: 'has', name: '包含'}] }] }, { key: 'gongxu', name: '工序', checks: [{ key: 'gongxu_name', name: '工序名称', multi: 1, operate: [{ key: '=', name: '=' }, { key: 'has', name: '包含'}] }, { key: 'file_count', name: '资料个数', operate: [{ key: '=', name: '=' }, { key: '>', name: '>'}] }, { key: 'file_name', name: '资料名称', multi: 1, operate: [{ key: '=', name: '=' }, { key: 'has', name: '包含'}] }] }, { key: 'jiaogong', name: '中间交工', checks: [{ key: 'file_count', name: '资料个数', operate: [{ key: '=', name: '=' }, { key: '>', name: '>'}] }, { key: 'file_name', name: '资料名称', multi: 1, operate: [{ key: '=', name: '=' }, { key: 'has', name: '包含'}] }] }, { key: 'pingding', name: '评定', checks: [{ key: 'file_count', name: '资料个数', operate: [{ key: '=', name: '=' }, { key: '>', name: '>'}] }, { key: 'file_name', name: '资料名称', multi: 1, operate: [{ key: '=', name: '=' }, { key: 'has', name: '包含'}] }] }, { key: 'all', name: '全部资料', checks: [{ key: 'file_count', name: '资料个数', operate: [{ key: '=', name: '=' }, { key: '>', name: '>'}] }, { key: 'file_name', name: '资料名称', multi: 1, operate: [{ key: '=', name: '=' }, { key: 'has', name: '包含'}]}] }, ]; const groupObj = (function(list){ const groups = list; let curGroup; const getGroups = function() { return groups; }; const getConditionHtml = function(condition) { const html = []; for (const check of condition) { if (html.length > 0) html.push('
'); html.push(`[${check.blockName}]${check.fieldName} ${check.operateName} ${check.value}${check.multi ? '(多)' : ''}`); } return html.join(''); }; const getPushStatusHtml = function(pushStatus) { const html = []; for (const ps of pushStatus) { if (html.length > 0) html.push('
'); const fieldConst = StatusConst.find(x => { return x.field === ps.field; }); if (!fieldConst) continue; switch(ps.field) { case 'gxby_status': case 'dagl_status': const valueConst = fieldConst.range.find(x => { return x.value === ps.value; }); if (valueConst) { html.push(`${ps.fieldName} = ${valueConst.name}`); } else { html.push(`${ps.fieldName} = ${ps.value}(该值状态已删除)`); } break; case 'gxby_date': html.push(`${ps.fieldName} = ${ps.alias}`); break; } } return html.join(''); }; const getRuleHtml = function(rule) { const html = []; html.push('', rule.name ,''); html.push(``, getConditionHtml(rule.condition), ''); html.push(``, getPushStatusHtml(rule.push_status), ''); html.push(` `); return html.join(''); }; const loadGroupRules = function(group) { const html = []; for (const rule of group.rules) { html.push(``, getRuleHtml(rule), ''); } $('#ruleOptions').html(html.join('')); }; const setCurGroup = function(group) { curGroup = group; if (!group) return; loadGroupRules(group); $('dd[groupId]').removeClass('bg-warning'); $(`dd[groupId=${curGroup.group_id}]`).addClass('bg-warning'); }; const getCurGroup = function() { return curGroup; }; const getGroupCaptionHtml = function(group) { return `
${group.group_name}
` + '
'; }; const getGroupHtml = function(group) { const html = []; html.push(`
`, getGroupCaptionHtml(group), '
'); return html.join(''); }; const addGroup = function() { postData(window.location.pathname + '/save', { group: {add: 1} }, function(result) { groups.push(result.add); $('#group-list').append(getGroupHtml(result.add)); }); }; const renameGroup = function(group_id, group_name) { postData(window.location.pathname + '/save', { group: { update: { group_id, group_name } } }, function(result){ const group = groups.find(x => { return x.group_id === result.update.group_id; }); group.group_name = result.update.group_name; group.rules.forEach(x => { x.group_name === group.group_name; }); $(`dd[groupId=${group.group_id}]`).html(getGroupCaptionHtml(group)); }); }; const delGroup = function(group_id){ postData(window.location.pathname + '/save', { group: {del: group_id} }, function(result) { $(`dd[groupId=${result.del}]`).remove(); const groupIndex = groups.findIndex(x => { return x.group_id === group_id; }); groups.splice(groupIndex, 1); }); }; const addRule = function(rule) { const rules = rule instanceof Array ? rule : [rule]; const group = groups.find(x => { return x.group_id === rules[0].group_id; }); group.rules.push(...rules); loadGroupRules(curGroup); }; const updateRule = function(rule) { const group = groups.find(x => { return x.group_id === rule.group_id; }); const orgRule = group.rules.find(x => { return x.id === rule.id; }); if (!orgRule) return; _.assignIn(orgRule, rule); loadGroupRules(curGroup); }; const delRule = function (rule) { const group = groups.find(x => { return x.group_id === rule.group_id; }); const index = group.rules.findIndex(x => { return x.id === rule.id; }); group.rules.splice(index, 1); loadGroupRules(curGroup); }; if (groups.length > 0) setCurGroup(groups[0]); return { getGroups, setCurGroup, getCurGroup, addGroup, delGroup, renameGroup, addRule, updateRule, delRule, getConditionHtml, getPushStatusHtml } })(ruleGroups); const ruleSaveObj = (function(){ let group_id, group_name; const addCheckHtml = function(check) { const html = []; html.push('', `[${check.blockName}]${check.fieldName} ${check.operateName} ${check.value}${check.multi ? '(多)' : ''}`, '', ''); $('#condition-list').append(html.join('')); }; const addStatusHtml = function(status) { const html = []; html.push(''); const selectStatus = StatusConst.find(x => { return x.field === status.field; }); const value = selectStatus.range.find(x => { return x.value === status.value; }); html.push(` ${status.fieldName} = ${value ? value.name : status.value}`); html.push(''); html.push(''); $('#status-list').append(html.join('')); }; const getConditionBlockHtml = function(blocks) { const html = []; for (const d of blocks) { html.push(``); } $('#condition-block').html(html.join('')); getConditionFieldHtml(blocks[0]); }; const getConditionFieldHtml = function(block) { const html = []; for (const d of block.checks) { html.push(``); } $('#condition-field').html(html.join('')); getConditionOperateHtml(block.checks[0]); showMulti(block.checks[0]); }; const getConditionOperateHtml = function(check) { const html = []; for (const d of check.operate) { html.push(``); } $('#condition-operate').html(html.join('')); }; const showMulti = function (check) { if (check.multi) { $('#multi-set').show(); } else { $('#multi-set').hide(); $('#condition-multi')[0].checked = false; } }; const getStatusFieldHtml = function(fields) { const html = []; for (const d of fields) { html.push(``); } $('#status-field').html(html.join('')); getStatusValueHtml(fields[0]); }; const getStatusValueHtml = function(status) { const html = []; for (const d of status.range) { html.push(``); } $('#status-value').html(html.join('')); }; const initModal = function() { getConditionBlockHtml(CheckConst); getStatusFieldHtml(StatusConst); }; initModal(); $('#condition-add').click(() => { const blockValue = $('#condition-block').val(); const fieldValue = $('#condition-field').val(); const operateValue = $('#condition-operate').val(); const checkValue = $('#condition-value').val(); const block = CheckConst.find(x => { return x.key === blockValue; }); if (!block) { toastr.warning('未知判断模块'); return; } const check = block.checks.find(x => { return x.key === fieldValue; }); if (!check) { toastr.warning('未知判断条件'); return; } if (!checkValue) { toastr.warning('请输入判断值'); return; } const operate = check.operate.find(x => { return x.key === operateValue; }); if (!operate) { toastr.warning('未知判断符'); return; } const data = { blockKey: blockValue, blockName: block.name, fieldKey: fieldValue, fieldName: check.name, operateKey: operateValue, operateName: operate.name, value: checkValue }; if (check.type === 'enum') { data.value = _.toInteger(data.value); if (_.isNil(data.value) || data.value < 0) { toastr.warning('判断值仅限0、正整数'); return; } } if (check.multi) { data.multi = $('#condition-multi')[0].checked; } addCheckHtml(data); }); $('#status-add').click(() => { const fieldValue = $('#status-field').val(); const statusValue = parseInt($('#status-value').val()); const field = StatusConst.find(x => { return x.field === fieldValue; }); const status = field.range.find(x => { return x.value === statusValue; }); if (!field || !status) { toastr.warning('未知判断条件'); return; } const data = { fieldName: field.title, field: fieldValue, value: statusValue }; addStatusHtml(data); }); $('body').on('click', 'a[name=condition-del]', function() { $(this).parent().parent().remove(); }); $('body').on('click', 'a[name=status-del]', function() { $(this).parent().parent().remove(); }); $('#condition-block').click(function() { const value = this.value; const block = CheckConst.find(x => { return x.key === value; }); getConditionFieldHtml(block); }); $('#condition-field').click(function() { const blockValue = $('#condition-block').val(); const block = CheckConst.find(x => { return x.key === blockValue; }); const fieldValue = this.value; const check = block.checks.find(x => { return x.key === fieldValue; }); getConditionOperateHtml(check); showMulti(check); }); $('#status-field').click(function() { const field = this.value; const selectStatus = StatusConst.find(x => { return x.field === field; }); getStatusValueHtml(selectStatus); }); const showRuleModal = function(rule, group) { initModal(); group_id = rule ? rule.group_id : group.group_id; group_name = rule ? rule.group_name : group.group_name; $('#rule-id').val(rule ? rule.id : ''); $('#rule-name').val(rule ? rule.name : ''); $('#loc-list').html(''); $('#condition-list').html(''); $('#status-list').html(''); if (rule) { for (const c of rule.condition) { addCheckHtml(c); } for (const s of rule.push_status) { addStatusHtml(s); } } $('#save-rule').modal('show'); }; const getRuleData = function() { const data = {}; data.name = $('#rule-name').val(); if (data.name.length > 20) { toastr.warning('名称过长,请再精简'); return; } try { data.condition = []; const clist = $('td[condition-info]'); for (const c of clist) { const info = c.getAttribute('condition-info').split('&^&'); data.condition.push({ blockName: info[0], blockKey: info[1], fieldName: info[2], fieldKey: info[3], operateName: info[4], operateKey: info[5], value: info[6], multi: info[7] ? parseInt(info[7]) : 0, }); } } catch(err) { toastr.warning('判断条件错误'); return; } try { data.push_status = []; const slist = $('td[status-info]'); for (const s of slist) { const info = s.getAttribute('status-info').split('&^&'); data.push_status.push({ fieldName: info[0], field: info[1], value: parseInt(info[2]), }); } } catch(err) { toastr.warning('更新状态错误'); return; } const id = $('#rule-id').val(); if (id) { data.id = id; } else { data.group_id = group_id; data.group_name = group_name; } return data; }; return { show: showRuleModal, data: getRuleData, } })(); $('#add-rule').click(() => { ruleSaveObj.show(null, groupObj.getCurGroup()); }); $('body').on('click', 'a[name=editRule]', function() { const ruleId = $(this).parent().parent().attr('ruleId'); const curGroup = groupObj.getCurGroup(); if (!curGroup) return; const rule = curGroup.rules.find(x => { return x.id == ruleId; }); ruleSaveObj.show(rule, curGroup); }); $('body').on('click', 'a[name=delRule]', function() { const ruleId = $(this).parent().parent().attr('ruleId'); const curGroup = groupObj.getCurGroup(); if (!curGroup) return; const rule = curGroup.rules.find(x => { return x.id == ruleId; }); if (curGroup.rules.length === 1) { toastr.warning('当前配置,仅剩最后一个规则,如需删除,请直接删除规则组'); return; } postData(window.location.pathname + '/save', { rule: { del: rule } }, function (result) { if (result.del) groupObj.delRule(result.del); }); }); $('#save-rule-ok').click(function() { const loData = ruleSaveObj.data(); const updateData = {}; if (loData.id) { updateData.update = loData; } else { updateData.add = loData; } postData(window.location.pathname + '/save', { rule: updateData }, function (result) { if (result.add) groupObj.addRule(result.add); if (result.update) groupObj.updateRule(result.update); $('#save-rule').modal('hide'); }) }); $('body').on('click', '.table-file', function(e) { if (this.getAttribute('renaming') === '1') return; if (e.target.tagName === 'A' || e.target.tagName === 'I' || e.target.tagName === 'INPUT') return; const groupId = this.getAttribute('groupId'); const group = ruleGroups.find(x => { return x.group_id === groupId; }); groupObj.setCurGroup(group); }); $('body').on('mouseenter', ".table-file", function(){ $(this).children(".btn-group-table").css("display","block"); }); $('body').on('mouseleave', ".table-file", function(){ $(this).children(".btn-group-table").css("display","none"); }); $('body').on('click', 'a[name=renameGroup]', function(e){ $(this).parents('.table-file').attr('renaming', '1'); $(`#${this.getAttribute('aria-describedby')}`).remove(); const groupId = $(this).parents('.table-file').attr('groupId'); const group = ruleGroups.find(x => { return x.group_id === groupId; }); if (!group) return; const html = []; html.push(`
`); html.push(''); $(`.table-file[groupId=${groupId}]`).html(html.join('')); e.stopPropagation(); }); $('body').on('click', 'a[name=renameOk]', function(){ const groupId = $(this).parents('.table-file').attr('groupId'); const newName = $(this).parents('.table-file').find('input').val(); groupObj.renameGroup(groupId, newName); $(this).parents('.table-file').attr('renaming', '0'); }); $('body').on('click', 'a[name=renameCancel]', function() { $(this).parents('.table-file').attr('renaming', '0'); const groupId = $(this).parents('.table-file').attr('groupId'); const group = ruleGroups.find(x => { return x.group_id === groupId; }); if (!group) return; const html = []; html.push(`
${group.group_name}
`); html.push(''); $(`.table-file[groupId=${groupId}]`).html(html.join('')); }); $('body').on('click', 'a[name=delGroup]', function(e){ e.stopPropagation(); const groupId = $(this).parents('.table-file').attr('groupId'); groupObj.delGroup(groupId); }); $('#addGroup').click(function() { groupObj.addGroup(); }); const loadCopyRuleList= function(groupId) { const group = groupObj.getGroups().find(x => { return x.group_id === groupId; }); const ruleHtml = group.rules.map(rule => { return `${rule.name}${groupObj.getConditionHtml(rule.condition)}${groupObj.getPushStatusHtml(rule.push_status)}` }); $('#copy-rule-list').html(ruleHtml); }; $('#copy-rule').on('show.bs.modal', function() { const groups = groupObj.getGroups(); const groupHtml = groups.map(x => { return ``}); $('#select-group').html(groupHtml.join('')); loadCopyRuleList(groups[0].group_id); }); $('#select-group').click(function() { loadCopyRuleList(this.value); }); $('#copy-rule-ok').click(function() { const selects = $('input:checked', '#copy-rule'); if (selects.length === 0) { toastr.warning('请选择要拷贝的规则'); return; } const copy = selects.map(function() { return this.getAttribute('ruleId'); }).get().join(','); const updateData = { rule: { copy, group_id: groupObj.getCurGroup().group_id } }; postData(window.location.pathname + '/save', updateData, function (result) { if (result.add) groupObj.addRule(result.add); $('#copy-rule').modal('hide'); }) }); const getSelectGroup = function() { const selectGroup = [{ value: '', text: '' }]; const groups = groupObj.getGroups(); for (const g of groups) { selectGroup.push({ value: g.group_id, text: g.group_name }); } return selectGroup; }; const xmjSpread = SpreadJsObj.createNewSpread($('#xmj-spread')[0]); const xmjSheet = xmjSpread.getActiveSheet(); $('[role=tab]').click(function() { const items = getSelectGroup(); const groupComboCell = SpreadJsObj.CellType.getCustomizeComboCellType(items); xmjTree.datas.forEach(x => { if (!x) return; const index = items.findIndex( i => { return i.value === x.group_id; } ); if (index < 0) x.group_id = ''; }); xmjSheet.getRange(-1, 2, -1, 1).cellType(groupComboCell); SpreadJsObj.reloadColData(xmjSheet, 2); if (xmjSpread.shown) return; setTimeout(() => { xmjSpread.refresh(); xmjSpread.shown = true; }, 100); }); const xmjSpreadSetting = { cols: [ { title: '工程编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 240, formatter: '@', cellType: 'tree', readOnly: true, }, { title: '工程名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 350, formatter: '@', readOnly: true, }, { title: '规则组', colSpan: '1', rowSpan: '1', field: 'group_id', hAlign: 0, width: 200, formatter: '@', cellType: 'customizeCombo', comboItems: getSelectGroup(), }, ], emptyRows: 0, headRows: 1, headRowHeight: [32], headColWidth: [32], defaultRowHeight: 21, headerFont: '12px 微软雅黑', font: '12px 微软雅黑', }; sjsSettingObj.setFxTreeStyle(xmjSpreadSetting, sjsSettingObj.FxTreeStyle.jz); SpreadJsObj.initSheet(xmjSheet, xmjSpreadSetting); const xmjTree = createNewPathTree('gather', { id: 'ledger_id', pid: 'ledger_pid', order: 'order', level: 'level', rootId: -1 }); let tenderId; const loadTenderData = function(tid) { tenderId = tid; postData(`/sp/${spid}/quality/tender/${tid}/load`, {filter: 'xmj;pos;quality'}, function(result) { const ledgerTree = createNewPathTree('ledger', { id: 'ledger_id', pid: 'ledger_pid', order: 'order', level: 'level', rootId: -1 }); const pos = new PosData({id: 'id', ledgerId: 'lid',}); ledgerTree.loadDatas(result.xmj); pos.loadDatas(result.pos); const recursiveLoad = function (node, parent, type = 'xmj') { if (type === 'xmj') { const cur = !node.b_code ? xmjTree.addNode({ id: node.id, tender_id: node.tender_id, code: node.code, name: node.name, rela_type: type, rela_id: node.id, rela_name: '', }, parent) : parent; if (node.children && node.children.length > 0) { for (const child of node.children) { recursiveLoad(child, cur); } } else { const posRange = pos.getLedgerPos(node.id) || []; for (const pos of posRange) { recursiveLoad(pos, cur, 'pos'); } } } if (type === 'pos') { if (!parent) return; const cur = parent.children ? parent.children.find(x => { return x.name === node.name }) : null; if (!cur) { xmjTree.addNode({ id: node.id, tender_id: node.tid, rela_id: parent.id, code: '', name: node.name, rela_type: 'type', rela_name: node.name, pid: [node.id]}, parent); } else { cur.pid.push(node.id); } } }; xmjTree.clearDatas(); for (const node of ledgerTree.children) { recursiveLoad(node); } xmjTree.sortTreeNode(false); const items = getSelectGroup(); const qualityIndex = []; for (const q of result.quality) { const key = q.rela_type + ';' + q.rela_id + ';' + q.rela_name; qualityIndex[key] = q; } for (const x of xmjTree.nodes) { const qua = qualityIndex[x.rela_type + ';' + x.rela_id + ';' + x.rela_name]; if (qua) { const index = items.findIndex( i => { return i.value === qua.group_id; } ); if (index < 0) return; x.group_id = qua.group_id; } } SpreadJsObj.loadSheetData(xmjSheet, SpreadJsObj.DataType.Tree, xmjTree); }); }; $('body').on('click', 'tr[tid]', function() { if (!$(this).hasClass('table-active')) { $('tr[tid].table-active').removeClass('table-active'); $(this).addClass('table-active'); if (!xmjSpread.shown) { setTimeout(() => { loadTenderData($('.table-active').attr('tid')); }, 1000); } else { loadTenderData($('.table-active').attr('tid')); } } }); xmjSpread.bind(spreadNS.Events.EditEnded, function (e, info) { if (!info.sheet.zh_setting) return; const col = info.sheet.zh_setting.cols[info.col]; if (col.field !== 'group_id') return; const node = SpreadJsObj.getSelectObject(info.sheet); const updateData = { rela_type: node.rela_type, rela_id: node.rela_id, rela_name: node.rela_name, group_id: info.editingText || '' }; if (updateData.group_id === node.group_id || (!updateData.group_id && !node.group_id)) return; // 更新至服务器 postData(`/sp/${spid}/quality/tender/${node.tender_id}/rule/save`, { quality: updateData }, function (result) { node.group_id = result.group_id; SpreadJsObj.reLoadRowData(info.sheet, info.row, 1); }, function() { SpreadJsObj.reLoadRowData(info.sheet, info.row, 1); }); }); });