revise_price.js 44 KB

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