quality_rule.js 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628
  1. 'use strict';
  2. $(() => {
  3. autoFlashHeight();
  4. const StatusConst = (function(){
  5. const result = [
  6. { field: 'gxby_status', title: '工序报验', type: 'enum', range: thirdParty.gxby},
  7. // { field: 'gxby_date', title: '完工日期', type: 'time'},
  8. { field: 'dagl_status', title: '档案管理', type: 'enum', range: thirdParty.dagl},
  9. ];
  10. return result;
  11. })();
  12. const CheckConst = [
  13. { 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: '包含'}] }] },
  14. { 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: '包含'}] }] },
  15. { 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: '包含'}] }] },
  16. { 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: '包含'}] }] },
  17. { 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: '包含'}]}] },
  18. ];
  19. const groupObj = (function(list){
  20. const groups = list;
  21. let curGroup;
  22. const getGroups = function() {
  23. return groups;
  24. };
  25. const getConditionHtml = function(condition) {
  26. const html = [];
  27. for (const check of condition) {
  28. if (html.length > 0) html.push('</br>');
  29. html.push(`[${check.blockName}]${check.fieldName} ${check.operateName} ${check.value}${check.multi ? '(多)' : ''}`);
  30. }
  31. return html.join('');
  32. };
  33. const getPushStatusHtml = function(pushStatus) {
  34. const html = [];
  35. for (const ps of pushStatus) {
  36. if (html.length > 0) html.push('</br>');
  37. const fieldConst = StatusConst.find(x => { return x.field === ps.field; });
  38. if (!fieldConst) continue;
  39. switch(ps.field) {
  40. case 'gxby_status':
  41. case 'dagl_status':
  42. const valueConst = fieldConst.range.find(x => { return x.value === ps.value; });
  43. if (valueConst) {
  44. html.push(`${ps.fieldName} = ${valueConst.name}`);
  45. } else {
  46. html.push(`${ps.fieldName} = ${ps.value}(该值状态已删除)`);
  47. }
  48. break;
  49. case 'gxby_date':
  50. html.push(`${ps.fieldName} = ${ps.alias}`);
  51. break;
  52. }
  53. }
  54. return html.join('');
  55. };
  56. const getRuleHtml = function(rule) {
  57. const html = [];
  58. html.push('<td>', rule.name ,'</td>');
  59. html.push(`<td>`, getConditionHtml(rule.condition), '</td>');
  60. html.push(`<td>`, getPushStatusHtml(rule.push_status), '</td>');
  61. 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>
  62. <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>`);
  63. return html.join('');
  64. };
  65. const loadGroupRules = function(group) {
  66. const html = [];
  67. for (const rule of group.rules) {
  68. html.push(`<tr class="text-center" ruleId = "${rule.id}">`, getRuleHtml(rule), '</tr>');
  69. }
  70. $('#ruleOptions').html(html.join(''));
  71. };
  72. const setCurGroup = function(group) {
  73. curGroup = group;
  74. if (!group) return;
  75. loadGroupRules(group);
  76. $('dd[groupId]').removeClass('bg-warning');
  77. $(`dd[groupId=${curGroup.group_id}]`).addClass('bg-warning');
  78. };
  79. const getCurGroup = function() {
  80. return curGroup;
  81. };
  82. const getGroupCaptionHtml = function(group) {
  83. return `<div class="d-flex justify-content-between align-items-center table-file" groupId="${group.group_id}"><div>${group.group_name}</div>` +
  84. ' <div class="btn-group-table" style="display: none;">\n' +
  85. ' <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' +
  86. ' <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' +
  87. '</div></div>';
  88. };
  89. const getGroupHtml = function(group) {
  90. const html = [];
  91. html.push(`<dd class="list-group-item" groupId="${group.group_id}">`, getGroupCaptionHtml(group), '</dd>');
  92. return html.join('');
  93. };
  94. const addGroup = function() {
  95. postData(window.location.pathname + '/save', { group: {add: 1} }, function(result) {
  96. groups.push(result.add);
  97. $('#group-list').append(getGroupHtml(result.add));
  98. });
  99. };
  100. const renameGroup = function(group_id, group_name) {
  101. postData(window.location.pathname + '/save', { group: { update: { group_id, group_name } } }, function(result){
  102. const group = groups.find(x => { return x.group_id === result.update.group_id; });
  103. group.group_name = result.update.group_name;
  104. group.rules.forEach(x => { x.group_name === group.group_name; });
  105. $(`dd[groupId=${group.group_id}]`).html(getGroupCaptionHtml(group));
  106. });
  107. };
  108. const delGroup = function(group_id){
  109. postData(window.location.pathname + '/save', { group: {del: group_id} }, function(result) {
  110. $(`dd[groupId=${result.del}]`).remove();
  111. const groupIndex = groups.findIndex(x => { return x.group_id === group_id; });
  112. groups.splice(groupIndex, 1);
  113. });
  114. };
  115. const addRule = function(rule) {
  116. const rules = rule instanceof Array ? rule : [rule];
  117. const group = groups.find(x => { return x.group_id === rules[0].group_id; });
  118. group.rules.push(...rules);
  119. loadGroupRules(curGroup);
  120. };
  121. const updateRule = function(rule) {
  122. const group = groups.find(x => { return x.group_id === rule.group_id; });
  123. const orgRule = group.rules.find(x => { return x.id === rule.id; });
  124. if (!orgRule) return;
  125. _.assignIn(orgRule, rule);
  126. loadGroupRules(curGroup);
  127. };
  128. const delRule = function (rule) {
  129. const group = groups.find(x => { return x.group_id === rule.group_id; });
  130. const index = group.rules.findIndex(x => { return x.id === rule.id; });
  131. group.rules.splice(index, 1);
  132. loadGroupRules(curGroup);
  133. };
  134. if (groups.length > 0) setCurGroup(groups[0]);
  135. return { getGroups, setCurGroup, getCurGroup, addGroup, delGroup, renameGroup, addRule, updateRule, delRule, getConditionHtml, getPushStatusHtml }
  136. })(ruleGroups);
  137. const ruleSaveObj = (function(){
  138. let group_id, group_name;
  139. const addCheckHtml = function(check) {
  140. const html = [];
  141. 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>`,
  142. '<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>');
  143. $('#condition-list').append(html.join(''));
  144. };
  145. const addStatusHtml = function(status) {
  146. const html = [];
  147. html.push('<tr>');
  148. const selectStatus = StatusConst.find(x => { return x.field === status.field; });
  149. const value = selectStatus.range.find(x => { return x.value === status.value; });
  150. html.push(`<td status-info="${status.fieldName}&^&${status.field}&^&${status.value}"> ${status.fieldName} = ${value ? value.name : status.value}</td>`);
  151. 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>');
  152. html.push('</tr>');
  153. $('#status-list').append(html.join(''));
  154. };
  155. const getConditionBlockHtml = function(blocks) {
  156. const html = [];
  157. for (const d of blocks) {
  158. html.push(`<option value="${d.key}">${d.name}</option>`);
  159. }
  160. $('#condition-block').html(html.join(''));
  161. getConditionFieldHtml(blocks[0]);
  162. };
  163. const getConditionFieldHtml = function(block) {
  164. const html = [];
  165. for (const d of block.checks) {
  166. html.push(`<option value="${d.key}">${d.name}</option>`);
  167. }
  168. $('#condition-field').html(html.join(''));
  169. getConditionOperateHtml(block.checks[0]);
  170. showMulti(block.checks[0]);
  171. };
  172. const getConditionOperateHtml = function(check) {
  173. const html = [];
  174. for (const d of check.operate) {
  175. html.push(`<option value="${d.key}">${d.name}</option>`);
  176. }
  177. $('#condition-operate').html(html.join(''));
  178. };
  179. const showMulti = function (check) {
  180. if (check.multi) {
  181. $('#multi-set').show();
  182. } else {
  183. $('#multi-set').hide();
  184. $('#condition-multi')[0].checked = false;
  185. }
  186. };
  187. const getStatusFieldHtml = function(fields) {
  188. const html = [];
  189. for (const d of fields) {
  190. html.push(`<option value="${d.field}">${d.title}</option>`);
  191. }
  192. $('#status-field').html(html.join(''));
  193. getStatusValueHtml(fields[0]);
  194. };
  195. const getStatusValueHtml = function(status) {
  196. const html = [];
  197. for (const d of status.range) {
  198. html.push(`<option value="${d.value}">${d.name}</option>`);
  199. }
  200. $('#status-value').html(html.join(''));
  201. };
  202. const initModal = function() {
  203. getConditionBlockHtml(CheckConst);
  204. getStatusFieldHtml(StatusConst);
  205. };
  206. initModal();
  207. $('#condition-add').click(() => {
  208. const blockValue = $('#condition-block').val();
  209. const fieldValue = $('#condition-field').val();
  210. const operateValue = $('#condition-operate').val();
  211. const checkValue = $('#condition-value').val();
  212. const block = CheckConst.find(x => { return x.key === blockValue; });
  213. if (!block) {
  214. toastr.warning('未知判断模块');
  215. return;
  216. }
  217. const check = block.checks.find(x => { return x.key === fieldValue; });
  218. if (!check) {
  219. toastr.warning('未知判断条件');
  220. return;
  221. }
  222. if (!checkValue) {
  223. toastr.warning('请输入判断值');
  224. return;
  225. }
  226. const operate = check.operate.find(x => { return x.key === operateValue; });
  227. if (!operate) {
  228. toastr.warning('未知判断符');
  229. return;
  230. }
  231. const data = { blockKey: blockValue, blockName: block.name, fieldKey: fieldValue, fieldName: check.name, operateKey: operateValue, operateName: operate.name, value: checkValue };
  232. if (check.type === 'enum') {
  233. data.value = _.toInteger(data.value);
  234. if (_.isNil(data.value) || data.value < 0) {
  235. toastr.warning('判断值仅限0、正整数');
  236. return;
  237. }
  238. }
  239. if (check.multi) {
  240. data.multi = $('#condition-multi')[0].checked;
  241. }
  242. addCheckHtml(data);
  243. });
  244. $('#status-add').click(() => {
  245. const fieldValue = $('#status-field').val();
  246. const statusValue = parseInt($('#status-value').val());
  247. const field = StatusConst.find(x => { return x.field === fieldValue; });
  248. const status = field.range.find(x => { return x.value === statusValue; });
  249. if (!field || !status) {
  250. toastr.warning('未知判断条件');
  251. return;
  252. }
  253. const data = { fieldName: field.title, field: fieldValue, value: statusValue };
  254. addStatusHtml(data);
  255. });
  256. $('body').on('click', 'a[name=condition-del]', function() {
  257. $(this).parent().parent().remove();
  258. });
  259. $('body').on('click', 'a[name=status-del]', function() {
  260. $(this).parent().parent().remove();
  261. });
  262. $('#condition-block').click(function() {
  263. const value = this.value;
  264. const block = CheckConst.find(x => { return x.key === value; });
  265. getConditionFieldHtml(block);
  266. });
  267. $('#condition-field').click(function() {
  268. const blockValue = $('#condition-block').val();
  269. const block = CheckConst.find(x => { return x.key === blockValue; });
  270. const fieldValue = this.value;
  271. const check = block.checks.find(x => { return x.key === fieldValue; });
  272. getConditionOperateHtml(check);
  273. showMulti(check);
  274. });
  275. $('#status-field').click(function() {
  276. const field = this.value;
  277. const selectStatus = StatusConst.find(x => { return x.field === field; });
  278. getStatusValueHtml(selectStatus);
  279. });
  280. const showRuleModal = function(rule, group) {
  281. initModal();
  282. group_id = rule ? rule.group_id : group.group_id;
  283. group_name = rule ? rule.group_name : group.group_name;
  284. $('#rule-id').val(rule ? rule.id : '');
  285. $('#rule-name').val(rule ? rule.name : '');
  286. $('#loc-list').html('');
  287. $('#condition-list').html('');
  288. $('#status-list').html('');
  289. if (rule) {
  290. for (const c of rule.condition) {
  291. addCheckHtml(c);
  292. }
  293. for (const s of rule.push_status) {
  294. addStatusHtml(s);
  295. }
  296. }
  297. $('#save-rule').modal('show');
  298. };
  299. const getRuleData = function() {
  300. const data = {};
  301. data.name = $('#rule-name').val();
  302. if (data.name.length > 20) {
  303. toastr.warning('名称过长,请再精简');
  304. return;
  305. }
  306. try {
  307. data.condition = [];
  308. const clist = $('td[condition-info]');
  309. for (const c of clist) {
  310. const info = c.getAttribute('condition-info').split('&^&');
  311. data.condition.push({
  312. blockName: info[0],
  313. blockKey: info[1],
  314. fieldName: info[2],
  315. fieldKey: info[3],
  316. operateName: info[4],
  317. operateKey: info[5],
  318. value: info[6],
  319. multi: info[7] ? parseInt(info[7]) : 0,
  320. });
  321. }
  322. } catch(err) {
  323. toastr.warning('判断条件错误');
  324. return;
  325. }
  326. try {
  327. data.push_status = [];
  328. const slist = $('td[status-info]');
  329. for (const s of slist) {
  330. const info = s.getAttribute('status-info').split('&^&');
  331. data.push_status.push({
  332. fieldName: info[0],
  333. field: info[1],
  334. value: parseInt(info[2]),
  335. });
  336. }
  337. } catch(err) {
  338. toastr.warning('更新状态错误');
  339. return;
  340. }
  341. const id = $('#rule-id').val();
  342. if (id) {
  343. data.id = id;
  344. } else {
  345. data.group_id = group_id;
  346. data.group_name = group_name;
  347. }
  348. return data;
  349. };
  350. return { show: showRuleModal, data: getRuleData, }
  351. })();
  352. $('#add-rule').click(() => {
  353. ruleSaveObj.show(null, groupObj.getCurGroup());
  354. });
  355. $('body').on('click', 'a[name=editRule]', function() {
  356. const ruleId = $(this).parent().parent().attr('ruleId');
  357. const curGroup = groupObj.getCurGroup();
  358. if (!curGroup) return;
  359. const rule = curGroup.rules.find(x => { return x.id == ruleId; });
  360. ruleSaveObj.show(rule, curGroup);
  361. });
  362. $('body').on('click', 'a[name=delRule]', function() {
  363. const ruleId = $(this).parent().parent().attr('ruleId');
  364. const curGroup = groupObj.getCurGroup();
  365. if (!curGroup) return;
  366. const rule = curGroup.rules.find(x => { return x.id == ruleId; });
  367. if (curGroup.rules.length === 1) {
  368. toastr.warning('当前配置,仅剩最后一个规则,如需删除,请直接删除规则组');
  369. return;
  370. }
  371. postData(window.location.pathname + '/save', { rule: { del: rule } }, function (result) {
  372. if (result.del) groupObj.delRule(result.del);
  373. });
  374. });
  375. $('#save-rule-ok').click(function() {
  376. const loData = ruleSaveObj.data();
  377. const updateData = {};
  378. if (loData.id) {
  379. updateData.update = loData;
  380. } else {
  381. updateData.add = loData;
  382. }
  383. postData(window.location.pathname + '/save', { rule: updateData }, function (result) {
  384. if (result.add) groupObj.addRule(result.add);
  385. if (result.update) groupObj.updateRule(result.update);
  386. $('#save-rule').modal('hide');
  387. })
  388. });
  389. $('body').on('click', '.table-file', function(e) {
  390. if (this.getAttribute('renaming') === '1') return;
  391. if (e.target.tagName === 'A' || e.target.tagName === 'I' || e.target.tagName === 'INPUT') return;
  392. const groupId = this.getAttribute('groupId');
  393. const group = ruleGroups.find(x => { return x.group_id === groupId; });
  394. groupObj.setCurGroup(group);
  395. });
  396. $('body').on('mouseenter', ".table-file", function(){
  397. $(this).children(".btn-group-table").css("display","block");
  398. });
  399. $('body').on('mouseleave', ".table-file", function(){
  400. $(this).children(".btn-group-table").css("display","none");
  401. });
  402. $('body').on('click', 'a[name=renameGroup]', function(e){
  403. $(this).parents('.table-file').attr('renaming', '1');
  404. $(`#${this.getAttribute('aria-describedby')}`).remove();
  405. const groupId = $(this).parents('.table-file').attr('groupId');
  406. const group = ruleGroups.find(x => { return x.group_id === groupId; });
  407. if (!group) return;
  408. const html = [];
  409. html.push(`<div><input type="text" class="form-control form-control-sm" style="width: 160px" value="${group.group_name}"/></div>`);
  410. html.push('<div class="btn-group-table" style="display: none;">',
  411. `<a href="javascript: void(0)" name="renameOk" class="mr-1"><i class="fa fa-check fa-fw"></i></a>`,
  412. `<a href="javascript: void(0)" class="mr-1" name="renameCancel"><i class="fa fa-remove fa-fw text-danger"></i></a>`, '</div>');
  413. $(`.table-file[groupId=${groupId}]`).html(html.join(''));
  414. e.stopPropagation();
  415. });
  416. $('body').on('click', 'a[name=renameOk]', function(){
  417. const groupId = $(this).parents('.table-file').attr('groupId');
  418. const newName = $(this).parents('.table-file').find('input').val();
  419. groupObj.renameGroup(groupId, newName);
  420. $(this).parents('.table-file').attr('renaming', '0');
  421. });
  422. $('body').on('click', 'a[name=renameCancel]', function() {
  423. $(this).parents('.table-file').attr('renaming', '0');
  424. const groupId = $(this).parents('.table-file').attr('groupId');
  425. const group = ruleGroups.find(x => { return x.group_id === groupId; });
  426. if (!group) return;
  427. const html = [];
  428. html.push(`<div>${group.group_name}</div>`);
  429. html.push('<div class="btn-group-table" style="display: none;">',
  430. '<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>',
  431. '<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>',
  432. '</div>');
  433. $(`.table-file[groupId=${groupId}]`).html(html.join(''));
  434. });
  435. $('body').on('click', 'a[name=delGroup]', function(e){
  436. e.stopPropagation();
  437. const groupId = $(this).parents('.table-file').attr('groupId');
  438. groupObj.delGroup(groupId);
  439. });
  440. $('#addGroup').click(function() {
  441. groupObj.addGroup();
  442. });
  443. const loadCopyRuleList= function(groupId) {
  444. const group = groupObj.getGroups().find(x => { return x.group_id === groupId; });
  445. const ruleHtml = group.rules.map(rule => {
  446. 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>`
  447. });
  448. $('#copy-rule-list').html(ruleHtml);
  449. };
  450. $('#copy-rule').on('show.bs.modal', function() {
  451. const groups = groupObj.getGroups();
  452. const groupHtml = groups.map(x => { return `<option value="${x.group_id}">${x.group_name}</option>`});
  453. $('#select-group').html(groupHtml.join(''));
  454. loadCopyRuleList(groups[0].group_id);
  455. });
  456. $('#select-group').click(function() {
  457. loadCopyRuleList(this.value);
  458. });
  459. $('#copy-rule-ok').click(function() {
  460. const selects = $('input:checked', '#copy-rule');
  461. if (selects.length === 0) {
  462. toastr.warning('请选择要拷贝的规则');
  463. return;
  464. }
  465. const copy = selects.map(function() { return this.getAttribute('ruleId'); }).get().join(',');
  466. const updateData = { rule: { copy, group_id: groupObj.getCurGroup().group_id } };
  467. postData(window.location.pathname + '/save', updateData, function (result) {
  468. if (result.add) groupObj.addRule(result.add);
  469. $('#copy-rule').modal('hide');
  470. })
  471. });
  472. const getSelectGroup = function() {
  473. const selectGroup = [{ value: '', text: '' }];
  474. const groups = groupObj.getGroups();
  475. for (const g of groups) {
  476. selectGroup.push({ value: g.group_id, text: g.group_name });
  477. }
  478. return selectGroup;
  479. };
  480. const xmjSpread = SpreadJsObj.createNewSpread($('#xmj-spread')[0]);
  481. const xmjSheet = xmjSpread.getActiveSheet();
  482. $('[role=tab]').click(function() {
  483. const items = getSelectGroup();
  484. const groupComboCell = SpreadJsObj.CellType.getCustomizeComboCellType(items);
  485. xmjTree.datas.forEach(x => {
  486. if (!x) return;
  487. const index = items.findIndex( i => { return i.value === x.group_id; } );
  488. if (index < 0) x.group_id = '';
  489. });
  490. xmjSheet.getRange(-1, 2, -1, 1).cellType(groupComboCell);
  491. SpreadJsObj.reloadColData(xmjSheet, 2);
  492. if (xmjSpread.shown) return;
  493. setTimeout(() => {
  494. xmjSpread.refresh();
  495. xmjSpread.shown = true;
  496. }, 100);
  497. });
  498. const xmjSpreadSetting = {
  499. cols: [
  500. { title: '工程编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 240, formatter: '@', cellType: 'tree', readOnly: true, },
  501. { title: '工程名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 350, formatter: '@', readOnly: true, },
  502. { title: '规则组', colSpan: '1', rowSpan: '1', field: 'group_id', hAlign: 0, width: 200, formatter: '@', cellType: 'customizeCombo', comboItems: getSelectGroup(), },
  503. ],
  504. emptyRows: 0,
  505. headRows: 1,
  506. headRowHeight: [32],
  507. headColWidth: [32],
  508. defaultRowHeight: 21,
  509. headerFont: '12px 微软雅黑',
  510. font: '12px 微软雅黑',
  511. };
  512. sjsSettingObj.setFxTreeStyle(xmjSpreadSetting, sjsSettingObj.FxTreeStyle.jz);
  513. SpreadJsObj.initSheet(xmjSheet, xmjSpreadSetting);
  514. const xmjTree = createNewPathTree('gather', { id: 'ledger_id', pid: 'ledger_pid', order: 'order', level: 'level', rootId: -1 });
  515. let tenderId;
  516. const loadTenderData = function(tid) {
  517. tenderId = tid;
  518. postData(`/sp/${spid}/quality/tender/${tid}/load`, {filter: 'xmj;pos;quality'}, function(result) {
  519. const ledgerTree = createNewPathTree('ledger', { id: 'ledger_id', pid: 'ledger_pid', order: 'order', level: 'level', rootId: -1 });
  520. const pos = new PosData({id: 'id', ledgerId: 'lid',});
  521. ledgerTree.loadDatas(result.xmj);
  522. pos.loadDatas(result.pos);
  523. const recursiveLoad = function (node, parent, type = 'xmj') {
  524. if (type === 'xmj') {
  525. 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;
  526. if (node.children && node.children.length > 0) {
  527. for (const child of node.children) {
  528. recursiveLoad(child, cur);
  529. }
  530. } else {
  531. const posRange = pos.getLedgerPos(node.id) || [];
  532. for (const pos of posRange) {
  533. recursiveLoad(pos, cur, 'pos');
  534. }
  535. }
  536. }
  537. if (type === 'pos') {
  538. if (!parent) return;
  539. const cur = parent.children ? parent.children.find(x => { return x.name === node.name }) : null;
  540. if (!cur) {
  541. 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);
  542. } else {
  543. cur.pid.push(node.id);
  544. }
  545. }
  546. };
  547. xmjTree.clearDatas();
  548. for (const node of ledgerTree.children) {
  549. recursiveLoad(node);
  550. }
  551. xmjTree.sortTreeNode(false);
  552. const items = getSelectGroup();
  553. const qualityIndex = [];
  554. for (const q of result.quality) {
  555. const key = q.rela_type + ';' + q.rela_id + ';' + q.rela_name;
  556. qualityIndex[key] = q;
  557. }
  558. for (const x of xmjTree.nodes) {
  559. const qua = qualityIndex[x.rela_type + ';' + x.rela_id + ';' + x.rela_name];
  560. if (qua) {
  561. const index = items.findIndex( i => { return i.value === qua.group_id; } );
  562. if (index < 0) return;
  563. x.group_id = qua.group_id;
  564. }
  565. }
  566. SpreadJsObj.loadSheetData(xmjSheet, SpreadJsObj.DataType.Tree, xmjTree);
  567. });
  568. };
  569. $('body').on('click', 'tr[tid]', function() {
  570. if (!$(this).hasClass('table-active')) {
  571. $('tr[tid].table-active').removeClass('table-active');
  572. $(this).addClass('table-active');
  573. if (!xmjSpread.shown) {
  574. setTimeout(() => {
  575. loadTenderData($('.table-active').attr('tid'));
  576. }, 1000);
  577. } else {
  578. loadTenderData($('.table-active').attr('tid'));
  579. }
  580. }
  581. });
  582. xmjSpread.bind(spreadNS.Events.EditEnded, function (e, info) {
  583. if (!info.sheet.zh_setting) return;
  584. const col = info.sheet.zh_setting.cols[info.col];
  585. if (col.field !== 'group_id') return;
  586. const node = SpreadJsObj.getSelectObject(info.sheet);
  587. const updateData = { rela_type: node.rela_type, rela_id: node.rela_id, rela_name: node.rela_name, group_id: info.editingText || '' };
  588. if (updateData.group_id === node.group_id || (!updateData.group_id && !node.group_id)) return;
  589. // 更新至服务器
  590. postData(`/sp/${spid}/quality/tender/${node.tender_id}/rule/save`, { quality: updateData }, function (result) {
  591. node.group_id = result.group_id;
  592. SpreadJsObj.reLoadRowData(info.sheet, info.row, 1);
  593. }, function() {
  594. SpreadJsObj.reLoadRowData(info.sheet, info.row, 1);
  595. });
  596. });
  597. });