stage.js 168 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447
  1. 'use strict';
  2. /**
  3. * 期计量 - 本期计量台账页面 js
  4. *
  5. * @author Mai
  6. * @date 2018/12/7
  7. * @version
  8. */
  9. const ckBillsSpread = window.location.pathname + '-billsSelect';
  10. function checkTzMeasureType () {
  11. return tender.measure_type === measureType.tz.value;
  12. }
  13. function transExpr(expr) {
  14. return $.trim(expr).replace('\t', '').replace('=', '').replace('%', '/100');
  15. }
  16. function getExprInfo (field) {
  17. const exprField = [
  18. {qty: 'sgfh_qty', expr: 'sgfh_expr'},
  19. {qty: 'sjcl_qty', expr: 'sjcl_expr'},
  20. {qty: 'qtcl_qty', expr: 'qtcl_expr'},
  21. {qty: 'contract_qty', expr: 'contract_expr'},
  22. ];
  23. return _.find(exprField, {qty: field});
  24. }
  25. /**
  26. * 从cookie中读取缓存的列显示设置,没有则取默认
  27. * @returns {*[]}
  28. */
  29. function customColDisplay () {
  30. const defaultSetting = [
  31. { title: '签约合同', fields: ['deal_qty', 'deal_tp'], visible: true },
  32. { title: '本期计量合同', fields: ['contract_qty', 'contract_tp'], visible: true },
  33. { title: '本期数量变更', fields: ['qc_qty', 'qc_tp', 'qc_bgl'], visible: true },
  34. { title: '本期完成计量', fields: ['gather_qty', 'gather_tp'], visible: true },
  35. { title: '截止本期计量合同', fields: ['end_contract_qty', 'end_contract_tp'], visible: true },
  36. { title: '截止本期数量变更', fields: ['end_qc_qty', 'end_qc_tp', 'end_qc_bgl'], visible: true },
  37. { title: '截止本期完成计量', fields: ['end_gather_qty', 'end_gather_tp', 'end_gather_percent'], visible: true },
  38. { title: '本期批注', fields: ['postil'], visible: true },
  39. { title: '图册号', fields: ['drawing_code'], visible: true },
  40. { title: '备注', fields: ['memo'], visible: true },
  41. { title: '总额计量', fields: ['is_tp'], visible: true},
  42. ];
  43. if (checkTzMeasureType()) {
  44. defaultSetting.splice(0, 1);
  45. }
  46. const settingStr = Cookies.get(ckColSetting);
  47. return settingStr ? JSON.parse(settingStr) : defaultSetting;
  48. }
  49. /**
  50. * 根据列显示设置,调整setting中的列是否显示
  51. * @param setting
  52. * @param customDisplay
  53. */
  54. function customizeStageTreeSetting(setting, customDisplay) {
  55. for (const cd of customDisplay) {
  56. for (const c of setting.cols) {
  57. if (cd.fields.indexOf(c.field) !== -1) {
  58. c.visible = cd.visible;
  59. }
  60. }
  61. }
  62. }
  63. /**
  64. * 初始化 树结构 列事件
  65. * @param setting
  66. */
  67. function initTreeColSettingEvents(setting) {
  68. const Events = {
  69. readOnly: {
  70. measureData: function (node) {
  71. return node.children && node.children.length > 0;
  72. },
  73. },
  74. };
  75. const getEvent = function (eventName) {
  76. const names = eventName.split('.');
  77. let event = Events;
  78. for (let name of names) {
  79. if (event[name]) {
  80. event = event[name];
  81. } else {
  82. return null;
  83. }
  84. }
  85. if (event && Object.prototype.toString.apply(event) !== "[object Function]") {
  86. return null;
  87. } else {
  88. return event;
  89. }
  90. };
  91. for (const col of setting.cols) {
  92. if (col.readOnly && Object.prototype.toString.apply(col.readOnly) === "[object String]") {
  93. col.readOnly = getEvent(col.readOnly);
  94. }
  95. }
  96. }
  97. // 生成所有附件列表
  98. function getAllList(currPageNum = 1) {
  99. // 每页最多几个附件
  100. const pageCount = 11;
  101. // 附件总数
  102. const total = attData.length;
  103. // 总页数
  104. const pageNum = Math.ceil(total/pageCount);
  105. $('#totalPage').text(pageNum);
  106. $('#currentPage').text(total === 0 ? 0 : currPageNum);
  107. // 当前页附件内容
  108. const currPageAttData = attData.slice((currPageNum-1)*pageCount, currPageNum*pageCount);
  109. let html = '';
  110. for(const att of currPageAttData) {
  111. html += '<tr ><td><a href="javascript:void(0)" file-id="'+ att.id +'">'+ att.filename + att.fileext +'</a></td><td>'+ att.username +'</td></tr>';
  112. }
  113. $('#alllist-table').html(html);
  114. $('#alllist-table').on('click', 'tr', function() {
  115. $('#alllist-table tr').removeClass('bg-light')
  116. $(this).addClass('bg-light')
  117. })
  118. }
  119. // 生成当前节点列表
  120. function getNodeList(node) {
  121. let html = '';
  122. for(const att of attData) {
  123. if (node === att.lid) {
  124. html += '<tr><td><a href="javascript:void(0)" file-id="'+ att.id +'">'+ att.filename + att.fileext +'</a></td><td>'+ att.username +'</td></tr>';
  125. }
  126. }
  127. $('#nodelist-table').html(html);
  128. $('#nodelist-table').on('click', 'tr', function() {
  129. $('#nodelist-table tr').removeClass('bg-light')
  130. $(this).addClass('bg-light')
  131. })
  132. }
  133. function getGxbyText(data) {
  134. const def = thirdParty.gxby.find(function (x) {
  135. return x.value === data.gxby_status;
  136. });
  137. return def ? def.name : '';
  138. }
  139. function getDaglText(data) {
  140. const def = thirdParty.dagl.find(function (x) {
  141. return x.value === data.dagl_status;
  142. });
  143. return def ? def.name : '';
  144. }
  145. $(document).ready(() => {
  146. let detail, searchLedger, checkedChanges;
  147. // 界面布局
  148. autoFlashHeight();
  149. // 初始化 台账树结构 数据结构
  150. const stageTreeSetting = {
  151. id: 'ledger_id',
  152. pid: 'ledger_pid',
  153. order: 'order',
  154. level: 'level',
  155. rootId: -1,
  156. keys: ['id', 'tender_id', 'ledger_id'],
  157. stageId: 'id',
  158. };
  159. // 台账树结构计算相关设置
  160. stageTreeSetting.updateFields = ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'postil', 'used', 'contract_expr'];
  161. stageTreeSetting.calcFields = ['deal_tp', 'total_price', 'contract_tp', 'qc_tp', 'gather_tp',
  162. 'pre_contract_tp', 'pre_qc_tp', 'pre_gather_tp', 'end_contract_tp', 'end_qc_tp', 'end_gather_tp'];
  163. stageTreeSetting.calcFun = function (node) {
  164. if (node.children && node.children.length === 0) {
  165. node.pre_gather_qty = ZhCalc.add(node.pre_contract_qty, node.pre_qc_qty);
  166. node.gather_qty = ZhCalc.add(node.contract_qty, node.qc_qty);
  167. node.end_contract_qty = ZhCalc.add(node.pre_contract_qty, node.contract_qty);
  168. node.end_qc_qty = ZhCalc.add(node.pre_qc_qty, node.qc_qty);
  169. node.end_gather_qty = ZhCalc.add(node.pre_gather_qty, node.gather_qty);
  170. }
  171. node.pre_gather_tp = ZhCalc.add(node.pre_contract_tp, node.pre_qc_tp);
  172. node.gather_tp = ZhCalc.add(node.contract_tp, node.qc_tp);
  173. node.end_contract_tp = ZhCalc.add(node.pre_contract_tp, node.contract_tp);
  174. node.end_qc_tp = ZhCalc.add(node.pre_qc_tp, node.qc_tp);
  175. node.end_gather_tp = ZhCalc.add(node.pre_gather_tp, node.gather_tp);
  176. node.end_final_tp = ZhCalc.add(node.end_qc_tp, node.total_price);
  177. node.end_gather_percent = ZhCalc.mul(ZhCalc.div(node.end_gather_tp, node.end_final_tp), 100, 2);
  178. node.final_dgn_price = ZhCalc.round(ZhCalc.div(node.end_gather_tp, ZhCalc.add(node.deal_dgn_qty1, node.c_dgn_qty1)), tenderInfo.decimal.up);
  179. };
  180. const stageTree = createNewPathTree('stage', stageTreeSetting);
  181. // 初始化 计量单元 数据结构
  182. const stagePosSetting = {
  183. id: 'id', ledgerId: 'lid',
  184. updateFields: ['contract_qty', 'qc_qty', 'postil', 'contract_expr'],
  185. };
  186. stagePosSetting.calcFun = function (pos) {
  187. pos.pre_gather_qty = ZhCalc.add(pos.pre_contract_qty, pos.pre_qc_qty);
  188. pos.gather_qty = ZhCalc.add(pos.contract_qty, pos.qc_qty);
  189. pos.end_contract_qty = ZhCalc.add(pos.pre_contract_qty, pos.contract_qty);
  190. pos.end_qc_qty = ZhCalc.add(pos.pre_qc_qty, pos.qc_qty);
  191. pos.end_gather_qty = ZhCalc.add(pos.pre_gather_qty, pos.gather_qty);
  192. pos.sum = ZhCalc.add(pos.end_qc_qty, pos.quantity);
  193. pos.end_gather_percent = ZhCalc.mul(ZhCalc.div(pos.end_gather_qty, pos.sum), 100, 2);
  194. pos.estimate_qty = !checkZero(pos.real_qty)
  195. ? ZhCalc.sub(ZhCalc.sub(pos.real_qty, pos.quantity), pos.end_qc_qty)
  196. : null;
  197. };
  198. const stagePos = new StagePosData(stagePosSetting);
  199. class Changes {
  200. constructor(obj) {
  201. const self = this;
  202. this.obj = obj;
  203. // 初始化 清单编号窗口 参数
  204. this.spreadSetting = {
  205. cols: [
  206. {title: '已用', field: '', width: 45, formatter: '@', cellType: 'image', readOnly: true, hAlign: 1, indent: 14, img: function (data) {
  207. if (data.uamount && !checkZero(data.uamount)) {
  208. return $('#icon-ok')[0];
  209. } else {
  210. return null;
  211. }
  212. }},
  213. {title: '变更令号', field: 'p_code', width: 100, formatter: '@', readOnly: true, hAlign: 0, },
  214. {title: '名称', field: 'name', width: 120, formatter: '@', readOnly: true, hAlign: 0,},
  215. {title: '变更部位', field: 'b_bwmx', width: 100, formatter: '@', readOnly: true, hAlign: 0,},
  216. //{title: '总数量', field: 'b_amount', width: 60, readOnly: true, hAlign: 2, },
  217. {title: '可变更数量', field: 'vamount', width: 60, readOnly: true, hAlign: 2, type: 'Number', getValue: function (data) {return data.vamount ? data.vamount + '' : '0';}},
  218. {title: '本期计量', field: 'uamount', width: 60, hAlign: 2, type: 'Number', },
  219. ],
  220. emptyRows: 0,
  221. headRows: 1,
  222. headRowHeight: [32],
  223. headerFont: '12px 微软雅黑',
  224. font: '12px 微软雅黑',
  225. getColor: function (sheet, data, row, col, defaultColor) {
  226. if (col.field === 'uamount') {
  227. if (data.bamount > 0) {
  228. const usedAmount = ZhCalc.add(data.uamount, data.pre_amount);
  229. return usedAmount < 0 || usedAmount > data.bamount ? '#ff6f5c' : defaultColor;
  230. } else if (data.bamount < 0) {
  231. const usedAmount = ZhCalc.add(data.uamount, data.pre_amount);
  232. return usedAmount > 0 || usedAmount < data.bamount ? '#ff6f5c' : defaultColor;
  233. } else {
  234. return data.uamount ? '#ff6f5c' : defaultColor;
  235. }
  236. } else {
  237. return defaultColor;
  238. }
  239. }
  240. };
  241. this.curChangeId = '';
  242. this.spread = SpreadJsObj.createNewSpread($('#change-spread')[0]);
  243. this.firstView = true;
  244. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  245. // 初次显示,需刷新spread界面,保证界面绘制正确
  246. this.obj.bind('shown.bs.modal', function () {
  247. if (self.firstView) {
  248. self.firstView = false;
  249. self.spread.refresh();
  250. }
  251. });
  252. // 切换变更令,加载右侧明细数据
  253. this.spread.bind(spreadNS.Events.SelectionChanged, function (e, info) {
  254. const change = SpreadJsObj.getSelectObject(info.sheet);
  255. self._loadChangeDetail(change);
  256. });
  257. // 填写本期计量
  258. this.spread.bind(spreadNS.Events.EditEnded, function (e, info) {
  259. if (info.sheet.zh_setting) {
  260. const col = info.sheet.zh_setting.cols[info.col];
  261. const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
  262. const node = sortData[info.row];
  263. node[col.field] = col.type === 'Number' ? parseFloat(info.editingText) : info.editingText;
  264. // 刷新界面
  265. SpreadJsObj.reLoadRowData(info.sheet, info.row, 1);
  266. }
  267. });
  268. this.spread.bind(spreadNS.Events.ClipboardPasted, function (e, info) {
  269. if (info.sheet.zh_setting) {
  270. const sortData = SpreadJsObj.getSortData(info.sheet);
  271. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  272. const curRow = iRow + info.cellRange.row;
  273. const curCol = info.cellRange.col;
  274. const col = info.sheet.zh_setting.cols[info.cellRange.col];
  275. sortData[curRow][col.field] = col.type === 'Number' ? _.toNumber(info.sheet.getText(curRow, curCol)) : info.sheet.getText(curRow, curCol);
  276. }
  277. SpreadJsObj.reLoadRowData(sheet, info.cellRange.row, sel.cellRange.rowCount);
  278. }
  279. });
  280. SpreadJsObj.addDeleteBind(this.spread, function (sheet) {
  281. if (sheet.zh_setting) {
  282. const sel = sheet.getSelections()[0];
  283. const sortData = SpreadJsObj.getSortData(sheet);
  284. // 仅本期计量可删除
  285. if (sel.col === 5 && sel.colCount === 1) {
  286. const col = sheet.zh_setting.cols[sel.col];
  287. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  288. const data = sortData[iRow];
  289. data[col.field] = null;
  290. }
  291. SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
  292. }
  293. }
  294. });
  295. // 过滤可变更数量为0
  296. $('#filterEmpty').click(function () {
  297. self._filterChange(!this.checked, $('#matchPos')[0].checked);
  298. });
  299. // 匹配编号
  300. $('#matchPos').click(function () {
  301. self._filterChange(!$('#filterEmpty')[0].checked, this.checked);
  302. });
  303. // 展开收起 变更令详细信息
  304. $('#show-bgl-detail').bind('click', function () {
  305. const detail = $('#bgl-detail'), bgl=$('#bgl'), obj=$(this);
  306. if (detail.hasClass('col-4')) {
  307. detail.attr('class', 'col').hide();
  308. bgl.attr('class', 'col-12');
  309. $('a', obj).attr('title', '展开侧栏');
  310. $('i', obj).attr('class', 'fa fa-chevron-left');
  311. self.spread.refresh();
  312. } else {
  313. detail.attr('class', 'col-4').show();
  314. bgl.attr('class', 'col-8');
  315. $('a', obj).attr('title', '收起侧栏');
  316. $('i', obj).attr('class', 'fa fa-chevron-right');
  317. self.spread.refresh();
  318. }
  319. });
  320. // 添加调用变更令
  321. $('#usg-bg-ok').click(function () {
  322. const data = { target: self.callData, change: [] };
  323. for (const c of self.displayChanges) {
  324. if (c.uamount) {
  325. if (c.bamount > 0) {
  326. const usedAmount = ZhCalc.add(c.uamount, c.pre_amount);
  327. if (usedAmount < 0 || usedAmount > c.bamount) {
  328. toastr.error('变更令:' + c.code + ' 超计,请修改本期计量后,再提交');
  329. return;
  330. }
  331. } else if (c.bamount < 0) {
  332. const usedAmount = ZhCalc.add(c.uamount, c.pre_amount);
  333. if (usedAmount > 0 || usedAmount < c.bamount) {
  334. toastr.error('变更令:' + c.code + ' 超计,请修改本期计量后,再提交');
  335. return;
  336. }
  337. } else {
  338. toastr.error('变更令:' + c.code + ' 超计,请修改本期计量后,再提交');
  339. return;
  340. }
  341. data.change.push({ cid: c.cid, cbid: c.cbid, qty: c.uamount });
  342. }
  343. }
  344. // 提交数据到后端
  345. postData(window.location.pathname + '/use-change', data, function(result) {
  346. if (result.pos) {
  347. stagePos.loadCurStageData(result.pos.curStageData);
  348. }
  349. const nodes = stageTree.loadPostStageData(result.bills);
  350. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  351. stagePosSpreadObj.loadCurPosData();
  352. if (detail) {
  353. detail.loadStageChangeUpdateData(result);
  354. } else {
  355. stageIm.loadUpdateChangeData(result)
  356. }
  357. self.obj.modal('hide');
  358. });
  359. })
  360. }
  361. _calculateAmount() {
  362. for (const c of this.changes) {
  363. c.bamount = _.toNumber(c.b_amount);
  364. c.vamount = ZhCalc.sub(c.bamount, c.used_amount);
  365. const uc = _.find(this.useChanges, {cid: c.cid, cbid: c.cbid});
  366. if (uc) {
  367. c.org_uamount = uc.qty;
  368. c.uamount = uc.qty;
  369. c.vamount = ZhCalc.add(c.vamount, c.uamount);
  370. }
  371. c.pre_amount = ZhCalc.sub(c.used_amount, c.uamount);
  372. }
  373. }
  374. _loadChangeDetail(change) {
  375. if (change) {
  376. if (change.cid === this.curChangeId) { return; }
  377. this.curChangeId = change.cid;
  378. const inputs = $('input[type!=checkbox][type!=radio]', this.obj);
  379. for (const i of inputs) {
  380. const field = $(i).attr('name');
  381. const text = (field && change[field]) ? change[field] : '';
  382. $(i).val(text);
  383. }
  384. const textareas = $('textarea', this.obj);
  385. for (const ta of textareas) {
  386. const field = $(ta).attr('name');
  387. const text = (field && change[field]) ? change[field] : '';
  388. ta.textContent = text;
  389. }
  390. const html = [];
  391. for (const a of change.attachments) {
  392. html.push('<tr>');
  393. html.push('<td>', '<a href="/change/download/file/' + a.id + '">', a.filename + a.fileext, '</a>', '</td>');
  394. html.push('<td>', a.u_name, '</td>');
  395. html.push('</tr>');
  396. }
  397. // 变更类型
  398. if (change.type) {
  399. const cType = change.type.split(',');
  400. $('input[name="type"]').prop("checked", false);
  401. for (const c of cType) {
  402. $('input[name="type"][value='+ c +']').prop("checked", true);
  403. }
  404. }
  405. // 变更类别
  406. $('select[name=class]').val(change.class);
  407. // 变更性质
  408. $('select[name=quality]').val(change.quality);
  409. // 变更单位
  410. $('select[name=company]').html('<option>' + (change.company ? change.company : '') + '</option>');
  411. // 费用承担方
  412. $('input[name=charge][value=' + change.charge + ']').prop('checked', true);
  413. // 附件
  414. $('#attachment').html(html.join(''));
  415. } else {
  416. const inputs = $('input', this.obj);
  417. for (const i of inputs) {
  418. $(i).val('');
  419. }
  420. const textareas = $('textarea', this.obj);
  421. for (const ta of textareas) {
  422. ta.innerText = '';
  423. }
  424. $('#attachment').html('');
  425. }
  426. }
  427. _viewChanges() {
  428. const sheet = this.spread.getActiveSheet();
  429. if (this.changes) {
  430. sheet.setSelection(0, 0, 1, 1);
  431. this._filterChange(!$('#filterEmpty')[0].checked, $('#matchPos')[0].checked);
  432. this._loadChangeDetail(this.changes[0]);
  433. } else {
  434. toastr.error('查询变更令有误,请刷新页面后重试');
  435. }
  436. }
  437. _filterChange(filterEmpty, matchPosName) {
  438. this.displayChanges = [];
  439. for (const c of this.changes) {
  440. const filterVisible = filterEmpty ? (c.vamount ? !checkZero(c.vamount) : false) : true;
  441. const matchVisible = matchPosName && this.callData.pos ? c.b_bwmx === this.callData.pos.name : true;
  442. if ((filterVisible && matchVisible) || (c.org_uamount)) {
  443. this.displayChanges.push(c);
  444. }
  445. }
  446. SpreadJsObj.loadSheetData(this.spread.getActiveSheet(), SpreadJsObj.DataType.Data, this.displayChanges);
  447. }
  448. loadChanges(data) {
  449. this.callData = data;
  450. if (this.callData.pos) {
  451. $('#matchPos').parent().show();
  452. } else {
  453. $('#matchPos').parent().hide();
  454. }
  455. const self = this;
  456. $('#b-code-hint').text('当前变更清单:' + data.bills.b_code);
  457. postData(window.location.pathname + '/valid-change', data, function (result) {
  458. self.changes = result.changes;
  459. self.useChanges = result.useChanges;
  460. self._calculateAmount();
  461. self._viewChanges();
  462. self.obj.modal('show');
  463. });
  464. }
  465. }
  466. const changesObj = new Changes($('#use-bg'));
  467. // 初始化 台账 spread
  468. const slSpread = SpreadJsObj.createNewSpread($('#stage-ledger')[0]);
  469. customizeStageTreeSetting(ledgerSpreadSetting, customColDisplay());
  470. // 数量变更列,添加按钮
  471. const col = _.find(ledgerSpreadSetting.cols, {field: 'qc_qty'});
  472. col.readOnly = true;
  473. col.cellType = 'activeImageBtn';
  474. col.normalImg = '#ellipsis-icon';
  475. col.indent = 5;
  476. col.showImage = function (data) {
  477. if (!data || (data.children && data.children.length > 0) || !(data.b_code && data.b_code !== '')) {
  478. return false;
  479. } else {
  480. const nodePos = stagePos.getLedgerPos(data.id);
  481. return !(nodePos && nodePos.length > 0);
  482. }
  483. };
  484. ledgerSpreadSetting.imageClick = function (data) {
  485. if (data.children && data.children.length > 0) return;
  486. const nodePos = stagePos.getLedgerPos(data.id);
  487. if (nodePos && nodePos.length > 0) return;
  488. changesObj.loadChanges({bills: data});
  489. };
  490. ledgerSpreadSetting.dgnUpFields = ['deal_dgn_qty1', 'deal_dgn_qty2', 'c_dgn_qty1', 'c_dgn_qty2'];
  491. ledgerSpreadSetting.getColor = function (sheet, data, row, col, defaultColor) {
  492. if (data) {
  493. if (col.field === 'gxby') {
  494. const def = thirdParty.gxby.find(function (x) {
  495. return x.value === data.gxby_status;
  496. });
  497. if (def && def.color) return def.color;
  498. } else if (col.field === 'dagl') {
  499. const def = thirdParty.dagl.find(function (x) {
  500. return x.value === data.dagl_status;
  501. });
  502. if (def && def.color) return def.color;
  503. }
  504. const posRange = stagePos.ledgerPos[itemsPre + data.id] || [];
  505. if (posRange.length > 0) {
  506. for (const p of posRange) {
  507. if (p.end_contract_qty > p.quantity) return '#f8d7da';
  508. }
  509. }
  510. if (data.is_tp) {
  511. return data.end_contract_tp > data.total_price ? '#f8d7da' : defaultColor;
  512. } else {
  513. return data.end_contract_qty > data.quantity ? '#f8d7da' : defaultColor;
  514. }
  515. } else {
  516. return defaultColor;
  517. }
  518. };
  519. sjsSettingObj.setFxTreeStyle(ledgerSpreadSetting, sjsSettingObj.FxTreeStyle.jz);
  520. sjsSettingObj.setPropValue(ledgerSpreadSetting, ['gxby'], 'getValue', getGxbyText);
  521. sjsSettingObj.setPropValue(ledgerSpreadSetting, ['dagl'], 'getValue', getDaglText);
  522. if (thousandth) sjsSettingObj.setTpThousandthFormat(ledgerSpreadSetting);
  523. SpreadJsObj.initSheet(slSpread.getActiveSheet(), ledgerSpreadSetting);
  524. slSpread.getActiveSheet().frozenColumnCount(5);
  525. slSpread.getActiveSheet().options.frozenlineColor = '#93b5e4';
  526. //初始化所有附件列表
  527. getAllList();
  528. // 初始化 计量单元 Spread
  529. const spSpread = SpreadJsObj.createNewSpread($('#stage-pos')[0]);
  530. const spCol = _.find(posSpreadSetting.cols, {field: 'qc_qty'});
  531. spCol.readOnly = true;
  532. spCol.cellType = 'activeImageBtn';
  533. spCol.normalImg = '#ellipsis-icon';
  534. spCol.indent = 5;
  535. spCol.showImage = function (data) {
  536. return data !== undefined && data !== null;
  537. };
  538. posSpreadSetting.imageClick = function (data) {
  539. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  540. changesObj.loadChanges({bills: node, pos: data});
  541. };
  542. posSpreadSetting.getColor = function (sheet, data, row, col, defaultColor) {
  543. if (data) {
  544. if (col.field === 'gxby') {
  545. const def = thirdParty.gxby.find(function (x) {
  546. return x.value === data.gxby_status;
  547. });
  548. if (def && def.color) return def.color;
  549. } else if (col.field === 'dagl') {
  550. const def = thirdParty.dagl.find(function (x) {
  551. return x.value === data.dagl_status;
  552. });
  553. if (def && def.color) return def.color;
  554. }
  555. }
  556. return data && data.end_contract_qty > data.quantity ? '#f8d7da' : defaultColor;
  557. };
  558. sjsSettingObj.setGridSelectStyle(posSpreadSetting);
  559. if (thousandth) sjsSettingObj.setTpThousandthFormat(posSpreadSetting);
  560. sjsSettingObj.setPropValue(posSpreadSetting, ['gxby'], 'getValue', getGxbyText);
  561. sjsSettingObj.setPropValue(posSpreadSetting, ['dagl'], 'getValue', getDaglText);
  562. SpreadJsObj.initSheet(spSpread.getActiveSheet(), posSpreadSetting);
  563. const errorList = $.cs_errorList({
  564. tabSelector: '#error-list-tab',
  565. selector: '#error-list',
  566. relaSpread: slSpread,
  567. storeKey: 'stage-error-' + stage.id,
  568. afterLocated: function () {
  569. stagePosSpreadObj.loadCurPosData();
  570. },
  571. afterShow: function () {
  572. slSpread.refresh();
  573. if (spSpread) spSpread.refresh();
  574. },
  575. });
  576. const stageTreeSpreadObj = {
  577. loadExprToInput(sheet) {
  578. const sel = sheet.getSelections()[0];
  579. const col = sheet.zh_setting.cols[sel.col], cell = sheet.getCell(sel.row, sel.col);
  580. if (col.type === 'Number') {
  581. const data = SpreadJsObj.getSelectObject(sheet);
  582. if (!data) {
  583. $('#bills-expr').val('').attr('readOnly', true);
  584. $('#bills-expr').removeAttr('data-row');
  585. return;
  586. }
  587. const nodePos = stagePos.getLedgerPos(data.id);
  588. if (nodePos && nodePos.length > 0) {
  589. $('#bills-expr').val('').attr('readOnly', true);
  590. } else {
  591. const exprInfo = getExprInfo(col.field);
  592. const value = exprInfo && data[exprInfo.expr] ? data[exprInfo.expr] : data[col.field];
  593. $('#bills-expr').val(value).attr('field', col.field).attr('org', data[col.field]);
  594. if (col.field.indexOf('tp') >= 0) {
  595. $('#bills-expr').attr('readOnly', readOnly || cell.locked() || data.is_tp !== 1);
  596. } else {
  597. $('#bills-expr').attr('readOnly', readOnly || cell.locked() || data.is_tp === 1)
  598. }
  599. }
  600. $('#bills-expr').attr('data-row', sel.row);
  601. } else {
  602. $('#bills-expr').val('').attr('readOnly', true);
  603. $('#bills-expr').removeAttr('data-row');
  604. }
  605. },
  606. refreshTreeNodes: function (sheet, nodes) {
  607. const tree = sheet.zh_tree;
  608. if (!tree) { return }
  609. const rows = [];
  610. for (const node of nodes) {
  611. rows.push(tree.nodes.indexOf(node));
  612. }
  613. SpreadJsObj.reLoadRowsData(sheet, rows);
  614. },
  615. editEnded: function (e, info) {
  616. if (info.sheet.zh_setting) {
  617. const col = info.sheet.zh_setting.cols[info.col];
  618. const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
  619. const node = sortData[info.row], updateData = {};
  620. const orgValue = node[col.field];
  621. let newValue = trimInvalidChar(info.editingText);
  622. if (orgValue == newValue || ((!orgValue || orgValue === '') && (!newValue || newValue === ''))) {
  623. return;
  624. }
  625. if (col.type === 'Number' && newValue && newValue !== '') {
  626. const num = _.toNumber(newValue);
  627. if (_.isFinite(num)) {
  628. newValue = num;
  629. } else {
  630. try {
  631. newValue = math.evaluate(transExpr(newValue));
  632. } catch(err) {
  633. toastr.error('输入的表达式非法');
  634. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  635. return;
  636. }
  637. }
  638. }
  639. if (col.field.indexOf('_dgn_') > 0) {
  640. if (node.b_code && node.b_code !== '') {
  641. toastr.error('仅项目节可输入项目节数量');
  642. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  643. return;
  644. }
  645. } else if (col.field !== 'postil' && col.field !== 'memo') {
  646. if (node.children && node.children.length > 0) {
  647. toastr.error('清单父项不可计量');
  648. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  649. return;
  650. } else {
  651. const nodePos = stagePos.getLedgerPos(node.id);
  652. if (nodePos && nodePos.length > 0) {
  653. toastr.error('该清单有计量单元,请在计量单元处计量');
  654. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  655. return;
  656. }
  657. }
  658. }
  659. if (col.field === 'memo') {
  660. updateData.main = {
  661. id: node.id
  662. };
  663. updateData.main[col.field] = newValue;
  664. } else if (col.field.indexOf('_dgn_') > 0) {
  665. updateData.dgn = {
  666. id: node.id
  667. };
  668. updateData.dgn[col.field] = newValue;
  669. } else if (col.field !== 'is_tp') {
  670. updateData.stage = {
  671. lid: node.id
  672. };
  673. updateData.stage[col.field] = newValue;
  674. const exprInfo = getExprInfo(col.field);
  675. if (exprInfo) {
  676. updateData.stage[exprInfo.expr] = info.editingText !== newValue+ '' ? trimInvalidChar(info.editingText) : '';
  677. }
  678. }
  679. postData(window.location.href + '/update', {bills: updateData}, function (data) {
  680. // tag update
  681. const nodes = stageTree.loadPostStageData(data);
  682. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  683. if (detail) {
  684. detail.loadStageLedgerUpdateData(data);
  685. } else {
  686. stageIm.loadUpdateLedgerData(data);
  687. }
  688. }, function () {
  689. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  690. });
  691. }
  692. },
  693. selectionChanged: function (e, info) {
  694. if (!info.oldSelections || !info.oldSelections[0] || info.newSelections[0].row !== info.oldSelections[0].row) {
  695. SpreadJsObj.resetTopAndSelect(spSpread.getActiveSheet());
  696. stagePosSpreadObj.loadCurPosData();
  697. if (posSearch) {
  698. posSearch.search();
  699. }
  700. }
  701. SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
  702. stageTreeSpreadObj.loadExprToInput(info.sheet);
  703. },
  704. deletePress(sheet) {
  705. if (sheet.zh_setting && sheet.zh_dataType === 'tree') {
  706. const tree = sheet.zh_tree;
  707. if (!tree) { return; }
  708. const sel = sheet.getSelections()[0];
  709. const validCols = [];
  710. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  711. const colSetting = sheet.zh_setting.cols[iCol];
  712. if (!colSetting.readOnly && colSetting.field !== 'qc_qty') {
  713. validCols.push(iCol);
  714. }
  715. }
  716. if (validCols.length === 0) { return; }
  717. const sortData = sheet.zh_tree.nodes;
  718. const datas = [], dgnDatas = [], mainDatas = [];
  719. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  720. const node = sortData[iRow];
  721. if (node) {
  722. const data = { lid: node.id }, dgnData = { id: node.id }, mainData = { id: node.id };
  723. let filter = true, filterDgn = true, filterMain = true;
  724. for (const iCol of validCols) {
  725. const colSetting = sheet.zh_setting.cols[iCol];
  726. if (sheet.zh_setting.dgnUpFields.indexOf(colSetting.field) !== -1) {
  727. if (node.b_code && node.b_code !== '') continue;
  728. } else if (colSetting.field !== 'postil') {
  729. if (node.children && node.children.length > 0) { continue; }
  730. const nodePos = stagePos.getLedgerPos(node.id);
  731. if (nodePos && nodePos.length > 0) { continue; }
  732. }
  733. if (sheet.zh_setting.dgnUpFields.indexOf(colSetting.field) !== -1) {
  734. if (node[colSetting.field] && node[colSetting.field] !== 0) {
  735. dgnData[colSetting.field] = 0;
  736. filterDgn = false;
  737. }
  738. } else if (colSetting.field === 'memo') {
  739. mainData[colSetting.field] = null;
  740. filterMain = false;
  741. } else {
  742. data[colSetting.field] = null;
  743. const exprInfo = getExprInfo(colSetting.field);
  744. if (exprInfo) {
  745. data[exprInfo.expr] = '';
  746. }
  747. filter = false;
  748. }
  749. }
  750. if (!filter) datas.push(data);
  751. if (!filterDgn) dgnDatas.push(dgnData);
  752. if (!filterMain) mainDatas.push(mainData);
  753. }
  754. }
  755. if (datas.length > 0 || dgnDatas.length > 0 || mainDatas.length > 0) {
  756. const bills = {};
  757. if (datas.length > 0) bills.stage = datas;
  758. if (dgnDatas.length > 0) bills.dgn = dgnDatas;
  759. if (mainDatas.length > 0) bills.main = mainDatas;
  760. postData(window.location.href + '/update', {bills: bills}, function (result) {
  761. const nodes = stageTree.loadPostStageData(result);
  762. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  763. if (detail) {
  764. detail.loadStageLedgerUpdateData(result);
  765. } else {
  766. stageIm.loadUpdateLedgerData(result);
  767. }
  768. stageTreeSpreadObj.loadExprToInput(sheet);
  769. });
  770. }
  771. }
  772. },
  773. clipboardPasting(e, info) {
  774. if (info.sheet.zh_setting) {
  775. const setting = info.sheet.zh_setting;
  776. const range = info.cellRange;
  777. const stageField = ['contract_qty', 'contract_tp', 'qc_qty', 'postil'];
  778. for (let iCol = range.col; iCol < range.col + range.colCount; iCol++) {
  779. const col = info.sheet.zh_setting.cols[iCol];
  780. if ((stageField.indexOf(col.field) === -1) && setting.dgnUpFields.indexOf(col.field) === -1
  781. && col.field !== 'memo') {
  782. toastr.error('不可修改此数据');
  783. info.cancel = true;
  784. return;
  785. }
  786. }
  787. }
  788. },
  789. clipboardPasted(e, info) {
  790. if (info.sheet.zh_setting && info.sheet.zh_tree) {
  791. const sheet = info.sheet, setting = info.sheet.zh_setting;
  792. const filterNodes = [], datas = [], dgnDatas = [], mainDatas = [];
  793. let bHint = false;
  794. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  795. const curRow = iRow + info.cellRange.row;
  796. const node = sheet.zh_tree.getItemsByIndex(curRow);
  797. const data = {lid: node.id}, dgnData = {id: node.id}, mainData = {id: node.id};
  798. let filter = true, filterDgn = true, filterMain = true;
  799. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  800. const curCol = info.cellRange.col + iCol;
  801. const col = info.sheet.zh_setting.cols[curCol];
  802. if (col.field === 'contract_tp') {
  803. if (!node.is_tp) continue;
  804. } else if (col.field === 'contract_qty') {
  805. if (node.is_tp) continue;
  806. }
  807. if (setting.dgnUpFields.indexOf(col.field) !== -1) {
  808. if (node.b_code && node.b_code !== '') continue;
  809. } else if (col.field !== 'postil') {
  810. if (node.children && node.children.length > 0) continue;
  811. const nodePos = stagePos.getLedgerPos(node.id);
  812. if (nodePos && nodePos.length > 0) continue;
  813. }
  814. const text = trimInvalidChar(sheet.getText(curRow, curCol));
  815. if (setting.dgnUpFields.indexOf(col.field) !== -1) {
  816. const num = _.toNumber(text);
  817. if (num) {
  818. dgnData[col.field] = num;
  819. filterDgn = false;
  820. } else {
  821. try {
  822. dgnData[col.field] = math.evaluate(transExpr(text));
  823. filterDgn = false;
  824. } catch(err) {
  825. if (!bHint) {
  826. toastr.warning('粘贴了非法表达式,已过滤');
  827. bHint = true;
  828. }
  829. }
  830. }
  831. } else if (col.field === 'memo') {
  832. mainData.memo = text;
  833. filterMain = false;
  834. } else {
  835. if (col.type === 'Number') {
  836. const num = _.toNumber(text);
  837. if (_.isFinite(num)) {
  838. data[col.field] = num;
  839. filter = false;
  840. } else {
  841. try {
  842. data[col.field] = math.evaluate(transExpr(text));
  843. const exprInfo = getExprInfo(col.field);
  844. if (exprInfo) {
  845. data[exprInfo.expr] = text;
  846. }
  847. filter = false;
  848. } catch(err) {
  849. if (!bHint) {
  850. toastr.warning('粘贴了非法表达式,已过滤');
  851. bHint = true;
  852. }
  853. }
  854. }
  855. } else {
  856. data[col.field] = text;
  857. }
  858. }
  859. }
  860. if (filter && filterDgn && filterMain) {
  861. filterNodes.push(node);
  862. } else {
  863. if (!filter) datas.push(data);
  864. if (!filterDgn) dgnDatas.push(dgnData);
  865. if (!filterMain) mainDatas.push(mainData);
  866. }
  867. }
  868. if (datas.length > 0 || dgnDatas.length > 0 || mainDatas.length > 0) {
  869. const updateData = {};
  870. if (datas.length > 0) updateData.stage = datas;
  871. if (dgnDatas.length > 0) updateData.dgn = dgnDatas;
  872. if (mainDatas.length > 0) updateData.main = mainDatas;
  873. postData(window.location.href + '/update', {bills: updateData}, function (data) {
  874. const nodes = stageTree.loadPostStageData(data);
  875. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes.concat(filterNodes));
  876. if (detail) {
  877. detail.loadStageLedgerUpdateData(data);
  878. } else {
  879. stageIm.loadUpdateLedgerData(data);
  880. }
  881. stageTreeSpreadObj.loadExprToInput(sheet);
  882. }, function () {
  883. // todo
  884. //stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), filterNodes);
  885. });
  886. } else {
  887. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), filterNodes);
  888. }
  889. }
  890. },
  891. measureAllPosInNode(node, ratio = 1) {
  892. const posterity = stageTree.getPosterity(node)
  893. const data = {updateType: 'update', updateData: []};
  894. for (const p of posterity) {
  895. if (p.children && p.children.length > 0) continue;
  896. const posRange = stagePos.getLedgerPos(p.id);
  897. if (posRange && posRange.length > 0) {
  898. for (const pr of posRange) {
  899. if (pr.contract_qty && !checkZero(pr.contract_qty)) continue;
  900. const validValue = ZhCalc.sub(pr.quantity, pr.end_contract_qty);
  901. if (validValue <= 0) continue;
  902. const value = ratio !== 1 ? ZhCalc.mul(pr.quantity, ratio) : pr.quantity;
  903. const pData = {
  904. pid: pr.id,
  905. lid: pr.lid,
  906. contract_qty: validValue > 0 ? (value > validValue ? validValue : value) : (value < validValue ? validValue : value),
  907. };
  908. data.updateData.push(pData);
  909. }
  910. }
  911. if (data.updateData.length > 1000 || _.map(data.updateData, 'lid').length > 500) {
  912. toastr.warning('选中的数据过多,仅计量' + data.updateData.length + '条,请稍后');
  913. break;
  914. }
  915. }
  916. if (data.updateData.length === 0) {
  917. toastr.info('其下全部计量单元均已计量');
  918. return;
  919. }
  920. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  921. if (result.pos) {
  922. stagePos.updateDatas(result.pos.pos);
  923. stagePos.loadCurStageData(result.pos.curStageData);
  924. }
  925. const nodes = stageTree.loadPostStageData(result.ledger);
  926. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  927. stagePosSpreadObj.loadCurPosData();
  928. if (detail) {
  929. detail.loadStagePosUpdateData(result);
  930. } else {
  931. stageIm.loadUpdatePosData(result);
  932. }
  933. toastr.success('已计量' + data.updateData.length + '条');
  934. }, function () {
  935. stagePosSpreadObj.loadCurPosData();
  936. });
  937. },
  938. topRowChanged(e, info) {
  939. SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
  940. },
  941. editStarting(e, info) {
  942. if (!info.sheet.zh_setting || !info.sheet.zh_tree) return;
  943. const col = info.sheet.zh_setting.cols[info.col];
  944. const node = info.sheet.zh_tree.nodes[info.row];
  945. const exprInfo = getExprInfo(col.field);
  946. if (exprInfo) {
  947. if (node[exprInfo.expr] && node[exprInfo.expr] !== '') {
  948. info.sheet.getCell(info.row, info.col).text(node[exprInfo.expr]);
  949. }
  950. }
  951. switch (col.field) {
  952. case 'contract_qty':
  953. case 'qc_qty':
  954. info.cancel = node.is_tp;
  955. break;
  956. case 'contract_tp':
  957. info.cancel = !node.is_tp;
  958. break;
  959. case 'is_tp':
  960. info.cancel = true;
  961. break;
  962. }
  963. },
  964. buttonClicked: function (e, info) {
  965. if (info.sheet.zh_setting) {
  966. const node = SpreadJsObj.getSelectObject(info.sheet);
  967. const col = info.sheet.zh_setting.cols[info.col];
  968. const posRange = stagePos.getLedgerPos(node.id);
  969. if (node.pre_used === 1 ||
  970. (node.children && node.children.length > 0) ||
  971. (node.unit !== '总额' && node.unit !== '元') ||
  972. (posRange && posRange.length > 0) /*|| !checkZero(node.qc_qty)*/) {
  973. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  974. return;
  975. }
  976. const postIsTp = function () {
  977. const data = { calcType: {id: node.id} };
  978. data.calcType.is_tp = info.sheet.getValue(info.row, info.col) || false;
  979. // 更新至服务器
  980. postData(window.location.pathname + '/update', {bills: data}, function (result) {
  981. const nodes = stageTree.loadPostStageData(result);
  982. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  983. if (detail) {
  984. detail.loadStageLedgerUpdateData(result);
  985. } else {
  986. stageIm.loadUpdateLedgerData(result);
  987. }
  988. });
  989. };
  990. if (col.field === 'is_tp') {
  991. if (info.sheet.isEditing()) {
  992. info.sheet.endEdit(true);
  993. }
  994. if (!checkZero(node.contract_qty) || !checkZero(node.contract_tp)) {
  995. $.msgBox({
  996. id: 'calc-type',
  997. title: '提示',
  998. message: '切换计量模式,已计量数据会被清空。',
  999. ok: {
  1000. caption: '确定',
  1001. callback: postIsTp,
  1002. },
  1003. cancel: {
  1004. caption: '取消',
  1005. callback: function () {
  1006. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1007. }
  1008. }
  1009. });
  1010. } else {
  1011. postIsTp();
  1012. }
  1013. }
  1014. }
  1015. },
  1016. };
  1017. slSpread.bind(spreadNS.Events.EditEnded, stageTreeSpreadObj.editEnded);
  1018. slSpread.bind(spreadNS.Events.SelectionChanged, stageTreeSpreadObj.selectionChanged);
  1019. slSpread.bind(spreadNS.Events.ClipboardPasting, stageTreeSpreadObj.clipboardPasting);
  1020. slSpread.bind(spreadNS.Events.ClipboardPasted, stageTreeSpreadObj.clipboardPasted);
  1021. slSpread.bind(spreadNS.Events.TopRowChanged, stageTreeSpreadObj.topRowChanged);
  1022. slSpread.bind(spreadNS.Events.EditStarting, stageTreeSpreadObj.editStarting);
  1023. slSpread.bind(spreadNS.Events.ButtonClicked, stageTreeSpreadObj.buttonClicked);
  1024. SpreadJsObj.addDeleteBind(slSpread, stageTreeSpreadObj.deletePress);
  1025. if (!readOnly) {
  1026. $('#bills-expr').bind('change onblur', function () {
  1027. if (this.readOnly) return;
  1028. const expr = $(this);
  1029. const row = expr.attr('data-row') ? _.toInteger(expr.attr('data-row')) : -1;
  1030. const select = stageTree.getItemsByIndex(row);
  1031. if (!select) return;
  1032. const field = expr.attr('field'), orgValue = expr.attr('org'), updateData = {};
  1033. let newValue = expr.val();
  1034. const num = _.toNumber(newValue);
  1035. if (_.isFinite(num)) {
  1036. newValue = num;
  1037. } else {
  1038. try {
  1039. newValue = math.evaluate(transExpr(newValue));
  1040. } catch(err) {
  1041. toastr.error('输入的表达式非法');
  1042. return;
  1043. }
  1044. }
  1045. if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
  1046. if (field.indexOf('_dgn_') > 0) {
  1047. updateData.dgn = {
  1048. id: select.id
  1049. };
  1050. updateData.dgn[field] = newValue;
  1051. } else {
  1052. updateData.stage = {
  1053. lid: select.id
  1054. };
  1055. updateData.stage[field] = newValue;
  1056. const exprInfo = getExprInfo(field);
  1057. if (exprInfo) {
  1058. updateData.stage[exprInfo.expr] = expr.val();
  1059. }
  1060. }
  1061. // 更新至服务器
  1062. postData(window.location.pathname + '/update', {bills: updateData}, function (result) {
  1063. const nodes = stageTree.loadPostStageData(result);
  1064. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1065. });
  1066. });
  1067. }
  1068. stageTreeSpreadObj.loadExprToInput(slSpread.getActiveSheet());
  1069. $.contextMenu({
  1070. selector: '#stage-ledger',
  1071. build: function ($trigger, e) {
  1072. const target = SpreadJsObj.safeRightClickSelection($trigger, e, slSpread);
  1073. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  1074. },
  1075. items: {
  1076. 'locateZjjl': {
  1077. name: '定位至中间计量',
  1078. icon: 'fa-sign-in',
  1079. callback: function (key, opt) {
  1080. if (!detail) {
  1081. detail = new Detail($('#detail-spread'));
  1082. }
  1083. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1084. const [leafUsedBills, usedPos] = stageIm.getFirstUsed(node);
  1085. if (leafUsedBills) {
  1086. if (!$('#zhongjian').hasClass('active')) {
  1087. const tab = $('#zhongjian'), tabPanel = $(tab.attr('content'));
  1088. $('a', '.side-menu').removeClass('active');
  1089. $('.tab-content .tab-select-show').removeClass('active');
  1090. tab.addClass('active');
  1091. tabPanel.addClass('active');
  1092. showSideTools(tab.hasClass('active'));
  1093. slSpread.refresh();
  1094. spSpread.refresh();
  1095. }
  1096. const relaXmj = stageIm.getRelaXmj(leafUsedBills);
  1097. const im = stageIm.getRelaImData(relaXmj, leafUsedBills, usedPos);
  1098. SpreadJsObj.locateData(detail.sheet, im);
  1099. detail.spread.refresh();
  1100. $('#zhongjian .sjs-bottom').height('400px');
  1101. $('.zhongjian-msg').height($('#zhongjian .sjs-bottom').height());
  1102. detail.reLoadDetailData();
  1103. } else {
  1104. toastr.error('无可定位中间计量');
  1105. }
  1106. },
  1107. },
  1108. }
  1109. });
  1110. const stagePosSpreadObj = {
  1111. loadExprToInput(sheet) {
  1112. const sel = sheet.getSelections()[0];
  1113. if (!sel) return;
  1114. const col = sheet.zh_setting.cols[sel.col], cell = sheet.getCell(sel.row, sel.col);
  1115. if (col && col.type === 'Number') {
  1116. const data = SpreadJsObj.getSelectObject(sheet);
  1117. if (data) {
  1118. const exprInfo = getExprInfo(col.field);
  1119. const value = exprInfo && data[exprInfo.expr] ? data[exprInfo.expr] : data[col.field];
  1120. $('#pos-expr').val(value).attr('field', col.field).attr('org', data[col.field])
  1121. .attr('readOnly', readOnly || cell.locked());
  1122. $('#pos-expr').attr('data-row', sel.row);
  1123. } else {
  1124. $('#pos-expr').val('').attr('readOnly', true);
  1125. $('#pos-expr').removeAttr('data-row');
  1126. }
  1127. } else {
  1128. $('#pos-expr').val('').attr('readOnly', true);
  1129. $('#pos-expr').removeAttr('data-row');
  1130. }
  1131. },
  1132. /**
  1133. * 加载计量单元 根据当前台账选择节点
  1134. */
  1135. loadCurPosData: function () {
  1136. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1137. if (node) {
  1138. const posData = stagePos.ledgerPos[itemsPre + node.id] || [];
  1139. SpreadJsObj.loadSheetData(spSpread.getActiveSheet(), 'data', posData);
  1140. getNodeList(node.id);
  1141. // 如果是附件是当前节点,隐藏
  1142. // if ($('#dqjiedian').hasClass('active')) {
  1143. // $('#showAttachment').hide();
  1144. // }
  1145. } else {
  1146. SpreadJsObj.loadSheetData(spSpread.getActiveSheet(), 'data', []);
  1147. }
  1148. stagePosSpreadObj.loadExprToInput(spSpread.getActiveSheet());
  1149. },
  1150. editEnded: function (e, info) {
  1151. if (info.sheet.zh_setting) {
  1152. // 未改变过,则直接跳过
  1153. const sortData = info.sheet.zh_data;
  1154. const posData = sortData ? sortData[info.row] : null;
  1155. const col = info.sheet.zh_setting.cols[info.col];
  1156. const orgText = posData ? posData[col.field] : null;
  1157. const newText = trimInvalidChar(info.editingText);
  1158. if (orgText === info.editingText || ((!orgText || orgText === '') && (newText === ''))) {
  1159. return;
  1160. }
  1161. // 台账模式下,不可新增
  1162. if (checkTzMeasureType() && !posData) {
  1163. toastr.error('台账模式不可新增计量单元数据');
  1164. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1165. return ;
  1166. }
  1167. // 不同节点下,计量单元检查输入
  1168. //const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1169. const node = stagePosSpreadObj.stageTreeNode;
  1170. if (!node) {
  1171. toastr.warning('数据错误, 请刷新页面后再试');
  1172. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1173. return;
  1174. } else if (newText !== '' && node.children && node.children > 0) {
  1175. toastr.error('父节点不可插入计量单元');
  1176. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1177. return;
  1178. } else if (newText !== '' && !node.b_code || node.b_code === '') {
  1179. toastr.error('项目节不可插入计量单元');
  1180. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1181. return;
  1182. }
  1183. // 生成提交数据
  1184. const data = {};
  1185. if (col.field === 'name') {
  1186. if ((!newText || newText === '') && posData) {
  1187. toastr.error('部位名称不可为空');
  1188. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1189. return;
  1190. } else if (!posData) {
  1191. if (newText !== '') {
  1192. data.updateType = 'add';
  1193. if ((node.pre_used === 1 || !checkZero(node.gather_qty) || !checkZero(node.gather_tp)) && sortData.length === 0) {
  1194. toastr.error('无计量单元的清单,计量后,不可新增计量单元');
  1195. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1196. return;
  1197. }
  1198. const order = (!sortData || sortData.length === 0) ? 1 : Math.max(sortData[sortData.length - 1].porder + 1, sortData.length + 1);
  1199. data.updateData = {name: newText, lid: node.id, tid: tender.id, porder: order};
  1200. } else {
  1201. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1202. return;
  1203. }
  1204. } else {
  1205. data.updateType = 'update';
  1206. data.updateData = {pid: posData.id, lid: posData.lid, name: newText};
  1207. }
  1208. } else if (!posData) {
  1209. toastr.warning('新增计量单元请先输入名称');
  1210. } else {
  1211. data.updateType = 'update';
  1212. data.updateData = {pid: posData.id, lid: posData.lid};
  1213. if (col.type === 'Number') {
  1214. const exprInfo = getExprInfo(col.field);
  1215. const num = _.toNumber(newText);
  1216. if (_.isFinite(num)) {
  1217. data.updateData[col.field] = num;
  1218. if (exprInfo) {
  1219. data.updateData[exprInfo.expr] = '';
  1220. }
  1221. } else {
  1222. try {
  1223. data.updateData[col.field] = math.evaluate(transExpr(newText));
  1224. if (exprInfo) {
  1225. data.updateData[exprInfo.expr] = newText;
  1226. }
  1227. } catch(err) {
  1228. toastr.error('输入的表达式非法');
  1229. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1230. return;
  1231. }
  1232. }
  1233. } else {
  1234. data.updateData[col.field] = newText;
  1235. }
  1236. }
  1237. // 提交数据到服务器
  1238. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  1239. if (result.pos) {
  1240. stagePos.updateDatas(result.pos.pos);
  1241. stagePos.loadCurStageData(result.pos.curStageData);
  1242. }
  1243. const refreshData = stageTree.loadPostStageData(result.ledger);
  1244. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  1245. stagePosSpreadObj.loadCurPosData();
  1246. if (detail) {
  1247. detail.loadStagePosUpdateData(result);
  1248. } else {
  1249. stageIm.loadUpdatePosData(result);
  1250. }
  1251. }, function () {
  1252. stagePosSpreadObj.loadCurPosData();
  1253. });
  1254. }
  1255. },
  1256. editStarting: function (e, info) {
  1257. stagePosSpreadObj.stageTreeNode = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1258. const sel = info.sheet.getSelections();
  1259. if (!sel || !sel[0]) return;
  1260. const col = info.sheet.zh_setting.cols[sel[0].col];
  1261. const node = SpreadJsObj.getSelectObject(info.sheet);
  1262. const exprInfo = getExprInfo(col.field);
  1263. if (exprInfo) {
  1264. if (node[exprInfo.expr] && node[exprInfo.expr] !== '') {
  1265. info.sheet.getCell(info.row, info.col).text(node[exprInfo.expr]);
  1266. }
  1267. }
  1268. },
  1269. clipboardPasting: function (e, info) {
  1270. if (info.sheet.zh_setting) {
  1271. const sortData = info.sheet.zh_data;
  1272. const range = info.cellRange;
  1273. const validField = ['contract_qty', 'qc_qty', 'postil', 'real_qty'];
  1274. if (!checkTzMeasureType()) {
  1275. validField.push('name', 'sgfh_qty', 'sjcl_qty', 'qtcl_qty', 'position', 'drawing_code');
  1276. }
  1277. for (let iCol = range.col; iCol < range.col + range.colCount; iCol++) {
  1278. const col = info.sheet.zh_setting.cols[iCol];
  1279. if (validField.indexOf(col.field) === -1) {
  1280. if (checkTzMeasureType()) {
  1281. toastr.error('不可修改此数据');
  1282. info.cancel = true;
  1283. return;
  1284. } else {
  1285. for (let iRow = range.row; iRow < range.row + range.rowCount; iRow) {
  1286. const pos = sortData(iRow);
  1287. if (pos.add_stage !== stage.id || pos.add_times !== stage.times) {
  1288. toastr.error('不可修改此数据');
  1289. info.cancel = true;
  1290. return;
  1291. }
  1292. }
  1293. }
  1294. }
  1295. }
  1296. }
  1297. },
  1298. clipboardPasted: function (e, info) {
  1299. if (info.sheet.zh_setting) {
  1300. if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
  1301. info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
  1302. }
  1303. const data = { updateType: '', updateData: [], };
  1304. const sortData = info.sheet.zh_data;
  1305. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1306. if (sortData && (info.cellRange.row >= sortData.length)) {
  1307. data.updateType = 'add';
  1308. if (info.cellRange.col !== 0) {
  1309. toastr.warning('新增计量单元请先输入名称');
  1310. stagePosSpreadObj.loadCurPosData();
  1311. return;
  1312. }
  1313. if ((node.pre_used === 1 || !checkZero(node.gather_qty) || !checkZero(node.gather_tp)) && sortData.length === 0) {
  1314. toastr.error('无计量单元的清单,计量后,不可新增计量单元');
  1315. stagePosSpreadObj.loadCurPosData();
  1316. return;
  1317. }
  1318. const lastOrder = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  1319. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  1320. const curRow = info.cellRange.row + iRow;
  1321. const newData = {lid: node.id, porder: lastOrder + curRow - sortData.length};
  1322. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  1323. const curCol = info.cellRange.col + iCol;
  1324. const colSetting = info.sheet.zh_setting.cols[curCol];
  1325. if (!colSetting) continue;
  1326. const newValue = trimInvalidChar(info.sheet.getText(curRow, curCol));
  1327. if (colSetting.type === 'Number') {
  1328. const num = _.toNumber(newValue);
  1329. if (num) {
  1330. newData[colSetting.field] = num;
  1331. } else {
  1332. try {
  1333. newData[colSetting.field] = math.evaluate(transExpr(newValue));
  1334. const exprInfo = getExprInfo(colSetting.field);
  1335. if (exprInfo) {
  1336. newData[exprInfo.expr] = newValue;
  1337. }
  1338. } catch(err) {
  1339. toastr.error('输入的表达式非法');
  1340. stagePosSpreadObj.loadCurPosData();
  1341. return;
  1342. }
  1343. }
  1344. } else {
  1345. newData[colSetting.field] = newValue;
  1346. }
  1347. }
  1348. data.updateData.push(newData);
  1349. }
  1350. } else {
  1351. data.updateType = 'update';
  1352. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  1353. const curRow = info.cellRange.row + iRow;
  1354. const curPos = sortData[curRow];
  1355. if (curPos) {
  1356. const newData = {pid: curPos.id, lid: curPos.lid};
  1357. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  1358. const curCol = info.cellRange.col + iCol;
  1359. const colSetting = info.sheet.zh_setting.cols[curCol];
  1360. const newValue = trimInvalidChar(info.sheet.getText(curRow, curCol));
  1361. if (colSetting.type === 'Number') {
  1362. const num = _.toNumber(newValue);
  1363. if (num) {
  1364. newData[colSetting.field] = num;
  1365. } else {
  1366. try {
  1367. newData[colSetting.field] = math.evaluate(transExpr(newValue));
  1368. const exprInfo = getExprInfo(colSetting.field);
  1369. if (exprInfo) {
  1370. newData[exprInfo.expr] = newValue;
  1371. }
  1372. } catch(err) {
  1373. toastr.error('输入的表达式非法');
  1374. stagePosSpreadObj.loadCurPosData();
  1375. return;
  1376. }
  1377. }
  1378. } else {
  1379. newData[colSetting.field] = newValue;
  1380. }
  1381. }
  1382. data.updateData.push(newData);
  1383. }
  1384. }
  1385. }
  1386. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  1387. if (result.pos) {
  1388. stagePos.updateDatas(result.pos.pos);
  1389. stagePos.loadCurStageData(result.pos.curStageData);
  1390. }
  1391. const nodes = stageTree.loadPostStageData(result.ledger);
  1392. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1393. stagePosSpreadObj.loadCurPosData();
  1394. if (detail) {
  1395. detail.loadStagePosUpdateData(result);
  1396. } else {
  1397. stageIm.loadUpdatePosData(result);
  1398. }
  1399. }, function () {
  1400. stagePosSpreadObj.loadCurPosData();
  1401. });
  1402. }
  1403. },
  1404. deletePress: function (sheet) {
  1405. if (sheet.zh_setting && sheet.zh_data) {
  1406. const sortData = sheet.zh_data;
  1407. if (!sortData || sortData.length === 0) { return; }
  1408. const sel = sheet.getSelections()[0];
  1409. const validCols = [];
  1410. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  1411. const colSetting = sheet.zh_setting.cols[iCol];
  1412. if (!colSetting.readOnly && colSetting.field !== 'qc_qty') {
  1413. validCols.push(iCol);
  1414. }
  1415. }
  1416. if (validCols.length === 0) { return; }
  1417. const datas = [], posSelects = [];
  1418. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  1419. const node = sortData[iRow];
  1420. if (node) {
  1421. const data = {pid: node.id, lid: node.lid};
  1422. for (const iCol of validCols) {
  1423. const colSetting = sheet.zh_setting.cols[iCol];
  1424. if (colSetting.field === 'name') {
  1425. toastr.error('部位名称不能为空');
  1426. return;
  1427. }
  1428. data[colSetting.field] = null;
  1429. const exprInfo = getExprInfo(colSetting.field);
  1430. if (exprInfo) {
  1431. data[exprInfo.expr] = '';
  1432. }
  1433. }
  1434. datas.push(data);
  1435. posSelects.push(node);
  1436. }
  1437. }
  1438. if (datas.length > 0) {
  1439. postData(window.location.pathname + '/update', {pos: {updateType: 'update', updateData: datas} }, function (result) {
  1440. if (result.pos) {
  1441. stagePos.updateDatas(result.pos.pos);
  1442. stagePos.loadCurStageData(result.pos.curStageData);
  1443. }
  1444. const nodes = stageTree.loadPostStageData(result.ledger);
  1445. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1446. if (detail) {
  1447. detail.loadStagePosUpdateData(result);
  1448. } else {
  1449. stageIm.loadUpdatePosData(result);
  1450. }
  1451. // todo 只加载改变项
  1452. stagePosSpreadObj.loadCurPosData();
  1453. });
  1454. }
  1455. }
  1456. },
  1457. deletePos: function (sheet) {
  1458. const sels = sheet.getSelections();
  1459. const sel = sels ? sels[0] : null;
  1460. if (sheet.zh_data && sel) {
  1461. const data = {updateType: 'delete', updateData: []};
  1462. for (let iRow = 0; iRow < sel.rowCount; iRow++) {
  1463. const posData = sheet.zh_data[sel.row + iRow];
  1464. if (posData) {
  1465. data.updateData.push(posData.id);
  1466. }
  1467. }
  1468. if (data.updateData.length > 0) {
  1469. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  1470. stagePos.removeDatas(result.pos.pos);
  1471. const refreshData = stageTree.loadPostStageData(result.ledger);
  1472. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  1473. stagePosSpreadObj.loadCurPosData();
  1474. if (detail) {
  1475. detail.loadStagePosUpdateData(result);
  1476. } else {
  1477. stageIm.loadUpdatePosData(result);
  1478. }
  1479. });
  1480. }
  1481. }
  1482. },
  1483. selectionChanged: function (e, info) {
  1484. stagePosSpreadObj.loadExprToInput(info.sheet);
  1485. },
  1486. addPegs: function (pegs) {
  1487. if (!pegs || pegs.length <= 0) return;
  1488. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1489. if (!node) return;
  1490. const sheet = spSpread.getActiveSheet();
  1491. const sortData = sheet.zh_data || [];
  1492. let order = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  1493. pegs.forEach(function (p) {p.porder = ++order; p.lid = node.id});
  1494. postData(window.location.pathname + '/update', {pos: {updateType: 'add', updateData: pegs} }, function (result) {
  1495. if (result.pos) {
  1496. stagePos.updateDatas(result.pos.pos);
  1497. }
  1498. stagePosSpreadObj.loadCurPosData();
  1499. });
  1500. }
  1501. };
  1502. // 加载上下窗口resizer
  1503. $.divResizer({
  1504. select: '#main-resize',
  1505. callback: function () {
  1506. slSpread.refresh();
  1507. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  1508. $(".sp-wrap").height(bcontent-30);
  1509. spSpread.refresh();
  1510. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  1511. }
  1512. });
  1513. // 加载计量单元数据 - 暂时统一加载,如有需要,切换成动态加载并缓存
  1514. postData(window.location.pathname + '/load', { filter: 'ledger;pos;detail;change' }, function (result) {
  1515. // 加载树结构
  1516. stageTree.loadDatas(result.ledgerData);
  1517. // stageTree.loadCurStageData(curStageData);
  1518. // stageTree.loadPreStageData(preStageData);
  1519. treeCalc.calculateAll(stageTree);
  1520. // 加载部位明细
  1521. stagePos.loadDatas(result.posData);
  1522. stagePos.calculateAll();
  1523. SpreadJsObj.loadSheetData(slSpread.getActiveSheet(), 'tree', stageTree);
  1524. SpreadJsObj.loadTopAndSelect(slSpread.getActiveSheet(), ckBillsSpread);
  1525. stagePosSpreadObj.loadCurPosData();
  1526. SpreadJsObj.resetTopAndSelect(spSpread.getActiveSheet());
  1527. // 加载中间计量
  1528. stageIm.init(stage, imType, tenderInfo.decimal);
  1529. stageIm.loadData(result.ledgerData, result.posData, result.detailData, result.changeData);
  1530. errorList.loadHisErrorData();
  1531. }, null, true);
  1532. spSpread.bind(spreadNS.Events.EditEnded, stagePosSpreadObj.editEnded);
  1533. spSpread.bind(spreadNS.Events.ClipboardPasting, stagePosSpreadObj.clipboardPasting);
  1534. spSpread.bind(spreadNS.Events.ClipboardPasted, stagePosSpreadObj.clipboardPasted);
  1535. spSpread.bind(spreadNS.Events.EditStarting, stagePosSpreadObj.editStarting);
  1536. spSpread.bind(spreadNS.Events.SelectionChanged, stagePosSpreadObj.selectionChanged);
  1537. SpreadJsObj.addDeleteBind(spSpread, stagePosSpreadObj.deletePress);
  1538. if (!readOnly) {
  1539. $('#pos-expr').bind('change onblur', function () {
  1540. if (this.readOnly) return;
  1541. const expr = $(this);
  1542. const posSheet = spSpread.getActiveSheet();
  1543. const row = expr.attr('data-row') ? _.toInteger(expr.attr('data-row')) : -1;
  1544. const select = posSheet.zh_data ? posSheet.zh_data[row] : null;
  1545. if (!select) return;
  1546. const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = expr.val();
  1547. if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
  1548. const data = {pid: select.id, lid: select.lid};
  1549. const exprInfo = getExprInfo(field);
  1550. if (newValue !== '') {
  1551. const num = _.toNumber(newValue);
  1552. if (num) {
  1553. data[field] = num;
  1554. if (exprInfo) data[exprInfo.expr] = '';
  1555. } else {
  1556. try {
  1557. data[field] = math.evaluate(transExpr(newValue));
  1558. if (exprInfo) data[exprInfo.expr] = newValue;
  1559. } catch (err) {
  1560. toastr.error('输入的表达式非法');
  1561. return;
  1562. }
  1563. }
  1564. } else {
  1565. data[field] = null;
  1566. if (exprInfo) data[exprInfo.expr] = '';
  1567. }
  1568. // 提交数据到服务器
  1569. postData(window.location.pathname + '/update', {pos: {updateType: 'update', updateData: data}}, function (result) {
  1570. if (result.pos) {
  1571. stagePos.updateDatas(result.pos.pos);
  1572. stagePos.loadCurStageData(result.pos.curStageData);
  1573. SpreadJsObj.reLoadRowData(posSheet, _.toNumber(row));
  1574. }
  1575. const refreshData = stageTree.loadPostStageData(result.ledger);
  1576. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  1577. });
  1578. });
  1579. }
  1580. if (!checkTzMeasureType()) {
  1581. const mergePeg = NewMergePeg({ callback: stagePosSpreadObj.addPegs});
  1582. $.contextMenu({
  1583. selector: '#stage-pos',
  1584. build: function ($trigger, e) {
  1585. const target = SpreadJsObj.safeRightClickSelection($trigger, e, spSpread);
  1586. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  1587. },
  1588. items: {
  1589. 'del': {
  1590. name: '删除',
  1591. icon: 'fa-remove',
  1592. disabled: function (key, opt) {
  1593. const sheet = spSpread.getActiveSheet();
  1594. if (sheet.zh_data && !readOnly) {
  1595. const selection = sheet.getSelections();
  1596. if (selection && selection[0]) {
  1597. let valid = sheet.zh_data.length < selection[0].row + selection[0].rowCount;
  1598. for (let iRow = 0; iRow < selection[0].rowCount; iRow++) {
  1599. const posData = sheet.zh_data[selection[0].row + iRow];
  1600. if (posData) {
  1601. if (posData.add_stage_order < stage.order || ZhCalc.isNonZero(posData.gather_qty) || ZhCalc.isNonZero(posData.end_gather_qty)) {
  1602. valid = true;
  1603. break;
  1604. }
  1605. } else {
  1606. valid = true;
  1607. break;
  1608. }
  1609. }
  1610. return valid;
  1611. } else {
  1612. return true;
  1613. }
  1614. } else {
  1615. return true;
  1616. }
  1617. },
  1618. callback: function (key, opt) {
  1619. stagePosSpreadObj.deletePos(spSpread.getActiveSheet());
  1620. }
  1621. },
  1622. 'merge-peg': {
  1623. name: '合并起讫桩号',
  1624. disabled: function (key, opt) {
  1625. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1626. return _.isNil(node) || _.isNil(node.b_code) || node.b_code === '';
  1627. },
  1628. callback: function (key, opt) {
  1629. mergePeg.show();
  1630. }
  1631. }
  1632. }
  1633. })
  1634. } else {
  1635. SpreadJsObj.forbiddenSpreadContextMenu('#stage-pos', spSpread);
  1636. }
  1637. $.subMenu({
  1638. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  1639. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  1640. key: 'menu.1.0.0',
  1641. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  1642. callback: function (info) {
  1643. if (info.mini) {
  1644. $('.panel-title').addClass('fluid');
  1645. $('#sub-menu').removeClass('panel-sidebar');
  1646. } else {
  1647. $('.panel-title').removeClass('fluid');
  1648. $('#sub-menu').addClass('panel-sidebar');
  1649. }
  1650. autoFlashHeight();
  1651. slSpread.refresh();
  1652. spSpread.refresh();
  1653. if (searchLedger) {
  1654. searchLedger.spread.refresh();
  1655. }
  1656. if (detail) {
  1657. detail.spread.refresh();
  1658. }
  1659. if (checkedChanges) checkedChanges.refresh();
  1660. if (errorList && errorList.spread) {
  1661. errorList.spread.refresh();
  1662. }
  1663. }
  1664. });
  1665. $('#row-view').on('show.bs.modal', function () {
  1666. const html = [], customDisplay = customColDisplay();
  1667. for (const cd of customDisplay) {
  1668. html.push('<tr>');
  1669. html.push('<td>', cd.title, '</td>');
  1670. html.push('<td>', '<input type="checkbox"' + (cd.visible ? ' checked=""' : '') + '>', '</td>');
  1671. html.push('</tr>');
  1672. }
  1673. $('#row-view-list').html(html.join(''));
  1674. });
  1675. $('#row-view-ok').click(function () {
  1676. const customDisplay = customColDisplay();
  1677. const cvl = $('#row-view-list').children();
  1678. for (const cv of cvl) {
  1679. const title = $(cv).children()[0].innerHTML;
  1680. const check = $('input', cv)[0].checked;
  1681. const cd = customDisplay.find(function (c) {
  1682. return c.title === title;
  1683. });
  1684. cd.visible = check;
  1685. }
  1686. customizeStageTreeSetting(ledgerSpreadSetting, customDisplay);
  1687. SpreadJsObj.refreshColumnVisible(slSpread.getActiveSheet());
  1688. Cookies.set(ckColSetting, JSON.stringify(customDisplay), 30*24*60*60*1000);
  1689. $('#row-view').modal('hide');
  1690. });
  1691. const posSearch = (function () {
  1692. let resultArr = [];
  1693. const search = function () {
  1694. resultArr = [];
  1695. const keyword = $('#pos-search-keyword').val();
  1696. const checkOver = $('#pos-over-search')[0].checked;
  1697. const checkEmpty = $('#pos-empty-search')[0].checked;
  1698. const sortData = spSpread.getActiveSheet().zh_data;
  1699. if (checkOver || checkEmpty) {
  1700. if (sortData) {
  1701. for (let i = 0, iLength = sortData.length; i < iLength; i++) {
  1702. const sd = sortData[i];
  1703. let match = false;
  1704. if (checkOver) {
  1705. if (sd.end_gather_qty) {
  1706. if (!sd.quantity || Math.abs(sd.end_gather_qty) > Math.abs(ZhCalc.add(sd.quantity, sd.end_qc_qty))) match = true;
  1707. }
  1708. }
  1709. if (checkEmpty) {
  1710. if (sd.quantity) {
  1711. if (!sd.end_gather_qty || ZhCalc.sub(ZhCalc.add(sd.quantity, sd.end_qc_qty), sd.end_gather_qty) > 0) match = true;
  1712. }
  1713. }
  1714. if (keyword && keyword !== '' && sd.name && sd.name.indexOf(keyword) === -1) match = false;
  1715. if (match) {
  1716. resultArr.push({index: i, data: sd});
  1717. }
  1718. }
  1719. }
  1720. } else if (keyword && keyword !== '') {
  1721. if (sortData) {
  1722. for (let i = 0, iLength = sortData.length; i < iLength; i++) {
  1723. const sd = sortData[i];
  1724. if (sd.name && sd.name.indexOf(keyword) > -1) {
  1725. resultArr.push({index: i, data: sd});
  1726. }
  1727. }
  1728. }
  1729. }
  1730. $('#pos-search-result').html('结果:' + resultArr.length);
  1731. };
  1732. const searchAndLocate = function () {
  1733. search();
  1734. if (resultArr.length > 0) {
  1735. const sheet = spSpread.getActiveSheet();
  1736. const sel = sheet.getSelections()[0];
  1737. const curRow = sel ? sel.row : 0;
  1738. const pos = resultArr[0];
  1739. if (pos.index !== curRow) {
  1740. sheet.setSelection(pos.index, sel ? sel.col : 0, 1, 1);
  1741. sheet.showRow(pos.index, spreadNS.VerticalPosition.center);
  1742. SpreadJsObj.reloadRowsBackColor(sheet, [pos.index, curRow]);
  1743. }
  1744. }
  1745. };
  1746. const locateNext = function () {
  1747. if (resultArr.length > 0) {
  1748. const sheet = spSpread.getActiveSheet();
  1749. const sel = sheet.getSelections()[0];
  1750. const curRow = sel ? sel.row : 0;
  1751. let next = _.find(resultArr, function (d) {
  1752. return d.index > curRow;
  1753. });
  1754. if (!next) next = resultArr[0];
  1755. if (next.index !== curRow) {
  1756. sheet.setSelection(next.index, sel ? sel.col : 0, 1, 1);
  1757. sheet.showRow(next.index, spreadNS.VerticalPosition.center);
  1758. SpreadJsObj.reloadRowsBackColor(sheet, [next.index, curRow]);
  1759. }
  1760. }
  1761. };
  1762. const locatePre = function () {
  1763. if (resultArr.length > 0) {
  1764. const sheet = spSpread.getActiveSheet();
  1765. const sel = sheet.getSelections()[0];
  1766. const curRow = sel ? sel.row : 0;
  1767. let next = _.findLast(resultArr, function (d) {
  1768. return d.index < curRow;
  1769. });
  1770. if (!next) next = resultArr[resultArr.length - 1];
  1771. if (next.index !== curRow) {
  1772. sheet.setSelection(next.index, sel ? sel.col : 0, 1, 1);
  1773. sheet.showRow(next.index, spreadNS.VerticalPosition.center);
  1774. SpreadJsObj.reloadRowsBackColor(sheet, [next.index, curRow]);
  1775. }
  1776. }
  1777. };
  1778. return {search, searchAndLocate, locateNext, locatePre};
  1779. })();
  1780. $('#pos-search-keyword').bind('keydown', function(e){
  1781. if (e.keyCode == 13) posSearch.searchAndLocate();
  1782. });
  1783. $('#pos-empty-search').click(function () {
  1784. if (this.checked) {
  1785. $('[for=' + this.id +']').addClass('text-warning');
  1786. } else {
  1787. $('[for=' + this.id +']').removeClass('text-warning');
  1788. }
  1789. if (this.checked) {
  1790. if ($('#pos-over-search')[0].checked) {
  1791. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  1792. } else {
  1793. $('#pos-search-keyword').attr('placeholder', '漏计中按名称查询');
  1794. }
  1795. } else {
  1796. if ($('#pos-over-search')[0].checked) {
  1797. $('#pos-search-keyword').attr('placeholder', '超计中按名称查询');
  1798. } else {
  1799. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  1800. }
  1801. }
  1802. posSearch.searchAndLocate();
  1803. });
  1804. $('#pos-over-search').click(function () {
  1805. if (this.checked) {
  1806. $('[for=' + this.id +']').addClass('text-danger');
  1807. } else {
  1808. $('[for=' + this.id +']').removeClass('text-danger');
  1809. }
  1810. if (this.checked) {
  1811. if ($('#pos-empty-search')[0].checked) {
  1812. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  1813. } else {
  1814. $('#pos-search-keyword').attr('placeholder', '超计中按名称查询');
  1815. }
  1816. } else {
  1817. if ($('#pos-empty-search')[0].checked) {
  1818. $('#pos-search-keyword').attr('placeholder', '漏计中按名称查询');
  1819. } else {
  1820. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  1821. }
  1822. }
  1823. posSearch.searchAndLocate();
  1824. });
  1825. $('#pos-search-next').click(() => {posSearch.locateNext()});
  1826. $('#pos-search-pre').click(() => {posSearch.locatePre()});
  1827. $.divResizer({
  1828. select: '#right-spr',
  1829. callback: function () {
  1830. slSpread.refresh();
  1831. spSpread.refresh();
  1832. if (searchLedger) {
  1833. searchLedger.spread.refresh();
  1834. }
  1835. if (detail) {
  1836. detail.spread.refresh();
  1837. }
  1838. if (checkedChanges) checkedChanges.refresh();
  1839. if (errorList && errorList.spread) {
  1840. errorList.spread.refresh();
  1841. }
  1842. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  1843. }
  1844. });
  1845. // 中间计量加载上下窗口resizer
  1846. $.divResizer({
  1847. select: '#zhongjian-spr',
  1848. callback: function () {
  1849. if (detail) {
  1850. detail.spread.refresh();
  1851. }
  1852. $('.zhongjian-msg').height($('#zhongjian .sjs-bottom').height());
  1853. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  1854. }
  1855. });
  1856. // 附件加载上下窗口resizer
  1857. $.divResizer({
  1858. select: '#file-spr',
  1859. callback: function () {
  1860. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  1861. }
  1862. });
  1863. // 变更令加载上下窗口resizer
  1864. $.divResizer({
  1865. select: '#change-spr',
  1866. callback: function () {
  1867. if (checkedChanges) checkedChanges.refresh();
  1868. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  1869. }
  1870. });
  1871. class Detail {
  1872. constructor (obj) {
  1873. const self = this;
  1874. this.spreadSetting = {
  1875. cols: [
  1876. {title: '编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 80, formatter: '@', readOnly: true},
  1877. {title: '中间计量表号', colSpan: '1', rowSpan: '1', field: 'im_code', hAlign: 0, width: 85, formatter: '@', readOnly: true},
  1878. {title: '交工证书/凭证号', colSpan: '1', rowSpan: '1', field: 'doc_code', hAlign: 0, width: 110, formatter: '@'},
  1879. {
  1880. title: stage.im_type === imType.tz.value ? '本期计量金额' : '本期计量数量',
  1881. colSpan: '1', rowSpan: '1', field: 'jl', hAlign: 2, width: 85, formatter: '@', readOnly: true
  1882. },
  1883. ],
  1884. headRows: 1,
  1885. emptyRows: 0,
  1886. headRowHeight: [32],
  1887. headColWidth: [30],
  1888. defaultRowHeight: 21,
  1889. headerFont: '12px 微软雅黑',
  1890. font: '12px 微软雅黑',
  1891. readOnly: readOnly,
  1892. selectedBackColor: '#fffacd',
  1893. };
  1894. this.spread = SpreadJsObj.createNewSpread(obj[0]);
  1895. this.sheet = this.spread.getActiveSheet();
  1896. this.spread.options.allowUserDragFill = true;
  1897. this.spread.options.defaultDragFillType = spreadNS.Fill.AutoFillType.fillSeries;
  1898. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  1899. this.detailObj = {
  1900. selectionChanged: function (e, info) {
  1901. self.reLoadDetailData();
  1902. if (!info.oldSelections || !info.oldSelections[0] || info.oldSelections[0].row !== info.newSelections[0].row) {
  1903. self.loadLocateInfo();
  1904. }
  1905. },
  1906. editEnded: function(e, info) {
  1907. if (info.sheet.zh_setting) {
  1908. const col = info.sheet.zh_setting.cols[info.col];
  1909. if (col.field !== 'doc_code') {
  1910. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1911. return;
  1912. }
  1913. const data = SpreadJsObj.getSelectObject(info.sheet);
  1914. if (data) {
  1915. const updateData = {lid: data.lid, pid: data.pid};
  1916. if (data.uuid) {
  1917. updateData.uuid = data.uuid;
  1918. } else {
  1919. updateData.code = data.code;
  1920. updateData.name = data.name;
  1921. updateData.unit = data.unit;
  1922. updateData.unit_price = data.unit_price;
  1923. updateData.pid = data.pid;
  1924. updateData.pos_name = data.pos_name;
  1925. }
  1926. if (data.custom_define.indexOf('doc_code') === -1) {
  1927. updateData.custom_define = data.custom_define;
  1928. updateData.custom_define.push('doc_code');
  1929. updateData.custom_define = updateData.custom_define.join(',');
  1930. }
  1931. updateData.doc_code = info.editingText === null ? '' : info.editingText;
  1932. postData(window.location.pathname + '/detail/save', updateData, function (result) {
  1933. stageIm.loadUpdateDetailData(result);
  1934. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1935. }, function () {
  1936. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1937. });
  1938. } else {
  1939. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1940. }
  1941. }
  1942. },
  1943. clipboardPasted: function (e, info) {
  1944. if (info.sheet.zh_setting && info.sheet.zh_data) {
  1945. const col = info.sheet.zh_setting.cols[info.cellRange.col];
  1946. if (info.cellRange.colCount > 1) {
  1947. toastr.warning('请勿同时复制粘贴多列数据');
  1948. SpreadJsObj.reLoadSheetData(paySpread.getActiveSheet());
  1949. return;
  1950. }
  1951. if (col.field !== 'doc_code') {
  1952. SpreadJsObj.reLoadSheetData(paySpread.getActiveSheet());
  1953. return;
  1954. }
  1955. const datas = [];
  1956. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  1957. const curRow = info.cellRange.row + iRow;
  1958. const data = info.sheet.zh_data[curRow];
  1959. if (data) {
  1960. const updateData = {lid: data.lid, pid: data.pid};
  1961. if (data.uuid) {
  1962. updateData.uuid = data.uuid;
  1963. } else {
  1964. updateData.code = data.code;
  1965. updateData.name = data.name;
  1966. updateData.unit = data.unit;
  1967. updateData.unit_price = data.unit_price;
  1968. updateData.pid = data.pid;
  1969. updateData.pos_name = data.pos_name;
  1970. }
  1971. if (data.custom_define.indexOf('doc_code') === -1) {
  1972. updateData.custom_define = data.custom_define;
  1973. updateData.custom_define.push('doc_code');
  1974. updateData.custom_define = updateData.custom_define.join(',');
  1975. }
  1976. updateData.doc_code = info.sheet.getText(curRow, info.cellRange.col).replace('\n', '');
  1977. datas.push(updateData);
  1978. }
  1979. }
  1980. if (datas.length > 0) {
  1981. postData(window.location.pathname + '/detail/save', datas, function (result) {
  1982. stageIm.loadUpdateDetailData(result);
  1983. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1984. }, function () {
  1985. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1986. })
  1987. }
  1988. }
  1989. },
  1990. deletePress: function (sheet) {
  1991. if (sheet.zh_setting) {
  1992. const datas = [];
  1993. const sel = sheet.getSelections()[0];
  1994. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  1995. const col = sheet.zh_setting.cols[iCol];
  1996. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  1997. const data = sheet.zh_data[iRow];
  1998. if (col.field === 'doc_code') {
  1999. const updateData = {lid: data.lid};
  2000. if (data.uuid) {
  2001. updateData.uuid = data.uuid;
  2002. updateData.doc_code = '';
  2003. datas.push(updateData);
  2004. }
  2005. }
  2006. }
  2007. }
  2008. if (datas.length > 0) {
  2009. postData(window.location.pathname + '/detail/save', datas, function (result) {
  2010. stageIm.loadUpdateDetailData(result);
  2011. SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
  2012. }, function () {
  2013. SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
  2014. });
  2015. }
  2016. }
  2017. },
  2018. dragFillBlock: function (e, info) {
  2019. info.cancel = true;
  2020. if (!info.sheet.zh_setting || !info.sheet.zh_data) return;
  2021. const sel = info.sheet.getSelections()[0];
  2022. const col = info.sheet.zh_setting.cols[info.fillRange.col];
  2023. if (info.fillRange.colCount > 1 || !sel || col.field !== 'doc_code') return;
  2024. const text = info.sheet.getText(sel.row + sel.rowCount - 1, sel.col);
  2025. if (text === '') return;
  2026. const regRst = /(\d+)$/g.exec(text), datas = [];
  2027. for (let iRow = 0; iRow < info.fillRange.rowCount; iRow++) {
  2028. const curRow = info.fillRange.row + iRow;
  2029. const data = info.sheet.zh_data[curRow];
  2030. if (data) {
  2031. const updateData = {lid: data.lid};
  2032. if (data.uuid) {
  2033. updateData.uuid = data.uuid;
  2034. } else {
  2035. updateData.code = data.code;
  2036. updateData.name = data.name;
  2037. updateData.unit = data.unit;
  2038. updateData.unit_price = data.unit_price;
  2039. updateData.pid = data.pid;
  2040. updateData.pos_name = data.pos_name;
  2041. }
  2042. if (regRst) {
  2043. updateData.doc_code = text.substr(0, regRst.index) + (parseInt(regRst[0]) + iRow + 1);
  2044. } else {
  2045. updateData.doc_code = text.replace('\n', '');
  2046. }
  2047. if (data.custom_define.indexOf('doc_code') === -1) {
  2048. updateData.custom_define = data.custom_define;
  2049. updateData.custom_define.push('doc_code');
  2050. updateData.custom_define = updateData.custom_define.join(',');
  2051. }
  2052. datas.push(updateData);
  2053. }
  2054. }
  2055. if (datas.length > 0) {
  2056. postData(window.location.pathname + '/detail/save', datas, function (result) {
  2057. stageIm.loadUpdateDetailData(result);
  2058. SpreadJsObj.reLoadRowData(info.sheet, info.fillRange.row, info.fillRange.rowCount);
  2059. }, function () {
  2060. SpreadJsObj.reLoadRowData(info.sheet, info.fillRange.row, info.fillRange.rowCount);
  2061. })
  2062. }
  2063. },
  2064. };
  2065. this.spread.bind(spreadNS.Events.SelectionChanged, this.detailObj.selectionChanged);
  2066. if (!readOnly) {
  2067. this.spread.bind(spreadNS.Events.EditEnded, this.detailObj.editEnded);
  2068. this.spread.bind(spreadNS.Events.ClipboardPasted, this.detailObj.clipboardPasted);
  2069. this.spread.bind(spreadNS.Events.DragFillBlock, this.detailObj.dragFillBlock);
  2070. SpreadJsObj.addDeleteBind(this.spread, this.detailObj.deletePress);
  2071. }
  2072. this._initImTypeSetRela();
  2073. this._initModifyDetail();
  2074. this._initLocateRela();
  2075. // 草图相关
  2076. this._initImageRela();
  2077. this.reBuildImData();
  2078. }
  2079. _initImTypeSetRela() {
  2080. const self = this;
  2081. const gatherConfirmPopover = {
  2082. reBind: function (obj, eventName, fun) {
  2083. obj.unbind(eventName);
  2084. obj.bind(eventName, fun);
  2085. },
  2086. check: function (pos, hint, okCallback) {
  2087. const confirmObj = $('#gather-confirm'), hintObj = $('#gather-confirm-hint');
  2088. const okObj = $('#gather-confirm-ok'), cancelObj = $('#gather-confirm-cancel');
  2089. this.reBind(cancelObj, 'click', function () {
  2090. confirmObj.hide();
  2091. });
  2092. this.reBind(okObj, 'click', function () {
  2093. okCallback();
  2094. confirmObj.hide();
  2095. });
  2096. hintObj.text(hint);
  2097. confirmObj.css("top", pos.y).css("left", pos.x).show();
  2098. }
  2099. };
  2100. this.gsTree = stageIm.getGsTree();
  2101. if (stage.im_type === imType.tz.value || stage.im_type === imType.bb.value) {
  2102. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  2103. jlCol.title = '本期计量金额';
  2104. SpreadJsObj.reLoadSheetHeader(self.sheet);
  2105. $('#type-title-contract').text('本期合同计量金额');
  2106. $('#type-title-qc').text('本期变更计量金额');
  2107. } else {
  2108. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  2109. jlCol.title = '本期计量数量';
  2110. SpreadJsObj.reLoadSheetHeader(self.sheet);
  2111. $('#type-title-contract').text('本期合同计量数量');
  2112. $('#type-title-qc').text('本期变更计量数量');
  2113. }
  2114. if (stage.im_type === imType.bb.value || stage.im_type === imType.bw.value) {
  2115. $('#show-jldy').parent().show();
  2116. $('#jldy').parent().show();
  2117. $('#show-xm-name').parent().hide();
  2118. $('#xm-name').parent().hide();
  2119. } else {
  2120. $('#show-jldy').parent().hide();
  2121. $('#jldy').parent().hide();
  2122. $('#show-xm-name').parent().show();
  2123. $('#xm-name').parent().show();
  2124. }
  2125. // 选择中间计量模式
  2126. $('div[name="im-type"]').click(function () {
  2127. function chooseType(obj) {
  2128. obj.style.cursor = 'default';
  2129. $(obj).children().addClass('text-primary');
  2130. $(obj).addClass('border-primary');
  2131. $('h5', obj).prepend('<i class="fa fa-check pull-right"></i>');
  2132. }
  2133. function validType(obj) {
  2134. obj.style.cursor = 'pointer';
  2135. $(obj).children().removeClass('text-primary');
  2136. $(obj).removeClass('border-primary');
  2137. $('i', obj).remove();
  2138. }
  2139. if (this.style.cursor === 'pointer') {
  2140. const typeArr = $('div[name="im-type"]');
  2141. for (const t of typeArr) {
  2142. if ($(t).attr('im-type') === $(this).attr('im-type')) {
  2143. chooseType(t);
  2144. } else {
  2145. validType(t)
  2146. }
  2147. }
  2148. }
  2149. });
  2150. $('#choose').on('show.bs.modal', function () {
  2151. function chooseType(obj) {
  2152. obj.style.cursor = 'default';
  2153. $(obj).children().addClass('text-primary');
  2154. $('i', obj).remove();
  2155. $('h5', obj).prepend('<i class="fa fa-check pull-right"></i>');
  2156. }
  2157. function validType(obj) {
  2158. obj.style.cursor = 'pointer';
  2159. $(obj).children().removeClass('text-primary');
  2160. $('i', obj).remove();
  2161. }
  2162. $('#im-pre').val(stage.im_pre ? stage.im_pre : '');
  2163. const typeArr = $('div[name="im-type"]');
  2164. for (const t of typeArr) {
  2165. if (parseInt($(t).attr('im-type')) === stage.im_type) {
  2166. chooseType(t);
  2167. } else {
  2168. validType(t)
  2169. }
  2170. }
  2171. });
  2172. // 提交 中间计量模式
  2173. $('#choose-ok').click(() => {
  2174. const chooseType = _.find($('div[name="im-type"]', '#im-type'), function (it) {
  2175. return it.style.cursor !== 'pointer';
  2176. });
  2177. const data = {
  2178. im_type: parseInt($(chooseType).attr('im-type')),
  2179. im_pre: $('#im-pre').val(),
  2180. };
  2181. postData(window.location.pathname + '/detail/build', data, function (result) {
  2182. stage.im_type = data.im_type;
  2183. stage.im_pre = data.im_pre;
  2184. if (stage.im_type === imType.tz.value || stage.im_type === imType.bb.value) {
  2185. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  2186. jlCol.title = '本期计量金额';
  2187. SpreadJsObj.reLoadSheetHeader(self.sheet);
  2188. $('#type-title-contract').text('本期合同计量金额');
  2189. $('#type-title-qc').text('本期变更计量金额');
  2190. } else {
  2191. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  2192. jlCol.title = '本期计量数量';
  2193. SpreadJsObj.reLoadSheetHeader(self.sheet);
  2194. $('#type-title-contract').text('本期合同计量数量');
  2195. $('#type-title-qc').text('本期变更计量数量');
  2196. }
  2197. if (stage.im_type === imType.bb.value || stage.im_type === imType.bw.value) {
  2198. $('#show-jldy').parent().show();
  2199. $('#jldy').parent().show();
  2200. $('#show-xm-name').parent().hide();
  2201. $('#xm-name').parent().hide();
  2202. } else {
  2203. $('#show-jldy').parent().hide();
  2204. $('#jldy').parent().hide();
  2205. $('#show-xm-name').parent().show();
  2206. $('#xm-name').parent().show();
  2207. }
  2208. // 加载生成数据
  2209. self.reBuildImData();
  2210. $('#choose').modal('hide');
  2211. });
  2212. });
  2213. // 显示树结构信息
  2214. $('#choose2').on('shown.bs.modal', function () {
  2215. if (!self.gsSpread) {
  2216. self.gsSpread = SpreadJsObj.createNewSpread($('#im-gather-spread')[0]);
  2217. const setting = {
  2218. cols: [
  2219. {title: '计量\n汇总', colSpan: '1', rowSpan: '1', field: 'check', hAlign: 1, width: 50, formatter: '@', readOnly: true, cellType: 'checkbox'},
  2220. {title: '项目节编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 150, formatter: '@', readOnly: true, cellType: 'tree'},
  2221. {title: '清单编号', colSpan: '1', rowSpan: '1', field: 'b_code', hAlign: 0, width: 80, formatter: '@', readOnly: true},
  2222. {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 230, formatter: '@', readOnly: true},
  2223. {title: '单位', colSpan: '1', rowSpan: '1', field: 'unit', hAlign: 1, width: 60, formatter: '@', readOnly: true},
  2224. ],
  2225. headRows: 1,
  2226. emptyRows: 0,
  2227. headRowHeight: [32],
  2228. defaultRowHeight: 21,
  2229. headerFont: '12px 微软雅黑',
  2230. font: '12px 微软雅黑',
  2231. };
  2232. sjsSettingObj.setFxTreeStyle(setting, sjsSettingObj.FxTreeStyle.jz);
  2233. SpreadJsObj.initSheet(self.gsSpread.getActiveSheet(), setting);
  2234. self.gsSpread.bind(spreadNS.Events.ButtonClicked, function (e, info) {
  2235. function checkParent(node) {
  2236. const parent = self.gsTree.getParent(node);
  2237. if (parent) {
  2238. return parent.check ? parent.check : checkParent(parent);
  2239. } else {
  2240. return false;
  2241. }
  2242. }
  2243. function checkChildren(node) {
  2244. for (const child of node.children) {
  2245. if (child.check) {
  2246. return true;
  2247. } else if (checkChildren(child)) {
  2248. return true;
  2249. }
  2250. }
  2251. return false;
  2252. }
  2253. if (!$('#im-gather-check')[0].checked) { return; }
  2254. const sheet = info.sheet, cellType = sheet.getCellType(info.row, info.col);
  2255. if (cellType instanceof spreadNS.CellTypes.CheckBox) {
  2256. if (sheet.isEditing()) {
  2257. sheet.endEdit(true);
  2258. }
  2259. }
  2260. if (info.sheet.zh_setting) {
  2261. const col = info.sheet.zh_setting.cols[info.col];
  2262. if (col.field !== 'check') {
  2263. return;
  2264. }
  2265. const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
  2266. const node = sortData[info.row];
  2267. if (!node.check) {
  2268. if (checkParent(node)) {
  2269. const rect = info.sheet.getCellRect(info.row, info.col);
  2270. gatherConfirmPopover.check({
  2271. x: rect.x + rect.width / 2 + 25,
  2272. y: rect.y + rect.height / 2 + 3,
  2273. }, '父项已勾选,继续将取消父项勾选。', function () {
  2274. node.check = true;
  2275. const parents = self.gsTree.getFullPathNodes(self.gsTree.getParent(node).full_path);
  2276. const rows = [self.gsTree.nodes.indexOf(node)];
  2277. for (const p of parents) {
  2278. if (p.check) {
  2279. p.check = false;
  2280. rows.push(self.gsTree.nodes.indexOf(p));
  2281. }
  2282. }
  2283. SpreadJsObj.reLoadRowsData(info.sheet, rows);
  2284. });
  2285. } else if (checkChildren(node)) {
  2286. const rect = info.sheet.getCellRect(info.row, info.col);
  2287. gatherConfirmPopover.check({
  2288. x: rect.x + rect.width / 2 + 25,
  2289. y: rect.y + rect.height / 2 + 3,
  2290. }, '子项已勾选,继续将取消子项勾选。', function () {
  2291. node.check = true;
  2292. const posterity = self.gsTree.getPosterity(node);
  2293. const rows = [self.gsTree.nodes.indexOf(node)];
  2294. for (const p of posterity) {
  2295. if (p.check) {
  2296. rows.push(self.gsTree.nodes.indexOf(p));
  2297. p.check = false;
  2298. }
  2299. }
  2300. SpreadJsObj.reLoadRowsData(info.sheet, rows);
  2301. });
  2302. } else {
  2303. node.check = true;
  2304. SpreadJsObj.reLoadRowsData(info.sheet, [self.gsTree.nodes.indexOf(node)]);
  2305. }
  2306. } else {
  2307. node.check = false;
  2308. SpreadJsObj.reLoadRowsData(info.sheet, [self.gsTree.nodes.indexOf(node)]);
  2309. }
  2310. }
  2311. });
  2312. const gatherNodes = stage.im_gather_node ? _.map(stage.im_gather_node.split(',')) : [];
  2313. for (const node of self.gsTree.datas) {
  2314. node.check = gatherNodes.indexOf(node.id + '') !== -1;
  2315. }
  2316. SpreadJsObj.loadSheetData(self.gsSpread.getActiveSheet(), SpreadJsObj.DataType.Tree, self.gsTree);
  2317. self.gsTree.expandByLevel(4);
  2318. SpreadJsObj.refreshTreeRowVisible(self.gsSpread.getActiveSheet());
  2319. SpreadJsObj.resetFieldReadOnly(self.gsSpread.getActiveSheet, 'check', !$('#im-gather-check')[0].checked);
  2320. } else {
  2321. const gatherNodes = stage.im_gather_node ? _.map(stage.im_gather_node.split(',')) : [];
  2322. for (const node of self.gsTree.datas) {
  2323. node.check = gatherNodes.indexOf(node.id + '') !== -1;
  2324. }
  2325. SpreadJsObj.reLoadColsData(self.gsSpread.getActiveSheet(), [0]);
  2326. }
  2327. });
  2328. // 提交 高级设置
  2329. $('#choose2-ok').click(() => {
  2330. if (!self.gsTree) { return; }
  2331. const nodes = [];
  2332. for (const node of self.gsTree.datas) {
  2333. if (node.check) {
  2334. nodes.push(node.id);
  2335. }
  2336. }
  2337. const data = {
  2338. im_gather: $('#im-gather-check')[0].checked,
  2339. im_gather_node: nodes.join(','),
  2340. };
  2341. postData(window.location.pathname + '/detail/adv', data, function (result) {
  2342. stage.im_gather = data.im_gather;
  2343. stage.im_gather_node = data.im_gather_node;
  2344. $('#choose2').modal('hide');
  2345. });
  2346. });
  2347. }
  2348. _initLocateRela() {
  2349. const self = this;
  2350. $('#im-locate2bills').click(function () {
  2351. const curIndex = parseInt($('#im-locate-info')[0].innerText.split('/')[0]);
  2352. const select = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  2353. if (select && select.source) {
  2354. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), select.source[curIndex-1].id, true);
  2355. stagePosSpreadObj.loadCurPosData();
  2356. }
  2357. });
  2358. $('#im-locate-pre').click(function () {
  2359. const curIndex = parseInt($('#im-locate-info')[0].innerText.split('/')[0]);
  2360. const select = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  2361. if (select && select.source) {
  2362. const targetIndex = math.max(curIndex-1, 1);
  2363. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), select.source[targetIndex-1].id, true);
  2364. stagePosSpreadObj.loadCurPosData();
  2365. $('#im-locate-info')[0].innerText = targetIndex + '/' + select.source.length;
  2366. }
  2367. });
  2368. $('#im-locate-next').click(function () {
  2369. const curIndex = parseInt($('#im-locate-info')[0].innerText.split('/')[0]);
  2370. const select = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  2371. if (select && select.source) {
  2372. const targetIndex = math.min(curIndex+1, select.source.length);
  2373. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), select.source[targetIndex-1].id, true);
  2374. stagePosSpreadObj.loadCurPosData();
  2375. $('#im-locate-info')[0].innerText = targetIndex + '/' + select.source.length;
  2376. }
  2377. });
  2378. }
  2379. _initModifyDetail() {
  2380. const self = this;
  2381. // 编辑
  2382. $('#edit-detail').click(function () {
  2383. $(this).hide();
  2384. $('#save-detail').show();
  2385. $('#cancel-detail').show();
  2386. $('#detail-show').hide();
  2387. $('#detail-edit').show();
  2388. self.updateImageData = null;
  2389. });
  2390. // 保存
  2391. $('#save-detail').click(() => {
  2392. function check(field, obj, org, update) {
  2393. const newValue = obj.val();
  2394. if (!org[field]) {
  2395. if (newValue !== '') {
  2396. update[field] = newValue;
  2397. if (data.custom_define.indexOf(field) === -1) update.custom_define.push(field);
  2398. }
  2399. } else if (newValue !== org[field]){
  2400. update[field] = newValue;
  2401. if (data.custom_define.indexOf(field) === -1) update.custom_define.push(field);
  2402. }
  2403. }
  2404. const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  2405. const updateData = {lid: data.lid, pid: data.pid};
  2406. if (data.uuid) {
  2407. updateData.uuid = data.uuid;
  2408. updateData.custom_define = data.custom_define;
  2409. } else {
  2410. updateData.code = data.code;
  2411. updateData.name = data.name;
  2412. updateData.unit = data.unit;
  2413. updateData.unit_price = data.unit_price;
  2414. updateData.pid = data.pid;
  2415. updateData.pos_name = data.pos_name;
  2416. updateData.custom_define = [];
  2417. }
  2418. check('bw', $('#bw-name'), data, updateData);
  2419. check('peg', $('#peg'), data, updateData);
  2420. check('xm', $('#xm-name'), data, updateData);
  2421. check('position', $('#position'), data, updateData);
  2422. check('jldy', $('#jldy'), data, updateData);
  2423. check('drawing_code', $('#drawing-code'), data, updateData);
  2424. check('calc_memo', $('#calc-memo'), data, updateData);
  2425. updateData.custom_define = updateData.custom_define.join(',');
  2426. postData(window.location.pathname + '/detail/save', updateData, function (result) {
  2427. stageIm.loadUpdateDetailData(result);
  2428. self.reLoadDetailData();
  2429. if (self.updateImageData && !self.updateImageData.uuid) {
  2430. self.updateImageData.uuid = result.uuid;
  2431. postData(window.location.pathname + '/detail/merge-img', self.updateImageData, function (result) {
  2432. stageIm.loadUpdateDetailData(result);
  2433. self.reLoadDetailData();
  2434. });
  2435. }
  2436. });
  2437. if (self.updateImageData && self.updateImageData.uuid) {
  2438. postData(window.location.pathname + '/detail/merge-img', self.updateImageData, function (result) {
  2439. stageIm.loadUpdateDetailData(result);
  2440. self.reLoadDetailData();
  2441. });
  2442. }
  2443. });
  2444. // 取消
  2445. $('#cancel-detail').click(() => {
  2446. self.reLoadDetailData();
  2447. });
  2448. }
  2449. _initImageRela() {
  2450. const self = this;
  2451. $('#edit-detail').click(function () {
  2452. loadImageItem();
  2453. });
  2454. function setdraggrable(){
  2455. $( ".img-item" ).draggable({ containment: "parent" },{stop: function( event, ui ) {
  2456. }}).resizable({ containment: "parent" },{ handles: 'n, e, s, w, ne, se, sw, nw' },{ maxWidth: parseFloat($('#imgwidth').val())},{maxHeight: parseFloat($('#imgheight').val())},{
  2457. stop: function( event, ui ) {
  2458. }
  2459. });
  2460. }
  2461. // 移动图片
  2462. const moveImageItem = function (ev) {
  2463. const item = this;
  2464. const view = $('.img-view')[0];
  2465. let oEvent = ev;
  2466. // 浏览器有一些图片的默认事件,这里要阻止
  2467. oEvent.preventDefault();
  2468. let disX = oEvent.clientX - item.offsetLeft;
  2469. let disY = oEvent.clientY - item.offsetTop;
  2470. view.onmousemove = function (ev) {
  2471. oEvent = ev;
  2472. oEvent.preventDefault();
  2473. let x = oEvent.clientX -disX;
  2474. let y = oEvent.clientY -disY;
  2475. // 图形移动的边界判断
  2476. x = x <= 0 ? 0 : x;
  2477. x = x >= view.offsetWidth - item.offsetWidth ? view.offsetWidth - item.offsetWidth : x;
  2478. y = y <= 0 ? 0 : y;
  2479. y = y >= view.offsetHeight - item.offsetHeight ? view.offsetHeight - item.offsetHeight : y;
  2480. item.style.left = x + 'px';
  2481. item.style.top = y + 'px';
  2482. };
  2483. // 图形移出父盒子取消移动事件,防止移动过快触发鼠标移出事件,导致鼠标弹起事件失效
  2484. view.onmouseleave = function () {
  2485. view.onmousemove = null;
  2486. view.onmouseup = null;
  2487. };
  2488. // 鼠标弹起后停止移动
  2489. view.onmouseup=function() {
  2490. view.onmousemove = null;
  2491. view.onmouseup = null;
  2492. };
  2493. };
  2494. const removeImageItem = function () {
  2495. $(this).parent().remove();
  2496. };
  2497. // 加载草图组成
  2498. const loadImageItem = function () {
  2499. self.updateImageData = null;
  2500. const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  2501. const items = data.calc_img_org ? JSON.parse(data.calc_img_org) : [];
  2502. const html = [];
  2503. for (const item of items) {
  2504. const itemStyle = 'top:' + item.top + ';' + 'left:' + item.left + ';' + 'width:' + item.width + ';' + 'height:' + item.height + ';';
  2505. html.push('<div class="img-item" style="' + itemStyle + '">');
  2506. html.push('<div class="img-bar">');
  2507. html.push('<a href="javascript: void(0);" class="text-danger" title="删除"><i class="fa fa-remove" style="font-size: 24px"></i></a>');
  2508. html.push('</div>');
  2509. html.push('<div class="focus" style="width:100%; height:100%"><img src="', item.src, '" id="draggable" style="width:100%; height:100%"></div>');
  2510. html.push('</div>');
  2511. }
  2512. $('.img-view').html(html.join(''));
  2513. $('.img-bar').click(removeImageItem);
  2514. setdraggrable();
  2515. };
  2516. // 上传图片
  2517. $('#upload-img').click(function () {
  2518. $('#upload-img-file').trigger('click');
  2519. });
  2520. $('#upload-img-file').change(function () {
  2521. const file = this.files[0];
  2522. const ext = file.name.toLowerCase().split('.').splice(-1)[0];
  2523. const imgStr = /(jpg|jpeg|png|bmp|BMP|JPG|PNG|JPEG)$/;
  2524. if (!imgStr.test(ext)) {
  2525. toastr.error('请上传正确的图片格式文件');
  2526. return
  2527. }
  2528. if ($(this).val()) {
  2529. const formData = new FormData();
  2530. formData.append('file', this.files[0]);
  2531. postDataWithFile(window.location.pathname + '/detail/add-img', formData, function (result) {
  2532. const html = [];
  2533. html.push('<div class="img-item">');
  2534. html.push('<div class="img-bar">');
  2535. html.push('<a href="javascript: void(0);" class="text-danger" title="删除"><i class="fa fa-remove" style="font-size: 24px"></i></a>');
  2536. html.push('</div>');
  2537. html.push('<div class="focus" style="width:100%; height:100%"><img src="', '/' + result, '" id="draggable" style="width:100%; height:100%"></div>');
  2538. html.push('</div>');
  2539. $('.img-view').append(html.join(''));
  2540. $('.img-bar').click(removeImageItem);
  2541. setdraggrable();
  2542. $('#upload-img-file').val('');
  2543. });
  2544. }
  2545. });
  2546. // 保存草图修改结果
  2547. $('#edit-img-ok').click(function () {
  2548. // 记录上传的图片的信息
  2549. const items = $('.img-item');
  2550. const img_remark = $('#text-edit').val()
  2551. const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  2552. if (items.length > 0) {
  2553. const itemInfo = [];
  2554. for (const item of items) {
  2555. const itemData = {
  2556. src: $('img', item).attr('src'),
  2557. left: item.style.left,
  2558. top: item.style.top,
  2559. width: item.style.width,
  2560. height: item.style.height,
  2561. };
  2562. itemInfo.push(itemData);
  2563. }
  2564. // 获取合并好的图片数据
  2565. const canvas = document.createElement('canvas');
  2566. const view = $('.img-view')[0];
  2567. canvas.height = view.clientHeight;
  2568. canvas.width = view.clientWidth;
  2569. const ctx = canvas.getContext('2d');
  2570. ctx.fillStyle = '#ffffff';
  2571. ctx.fillRect(0, 0, canvas.width, canvas.height);
  2572. for (const b of $('.img-item')) {
  2573. const pos = $(b).position();
  2574. const img = $('img', b)[0];
  2575. ctx.drawImage(img, pos.left, pos.top, img.width, img.height);
  2576. }
  2577. // 生成上传数据
  2578. const updateData = {updateType: 'update', lid: data.lid, pid: data.pid};
  2579. if (data.uuid) {
  2580. updateData.uuid = data.uuid;
  2581. }
  2582. if (data.custom_define.indexOf('calc_img') === -1) {
  2583. updateData.custom_define = data.custom_define;
  2584. updateData.custom_define.push('calc_img');
  2585. updateData.custom_define = updateData.custom_define.join(',');
  2586. }
  2587. updateData.img = canvas.toDataURL('image/png');
  2588. updateData.imgInfo = itemInfo;
  2589. updateData.calc_img_remark = img_remark;
  2590. self.updateImageData = updateData;
  2591. $('#calc-img').attr('src', updateData.img);
  2592. $('#view-calc-img').attr('src', updateData.img);
  2593. $('#show-calc-img').attr('src', updateData.img);
  2594. $('#view-calc-remark').text(img_remark);
  2595. $('#edit-img').modal('hide');
  2596. // updateImageData = updateData;
  2597. // $('#edit-img').modal('hide');
  2598. // postData(window.location.pathname + '/detail/merge-img', updateData, function (result) {
  2599. // stageIm.loadUpdateDetailData(result);
  2600. // data.calc_img = result.calc_img;
  2601. // data.calc_img_org = result.calc_img_org;
  2602. // const calcImgSrc = data && data.calc_img ? '/' + data.calc_img : '';
  2603. // $('#show-calc-img').attr('src', calcImgSrc);
  2604. // $('#calc-img').attr('src', calcImgSrc);
  2605. // $('#view-calc-img').attr('src', calcImgSrc);
  2606. // $('#edit-img').modal('hide');
  2607. // });
  2608. } else if (data.calc_img) {
  2609. self.updateImageData = {updateType: 'clear', lid: data.lid, pid: data.pid, uuid: data.uuid};
  2610. $('#show-calc-img').attr('src', '');
  2611. $('#calc-img').attr('src', '');
  2612. $('#view-calc-img').attr('src', '');
  2613. $('#view-calc-remark').val('');
  2614. $('#text-edit').val('')
  2615. $('#edit-img').modal('hide');
  2616. // postData(window.location.pathname + '/detail/merge-img', {updateType: 'clear', lid: data.lid, pid: data.pid, uuid: data.uuid}, function (result) {
  2617. // stageIm.loadUpdateDetailData(result);
  2618. // data.calc_img = result.calc_img;
  2619. // data.calc_img_org = result.calc_img_org;
  2620. // const calcImgSrc = data && data.calc_img ? '/' + data.calc_img : '';
  2621. // $('#show-calc-img').attr('src', calcImgSrc);
  2622. // $('#calc-img').attr('src', calcImgSrc);
  2623. // $('#view-calc-img').attr('src', calcImgSrc);
  2624. // $('#edit-img').modal('hide');
  2625. // });
  2626. } else {
  2627. self.updateImageData = null;
  2628. $('#show-calc-img').attr('src', '');
  2629. $('#calc-img').attr('src', '');
  2630. $('#view-calc-img').attr('src', '');
  2631. $('#view-calc-remark').val('');
  2632. $('#text-edit').val('')
  2633. $('#edit-img').modal('hide');
  2634. }
  2635. });
  2636. }
  2637. reBuildImData() {
  2638. const imData = stageIm.buildImData();
  2639. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  2640. this.reLoadDetailData();
  2641. this.loadLocateInfo();
  2642. }
  2643. loadStageLedgerUpdateData(data) {
  2644. const imData = stageIm.loadUpdateLedgerData(data);
  2645. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  2646. this.reLoadDetailData();
  2647. }
  2648. loadStagePosUpdateData(data) {
  2649. const imData = stageIm.loadUpdatePosData(data);
  2650. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  2651. this.reLoadDetailData();
  2652. }
  2653. loadStageChangeUpdateData(data) {
  2654. const imData = stageIm.loadUpdateChangeData(data);
  2655. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  2656. this.reLoadDetailData();
  2657. }
  2658. loadLocateInfo() {
  2659. const select = SpreadJsObj.getSelectObject(this.sheet);
  2660. if (select && select.source.length > 1) {
  2661. $('#im-locate2bills').next().show();
  2662. } else {
  2663. $('#im-locate2bills').next().hide();
  2664. }
  2665. $('#im-locate-info')[0].innerText = '1/' + (select ? select.source.length : '0');
  2666. }
  2667. reLoadDetailData() {
  2668. const data = SpreadJsObj.getSelectObject(this.spread.getActiveSheet());
  2669. if (data) {
  2670. $('#edit-detail').show();
  2671. $('#modify-img').show();
  2672. } else {
  2673. $('#edit-detail').hide();
  2674. $('#modify-img').hide();
  2675. }
  2676. $('#save-detail').hide();
  2677. $('#cancel-detail').hide();
  2678. $('#detail-show').show();
  2679. $('#detail-edit').hide();
  2680. const contractJl = data && data.contract_jl ? data.contract_jl : '';
  2681. $('#show-contract-jl').text(contractJl);
  2682. $('#contract-jl').val(contractJl);
  2683. const qcJl = data && data.qc_jl ? data.qc_jl : '';
  2684. $('#show-qc-jl').text(qcJl);
  2685. $('#qc-jl').val(qcJl);
  2686. const bglCode = data && data.bgl_code ? data.bgl_code : '';
  2687. $('#show-bgl-code').text(bglCode);
  2688. $('#bgl-code').val(bglCode);
  2689. const bglDrawingCode = data && data.bgl_drawing_code ? data.bgl_drawing_code : '';
  2690. $('#show-bgl-drawing-code').text(bglDrawingCode);
  2691. $('#bgl-drawing-code').val(bglDrawingCode);
  2692. const bwName = data && data.bw ? data.bw : '';
  2693. $('#show-bw-name').text(bwName);
  2694. $('#bw-name').val(bwName);
  2695. const position = data && data.position ? data.position : '';
  2696. $('#show-position').text(position);
  2697. $('#position').val(position);
  2698. const peg = data && data.peg ? data.peg : '';
  2699. $('#show-peg').text(peg);
  2700. $('#peg').val(peg);
  2701. const xmName = data && data.xm ? data.xm: '';
  2702. $('#show-xm-name').text(xmName);
  2703. $('#xm-name').val(xmName);
  2704. const jldy = data && data.jldy ? data.jldy: '';
  2705. $('#show-jldy').text(jldy);
  2706. $('#jldy').val(jldy);
  2707. const drawingCode = data && data.drawing_code ? data.drawing_code: '';
  2708. $('#show-drawing-code').text(drawingCode);
  2709. $('#drawing-code').val(drawingCode);
  2710. const calcMemo = data && data.calc_memo ? data.calc_memo: '';
  2711. $('#show-calc-memo').html(calcMemo.replace(/\n/g, '<br/>'));
  2712. $('#calc-memo').val(calcMemo);
  2713. const calcImgSrc = data && data.calc_img ? '/' + data.calc_img : '';
  2714. $('#show-calc-img').attr('src', calcImgSrc);
  2715. $('#calc-img').attr('src', calcImgSrc);
  2716. $('#view-calc-img').attr('src', calcImgSrc);
  2717. const calcImgRemark = data && data.calc_img_remark || '';
  2718. $('#view-calc-remark').val(calcImgRemark);
  2719. $("#view-calc-remark").attr('readonly', true);
  2720. // 处理 编辑 -> 添加草图中textarea多余的空格
  2721. $('#text-edit').val(calcImgRemark)
  2722. }
  2723. }
  2724. class CheckedChange {
  2725. constructor (setting) {
  2726. const self = this;
  2727. this.changeSpreadSetting = {
  2728. cols: [
  2729. {title: '变更令号', colSpan: '1', rowSpan: '1', field: 'p_code', hAlign: 0, width: 100, formatter: '@'},
  2730. {title: '变更名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 180, formatter: '@'},
  2731. {title: '金额', colSpan: '1', rowSpan: '1', field: 'total_price', hAlign: 2, width: 80, type: 'Number'},
  2732. {title: '批复文号', colSpan: '1', rowSpan: '1', field: 'w_code', hAlign: 0, width: 100, formatter: '@'},
  2733. ],
  2734. emptyRows: 0,
  2735. headRows: 1,
  2736. headRowHeight: [32],
  2737. headColWidth: [30],
  2738. defaultRowHeight: 21,
  2739. headerFont: '12px 微软雅黑',
  2740. font: '12px 微软雅黑',
  2741. readOnly: true,
  2742. };
  2743. this.changeSpread = SpreadJsObj.createNewSpread(setting.changeObj[0]);
  2744. this.changeSheet = this.changeSpread.getActiveSheet();
  2745. SpreadJsObj.initSheet(this.changeSheet, this.changeSpreadSetting);
  2746. this.changeBillsSpreadSetting = {
  2747. cols: [
  2748. {title: '清单编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 80, formatter: '@'},
  2749. {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 150, type: 'Number'},
  2750. {title: '单位', colSpan: '1', rowSpan: '1', field: 'unit', hAlign: 1, width: 50, formatter: '@'},
  2751. {title: '单价', colSpan: '1', rowSpan: '1', field: 'unit_price', hAlign: 2, width: 60, type: 'Number'},
  2752. {title: '数量', colSpan: '1', rowSpan: '1', field: 'qty', hAlign: 2, width: 60, formatter: '@'},
  2753. {title: '金额', colSpan: '1', rowSpan: '1', field: 'tp', hAlign: 2, width: 60, formatter: '@'},
  2754. {title: '变更部位', colSpan: '1', rowSpan: '1', field: 'bwmx', hAlign: 0, width: 100, formatter: '@'},
  2755. ],
  2756. emptyRows: 0,
  2757. headRows: 1,
  2758. headRowHeight: [32],
  2759. defaultRowHeight: 21,
  2760. headerFont: '12px 微软雅黑',
  2761. font: '12px 微软雅黑',
  2762. readOnly: true
  2763. };
  2764. this.changeBillsSpread = SpreadJsObj.createNewSpread(setting.changeBillsObj[0]);
  2765. this.changeBillsSheet = this.changeBillsSpread.getActiveSheet();
  2766. SpreadJsObj.initSheet(this.changeBillsSheet, this.changeBillsSpreadSetting);
  2767. this.changeSheet.bind(spreadNS.Events.SelectionChanged, function (e, info) {
  2768. const change = SpreadJsObj.getSelectObject(self.changeSheet);
  2769. if (change.cid === self.curChangeId) { return; }
  2770. self.curChangeId = change.cid;
  2771. if (change.detail) {
  2772. self.loadChangeDetailData();
  2773. } else {
  2774. postData(window.location.pathname + '/change/detail', {cid: change.cid}, function (result) {
  2775. change.detail = result;
  2776. self.analyzeChange(change);
  2777. self.loadChangeDetailData();
  2778. });
  2779. }
  2780. });
  2781. this.changes = null;
  2782. this.reloadChangeData();
  2783. setting.reloadObj.click(function() {
  2784. self.reloadChangeData();
  2785. });
  2786. }
  2787. loadChangeDetailData() {
  2788. const change = SpreadJsObj.getSelectObject(this.changeSheet);
  2789. if (change) {
  2790. SpreadJsObj.loadSheetData(this.changeBillsSheet, SpreadJsObj.DataType.Data, change.bills);
  2791. } else {
  2792. SpreadJsObj.loadSheetData(this.changeBillsSheet, SpreadJsObj.DataType.Data, []);
  2793. }
  2794. }
  2795. refresh() {
  2796. this.changeSpread.refresh();
  2797. this.changeBillsSpread.refresh();
  2798. }
  2799. reloadChangeData() {
  2800. const self = this;
  2801. postData(window.location.pathname + '/change/data', null, function (result) {
  2802. self.changes = result.changes;
  2803. SpreadJsObj.loadSheetData(self.changeSheet, SpreadJsObj.DataType.Data, self.changes);
  2804. self.changeSheet.setSelection(0, 0, 1, 1);
  2805. if (self.changes.length > 0) self.analyzeChange(result.changes[0]);
  2806. self.loadChangeDetailData();
  2807. });
  2808. }
  2809. analyzeChange(change) {
  2810. change.bills = change.detail.bills;
  2811. for (const b of change.bills) {
  2812. const aub = change.detail.addUsedBills.find(function (x) {
  2813. return x.id === b.id;
  2814. });
  2815. if (aub) {
  2816. b.used_qty = aub.used_qty;
  2817. }
  2818. b.qty = _.toNumber(b.samount);
  2819. b.valid_qty = ZhCalc.sub(b.qty, b.used_qty);
  2820. b.tp = ZhCalc.round(ZhCalc.mul(b.qty, b.unit_price), tenderInfo.decimal.tp);
  2821. b.pos = _.filter(change.detail.curUsedBills, {cbid: b.id});
  2822. b.cur_qty = 0;
  2823. for (const p of b.pos) {
  2824. p.f_qty = p.p_qty ? p.p_qty : p.l_qty;
  2825. b.cur_qty = ZhCalc.add(b.cur_qty, p.qty);
  2826. }
  2827. }
  2828. }
  2829. }
  2830. // 展开收起附件
  2831. $('a', '.right-nav').bind('click', function () {
  2832. //const main = $('#main-view'), tool = $('#tools-view');
  2833. const tab = $(this), tabPanel = $(tab.attr('content'));
  2834. if (!tab.hasClass('active')) {
  2835. $('a', '.side-menu').removeClass('active');
  2836. $('.tab-content .tab-select-show').removeClass('active');
  2837. tab.addClass('active');
  2838. tabPanel.addClass('active');
  2839. showSideTools(tab.hasClass('active'));
  2840. if (tab.attr('content') === '#search' && !searchLedger) {
  2841. searchLedger = $.billsSearch({
  2842. selector: '#search',
  2843. searchSpread: slSpread,
  2844. searchRangeStr: '项目节编号/名称',
  2845. searchOver: true,
  2846. searchEmpty: true,
  2847. resultSpreadSetting: {
  2848. cols: [
  2849. {title: '项目节编号', field: 'code', hAlign: 0, width: 90, formatter: '@'},
  2850. {title: '清单编号', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
  2851. {title: '名称', field: 'name', width: 150, hAlign: 0, formatter: '@'},
  2852. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@'},
  2853. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  2854. {title: '数量', field: 'quantity', hAlign: 2, width: 50},
  2855. {title: '完成率(%)', field: 'complete_percent', hAlign: 2, width: 70},
  2856. ],
  2857. emptyRows: 0,
  2858. headRows: 1,
  2859. headRowHeight: [32],
  2860. headColWidth: [30],
  2861. defaultRowHeight: 21,
  2862. headerFont: '12px 微软雅黑',
  2863. font: '12px 微软雅黑',
  2864. selectedBackColor: '#fffacd',
  2865. },
  2866. afterLocated: function () {
  2867. stagePosSpreadObj.loadCurPosData();
  2868. },
  2869. customSearch: [
  2870. {
  2871. key: 'less', title: '漏计', valid: true,
  2872. check: function (node) {
  2873. if (node.quantity) {
  2874. return ZhCalc.sub(ZhCalc.add(node.quantity, node.end_qc_qty), node.end_gather_qty) > 0;
  2875. } else if (node.total_price) {
  2876. return ZhCalc.sub(ZhCalc.add(node.total_price, node.end_qc_tp), node.end_gather_tp) > 0;
  2877. }
  2878. }
  2879. }, {
  2880. key: 'over', title: '超计', valid: true,
  2881. check: function (node) {
  2882. const posRange = stagePos.ledgerPos[itemsPre + node.id] || [];
  2883. if (posRange.length > 0) {
  2884. for (const p of posRange) {
  2885. if (p.end_contract_qty > p.quantity) return true;
  2886. }
  2887. return false;
  2888. } else if (node.end_gather_qty) {
  2889. return !node.quantity || Math.abs(node.end_gather_qty) > Math.abs(ZhCalc.add(node.quantity, node.end_qc_qty));
  2890. } else if (node.end_gather_tp) {
  2891. return !node.total_price || Math.abs(node.end_gather_tp) > Math.abs(ZhCalc.add(node.total_price, node.end_qc_tp));
  2892. }
  2893. }
  2894. }, {
  2895. key: 'empty', title: '漏计', valid: false,
  2896. check: function (node) {
  2897. if (node.quantity) {
  2898. return !node.end_gather_qty || checkZero(node.end_gather_qty);
  2899. } else if (node.total_price) {
  2900. return !node.end_gather_tp || checkZero(node.end_gather_tp);
  2901. }
  2902. }
  2903. }, {
  2904. key: 'estimate', title: '预计变更', valid: true,
  2905. check: function (node) {
  2906. const posRange = stagePos.ledgerPos[itemsPre + node.id] || [];
  2907. if (posRange.length > 0) {
  2908. for (const p of posRange) {
  2909. if (!checkZero(p.estimate_qty)) return true;
  2910. }
  2911. return false;
  2912. } else {
  2913. return false;
  2914. }
  2915. }
  2916. }
  2917. ],
  2918. });
  2919. searchLedger.spread.refresh();
  2920. }
  2921. if (tab.attr('content') === '#fujian') {
  2922. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2923. getNodeList(node.id);
  2924. }
  2925. if (tab.attr('content') === '#zhongjian') {
  2926. if (!detail) {
  2927. detail = new Detail($('#detail-spread'));
  2928. detail.spread.refresh();
  2929. $('#zhongjian .sjs-bottom').height('400px');
  2930. $('.zhongjian-msg').height($('#zhongjian .sjs-bottom').height());
  2931. } else {
  2932. detail.spread.refresh();
  2933. $('#zhongjian .sjs-bottom').height('400px');
  2934. $('.zhongjian-msg').height($('#zhongjian .sjs-bottom').height());
  2935. }
  2936. }
  2937. if (tab.attr('content') === '#checked-change') {
  2938. if (!checkedChanges) {
  2939. checkedChanges = new CheckedChange({
  2940. changeObj: $('#cc-spread'),
  2941. changeBillsObj: $('#ccb-spread'),
  2942. reloadObj: $('#refresh-cc'),
  2943. });
  2944. checkedChanges.refresh();
  2945. } else {
  2946. $('#ccb-spread').height('400px');
  2947. checkedChanges.refresh();
  2948. }
  2949. }
  2950. if (tab.attr('content') === '#error-list') {
  2951. errorList.spread.refresh();
  2952. }
  2953. } else {
  2954. tab.removeClass('active');
  2955. tabPanel.removeClass('active');
  2956. showSideTools(tab.hasClass('active'));
  2957. }
  2958. slSpread.refresh();
  2959. spSpread.refresh();
  2960. });
  2961. // 切换附件里节点和所有附件
  2962. $('#fujian .nav-link').on('click', function () {
  2963. const tabPanel = $(this).attr('fujian-content');
  2964. if (tabPanel !== 'syfujian') {
  2965. $('#showPage').hide();
  2966. } else {
  2967. $('#showPage').show();
  2968. }
  2969. $('#showAttachment').hide();
  2970. });
  2971. // 上传附件
  2972. $('#upload-file-btn').click(function () {
  2973. if (curAuditor && curAuditor.aid !== cur_uid) {
  2974. return toastr.error('当前操作没有权限!');
  2975. }
  2976. const files = $('#upload-file')[0].files;
  2977. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2978. const formData = new FormData();
  2979. formData.append('lid', node.id);
  2980. for (const file of files) {
  2981. if (file === undefined) {
  2982. toastr.error('未选择上传文件!');
  2983. return false;
  2984. }
  2985. const filesize = file.size;
  2986. if (filesize > 30 * 1024 * 1024) {
  2987. toastr.error('存在上传文件大小过大!');
  2988. return false;
  2989. }
  2990. const fileext = '.' + file.name.toLowerCase().split('.').splice(-1)[0];
  2991. if (whiteList.indexOf(fileext) === -1) {
  2992. toastr.error('只能上传指定格式的附件!');
  2993. return false;
  2994. }
  2995. formData.append('size', filesize);
  2996. formData.append('file[]', file);
  2997. }
  2998. postDataWithFile('/tender/' + tender.id + '/measure/stage/' + stage.order + '/upload/file', formData, function (data) {
  2999. $('#upload').modal('hide');
  3000. // 插入到attData中
  3001. attData = data.concat(attData);
  3002. // 重新生成List
  3003. getAllList();
  3004. getNodeList(node.id);
  3005. }, function () {
  3006. toastr.error('附件上传失败');
  3007. });
  3008. $('#upload-file').val('');
  3009. });
  3010. // 获取附件信息
  3011. $('body').on('click', '.list-table a', function () {
  3012. const fid = $(this).attr('file-id');
  3013. if ($('#showAttachment').attr('file-id') === fid && !$('#showAttachment').is(":hidden")) {
  3014. return;
  3015. }
  3016. const att = attData.find(function (item) {
  3017. return item.id === parseInt(fid);
  3018. });
  3019. $('#edit-att').hide();
  3020. $('#show-att').show();
  3021. if (att !== undefined) {
  3022. // 进来先把编辑功能隐藏
  3023. $('#btn-att a').eq(3).hide()
  3024. $('#show-att tr').eq(0).children('td').text(att.filename + att.fileext);
  3025. const name = att.code !== null && att.code !== '' ? att.code : (att.b_code !== null ? att.b_code : '');
  3026. $('#show-att tr').eq(1).children('td').text($.trim(name + ' ' + att.lname));
  3027. $('#show-att tr').eq(2).find('a').attr('href', '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + att.id);
  3028. // $('#show-att tr').eq(2).find('a').attr('href', att.filepath);
  3029. $('#show-att tr').eq(3).children('td').eq(0).text(att.username);
  3030. $('#show-att tr').eq(3).children('td').eq(1).text(att.in_time);
  3031. $('#show-att tr').eq(4).children('td').text(att.remark);
  3032. // 附件uid等于当前用户id, 附件上传本人
  3033. if (parseInt(cur_uid) === att.uid) {
  3034. $('#btn-att').show();
  3035. let showDel = false;
  3036. if (!curAuditor) {
  3037. stage.status === auditConst.status.checked && parseInt(att.re_upload) && (showDel = true)
  3038. stage.status === auditConst.status.uncheck && parseInt(cur_uid) === stage.user_id && (showDel = true)
  3039. stage.status === auditConst.status.checkNo && parseInt(cur_uid) === stage.user_id && (showDel = true)
  3040. } else {
  3041. curAuditor.aid === parseInt(cur_uid) && (showDel = true)
  3042. }
  3043. if (showDel) $('#btn-att a').eq(3).show();
  3044. // $('#btn-att a').eq(3).show();
  3045. $('#btn-att a').eq(2).hide();
  3046. $('#btn-att a').eq(4).hide();
  3047. $('#btn-att a').eq(5).hide();
  3048. } else {
  3049. $('#btn-att').hide();
  3050. $('#btn-att a').eq(3).hide();
  3051. $('#btn-att a').eq(2).hide();
  3052. $('#btn-att a').eq(4).hide();
  3053. $('#btn-att a').eq(5).hide();
  3054. }
  3055. $('#showAttachment').attr('file-id', fid);
  3056. $('#showAttachment').show();
  3057. } else {
  3058. $('#showAttachment').hide();
  3059. $('#showAttachment').attr('file-id', '');
  3060. toastr.error('附件信息获取失败');
  3061. }
  3062. });
  3063. // $('body').on('click', '.alllist-table a', handleFileList);
  3064. $('body').on('click', '#btn-att a', function () {
  3065. const content = $(this).attr('content');
  3066. const fid = $('#showAttachment').attr('file-id');
  3067. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  3068. if (content === 'edit') {
  3069. $('#btn-att a').eq(3).hide();
  3070. $('#btn-att a').eq(2).show();
  3071. $('#btn-att a').eq(4).show();
  3072. $('#btn-att a').eq(5).show();
  3073. $('#show-att').hide();
  3074. $('#edit-att').show();
  3075. const att = attData.find(function (item) {
  3076. return item.id === parseInt(fid);
  3077. });
  3078. $('#edit-att .form-group').eq(0).find('input').val(att.filename);
  3079. $('#edit-att .form-group').eq(0).find('span').eq(1).text(att.fileext);
  3080. const name = att.code !== null && att.code !== '' ? att.code : (att.b_code !== null ? att.b_code : '');
  3081. $('#edit-att .form-group').eq(1).find('input').val($.trim(name + ' ' + att.lname));
  3082. $('#edit-att .form-group').eq(2).find('input').val(att.in_time);
  3083. $('#edit-att .form-group').eq(3).find('input').val(att.remark);
  3084. } else if (content === 'cancel') {
  3085. $('#show-att').show();
  3086. $('#edit-att').hide();
  3087. $('#btn-att a').eq(3).show();
  3088. $('#btn-att a').eq(2).hide();
  3089. $('#btn-att a').eq(4).hide();
  3090. $('#btn-att a').eq(5).hide();
  3091. } else if (content === 'save') {
  3092. const formData = new FormData();
  3093. formData.append('id', fid);
  3094. formData.append('filename', $('#edit-att .form-group').eq(0).find('input').val());
  3095. formData.append('fileext', $('#edit-att .form-group').eq(0).find('span').eq(1).text());
  3096. formData.append('remark', $('#edit-att .form-group').eq(3).find('input').val());
  3097. const file = $('#change-att-btn')[0];
  3098. if (file.files[0] !== undefined) {
  3099. const filesize = file.files[0].size;
  3100. formData.append('size', filesize);
  3101. formData.append('file', file.files[0]);
  3102. }
  3103. postDataWithFile('/tender/' + tender.id + '/measure/stage/' + stage.order + '/save/file', formData, function (data) {
  3104. // 替换到attData中
  3105. const att_index = attData.findIndex(function (item) {
  3106. return item.id === parseInt(fid);
  3107. });
  3108. attData.splice(att_index, 1, data);
  3109. // 重新生成List
  3110. getAllList(parseInt($('#currentPage').text()));
  3111. getNodeList(node.id);
  3112. $('#show-att').show();
  3113. $('#edit-att').hide();
  3114. $('#show-att tr').eq(0).children('td').text(data.filename + data.fileext);
  3115. const name = data.code !== null && data.code !== '' ? data.code : (data.b_code !== null ? data.b_code : '');
  3116. $('#show-att tr').eq(1).children('td').text($.trim(name + ' ' + data.lname));
  3117. $('#show-att tr').eq(2).find('a').attr('href', '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + data.id);
  3118. $('#show-att tr').eq(3).children('td').eq(0).text(data.username);
  3119. $('#show-att tr').eq(3).children('td').eq(1).text(data.in_time);
  3120. $('#show-att tr').eq(4).children('td').text(data.remark);
  3121. $('#btn-att a').eq(3).show();
  3122. $('#btn-att a').eq(2).hide();
  3123. $('#btn-att a').eq(4).hide();
  3124. $('#btn-att a').eq(5).hide();
  3125. }, function () {
  3126. toastr.error('附件上传失败');
  3127. });
  3128. $('#change-att-btn').val('');
  3129. } else if (content === 'del') {
  3130. const data = {id: fid};
  3131. postData('/tender/' + tender.id + '/measure/stage/' + stage.order + '/delete/file', data, function (result) {
  3132. // 删除到attData中
  3133. const att_index = attData.findIndex(function (item) {
  3134. return item.id === parseInt(fid);
  3135. });
  3136. attData.splice(att_index, 1);
  3137. // 重新生成List
  3138. if ($('#alllist-table tr').length === 1) {
  3139. getAllList(parseInt($('#currentPage').text()) - 1);
  3140. } else {
  3141. getAllList(parseInt($('#currentPage').text()));
  3142. }
  3143. getNodeList(node.id);
  3144. $('#showAttachment').hide();
  3145. $('#showAttachment').attr('file-id', '');
  3146. });
  3147. } else if (content === 'view') {
  3148. const data = {id: fid};
  3149. postData('/tender/' + tender.id + '/measure/stage/' + stage.order + '/check/file', data, function (result) {
  3150. const { filepath } = result
  3151. $('#load-file').attr('href', filepath);
  3152. $('#load-file')[0].click();
  3153. // $('#show-att tr').eq(2).find('a').attr('href', filepath)
  3154. // $('#show-att tr').eq(2).find('a').children('span').eq(0).trigger('click')
  3155. });
  3156. } else if (content === 'location') {
  3157. const att = attData.find(item => item.id === parseInt(fid));
  3158. if (Object.keys(att).length) {
  3159. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), att.ledger_id, true);
  3160. stagePosSpreadObj.loadCurPosData();
  3161. }
  3162. }
  3163. });
  3164. // 替换附件
  3165. $('#change-att-btn').on('change', function () {
  3166. const file = $('#change-att-btn')[0].files[0];
  3167. const name = file.name;
  3168. const filename = name.substring(0, name.lastIndexOf("."));
  3169. const fileext = name.substr(name.indexOf("."));
  3170. const filesize = file.size;
  3171. if (filesize > 10 * 1024 * 1024) {
  3172. toastr.error('文件大小过大!');
  3173. $('#change-att-btn').val('');
  3174. return false;
  3175. }
  3176. if (whiteList.indexOf(fileext) === -1) {
  3177. toastr.error('只能上传指定格式的附件!');
  3178. $('#change-att-btn').val('');
  3179. return false;
  3180. }
  3181. $('#edit-att .form-group').eq(0).find('input').val(filename);
  3182. $('#edit-att .form-group').eq(0).find('span').eq(1).text(fileext);
  3183. });
  3184. // 切换页数
  3185. $('.page-select').on('click', function () {
  3186. const totalPageNum = parseInt($('#totalPage').text());
  3187. const lastPageNum = parseInt($('#currentPage').text());
  3188. const status = $(this).attr('content');
  3189. if (status === 'pre' && lastPageNum > 1) {
  3190. getAllList(lastPageNum-1);
  3191. $('#showAttachment').hide();
  3192. } else if (status === 'next' && lastPageNum < totalPageNum) {
  3193. getAllList(lastPageNum+1);
  3194. $('#showAttachment').hide();
  3195. }
  3196. });
  3197. // 显示层次
  3198. (function (select, sheet) {
  3199. $(select).click(function () {
  3200. if (!sheet.zh_tree) return;
  3201. const tag = $(this).attr('tag');
  3202. const tree = sheet.zh_tree;
  3203. switch (tag) {
  3204. case "1":
  3205. case "2":
  3206. case "3":
  3207. case "4":
  3208. case "5":
  3209. tree.expandByLevel(parseInt(tag));
  3210. SpreadJsObj.refreshTreeRowVisible(sheet);
  3211. break;
  3212. case "last":
  3213. tree.expandByCustom(() => { return true; });
  3214. SpreadJsObj.refreshTreeRowVisible(sheet);
  3215. break;
  3216. case "leafXmj":
  3217. tree.expandToLeafXmj();
  3218. SpreadJsObj.refreshTreeRowVisible(sheet);
  3219. break;
  3220. case "curMeasure":
  3221. tree.expandByCustom(function (node) {
  3222. for (const field of ['contract_tp', 'qc_tp', 'gather_tp']) {
  3223. if (node[field]) {
  3224. return true;
  3225. }
  3226. }
  3227. return false;
  3228. });
  3229. SpreadJsObj.refreshTreeRowVisible(sheet);
  3230. break;
  3231. }
  3232. });
  3233. })('a[name=showLevel]', slSpread.getActiveSheet());
  3234. const dataChecker = DataChecker({
  3235. checkUrl: window.location.pathname + '/check',
  3236. completeData: function (data) {
  3237. stagePos.updateDatas({pos: data.source.pos});
  3238. const refreshData = stageTree.loadPostStageData({bills: data.source.bills});
  3239. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  3240. stagePosSpreadObj.loadCurPosData();
  3241. for (const e of data.error) {
  3242. e.serialNo = stageTree.getNodeIndex(stageTree.getItems(e.ledger_id)) + 1;
  3243. }
  3244. },
  3245. errorList: errorList,
  3246. });
  3247. $('[name=stage-start]').submit(function (e) {
  3248. if (checkAuditorFrom()) {
  3249. $(this).parent().parent().parent().modal('hide');
  3250. dataChecker.checkAndPost(this.action, {});
  3251. $('#hide-all').hide();
  3252. }
  3253. return false;
  3254. });
  3255. $('#audit-check0').submit(function (e) {
  3256. $(this).parent().parent().modal('hide');
  3257. const data = {
  3258. opinion: $('[name=opinion]', this).val().replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' '),
  3259. checkType: parseInt($('[name=checkType]', this).val()),
  3260. };
  3261. dataChecker.checkAndPost(this.action, data);
  3262. $('#hide-all').hide();
  3263. return false;
  3264. });
  3265. $('#audit-check2').submit(function (e) {
  3266. $(this).parent().parent().modal('hide');
  3267. const data = {
  3268. opinion: $('[name=opinion]', this).val().replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' '),
  3269. checkType: parseInt($('[name=checkType]', this).val()),
  3270. };
  3271. dataChecker.checkAndPost(this.action, data);
  3272. $('#hide-all').hide();
  3273. return false;
  3274. });
  3275. $('#exportExcel').click(function () {
  3276. const data = [];
  3277. const setting = {
  3278. cols: [
  3279. {title: '项目节编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 145, formatter: '@', cellType: 'tree'},
  3280. {title: '清单编号', colSpan: '1', rowSpan: '2', field: 'b_code', hAlign: 0, width: 70, formatter: '@'},
  3281. {title: '计量单元', colSpan: '1', rowSpan: '2', field: 'pos_code', hAlign: 0, width: 70, formatter: '@'},
  3282. {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 185, formatter: '@'},
  3283. {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 60, formatter: '@', cellType: 'unit'},
  3284. {title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 60, type: 'Number'},
  3285. {title: '台账|数量', colSpan: '2|1', rowSpan: '1|1', field: 'quantity', hAlign: 2, width: 60, type: 'Number'},
  3286. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'total_price', hAlign: 2, width: 60, type: 'Number'},
  3287. {title: '本期合同计量|数量', colSpan: '2|1', rowSpan: '1|1', field: 'contract_qty', hAlign: 2, width: 60, type: 'Number'},
  3288. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'contract_tp', hAlign: 2, width: 60, type: 'Number'},
  3289. {title: '本期数量变更|数量', colSpan: '2|1', rowSpan: '1|1', field: 'qc_qty', hAlign: 2, width: 60, type: 'Number'},
  3290. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'qc_tp', hAlign: 2, width: 60, type: 'Number'},
  3291. {title: '本期完成计量|数量', colSpan: '2|1', rowSpan: '1|1', field: 'gather_qty', hAlign: 2, width: 60, type: 'Number'},
  3292. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'gather_tp', hAlign: 2, width: 60, type: 'Number'},
  3293. {title: '截止本期合同计量|数量', colSpan: '2|1', rowSpan: '1|1', field: 'end_contract_qty', hAlign: 2, width: 60, type: 'Number'},
  3294. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'end_contract_tp', hAlign: 2, width: 60, type: 'Number'},
  3295. {title: '截止本期数量变更|数量', colSpan: '2|1', rowSpan: '1|1', field: 'end_qc_qty', hAlign: 2, width: 60, type: 'Number'},
  3296. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'end_qc_tp', hAlign: 2, width: 60, type: 'Number'},
  3297. {title: '截止本期完成计量|数量', colSpan: '3|1', rowSpan: '1|1', field: 'end_gather_qty', hAlign: 2, width: 60, type: 'Number'},
  3298. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'end_gather_tp', hAlign: 2, width: 60, type: 'Number'},
  3299. {title: '|完成率(%)', colSpan: '|1', rowSpan: '|1', field: 'end_gather_percent', hAlign: 2, width: 80, type: 'Number'},
  3300. {title: '合同|项目节数量1', colSpan: '2|1', rowSpan: '1|1', field: 'deal_dgn_qty1', hAlign: 2, width: 60, type: 'Number'},
  3301. {title: '|项目节数量2', colSpan: '|1', rowSpan: '|1', field: 'deal_dgn_qty2', hAlign: 2, width: 60, type: 'Number'},
  3302. {title: '变更|项目节数量1', colSpan: '2|1', rowSpan: '1|1', field: 'c_dgn_qty1', hAlign: 2, width: 60, type: 'Number'},
  3303. {title: '|项目节数量2', colSpan: '|1', rowSpan: '|1', field: 'c_dgn_qty2', hAlign: 2, width: 60, type: 'Number'},
  3304. {title: '经济指标', colSpan: '1', rowSpan: '2', field: 'final_dgn_price', hAlign: 2, width: 60, type: 'Number'},
  3305. {title: '本期批注', colSpan: '1', rowSpan: '2', field: 'postil', hAlign: 0, width: 100, formatter: '@', cellType: 'autoTip'},
  3306. {title: '图(册)号', colSpan: '1', rowSpan: '2', field: 'drawing_code', hAlign: 0, width: 80, formatter: '@'},
  3307. {title: '备注', colSpan: '1', rowSpan: '2', field: 'memo', hAlign: 0, width: 100, formatter: '@', cellType: 'ellipsisAutoTip'},
  3308. ],
  3309. headRows: 2,
  3310. headRowHeight: [25, 25],
  3311. defaultRowHeight: 21,
  3312. headerFont: 'bold 10px 微软雅黑',
  3313. font: '10px 微软雅黑'
  3314. };
  3315. for (const node of stageTree.nodes) {
  3316. data.push({
  3317. code: node.code, b_code: node.b_code, name: node.name, unit: node.unit,
  3318. unit_price: node.unit_price, quantity: node.quantity, total_price: node.total_price,
  3319. contract_qty: node.contract_qty, contract_tp: node.contract_tp,
  3320. qc_qty: node.qc_qty, qc_tp: node.qc_tp,
  3321. gather_qty: node.gather_qty, gather_tp: node.gather_tp,
  3322. end_contract_qty: node.end_contract_qty, end_contract_tp: node.end_contract_tp,
  3323. end_qc_qty: node.end_qc_qty, end_qc_tp: node.end_qc_tp,
  3324. end_gather_qty: node.end_gather_qty, end_gather_tp: node.end_gather_tp, end_gather_percent: node.end_gather_percent,
  3325. deal_dgn_qty1: node.deal_dgn_qty1, deal_dgn_qty2: node.deal_dgn_qty2,
  3326. c_dgn_qty1: node.c_dgn_qty1, c_dgn_qty2: node.c_dgn_qty2,
  3327. final_dgn_price: node.final_dgn_price,
  3328. postil: node.postil, drawing_code: node.drawing_code, memo: node.memo,
  3329. });
  3330. const posRange = stagePos.getLedgerPos(node.id);
  3331. if (posRange && posRange.length > 0) {
  3332. for (const [i, p] of posRange.entries()) {
  3333. data.push({
  3334. pos_code: (i + 1) + '', name: p.name,
  3335. quantity: p.quantity,
  3336. contract_qty: p.contract_qty, qc_qty: p.qc_qty, gather_qty: p.gather_qty,
  3337. end_contract_qty: p.end_contract_qty, end_qc_qty: p.end_qc_qty, end_gather_qty: p.end_gather_qty,
  3338. drawing_code: p.drawing_code, memo: p.memo
  3339. });
  3340. }
  3341. }
  3342. }
  3343. SpreadExcelObj.exportSimpleXlsxSheet(setting, data, $('.sidebar-title').attr('data-original-title') + "计量台账.xlsx");
  3344. });
  3345. });