change_revise.js 116 KB

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