revise_price.js 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Mai
  6. * @date
  7. * @version
  8. */
  9. const showSideTools = function (show) {
  10. const left = $('#left-view'), right = $('#right-view'), parent = left.parent();
  11. if (show) {
  12. right.show();
  13. autoFlashHeight();
  14. const percent = 100 - right.outerWidth() /parent.width() * 100;
  15. left.css('width', percent + '%');
  16. } else {
  17. left.width(parent.width());
  18. right.hide();
  19. }
  20. };
  21. const setPriceHint = function (show) {
  22. const hinticon = show ? 'fa-bell' : undefined;
  23. subMiniMenu.$children[2].hinticon = hinticon;
  24. subMenu.$children[2].hinticon = hinticon;
  25. };
  26. $(document).ready(() => {
  27. const ledgerGclSpreadSetting = {
  28. cols: [
  29. { title: '清单编号', colSpan: '1', rowSpan: '2', field: 'b_code', hAlign: 0, width: 80, formatter: '@' },
  30. { title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 200, formatter: '@' },
  31. { title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 60, formatter: '@' },
  32. { title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 80, type: 'Number' },
  33. ],
  34. emptyRows: 0,
  35. headRows: 1,
  36. headRowHeight: [32],
  37. headColWidth: [30],
  38. defaultRowHeight: 21,
  39. headerFont: '12px 微软雅黑',
  40. font: '12px 微软雅黑',
  41. readOnly: true,
  42. };
  43. const ledgerXmjSpreadSetting = {
  44. cols: [
  45. {title: '项目节编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 100, formatter: '@'},
  46. {title: '单位工程', colSpan: '1', rowSpan: '1', field: 'dwgc', hAlign: 0, width: 80, formatter: '@'},
  47. {title: '分部工程', colSpan: '1', rowSpan: '1', field: 'fbgc', hAlign: 0, width: 80, formatter: '@'},
  48. {title: '分项工程', colSpan: '1', rowSpan: '1', field: 'fxgc', hAlign: 0, width: 80, formatter: '@'},
  49. {title: '细目', colSpan: '1', rowSpan: '1', field: 'jldy', hAlign: 0, width: 80, formatter: '@'},
  50. {title: '计量单元', colSpan: '1', rowSpan: '1', field: 'bwmx', hAlign: 0, width: 80, formatter: '@'},
  51. ],
  52. emptyRows: 0,
  53. headRows: 1,
  54. headRowHeight: [32],
  55. headColWidth: [30],
  56. defaultRowHeight: 21,
  57. headerFont: '12px 微软雅黑',
  58. font: '12px 微软雅黑',
  59. readOnly: true,
  60. };
  61. const priceSpreadSetting = {
  62. cols: [
  63. { title: '清单编号', colSpan: '1', rowSpan: '2', field: 'b_code', hAlign: 0, width: 100, formatter: '@', readOnly: true },
  64. { title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 210, formatter: '@', readOnly: true },
  65. { title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 60, formatter: '@', readOnly: true },
  66. { title: '当前单价', colSpan: '1', rowSpan: '2', field: 'org_price', hAlign: 2, width: 80, type: 'Number', readOnly: true },
  67. { title: '调整后单价', colSpan: '1', rowSpan: '2', field: 'new_price', hAlign: 2, width: 80, type: 'Number' },
  68. { title: '备注', colSpan: '1', rowSpan: '2', field: 'memo', hAlign: 2, width: 150, formatter: '@' },
  69. ],
  70. emptyRows: 0,
  71. headRows: 1,
  72. headRowHeight: [32],
  73. headColWidth: [30],
  74. defaultRowHeight: 21,
  75. headerFont: '12px 微软雅黑',
  76. font: '12px 微软雅黑',
  77. readOnly,
  78. getColor: function (sheet, data, row, col, defaultColor) {
  79. if (!data || (data.rela_lid && data.rela_cid)) return defaultColor;
  80. const samePrice = sheet.zh_data.find(x => {
  81. return x.b_code === data.b_code && x.name === data.name && x.unit === data.unit && x.org_price === data.org_price;
  82. });
  83. return samePrice ? '#f5deb3' : defaultColor;
  84. }
  85. };
  86. const priceBwSpreadSetting = {
  87. cols: [
  88. {title: '项目节编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 150, formatter: '@', cellType: 'tree'},
  89. {title: '清单编号', colSpan: '1', rowSpan: '1', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
  90. {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 230, formatter: '@'},
  91. {title: '单位', colSpan: '1', rowSpan: '1', field: 'unit', hAlign: 1, width: 60, formatter: '@'},
  92. {title: '原单价', colSpan: '1', rowSpan: '1', field: 'unit_price', hAlign: 2, width: 60, type: 'Number'},
  93. ],
  94. headRows: 1,
  95. emptyRows: 0,
  96. headRowHeight: [25],
  97. defaultRowHeight: 21,
  98. headerFont: '12px 微软雅黑',
  99. font: '12px 微软雅黑',
  100. readOnly: true,
  101. };
  102. sjsSettingObj.setFxTreeStyle(priceBwSpreadSetting, sjsSettingObj.FxTreeStyle.jz);
  103. const priceChangeSpreadSetting = {
  104. cols: [
  105. {title: '变更令', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 80, formatter: '@'},
  106. {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 230, formatter: '@'},
  107. {title: '批复文号', colSpan: '1', rowSpan: '1', field: 'w_code', hAlign: 1, width: 80, formatter: '@'},
  108. ],
  109. headRows: 1,
  110. emptyRows: 0,
  111. headRowHeight: [25],
  112. defaultRowHeight: 21,
  113. headerFont: '12px 微软雅黑',
  114. font: '12px 微软雅黑',
  115. readOnly: true,
  116. };
  117. autoFlashHeight();
  118. const bcontent = $(".bcontent-wrap").length > 0 ? $(".bcontent-wrap").height() : 0;
  119. $(".sp-wrap").height(bcontent-30);
  120. const priceSpread = SpreadJsObj.createNewSpread($('#price-spread')[0]);
  121. const priceSheet = priceSpread.getActiveSheet();
  122. const priceBwSpread = SpreadJsObj.createNewSpread($('#price-bw-spread')[0]);
  123. const priceBwSheet = priceBwSpread.getActiveSheet();
  124. const priceChangeSpread = SpreadJsObj.createNewSpread($('#price-change-spread')[0]);
  125. const priceChangeSheet = priceChangeSpread.getActiveSheet();
  126. SpreadJsObj.initSheet(priceSheet, priceSpreadSetting);
  127. SpreadJsObj.initSheet(priceBwSheet, priceBwSpreadSetting);
  128. SpreadJsObj.initSheet(priceChangeSheet, priceChangeSpreadSetting);
  129. class RevisePrice {
  130. constructor () {
  131. this.data = [];
  132. this.tree = createNewPathTree('filter', {
  133. id: 'ledger_id',
  134. pid: 'ledger_pid',
  135. order: 'order',
  136. level: 'level',
  137. rootId: -1,
  138. fullPath: 'full_path',
  139. keys: ['id', 'tender_id', 'ledger_id'],
  140. });
  141. }
  142. resortData() {
  143. this.data.sort(function (a, b) {
  144. return a.order - b.order;
  145. });
  146. }
  147. loadDatas(datas, treeData, changeData) {
  148. this.data = datas;
  149. this.tree.loadDatas(treeData);
  150. this.resortData();
  151. this.change = changeData;
  152. this.relaChange = [];
  153. if (this.data.length > 0) this.refreshRela(this.data[0]);
  154. }
  155. loadUpdateData(updateData) {
  156. if (updateData.add) {
  157. for (const a of updateData.add) {
  158. this.data.push(a);
  159. }
  160. }
  161. if (updateData.update) {
  162. for (const u of updateData.update) {
  163. const d = this.data.find(function (x) {
  164. return u.id === x.id;
  165. });
  166. if (d) {
  167. _.assign(d, u);
  168. } else {
  169. this.data.push(d);
  170. }
  171. }
  172. }
  173. if (updateData.del) {
  174. _.remove(this.data, function (d) {
  175. return updateData.del.indexOf(d.id) >= 0;
  176. });
  177. }
  178. this.resortData();
  179. }
  180. getSamePrice(price) {
  181. return this.data.filter(x => {
  182. if (x.id === price.id) return false;
  183. return x.b_code === price.b_code && x.name === price.name && x.unit === price.unit && x.org_price === price.org_price;
  184. });
  185. }
  186. refreshTreeRela(price, samePrice) {
  187. if (!samePrice) samePrice = this.getSamePrice(price);
  188. if (price.rela_lid) {
  189. this.tree.loadFilter(price.rela_lid);
  190. } else {
  191. const invalid = [];
  192. for (const sp of samePrice) {
  193. const lid = sp.rela_lid ? sp.rela_lid.split(',') : [];
  194. invalid.push(...lid);
  195. }
  196. this.tree.loadFilter(invalid.join(','), 'filter');
  197. }
  198. }
  199. refreshChangeRela(price, samePrice) {
  200. if (!samePrice) samePrice = this.getSamePrice(price);
  201. if (price.rela_cid) {
  202. const choose = price.rela_cid.split(',');
  203. for (const c of this.change) {
  204. c.rela = choose.indexOf(c.cid + '') >= 0;
  205. c.valid = c.rela;
  206. }
  207. } else {
  208. const invalid = [];
  209. for (const sp of samePrice) {
  210. const cid = sp.rela_cid ? sp.rela_cid.split(',') : [];
  211. invalid.push(...cid);
  212. }
  213. for (const c of this.change) {
  214. c.rela = invalid.indexOf(c.cid + '') >= 0;
  215. if (c.rela) {
  216. c.valid = 0;
  217. } else {
  218. const exist = c.bills.find(x => {
  219. return x.code === price.b_code && x.name === price.name && x.unit === price.unit && x.unit_price === price.org_price;
  220. });
  221. c.valid = exist;
  222. }
  223. }
  224. }
  225. this.relaChange.length = 0;
  226. for (const c of this.change) {
  227. if (c.valid) this.relaChange.push(c);
  228. }
  229. }
  230. refreshRela(price) {
  231. const samePrice = this.getSamePrice(price);
  232. this.refreshTreeRela(price, samePrice);
  233. this.refreshChangeRela(price, samePrice);
  234. }
  235. }
  236. const revisePrice = new RevisePrice();
  237. const priceOprObj = {
  238. addRevisePrice(data) {
  239. const op = revisePrice.data.find(x => {
  240. return x.b_code === data.b_code && x.name === x.name && x.unit === x.unit && checkZero(ZhCalc.sub(x.org_price, data.unit_price)) && (!x.rela_lid || !x.rela_cid);
  241. });
  242. if (op) {
  243. toastr.warning('已存在该单价调整');
  244. SpreadJsObj.locateData(priceSheet, op);
  245. return;
  246. }
  247. postData(window.location.pathname + '/update', { add: { b_code: data.b_code, name: data.name, unit: data.unit, unit_price: data.unit_price } }, result => {
  248. revisePrice.loadUpdateData(result);
  249. SpreadJsObj.reLoadSheetData(priceSheet);
  250. setPriceHint(revisePrice.data.length > 0);
  251. });
  252. },
  253. /**
  254. * 删除按钮响应事件
  255. * @param sheet
  256. */
  257. deletePress: function (sheet) {
  258. if (!sheet.zh_setting || readOnly) return;
  259. const sortData = sheet.zh_data;
  260. const datas = [];
  261. const sels = sheet.getSelections();
  262. if (!sels || !sels[0]) return;
  263. for (let iRow = sels[0].row; iRow < sels[0].row + sels[0].rowCount; iRow++) {
  264. let bDel = false;
  265. const node = sortData[iRow];
  266. if (node) {
  267. const data = {id: node.id};
  268. for (let iCol = sels[0].col; iCol < sels[0].col + sels[0].colCount; iCol++) {
  269. const style = sheet.getStyle(iRow, iCol);
  270. if (!style.locked) {
  271. const colSetting = sheet.zh_setting.cols[iCol];
  272. data[colSetting.field] = null;
  273. bDel = true;
  274. }
  275. }
  276. if (bDel) {
  277. datas.push(data);
  278. }
  279. }
  280. }
  281. if (datas.length > 0) {
  282. postData(window.location.pathname + '/update', {update: datas}, function (result) {
  283. revisePrice.loadUpdateData(result);
  284. SpreadJsObj.reLoadSheetData(priceSheet);
  285. }, function () {
  286. SpreadJsObj.reLoadSheetData(priceSheet);
  287. });
  288. }
  289. },
  290. delete: function (sheet) {
  291. if (!sheet.zh_setting || readOnly) return;
  292. const sortData = sheet.zh_data;
  293. const datas = [];
  294. const sels = sheet.getSelections();
  295. if (!sels || !sels[0]) return;
  296. for (let iRow = sels[0].row, iLen = sels[0].row + sels[0].rowCount; iRow < iLen; iRow++) {
  297. const node = sortData[iRow];
  298. datas.push(node.id);
  299. }
  300. if (datas.length > 0) {
  301. postData(window.location.pathname + '/update', {del: datas}, function (result) {
  302. revisePrice.loadUpdateData(result);
  303. SpreadJsObj.reLoadSheetData(priceSheet);
  304. setPriceHint(revisePrice.data.length > 0);
  305. }, function () {
  306. SpreadJsObj.reLoadSheetData(priceSheet);
  307. });
  308. }
  309. },
  310. editEnded: function (e, info) {
  311. if (!info.sheet.zh_setting || !info.sheet.zh_data) return;
  312. const node = info.sheet.zh_data[info.row];
  313. if (!node) return;
  314. const col = info.sheet.zh_setting.cols[info.col];
  315. const data = { update: { id: node.id, org_price: node.org_price } };
  316. const oldValue = node ? node[col.field] : null;
  317. const newValue = trimInvalidChar(info.editingText);
  318. if (oldValue == info.editingText || ((!oldValue || oldValue === '') && (newValue === ''))) {
  319. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  320. return;
  321. }
  322. if (col.type === 'Number') {
  323. const num = _.toNumber(newValue);
  324. if (num) data.update[col.field] = num;
  325. } else {
  326. data.update[col.field] = newValue;
  327. }
  328. postData(window.location.pathname + '/update', data, function (result) {
  329. revisePrice.loadUpdateData(result);
  330. SpreadJsObj.reLoadSheetData(info.sheet);
  331. }, function () {
  332. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  333. });
  334. },
  335. clipboardPasting(e, info) {
  336. const setting = info.sheet.zh_setting, sortData = info.sheet.zh_data;
  337. info.cancel = true;
  338. if (!setting || !sortData) return;
  339. const pasteData = info.pasteData.html
  340. ? SpreadJsObj.analysisPasteHtml(info.pasteData.html)
  341. : (info.pasteData.text === ''
  342. ? SpreadJsObj.Clipboard.getAnalysisPasteText()
  343. : SpreadJsObj.analysisPasteText(info.pasteData.text));
  344. const uDatas = [];
  345. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  346. const curRow = info.cellRange.row + iRow;
  347. const node = sortData[curRow];
  348. let bPaste = false;
  349. const data = {};
  350. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  351. const curCol = info.cellRange.col + iCol;
  352. const colSetting = setting.cols[curCol];
  353. const value = trimInvalidChar(pasteData[iRow][iCol]);
  354. if (colSetting.type === 'Number') {
  355. const num = _.toNumber(value);
  356. if (num) {
  357. data[colSetting.field] = num;
  358. bPaste = true;
  359. }
  360. } else {
  361. data[colSetting.field] = value;
  362. bPaste = true;
  363. }
  364. }
  365. if (bPaste) {
  366. data.id = node.id;
  367. uDatas.push(data);
  368. }
  369. }
  370. const updateData = {};
  371. if (uDatas.length > 0) updateData.update = uDatas;
  372. if (uDatas.length > 0) {
  373. postData(window.location.pathname + '/update', updateData, function (result) {
  374. revisePrice.loadUpdateData(result);
  375. SpreadJsObj.reLoadSheetData(info.sheet);
  376. });
  377. } else {
  378. SpreadJsObj.reLoadSheetData(info.sheet);
  379. }
  380. },
  381. upMove: function () {
  382. const sels = priceSheet.getSelections(), sortData = priceSheet.zh_data;
  383. const node = sortData[sels[0].row];
  384. const preNode = sortData[sels[0].row - 1];
  385. const data = [
  386. {id: node.id, order: preNode.order},
  387. {id: preNode.id, order: node.order}
  388. ];
  389. postData(window.location.pathname + '/update', {update: data}, function (result) {
  390. revisePrice.loadUpdateData(result);
  391. SpreadJsObj.reLoadRowsData(priceSheet, [sels[0].row, sels[0].row - 1]);
  392. priceSheet.setSelection(sels[0].row - 1, sels[0].col, sels[0].rowCount, sels[0].colCount);
  393. });
  394. },
  395. downMove: function () {
  396. const sels = priceSheet.getSelections(), sortData = priceSheet.zh_data;
  397. const node = sortData[sels[0].row];
  398. const nextNode = sortData[sels[0].row + 1];
  399. const data = [
  400. {id: node.id, order: nextNode.order},
  401. {id: nextNode.id, order: node.order}
  402. ];
  403. postData(window.location.pathname + '/update', {update: data}, function (result) {
  404. revisePrice.loadUpdateData(result);
  405. SpreadJsObj.reLoadRowsData(priceSheet, [sels[0].row, sels[0].row + 1]);
  406. priceSheet.setSelection(sels[0].row + 1, sels[0].col, sels[0].rowCount, sels[0].colCount);
  407. });
  408. },
  409. updateRelaLid: function (price, rela_lid) {
  410. const data = { update: { id: price.id, rela_lid } };
  411. postData(window.location.pathname + '/update', data, function (result) {
  412. revisePrice.loadUpdateData(result);
  413. revisePrice.refreshTreeRela(price);
  414. SpreadJsObj.refreshTreeRowVisible(priceBwSheet);
  415. SpreadJsObj.reloadRowBackColor(priceSheet, revisePrice.data.indexOf(price));
  416. });
  417. },
  418. updateRelaCid: function (price, rela_cid) {
  419. const data = { update: { id: price.id, rela_cid } };
  420. postData(window.location.pathname + '/update', data, function (result) {
  421. revisePrice.loadUpdateData(result);
  422. revisePrice.refreshChangeRela(price);
  423. SpreadJsObj.reLoadSheetData(priceChangeSheet);
  424. SpreadJsObj.reloadRowBackColor(priceSheet, revisePrice.data.indexOf(price));
  425. });
  426. },
  427. selectionChanged: function () {
  428. const price = SpreadJsObj.getSelectObject(priceSheet);
  429. revisePrice.refreshRela(price);
  430. SpreadJsObj.refreshTreeRowVisible(priceBwSheet);
  431. SpreadJsObj.reLoadSheetData(priceChangeSheet);
  432. },
  433. };
  434. if (!readOnly) {
  435. priceSheet.bind(spreadNS.Events.EditEnded, priceOprObj.editEnded);
  436. priceSheet.bind(spreadNS.Events.ClipboardPasting, priceOprObj.clipboardPasting);
  437. SpreadJsObj.addDeleteBind(priceSpread, priceOprObj.deletePress);
  438. $.contextMenu({
  439. selector: '#price-spread',
  440. build: function ($trigger, e) {
  441. const target = SpreadJsObj.safeRightClickSelection($trigger, e, priceSpread);
  442. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  443. },
  444. items: {
  445. del: {
  446. name: '删除',
  447. icon: 'fa-remove',
  448. callback: function (key, opt) {
  449. priceOprObj.delete(priceSheet);
  450. },
  451. disabled: function (key, opt) {
  452. const node = SpreadJsObj.getSelectObject(priceSheet);
  453. return node === undefined || node === null;
  454. },
  455. visible: function (key, opt) {
  456. return !readOnly;
  457. }
  458. },
  459. sprDel: '----',
  460. upMove: {
  461. name: '上移',
  462. icon: 'fa-arrow-up',
  463. callback: function (key, opt) {
  464. priceOprObj.upMove();
  465. },
  466. disabled: function (key, opt) {
  467. const sels = priceSheet.getSelections();
  468. if (!sels || !sels[0] || sels[0].row === 0) return true;
  469. const row = sels[0].row;
  470. const node = revisePrice.data[row];
  471. return node === undefined || node === null;
  472. },
  473. visible: function (key, opt) {
  474. return !readOnly;
  475. }
  476. },
  477. downMove: {
  478. name: '下移',
  479. icon: 'fa-arrow-down',
  480. callback: function (key, opt) {
  481. priceOprObj.downMove();
  482. },
  483. disabled: function (key, opt) {
  484. const sels = priceSheet.getSelections();
  485. if (!sels || !sels[0] || sels[0].row >= revisePrice.data.length - 1) return true;
  486. const row = sels[0].row;
  487. const node = revisePrice.data[row];
  488. return node === undefined || node === null;
  489. },
  490. visible: function (key, opt) {
  491. return !readOnly;
  492. }
  493. },
  494. sprMove: '----',
  495. chooseRelaBw: {
  496. name: '选择应用部位',
  497. icon: 'fa-link',
  498. callback: function (key, opt) {
  499. const price = SpreadJsObj.getSelectObject(priceSheet);
  500. const samePrice = revisePrice.getSamePrice(price);
  501. chooseRelaBw.show(price, samePrice);
  502. },
  503. disabled: function (key, opt) {
  504. const node = SpreadJsObj.getSelectObject(priceSheet);
  505. return !node;
  506. },
  507. visible: function (key, opt) {
  508. return !readOnly;
  509. }
  510. },
  511. chooseRelaChange: {
  512. name: '选择应用变更令',
  513. icon: 'fa-link',
  514. callback: function (key, opt) {
  515. const price = SpreadJsObj.getSelectObject(priceSheet);
  516. const samePrice = revisePrice.getSamePrice(price);
  517. chooseRelaChange.show(price, samePrice);
  518. },
  519. disabled: function (key, opt) {
  520. const node = SpreadJsObj.getSelectObject(priceSheet);
  521. return !node;
  522. },
  523. visible: function (key, opt) {
  524. return !readOnly;
  525. }
  526. },
  527. noRelaChange: {
  528. name: '不应用于变更令',
  529. icon: 'fa-unlink',
  530. callback: function (key, opt) {
  531. const price = SpreadJsObj.getSelectObject(priceSheet);
  532. priceOprObj.updateRelaCid(price, '-1');
  533. },
  534. disabled: function (key, opt) {
  535. const node = SpreadJsObj.getSelectObject(priceSheet);
  536. return !node;
  537. },
  538. visible: function (key, opt) {
  539. return !readOnly;
  540. }
  541. },
  542. },
  543. });
  544. }
  545. priceSpread.bind(spreadNS.Events.SelectionChanged, priceOprObj.selectionChanged);
  546. class LedgerGcl {
  547. constructor(setting) {
  548. this.setting = setting;
  549. this.spread = SpreadJsObj.createNewSpread($(this.setting.selector)[0]);
  550. this.sheet = this.spread.getActiveSheet();
  551. SpreadJsObj.initSheet(this.sheet, this.setting.spreadSetting);
  552. this.xmjSpread = SpreadJsObj.createNewSpread($(this.setting.xmjSelector)[0]);
  553. this.xmjSheet = this.xmjSpread.getActiveSheet();
  554. SpreadJsObj.initSheet(this.xmjSheet, this.setting.xmjSpreadSetting);
  555. if (!readOnly) {
  556. this.spread.bind(spreadNS.Events.CellDoubleClick, function (e, info) {
  557. const gcl = SpreadJsObj.getSelectObject(info.sheet);
  558. priceOprObj.addRevisePrice(gcl);
  559. });
  560. }
  561. const self = this;
  562. this.spread.bind(spreadNS.Events.SelectionChanged, function (e, info) {
  563. self.loadLeafXmj();
  564. });
  565. }
  566. loadData(bills, pos) {
  567. gclGatherModel.loadLedgerData(bills);
  568. gclGatherModel.loadPosData(pos);
  569. this.gcl = gclGatherModel.gatherGclData();
  570. this.sheet && SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, this.gcl);
  571. this.loadLeafXmj(0);
  572. }
  573. loadLeafXmj(iGclRow) {
  574. const gcl = iGclRow ? this.gcl[iGclRow] : SpreadJsObj.getSelectObject(this.sheet);
  575. SpreadJsObj.resetTopAndSelect(this.xmjSheet);
  576. if (gcl) {
  577. SpreadJsObj.loadSheetData(this.xmjSheet, SpreadJsObj.DataType.Data, gcl.leafXmjs);
  578. } else {
  579. SpreadJsObj.loadSheetData(this.xmjSheet, SpreadJsObj.DataType.Data, []);
  580. }
  581. }
  582. }
  583. const ledgerGcl = new LedgerGcl({
  584. selector: '#ledger-gcl-spread',
  585. spreadSetting: ledgerGclSpreadSetting,
  586. xmjSelector: '#ledger-xmj-spread',
  587. xmjSpreadSetting: ledgerXmjSpreadSetting,
  588. });
  589. $.subMenu({
  590. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  591. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  592. key: 'menu.1.0.0',
  593. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  594. callback: function (info) {
  595. if (info.mini) {
  596. $('.panel-title').addClass('fluid');
  597. $('#sub-menu').removeClass('panel-sidebar');
  598. } else {
  599. $('.panel-title').removeClass('fluid');
  600. $('#sub-menu').addClass('panel-sidebar');
  601. }
  602. autoFlashHeight();
  603. priceSpread.refresh();
  604. ledgerGcl.spread.refresh();
  605. priceBwSpread.refresh();
  606. priceChangeSpread.refresh();
  607. }
  608. });
  609. $.divResizer({
  610. select: '#revise-right-spr',
  611. callback: function () {
  612. priceSpread.refresh();
  613. priceBwSpread.refresh();
  614. priceChangeSpread.refresh();
  615. ledgerGcl.spread.refresh();
  616. ledgerGcl.xmjSpread.refresh();
  617. }
  618. });
  619. $.divResizer({
  620. select: '#gcl-spr',
  621. callback: function () {
  622. ledgerGcl.spread.refresh();
  623. ledgerGcl.xmjSpread.refresh();
  624. }
  625. });
  626. $.divResizer({
  627. select: '#price-resize',
  628. callback: function () {
  629. priceSpread.refresh();
  630. let bcontent = $(".bcontent-wrap").length > 0 ? $(".bcontent-wrap").height() : 0;
  631. $(".sp-wrap").height(bcontent-30);
  632. priceBwSpread.refresh();
  633. priceChangeSpread.refresh();
  634. }
  635. });
  636. class ChooseRelaBw {
  637. constructor() {
  638. const self = this;
  639. this.tree = createNewPathTree('ledger', {
  640. id: 'ledger_id',
  641. pid: 'ledger_pid',
  642. order: 'order',
  643. level: 'level',
  644. rootId: -1,
  645. fullPath: 'full_path',
  646. keys: ['id', 'tender_id', 'ledger_id'],
  647. });
  648. $('#choose-rela-bw').on('shown.bs.modal', function() {
  649. self.initSpread();
  650. SpreadJsObj.reloadColData(self.sheet, 0, 1);
  651. SpreadJsObj.reloadRowBackColor(self.sheet, 0, self.tree.nodes.length);
  652. });
  653. $('#choose-rela-bw-ok').click(function() {
  654. const choose_lid = [];
  655. self.tree.nodes.forEach(x => {
  656. if (x.check) choose_lid.push(x.ledger_id);
  657. });
  658. priceOprObj.updateRelaLid(self.price, choose_lid.join(','));
  659. $('#choose-rela-bw').modal('hide');
  660. });
  661. }
  662. get locate() {
  663. return this._locate;
  664. }
  665. set locate(value) {
  666. if (!this.searchResult || this.searchResult.length === 0) return;
  667. this._locate = !value || value >= this.searchResult.length ? 0 : (value < 0 ? this.searchResult.length - 1 : value);
  668. SpreadJsObj.locateTreeNode(this.sheet, this.searchResult[this._locate].ledger_id, true);
  669. }
  670. search(keyword) {
  671. this.searchResult = [];
  672. for (const node of this.tree.nodes) {
  673. const code = node.code || '', name = node.name || '', b_code = node.b_code || '';
  674. if (code.indexOf(keyword) >= 0 || b_code.indexOf(keyword) >= 0 || name.indexOf(keyword) >= 0) this.searchResult.push(node);
  675. }
  676. $('#rela-bw-search-result').html(`结果:${this.searchResult.length}`);
  677. this.locate = 0;
  678. }
  679. initSpread() {
  680. if (this.spread) return;
  681. this.spread = SpreadJsObj.createNewSpread($('#rela-bw-spread')[0]);
  682. this.sheet = this.spread.getActiveSheet();
  683. const spreadSetting = {
  684. cols: [
  685. {title: '选择', colSpan: '1', rowSpan: '1', field: 'check', hAlign: 1, width: 50, formatter: '@', cellType: 'checkbox'},
  686. {title: '项目节编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 150, formatter: '@', cellType: 'tree'},
  687. {title: '清单编号', colSpan: '1', rowSpan: '1', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
  688. {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 230, formatter: '@'},
  689. {title: '单位', colSpan: '1', rowSpan: '1', field: 'unit', hAlign: 1, width: 60, formatter: '@'},
  690. {title: '原单价', colSpan: '1', rowSpan: '1', field: 'unit_price', hAlign: 2, width: 60, type: 'Number'},
  691. ],
  692. headRows: 1,
  693. emptyRows: 0,
  694. headRowHeight: [25],
  695. defaultRowHeight: 21,
  696. headerFont: '12px 微软雅黑',
  697. font: '12px 微软雅黑',
  698. readOnly: true,
  699. getColor: function (sheet, data, row, col, defaultColor) {
  700. return data && data.invalid ? '#dddddd' : defaultColor;
  701. }
  702. };
  703. sjsSettingObj.setFxTreeStyle(spreadSetting, sjsSettingObj.FxTreeStyle.jz);
  704. SpreadJsObj.initSheet(this.sheet, spreadSetting);
  705. const self = this;
  706. this.spread.bind(spreadNS.Events.ButtonClicked, function (e, info) {
  707. function checkInvalid(node) {
  708. if (node.invalid) return 1;
  709. if (self.tree.checkParent(node, 'invalid')) return 2;
  710. if (self.tree.checkChildren(node, 'invalid')) return 3;
  711. return 0;
  712. }
  713. const sheet = info.sheet, cellType = sheet.getCellType(info.row, info.col);
  714. if (!sheet.zh_setting) return;
  715. if (cellType instanceof spreadNS.CellTypes.CheckBox) {
  716. if (sheet.isEditing()) sheet.endEdit(true);
  717. }
  718. const col = sheet.zh_setting.cols[info.col];
  719. if (col.field !== 'check') return;
  720. const tree = sheet.zh_tree;
  721. const node = SpreadJsObj.getSelectObject(sheet);
  722. if (node.b_code) {
  723. toastr.warning('请选择部位');
  724. return;
  725. }
  726. if (!node.check) {
  727. const invalid = checkInvalid(node);
  728. const invalidHint = ['该部位已被选择,请勿重复选择', '该部位的父项已被选择,请勿选择', '该部位的子项已被选择,请勿在其子项中选择'];
  729. if (invalid) {
  730. toastr.warning(invalidHint[invalid-1]);
  731. return;
  732. }
  733. if (self.tree.checkParent(node)) {
  734. const rect = info.sheet.getCellRect(info.row, info.col);
  735. self.chooseConfirmPopover({
  736. x: rect.x + rect.width / 2 + 25,
  737. y: rect.y + rect.height / 2 + 3,
  738. }, '父项已勾选,继续将取消父项勾选。', function () {
  739. node.check = true;
  740. const parents = tree.getFullPathNodes(tree.getParent(node).full_path);
  741. const rows = [tree.nodes.indexOf(node)];
  742. for (const p of parents) {
  743. if (p.check) {
  744. p.check = false;
  745. rows.push(tree.nodes.indexOf(p));
  746. }
  747. }
  748. SpreadJsObj.reLoadRowsData(info.sheet, rows);
  749. });
  750. } else if (self.tree.checkChildren(node)) {
  751. const rect = info.sheet.getCellRect(info.row, info.col);
  752. self.chooseConfirmPopover({
  753. x: rect.x + rect.width / 2 + 25,
  754. y: rect.y + rect.height / 2 + 3,
  755. }, '子项已勾选,继续将取消子项勾选。', function () {
  756. node.check = true;
  757. const posterity = tree.getPosterity(node);
  758. const rows = [tree.nodes.indexOf(node)];
  759. for (const p of posterity) {
  760. if (p.check) {
  761. rows.push(tree.nodes.indexOf(p));
  762. p.check = false;
  763. }
  764. }
  765. SpreadJsObj.reLoadRowsData(info.sheet, rows);
  766. });
  767. } else {
  768. node.check = true;
  769. SpreadJsObj.reLoadRowsData(info.sheet, [info.row]);
  770. }
  771. } else {
  772. node.check = false;
  773. SpreadJsObj.reLoadRowsData(info.sheet, [info.row]);
  774. }
  775. });
  776. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Tree, this.tree);
  777. (function (select, sheet) {
  778. $(select).click(function () {
  779. if (!sheet.zh_tree) return;
  780. const tag = $(this).attr('tag');
  781. const tree = sheet.zh_tree;
  782. setTimeout(() => {
  783. showWaitingView();
  784. switch (tag) {
  785. case "1":
  786. case "2":
  787. case "3":
  788. case "4":
  789. case "5":
  790. tree.expandByLevel(parseInt(tag));
  791. SpreadJsObj.refreshTreeRowVisible(sheet);
  792. break;
  793. case "last":
  794. tree.expandByCustom(() => { return true; });
  795. SpreadJsObj.refreshTreeRowVisible(sheet);
  796. break;
  797. case "leafXmj":
  798. tree.expandToLeafXmj();
  799. SpreadJsObj.refreshTreeRowVisible(sheet);
  800. break;
  801. }
  802. closeWaitingView();
  803. }, 100);
  804. });
  805. })('a[name=showLevel]', this.sheet);
  806. $('#rela-bw-search-keyword').change(function () {
  807. self.search(this.value);
  808. });
  809. $('#rela-bw-search-pre').click(function () {
  810. self.locate = self.locate - 1;
  811. });
  812. $('#rela-bw-search-next').click(function () {
  813. self.locate = self.locate + 1;
  814. });
  815. }
  816. reBind(obj, eventName, fun) {
  817. obj.unbind(eventName);
  818. obj.bind(eventName, fun);
  819. }
  820. chooseConfirmPopover(pos, hint, okCallback) {
  821. const confirmObj = $('#choose-confirm'), hintObj = $('#choose-confirm-hint');
  822. const okObj = $('#choose-confirm-ok'), cancelObj = $('#choose-confirm-cancel');
  823. this.reBind(cancelObj, 'click', function () {
  824. confirmObj.hide();
  825. });
  826. this.reBind(okObj, 'click', function () {
  827. okCallback();
  828. confirmObj.hide();
  829. });
  830. hintObj.text(hint);
  831. confirmObj.css("top", pos.y).css("left", pos.x).show();
  832. }
  833. loadTree(data) {
  834. this.tree.loadDatas(data);
  835. }
  836. show(price, samePrice){
  837. this.price = price;
  838. this.choose = price.rela_lid ? price.rela_lid.split(',') : [];
  839. this.invalid = [];
  840. for (const sp of samePrice) {
  841. const lid = sp.rela_lid ? sp.rela_lid.split(',') : [];
  842. this.invalid.push(...lid);
  843. }
  844. for (const node of this.tree.nodes) {
  845. node.check = this.choose.indexOf(node.ledger_id + '') >= 0;
  846. node.invalid = this.invalid.indexOf(node.ledger_id + '') >= 0;
  847. }
  848. $('#choose-rela-bw').modal('show');
  849. }
  850. }
  851. const chooseRelaBw = new ChooseRelaBw();
  852. class ChooseRelaChange {
  853. constructor (){
  854. const self = this;
  855. $('#choose-rela-change').on('shown.bs.modal', function() {
  856. self.initSpread();
  857. SpreadJsObj.reloadColData(self.sheet, 0, 1);
  858. SpreadJsObj.reloadRowBackColor(self.sheet, 0, self.change.length);
  859. });
  860. $('#choose-rela-change-ok').click(function() {
  861. const choose_cid = [];
  862. self.change.forEach(x => {
  863. if (x.check) choose_cid.push(x.cid);
  864. });
  865. priceOprObj.updateRelaCid(self.price, choose_cid.join(','));
  866. $('#choose-rela-change').modal('hide');
  867. });
  868. }
  869. initSpread() {
  870. if (this.spread) return;
  871. this.spread = SpreadJsObj.createNewSpread($('#rela-change-spread')[0]);
  872. this.sheet = this.spread.getActiveSheet();
  873. const spreadSetting = {
  874. cols: [
  875. {title: '选择', colSpan: '1', rowSpan: '1', field: 'check', hAlign: 1, width: 50, formatter: '@', cellType: 'checkbox'},
  876. {title: '变更令', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 150, formatter: '@'},
  877. {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 230, formatter: '@'},
  878. {title: '单位', colSpan: '1', rowSpan: '1', field: 'unit', hAlign: 1, width: 60, formatter: '@'},
  879. ],
  880. headRows: 1,
  881. emptyRows: 0,
  882. headRowHeight: [25],
  883. defaultRowHeight: 21,
  884. headerFont: '12px 微软雅黑',
  885. font: '12px 微软雅黑',
  886. readOnly: true,
  887. getColor: function (sheet, data, row, col, defaultColor) {
  888. return data && data.invalid ? '#dddddd' : defaultColor;
  889. }
  890. };
  891. SpreadJsObj.initSheet(this.sheet, spreadSetting);
  892. this.spread.bind(spreadNS.Events.ButtonClicked, function (e, info) {
  893. const sheet = info.sheet, cellType = sheet.getCellType(info.row, info.col);
  894. if (!sheet.zh_setting) return;
  895. if (cellType instanceof spreadNS.CellTypes.CheckBox) {
  896. if (sheet.isEditing()) sheet.endEdit(true);
  897. }
  898. const col = sheet.zh_setting.cols[info.col];
  899. if (col.field !== 'check') return;
  900. const node = SpreadJsObj.getSelectObject(sheet);
  901. if (!node.check) {
  902. if (node.invalid) return;
  903. node.check = true;
  904. SpreadJsObj.reLoadRowsData(info.sheet, [info.row]);
  905. } else {
  906. node.check = false;
  907. SpreadJsObj.reLoadRowsData(info.sheet, [info.row]);
  908. }
  909. });
  910. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, this.change);
  911. }
  912. loadChange(data) {
  913. this.change = data;
  914. }
  915. show(price, samePrice) {
  916. this.price = price;
  917. this.choose = price.rela_cid ? price.rela_cid.split(',') : [];
  918. this.invalid = [];
  919. for (const sp of samePrice) {
  920. const cid = sp.rela_cid ? sp.rela_cid.split(',') : [];
  921. this.invalid.push(...cid);
  922. }
  923. for (const c of this.change) {
  924. c.check = this.choose.indexOf(c.cid + '') >= 0;
  925. c.invalid = this.invalid.indexOf(c.cid + '') >= 0;
  926. if (!c.check && !c.invalid) {
  927. const exist = c.bills.find(x => {
  928. return x.code === price.b_code && x.name === price.name && x.unit === price.unit && x.unit_price === price.org_price;
  929. });
  930. c.visible = !!exist;
  931. }
  932. }
  933. if (this.sheet) SpreadJsObj.refreshTreeRowVisible(this.sheet);
  934. $('#choose-rela-change').modal('show');
  935. }
  936. }
  937. const chooseRelaChange = new ChooseRelaChange();
  938. postData('load', { filter: 'bills;pos;price;change' }, result => {
  939. revisePrice.loadDatas(result.price, result.bills, result.change);
  940. SpreadJsObj.loadSheetData(priceSheet, SpreadJsObj.DataType.Data, revisePrice.data);
  941. ledgerGcl.loadData(result.bills, result.pos);
  942. chooseRelaBw.loadTree(result.bills);
  943. chooseRelaChange.loadChange(result.change);
  944. SpreadJsObj.loadSheetData(priceBwSheet, SpreadJsObj.DataType.Tree, revisePrice.tree);
  945. SpreadJsObj.loadSheetData(priceChangeSheet, SpreadJsObj.DataType.Data, revisePrice.relaChange);
  946. $("[content='#ledgerGcl']").click();
  947. });
  948. $('a', '#side-menu').bind('click', function (e) {
  949. e.preventDefault();
  950. const tab = $(this), tabPanel = $(tab.attr('content'));
  951. // 展开工具栏、切换标签
  952. if (!tab.hasClass('active')) {
  953. $('a', '#side-menu').removeClass('active');
  954. tab.addClass('active');
  955. $('#right-view .tab-pane').removeClass('active');
  956. tabPanel.addClass('active');
  957. showSideTools(tab.hasClass('active'));
  958. ledgerGcl.spread.refresh();
  959. ledgerGcl.xmjSpread.refresh();
  960. } else {// 收起工具栏
  961. tab.removeClass('active');
  962. tabPanel.removeClass('active');
  963. showSideTools(tab.hasClass('active'));
  964. }
  965. priceSpread.refresh();
  966. priceBwSpread.refresh();
  967. priceChangeSpread.refresh();
  968. });
  969. $('a', '.bcontent-wrap').click(function() {
  970. $('[name=priceRela]').removeClass('active');
  971. $(this).addClass('active');
  972. $('#priceRelaTab').children().removeClass('active');
  973. $(this.getAttribute('href')).addClass('active');
  974. priceBwSpread.refresh();
  975. priceChangeSpread.refresh();
  976. });
  977. });