revise_price.js 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026
  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) return defaultColor;
  80. if (data.rela_lid && data.rela_cid) return '#f5deb3';
  81. const samePrice = sheet.zh_data.find(x => {
  82. return x.b_code === data.b_code && x.name === data.name && x.unit === data.unit && x.org_price === data.org_price && data.id !== x.id;
  83. });
  84. return !samePrice ? defaultColor : '#f5deb3';
  85. }
  86. };
  87. const priceBwSpreadSetting = {
  88. cols: [
  89. {title: '项目节编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 150, formatter: '@', cellType: 'tree'},
  90. {title: '清单编号', colSpan: '1', rowSpan: '1', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
  91. {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 230, formatter: '@'},
  92. {title: '单位', colSpan: '1', rowSpan: '1', field: 'unit', hAlign: 1, width: 60, formatter: '@'},
  93. {title: '原单价', colSpan: '1', rowSpan: '1', field: 'unit_price', hAlign: 2, width: 60, type: 'Number'},
  94. ],
  95. headRows: 1,
  96. emptyRows: 0,
  97. headRowHeight: [25],
  98. defaultRowHeight: 21,
  99. headerFont: '12px 微软雅黑',
  100. font: '12px 微软雅黑',
  101. readOnly: true,
  102. };
  103. sjsSettingObj.setFxTreeStyle(priceBwSpreadSetting, sjsSettingObj.FxTreeStyle.jz);
  104. const priceChangeSpreadSetting = {
  105. cols: [
  106. {title: '变更令', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 80, formatter: '@'},
  107. {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 230, formatter: '@'},
  108. {title: '批复文号', colSpan: '1', rowSpan: '1', field: 'w_code', hAlign: 1, width: 80, formatter: '@'},
  109. ],
  110. headRows: 1,
  111. emptyRows: 0,
  112. headRowHeight: [25],
  113. defaultRowHeight: 21,
  114. headerFont: '12px 微软雅黑',
  115. font: '12px 微软雅黑',
  116. readOnly: true,
  117. };
  118. autoFlashHeight();
  119. const bcontent = $(".bcontent-wrap").length > 0 ? $(".bcontent-wrap").height() : 0;
  120. $(".sp-wrap").height(bcontent-30);
  121. const priceSpread = SpreadJsObj.createNewSpread($('#price-spread')[0]);
  122. const priceSheet = priceSpread.getActiveSheet();
  123. const priceBwSpread = SpreadJsObj.createNewSpread($('#price-bw-spread')[0]);
  124. const priceBwSheet = priceBwSpread.getActiveSheet();
  125. const priceChangeSpread = SpreadJsObj.createNewSpread($('#price-change-spread')[0]);
  126. const priceChangeSheet = priceChangeSpread.getActiveSheet();
  127. SpreadJsObj.initSheet(priceSheet, priceSpreadSetting);
  128. SpreadJsObj.initSheet(priceBwSheet, priceBwSpreadSetting);
  129. SpreadJsObj.initSheet(priceChangeSheet, priceChangeSpreadSetting);
  130. class RevisePrice {
  131. constructor () {
  132. this.data = [];
  133. this.tree = createNewPathTree('filter', {
  134. id: 'ledger_id',
  135. pid: 'ledger_pid',
  136. order: 'order',
  137. level: 'level',
  138. rootId: -1,
  139. fullPath: 'full_path',
  140. keys: ['id', 'tender_id', 'ledger_id'],
  141. });
  142. }
  143. resortData() {
  144. this.data.sort(function (a, b) {
  145. return a.order - b.order;
  146. });
  147. }
  148. loadDatas(datas, treeData, changeData) {
  149. this.data = datas;
  150. this.tree.loadDatas(treeData);
  151. this.resortData();
  152. this.change = changeData;
  153. this.relaChange = [];
  154. if (this.data.length > 0) this.refreshRela(this.data[0]);
  155. }
  156. loadUpdateData(updateData) {
  157. if (updateData.add) {
  158. for (const a of updateData.add) {
  159. this.data.push(a);
  160. }
  161. }
  162. if (updateData.update) {
  163. for (const u of updateData.update) {
  164. const d = this.data.find(function (x) {
  165. return u.id === x.id;
  166. });
  167. if (d) {
  168. _.assign(d, u);
  169. } else {
  170. this.data.push(d);
  171. }
  172. }
  173. }
  174. if (updateData.del) {
  175. _.remove(this.data, function (d) {
  176. return updateData.del.indexOf(d.id) >= 0;
  177. });
  178. }
  179. this.resortData();
  180. }
  181. getSamePrice(price) {
  182. return this.data.filter(x => {
  183. if (x.id === price.id) return false;
  184. return x.b_code === price.b_code && x.name === price.name && x.unit === price.unit && x.org_price === price.org_price;
  185. });
  186. }
  187. refreshTreeRela(price, samePrice) {
  188. if (!samePrice) samePrice = this.getSamePrice(price);
  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(','), 'filter');
  198. }
  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. });