quality_rule.js 30 KB

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