123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628 |
- '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('</br>');
- 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('</br>');
- 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('<td>', rule.name ,'</td>');
- html.push(`<td>`, getConditionHtml(rule.condition), '</td>');
- html.push(`<td>`, getPushStatusHtml(rule.push_status), '</td>');
- html.push(`<td><a href="javascript: void(0);" class="mr-1" data-toggle="tooltip" data-placement="bottom" data-original-title="编辑" name="editRule"><i class="fa fa-pencil fa-fw"></i></a>
- <a href="javascript: void(0);" class="mr-1" data-toggle="tooltip" data-placement="bottom" data-original-title="删除" name="delRule"><i class="fa fa-trash-o fa-fw text-danger"></i></a></td>`);
- return html.join('');
- };
- const loadGroupRules = function(group) {
- const html = [];
- for (const rule of group.rules) {
- html.push(`<tr class="text-center" ruleId = "${rule.id}">`, getRuleHtml(rule), '</tr>');
- }
- $('#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 `<div class="d-flex justify-content-between align-items-center table-file" groupId="${group.group_id}"><div>${group.group_name}</div>` +
- ' <div class="btn-group-table" style="display: none;">\n' +
- ' <a href="javascript: void(0);" class="mr-1" data-toggle="tooltip" data-placement="bottom" data-original-title="编辑" name="renameGroup"><i class="fa fa-pencil fa-fw"></i></a>\n' +
- ' <a href="javascript: void(0);" class="mr-1" data-toggle="tooltip" data-placement="bottom" data-original-title="删除" name="delGroup"><i class="fa fa-trash-o fa-fw text-danger"></i></a>\n' +
- '</div></div>';
- };
- const getGroupHtml = function(group) {
- const html = [];
- html.push(`<dd class="list-group-item" groupId="${group.group_id}">`, getGroupCaptionHtml(group), '</dd>');
- 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('<tr>', `<td condition-info="${check.blockName}&^&${check.blockKey}&^&${check.fieldName}&^&${check.fieldKey}&^&${check.operateName}&^&${check.operateKey}&^&${check.value}&^&${check.multi ? 1 : 0}">[${check.blockName}]${check.fieldName} ${check.operateName} ${check.value}${check.multi ? '(多)' : ''}</td>`,
- '<td><a href="javascript: void(0);" class="mr-1" data-toggle="tooltip" data-placement="bottom" data-original-title="删除" name="condition-del"><i class="fa fa-trash-o fa-fw text-danger"></i></a></td>', '</tr>');
- $('#condition-list').append(html.join(''));
- };
- const addStatusHtml = function(status) {
- const html = [];
- html.push('<tr>');
- const selectStatus = StatusConst.find(x => { return x.field === status.field; });
- const value = selectStatus.range.find(x => { return x.value === status.value; });
- html.push(`<td status-info="${status.fieldName}&^&${status.field}&^&${status.value}"> ${status.fieldName} = ${value ? value.name : status.value}</td>`);
- html.push('<td><a href="javascript: void(0);" class="mr-1" data-toggle="tooltip" data-placement="bottom" data-original-title="删除" name="status-del"><i class="fa fa-trash-o fa-fw text-danger"></i></a></td>');
- html.push('</tr>');
- $('#status-list').append(html.join(''));
- };
- const getConditionBlockHtml = function(blocks) {
- const html = [];
- for (const d of blocks) {
- html.push(`<option value="${d.key}">${d.name}</option>`);
- }
- $('#condition-block').html(html.join(''));
- getConditionFieldHtml(blocks[0]);
- };
- const getConditionFieldHtml = function(block) {
- const html = [];
- for (const d of block.checks) {
- html.push(`<option value="${d.key}">${d.name}</option>`);
- }
- $('#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(`<option value="${d.key}">${d.name}</option>`);
- }
- $('#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(`<option value="${d.field}">${d.title}</option>`);
- }
- $('#status-field').html(html.join(''));
- getStatusValueHtml(fields[0]);
- };
- const getStatusValueHtml = function(status) {
- const html = [];
- for (const d of status.range) {
- html.push(`<option value="${d.value}">${d.name}</option>`);
- }
- $('#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(`<div><input type="text" class="form-control form-control-sm" style="width: 160px" value="${group.group_name}"/></div>`);
- html.push('<div class="btn-group-table" style="display: none;">',
- `<a href="javascript: void(0)" name="renameOk" class="mr-1"><i class="fa fa-check fa-fw"></i></a>`,
- `<a href="javascript: void(0)" class="mr-1" name="renameCancel"><i class="fa fa-remove fa-fw text-danger"></i></a>`, '</div>');
- $(`.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(`<div>${group.group_name}</div>`);
- html.push('<div class="btn-group-table" style="display: none;">',
- '<a href="javascript: void(0);" class="mr-1" data-toggle="tooltip" data-placement="bottom" data-original-title="编辑" name="renameGroup"><i class="fa fa-pencil fa-fw"></i></a>',
- '<a href="javascript: void(0);" class="mr-1" data-toggle="tooltip" data-placement="bottom" data-original-title="删除" name="delGroup"><i class="fa fa-trash-o fa-fw text-danger"></i></a>',
- '</div>');
- $(`.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 `<tr class="text-center"><td><input type="checkbox" name="copy-rule-id" ruleId="${rule.id}"></td><td>${rule.name}</td><td>${groupObj.getConditionHtml(rule.condition)}</td><td>${groupObj.getPushStatusHtml(rule.push_status)}</td></tr>`
- });
- $('#copy-rule-list').html(ruleHtml);
- };
- $('#copy-rule').on('show.bs.modal', function() {
- const groups = groupObj.getGroups();
- const groupHtml = groups.map(x => { return `<option value="${x.group_id}">${x.group_name}</option>`});
- $('#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);
- });
- });
- });
|