revise_price.js 44 KB

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