revise_price.js 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936
  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. ],
  93. headRows: 1,
  94. emptyRows: 0,
  95. headRowHeight: [25],
  96. defaultRowHeight: 21,
  97. headerFont: '12px 微软雅黑',
  98. font: '12px 微软雅黑',
  99. readOnly: true,
  100. };
  101. sjsSettingObj.setFxTreeStyle(priceBwSpreadSetting, sjsSettingObj.FxTreeStyle.jz);
  102. const priceChangeSpreadSetting = {
  103. cols: [
  104. {title: '变更令', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 80, formatter: '@'},
  105. {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 230, formatter: '@'},
  106. {title: '批复文号', colSpan: '1', rowSpan: '1', field: 'w_code', hAlign: 1, width: 80, formatter: '@'},
  107. ],
  108. headRows: 1,
  109. emptyRows: 0,
  110. headRowHeight: [25],
  111. defaultRowHeight: 21,
  112. headerFont: '12px 微软雅黑',
  113. font: '12px 微软雅黑',
  114. readOnly: true,
  115. getForeColor: function (sheet, data, row, col, defaultColor) {
  116. return data && data.valid ? defaultColor : '#ddd';
  117. },
  118. };
  119. autoFlashHeight();
  120. const bcontent = $(".bcontent-wrap").length > 0 ? $(".bcontent-wrap").height() : 0;
  121. $(".sp-wrap").height(bcontent-30);
  122. const priceSpread = SpreadJsObj.createNewSpread($('#price-spread')[0]);
  123. const priceSheet = priceSpread.getActiveSheet();
  124. const priceBwSpread = SpreadJsObj.createNewSpread($('#price-bw-spread')[0]);
  125. const priceBwSheet = priceBwSpread.getActiveSheet();
  126. const priceChangeSpread = SpreadJsObj.createNewSpread($('#price-change-spread')[0]);
  127. const priceChangeSheet = priceChangeSpread.getActiveSheet();
  128. SpreadJsObj.initSheet(priceSheet, priceSpreadSetting);
  129. SpreadJsObj.initSheet(priceBwSheet, priceBwSpreadSetting);
  130. SpreadJsObj.initSheet(priceChangeSheet, priceChangeSpreadSetting);
  131. class RevisePrice {
  132. constructor () {
  133. this.data = [];
  134. this.tree = createNewPathTree('filter', {
  135. id: 'ledger_id',
  136. pid: 'ledger_pid',
  137. order: 'order',
  138. level: 'level',
  139. rootId: -1,
  140. fullPath: 'full_path',
  141. keys: ['id', 'tender_id', 'ledger_id'],
  142. });
  143. }
  144. resortData() {
  145. this.data.sort(function (a, b) {
  146. return a.order - b.order;
  147. });
  148. }
  149. loadDatas(datas, treeData, changeData) {
  150. this.data = datas;
  151. this.tree.loadDatas(treeData);
  152. this.resortData();
  153. this.change = changeData;
  154. this.relaChange = [];
  155. if (this.data.length > 0) this.refreshRela(this.data[0]);
  156. }
  157. loadUpdateData(updateData) {
  158. if (updateData.add) {
  159. for (const a of updateData.add) {
  160. this.data.push(a);
  161. }
  162. }
  163. if (updateData.update) {
  164. for (const u of updateData.update) {
  165. const d = this.data.find(function (x) {
  166. return u.id === x.id;
  167. });
  168. if (d) {
  169. _.assign(d, u);
  170. } else {
  171. this.data.push(d);
  172. }
  173. }
  174. }
  175. if (updateData.del) {
  176. _.remove(this.data, function (d) {
  177. return updateData.del.indexOf(d.id) >= 0;
  178. });
  179. }
  180. this.resortData();
  181. }
  182. getSamePrice(price) {
  183. return this.data.filter(x => {
  184. if (x.id === price.id) return false;
  185. return x.b_code === price.b_code && x.name === price.name && x.unit === price.unit && x.org_price === price.org_price;
  186. });
  187. }
  188. refreshTreeRela(price, samePrice) {
  189. if (price.rela_lid) {
  190. this.tree.loadFilter(price.rela_lid);
  191. } else {
  192. const invalid = [];
  193. for (const sp of samePrice) {
  194. const lid = sp.rela_lid ? sp.rela_lid.split(',') : [];
  195. invalid.push(...lid);
  196. }
  197. this.tree.loadFilter(invalid.join(','), 'access');
  198. }
  199. }
  200. refreshChangeRela(price, samePrice) {
  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. });
  414. },
  415. updateRelaCid: function (price, rela_cid) {
  416. const data = { update: { id: price.id, rela_cid } };
  417. postData(window.location.pathname + '/update', data, function (result) {
  418. revisePrice.loadUpdateData(result);
  419. });
  420. },
  421. selectionChanged: function () {
  422. const price = SpreadJsObj.getSelectObject(priceSheet);
  423. revisePrice.refreshRela(price);
  424. SpreadJsObj.refreshTreeRowVisible(priceBwSheet);
  425. SpreadJsObj.reLoadSheetData(priceChangeSheet);
  426. },
  427. };
  428. if (!readOnly) {
  429. priceSheet.bind(spreadNS.Events.EditEnded, priceOprObj.editEnded);
  430. priceSheet.bind(spreadNS.Events.ClipboardPasting, priceOprObj.clipboardPasting);
  431. SpreadJsObj.addDeleteBind(priceSpread, priceOprObj.deletePress);
  432. $.contextMenu({
  433. selector: '#price-spread',
  434. build: function ($trigger, e) {
  435. const target = SpreadJsObj.safeRightClickSelection($trigger, e, priceSpread);
  436. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  437. },
  438. items: {
  439. del: {
  440. name: '删除',
  441. icon: 'fa-remove',
  442. callback: function (key, opt) {
  443. priceOprObj.delete(priceSheet);
  444. },
  445. disabled: function (key, opt) {
  446. const node = SpreadJsObj.getSelectObject(priceSheet);
  447. return node === undefined || node === null;
  448. },
  449. visible: function (key, opt) {
  450. return !readOnly;
  451. }
  452. },
  453. sprDel: '----',
  454. upMove: {
  455. name: '上移',
  456. icon: 'fa-arrow-up',
  457. callback: function (key, opt) {
  458. priceOprObj.upMove();
  459. },
  460. disabled: function (key, opt) {
  461. const sels = priceSheet.getSelections();
  462. if (!sels || !sels[0] || sels[0].row === 0) return true;
  463. const row = sels[0].row;
  464. const node = revisePrice.data[row];
  465. return node === undefined || node === null;
  466. },
  467. visible: function (key, opt) {
  468. return !readOnly;
  469. }
  470. },
  471. downMove: {
  472. name: '下移',
  473. icon: 'fa-arrow-down',
  474. callback: function (key, opt) {
  475. priceOprObj.downMove();
  476. },
  477. disabled: function (key, opt) {
  478. const sels = priceSheet.getSelections();
  479. if (!sels || !sels[0] || sels[0].row >= revisePrice.data.length - 1) return true;
  480. const row = sels[0].row;
  481. const node = revisePrice.data[row];
  482. return node === undefined || node === null;
  483. },
  484. visible: function (key, opt) {
  485. return !readOnly;
  486. }
  487. },
  488. sprMove: '----',
  489. chooseRelaBw: {
  490. name: '选择应用部位',
  491. icon: 'fa-tags',
  492. callback: function (key, opt) {
  493. const price = SpreadJsObj.getSelectObject(priceSheet);
  494. const samePrice = revisePrice.getSamePrice(price);
  495. chooseRelaBw.show(price, samePrice);
  496. },
  497. disabled: function (key, opt) {
  498. const node = SpreadJsObj.getSelectObject(priceSheet);
  499. return !node;
  500. },
  501. visible: function (key, opt) {
  502. return !readOnly;
  503. }
  504. },
  505. chooseRelaChange: {
  506. name: '选择应用变更令',
  507. icon: 'fa-tags',
  508. callback: function (key, opt) {
  509. const price = SpreadJsObj.getSelectObject(priceSheet);
  510. const samePrice = revisePrice.getSamePrice(price);
  511. chooseRelaChange.show(price, samePrice);
  512. },
  513. disabled: function (key, opt) {
  514. const node = SpreadJsObj.getSelectObject(priceSheet);
  515. return !node;
  516. },
  517. visible: function (key, opt) {
  518. return !readOnly;
  519. }
  520. },
  521. },
  522. });
  523. }
  524. priceSpread.bind(spreadNS.Events.SelectionChanged, priceOprObj.selectionChanged);
  525. class LedgerGcl {
  526. constructor(setting) {
  527. this.setting = setting;
  528. this.spread = SpreadJsObj.createNewSpread($(this.setting.selector)[0]);
  529. this.sheet = this.spread.getActiveSheet();
  530. SpreadJsObj.initSheet(this.sheet, this.setting.spreadSetting);
  531. this.xmjSpread = SpreadJsObj.createNewSpread($(this.setting.xmjSelector)[0]);
  532. this.xmjSheet = this.xmjSpread.getActiveSheet();
  533. SpreadJsObj.initSheet(this.xmjSheet, this.setting.xmjSpreadSetting);
  534. if (!readOnly) {
  535. this.spread.bind(spreadNS.Events.CellDoubleClick, function (e, info) {
  536. const gcl = SpreadJsObj.getSelectObject(info.sheet);
  537. priceOprObj.addRevisePrice(gcl);
  538. });
  539. }
  540. const self = this;
  541. this.spread.bind(spreadNS.Events.SelectionChanged, function (e, info) {
  542. self.loadLeafXmj();
  543. });
  544. }
  545. loadData(bills, pos) {
  546. gclGatherModel.loadLedgerData(bills);
  547. gclGatherModel.loadPosData(pos);
  548. this.gcl = gclGatherModel.gatherGclData();
  549. this.sheet && SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, this.gcl);
  550. this.loadLeafXmj(0);
  551. }
  552. loadLeafXmj(iGclRow) {
  553. const gcl = iGclRow ? this.gcl[iGclRow] : SpreadJsObj.getSelectObject(this.sheet);
  554. SpreadJsObj.resetTopAndSelect(this.xmjSheet);
  555. if (gcl) {
  556. SpreadJsObj.loadSheetData(this.xmjSheet, SpreadJsObj.DataType.Data, gcl.leafXmjs);
  557. } else {
  558. SpreadJsObj.loadSheetData(this.xmjSheet, SpreadJsObj.DataType.Data, []);
  559. }
  560. }
  561. }
  562. const ledgerGcl = new LedgerGcl({
  563. selector: '#ledger-gcl-spread',
  564. spreadSetting: ledgerGclSpreadSetting,
  565. xmjSelector: '#ledger-xmj-spread',
  566. xmjSpreadSetting: ledgerXmjSpreadSetting,
  567. });
  568. $.subMenu({
  569. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  570. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  571. key: 'menu.1.0.0',
  572. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  573. callback: function (info) {
  574. if (info.mini) {
  575. $('.panel-title').addClass('fluid');
  576. $('#sub-menu').removeClass('panel-sidebar');
  577. } else {
  578. $('.panel-title').removeClass('fluid');
  579. $('#sub-menu').addClass('panel-sidebar');
  580. }
  581. autoFlashHeight();
  582. priceSpread.refresh();
  583. ledgerGcl.spread.refresh();
  584. priceBwSpread.refresh();
  585. priceChangeSpread.refresh();
  586. }
  587. });
  588. $.divResizer({
  589. select: '#revise-right-spr',
  590. callback: function () {
  591. priceSpread.refresh();
  592. priceBwSpread.refresh();
  593. priceChangeSpread.refresh();
  594. ledgerGcl.spread.refresh();
  595. ledgerGcl.xmjSpread.refresh();
  596. }
  597. });
  598. $.divResizer({
  599. select: '#gcl-spr',
  600. callback: function () {
  601. ledgerGcl.spread.refresh();
  602. ledgerGcl.xmjSpread.refresh();
  603. }
  604. });
  605. $.divResizer({
  606. select: '#price-resize',
  607. callback: function () {
  608. priceSpread.refresh();
  609. let bcontent = $(".bcontent-wrap").length > 0 ? $(".bcontent-wrap").height() : 0;
  610. $(".sp-wrap").height(bcontent-30);
  611. priceBwSpread.refresh();
  612. priceChangeSpread.refresh();
  613. }
  614. });
  615. class ChooseRelaBw {
  616. constructor() {
  617. const self = this;
  618. this.tree = createNewPathTree('base', {
  619. id: 'ledger_id',
  620. pid: 'ledger_pid',
  621. order: 'order',
  622. level: 'level',
  623. rootId: -1,
  624. fullPath: 'full_path',
  625. keys: ['id', 'tender_id', 'ledger_id'],
  626. });
  627. $('#choose-rela-bw').on('shown.bs.modal', function() {
  628. self.initSpread();
  629. SpreadJsObj.reloadColData(self.sheet, 0, 1);
  630. SpreadJsObj.reloadRowBackColor(self.sheet, 0, self.tree.nodes.length);
  631. });
  632. $('#choose-rela-bw-ok').click(function() {
  633. const choose_lid = [];
  634. self.tree.nodes.forEach(x => {
  635. if (x.check) choose_lid.push(x.ledger_id);
  636. });
  637. priceOprObj.updateRelaLid(self.price, choose_lid.join(','));
  638. $('#choose-rela-bw').modal('hide');
  639. });
  640. }
  641. initSpread() {
  642. if (this.spread) return;
  643. this.spread = SpreadJsObj.createNewSpread($('#rela-bw-spread')[0]);
  644. this.sheet = this.spread.getActiveSheet();
  645. const spreadSetting = {
  646. cols: [
  647. {title: '选择', colSpan: '1', rowSpan: '1', field: 'check', hAlign: 1, width: 50, formatter: '@', cellType: 'checkbox'},
  648. {title: '项目节编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 150, formatter: '@', cellType: 'tree'},
  649. {title: '清单编号', colSpan: '1', rowSpan: '1', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
  650. {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 230, formatter: '@'},
  651. {title: '单位', colSpan: '1', rowSpan: '1', field: 'unit', hAlign: 1, width: 60, formatter: '@'},
  652. ],
  653. headRows: 1,
  654. emptyRows: 0,
  655. headRowHeight: [25],
  656. defaultRowHeight: 21,
  657. headerFont: '12px 微软雅黑',
  658. font: '12px 微软雅黑',
  659. readOnly: true,
  660. getColor: function (sheet, data, row, col, defaultColor) {
  661. return data && data.invalid ? '#dddddd' : defaultColor;
  662. }
  663. };
  664. sjsSettingObj.setFxTreeStyle(spreadSetting, sjsSettingObj.FxTreeStyle.jz);
  665. SpreadJsObj.initSheet(this.sheet, spreadSetting);
  666. const self = this;
  667. this.spread.bind(spreadNS.Events.ButtonClicked, function (e, info) {
  668. function checkInvalid(node) {
  669. if (node.invalid) return 1;
  670. if (self.tree.checkParent(node, 'invalid')) return 2;
  671. if (self.tree.checkChildren(node, 'invalid')) return 3;
  672. return 0;
  673. }
  674. const sheet = info.sheet, cellType = sheet.getCellType(info.row, info.col);
  675. if (!sheet.zh_setting) return;
  676. if (cellType instanceof spreadNS.CellTypes.CheckBox) {
  677. if (sheet.isEditing()) sheet.endEdit(true);
  678. }
  679. const col = sheet.zh_setting.cols[info.col];
  680. if (col.field !== 'check') return;
  681. const tree = sheet.zh_tree;
  682. const node = SpreadJsObj.getSelectObject(sheet);
  683. if (node.b_code) {
  684. toastr.warning('请选择部位');
  685. return;
  686. }
  687. if (!node.check) {
  688. const invalid = checkInvalid(node);
  689. const invalidHint = ['该部位已被选择,请勿重复选择', '该部位的父项已被选择,请勿选择', '该部位的子项已被选择,请勿在其子项中选择'];
  690. if (invalid) {
  691. toastr.warning(invalidHint[invalid-1]);
  692. return;
  693. }
  694. if (self.tree.checkParent(node)) {
  695. const rect = info.sheet.getCellRect(info.row, info.col);
  696. self.chooseConfirmPopover({
  697. x: rect.x + rect.width / 2 + 25,
  698. y: rect.y + rect.height / 2 + 3,
  699. }, '父项已勾选,继续将取消父项勾选。', function () {
  700. node.check = true;
  701. const parents = tree.getFullPathNodes(tree.getParent(node).full_path);
  702. const rows = [tree.nodes.indexOf(node)];
  703. for (const p of parents) {
  704. if (p.check) {
  705. p.check = false;
  706. rows.push(tree.nodes.indexOf(p));
  707. }
  708. }
  709. SpreadJsObj.reLoadRowsData(info.sheet, rows);
  710. });
  711. } else if (self.tree.checkChildren(node)) {
  712. const rect = info.sheet.getCellRect(info.row, info.col);
  713. self.chooseConfirmPopover({
  714. x: rect.x + rect.width / 2 + 25,
  715. y: rect.y + rect.height / 2 + 3,
  716. }, '子项已勾选,继续将取消子项勾选。', function () {
  717. node.check = true;
  718. const posterity = tree.getPosterity(node);
  719. const rows = [tree.nodes.indexOf(node)];
  720. for (const p of posterity) {
  721. if (p.check) {
  722. rows.push(tree.nodes.indexOf(p));
  723. p.check = false;
  724. }
  725. }
  726. SpreadJsObj.reLoadRowsData(info.sheet, rows);
  727. });
  728. } else {
  729. node.check = true;
  730. SpreadJsObj.reLoadRowsData(info.sheet, [info.row]);
  731. }
  732. } else {
  733. node.check = false;
  734. SpreadJsObj.reLoadRowsData(info.sheet, [info.row]);
  735. }
  736. });
  737. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Tree, this.tree);
  738. }
  739. reBind(obj, eventName, fun) {
  740. obj.unbind(eventName);
  741. obj.bind(eventName, fun);
  742. }
  743. chooseConfirmPopover(pos, hint, okCallback) {
  744. const confirmObj = $('#choose-confirm'), hintObj = $('#choose-confirm-hint');
  745. const okObj = $('#choose-confirm-ok'), cancelObj = $('#choose-confirm-cancel');
  746. this.reBind(cancelObj, 'click', function () {
  747. confirmObj.hide();
  748. });
  749. this.reBind(okObj, 'click', function () {
  750. okCallback();
  751. confirmObj.hide();
  752. });
  753. hintObj.text(hint);
  754. confirmObj.css("top", pos.y).css("left", pos.x).show();
  755. }
  756. loadTree(data) {
  757. this.tree.loadDatas(data);
  758. }
  759. show(price, samePrice){
  760. this.price = price;
  761. this.choose = price.rela_lid ? price.rela_lid.split(',') : [];
  762. this.invalid = [];
  763. for (const sp of samePrice) {
  764. const lid = sp.rela_lid ? sp.rela_lid.split(',') : [];
  765. this.invalid.push(...lid);
  766. }
  767. for (const node of this.tree.nodes) {
  768. node.check = this.choose.indexOf(node.ledger_id + '') >= 0;
  769. node.invalid = this.invalid.indexOf(node.ledger_id + '') >= 0;
  770. }
  771. $('#choose-rela-bw').modal('show');
  772. }
  773. }
  774. const chooseRelaBw = new ChooseRelaBw();
  775. class ChooseRelaChange {
  776. constructor (){
  777. const self = this;
  778. $('#choose-rela-change').on('shown.bs.modal', function() {
  779. self.initSpread();
  780. SpreadJsObj.reloadColData(self.sheet, 0, 1);
  781. SpreadJsObj.reloadRowBackColor(self.sheet, 0, self.change.length);
  782. });
  783. $('#choose-rela-change-ok').click(function() {
  784. const choose_cid = [];
  785. self.change.forEach(x => {
  786. if (x.check) choose_cid.push(x.cid);
  787. });
  788. priceOprObj.updateRelaCid(self.price, choose_cid.join(','));
  789. $('#choose-rela-change').modal('hide');
  790. });
  791. }
  792. initSpread() {
  793. if (this.spread) return;
  794. this.spread = SpreadJsObj.createNewSpread($('#rela-change-spread')[0]);
  795. this.sheet = this.spread.getActiveSheet();
  796. const spreadSetting = {
  797. cols: [
  798. {title: '选择', colSpan: '1', rowSpan: '1', field: 'check', hAlign: 1, width: 50, formatter: '@', cellType: 'checkbox'},
  799. {title: '变更令', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 150, formatter: '@'},
  800. {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 230, formatter: '@'},
  801. {title: '单位', colSpan: '1', rowSpan: '1', field: 'unit', hAlign: 1, width: 60, formatter: '@'},
  802. ],
  803. headRows: 1,
  804. emptyRows: 0,
  805. headRowHeight: [25],
  806. defaultRowHeight: 21,
  807. headerFont: '12px 微软雅黑',
  808. font: '12px 微软雅黑',
  809. readOnly: true,
  810. getColor: function (sheet, data, row, col, defaultColor) {
  811. return data && data.invalid ? '#dddddd' : defaultColor;
  812. }
  813. };
  814. SpreadJsObj.initSheet(this.sheet, spreadSetting);
  815. this.spread.bind(spreadNS.Events.ButtonClicked, function (e, info) {
  816. const sheet = info.sheet, cellType = sheet.getCellType(info.row, info.col);
  817. if (!sheet.zh_setting) return;
  818. if (cellType instanceof spreadNS.CellTypes.CheckBox) {
  819. if (sheet.isEditing()) sheet.endEdit(true);
  820. }
  821. const col = sheet.zh_setting.cols[info.col];
  822. if (col.field !== 'check') return;
  823. const node = SpreadJsObj.getSelectObject(sheet);
  824. if (!node.check) {
  825. if (node.invalid) return;
  826. node.check = true;
  827. SpreadJsObj.reLoadRowsData(info.sheet, [info.row]);
  828. } else {
  829. node.check = false;
  830. SpreadJsObj.reLoadRowsData(info.sheet, [info.row]);
  831. }
  832. });
  833. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, this.change);
  834. }
  835. loadChange(data) {
  836. this.change = data;
  837. }
  838. show(price, samePrice) {
  839. this.price = price;
  840. this.choose = price.rela_cid ? price.rela_cid.split(',') : [];
  841. this.invalid = [];
  842. for (const sp of samePrice) {
  843. const cid = sp.rela_cid ? sp.rela_cid.split(',') : [];
  844. this.invalid.push(...cid);
  845. }
  846. for (const c of this.change) {
  847. c.check = this.choose.indexOf(c.cid + '') >= 0;
  848. c.invalid = this.invalid.indexOf(c.cid + '') >= 0;
  849. if (!c.check && !c.invalid) {
  850. const exist = c.bills.find(x => {
  851. return x.code === price.b_code && x.name === price.name && x.unit === price.unit && x.unit_price === price.org_price;
  852. });
  853. c.visible = !exist;
  854. }
  855. }
  856. $('#choose-rela-change').modal('show');
  857. }
  858. }
  859. const chooseRelaChange = new ChooseRelaChange();
  860. postData('load', { filter: 'bills;pos;price;change' }, result => {
  861. revisePrice.loadDatas(result.price, result.bills, result.change);
  862. SpreadJsObj.loadSheetData(priceSheet, SpreadJsObj.DataType.Data, revisePrice.data);
  863. ledgerGcl.loadData(result.bills, result.pos);
  864. chooseRelaBw.loadTree(result.bills);
  865. chooseRelaChange.loadChange(result.change);
  866. SpreadJsObj.loadSheetData(priceBwSheet, SpreadJsObj.DataType.Tree, revisePrice.tree);
  867. SpreadJsObj.loadSheetData(priceChangeSheet, SpreadJsObj.DataType.Data, revisePrice.relaChange);
  868. $("[content='#ledgerGcl']").click();
  869. });
  870. $('a', '#side-menu').bind('click', function (e) {
  871. e.preventDefault();
  872. const tab = $(this), tabPanel = $(tab.attr('content'));
  873. // 展开工具栏、切换标签
  874. if (!tab.hasClass('active')) {
  875. $('a', '#side-menu').removeClass('active');
  876. tab.addClass('active');
  877. $('#right-view .tab-pane').removeClass('active');
  878. tabPanel.addClass('active');
  879. showSideTools(tab.hasClass('active'));
  880. ledgerGcl.spread.refresh();
  881. ledgerGcl.xmjSpread.refresh();
  882. } else {// 收起工具栏
  883. tab.removeClass('active');
  884. tabPanel.removeClass('active');
  885. showSideTools(tab.hasClass('active'));
  886. }
  887. priceSpread.refresh();
  888. priceBwSpread.refresh();
  889. priceChangeSpread.refresh();
  890. });
  891. $('a', '.bcontent-wrap').click(function() {
  892. $('[name=priceRela]').removeClass('active');
  893. $(this).addClass('active');
  894. $('#priceRelaTab').children().removeClass('active');
  895. $(this.getAttribute('href')).addClass('active');
  896. priceBwSpread.refresh();
  897. priceChangeSpread.refresh();
  898. });
  899. });