change_revise.js 117 KB

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