ledger.js 120 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598
  1. /**
  2. * 台账相关js
  3. *
  4. * @author Mai
  5. * @date 2018/02/05
  6. * @version
  7. */
  8. const ckBillsSpread = window.location.pathname + '-billsSelect';
  9. function checkTzMeasureType () {
  10. return tender.measure_type === measureType.tz.value;
  11. }
  12. function getTenderId() {
  13. return window.location.pathname.split('/')[2];
  14. }
  15. const copyBlockTag = 'zh.calc.copyBlock';
  16. const invalidFields = {
  17. parent: ['sgfh_qty', 'sgfh_tp', 'sjcl_qty', 'sjcl_tp', 'qtcl_qty', 'qtcl_tp', 'deal_qty', 'deal_tp', 'unit_price'],
  18. gcl: ['dgn_qty1', 'dgn_qty2'],
  19. posCode: ['b_code'],
  20. posCalc: ['sgfh_qty', 'sgfh_tp', 'sjcl_qty', 'sjcl_tp', 'qtcl_qty', 'qtcl_tp'],
  21. posXmj: ['code'],
  22. };
  23. function transExpr(expr) {
  24. return expr.replace('=', '').replace('%', '/100');
  25. }
  26. $(document).ready(function() {
  27. let stdXmj, stdGcl, dealBills, searchLedger;
  28. autoFlashHeight();
  29. // 初始化台账
  30. const ledgerSpread = SpreadJsObj.createNewSpread($('#ledger-spread')[0]);
  31. const treeSetting = {
  32. id: 'ledger_id',
  33. pid: 'ledger_pid',
  34. order: 'order',
  35. level: 'level',
  36. rootId: -1,
  37. keys: ['id', 'tender_id', 'ledger_id'],
  38. preUrl: '/tender/' + getTenderId() + '/ledger',
  39. };
  40. if (checkTzMeasureType()) {
  41. treeSetting.calcFields = ['sgfh_tp', 'sjcl_tp', 'qtcl_tp', 'total_price'];
  42. } else {
  43. treeSetting.calcFields = ['deal_tp', 'sgfh_tp', 'sjcl_tp', 'qtcl_tp', 'total_price'];
  44. }
  45. treeSetting.calcFun = function (node) {
  46. node.dgn_price = ZhCalc.round(ZhCalc.div(node.total_price, node.dgn_qty1), 2);
  47. };
  48. const ledgerTree = createNewPathTree('ledger', treeSetting);
  49. // 初始化 计量单元
  50. const pos = new PosData({
  51. id: 'id', ledgerId: 'lid',
  52. });
  53. const posSpread = SpreadJsObj.createNewSpread($('#pos-spread')[0]);
  54. $.subMenu({
  55. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  56. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  57. key: 'menu.1.0.0',
  58. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  59. callback: function (info) {
  60. if (info.mini) {
  61. $('.panel-title').addClass('fluid');
  62. $('#sub-menu').removeClass('panel-sidebar');
  63. } else {
  64. $('.panel-title').removeClass('fluid');
  65. $('#sub-menu').addClass('panel-sidebar');
  66. }
  67. autoFlashHeight();
  68. ledgerSpread.refresh();
  69. if (posSpread) {
  70. posSpread.refresh();
  71. }
  72. if (stdXmj) {
  73. stdXmj.spread.refresh();
  74. }
  75. if (stdGcl) {
  76. stdGcl.spread.refresh();
  77. }
  78. if (dealBills) {
  79. dealBills.spread.refresh();
  80. }
  81. if (searchLedger) {
  82. searchLedger.spread.refresh();
  83. }
  84. }
  85. });
  86. // 定义事件
  87. const treeOperationObj = {
  88. loadExprToInput(sheet) {
  89. const sel = sheet.getSelections()[0];
  90. const col = sheet.zh_setting.cols[sel.col], cell = sheet.getCell(sel.row, sel.col);
  91. if (col && col.type === 'Number') {
  92. const data = SpreadJsObj.getSelectObject(sheet);
  93. if (data) {
  94. $('#bills-expr').val(data[col.field]).attr('field', col.field).attr('org', data[col.field]);
  95. if (col.field.indexOf('dgn') >= 0) {
  96. $('#bills-expr').attr('readOnly', readOnly || cell.locked() || (_.isString(data.b_code) && data.b_code !== ''));
  97. } else {
  98. $('#bills-expr').attr('readOnly', readOnly || cell.locked() || (data.children && data.children.length > 0));
  99. }
  100. } else {
  101. $('#bills-expr').val('').attr('readOnly', true);
  102. }
  103. } else {
  104. $('#bills-expr').val('').attr('readOnly', true);
  105. }
  106. },
  107. getSelectNode: function (sheet) {
  108. if (!sheet || !sheet.zh_tree) {
  109. return null;
  110. } else {
  111. const sel = sheet.getSelections()[0];
  112. return sheet.zh_tree.nodes[sel.row];
  113. }
  114. },
  115. getDefaultSelectInfo: function (sheet) {
  116. const tree = sheet.zh_tree;
  117. if (!tree) return;
  118. const sel = sheet.getSelections()[0];
  119. const node = sheet.zh_tree.nodes[sel.row];
  120. if (!node) return;
  121. let count = 1;
  122. if (sel.rowCount > 1) {
  123. for (let r = 1; r < sel.rowCount; r++) {
  124. const rNode = sheet.zh_tree.nodes[sel.row + r];
  125. if (rNode.level > node.level) continue;
  126. if ((rNode.level < node.level) || (rNode.level === node.level && rNode.pid !== node.pid)) {
  127. toastr.error('请选择同一清单下的节点,进行该操作');
  128. return;
  129. }
  130. count += 1;
  131. }
  132. }
  133. return [tree, node, count];
  134. },
  135. /**
  136. * 刷新顶部按钮是否可用
  137. * @param sheet
  138. * @param selections
  139. */
  140. refreshOperationValid: function (sheet, selection) {
  141. const setObjEnable = function (obj, enable) {
  142. if (enable) {
  143. obj.removeClass('disabled');
  144. } else {
  145. obj.addClass('disabled');
  146. }
  147. };
  148. const invalidAll = function () {
  149. setObjEnable($('#insert'), false);
  150. setObjEnable($('#delete'), false);
  151. setObjEnable($('#up-move'), false);
  152. setObjEnable($('#down-move'), false);
  153. setObjEnable($('#up-level'), false);
  154. setObjEnable($('#down-level'), false);
  155. };
  156. const sel = selection ? selection[0] : sheet.getSelections()[0];
  157. const row = sel ? sel.row : -1;
  158. const tree = sheet.zh_tree;
  159. if (!tree) {
  160. invalidAll();
  161. return;
  162. }
  163. const first = sheet.zh_tree.nodes[row];
  164. if (!first) {
  165. invalidAll();
  166. return;
  167. }
  168. let last = first, sameParent = true;
  169. if (sel.rowCount > 1 && first) {
  170. for (let r = 1; r < sel.rowCount; r++) {
  171. const rNode = tree.nodes[row + r];
  172. if (!rNode) {
  173. sameParent = false;
  174. break;
  175. }
  176. if (rNode.level > first.level) continue;
  177. if ((rNode.level < first.level) || (rNode.level === first.level && rNode.pid !== first.pid)) {
  178. sameParent = false;
  179. break;
  180. }
  181. last = rNode;
  182. }
  183. }
  184. const preNode = tree.getPreSiblingNode(first);
  185. const valid = !sheet.zh_setting.readOnly;
  186. setObjEnable($('#insert'), valid && first && first.level > 1);
  187. setObjEnable($('#delete'), valid && first && sameParent && !(first.level === 1 && first.node_type));
  188. setObjEnable($('#up-move'), valid && first && sameParent && first.level > 1 && preNode);
  189. setObjEnable($('#down-move'), valid && first && sameParent && first.level > 1 && !tree.isLastSibling(last));
  190. if (checkTzMeasureType()) {
  191. const posRange = last ? pos.getLedgerPos(last.id) : [];
  192. setObjEnable($('#up-level'), valid && first && sameParent && tree.getParent(first) && first.level > 2 && ((!posRange || posRange.length === 0) || tree.isLastSibling(last)));
  193. const preNodePosRange = preNode ? pos.getLedgerPos(preNode.id) : [];
  194. setObjEnable($('#down-level'), valid && first && sameParent && first.level > 1 && preNode && (!preNodePosRange || preNodePosRange.length === 0));
  195. } else {
  196. setObjEnable($('#up-level'), valid && first && sameParent && first.level > 2 && tree.getParent(first));
  197. setObjEnable($('#down-level'), valid && first && sameParent && first.level > 1 && preNode);
  198. }
  199. setObjEnable($('#cut'), valid);
  200. setObjEnable($('#paste'), valid);
  201. },
  202. refreshTree: function (sheet, data) {
  203. SpreadJsObj.massOperationSheet(sheet, function () {
  204. const tree = sheet.zh_tree;
  205. // 处理删除
  206. if (data.delete) {
  207. data.delete.sort(function (x, y) {
  208. return y.deleteIndex - x.deleteIndex;
  209. });
  210. for (const d of data.delete) {
  211. sheet.deleteRows(d.deleteIndex, 1);
  212. }
  213. }
  214. // 处理新增
  215. if (data.create) {
  216. const newNodes = data.create;
  217. if (newNodes) {
  218. newNodes.sort(function (a, b) {
  219. return a.index - b.index;
  220. });
  221. for (const node of newNodes) {
  222. sheet.addRows(node.index, 1);
  223. SpreadJsObj.reLoadRowData(sheet, tree.nodes.indexOf(node), 1);
  224. }
  225. }
  226. }
  227. // 处理更新
  228. if (data.update) {
  229. const rows = [];
  230. for (const u of data.update) {
  231. rows.push(tree.nodes.indexOf(u));
  232. }
  233. SpreadJsObj.reLoadRowsData(sheet, rows);
  234. }
  235. // 处理展开
  236. if (data.expand) {
  237. const expanded = [];
  238. for (const e of data.expand) {
  239. if (expanded.indexOf(e) === -1) {
  240. const posterity = tree.getPosterity(e);
  241. for (const p of posterity) {
  242. sheet.setRowVisible(tree.nodes.indexOf(p), p.visible);
  243. expanded.push(p);
  244. }
  245. }
  246. }
  247. }
  248. });
  249. },
  250. /**
  251. * 新增节点
  252. * @param spread
  253. */
  254. addNode: function (sheet, count = 1) {
  255. const self = this;
  256. const sel = sheet.getSelections()[0];
  257. const row = sheet.getSelections()[0].row;
  258. const tree = sheet.zh_tree;
  259. if (!tree) { return; }
  260. const node = sheet.zh_tree.nodes[row];
  261. if (!node) { return; }
  262. postData(window.location.pathname + '/update', {
  263. postType: 'add',
  264. postData: {
  265. id: tree.getNodeKey(node),
  266. count: count,
  267. }
  268. }, function (result) {
  269. const refreshNode = tree.loadPostData(result);
  270. self.refreshTree(sheet, refreshNode);
  271. sheet.setSelection(refreshNode.create[0].index, sel.col, sel.rowCount, sel.colCount);
  272. SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, refreshNode.create[0].index]);
  273. self.refreshOperationValid(sheet);
  274. });
  275. },
  276. /**
  277. * 删除选中节点
  278. * @param spread
  279. */
  280. deleteNode: function (sheet) {
  281. const self = this;
  282. const [tree, node, count] = this.getDefaultSelectInfo(sheet);
  283. if (tree && node && count) {
  284. const data = {
  285. postType: 'delete',
  286. postData: {
  287. id: tree.getNodeKey(node),
  288. count: count
  289. }
  290. };
  291. postData(window.location.pathname + '/update', data, function (result) {
  292. const refreshNode = tree.loadPostData(result);
  293. for (const d of refreshNode.delete) pos.removeDatasByMasterId(d.id);
  294. self.refreshTree(sheet, refreshNode);
  295. self.refreshOperationValid(sheet);
  296. posOperationObj.loadCurPosData();
  297. });
  298. }
  299. },
  300. /**
  301. * 上移选中节点
  302. * @param spread
  303. */
  304. upMove: function (sheet) {
  305. const self = this;
  306. const [tree, node, count] = this.getDefaultSelectInfo(sheet);
  307. if (tree && node && count) {
  308. const data = {
  309. postType: 'up-move',
  310. postData: {
  311. id: tree.getNodeKey(node),
  312. count: count
  313. }
  314. };
  315. postData(window.location.pathname + '/update', data, function (result) {
  316. const refreshNode = tree.loadPostData(result);
  317. self.refreshTree(sheet, refreshNode);
  318. const sel = sheet.getSelections()[0];
  319. sheet.setSelection(tree.nodes.indexOf(node), sel.col, sel.rowCount, sel.colCount);
  320. SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, tree.nodes.indexOf(node)]);
  321. self.refreshOperationValid(sheet);
  322. });
  323. }
  324. },
  325. /**
  326. * 下移选中节点
  327. * @param spread
  328. */
  329. downMove: function (sheet) {
  330. const self = this;
  331. const [tree, node, count] = this.getDefaultSelectInfo(sheet);
  332. if (tree && node && count) {
  333. const data = {
  334. postType: 'down-move',
  335. postData: {
  336. id: tree.getNodeKey(node),
  337. count: count
  338. }
  339. };
  340. postData(window.location.pathname + '/update', data, function (result) {
  341. const refreshNode = tree.loadPostData(result);
  342. self.refreshTree(sheet, refreshNode);
  343. const sel = sheet.getSelections()[0];
  344. sheet.setSelection(tree.nodes.indexOf(node), sel.col, sel.rowCount, sel.colCount);
  345. SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, tree.nodes.indexOf(node)]);
  346. self.refreshOperationValid(sheet);
  347. });
  348. }
  349. },
  350. /**
  351. * 升级选中节点
  352. * @param spread
  353. */
  354. upLevel: function (sheet) {
  355. const self = this;
  356. const [tree, node, count] = this.getDefaultSelectInfo(sheet);
  357. if (tree && node && count) {
  358. const data = {
  359. postType: 'up-level',
  360. postData: {
  361. id: tree.getNodeKey(node),
  362. count: count
  363. }
  364. };
  365. postData(window.location.pathname + '/update', data, function (result) {
  366. const refreshNode = tree.loadPostData(result);
  367. self.refreshTree(sheet, refreshNode);
  368. self.refreshOperationValid(sheet);
  369. });
  370. }
  371. },
  372. /**
  373. * 降级选中节点
  374. * @param spread
  375. */
  376. downLevel: function (sheet) {
  377. const self = this;
  378. const [tree, node, count] = this.getDefaultSelectInfo(sheet);
  379. if (tree && node && count) {
  380. const data = {
  381. postType: 'down-level',
  382. postData: {
  383. id: tree.getNodeKey(node),
  384. count: count
  385. }
  386. };
  387. postData(window.location.pathname + '/update', data, function (result) {
  388. const refreshNode = tree.loadPostData(result);
  389. self.refreshTree(sheet, refreshNode);
  390. self.refreshOperationValid(sheet);
  391. });
  392. }
  393. },
  394. /**
  395. * 编辑单元格响应事件
  396. * @param {Object} e
  397. * @param {Object} info
  398. */
  399. editEnded: function (e, info) {
  400. if (info.sheet.zh_setting) {
  401. const col = info.sheet.zh_setting.cols[info.col];
  402. const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
  403. const node = sortData[info.row];
  404. const data = {
  405. id: node.id,
  406. tender_id: node.tender_id,
  407. ledger_id: node.ledger_id
  408. };
  409. // 未改变值则不提交
  410. const orgValue = node[col.field];
  411. const newValue = trimInvalidChar(info.editingText);
  412. if (orgValue == info.editingText || ((!orgValue || orgValue === '') && (newValue === ''))) {
  413. return;
  414. }
  415. // 台账模式,检查计量单元相关
  416. if (checkTzMeasureType()) {
  417. if (col.field === 'sgfh_qty' || col.field === 'sgfh_tp' ||
  418. col.field === 'sjcl_qty' || col.field === 'sjcl_tp' ||
  419. col.field === 'qtcl_qty' || col.field === 'qtcl_tp') {
  420. if (!node.children || node.children.length ===0) {
  421. const lPos = pos.getLedgerPos(node.id);
  422. if (lPos && lPos.length > 0) {
  423. toastr.error('清单含有计量单元,请在计量单元输入数量');
  424. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  425. return;
  426. }
  427. }
  428. }
  429. if (col.field === 'b_code' && (info.editingText === '' || !info.editingText)) {
  430. const lPos = pos.getLedgerPos(node.id);
  431. if (lPos && lPos.length > 0) {
  432. toastr.error('清单含有计量单元,请先删除计量单元,再删除清单编号');
  433. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  434. return;
  435. }
  436. }
  437. }
  438. // 获取更新数据
  439. if (col.type === 'Number') {
  440. if (newValue) {
  441. const num = _.toNumber(newValue);
  442. if (_.isFinite(num)) {
  443. data[col.field] = num;
  444. } else {
  445. try {
  446. data[col.field] = math.evaluate(transExpr(newValue));
  447. } catch(err) {
  448. toastr.error('输入的表达式非法');
  449. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  450. return;
  451. }
  452. }
  453. } else {
  454. data[col.field] = null;
  455. }
  456. } else {
  457. data[col.field] = newValue;
  458. }
  459. // 更新至服务器
  460. postData(window.location.pathname + '/update', {postType: 'update', postData: data}, function (result) {
  461. const refreshNode = ledgerTree.loadPostData(result);
  462. treeOperationObj.refreshTree(info.sheet, refreshNode);
  463. });
  464. }
  465. },
  466. /**
  467. * 粘贴单元格响应事件
  468. * @param e
  469. * @param info
  470. */
  471. clipboardPasted: function (e, info) {
  472. if (info.sheet.zh_setting && info.sheet.zh_dataType === 'tree') {
  473. const tree = info.sheet.zh_tree;
  474. if (!tree) { return; }
  475. const sortData = info.sheet.zh_tree.nodes;
  476. const datas = [], filterNodes = [];
  477. let bHint = false, bPaste;
  478. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow ++) {
  479. bPaste = false;
  480. const curRow = info.cellRange.row + iRow;
  481. const node = sortData[curRow];
  482. if (node) {
  483. const data = info.sheet.zh_tree.getNodeKeyData(node);
  484. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  485. const curCol = info.cellRange.col + iCol;
  486. const colSetting = info.sheet.zh_setting.cols[curCol];
  487. const value = trimInvalidChar(info.sheet.getText(curRow, curCol));
  488. const lPos = pos.getLedgerPos(node.id);
  489. if (lPos && lPos.length > 0) {
  490. if (value === '' && colSetting.field === 'b_code') {
  491. if (!bHint) {
  492. toastr.warning('清单含有计量单元,请先删除计量单元,再删除清单编号');
  493. bHint = true;
  494. }
  495. continue;
  496. }
  497. if (colSetting.field === 'sgfh_qty' || colSetting.field === 'sgfh_tp' ||
  498. colSetting.field === 'sjcl_qty' || colSetting.field === 'sjcl_tp' ||
  499. colSetting.field === 'qtcl_qty' || colSetting.field === 'qtcl_tp') {
  500. if (!bHint) {
  501. toastr.warning('清单含有计量单元,数量金额根据计量单元汇总计算所得,不可编辑');
  502. bHint = true;
  503. }
  504. continue;
  505. }
  506. }
  507. if (colSetting.type === 'Number') {
  508. const num = _.toNumber(value);
  509. if (num) {
  510. data[colSetting.field] = num;
  511. bPaste = true;
  512. } else {
  513. try {
  514. data[colSetting.field] = math.evaluate(transExpr(value));
  515. bPaste = true;
  516. } catch(err) {
  517. delete data[colSetting.field];
  518. if (!bHint) {
  519. toastr.warning('输入的表达式非法');
  520. bHint = true;
  521. }
  522. }
  523. }
  524. } else {
  525. data[colSetting.field] = value;
  526. bPaste = true;
  527. }
  528. }
  529. if (bPaste) {
  530. datas.push(data);
  531. } else {
  532. filterNodes.push(node);
  533. }
  534. }
  535. }
  536. if (datas.length > 0) {
  537. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  538. const refreshNode = tree.loadPostData(result);
  539. if (refreshNode.update) {
  540. refreshNode.update = refreshNode.update.concat(filterNodes);
  541. }
  542. treeOperationObj.refreshTree(info.sheet, refreshNode);
  543. }, function () {
  544. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  545. });
  546. } else {
  547. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  548. }
  549. }
  550. },
  551. clipboardPasting: function (e, info) {
  552. const tree = info.sheet.zh_tree, setting = info.sheet.zh_setting;
  553. info.cancel = true;
  554. if (!setting || !tree) return;
  555. const pasteData = info.pasteData.html
  556. ? SpreadJsObj.analysisPasteHtml(info.pasteData.html)
  557. : (info.pasteData.text === ''
  558. ? SpreadJsObj.Clipboard.getAnalysisPasteText()
  559. : SpreadJsObj.analysisPasteText(info.pasteData.text));
  560. const hint = {
  561. invalidExpr: {type: 'warning', msg: '粘贴的表达式非法'},
  562. posCode: {type: 'warning', msg: '清单含有计量单元,不可粘贴清单编号为空'},
  563. posQty: {type: 'warning', msg: '清单含有计量单元,数量金额根据计量单元汇总计算所得,不可粘贴'},
  564. parent: {type: 'warning', msg: '含有子项的清单,不可粘贴数量、单价、金额'},
  565. gcl: {type: 'warning', msg: '工程量清单,不可粘贴项目节数量'},
  566. posXmj: {type: 'warning', msg: '清单含有计量单元,不可粘贴项目节编号'},
  567. };
  568. const datas = [], filterNodes = [];
  569. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  570. const curRow = info.cellRange.row + iRow;
  571. const node = tree.nodes[curRow];
  572. if (!node) continue;
  573. let bPaste = false;
  574. const data = info.sheet.zh_tree.getNodeKeyData(node);
  575. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  576. const curCol = info.cellRange.col + iCol;
  577. const colSetting = info.sheet.zh_setting.cols[curCol];
  578. const value = trimInvalidChar(pasteData[iRow][iCol]);
  579. const lPos = pos.getLedgerPos(node.id);
  580. if (node.children && node.children.length > 0 && invalidFields.parent.indexOf(colSetting.field) >= 0) {
  581. toastMessageUniq(hint.parent);
  582. continue;
  583. }
  584. if (!_.isEmpty(node.b_code) && invalidFields.gcl.indexOf(colSetting.field) >= 0) {
  585. toastMessageUniq(hint.gcl);
  586. continue;
  587. }
  588. if (lPos && lPos.length > 0) {
  589. if (value === '' && invalidFields.posCode.indexOf(colSetting.field) >= 0) {
  590. toastMessageUniq(hint.posCode);
  591. continue;
  592. }
  593. if (invalidFields.posCalc.indexOf(colSetting.field) >= 0) {
  594. toastMessageUniq(hint.posQty);
  595. continue;
  596. }
  597. if (value !== '' && invalidFields.posXmj.indexOf(colSetting.field) >= 0) {
  598. toastMessageUniq(hint.posXmj);
  599. continue;
  600. }
  601. }
  602. if (colSetting.type === 'Number') {
  603. const num = _.toNumber(value);
  604. if (num) {
  605. data[colSetting.field] = num;
  606. bPaste = true;
  607. } else {
  608. try {
  609. data[colSetting.field] = math.evaluate(transExpr(value));
  610. } catch(err) {
  611. toastMessageUniq(hint.invalidExpr);
  612. }
  613. }
  614. } else {
  615. data[colSetting.field] = value;
  616. bPaste = true;
  617. }
  618. }
  619. if (bPaste) {
  620. datas.push(data);
  621. } else {
  622. filterNodes.push(node);
  623. }
  624. }
  625. if (datas.length > 0) {
  626. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  627. const refreshNode = tree.loadPostData(result);
  628. if (refreshNode.update) {
  629. refreshNode.update = refreshNode.update.concat(filterNodes);
  630. }
  631. treeOperationObj.refreshTree(info.sheet, refreshNode);
  632. }, function () {
  633. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  634. });
  635. } else {
  636. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  637. }
  638. },
  639. /**
  640. * 删除按钮响应事件
  641. * @param sheet
  642. */
  643. deletePress: function (sheet) {
  644. if (sheet.zh_setting && sheet.zh_dataType === 'tree') {
  645. const tree = sheet.zh_tree;
  646. if (!tree) { return; }
  647. const sortData = sheet.zh_tree.nodes;
  648. const datas = [], nodes = [];
  649. const sel = sheet.getSelections()[0];
  650. let bHint = false;
  651. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  652. const node = sortData[iRow];
  653. if (node) {
  654. let bDel = false;
  655. const data = sheet.zh_tree.getNodeKeyData(node);
  656. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  657. const col = sheet.zh_setting.cols[iCol];
  658. if (col.field === 'b_code' || col.field === 'sgfh_qty' || col.field === 'sgfh_tp' ||
  659. col.field === 'sjcl_qty' || col.field === 'sjcl_tp' ||
  660. col.field === 'qtcl_qty' || col.field === 'qtcl_tp') {
  661. const lPos = pos.getLedgerPos(node.id);
  662. if (lPos && lPos.length > 0) {
  663. if (!bHint) {
  664. if (col.field === 'code') {
  665. toastr.warning('清单含有计量单元,请先删除计量单元,再删除清单编号');
  666. } else {
  667. toastr.warning('清单含有计量单元,数量金额根据计量单元汇总计算所得,不可删除');
  668. }
  669. bHint = true;
  670. }
  671. continue;
  672. }
  673. }
  674. const style = sheet.getStyle(iRow, iCol);
  675. if (!style.locked) {
  676. const colSetting = sheet.zh_setting.cols[iCol];
  677. data[colSetting.field] = null;
  678. bDel = true;
  679. }
  680. }
  681. if (bDel) {
  682. datas.push(data);
  683. nodes.push(node);
  684. }
  685. }
  686. }
  687. if (datas.length > 0) {
  688. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  689. const refreshNode = tree.loadPostData(result);
  690. treeOperationObj.refreshTree(sheet, refreshNode);
  691. });
  692. }
  693. }
  694. },
  695. /**
  696. * 粘贴整块
  697. * @param spread
  698. * @param block
  699. */
  700. pasteBlock: function (spread, copyInfo) {
  701. const self = this;
  702. const sheet = spread.getActiveSheet();
  703. const sel = sheet.getSelections()[0];
  704. const row = sel.row;
  705. const tree = sheet.zh_tree;
  706. if (!tree) { return; }
  707. const node = tree.nodes[row];
  708. if (!node) { return; }
  709. postData(window.location.pathname + '/update', {
  710. postType: 'paste-block',
  711. postData: {
  712. id: tree.getNodeKey(node),
  713. tid: copyInfo.tid,
  714. block: copyInfo.block,
  715. }
  716. }, function (data) {
  717. pos.updateDatas(data.pos);
  718. const result = tree.loadPostData(data.ledger);
  719. self.refreshTree(sheet, result);
  720. sheet.setSelection(result.create[0].index, sel.col, sel.rowCount, sel.colCount);
  721. SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, result.create[0].index]);
  722. self.refreshOperationValid(sheet);
  723. removeLocalCache(copyBlockTag);
  724. }, null, true);
  725. },
  726. selectionChanged: function (e, info) {
  727. if (!info.oldSelections[0] || info.newSelections[0].row !== info.oldSelections[0].row) {
  728. posOperationObj.loadCurPosData();
  729. SpreadJsObj.resetTopAndSelect(posSpread.getActiveSheet());
  730. posSearch.search($('#pos-keyword').val());
  731. }
  732. SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
  733. treeOperationObj.loadExprToInput(info.sheet);
  734. },
  735. topRowChanged(e, info) {
  736. SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
  737. },
  738. cut: function (sheet, sel, callback) {
  739. if (!sheet || !sel) return;
  740. if (sel.colCount >= sheet.zh_setting.cols.length) {
  741. toastr.warning('请勿选中整行剪切');
  742. return;
  743. }
  744. const sortData = SpreadJsObj.getSortData(sheet), datas = [];
  745. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  746. const node = sortData[iRow];
  747. if (node) {
  748. const data = sheet.zh_tree.getNodeKeyData(node);
  749. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  750. const col = sheet.zh_setting.cols[iCol];
  751. if (col.field === 'b_code' || col.field === 'sgfh_qty' || col.field === 'sgfh_tp' ||
  752. col.field === 'sjcl_qty' || col.field === 'sjcl_tp' ||
  753. col.field === 'qtcl_qty' || col.field === 'qtcl_tp') {
  754. const lPos = pos.getLedgerPos(node.id);
  755. if (lPos && lPos.length > 0) {
  756. toastr.error('不可剪切');
  757. return;
  758. }
  759. }
  760. const style = sheet.getStyle(iRow, iCol);
  761. if (style.locked) {
  762. toastr.error('不可剪切');
  763. return;
  764. }
  765. const colSetting = sheet.zh_setting.cols[iCol];
  766. data[colSetting.field] = null;
  767. }
  768. datas.push(data);
  769. }
  770. }
  771. if (datas.length > 0) {
  772. callback();
  773. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  774. const refreshNode = sheet.zh_tree.loadPostData(result);
  775. treeOperationObj.refreshTree(sheet, refreshNode);
  776. });
  777. }
  778. },
  779. editStarting(e, info) {
  780. if (!info.sheet.zh_setting || !info.sheet.zh_tree) return;
  781. const col = info.sheet.zh_setting.cols[info.col];
  782. const node = info.sheet.zh_tree.nodes[info.row];
  783. if (!node) {
  784. info.cancel = true;
  785. return;
  786. }
  787. switch (col.field) {
  788. case 'code':
  789. const posRange = pos.getLedgerPos(node.id);
  790. info.cancel = posRange && posRange.length > 0;
  791. break;
  792. case 'unit_price':
  793. case 'sgfh_qty':
  794. case 'sgfh_tp':
  795. case 'sjcl_qty':
  796. case 'sjcl_tp':
  797. case 'qtcl_qty':
  798. case 'qtcl_tp':
  799. case 'deal_qty':
  800. case 'deal_tp':
  801. info.cancel = node.children && node.children.length > 0;
  802. break;
  803. case 'dgn_qty1':
  804. case 'dgn_qty2':
  805. info.cancel = !_.isEmpty(node.b_code);
  806. break;
  807. }
  808. },
  809. sortCode: function (sheet) {
  810. const tree = sheet.zh_tree;
  811. if (!tree) return;
  812. const select = SpreadJsObj.getSelectObject(sheet);
  813. if (!select || !select.code) return;
  814. const recursiveSortCode = function (data, parentCode, children) {
  815. if (!children || children.length === 0) return;
  816. for (const [i, child] of children.entries()) {
  817. if (!child.b_code || child.b_code === '') {
  818. const code = parentCode + '-' + (i + 1);
  819. const cData = tree.getNodeKeyData(child);
  820. cData.code = code;
  821. data.push(cData);
  822. if (!tree.isLeafXmj(child)) {
  823. recursiveSortCode(data, code, child.children);
  824. }
  825. }
  826. }
  827. };
  828. const data = [];
  829. recursiveSortCode(data, select.code, select.children);
  830. if (data.length > 0) {
  831. postData(window.location.pathname + '/update', {postType: 'update', postData: data}, function (result) {
  832. const refreshNode = tree.loadPostData(result);
  833. treeOperationObj.refreshTree(sheet, refreshNode);
  834. })
  835. }
  836. },
  837. };
  838. sjsSettingObj.setFxTreeStyle(ledgerSpreadSetting, sjsSettingObj.FxTreeStyle.jz);
  839. ledgerTreeCol.initSpreadSetting(ledgerSpreadSetting);
  840. SpreadJsObj.initSheet(ledgerSpread.getActiveSheet(), ledgerSpreadSetting);
  841. SpreadJsObj.selChangedRefreshBackColor(ledgerSpread.getActiveSheet());
  842. // 绑定事件
  843. ledgerSpread.bind(GC.Spread.Sheets.Events.SelectionChanged, treeOperationObj.selectionChanged);
  844. ledgerSpread.bind(spreadNS.Events.TopRowChanged, treeOperationObj.topRowChanged);
  845. if (!ledgerSpreadSetting.readOnly) {
  846. ledgerSpread.bind(GC.Spread.Sheets.Events.SelectionChanged, function (e, info) {
  847. treeOperationObj.refreshOperationValid(info.sheet, info.newSelections);
  848. });
  849. ledgerSpread.bind(GC.Spread.Sheets.Events.EditEnded, treeOperationObj.editEnded);
  850. //ledgerSpread.bind(GC.Spread.Sheets.Events.ClipboardPasted, treeOperationObj.clipboardPasted);
  851. SpreadJsObj.addDeleteBind(ledgerSpread, treeOperationObj.deletePress);
  852. ledgerSpread.bind(GC.Spread.Sheets.Events.ClipboardChanging, function (e, info) {
  853. const copyText = SpreadJsObj.getFilterCopyText(info.sheet);
  854. //console.log(info.copyData);
  855. SpreadJsObj.Clipboard.setCopyData(copyText);
  856. //copyToClipboard(copyText);
  857. });
  858. ledgerSpread.bind(GC.Spread.Sheets.Events.ClipboardPasting, treeOperationObj.clipboardPasting);
  859. ledgerSpread.bind(spreadNS.Events.EditStarting, treeOperationObj.editStarting);
  860. SpreadJsObj.addCutEvents(ledgerSpread, treeOperationObj.cut);
  861. // 绑定 删除等 顶部按钮
  862. $('#insert').click(() => {
  863. treeOperationObj.addNode(ledgerSpread.getActiveSheet());
  864. });
  865. $('#delete').click(function () {
  866. treeOperationObj.deleteNode(ledgerSpread.getActiveSheet());
  867. });
  868. $('#up-move').click(function () {
  869. treeOperationObj.upMove(ledgerSpread.getActiveSheet());
  870. });
  871. $('#down-move').click(function () {
  872. treeOperationObj.downMove(ledgerSpread.getActiveSheet());
  873. });
  874. $('#up-level').click(function () {
  875. treeOperationObj.upLevel(ledgerSpread.getActiveSheet());
  876. });
  877. $('#down-level').click(function () {
  878. treeOperationObj.downLevel(ledgerSpread.getActiveSheet());
  879. });
  880. $('#copy').click(function () {
  881. ledgerSpread.commandManager().execute({
  882. cmd: 'copy',
  883. sheetName: ledgerSpread.getActiveSheet().name()
  884. });
  885. });
  886. $('#paste').click(function () {
  887. ledgerSpread.commandManager().execute({
  888. cmd: 'paste',
  889. sheetName: ledgerSpread.getActiveSheet().name()
  890. });
  891. });
  892. $('#cut').click(function () {
  893. ledgerSpread.commandManager().execute({
  894. cmd: 'cut',
  895. sheetName: ledgerSpread.getActiveSheet().name()
  896. });
  897. });
  898. $('#bills-expr').bind('change mouseleave', function () {
  899. if (document.activeElement.id !== "bills-expr") return;
  900. const expr = $(this);
  901. const sheet = ledgerSpread.getActiveSheet();
  902. const select = SpreadJsObj.getSelectObject(sheet);
  903. const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = trimInvalidChar(expr.val());
  904. if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
  905. const data = {
  906. id: select.id,
  907. tender_id: select.tender_id,
  908. ledger_id: select.ledger_id
  909. };
  910. if (newValue !== '') {
  911. const num = _.toNumber(newValue);
  912. if (num) {
  913. data[field] = num;
  914. } else {
  915. try {
  916. data[field] = math.evaluate(transExpr(newValue));
  917. } catch (err) {
  918. toastr.error('输入的表达式非法');
  919. return;
  920. }
  921. }
  922. } else {
  923. data[field] = null;
  924. }
  925. // 更新至服务器
  926. postData(window.location.pathname + '/update', {postType: 'update', postData: data}, function (result) {
  927. const refreshNode = ledgerTree.loadPostData(result);
  928. expr.val(select[field]);
  929. treeOperationObj.refreshTree(sheet, refreshNode);
  930. });
  931. });
  932. }
  933. let batchInsertObj;
  934. $.contextMenu.types.batchInsert = function (item, opt, root) {
  935. const self = this;
  936. if ($.isFunction(item.icon)) {
  937. item._icon = item.icon.call(this, this, $t, key, item);
  938. } else {
  939. if (typeof(item.icon) === 'string' && item.icon.substring(0, 3) === 'fa-') {
  940. // to enable font awesome
  941. item._icon = root.classNames.icon + ' ' + root.classNames.icon + '--fa fa ' + item.icon;
  942. } else {
  943. item._icon = root.classNames.icon + ' ' + root.classNames.icon + '-' + item.icon;
  944. }
  945. }
  946. this.addClass(item._icon);
  947. const $obj = $('<div>' + item.name + '<input class="text-right ml-1 mr-1" type="tel" max="100" min="1" value="' + item.value + '" style="width: 30px; height: 18px; padding-right: 4px;">行</div>')
  948. .appendTo(this);
  949. const $input = $obj.find('input');
  950. const event = () => {
  951. if (self.hasClass('context-menu-disabled')) return;
  952. item.batchInsert($input[0], root);
  953. };
  954. $obj.on('click', event).keypress(function (e) {if (e.keyCode === 13) { event(); }});
  955. $input.click((e) => {e.stopPropagation();})
  956. .keyup((e) => {if (e.keyCode === 13) item.batchInsert($input[0], root);})
  957. .on('input', function () {this.value = this.value.replace(/[^\d]/g, '');});
  958. };
  959. // 右键菜单
  960. const billsContextMenuOptions = {
  961. selector: '#ledger-spread',
  962. build: function ($trigger, e) {
  963. const target = SpreadJsObj.safeRightClickSelection($trigger, e, ledgerSpread);
  964. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  965. },
  966. items: {},
  967. };
  968. if (!readOnly) {
  969. billsContextMenuOptions.items.create = {
  970. name: '新增',
  971. icon: 'fa-sign-in',
  972. callback: function (key, opt) {
  973. treeOperationObj.addNode(ledgerSpread.getActiveSheet());
  974. },
  975. disabled: function (key, opt) {
  976. const sheet = ledgerSpread.getActiveSheet();
  977. const selection = sheet.getSelections();
  978. const sel = selection ? selection[0] : sheet.getSelections()[0];
  979. const row = sel ? sel.row : -1;
  980. const tree = sheet.zh_tree;
  981. if (!tree) return true;
  982. const first = sheet.zh_tree.nodes[row];
  983. let last = first, sameParent = true;
  984. if (sel.rowCount > 1) {
  985. for (let r = 1; r < sel.rowCount; r++) {
  986. const rNode = tree.nodes[sel.row + r];
  987. if (rNode.level > first.level) continue;
  988. if ((rNode.level < first.level) || (rNode.level === first.level && rNode.pid !== first.pid)) {
  989. sameParent = false;
  990. break;
  991. }
  992. last = rNode;
  993. }
  994. }
  995. const valid = !sheet.zh_setting.readOnly;
  996. return !(valid && first && first.level > 1);
  997. },
  998. visible: function (key, opt) {
  999. return !readOnly;
  1000. }
  1001. };
  1002. billsContextMenuOptions.items.delete = {
  1003. name: '删除',
  1004. icon: 'fa-remove',
  1005. callback: function (key, opt) {
  1006. treeOperationObj.deleteNode(ledgerSpread.getActiveSheet());
  1007. },
  1008. disabled: function (key, opt) {
  1009. const sheet = ledgerSpread.getActiveSheet();
  1010. const selection = sheet.getSelections();
  1011. const sel = selection ? selection[0] : sheet.getSelections()[0];
  1012. const row = sel ? sel.row : -1;
  1013. const tree = sheet.zh_tree;
  1014. if (!tree) return true;
  1015. const first = sheet.zh_tree.nodes[row];
  1016. let last = first, sameParent = true;
  1017. if (sel.rowCount > 1) {
  1018. for (let r = 1; r < sel.rowCount; r++) {
  1019. const rNode = tree.nodes[sel.row + r];
  1020. if (rNode.level > first.level) continue;
  1021. if ((rNode.level < first.level) || (rNode.level === first.level && rNode.pid !== first.pid)) {
  1022. sameParent = false;
  1023. break;
  1024. }
  1025. last = rNode;
  1026. }
  1027. }
  1028. const valid = !sheet.zh_setting.readOnly;
  1029. return !(valid && first && sameParent && !(first.level === 1 && first.node_type));
  1030. },
  1031. visible: function (key, opt) {
  1032. return !readOnly;
  1033. }
  1034. };
  1035. billsContextMenuOptions.items.sprBase = '-----------';
  1036. }
  1037. billsContextMenuOptions.items.copyBlock = {
  1038. name: '复制整块',
  1039. icon: 'fa-files-o',
  1040. callback: function (key, opt) {
  1041. /*ledgerSpread.commandManager().execute({
  1042. cmd:"copy",
  1043. sheetName:ledgerSpread.getActiveSheet().name()
  1044. });*/
  1045. treeOperationObj.block = [];
  1046. const copyBlockList = [];
  1047. const sheet = ledgerSpread.getActiveSheet();
  1048. const sel = sheet.getSelections()[0];
  1049. let iRow = sel.row;
  1050. const pid = sheet.zh_tree.nodes[iRow].ledger_pid;
  1051. while (iRow < sel.row + sel.rowCount) {
  1052. const node = sheet.zh_tree.nodes[iRow];
  1053. if (node.ledger_pid !== pid) {
  1054. toastr.error('仅可同时选中同层节点');
  1055. return;
  1056. }
  1057. copyBlockList.push(node.ledger_id);
  1058. iRow += sheet.zh_tree.getPosterity(node).length + 1;
  1059. }
  1060. const tenderId = _.toInteger(getTenderId());
  1061. setLocalCache(copyBlockTag, JSON.stringify({tid: tenderId, block: copyBlockList}));
  1062. //treeOperationObj.block = copyBlockList;
  1063. },
  1064. visible: function (key, opt) {
  1065. const sheet = ledgerSpread.getActiveSheet();
  1066. const selection = sheet.getSelections();
  1067. const row = selection[0].row;
  1068. const select = ledgerTree.nodes[row];
  1069. return select;
  1070. },
  1071. disabled: function (key, opt) {
  1072. const sheet = ledgerSpread.getActiveSheet();
  1073. const selection = sheet.getSelections();
  1074. const row = selection[0].row;
  1075. const select = ledgerTree.nodes[row];
  1076. return select && select.level <= 1;
  1077. }
  1078. };
  1079. if (!readOnly) {
  1080. billsContextMenuOptions.items.pasteBlock = {
  1081. name: '粘贴整块',
  1082. icon: 'fa-clipboard',
  1083. disabled: function (key, opt) {
  1084. //const block = treeOperationObj.block || [];
  1085. const copyInfo = JSON.parse(getLocalCache(copyBlockTag));
  1086. return !(copyInfo && copyInfo.tid && copyInfo.tid > 0 && copyInfo.block && copyInfo.block.length > 0);
  1087. },
  1088. callback: function (key, opt) {
  1089. //const block = treeOperationObj.block || [];
  1090. const copyInfo = JSON.parse(getLocalCache(copyBlockTag));
  1091. if (copyInfo.block.length > 0) {
  1092. treeOperationObj.pasteBlock(ledgerSpread, copyInfo);
  1093. } else {
  1094. document.execCommand('paste');
  1095. }
  1096. },
  1097. visible: function (key, opt) {
  1098. return !readOnly;
  1099. }
  1100. };
  1101. billsContextMenuOptions.items.sprBlock = '-----------';
  1102. }
  1103. if (!readOnly) {
  1104. billsContextMenuOptions.items.sortChildren = {
  1105. name: '顺序重排子项编号',
  1106. icon: 'fa-sort-numeric-asc',
  1107. disabled: function (key, opt) {
  1108. const node = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
  1109. return !node || !node.code || !node.children || node.children === 0;
  1110. },
  1111. callback: function (key, opt) {
  1112. treeOperationObj.sortCode(ledgerSpread.getActiveSheet());
  1113. },
  1114. visible: function (key, opt) {
  1115. return !readOnly;
  1116. }
  1117. };
  1118. if (!checkTzMeasureType()) {
  1119. billsContextMenuOptions.items.applyDeal2Sgfh = {
  1120. name: '填设计量',
  1121. callback: function (key, opt) {
  1122. postData(window.location.pathname + '/deal2sgfh', null, function (result) {
  1123. ledgerTree.loadDatas(result.bills);
  1124. treeCalc.calculateAll(ledgerTree);
  1125. SpreadJsObj.loadSheetData(ledgerSpread.getActiveSheet(), 'tree', ledgerTree);
  1126. });
  1127. }
  1128. };
  1129. }
  1130. billsContextMenuOptions.items.sprSort = '-----------';
  1131. }
  1132. if (!readOnly) {
  1133. billsContextMenuOptions.items.batchInsert = {
  1134. name: '批量插入',
  1135. type: 'batchInsert',
  1136. value: '2',
  1137. icon: 'fa-sign-in',
  1138. batchInsert: function (obj, root) {
  1139. if (_.toNumber(obj.value) > _.toNumber(obj.max)) {
  1140. obj.value = obj.max;
  1141. toastr.warning('批量插入不可多于' + obj.max);
  1142. } else if(_.toNumber(obj.value) < _.toNumber(obj.min)) {
  1143. obj.value = obj.min;
  1144. toastr.warning('批量插入不可少于' + obj.min);
  1145. } else {
  1146. treeOperationObj.addNode(ledgerSpread.getActiveSheet(), parseInt(obj.value));
  1147. root.$menu.trigger('contextmenu:hide');
  1148. }
  1149. },
  1150. disabled: function (key, opt) {
  1151. const sheet = ledgerSpread.getActiveSheet();
  1152. const selection = sheet.getSelections();
  1153. const sel = selection ? selection[0] : sheet.getSelections()[0];
  1154. const row = sel ? sel.row : -1;
  1155. const tree = sheet.zh_tree;
  1156. if (!tree) return true;
  1157. const first = sheet.zh_tree.nodes[row];
  1158. let last = first, sameParent = true;
  1159. if (sel.rowCount > 1) {
  1160. for (let r = 1; r < sel.rowCount; r++) {
  1161. const rNode = tree.nodes[sel.row + r];
  1162. if (rNode.level > first.level) continue;
  1163. if ((rNode.level < first.level) || (rNode.level === first.level && rNode.pid !== first.pid)) {
  1164. sameParent = false;
  1165. break;
  1166. }
  1167. last = rNode;
  1168. }
  1169. }
  1170. const valid = !sheet.zh_setting.readOnly;
  1171. return !(valid && first && first.level > 1);
  1172. },
  1173. visible: function (key, opt) {
  1174. return !readOnly;
  1175. }
  1176. };
  1177. billsContextMenuOptions.items.batchInsertBillsPos = {
  1178. name: '批量插入清单-计量单元',
  1179. icon: 'fa-sign-in',
  1180. disabled: function (key, opt) {
  1181. if (!checkTzMeasureType()) return true;
  1182. const sheet = ledgerSpread.getActiveSheet();
  1183. const selection = sheet.getSelections();
  1184. const row = selection[0].row;
  1185. const select = ledgerTree.nodes[row];
  1186. if (select) {
  1187. if (select.code && select.code !== '') {
  1188. return !ledgerTree.isLeafXmj(select);
  1189. } else {
  1190. const parent = ledgerTree.getParent(select);
  1191. return !(parent && ledgerTree.isLeafXmj(parent));
  1192. }
  1193. } else {
  1194. return false;
  1195. }
  1196. },
  1197. callback: function (key, opt) {
  1198. if (!batchInsertObj) {
  1199. batchInsertObj = new BatchInsertBillsPosObj($('#batch'));
  1200. } else {
  1201. batchInsertObj.initView();
  1202. }
  1203. $('#batch').modal('show');
  1204. },
  1205. visible: function (key, opt) {
  1206. return !readOnly;
  1207. }
  1208. };
  1209. billsContextMenuOptions.items.sprBatch = '-----------';
  1210. }
  1211. if (!readOnly) {
  1212. billsContextMenuOptions.items.importExcel = {
  1213. name: '导入分项清单Excel',
  1214. icon: 'fa-file-excel-o',
  1215. disabled: function (key, opt) {
  1216. return readOnly;
  1217. },
  1218. callback: function (key, opt) {
  1219. importExcel.doImport({
  1220. template: {
  1221. hint: '0号台账',
  1222. url: '/template/导入分项清单EXCEL格式.xls',
  1223. },
  1224. callback: function (sheet) {
  1225. postDataCompress(window.location.pathname + '/upload-excel/tz', sheet, function (result) {
  1226. ledgerTree.loadDatas(result.bills);
  1227. treeCalc.calculateAll(ledgerTree);
  1228. SpreadJsObj.loadSheetData(ledgerSpread.getActiveSheet(), 'tree', ledgerTree);
  1229. pos.loadDatas(result.pos);
  1230. posOperationObj.loadCurPosData();
  1231. }, null);
  1232. },
  1233. // callback: function (file, select) {
  1234. // const formData = new FormData();
  1235. // formData.append('file', file.files[0]);
  1236. // postDataWithFileProgress(window.location.pathname + '/upload-excel?ueType=tz&sheetName=' + select, formData, function (result) {
  1237. // ledgerTree.loadDatas(result.bills);
  1238. // treeCalc.calculateAll(ledgerTree);
  1239. // SpreadJsObj.loadSheetData(ledgerSpread.getActiveSheet(), 'tree', ledgerTree);
  1240. // pos.loadDatas(result.pos);
  1241. // posOperationObj.loadCurPosData();
  1242. // }, null);
  1243. // }
  1244. //u_type: importExcel.uploadType.file,
  1245. });
  1246. //$('#upload-ledger').modal('show');
  1247. },
  1248. visible: function (key, opt) {
  1249. return !readOnly;
  1250. }
  1251. };
  1252. billsContextMenuOptions.items.importGclBills2Xmj = {
  1253. name: '导入工程量清单至项目节',
  1254. icon: 'fa-file-excel-o',
  1255. disabled: function (key, opt) {
  1256. const node = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
  1257. return readOnly
  1258. || (node.children && node.children.length > 0)
  1259. || (!_.isNil(node.b_code) && node.b_code !== '');
  1260. },
  1261. callback: function (key, opt) {
  1262. const node = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
  1263. importExcel.doImport({
  1264. template: {
  1265. hint: '工程量清单',
  1266. url: '/template/导入工程量清单EXCEL格式.xls',
  1267. },
  1268. callback: function (sheet) {
  1269. postDataCompress(window.location.pathname + '/upload-excel/gcl2xmj', {id: node.id, sheet: sheet}, function (result) {
  1270. const ledgerSheet = ledgerSpread.getActiveSheet();
  1271. const sel = ledgerSheet.getSelections();
  1272. const refreshNode = ledgerTree.loadPostData(result);
  1273. treeOperationObj.refreshTree(ledgerSheet, refreshNode);
  1274. if (refreshNode.create[0]) {
  1275. if (sel && sel[0]) {
  1276. ledgerSheet.setSelection(refreshNode.create[0].index, sel[0].col, sel[0].rowCount, sel[0].colCount);
  1277. SpreadJsObj.reloadRowsBackColor(ledgerSheet, [sel[0].row, refreshNode.create[0].index]);
  1278. } else {
  1279. ledgerSheet.setSelection(refreshNode.create[0].index, 0, 1, 1);
  1280. SpreadJsObj.reloadRowsBackColor(ledgerSheet, [refreshNode.create[0].index]);
  1281. }
  1282. }
  1283. treeOperationObj.refreshOperationValid(ledgerSheet);
  1284. }, null);
  1285. }
  1286. });
  1287. },
  1288. visible: function (key, opt) {
  1289. return !readOnly;
  1290. }
  1291. };
  1292. billsContextMenuOptions.items.sprImport = '-----------';
  1293. }
  1294. billsContextMenuOptions.items.exportExcel = {
  1295. name: '导出表格数据',
  1296. icon: 'fa-file-excel-o',
  1297. callback: function (key, opt) {
  1298. const fileName = $('.text-truncate').attr('data-original-title') + '.xlsx';
  1299. SpreadExcelObj.exportSpread2XlsxWithHeader(ledgerSpread, fileName);
  1300. },
  1301. visible: function (key, opt) {
  1302. try {
  1303. return is_debug;
  1304. } catch (err) {
  1305. return false;
  1306. }
  1307. }
  1308. };
  1309. $.contextMenu(billsContextMenuOptions);
  1310. const posSearch = $.posSearch({selector: '#pos-search', searchSpread: posSpread});
  1311. // 台账模式加载计量单元数据
  1312. if (checkTzMeasureType()) {
  1313. $.divResizer({
  1314. select: '#main-resize',
  1315. callback: function () {
  1316. ledgerSpread.refresh();
  1317. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  1318. $(".sp-wrap").height(bcontent-30);
  1319. posSpread.refresh();
  1320. }
  1321. });
  1322. SpreadJsObj.initSheet(posSpread.getActiveSheet(), posSpreadSetting);
  1323. }
  1324. //绑定计量单元编辑事件
  1325. const posOperationObj = {
  1326. editStarting: function (e, info) {
  1327. posOperationObj.ledgerTreeNode = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
  1328. },
  1329. loadExprToInput: function () {
  1330. const sheet = posSpread.getActiveSheet();
  1331. const sel = sheet.getSelections()[0];
  1332. if (!sel || !sheet.zh_setting) return;
  1333. const col = sheet.zh_setting.cols[sel.col], cell = sheet.getCell(sel.row, sel.col);
  1334. if (col && col.type === 'Number') {
  1335. const data = SpreadJsObj.getSelectObject(sheet);
  1336. if (data) {
  1337. $('#pos-expr').val(data[col.field]).attr('field', col.field).attr('org', data[col.field])
  1338. .attr('row', sel.row).attr('readOnly', readOnly || cell.locked());
  1339. } else {
  1340. $('#pos-expr').val('').attr('readOnly', true);
  1341. }
  1342. } else {
  1343. $('#pos-expr').val('').attr('readOnly', true);
  1344. }
  1345. },
  1346. /**
  1347. * 加载计量单元 根据当前台账选择节点
  1348. */
  1349. loadCurPosData: function () {
  1350. //spreadJsObj.reinitSheet(posSpread.getActiveSheet());
  1351. const node = treeOperationObj.getSelectNode(ledgerSpread.getActiveSheet());
  1352. if (node) {
  1353. const posData = pos.ledgerPos[itemsPre + node.id] || [];
  1354. SpreadJsObj.loadSheetData(posSpread.getActiveSheet(), 'data', posData);
  1355. } else {
  1356. SpreadJsObj.loadSheetData(posSpread.getActiveSheet(), 'data', []);
  1357. }
  1358. posOperationObj.loadExprToInput();
  1359. },
  1360. /**
  1361. * 编辑单元格响应事件
  1362. * @param {Object} e
  1363. * @param {Object} info
  1364. */
  1365. editEnded: function (e, info) {
  1366. if (info.sheet.zh_setting) {
  1367. const posData = info.sheet.zh_data ? info.sheet.zh_data[info.row] : null;
  1368. const col = info.sheet.zh_setting.cols[info.col];
  1369. const orgText = posData ? posData[col.field] : null;
  1370. const newText = trimInvalidChar(info.editingText);
  1371. if (orgText === newText || ((!orgText || orgText === '') && (newText === ''))) {
  1372. return;
  1373. }
  1374. //const node = treeOperationObj.getSelectNode(ledgerSpread.getActiveSheet());
  1375. const node = posOperationObj.ledgerTreeNode;
  1376. if (!node) {
  1377. toastr.error('数据错误,请选择台账节点后再试');
  1378. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1379. return;
  1380. } else if (newText && newText !== '' && node.children && node.children.length > 0) {
  1381. toastr.error('父节点不可插入计量单元');
  1382. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1383. return;
  1384. } else if (newText && newText !== '' && (!node.b_code || node.b_code === '')) {
  1385. toastr.error('项目节不可插入计量单元');
  1386. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1387. return;
  1388. }
  1389. const data = {};
  1390. if (col.field === 'name') {
  1391. if (newText === '' && posData) {
  1392. toastr.error('部位名称不可为空');
  1393. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1394. return;
  1395. } else if (!posData) {
  1396. if (newText && newText !== '') {
  1397. data.updateType = 'add';
  1398. const sortData = info.sheet.zh_data;
  1399. const order = (!sortData || sortData.length === 0) ? 1 : Math.max(sortData[sortData.length - 1].porder + 1, sortData.length + 1);
  1400. data.updateData = { name: newText, lid: node.id, tid: tender.id, porder: order};
  1401. } else {
  1402. return;
  1403. }
  1404. } else {
  1405. data.updateType = 'update';
  1406. data.updateData = {id: posData.id, name: newText};
  1407. }
  1408. } else if (!posData) {
  1409. toastr.warning('新增计量单元请先输入名称');
  1410. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1411. return;
  1412. } else {
  1413. data.updateType = 'update';
  1414. data.updateData = {id: posData.id};
  1415. if (col.type === 'Number') {
  1416. const num = _.toNumber(newText);
  1417. if (_.isFinite(num)) {
  1418. data.updateData[col.field] = num;
  1419. } else {
  1420. try {
  1421. data.updateData[col.field] = math.evaluate(transExpr(newText));
  1422. } catch(err) {
  1423. toastr.error('输入的表达式非法');
  1424. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1425. return;
  1426. }
  1427. }
  1428. } else {
  1429. data.updateData[col.field] = newText;
  1430. }
  1431. }
  1432. postData('/tender/' + getTenderId() + '/pos/update', data, function (result) {
  1433. const updateRst = pos.updateDatas(result.pos);
  1434. // 刷新当前行, 不适用于新增(在非下一空白行新增)
  1435. if (updateRst.create.length > 0) {
  1436. // info.sheet.addRows(info.row, 1);
  1437. // if (info.sheet.zh_data.length === 0) {
  1438. // info.sheet.zh_data = pos.ledgerPos[itemsPre + node.id] || [];
  1439. // }
  1440. // SpreadJsObj.reLoadRowData(info.sheet, info.sheet.zh_data.length - 1);
  1441. posOperationObj.loadCurPosData();
  1442. } else {
  1443. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1444. }
  1445. const loadResult = ledgerTree.loadPostData(result.ledger);
  1446. treeOperationObj.refreshTree(ledgerSpread.getActiveSheet(), loadResult);
  1447. treeOperationObj.refreshOperationValid(ledgerSpread.getActiveSheet());
  1448. }, function () {
  1449. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1450. });
  1451. }
  1452. },
  1453. /**
  1454. * 删除按钮响应事件
  1455. * @param sheet
  1456. */
  1457. deletePress: function (sheet) {
  1458. const self = this;
  1459. if (sheet.zh_setting) {
  1460. const sortData = sheet.zh_data;
  1461. const datas = [], posSelects = [];
  1462. const sel = sheet.getSelections()[0];
  1463. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  1464. let bDel = false;
  1465. const node = sortData[iRow];
  1466. if (node) {
  1467. const data = {id: node.id};
  1468. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  1469. const colSetting = sheet.zh_setting.cols[iCol];
  1470. if (colSetting.field === 'name') {
  1471. toastr.error('部位名称不能为空');
  1472. return;
  1473. }
  1474. const style = sheet.getStyle(iRow, iCol);
  1475. if (!style.locked) {
  1476. const colSetting = sheet.zh_setting.cols[iCol];
  1477. data[colSetting.field] = null;
  1478. bDel = true;
  1479. }
  1480. }
  1481. if (bDel) {
  1482. datas.push(data);
  1483. posSelects.push(node);
  1484. }
  1485. }
  1486. }
  1487. if (datas.length > 0) {
  1488. postData('/tender/' + getTenderId() + '/pos/update', {updateType: 'update', updateData: datas}, function (result) {
  1489. pos.updateDatas(result.pos);
  1490. posOperationObj.loadCurPosData();
  1491. const loadResult = ledgerTree.loadPostData(result.ledger);
  1492. treeOperationObj.refreshTree(ledgerSpread.getActiveSheet(), loadResult);
  1493. treeOperationObj.refreshOperationValid(ledgerSpread.getActiveSheet());
  1494. }, function () {
  1495. posOperationObj.loadCurPosData();
  1496. });
  1497. }
  1498. }
  1499. },
  1500. /**
  1501. * 删除 计量单元
  1502. * @param sheet
  1503. */
  1504. deletePos: function (sheet) {
  1505. const selection = sheet.getSelections();
  1506. const data = {
  1507. updateType: 'delete',
  1508. updateData: [],
  1509. };
  1510. const row = selection[0].row, count = selection[0].rowCount;
  1511. const sortData = sheet.zh_data;
  1512. for (let iRow = 0; iRow < count; iRow++) {
  1513. if (sortData[iRow + row]) {
  1514. data.updateData.push(sortData[iRow + row].id);
  1515. }
  1516. }
  1517. if (data.updateData.length > 0) {
  1518. postData('/tender/' + getTenderId() + '/pos/update', data, function (result) {
  1519. pos.removeDatas(result.pos);
  1520. sheet.deleteRows(row, count);
  1521. const loadResult = ledgerTree.loadPostData(result.ledger);
  1522. treeOperationObj.refreshTree(ledgerSpread.getActiveSheet(), loadResult);
  1523. treeOperationObj.refreshOperationValid(ledgerSpread.getActiveSheet());
  1524. });
  1525. }
  1526. },
  1527. /**
  1528. * 粘贴单元格响应事件
  1529. * @param e
  1530. * @param info
  1531. */
  1532. clipboardPasted: function (e, info) {
  1533. if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
  1534. info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
  1535. }
  1536. const node = treeOperationObj.getSelectNode(ledgerSpread.getActiveSheet());
  1537. if (node.code && (node.code !== '')) {
  1538. toastr.error('项目节不可含有清单明细');
  1539. posOperationObj.loadCurPosData();
  1540. return;
  1541. }
  1542. if (node.children && (node.children.length > 0)) {
  1543. toastr.error('仅清单子项可以含有计量单元');
  1544. posOperationObj.loadCurPosData();
  1545. return;
  1546. }
  1547. if (info.sheet.zh_setting) {
  1548. const data = [];
  1549. const sortData = info.sheet.zh_data || [];
  1550. if (sortData.length === 0 || info.cellRange.row + info.cellRange.rowCount > sortData.length) {
  1551. if (info.cellRange.col !== 0) {
  1552. toastr.warning('新增计量单元请先输入名称');
  1553. posOperationObj.loadCurPosData();
  1554. return;
  1555. }
  1556. }
  1557. const lastOrder = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  1558. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  1559. let bPaste = false;
  1560. const curRow = info.cellRange.row + iRow;
  1561. const posData = curRow >= sortData.length ? {lid: node.id, porder: lastOrder + curRow - sortData.length} : {id: sortData[curRow].id, lid: node.id};
  1562. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  1563. const curCol = info.cellRange.col + iCol;
  1564. const colSetting = info.sheet.zh_setting.cols[curCol];
  1565. if (!colSetting) continue;
  1566. posData[colSetting.field] = trimInvalidChar(info.sheet.getText(curRow, curCol));
  1567. if (colSetting.type === 'Number') {
  1568. const num = _.toNumber(posData[colSetting.field]);
  1569. if (num) {
  1570. posData[colSetting.field] = num;
  1571. bPaste = true;
  1572. } else {
  1573. try {
  1574. posData[colSetting.field] = math.evaluate(transExpr(posData[colSetting.field]));
  1575. bPaste = true;
  1576. } catch(err) {
  1577. delete posData[colSetting.field];
  1578. toastr.warning('粘贴了表达式非法,已过滤');
  1579. }
  1580. }
  1581. } else {
  1582. bPaste = true;
  1583. }
  1584. }
  1585. if (bPaste) {
  1586. data.push(posData);
  1587. }
  1588. }
  1589. if (data.length > 0) {
  1590. postData('/tender/' + getTenderId() + '/pos/paste', data, function (result) {
  1591. pos.updateDatas(result.pos);
  1592. posOperationObj.loadCurPosData();
  1593. const loadResult = ledgerTree.loadPostData(result.ledger);
  1594. treeOperationObj.refreshTree(ledgerSpread.getActiveSheet(), loadResult);
  1595. posOperationObj.loadCurPosData();
  1596. treeOperationObj.refreshOperationValid(ledgerSpread.getActiveSheet());
  1597. }, function () {
  1598. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1599. });
  1600. } else {
  1601. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1602. }
  1603. }
  1604. },
  1605. selectionChanged: function (e, info) {
  1606. posOperationObj.loadExprToInput();
  1607. },
  1608. addPegs: function (pegs) {
  1609. if (!pegs || pegs.length <= 0) return;
  1610. const node = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
  1611. if (!node) return;
  1612. const sheet = posSpread.getActiveSheet();
  1613. const sortData = sheet.zh_data || [];
  1614. let order = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  1615. pegs.forEach(function (p) {p.porder = ++order; p.lid = node.id});
  1616. postData('/tender/' + getTenderId() + '/pos/paste', pegs, function (result) {
  1617. pos.updateDatas(result.pos);
  1618. posOperationObj.loadCurPosData();
  1619. treeOperationObj.refreshOperationValid(ledgerSpread.getActiveSheet());
  1620. });
  1621. }
  1622. };
  1623. posSpread.bind(spreadNS.Events.SelectionChanged, posOperationObj.selectionChanged);
  1624. if (!posSpreadSetting.readOnly) {
  1625. $('#pos-expr').bind('change mouseleave', function () {
  1626. if (document.activeElement.id !== "pos-expr") return;
  1627. const expr = $(this);
  1628. const posSheet = posSpread.getActiveSheet();
  1629. const select = SpreadJsObj.getSelectObject(posSheet);
  1630. if (!select) return;
  1631. const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = expr.val(), row = trimInvalidChar(expr.attr('row'));
  1632. if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
  1633. const data = {id: select.id};
  1634. if (newValue !== '') {
  1635. const num = _.toNumber(newValue);
  1636. if (num) {
  1637. data[field] = num;
  1638. } else {
  1639. try {
  1640. data[field] = math.evaluate(transExpr(newValue));
  1641. } catch (err) {
  1642. toastr.error('输入的表达式非法');
  1643. return;
  1644. }
  1645. }
  1646. } else {
  1647. data[field] = null;
  1648. }
  1649. // 更新至服务器
  1650. postData('/tender/' + getTenderId() + '/pos/update', {updateType: 'update', updateData: data}, function (result) {
  1651. const updateRst = pos.updateDatas(result.pos);
  1652. expr.val(select[field]);
  1653. SpreadJsObj.reLoadRowData(posSheet, _.toNumber(row));
  1654. const loadResult = ledgerTree.loadPostData(result.ledger);
  1655. treeOperationObj.refreshTree(ledgerSpread.getActiveSheet(), loadResult);
  1656. treeOperationObj.refreshOperationValid(ledgerSpread.getActiveSheet());
  1657. });
  1658. });
  1659. SpreadJsObj.addDeleteBind(posSpread, posOperationObj.deletePress);
  1660. posSpread.bind(spreadNS.Events.EditStarting, posOperationObj.editStarting);
  1661. posSpread.bind(spreadNS.Events.EditEnded, posOperationObj.editEnded);
  1662. posSpread.bind(spreadNS.Events.ClipboardPasted, posOperationObj.clipboardPasted);
  1663. const mergePeg = NewMergePeg({ callback: posOperationObj.addPegs });
  1664. // 右键菜单
  1665. $.contextMenu({
  1666. selector: '#pos-spread',
  1667. build: function ($trigger, e) {
  1668. const target = SpreadJsObj.safeRightClickSelection($trigger, e, posSpread);
  1669. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  1670. },
  1671. items: {
  1672. 'delete': {
  1673. name: '删除',
  1674. icon: 'fa-remove',
  1675. disabled: function (key, opt) {
  1676. const sheet = posSpread.getActiveSheet();
  1677. if (sheet.zh_data) {
  1678. const selection = sheet.getSelections();
  1679. return sheet.zh_data.length < selection[0].row + selection[0].rowCount;
  1680. } else {
  1681. return true;
  1682. }
  1683. },
  1684. callback: function (key, opt) {
  1685. posOperationObj.deletePos(posSpread.getActiveSheet());
  1686. }
  1687. },
  1688. 'merge-peg': {
  1689. name: '合并起讫桩号',
  1690. disabled: function (key, opt) {
  1691. const node = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
  1692. return _.isNil(node) || _.isNil(node.b_code) || node.b_code === '';
  1693. },
  1694. callback: function (key, opt) {
  1695. mergePeg.show();
  1696. }
  1697. }
  1698. }
  1699. });
  1700. } else {
  1701. SpreadJsObj.forbiddenSpreadContextMenu('#pos-spread', posSpread);
  1702. }
  1703. postData(window.location.pathname + '/load', {}, function (data) {
  1704. ledgerTree.loadDatas(data.bills);
  1705. treeCalc.calculateAll(ledgerTree);
  1706. SpreadJsObj.loadSheetData(ledgerSpread.getActiveSheet(), 'tree', ledgerTree);
  1707. SpreadJsObj.loadTopAndSelect(ledgerSpread.getActiveSheet(), ckBillsSpread);
  1708. pos.loadDatas(data.pos);
  1709. posOperationObj.loadCurPosData();
  1710. SpreadJsObj.resetTopAndSelect(posSpread.getActiveSheet());
  1711. treeOperationObj.refreshOperationValid(ledgerSpread.getActiveSheet());
  1712. treeOperationObj.loadExprToInput(ledgerSpread.getActiveSheet());
  1713. }, null, true);
  1714. $.divResizer({
  1715. select: '#right-spr',
  1716. callback: function () {
  1717. ledgerSpread.refresh();
  1718. if (posSpread) {
  1719. posSpread.refresh();
  1720. }
  1721. if (stdXmj) {
  1722. stdXmj.spread.refresh();
  1723. }
  1724. if (stdGcl) {
  1725. stdGcl.spread.refresh();
  1726. }
  1727. if (dealBills) {
  1728. dealBills.spread.refresh();
  1729. }
  1730. if (searchLedger) {
  1731. searchLedger.spread.refresh();
  1732. }
  1733. }
  1734. });
  1735. const stdLibCellDoubleClick = function (e, info) {
  1736. const stdSheet = info.sheet;
  1737. const mainSheet = ledgerSpread.getActiveSheet();
  1738. if (!stdSheet.zh_setting || !stdSheet.zh_tree || !mainSheet.zh_tree) { return; }
  1739. const stdTree = stdSheet.zh_tree;
  1740. const stdNode = stdTree.nodes[info.row];
  1741. const mainTree = mainSheet.zh_tree;
  1742. const sel = mainSheet.getSelections()[0];
  1743. const mainNode = mainTree.nodes[sel.row];
  1744. if (!stdNode) { return; }
  1745. if (info.sheet.zh_setting.stdType === 'gcl') {
  1746. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  1747. toastr.warning('非最底层项目下,不应添加清单');
  1748. return;
  1749. }
  1750. }
  1751. postData(window.location.pathname + '/update', {
  1752. postType: 'add-std',
  1753. postData: {
  1754. id: ledgerTree.getNodeKey(mainNode),
  1755. tender_id: mainNode.tender_id,
  1756. stdType: info.sheet.zh_setting.stdType,
  1757. stdLibId: stdNode.list_id,
  1758. stdNode: stdTree.getNodeKey(stdNode)
  1759. }
  1760. }, function (result) {
  1761. const refreshNode = mainTree.loadPostData(result);
  1762. treeOperationObj.refreshTree(mainSheet, refreshNode);
  1763. if (refreshNode.create && refreshNode.create.length > 0) {
  1764. mainSheet.setSelection(refreshNode.create[refreshNode.create.length - 1].index, sel.col, sel.rowCount, sel.colCount);
  1765. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, refreshNode.create[refreshNode.create.length - 1].index]);
  1766. } else {
  1767. const node = _.find(ledgerTree.nodes, {code: stdNode.code, name: stdNode.name});
  1768. if (node) {
  1769. mainSheet.setSelection(ledgerTree.nodes.indexOf(node), sel.col, sel.rowCount, sel.colCount);
  1770. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, ledgerTree.nodes.indexOf(node)]);
  1771. }
  1772. }
  1773. treeOperationObj.refreshOperationValid(mainSheet);
  1774. ledgerSpread.focus();
  1775. posOperationObj.loadCurPosData();
  1776. });
  1777. };
  1778. const stdXmjSetting = {
  1779. selector: '#std-xmj',
  1780. stdType: 'xmj',
  1781. treeSetting: {
  1782. id: 'chapter_id',
  1783. pid: 'pid',
  1784. order: 'order',
  1785. level: 'level',
  1786. rootId: -1,
  1787. keys: ['id', 'list_id', 'chapter_id'],
  1788. },
  1789. spreadSetting: {
  1790. cols: [
  1791. {title: '项目节编号', field: 'code', hAlign: 0, width: 120, formatter: '@', readOnly: true, cellType: 'tree'},
  1792. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  1793. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true}
  1794. ],
  1795. treeCol: 0,
  1796. emptyRows: 0,
  1797. headRows: 1,
  1798. headRowHeight: [32],
  1799. defaultRowHeight: 21,
  1800. headerFont: '12px 微软雅黑',
  1801. font: '12px 微软雅黑',
  1802. headColWidth: [0],
  1803. selectedBackColor: '#fffacd',
  1804. },
  1805. cellDoubleClick: stdLibCellDoubleClick,
  1806. page: 'ledger',
  1807. tid: getTenderId(),
  1808. };
  1809. const stdGclSetting = {
  1810. selector: '#std-gcl',
  1811. stdType: 'gcl',
  1812. treeSetting: {
  1813. id: 'bill_id',
  1814. pid: 'pid',
  1815. order: 'order',
  1816. level: 'level',
  1817. rootId: -1,
  1818. keys: ['id', 'list_id', 'bill_id']
  1819. },
  1820. spreadSetting: {
  1821. cols: [
  1822. {title: '清单编号', field: 'b_code', hAlign: 0, width: 120, formatter: '@', readOnly: true, cellType: 'tree'},
  1823. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  1824. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true}
  1825. ],
  1826. treeCol: 0,
  1827. emptyRows: 0,
  1828. headRows: 1,
  1829. headRowHeight: [32],
  1830. defaultRowHeight: 21,
  1831. headerFont: '12px 微软雅黑',
  1832. font: '12px 微软雅黑',
  1833. headColWidth: [0],
  1834. selectedBackColor: '#fffacd',
  1835. },
  1836. cellDoubleClick: stdLibCellDoubleClick,
  1837. page: 'ledger',
  1838. tid: getTenderId(),
  1839. };
  1840. // 展开收起标准清单
  1841. $('a', '#side-menu').bind('click', function (e) {
  1842. e.preventDefault();
  1843. const tab = $(this), tabPanel = $(tab.attr('content'));
  1844. const showSideTools = function (show) {
  1845. const left = $('#left-view'), right = $('#right-view'), parent = left.parent();
  1846. if (show) {
  1847. right.show();
  1848. autoFlashHeight();
  1849. /**
  1850. * right.show()后, parent被撑开成2倍left.height, 导致parent.width减少了10px
  1851. * 第一次left.width调整后,parent的缩回left.height, 此时parent.width又增加了10px
  1852. * 故需要通过最终的parent.width再计算一次left.width
  1853. *
  1854. * Q: 为什么不通过先计算left.width的宽度,以避免计算两次left.width?
  1855. * A: 右侧工具栏不一定显示,当右侧工具栏显示过一次后,就必须使用parent和right来计算left.width
  1856. *
  1857. */
  1858. //left.css('width', parent.width() - right.outerWidth());
  1859. //left.css('width', parent.width() - right.outerWidth());
  1860. const percent = 100 - right.outerWidth() /parent.width() * 100;
  1861. left.css('width', percent + '%');
  1862. } else {
  1863. left.width(parent.width());
  1864. right.hide();
  1865. }
  1866. };
  1867. // 展开工具栏、切换标签
  1868. if (!tab.hasClass('active')) {
  1869. const close = $('.active', '#side-menu').length === 0;
  1870. $('a', '#side-menu').removeClass('active');
  1871. tab.addClass('active');
  1872. $('.tab-content .tab-pane').removeClass('active');
  1873. tabPanel.addClass('active');
  1874. showSideTools(tab.hasClass('active'));
  1875. if (tab.attr('content') === '#std-xmj') {
  1876. if (!stdXmj) {
  1877. stdXmj = new stdLib(stdXmjSetting);
  1878. //stdXmj.loadLib($('select', '#std-xmj').val());
  1879. }
  1880. stdXmj.spread.refresh();
  1881. } else if (tab.attr('content') === '#std-gcl') {
  1882. if (!stdGcl) {
  1883. stdGcl = new stdLib(stdGclSetting);
  1884. //stdGcl.loadLib($('select', '#std-gcl').val());
  1885. }
  1886. stdGcl.spread.refresh();
  1887. } else if (tab.attr('content') === '#deal-bills') {
  1888. if (!dealBills) {
  1889. dealBills = new DealBills('#deal-bills-spread', {
  1890. cols: [
  1891. {title: '清单编号', field: 'code', hAlign: 0, width: 85, formatter: '@', readOnly: true},
  1892. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  1893. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true},
  1894. {title: '单价', field: 'unit_price', hAlign: 2, width: 50, readOnly: true},
  1895. {title: '数量', field: 'quantity', hAlign: 2, width: 50, readOnly: true},
  1896. {title: '金额', field: 'total_price', hAlign: 2, width: 50, readOnly: true},
  1897. ],
  1898. emptyRows: 0,
  1899. headRows: 1,
  1900. headRowHeight: [32],
  1901. defaultRowHeight: 21,
  1902. headerFont: '12px 微软雅黑',
  1903. font: '12px 微软雅黑',
  1904. headColWidth: [0],
  1905. selectedBackColor: '#fffacd',
  1906. });
  1907. dealBills.loadData();
  1908. }
  1909. dealBills.spread.refresh();
  1910. } else if (tab.attr('content') === '#search' && !searchLedger) {
  1911. if (!searchLedger) {
  1912. searchLedger = $.billsSearch({
  1913. selector: '#search',
  1914. searchSpread: ledgerSpread,
  1915. resultSpreadSetting: {
  1916. cols: [
  1917. {title: '项目节编号', field: 'code', hAlign: 0, width: 120, formatter: '@', readOnly: true},
  1918. {title: '清单编号', field: 'b_code', hAlign: 0, width: 120, formatter: '@', readOnly: true},
  1919. {title: '名称', field: 'name', width: 150, hAlign: 0, formatter: '@', readOnly: true},
  1920. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@', readOnly: true},
  1921. {title: '单价', field: 'unit_price', hAlign: 2, width: 50, readOnly: true},
  1922. {title: '数量', field: 'quantity', hAlign: 2, width: 50, readOnly: true},
  1923. ],
  1924. emptyRows: 0,
  1925. headRows: 1,
  1926. headRowHeight: [32],
  1927. defaultRowHeight: 21,
  1928. headerFont: '12px 微软雅黑',
  1929. font: '12px 微软雅黑',
  1930. selectedBackColor: '#fffacd',
  1931. },
  1932. afterLocated: function () {
  1933. posOperationObj.loadCurPosData();
  1934. }
  1935. });
  1936. }
  1937. searchLedger.spread.refresh();
  1938. }
  1939. } else { // 收起工具栏
  1940. tab.removeClass('active');
  1941. tabPanel.removeClass('active');
  1942. showSideTools(tab.hasClass('active'));
  1943. }
  1944. ledgerSpread.refresh();
  1945. if (posSpread) {
  1946. posSpread.refresh();
  1947. }
  1948. });
  1949. class DealBills {
  1950. constructor (selector, spreadSetting) {
  1951. const self = this;
  1952. this.obj = $(selector)[0];
  1953. this.url = '/tender/' + getTenderId() + '/deal';
  1954. this.spreadSetting = spreadSetting;
  1955. this.spread = SpreadJsObj.createNewSpread(this.obj);
  1956. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  1957. if (!readOnly) {
  1958. this.spread.bind(spreadNS.Events.CellDoubleClick, function (e, info) {
  1959. const dealSheet = info.sheet;
  1960. const mainSheet = ledgerSpread.getActiveSheet();
  1961. const dealBills = SpreadJsObj.getSelectObject(dealSheet);
  1962. if (!dealBills) { return; }
  1963. const mainTree = mainSheet.zh_tree;
  1964. const mainNode = SpreadJsObj.getSelectObject(mainSheet);
  1965. if (!mainNode || !mainTree) { return; }
  1966. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  1967. toastr.error('非最底层项目下,不应添加清单');
  1968. return;
  1969. }
  1970. postData(window.location.pathname + '/update', {
  1971. postType: 'add-deal',
  1972. postData: {
  1973. id: mainNode.ledger_id,
  1974. type: mainNode.code ? 'child' : 'next',
  1975. dealBills: {
  1976. b_code: dealBills.code, name: dealBills.name, unit: dealBills.unit,
  1977. unit_price: dealBills.unit_price,
  1978. }
  1979. },
  1980. }, function (result) {
  1981. const refreshData = mainTree.loadPostData(result);
  1982. treeOperationObj.refreshTree(mainSheet, refreshData);
  1983. const sel = mainSheet.getSelections()[0];
  1984. mainSheet.setSelection(refreshData.create[0].index, sel.col, sel.rowCount, sel.colCount);
  1985. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, refreshData.create[0].index]);
  1986. treeOperationObj.refreshOperationValid(mainSheet);
  1987. ledgerSpread.focus();
  1988. posOperationObj.loadCurPosData();
  1989. });
  1990. });
  1991. }
  1992. $('#upload-deal-bills').click(function () {
  1993. const file = $('#deal-bills-file')[0];
  1994. const formData = new FormData();
  1995. formData.append('file', file.files[0]);
  1996. postDataWithFileProgress(self.url+'/upload-excel', formData, function (data) {
  1997. self.data = data;
  1998. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', data);
  1999. $('#upload-deal').modal('hide');
  2000. }, function () {
  2001. $('#upload-deal').modal('hide');
  2002. });
  2003. });
  2004. if (!readOnly) {
  2005. $.contextMenu({
  2006. selector: selector,
  2007. build: function ($trigger, e) {
  2008. const target = SpreadJsObj.safeRightClickSelection($trigger, e, self.spread);
  2009. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  2010. },
  2011. items: {
  2012. apply: {
  2013. name: '应用全部清单单价至台账',
  2014. disabled: function (key, opt) {
  2015. const sheet = self.spread.getActiveSheet();
  2016. return sheet.getRowCount() === 0;
  2017. },
  2018. callback: function (key, opt) {
  2019. const datas = [], sourceData = self.spread.getActiveSheet().zh_data;
  2020. for (const db of sourceData) {
  2021. const targets = ledgerTree.nodes.filter(function (x) {
  2022. return x.b_code === db.code && x.name === db.name && x.unit === db.unit;
  2023. });
  2024. for (const t of targets) {
  2025. if (t.children && t.children.length > 0) continue;
  2026. const data = ledgerTree.getNodeKeyData(t);
  2027. data.unit_price = db.unit_price;
  2028. datas.push(data);
  2029. }
  2030. }
  2031. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  2032. const refreshNode = ledgerTree.loadPostData(result);
  2033. treeOperationObj.refreshTree(ledgerSpread.getActiveSheet(), refreshNode);
  2034. });
  2035. }
  2036. }
  2037. }
  2038. });
  2039. }
  2040. }
  2041. loadData () {
  2042. const self = this;
  2043. postData(this.url+'/get-data', {}, function (data) {
  2044. self.data = data;
  2045. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', data);
  2046. if (data.length > 0) self.spread.getActiveSheet().setSelection(0, 0, 1, 1);
  2047. });
  2048. }
  2049. calculateData () {
  2050. if (this.data) {
  2051. for (const d of this.data) {
  2052. d.total_price = _.multiply(d.quantity, d.unit_price);
  2053. }
  2054. }
  2055. }
  2056. }
  2057. class BatchInsertBillsPosObj {
  2058. constructor (obj) {
  2059. const self = this;
  2060. this.obj = obj;
  2061. this.billsCount = 6;
  2062. this.posCount = 1000;
  2063. // 初始化 清单编号窗口 参数
  2064. this.qdSpreadSetting = {
  2065. cols: [
  2066. {title: '编号', field: 'code', hAlign: 0, width: 80, formatter: '@'},
  2067. {title: '名称', field: 'name', hAlign: 0, width: 120, formatter: '@'},
  2068. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@'},
  2069. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  2070. {title: '图册号', field: 'name', hAlign: 0, width: 60, formatter: '@'},
  2071. ],
  2072. emptyRows: this.billsCount,
  2073. headRows: 1,
  2074. headRowHeight: [32],
  2075. headerFont: '12px 微软雅黑',
  2076. font: '12px 微软雅黑',
  2077. };
  2078. this.qdSpread = SpreadJsObj.createNewSpread($('.batch-l-t', this.obj)[0]);
  2079. // 初始化 部位数量复核表 参数
  2080. this.posSpreadSetting = {
  2081. cols: [
  2082. {title: '计量单元', field: 'bw', hAlign: 0, width: 80, formatter: '@'},
  2083. {title: '图册号', field: 'drawingCode', hAlign: 0, formatter: '@', width: 60},
  2084. ],
  2085. emptyRows: this.posCount,
  2086. headRows: 1,
  2087. headRowHeight: [32],
  2088. headerFont: '12px 微软雅黑',
  2089. font: '12px 微软雅黑',
  2090. };
  2091. for (let iNum = 1; iNum <= this.billsCount; iNum++) {
  2092. this.posSpreadSetting.cols.push(
  2093. {title: '清单' + iNum, field: 'bills' + iNum, hAlign: 2, width: 50}
  2094. )
  2095. }
  2096. this.posSpread = SpreadJsObj.createNewSpread($('.batch-l-b', this.obj)[0]);
  2097. // 初始化 签约清单 参数
  2098. this.dealSpreadSetting = {
  2099. cols: [
  2100. {title: '清单编号', field: 'code', width: 80, hAlign: 0, formatter: '@', readOnly: true},
  2101. {title: '名称', field: 'name', width: 230, hAlign: 0, formatter: '@', readOnly: true},
  2102. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true},
  2103. {title: '单价', field: 'unit_price', hAlign: 2, width: 60, readOnly: true},
  2104. ],
  2105. emptyRows: 0,
  2106. headRows: 1,
  2107. headRowHeight: [32],
  2108. headerFont: '12px 微软雅黑',
  2109. font: '12px 微软雅黑',
  2110. };
  2111. this.dealSpread = SpreadJsObj.createNewSpread($('.batch-r', this.obj)[0]);
  2112. // 初始化 清单编号、部位数量复核表 表格
  2113. this.initView();
  2114. SpreadJsObj.initSheet(this.dealSpread.getActiveSheet(), this.dealSpreadSetting);
  2115. SpreadJsObj.refreshColumnAlign(this.dealSpread.getActiveSheet());
  2116. $.contextMenu({
  2117. selector: '.batch-l-t',
  2118. build: function ($trigger, e) {
  2119. const target = SpreadJsObj.safeRightClickSelection($trigger, e, self.qdSpread);
  2120. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  2121. },
  2122. items: {
  2123. 'create': {
  2124. name: '新增行',
  2125. icon: 'fa-sign-in',
  2126. callback: function (key, opt) {
  2127. const qdSheet = self.qdSpread.getActiveSheet();
  2128. const posSheet = self.posSpread.getActiveSheet();
  2129. qdSheet.addRows(qdSheet.getRowCount(), 1);
  2130. const index = qdSheet.getRowCount();
  2131. qdSheet.getCell(qdSheet.getRowCount() - 1, 0, spreadNS.SheetArea.rowHeader).text('清单' + index);
  2132. posSheet.addColumns(posSheet.getColumnCount(), 1);
  2133. posSheet.getCell(0, index + 2 - 1, spreadNS.SheetArea.colHeader).text('清单' + index);
  2134. },
  2135. },
  2136. 'delete': {
  2137. name: '删除行',
  2138. icon: 'fa-remove',
  2139. callback: function (key, opt) {
  2140. const qdSheet = self.qdSpread.getActiveSheet();
  2141. const posSheet = self.posSpread.getActiveSheet();
  2142. const sel = qdSheet.getSelections()[0];
  2143. qdSheet.deleteRows(sel.row, sel.rowCount);
  2144. posSheet.deleteColumns(sel.row + 2, sel.rowCount);
  2145. for (let iRow = 0, iLen = qdSheet.getRowCount(); iRow < iLen; iRow++) {
  2146. qdSheet.getCell(iRow, 0, spreadNS.SheetArea.rowHeader).text('清单' + (iRow+1));
  2147. }
  2148. for (let iCol = 0, iLen = posSheet.getColumnCount() - 2; iCol < iLen; iCol++) {
  2149. posSheet.getCell(0, iCol + 2, spreadNS.SheetArea.colHeader).text('清单' + (iCol+1));
  2150. }
  2151. qdSheet.setSelection(sel.row, sel.col, 1, 1);
  2152. },
  2153. },
  2154. }
  2155. });
  2156. // 拉取签约清单数据
  2157. if (dealBills) {
  2158. SpreadJsObj.loadSheetData(this.dealSpread.getActiveSheet(), 'data', dealBills.data);
  2159. } else {
  2160. postData('/tender/' + getTenderId() + '/deal/get-data', {}, function (data) {
  2161. SpreadJsObj.loadSheetData(self.dealSpread.getActiveSheet(), 'data', data);
  2162. });
  2163. }
  2164. // 双击签约清单,自动添加到清单编号窗口
  2165. this.dealSpread.bind(GC.Spread.Sheets.Events.CellDoubleClick, function (e, info) {
  2166. const deal = info.sheet.zh_data[info.row];
  2167. const qdSheet = self.qdSpread.getActiveSheet(), posSheet = self.posSpread.getActiveSheet();
  2168. const sel = qdSheet.getSelections()[0];
  2169. qdSheet.getCell(sel.row, 0).value(deal.code);
  2170. qdSheet.getCell(sel.row, 1).value(deal.name);
  2171. qdSheet.getCell(sel.row, 2).value(deal.unit);
  2172. qdSheet.getCell(sel.row, 3).value(deal.unit_price);
  2173. if (sel.row + 1 === qdSheet.getRowCount()) {
  2174. const count = sel.row + 2;
  2175. qdSheet.setRowCount(count);
  2176. qdSheet.getCell(sel.row + 1, 0, GC.Spread.Sheets.SheetArea.rowHeader).text('清单' + count);
  2177. const colCount = posSheet.getColumnCount() + 1
  2178. posSheet.setColumnCount(colCount);
  2179. posSheet.getCell(0, colCount - 1, GC.Spread.Sheets.SheetArea.colHeader).text('清单' + count);
  2180. }
  2181. qdSheet.setSelection(sel.row + 1, sel.col, 1, 1);
  2182. });
  2183. this.qdSpread.bind(spreadNS.Events.ClipboardPasted, function (e, info) {
  2184. const billsCount = info.sheet.getRowCount(), posSheet = self.posSpread.getActiveSheet();
  2185. const count = posSheet.getColumnCount() - 2;
  2186. if (billsCount > count) {
  2187. posSheet.setColumnCount(billsCount + 2);
  2188. for (let i = count + 1; i <= billsCount; i++) {
  2189. info.sheet.getCell(i - 1, 0, spreadNS.SheetArea.rowHeader).text('清单' + i);
  2190. posSheet.getCell(0, i + 2 - 1, spreadNS.SheetArea.colHeader).text('清单' + i);
  2191. }
  2192. }
  2193. if (info.cellRange.col === 0 && info.cellRange.colCount === 1) {
  2194. const dealBills = self.dealSpread.getActiveSheet().zh_data;
  2195. if (dealBills && dealBills.length > 0) {
  2196. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  2197. const curRow = iRow + info.cellRange.row;
  2198. const bills = _.find(dealBills, {code: info.sheet.getText(curRow, 0)});
  2199. if (bills) {
  2200. info.sheet.getCell(curRow, 1).value(bills.name);
  2201. info.sheet.getCell(curRow, 2).value(bills.unit);
  2202. info.sheet.getCell(curRow, 3).value(bills.unit_price);
  2203. }
  2204. }
  2205. }
  2206. }
  2207. });
  2208. this.qdSpread.bind(spreadNS.Events.EditEnded, function (e, info) {
  2209. if (info.col === 0) {
  2210. const dealBills = self.dealSpread.getActiveSheet().zh_data;
  2211. if (dealBills && dealBills.length > 0) {
  2212. const bills = _.find(dealBills, {code: info.editingText});
  2213. if (bills) {
  2214. info.sheet.getCell(info.row, 1).value(bills.name);
  2215. info.sheet.getCell(info.row, 2).value(bills.unit);
  2216. info.sheet.getCell(info.row, 3).value(bills.unit_price);
  2217. }
  2218. }
  2219. }
  2220. });
  2221. this.obj.bind('shown.bs.modal', function () {
  2222. self.qdSpread.refresh();
  2223. self.posSpread.refresh();
  2224. self.dealSpread.refresh();
  2225. });
  2226. $('#batch-ok').click(function () {
  2227. const sheet = ledgerSpread.getActiveSheet();
  2228. const sel = sheet.getSelections()[0];
  2229. const row = sel.row;
  2230. const select = ledgerTree.nodes[row];
  2231. if (select) {
  2232. const insertData = {};
  2233. insertData.batchType = (select.code && select.code !== '') ? 'child' : 'next';
  2234. insertData.id = ledgerTree.getNodeKey(select);
  2235. insertData.batchData = self.getBatchData();
  2236. if (insertData.batchData.length > 0) {
  2237. postData(window.location.pathname + '/update', {postType: 'batch-insert', postData: insertData}, function (data) {
  2238. pos.updateDatas(data.pos);
  2239. const result = ledgerTree.loadPostData(data.ledger);
  2240. treeOperationObj.refreshTree(sheet, result);
  2241. sheet.setSelection(result.create[0].index, sel.col, sel.rowCount, sel.colCount);
  2242. SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, result.create[0].index]);
  2243. treeOperationObj.refreshOperationValid(sheet);
  2244. self.obj.modal('hide');
  2245. }, null, true);
  2246. } else {
  2247. self.obj.modal('hide');
  2248. }
  2249. }
  2250. });
  2251. }
  2252. // 初始化左侧表格
  2253. initView () {
  2254. // 初始化 清单编号
  2255. const qdSheet = this.qdSpread.getActiveSheet();
  2256. qdSheet.setColumnWidth(0, 45, spreadNS.SheetArea.rowHeader);
  2257. SpreadJsObj.initSheet(qdSheet, this.qdSpreadSetting);
  2258. SpreadJsObj.refreshColumnAlign(qdSheet);
  2259. // 清理原有数据
  2260. SpreadJsObj.beginMassOperation(qdSheet);
  2261. qdSheet.clear(0, 0, qdSheet.getRowCount(), qdSheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  2262. for (let iRow = 1; iRow <= this.billsCount; iRow++) {
  2263. qdSheet.getCell(iRow - 1, 0, GC.Spread.Sheets.SheetArea.rowHeader).text('清单' + iRow);
  2264. }
  2265. qdSheet.setSelection(0, 0, 1 ,1);
  2266. SpreadJsObj.endMassOperation(qdSheet);
  2267. // 初始化 部位数量复核表
  2268. const posSheet = this.posSpread.getActiveSheet();
  2269. SpreadJsObj.initSheet(posSheet, this.posSpreadSetting);
  2270. SpreadJsObj.refreshColumnAlign(posSheet);
  2271. // 清理原有数据
  2272. SpreadJsObj.beginMassOperation(posSheet);
  2273. posSheet.setColumnWidth(0, 45, GC.Spread.Sheets.SheetArea.rowHeader);
  2274. posSheet.clear(0, 0, posSheet.getRowCount(), posSheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  2275. posSheet.setSelection(0, 0, 1 ,1);
  2276. SpreadJsObj.endMassOperation(posSheet);
  2277. // 检查签约清单数据,以工具栏数据为准
  2278. if (dealBills) {
  2279. SpreadJsObj.loadSheetData(this.dealSpread.getActiveSheet(), 'data', dealBills.data);
  2280. }
  2281. this.dealSpread.getActiveSheet().setSelection(0, 0, 1, 1);
  2282. }
  2283. // 获取界面数据
  2284. getBatchData () {
  2285. const result = [];
  2286. const qdSheet = this.qdSpread.getActiveSheet(), posSheet = this.posSpread.getActiveSheet();
  2287. for (let iRow = 0; iRow < qdSheet.getRowCount(); iRow++) {
  2288. if (qdSheet.getText(iRow, 0) === '') { continue; }
  2289. const qd = {
  2290. b_code: qdSheet.getText(iRow, 0),
  2291. name: qdSheet.getText(iRow, 1),
  2292. unit: qdSheet.getText(iRow, 2),
  2293. price: _.toNumber(qdSheet.getText(iRow, 3)),
  2294. pos: [],
  2295. };
  2296. result.push(qd);
  2297. for (let iPosRow = 0; iPosRow < posSheet.getRowCount(); iPosRow++) {
  2298. const value = _.toNumber(posSheet.getText(iPosRow, iRow + 2));
  2299. if (value !== 0 && !isNaN(value)) {
  2300. qd.pos.push({
  2301. name: posSheet.getText(iPosRow, 0),
  2302. drawing_code: posSheet.getText(iPosRow, 1),
  2303. quantity: value, porder: qd.pos.length + 1,
  2304. });
  2305. }
  2306. }
  2307. }
  2308. return result;
  2309. }
  2310. }
  2311. $('#searchAccount').click(() => {
  2312. const data = {
  2313. keyword: $('#searchName').val(),
  2314. };
  2315. postData('/search/user', data, (data) => {
  2316. const resultDiv = $('#searchResult');
  2317. if (data) {
  2318. $('h5>span', resultDiv).text(data.name);
  2319. $('#addAuditor').attr('auditorId', data.id);
  2320. $('h6', resultDiv).text(data.role);
  2321. $('p', resultDiv).text(data.company);
  2322. resultDiv.show();
  2323. } else {
  2324. toastr.info('未查询到该审核人');
  2325. resultDiv.hide();
  2326. }
  2327. }, () => {
  2328. $('#searchResult').hide();
  2329. });
  2330. });
  2331. // 审批人分组选择
  2332. $('#account_group').change(function () {
  2333. let account_html = '<option value="0">选择审批人</option>';
  2334. for (const account of accountList) {
  2335. if (parseInt($(this).val()) === 0 || parseInt($(this).val()) === account.account_group) {
  2336. const role = account.role !== '' ? '(' + account.role + ')' : '';
  2337. const company = account.company !== '' ? ' -' + account.company : '';
  2338. account_html += '<option value="' + account.id + '">' + account.name + role + company + '</option>';
  2339. }
  2340. }
  2341. $('#account_list').html(account_html);
  2342. });
  2343. // 添加到审批流程中
  2344. $('body').on('change', '#account_list', function () {
  2345. let id = $(this).val();
  2346. id = parseInt(id);
  2347. if (id !== 0) {
  2348. const data = {
  2349. auditorId: $(this).val(),
  2350. };
  2351. postData('/tender/' + getTenderId() + '/ledger/audit/add', data, (data) => {
  2352. const html = [];
  2353. html.push('<li class="list-group-item" auditorId="' + data.audit_id + '"><a href="javascript: void(0)" class="text-danger pull-right">移除</a>');
  2354. html.push('<span>');
  2355. html.push(data.audit_order + ' ');
  2356. html.push(data.name + ' ');
  2357. html.push('</span>');
  2358. html.push('<small class="text-muted">');
  2359. html.push(data.role);
  2360. html.push('</small></li>');
  2361. $('#auditors').append(html.join(''));
  2362. // 如果是重新上报,添加到重新上报列表中
  2363. const auditorshtml = [];
  2364. // 重新上报时。令其它的审批人流程图标转换
  2365. $('#auditors-list li i').removeClass('fa-stop-circle').addClass('fa-chevron-circle-down');
  2366. for (let i = 0; i < $('#auditors-list li').length; i++) {
  2367. $('#auditors-list li').eq(i).find('.pull-right').text(transFormToChinese(i+1) + '审');
  2368. $('#auditors-list2 li').eq(i).find('.pull-right').text(transFormToChinese(i+1) + '审');
  2369. }
  2370. // 添加新审批人
  2371. auditorshtml.push('<li class="list-group-item" data-auditid="' + data.audit_id + '">');
  2372. auditorshtml.push('<i class="fa fa-stop-circle"></i> ');
  2373. auditorshtml.push(data.name + ' <small class="text-muted">' + data.role + '</small>');
  2374. auditorshtml.push('<span class="pull-right">终审</span>');
  2375. auditorshtml.push('</li>');
  2376. $('#auditors-list').append(auditorshtml.join(''));
  2377. const auditorshtml2 = [];
  2378. // 重新上报时。令其它的审批人流程图标转换
  2379. $('#auditors-list2 li i').removeClass('fa-stop-circle').addClass('fa-chevron-circle-down');
  2380. // 添加新审批人
  2381. auditorshtml2.push('<li class="list-group-item" data-auditid="' + data.audit_id + '">');
  2382. auditorshtml2.push('<h5 class="card-title"><i class="fa fa-stop-circle"></i> ');
  2383. auditorshtml2.push(data.name + ' <small class="text-muted">' + data.role + '</small>');
  2384. auditorshtml2.push('<span class="pull-right">终审</span>');
  2385. auditorshtml2.push('</h5></li>');
  2386. $('#auditors-list2').append(auditorshtml2.join(''));
  2387. });
  2388. }
  2389. });
  2390. $('body').on('click', '#auditors li>a', function () {
  2391. const li = $(this).parent();
  2392. const data = {
  2393. auditorId: parseInt(li.attr('auditorId')),
  2394. };
  2395. postData('/tender/' + getTenderId() + '/ledger/audit/delete', data, (data2) => {
  2396. li.remove();
  2397. for (const a of data2) {
  2398. const aLi = $('li[auditorId=' + a.audit_id + ']');
  2399. $('span', aLi).text(a.audit_order + ' ' + a.name + ' ');
  2400. }
  2401. // 如果是重新上报
  2402. // 令最后一个图标转换
  2403. $('#auditors-list li[data-auditid="' + data.auditorId + '"]').remove();
  2404. if ($('#auditors-list li').length !== 0 && !$('#auditors-list li i').hasClass('fa-stop-circle')) {
  2405. $('#auditors-list li').eq($('#auditors-list li').length-1).children('i')
  2406. .removeClass('fa-chevron-circle-down').addClass('fa-stop-circle');
  2407. }
  2408. $('#auditors-list2 li[data-auditid="' + data.auditorId + '"]').remove();
  2409. if ($('#auditors-list2 li').length !== 0 && !$('#auditors-list2 li i').hasClass('fa-stop-circle')) {
  2410. $('#auditors-list2 li').eq($('#auditors-list2 li').length-1).children('i')
  2411. .removeClass('fa-chevron-circle-down').addClass('fa-stop-circle');
  2412. }
  2413. for (let i = 0; i < $('#auditors-list li').length; i++) {
  2414. $('#auditors-list li').eq(i).find('.pull-right').text((i+1 === $('#auditors-list li').length ? '终' : transFormToChinese(i+1)) + '审')
  2415. $('#auditors-list2 li').eq(i).find('.pull-right').text((i+1 === $('#auditors-list2 li').length ? '终' : transFormToChinese(i+1)) + '审')
  2416. }
  2417. });
  2418. });
  2419. $('#hideSp').click(function () {
  2420. $('#sp-list2').modal('hide');
  2421. });
  2422. // 多层modal关闭后的滚动bug修复
  2423. $('#sp-list2').on('hidden.bs.modal', function (e) {
  2424. $(document.body).addClass('modal-open');
  2425. });
  2426. // 显示层次
  2427. (function (select, sheet) {
  2428. $(select).click(function () {
  2429. const tag = $(this).attr('tag');
  2430. const tree = sheet.zh_tree;
  2431. if (!tree) return;
  2432. switch (tag) {
  2433. case "1":
  2434. case "2":
  2435. case "3":
  2436. case "4":
  2437. case "5":
  2438. tree.expandByLevel(parseInt(tag));
  2439. SpreadJsObj.refreshTreeRowVisible(sheet);
  2440. break;
  2441. case "last":
  2442. tree.expandByCustom(() => { return true; });
  2443. SpreadJsObj.refreshTreeRowVisible(sheet);
  2444. break;
  2445. case "leafXmj":
  2446. tree.expandToLeafXmj();
  2447. SpreadJsObj.refreshTreeRowVisible(sheet);
  2448. break;
  2449. }
  2450. });
  2451. })('a[name=showLevel]', ledgerSpread.getActiveSheet());
  2452. // $('#exportLedger').click(function () {
  2453. // const data = [];
  2454. // const setting = {
  2455. // header: ['项目节编号', '清单子目号', '部位明细', '名称', '单位', '清单数量', '设计数量1', '设计数量2', '单价', '合价', '图号', '备注'],
  2456. // width: [100, 70, 70, 300, 60, 80, 80, 80, 80, 80, 100, 100],
  2457. // hAlign: ['left', 'left', 'left', 'left','center', 'right', 'right', 'right', 'right', 'right', 'left', 'left'],
  2458. // };
  2459. // for (const node of ledgerTree.nodes) {
  2460. // data.push([node.code, node.b_code, '', node.name, node.unit,
  2461. // node.quantity, node.dgn_qty1, node.dgn_qty2, node.unit_price, node.total_price,
  2462. // node.drawing_code, node.memo
  2463. // ]);
  2464. // const posRange = pos.getLedgerPos(node.id);
  2465. // if (posRange && posRange.length > 0) {
  2466. // for (const [i, p] of posRange.entries()) {
  2467. // data.push(['', '', (i + 1) + '', p.name, '',
  2468. // p.quantity, '', '', '', '',
  2469. // p.drawing_code, p.memo
  2470. // ]);
  2471. // }
  2472. // }
  2473. // }
  2474. //
  2475. // XLSXObj.exportXlsxSheet(setting, data, "台账分解.xlsx");
  2476. // });
  2477. $('#exportLedger').click(function () {
  2478. const data = [];
  2479. const setting = {
  2480. cols: [
  2481. {title: '项目节编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 100, formatter: '@'},
  2482. {title: '清单子目号', colSpan: '1', rowSpan: '1', field: 'b_code', hAlign: 0, width: 70, formatter: '@'},
  2483. {title: '部位明细', colSpan: '1', rowSpan: '1', field: 'pos_code', hAlign: 1, width: 70, formatter: '@'},
  2484. {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 300, formatter: '@'},
  2485. {title: '单位', colSpan: '1', rowSpan: '1', field: 'unit', hAlign: 1, width: 60, formatter: '@'},
  2486. {title: '清单数量', colSpan: '1', rowSpan: '1', field: 'quantity', hAlign: 2, width: 80, type: 'Number'},
  2487. {title: '设计数量1', colSpan: '1', rowSpan: '1', field: 'dgn_qty1', hAlign: 2, width: 80, type: 'Number'},
  2488. {title: '设计数量2', colSpan: '1', rowSpan: '1', field: 'dgn_qty2', hAlign: 2, width: 80, type: 'Number'},
  2489. {title: '单价', colSpan: '1', rowSpan: '1', field: 'unit_price', hAlign: 2, width: 80, type: 'Number'},
  2490. {title: '合价', colSpan: '1', rowSpan: '1', field: 'total_price', hAlign: 2, width: 80, type: 'Number'},
  2491. {title: '图号', colSpan: '1', rowSpan: '1', field: 'drawing_code', hAlign: 0, width: 100, formatter: '@'},
  2492. {title: '备注', colSpan: '1', rowSpan: '1', field: 'memo', hAlign: 0, width: 100, formatter: '@'},
  2493. ],
  2494. headRows: 1,
  2495. headRowHeight: [32],
  2496. defaultRowHeight: 21,
  2497. headerFont: 'bold 10px 微软雅黑',
  2498. font: '10px 微软雅黑'
  2499. };
  2500. for (const node of ledgerTree.nodes) {
  2501. data.push({
  2502. code: node.code, b_code: node.b_code, name: node.name, unit: node.unit,
  2503. unit_price: node.unit_price, quantity: node.quantity, total_price: node.total_price,
  2504. dgn_qty1: node.dgn_qty1, dgn_qty2: node.dgn_qty2,
  2505. drawing_code: node.drawing_code, memo: node.memo
  2506. });
  2507. const posRange = pos.getLedgerPos(node.id);
  2508. if (posRange && posRange.length > 0) {
  2509. for (const [i, p] of posRange.entries()) {
  2510. data.push({
  2511. pos_code: (i + 1) + '', name: p.name,
  2512. quantity: p.quantity, drawing_code: p.drawing_code, memo: p.memo
  2513. });
  2514. }
  2515. }
  2516. }
  2517. SpreadExcelObj.exportSimpleXlsxSheet(setting, data, "台账分解.xlsx");
  2518. });
  2519. });
  2520. // 检查上报情况
  2521. function checkAuditorFrom () {
  2522. if ($('#auditors li').length === 0) {
  2523. toastr.error('请先选择审批人,再上报数据');
  2524. return false;
  2525. }
  2526. $('#hide-all').show();
  2527. }