stage.js 168 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435
  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 || node.unit !== '总额' || (posRange && posRange.length > 0) /*|| !checkZero(node.qc_qty)*/) {
  970. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  971. return;
  972. }
  973. const postIsTp = function () {
  974. const data = { calcType: {id: node.id} };
  975. data.calcType.is_tp = info.sheet.getValue(info.row, info.col) || false;
  976. // 更新至服务器
  977. postData(window.location.pathname + '/update', {bills: data}, function (result) {
  978. const nodes = stageTree.loadPostStageData(result);
  979. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  980. if (detail) {
  981. detail.loadStageLedgerUpdateData(result);
  982. } else {
  983. stageIm.loadUpdateLedgerData(result);
  984. }
  985. });
  986. };
  987. if (col.field === 'is_tp') {
  988. if (info.sheet.isEditing()) {
  989. info.sheet.endEdit(true);
  990. }
  991. if (!checkZero(node.contract_qty) || !checkZero(node.contract_tp)) {
  992. $.msgBox({
  993. id: 'calc-type',
  994. title: '提示',
  995. message: '切换计量模式,已计量数据会被清空。',
  996. ok: {
  997. caption: '确定',
  998. callback: postIsTp,
  999. },
  1000. cancel: {
  1001. caption: '取消',
  1002. callback: function () {
  1003. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1004. }
  1005. }
  1006. });
  1007. } else {
  1008. postIsTp();
  1009. }
  1010. }
  1011. }
  1012. },
  1013. };
  1014. slSpread.bind(spreadNS.Events.EditEnded, stageTreeSpreadObj.editEnded);
  1015. slSpread.bind(spreadNS.Events.SelectionChanged, stageTreeSpreadObj.selectionChanged);
  1016. slSpread.bind(spreadNS.Events.ClipboardPasting, stageTreeSpreadObj.clipboardPasting);
  1017. slSpread.bind(spreadNS.Events.ClipboardPasted, stageTreeSpreadObj.clipboardPasted);
  1018. slSpread.bind(spreadNS.Events.TopRowChanged, stageTreeSpreadObj.topRowChanged);
  1019. slSpread.bind(spreadNS.Events.EditStarting, stageTreeSpreadObj.editStarting);
  1020. slSpread.bind(spreadNS.Events.ButtonClicked, stageTreeSpreadObj.buttonClicked);
  1021. SpreadJsObj.addDeleteBind(slSpread, stageTreeSpreadObj.deletePress);
  1022. if (!readOnly) {
  1023. $('#bills-expr').bind('change onblur', function () {
  1024. if (this.readOnly) return;
  1025. const expr = $(this);
  1026. const row = expr.attr('data-row') ? _.toInteger(expr.attr('data-row')) : -1;
  1027. const select = stageTree.getItemsByIndex(row);
  1028. if (!select) return;
  1029. const field = expr.attr('field'), orgValue = expr.attr('org'), updateData = {};
  1030. let newValue = expr.val();
  1031. const num = _.toNumber(newValue);
  1032. if (_.isFinite(num)) {
  1033. newValue = num;
  1034. } else {
  1035. try {
  1036. newValue = math.evaluate(transExpr(newValue));
  1037. } catch(err) {
  1038. toastr.error('输入的表达式非法');
  1039. return;
  1040. }
  1041. }
  1042. if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
  1043. if (field.indexOf('_dgn_') > 0) {
  1044. updateData.dgn = {
  1045. id: select.id
  1046. };
  1047. updateData.dgn[field] = newValue;
  1048. } else {
  1049. updateData.stage = {
  1050. lid: select.id
  1051. };
  1052. updateData.stage[field] = newValue;
  1053. const exprInfo = getExprInfo(field);
  1054. if (exprInfo) {
  1055. updateData.stage[exprInfo.expr] = expr.val();
  1056. }
  1057. }
  1058. // 更新至服务器
  1059. postData(window.location.pathname + '/update', {bills: updateData}, function (result) {
  1060. const nodes = stageTree.loadPostStageData(result);
  1061. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1062. });
  1063. });
  1064. }
  1065. stageTreeSpreadObj.loadExprToInput(slSpread.getActiveSheet());
  1066. $.contextMenu({
  1067. selector: '#stage-ledger',
  1068. build: function ($trigger, e) {
  1069. const target = SpreadJsObj.safeRightClickSelection($trigger, e, slSpread);
  1070. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  1071. },
  1072. items: {
  1073. 'locateZjjl': {
  1074. name: '定位至中间计量',
  1075. icon: 'fa-sign-in',
  1076. callback: function (key, opt) {
  1077. if (!detail) {
  1078. detail = new Detail($('#detail-spread'));
  1079. }
  1080. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1081. const [leafUsedBills, usedPos] = stageIm.getFirstUsed(node);
  1082. if (leafUsedBills) {
  1083. if (!$('#zhongjian').hasClass('active')) {
  1084. const tab = $('#zhongjian'), tabPanel = $(tab.attr('content'));
  1085. $('a', '.side-menu').removeClass('active');
  1086. $('.tab-content .tab-select-show').removeClass('active');
  1087. tab.addClass('active');
  1088. tabPanel.addClass('active');
  1089. showSideTools(tab.hasClass('active'));
  1090. slSpread.refresh();
  1091. spSpread.refresh();
  1092. }
  1093. const relaXmj = stageIm.getRelaXmj(leafUsedBills);
  1094. const im = stageIm.getRelaImData(relaXmj, leafUsedBills, usedPos);
  1095. SpreadJsObj.locateData(detail.sheet, im);
  1096. detail.spread.refresh();
  1097. $('#zhongjian .sjs-bottom').height('400px');
  1098. $('.zhongjian-msg').height($('#zhongjian .sjs-bottom').height());
  1099. detail.reLoadDetailData();
  1100. } else {
  1101. toastr.error('无可定位中间计量');
  1102. }
  1103. },
  1104. },
  1105. }
  1106. });
  1107. const stagePosSpreadObj = {
  1108. loadExprToInput(sheet) {
  1109. const sel = sheet.getSelections()[0];
  1110. if (!sel) return;
  1111. const col = sheet.zh_setting.cols[sel.col], cell = sheet.getCell(sel.row, sel.col);
  1112. if (col && col.type === 'Number') {
  1113. const data = SpreadJsObj.getSelectObject(sheet);
  1114. if (data) {
  1115. const exprInfo = getExprInfo(col.field);
  1116. const value = exprInfo && data[exprInfo.expr] ? data[exprInfo.expr] : data[col.field];
  1117. $('#pos-expr').val(value).attr('field', col.field).attr('org', data[col.field])
  1118. .attr('readOnly', readOnly || cell.locked());
  1119. $('#pos-expr').attr('data-row', sel.row);
  1120. } else {
  1121. $('#pos-expr').val('').attr('readOnly', true);
  1122. $('#pos-expr').removeAttr('data-row');
  1123. }
  1124. } else {
  1125. $('#pos-expr').val('').attr('readOnly', true);
  1126. $('#pos-expr').removeAttr('data-row');
  1127. }
  1128. },
  1129. /**
  1130. * 加载计量单元 根据当前台账选择节点
  1131. */
  1132. loadCurPosData: function () {
  1133. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1134. if (node) {
  1135. const posData = stagePos.ledgerPos[itemsPre + node.id] || [];
  1136. SpreadJsObj.loadSheetData(spSpread.getActiveSheet(), 'data', posData);
  1137. getNodeList(node.id);
  1138. // 如果是附件是当前节点,隐藏
  1139. // if ($('#dqjiedian').hasClass('active')) {
  1140. // $('#showAttachment').hide();
  1141. // }
  1142. } else {
  1143. SpreadJsObj.loadSheetData(spSpread.getActiveSheet(), 'data', []);
  1144. }
  1145. stagePosSpreadObj.loadExprToInput(spSpread.getActiveSheet());
  1146. },
  1147. editEnded: function (e, info) {
  1148. if (info.sheet.zh_setting) {
  1149. // 未改变过,则直接跳过
  1150. const sortData = info.sheet.zh_data;
  1151. const posData = sortData ? sortData[info.row] : null;
  1152. const col = info.sheet.zh_setting.cols[info.col];
  1153. const orgText = posData ? posData[col.field] : null;
  1154. const newText = trimInvalidChar(info.editingText);
  1155. if (orgText === info.editingText || ((!orgText || orgText === '') && (newText === ''))) {
  1156. return;
  1157. }
  1158. // 台账模式下,不可新增
  1159. if (checkTzMeasureType() && !posData) {
  1160. toastr.error('台账模式不可新增计量单元数据');
  1161. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1162. return ;
  1163. }
  1164. // 不同节点下,计量单元检查输入
  1165. //const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1166. const node = stagePosSpreadObj.stageTreeNode;
  1167. if (!node) {
  1168. toastr.warning('数据错误, 请刷新页面后再试');
  1169. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1170. return;
  1171. } else if (newText !== '' && node.children && node.children > 0) {
  1172. toastr.error('父节点不可插入计量单元');
  1173. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1174. return;
  1175. } else if (newText !== '' && !node.b_code || node.b_code === '') {
  1176. toastr.error('项目节不可插入计量单元');
  1177. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1178. return;
  1179. }
  1180. // 生成提交数据
  1181. const data = {};
  1182. if (col.field === 'name') {
  1183. if ((!newText || newText === '') && posData) {
  1184. toastr.error('部位名称不可为空');
  1185. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1186. return;
  1187. } else if (!posData) {
  1188. if (newText !== '') {
  1189. data.updateType = 'add';
  1190. if ((node.pre_used === 1 || !checkZero(node.gather_qty) || !checkZero(node.gather_tp)) && sortData.length === 0) {
  1191. toastr.error('无计量单元的清单,计量后,不可新增计量单元');
  1192. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1193. return;
  1194. }
  1195. const order = (!sortData || sortData.length === 0) ? 1 : Math.max(sortData[sortData.length - 1].porder + 1, sortData.length + 1);
  1196. data.updateData = {name: newText, lid: node.id, tid: tender.id, porder: order};
  1197. } else {
  1198. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1199. return;
  1200. }
  1201. } else {
  1202. data.updateType = 'update';
  1203. data.updateData = {pid: posData.id, lid: posData.lid, name: newText};
  1204. }
  1205. } else if (!posData) {
  1206. toastr.warning('新增计量单元请先输入名称');
  1207. } else {
  1208. data.updateType = 'update';
  1209. data.updateData = {pid: posData.id, lid: posData.lid};
  1210. if (col.type === 'Number') {
  1211. const exprInfo = getExprInfo(col.field);
  1212. const num = _.toNumber(newText);
  1213. if (_.isFinite(num)) {
  1214. data.updateData[col.field] = num;
  1215. if (exprInfo) {
  1216. data.updateData[exprInfo.expr] = '';
  1217. }
  1218. } else {
  1219. try {
  1220. data.updateData[col.field] = math.evaluate(transExpr(newText));
  1221. if (exprInfo) {
  1222. data.updateData[exprInfo.expr] = newText;
  1223. }
  1224. } catch(err) {
  1225. toastr.error('输入的表达式非法');
  1226. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1227. return;
  1228. }
  1229. }
  1230. } else {
  1231. data.updateData[col.field] = newText;
  1232. }
  1233. }
  1234. // 提交数据到服务器
  1235. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  1236. if (result.pos) {
  1237. stagePos.updateDatas(result.pos.pos);
  1238. stagePos.loadCurStageData(result.pos.curStageData);
  1239. }
  1240. const refreshData = stageTree.loadPostStageData(result.ledger);
  1241. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  1242. stagePosSpreadObj.loadCurPosData();
  1243. if (detail) {
  1244. detail.loadStagePosUpdateData(result);
  1245. } else {
  1246. stageIm.loadUpdatePosData(result);
  1247. }
  1248. }, function () {
  1249. stagePosSpreadObj.loadCurPosData();
  1250. });
  1251. }
  1252. },
  1253. editStarting: function (e, info) {
  1254. stagePosSpreadObj.stageTreeNode = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1255. const sel = info.sheet.getSelections();
  1256. if (!sel || !sel[0]) return;
  1257. const col = info.sheet.zh_setting.cols[sel[0].col];
  1258. const node = SpreadJsObj.getSelectObject(info.sheet);
  1259. const exprInfo = getExprInfo(col.field);
  1260. if (exprInfo) {
  1261. if (node[exprInfo.expr] && node[exprInfo.expr] !== '') {
  1262. info.sheet.getCell(info.row, info.col).text(node[exprInfo.expr]);
  1263. }
  1264. }
  1265. },
  1266. clipboardPasting: function (e, info) {
  1267. if (info.sheet.zh_setting) {
  1268. const sortData = info.sheet.zh_data;
  1269. const range = info.cellRange;
  1270. const validField = ['contract_qty', 'qc_qty', 'postil', 'real_qty'];
  1271. if (!checkTzMeasureType()) {
  1272. validField.push('name', 'sgfh_qty', 'sjcl_qty', 'qtcl_qty', 'position', 'drawing_code');
  1273. }
  1274. for (let iCol = range.col; iCol < range.col + range.colCount; iCol++) {
  1275. const col = info.sheet.zh_setting.cols[iCol];
  1276. if (validField.indexOf(col.field) === -1) {
  1277. if (checkTzMeasureType()) {
  1278. toastr.error('不可修改此数据');
  1279. info.cancel = true;
  1280. return;
  1281. } else {
  1282. for (let iRow = range.row; iRow < range.row + range.rowCount; iRow) {
  1283. const pos = sortData(iRow);
  1284. if (pos.add_stage !== stage.id || pos.add_times !== stage.times) {
  1285. toastr.error('不可修改此数据');
  1286. info.cancel = true;
  1287. return;
  1288. }
  1289. }
  1290. }
  1291. }
  1292. }
  1293. }
  1294. },
  1295. clipboardPasted: function (e, info) {
  1296. if (info.sheet.zh_setting) {
  1297. if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
  1298. info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
  1299. }
  1300. const data = { updateType: '', updateData: [], };
  1301. const sortData = info.sheet.zh_data;
  1302. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1303. if (sortData && (info.cellRange.row >= sortData.length)) {
  1304. data.updateType = 'add';
  1305. if (info.cellRange.col !== 0) {
  1306. toastr.warning('新增计量单元请先输入名称');
  1307. stagePosSpreadObj.loadCurPosData();
  1308. return;
  1309. }
  1310. if ((node.pre_used === 1 || !checkZero(node.gather_qty) || !checkZero(node.gather_tp)) && sortData.length === 0) {
  1311. toastr.error('无计量单元的清单,计量后,不可新增计量单元');
  1312. stagePosSpreadObj.loadCurPosData();
  1313. return;
  1314. }
  1315. const lastOrder = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  1316. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  1317. const curRow = info.cellRange.row + iRow;
  1318. const newData = {lid: node.id, porder: lastOrder + curRow - sortData.length};
  1319. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  1320. const curCol = info.cellRange.col + iCol;
  1321. const colSetting = info.sheet.zh_setting.cols[curCol];
  1322. if (!colSetting) continue;
  1323. const newValue = trimInvalidChar(info.sheet.getText(curRow, curCol));
  1324. if (colSetting.type === 'Number') {
  1325. const num = _.toNumber(newValue);
  1326. if (num) {
  1327. newData[colSetting.field] = num;
  1328. } else {
  1329. try {
  1330. newData[colSetting.field] = math.evaluate(transExpr(newValue));
  1331. const exprInfo = getExprInfo(colSetting.field);
  1332. if (exprInfo) {
  1333. newData[exprInfo.expr] = newValue;
  1334. }
  1335. } catch(err) {
  1336. toastr.error('输入的表达式非法');
  1337. stagePosSpreadObj.loadCurPosData();
  1338. return;
  1339. }
  1340. }
  1341. } else {
  1342. newData[colSetting.field] = newValue;
  1343. }
  1344. }
  1345. data.updateData.push(newData);
  1346. }
  1347. } else {
  1348. data.updateType = 'update';
  1349. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  1350. const curRow = info.cellRange.row + iRow;
  1351. const curPos = sortData[curRow];
  1352. if (curPos) {
  1353. const newData = {pid: curPos.id, lid: curPos.lid};
  1354. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  1355. const curCol = info.cellRange.col + iCol;
  1356. const colSetting = info.sheet.zh_setting.cols[curCol];
  1357. const newValue = trimInvalidChar(info.sheet.getText(curRow, curCol));
  1358. if (colSetting.type === 'Number') {
  1359. const num = _.toNumber(newValue);
  1360. if (num) {
  1361. newData[colSetting.field] = num;
  1362. } else {
  1363. try {
  1364. newData[colSetting.field] = math.evaluate(transExpr(newValue));
  1365. const exprInfo = getExprInfo(colSetting.field);
  1366. if (exprInfo) {
  1367. newData[exprInfo.expr] = newValue;
  1368. }
  1369. } catch(err) {
  1370. toastr.error('输入的表达式非法');
  1371. stagePosSpreadObj.loadCurPosData();
  1372. return;
  1373. }
  1374. }
  1375. } else {
  1376. newData[colSetting.field] = newValue;
  1377. }
  1378. }
  1379. data.updateData.push(newData);
  1380. }
  1381. }
  1382. }
  1383. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  1384. if (result.pos) {
  1385. stagePos.updateDatas(result.pos.pos);
  1386. stagePos.loadCurStageData(result.pos.curStageData);
  1387. }
  1388. const nodes = stageTree.loadPostStageData(result.ledger);
  1389. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1390. stagePosSpreadObj.loadCurPosData();
  1391. if (detail) {
  1392. detail.loadStagePosUpdateData(result);
  1393. } else {
  1394. stageIm.loadUpdatePosData(result);
  1395. }
  1396. }, function () {
  1397. stagePosSpreadObj.loadCurPosData();
  1398. });
  1399. }
  1400. },
  1401. deletePress: function (sheet) {
  1402. if (sheet.zh_setting && sheet.zh_data) {
  1403. const sortData = sheet.zh_data;
  1404. if (!sortData || sortData.length === 0) { return; }
  1405. const sel = sheet.getSelections()[0];
  1406. const validCols = [];
  1407. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  1408. const colSetting = sheet.zh_setting.cols[iCol];
  1409. if (!colSetting.readOnly && colSetting.field !== 'qc_qty') {
  1410. validCols.push(iCol);
  1411. }
  1412. }
  1413. if (validCols.length === 0) { return; }
  1414. const datas = [], posSelects = [];
  1415. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  1416. const node = sortData[iRow];
  1417. if (node) {
  1418. const data = {pid: node.id, lid: node.lid};
  1419. for (const iCol of validCols) {
  1420. const colSetting = sheet.zh_setting.cols[iCol];
  1421. if (colSetting.field === 'name') {
  1422. toastr.error('部位名称不能为空');
  1423. return;
  1424. }
  1425. data[colSetting.field] = null;
  1426. const exprInfo = getExprInfo(colSetting.field);
  1427. if (exprInfo) {
  1428. data[exprInfo.expr] = '';
  1429. }
  1430. }
  1431. datas.push(data);
  1432. posSelects.push(node);
  1433. }
  1434. }
  1435. if (datas.length > 0) {
  1436. postData(window.location.pathname + '/update', {pos: {updateType: 'update', updateData: datas} }, function (result) {
  1437. if (result.pos) {
  1438. stagePos.updateDatas(result.pos.pos);
  1439. stagePos.loadCurStageData(result.pos.curStageData);
  1440. }
  1441. const nodes = stageTree.loadPostStageData(result.ledger);
  1442. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1443. if (detail) {
  1444. detail.loadStagePosUpdateData(result);
  1445. } else {
  1446. stageIm.loadUpdatePosData(result);
  1447. }
  1448. // todo 只加载改变项
  1449. stagePosSpreadObj.loadCurPosData();
  1450. });
  1451. }
  1452. }
  1453. },
  1454. deletePos: function (sheet) {
  1455. const sels = sheet.getSelections();
  1456. const sel = sels ? sels[0] : null;
  1457. if (sheet.zh_data && sel) {
  1458. const data = {updateType: 'delete', updateData: []};
  1459. for (let iRow = 0; iRow < sel.rowCount; iRow++) {
  1460. const posData = sheet.zh_data[sel.row + iRow];
  1461. if (posData) {
  1462. data.updateData.push(posData.id);
  1463. }
  1464. }
  1465. if (data.updateData.length > 0) {
  1466. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  1467. stagePos.removeDatas(result.pos.pos);
  1468. const refreshData = stageTree.loadPostStageData(result.ledger);
  1469. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  1470. stagePosSpreadObj.loadCurPosData();
  1471. if (detail) {
  1472. detail.loadStagePosUpdateData(result);
  1473. } else {
  1474. stageIm.loadUpdatePosData(result);
  1475. }
  1476. });
  1477. }
  1478. }
  1479. },
  1480. selectionChanged: function (e, info) {
  1481. stagePosSpreadObj.loadExprToInput(info.sheet);
  1482. },
  1483. addPegs: function (pegs) {
  1484. if (!pegs || pegs.length <= 0) return;
  1485. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1486. if (!node) return;
  1487. const sheet = spSpread.getActiveSheet();
  1488. const sortData = sheet.zh_data || [];
  1489. let order = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  1490. pegs.forEach(function (p) {p.porder = ++order; p.lid = node.id});
  1491. postData(window.location.pathname + '/update', {pos: {updateType: 'add', updateData: pegs} }, function (result) {
  1492. if (result.pos) {
  1493. stagePos.updateDatas(result.pos.pos);
  1494. }
  1495. stagePosSpreadObj.loadCurPosData();
  1496. });
  1497. }
  1498. };
  1499. // 加载上下窗口resizer
  1500. $.divResizer({
  1501. select: '#main-resize',
  1502. callback: function () {
  1503. slSpread.refresh();
  1504. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  1505. $(".sp-wrap").height(bcontent-30);
  1506. spSpread.refresh();
  1507. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  1508. }
  1509. });
  1510. // 加载计量单元数据 - 暂时统一加载,如有需要,切换成动态加载并缓存
  1511. postData(window.location.pathname + '/load', { filter: 'ledger;pos;detail;change' }, function (result) {
  1512. // 加载树结构
  1513. stageTree.loadDatas(result.ledgerData);
  1514. // stageTree.loadCurStageData(curStageData);
  1515. // stageTree.loadPreStageData(preStageData);
  1516. treeCalc.calculateAll(stageTree);
  1517. // 加载部位明细
  1518. stagePos.loadDatas(result.posData);
  1519. stagePos.calculateAll();
  1520. SpreadJsObj.loadSheetData(slSpread.getActiveSheet(), 'tree', stageTree);
  1521. SpreadJsObj.loadTopAndSelect(slSpread.getActiveSheet(), ckBillsSpread);
  1522. stagePosSpreadObj.loadCurPosData();
  1523. SpreadJsObj.resetTopAndSelect(spSpread.getActiveSheet());
  1524. // 加载中间计量
  1525. stageIm.init(stage, imType, tenderInfo.decimal);
  1526. stageIm.loadData(result.ledgerData, result.posData, result.detailData, result.changeData);
  1527. errorList.loadHisErrorData();
  1528. }, null, true);
  1529. spSpread.bind(spreadNS.Events.EditEnded, stagePosSpreadObj.editEnded);
  1530. spSpread.bind(spreadNS.Events.ClipboardPasting, stagePosSpreadObj.clipboardPasting);
  1531. spSpread.bind(spreadNS.Events.ClipboardPasted, stagePosSpreadObj.clipboardPasted);
  1532. spSpread.bind(spreadNS.Events.EditStarting, stagePosSpreadObj.editStarting);
  1533. spSpread.bind(spreadNS.Events.SelectionChanged, stagePosSpreadObj.selectionChanged);
  1534. SpreadJsObj.addDeleteBind(spSpread, stagePosSpreadObj.deletePress);
  1535. if (!readOnly) {
  1536. $('#pos-expr').bind('change onblur', function () {
  1537. if (this.readOnly) return;
  1538. const expr = $(this);
  1539. const posSheet = spSpread.getActiveSheet();
  1540. const row = expr.attr('data-row') ? _.toInteger(expr.attr('data-row')) : -1;
  1541. const select = posSheet.zh_data ? posSheet.zh_data[row] : null;
  1542. if (!select) return;
  1543. const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = expr.val();
  1544. if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
  1545. const data = {pid: select.id, lid: select.lid};
  1546. const exprInfo = getExprInfo(field);
  1547. if (newValue !== '') {
  1548. const num = _.toNumber(newValue);
  1549. if (num) {
  1550. data[field] = num;
  1551. if (exprInfo) data[exprInfo.expr] = '';
  1552. } else {
  1553. try {
  1554. data[field] = math.evaluate(transExpr(newValue));
  1555. if (exprInfo) data[exprInfo.expr] = newValue;
  1556. } catch (err) {
  1557. toastr.error('输入的表达式非法');
  1558. return;
  1559. }
  1560. }
  1561. } else {
  1562. data[field] = null;
  1563. if (exprInfo) data[exprInfo.expr] = '';
  1564. }
  1565. // 提交数据到服务器
  1566. postData(window.location.pathname + '/update', {pos: {updateType: 'update', updateData: data}}, function (result) {
  1567. if (result.pos) {
  1568. stagePos.updateDatas(result.pos.pos);
  1569. stagePos.loadCurStageData(result.pos.curStageData);
  1570. SpreadJsObj.reLoadRowData(posSheet, _.toNumber(row));
  1571. }
  1572. const refreshData = stageTree.loadPostStageData(result.ledger);
  1573. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  1574. });
  1575. });
  1576. }
  1577. if (!checkTzMeasureType()) {
  1578. const mergePeg = NewMergePeg({ callback: stagePosSpreadObj.addPegs});
  1579. $.contextMenu({
  1580. selector: '#stage-pos',
  1581. build: function ($trigger, e) {
  1582. const target = SpreadJsObj.safeRightClickSelection($trigger, e, spSpread);
  1583. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  1584. },
  1585. items: {
  1586. 'del': {
  1587. name: '删除',
  1588. icon: 'fa-remove',
  1589. disabled: function (key, opt) {
  1590. const sheet = spSpread.getActiveSheet();
  1591. if (sheet.zh_data && !readOnly) {
  1592. const selection = sheet.getSelections();
  1593. if (selection && selection[0]) {
  1594. let valid = sheet.zh_data.length < selection[0].row + selection[0].rowCount;
  1595. for (let iRow = 0; iRow < selection[0].rowCount; iRow++) {
  1596. const posData = sheet.zh_data[selection[0].row + iRow];
  1597. if (posData) {
  1598. if (posData.add_stage_order < stage.order || ZhCalc.isNonZero(posData.gather_qty) || ZhCalc.isNonZero(posData.end_gather_qty)) {
  1599. valid = true;
  1600. break;
  1601. }
  1602. } else {
  1603. valid = true;
  1604. break;
  1605. }
  1606. }
  1607. return valid;
  1608. } else {
  1609. return true;
  1610. }
  1611. } else {
  1612. return true;
  1613. }
  1614. },
  1615. callback: function (key, opt) {
  1616. stagePosSpreadObj.deletePos(spSpread.getActiveSheet());
  1617. }
  1618. },
  1619. 'merge-peg': {
  1620. name: '合并起讫桩号',
  1621. disabled: function (key, opt) {
  1622. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1623. return _.isNil(node) || _.isNil(node.b_code) || node.b_code === '';
  1624. },
  1625. callback: function (key, opt) {
  1626. mergePeg.show();
  1627. }
  1628. }
  1629. }
  1630. })
  1631. } else {
  1632. SpreadJsObj.forbiddenSpreadContextMenu('#stage-pos', spSpread);
  1633. }
  1634. $.subMenu({
  1635. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  1636. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  1637. key: 'menu.1.0.0',
  1638. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  1639. callback: function (info) {
  1640. if (info.mini) {
  1641. $('.panel-title').addClass('fluid');
  1642. $('#sub-menu').removeClass('panel-sidebar');
  1643. } else {
  1644. $('.panel-title').removeClass('fluid');
  1645. $('#sub-menu').addClass('panel-sidebar');
  1646. }
  1647. autoFlashHeight();
  1648. slSpread.refresh();
  1649. spSpread.refresh();
  1650. if (searchLedger) {
  1651. searchLedger.spread.refresh();
  1652. }
  1653. if (detail) {
  1654. detail.spread.refresh();
  1655. }
  1656. if (checkedChanges) checkedChanges.refresh();
  1657. }
  1658. });
  1659. $('#row-view').on('show.bs.modal', function () {
  1660. const html = [], customDisplay = customColDisplay();
  1661. for (const cd of customDisplay) {
  1662. html.push('<tr>');
  1663. html.push('<td>', cd.title, '</td>');
  1664. html.push('<td>', '<input type="checkbox"' + (cd.visible ? ' checked=""' : '') + '>', '</td>');
  1665. html.push('</tr>');
  1666. }
  1667. $('#row-view-list').html(html.join(''));
  1668. });
  1669. $('#row-view-ok').click(function () {
  1670. const customDisplay = customColDisplay();
  1671. const cvl = $('#row-view-list').children();
  1672. for (const cv of cvl) {
  1673. const title = $(cv).children()[0].innerHTML;
  1674. const check = $('input', cv)[0].checked;
  1675. const cd = customDisplay.find(function (c) {
  1676. return c.title === title;
  1677. });
  1678. cd.visible = check;
  1679. }
  1680. customizeStageTreeSetting(ledgerSpreadSetting, customDisplay);
  1681. SpreadJsObj.refreshColumnVisible(slSpread.getActiveSheet());
  1682. Cookies.set(ckColSetting, JSON.stringify(customDisplay), 30*24*60*60*1000);
  1683. $('#row-view').modal('hide');
  1684. });
  1685. const posSearch = (function () {
  1686. let resultArr = [];
  1687. const search = function () {
  1688. resultArr = [];
  1689. const keyword = $('#pos-search-keyword').val();
  1690. const checkOver = $('#pos-over-search')[0].checked;
  1691. const checkEmpty = $('#pos-empty-search')[0].checked;
  1692. const sortData = spSpread.getActiveSheet().zh_data;
  1693. if (checkOver || checkEmpty) {
  1694. if (sortData) {
  1695. for (let i = 0, iLength = sortData.length; i < iLength; i++) {
  1696. const sd = sortData[i];
  1697. let match = false;
  1698. if (checkOver) {
  1699. if (sd.end_gather_qty) {
  1700. if (!sd.quantity || Math.abs(sd.end_gather_qty) > Math.abs(ZhCalc.add(sd.quantity, sd.end_qc_qty))) match = true;
  1701. }
  1702. }
  1703. if (checkEmpty) {
  1704. if (sd.quantity) {
  1705. if (!sd.end_gather_qty || ZhCalc.sub(ZhCalc.add(sd.quantity, sd.end_qc_qty), sd.end_gather_qty) > 0) match = true;
  1706. }
  1707. }
  1708. if (keyword && keyword !== '' && sd.name && sd.name.indexOf(keyword) === -1) match = false;
  1709. if (match) {
  1710. resultArr.push({index: i, data: sd});
  1711. }
  1712. }
  1713. }
  1714. } else if (keyword && keyword !== '') {
  1715. if (sortData) {
  1716. for (let i = 0, iLength = sortData.length; i < iLength; i++) {
  1717. const sd = sortData[i];
  1718. if (sd.name && sd.name.indexOf(keyword) > -1) {
  1719. resultArr.push({index: i, data: sd});
  1720. }
  1721. }
  1722. }
  1723. }
  1724. $('#pos-search-result').html('结果:' + resultArr.length);
  1725. };
  1726. const searchAndLocate = function () {
  1727. search();
  1728. if (resultArr.length > 0) {
  1729. const sheet = spSpread.getActiveSheet();
  1730. const sel = sheet.getSelections()[0];
  1731. const curRow = sel ? sel.row : 0;
  1732. const pos = resultArr[0];
  1733. if (pos.index !== curRow) {
  1734. sheet.setSelection(pos.index, sel ? sel.col : 0, 1, 1);
  1735. sheet.showRow(pos.index, spreadNS.VerticalPosition.center);
  1736. SpreadJsObj.reloadRowsBackColor(sheet, [pos.index, curRow]);
  1737. }
  1738. }
  1739. };
  1740. const locateNext = function () {
  1741. if (resultArr.length > 0) {
  1742. const sheet = spSpread.getActiveSheet();
  1743. const sel = sheet.getSelections()[0];
  1744. const curRow = sel ? sel.row : 0;
  1745. let next = _.find(resultArr, function (d) {
  1746. return d.index > curRow;
  1747. });
  1748. if (!next) next = resultArr[0];
  1749. if (next.index !== curRow) {
  1750. sheet.setSelection(next.index, sel ? sel.col : 0, 1, 1);
  1751. sheet.showRow(next.index, spreadNS.VerticalPosition.center);
  1752. SpreadJsObj.reloadRowsBackColor(sheet, [next.index, curRow]);
  1753. }
  1754. }
  1755. };
  1756. const locatePre = function () {
  1757. if (resultArr.length > 0) {
  1758. const sheet = spSpread.getActiveSheet();
  1759. const sel = sheet.getSelections()[0];
  1760. const curRow = sel ? sel.row : 0;
  1761. let next = _.findLast(resultArr, function (d) {
  1762. return d.index < curRow;
  1763. });
  1764. if (!next) next = resultArr[resultArr.length - 1];
  1765. if (next.index !== curRow) {
  1766. sheet.setSelection(next.index, sel ? sel.col : 0, 1, 1);
  1767. sheet.showRow(next.index, spreadNS.VerticalPosition.center);
  1768. SpreadJsObj.reloadRowsBackColor(sheet, [next.index, curRow]);
  1769. }
  1770. }
  1771. };
  1772. return {search, searchAndLocate, locateNext, locatePre};
  1773. })();
  1774. $('#pos-search-keyword').bind('keydown', function(e){
  1775. if (e.keyCode == 13) posSearch.searchAndLocate();
  1776. });
  1777. $('#pos-empty-search').click(function () {
  1778. if (this.checked) {
  1779. $('[for=' + this.id +']').addClass('text-warning');
  1780. } else {
  1781. $('[for=' + this.id +']').removeClass('text-warning');
  1782. }
  1783. if (this.checked) {
  1784. if ($('#pos-over-search')[0].checked) {
  1785. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  1786. } else {
  1787. $('#pos-search-keyword').attr('placeholder', '漏计中按名称查询');
  1788. }
  1789. } else {
  1790. if ($('#pos-over-search')[0].checked) {
  1791. $('#pos-search-keyword').attr('placeholder', '超计中按名称查询');
  1792. } else {
  1793. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  1794. }
  1795. }
  1796. posSearch.searchAndLocate();
  1797. });
  1798. $('#pos-over-search').click(function () {
  1799. if (this.checked) {
  1800. $('[for=' + this.id +']').addClass('text-danger');
  1801. } else {
  1802. $('[for=' + this.id +']').removeClass('text-danger');
  1803. }
  1804. if (this.checked) {
  1805. if ($('#pos-empty-search')[0].checked) {
  1806. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  1807. } else {
  1808. $('#pos-search-keyword').attr('placeholder', '超计中按名称查询');
  1809. }
  1810. } else {
  1811. if ($('#pos-empty-search')[0].checked) {
  1812. $('#pos-search-keyword').attr('placeholder', '漏计中按名称查询');
  1813. } else {
  1814. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  1815. }
  1816. }
  1817. posSearch.searchAndLocate();
  1818. });
  1819. $('#pos-search-next').click(() => {posSearch.locateNext()});
  1820. $('#pos-search-pre').click(() => {posSearch.locatePre()});
  1821. $.divResizer({
  1822. select: '#right-spr',
  1823. callback: function () {
  1824. slSpread.refresh();
  1825. spSpread.refresh();
  1826. if (searchLedger) {
  1827. searchLedger.spread.refresh();
  1828. }
  1829. if (detail) {
  1830. detail.spread.refresh();
  1831. }
  1832. if (checkedChanges) checkedChanges.refresh();
  1833. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  1834. }
  1835. });
  1836. // 中间计量加载上下窗口resizer
  1837. $.divResizer({
  1838. select: '#zhongjian-spr',
  1839. callback: function () {
  1840. if (detail) {
  1841. detail.spread.refresh();
  1842. }
  1843. $('.zhongjian-msg').height($('#zhongjian .sjs-bottom').height());
  1844. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  1845. }
  1846. });
  1847. // 附件加载上下窗口resizer
  1848. $.divResizer({
  1849. select: '#file-spr',
  1850. callback: function () {
  1851. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  1852. }
  1853. });
  1854. // 变更令加载上下窗口resizer
  1855. $.divResizer({
  1856. select: '#change-spr',
  1857. callback: function () {
  1858. if (checkedChanges) checkedChanges.refresh();
  1859. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  1860. }
  1861. });
  1862. class Detail {
  1863. constructor (obj) {
  1864. const self = this;
  1865. this.spreadSetting = {
  1866. cols: [
  1867. {title: '编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 80, formatter: '@', readOnly: true},
  1868. {title: '中间计量表号', colSpan: '1', rowSpan: '1', field: 'im_code', hAlign: 0, width: 85, formatter: '@', readOnly: true},
  1869. {title: '交工证书/凭证号', colSpan: '1', rowSpan: '1', field: 'doc_code', hAlign: 0, width: 110, formatter: '@'},
  1870. {
  1871. title: stage.im_type === imType.tz.value ? '本期计量金额' : '本期计量数量',
  1872. colSpan: '1', rowSpan: '1', field: 'jl', hAlign: 2, width: 85, formatter: '@', readOnly: true
  1873. },
  1874. ],
  1875. headRows: 1,
  1876. emptyRows: 0,
  1877. headRowHeight: [32],
  1878. headColWidth: [30],
  1879. defaultRowHeight: 21,
  1880. headerFont: '12px 微软雅黑',
  1881. font: '12px 微软雅黑',
  1882. readOnly: readOnly,
  1883. selectedBackColor: '#fffacd',
  1884. };
  1885. this.spread = SpreadJsObj.createNewSpread(obj[0]);
  1886. this.sheet = this.spread.getActiveSheet();
  1887. this.spread.options.allowUserDragFill = true;
  1888. this.spread.options.defaultDragFillType = spreadNS.Fill.AutoFillType.fillSeries;
  1889. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  1890. this.detailObj = {
  1891. selectionChanged: function (e, info) {
  1892. self.reLoadDetailData();
  1893. if (!info.oldSelections || !info.oldSelections[0] || info.oldSelections[0].row !== info.newSelections[0].row) {
  1894. self.loadLocateInfo();
  1895. }
  1896. },
  1897. editEnded: function(e, info) {
  1898. if (info.sheet.zh_setting) {
  1899. const col = info.sheet.zh_setting.cols[info.col];
  1900. if (col.field !== 'doc_code') {
  1901. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1902. return;
  1903. }
  1904. const data = SpreadJsObj.getSelectObject(info.sheet);
  1905. if (data) {
  1906. const updateData = {lid: data.lid, pid: data.pid};
  1907. if (data.uuid) {
  1908. updateData.uuid = data.uuid;
  1909. } else {
  1910. updateData.code = data.code;
  1911. updateData.name = data.name;
  1912. updateData.unit = data.unit;
  1913. updateData.unit_price = data.unit_price;
  1914. updateData.pid = data.pid;
  1915. updateData.pos_name = data.pos_name;
  1916. }
  1917. if (data.custom_define.indexOf('doc_code') === -1) {
  1918. updateData.custom_define = data.custom_define;
  1919. updateData.custom_define.push('doc_code');
  1920. updateData.custom_define = updateData.custom_define.join(',');
  1921. }
  1922. updateData.doc_code = info.editingText === null ? '' : info.editingText;
  1923. postData(window.location.pathname + '/detail/save', updateData, function (result) {
  1924. stageIm.loadUpdateDetailData(result);
  1925. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1926. }, function () {
  1927. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1928. });
  1929. } else {
  1930. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1931. }
  1932. }
  1933. },
  1934. clipboardPasted: function (e, info) {
  1935. if (info.sheet.zh_setting && info.sheet.zh_data) {
  1936. const col = info.sheet.zh_setting.cols[info.cellRange.col];
  1937. if (info.cellRange.colCount > 1) {
  1938. toastr.warning('请勿同时复制粘贴多列数据');
  1939. SpreadJsObj.reLoadSheetData(paySpread.getActiveSheet());
  1940. return;
  1941. }
  1942. if (col.field !== 'doc_code') {
  1943. SpreadJsObj.reLoadSheetData(paySpread.getActiveSheet());
  1944. return;
  1945. }
  1946. const datas = [];
  1947. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  1948. const curRow = info.cellRange.row + iRow;
  1949. const data = info.sheet.zh_data[curRow];
  1950. if (data) {
  1951. const updateData = {lid: data.lid, pid: data.pid};
  1952. if (data.uuid) {
  1953. updateData.uuid = data.uuid;
  1954. } else {
  1955. updateData.code = data.code;
  1956. updateData.name = data.name;
  1957. updateData.unit = data.unit;
  1958. updateData.unit_price = data.unit_price;
  1959. updateData.pid = data.pid;
  1960. updateData.pos_name = data.pos_name;
  1961. }
  1962. if (data.custom_define.indexOf('doc_code') === -1) {
  1963. updateData.custom_define = data.custom_define;
  1964. updateData.custom_define.push('doc_code');
  1965. updateData.custom_define = updateData.custom_define.join(',');
  1966. }
  1967. updateData.doc_code = info.sheet.getText(curRow, info.cellRange.col).replace('\n', '');
  1968. datas.push(updateData);
  1969. }
  1970. }
  1971. if (datas.length > 0) {
  1972. postData(window.location.pathname + '/detail/save', datas, function (result) {
  1973. stageIm.loadUpdateDetailData(result);
  1974. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1975. }, function () {
  1976. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1977. })
  1978. }
  1979. }
  1980. },
  1981. deletePress: function (sheet) {
  1982. if (sheet.zh_setting) {
  1983. const datas = [];
  1984. const sel = sheet.getSelections()[0];
  1985. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  1986. const col = sheet.zh_setting.cols[iCol];
  1987. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  1988. const data = sheet.zh_data[iRow];
  1989. if (col.field === 'doc_code') {
  1990. const updateData = {lid: data.lid};
  1991. if (data.uuid) {
  1992. updateData.uuid = data.uuid;
  1993. updateData.doc_code = '';
  1994. datas.push(updateData);
  1995. }
  1996. }
  1997. }
  1998. }
  1999. if (datas.length > 0) {
  2000. postData(window.location.pathname + '/detail/save', datas, function (result) {
  2001. stageIm.loadUpdateDetailData(result);
  2002. SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
  2003. }, function () {
  2004. SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
  2005. });
  2006. }
  2007. }
  2008. },
  2009. dragFillBlock: function (e, info) {
  2010. info.cancel = true;
  2011. if (!info.sheet.zh_setting || !info.sheet.zh_data) return;
  2012. const sel = info.sheet.getSelections()[0];
  2013. const col = info.sheet.zh_setting.cols[info.fillRange.col];
  2014. if (info.fillRange.colCount > 1 || !sel || col.field !== 'doc_code') return;
  2015. const text = info.sheet.getText(sel.row + sel.rowCount - 1, sel.col);
  2016. if (text === '') return;
  2017. const regRst = /(\d+)$/g.exec(text), datas = [];
  2018. for (let iRow = 0; iRow < info.fillRange.rowCount; iRow++) {
  2019. const curRow = info.fillRange.row + iRow;
  2020. const data = info.sheet.zh_data[curRow];
  2021. if (data) {
  2022. const updateData = {lid: data.lid};
  2023. if (data.uuid) {
  2024. updateData.uuid = data.uuid;
  2025. } else {
  2026. updateData.code = data.code;
  2027. updateData.name = data.name;
  2028. updateData.unit = data.unit;
  2029. updateData.unit_price = data.unit_price;
  2030. updateData.pid = data.pid;
  2031. updateData.pos_name = data.pos_name;
  2032. }
  2033. if (regRst) {
  2034. updateData.doc_code = text.substr(0, regRst.index) + (parseInt(regRst[0]) + iRow + 1);
  2035. } else {
  2036. updateData.doc_code = text.replace('\n', '');
  2037. }
  2038. if (data.custom_define.indexOf('doc_code') === -1) {
  2039. updateData.custom_define = data.custom_define;
  2040. updateData.custom_define.push('doc_code');
  2041. updateData.custom_define = updateData.custom_define.join(',');
  2042. }
  2043. datas.push(updateData);
  2044. }
  2045. }
  2046. if (datas.length > 0) {
  2047. postData(window.location.pathname + '/detail/save', datas, function (result) {
  2048. stageIm.loadUpdateDetailData(result);
  2049. SpreadJsObj.reLoadRowData(info.sheet, info.fillRange.row, info.fillRange.rowCount);
  2050. }, function () {
  2051. SpreadJsObj.reLoadRowData(info.sheet, info.fillRange.row, info.fillRange.rowCount);
  2052. })
  2053. }
  2054. },
  2055. };
  2056. this.spread.bind(spreadNS.Events.SelectionChanged, this.detailObj.selectionChanged);
  2057. if (!readOnly) {
  2058. this.spread.bind(spreadNS.Events.EditEnded, this.detailObj.editEnded);
  2059. this.spread.bind(spreadNS.Events.ClipboardPasted, this.detailObj.clipboardPasted);
  2060. this.spread.bind(spreadNS.Events.DragFillBlock, this.detailObj.dragFillBlock);
  2061. SpreadJsObj.addDeleteBind(this.spread, this.detailObj.deletePress);
  2062. }
  2063. this._initImTypeSetRela();
  2064. this._initModifyDetail();
  2065. this._initLocateRela();
  2066. // 草图相关
  2067. this._initImageRela();
  2068. this.reBuildImData();
  2069. }
  2070. _initImTypeSetRela() {
  2071. const self = this;
  2072. const gatherConfirmPopover = {
  2073. reBind: function (obj, eventName, fun) {
  2074. obj.unbind(eventName);
  2075. obj.bind(eventName, fun);
  2076. },
  2077. check: function (pos, hint, okCallback) {
  2078. const confirmObj = $('#gather-confirm'), hintObj = $('#gather-confirm-hint');
  2079. const okObj = $('#gather-confirm-ok'), cancelObj = $('#gather-confirm-cancel');
  2080. this.reBind(cancelObj, 'click', function () {
  2081. confirmObj.hide();
  2082. });
  2083. this.reBind(okObj, 'click', function () {
  2084. okCallback();
  2085. confirmObj.hide();
  2086. });
  2087. hintObj.text(hint);
  2088. confirmObj.css("top", pos.y).css("left", pos.x).show();
  2089. }
  2090. };
  2091. this.gsTree = stageIm.getGsTree();
  2092. if (stage.im_type === imType.tz.value || stage.im_type === imType.bb.value) {
  2093. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  2094. jlCol.title = '本期计量金额';
  2095. SpreadJsObj.reLoadSheetHeader(self.sheet);
  2096. $('#type-title-contract').text('本期合同计量金额');
  2097. $('#type-title-qc').text('本期变更计量金额');
  2098. } else {
  2099. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  2100. jlCol.title = '本期计量数量';
  2101. SpreadJsObj.reLoadSheetHeader(self.sheet);
  2102. $('#type-title-contract').text('本期合同计量数量');
  2103. $('#type-title-qc').text('本期变更计量数量');
  2104. }
  2105. if (stage.im_type === imType.bb.value || stage.im_type === imType.bw.value) {
  2106. $('#show-jldy').parent().show();
  2107. $('#jldy').parent().show();
  2108. $('#show-xm-name').parent().hide();
  2109. $('#xm-name').parent().hide();
  2110. } else {
  2111. $('#show-jldy').parent().hide();
  2112. $('#jldy').parent().hide();
  2113. $('#show-xm-name').parent().show();
  2114. $('#xm-name').parent().show();
  2115. }
  2116. // 选择中间计量模式
  2117. $('div[name="im-type"]').click(function () {
  2118. function chooseType(obj) {
  2119. obj.style.cursor = 'default';
  2120. $(obj).children().addClass('text-primary');
  2121. $(obj).addClass('border-primary');
  2122. $('h5', obj).prepend('<i class="fa fa-check pull-right"></i>');
  2123. }
  2124. function validType(obj) {
  2125. obj.style.cursor = 'pointer';
  2126. $(obj).children().removeClass('text-primary');
  2127. $(obj).removeClass('border-primary');
  2128. $('i', obj).remove();
  2129. }
  2130. if (this.style.cursor === 'pointer') {
  2131. const typeArr = $('div[name="im-type"]');
  2132. for (const t of typeArr) {
  2133. if ($(t).attr('im-type') === $(this).attr('im-type')) {
  2134. chooseType(t);
  2135. } else {
  2136. validType(t)
  2137. }
  2138. }
  2139. }
  2140. });
  2141. $('#choose').on('show.bs.modal', function () {
  2142. function chooseType(obj) {
  2143. obj.style.cursor = 'default';
  2144. $(obj).children().addClass('text-primary');
  2145. $('i', obj).remove();
  2146. $('h5', obj).prepend('<i class="fa fa-check pull-right"></i>');
  2147. }
  2148. function validType(obj) {
  2149. obj.style.cursor = 'pointer';
  2150. $(obj).children().removeClass('text-primary');
  2151. $('i', obj).remove();
  2152. }
  2153. $('#im-pre').val(stage.im_pre ? stage.im_pre : '');
  2154. const typeArr = $('div[name="im-type"]');
  2155. for (const t of typeArr) {
  2156. if (parseInt($(t).attr('im-type')) === stage.im_type) {
  2157. chooseType(t);
  2158. } else {
  2159. validType(t)
  2160. }
  2161. }
  2162. });
  2163. // 提交 中间计量模式
  2164. $('#choose-ok').click(() => {
  2165. const chooseType = _.find($('div[name="im-type"]', '#im-type'), function (it) {
  2166. return it.style.cursor !== 'pointer';
  2167. });
  2168. const data = {
  2169. im_type: parseInt($(chooseType).attr('im-type')),
  2170. im_pre: $('#im-pre').val(),
  2171. };
  2172. postData(window.location.pathname + '/detail/build', data, function (result) {
  2173. stage.im_type = data.im_type;
  2174. stage.im_pre = data.im_pre;
  2175. if (stage.im_type === imType.tz.value || stage.im_type === imType.bb.value) {
  2176. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  2177. jlCol.title = '本期计量金额';
  2178. SpreadJsObj.reLoadSheetHeader(self.sheet);
  2179. $('#type-title-contract').text('本期合同计量金额');
  2180. $('#type-title-qc').text('本期变更计量金额');
  2181. } else {
  2182. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  2183. jlCol.title = '本期计量数量';
  2184. SpreadJsObj.reLoadSheetHeader(self.sheet);
  2185. $('#type-title-contract').text('本期合同计量数量');
  2186. $('#type-title-qc').text('本期变更计量数量');
  2187. }
  2188. if (stage.im_type === imType.bb.value || stage.im_type === imType.bw.value) {
  2189. $('#show-jldy').parent().show();
  2190. $('#jldy').parent().show();
  2191. $('#show-xm-name').parent().hide();
  2192. $('#xm-name').parent().hide();
  2193. } else {
  2194. $('#show-jldy').parent().hide();
  2195. $('#jldy').parent().hide();
  2196. $('#show-xm-name').parent().show();
  2197. $('#xm-name').parent().show();
  2198. }
  2199. // 加载生成数据
  2200. self.reBuildImData();
  2201. $('#choose').modal('hide');
  2202. });
  2203. });
  2204. // 显示树结构信息
  2205. $('#choose2').on('shown.bs.modal', function () {
  2206. if (!self.gsSpread) {
  2207. self.gsSpread = SpreadJsObj.createNewSpread($('#im-gather-spread')[0]);
  2208. const setting = {
  2209. cols: [
  2210. {title: '计量\n汇总', colSpan: '1', rowSpan: '1', field: 'check', hAlign: 1, width: 50, formatter: '@', readOnly: true, cellType: 'checkbox'},
  2211. {title: '项目节编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 150, formatter: '@', readOnly: true, cellType: 'tree'},
  2212. {title: '清单编号', colSpan: '1', rowSpan: '1', field: 'b_code', hAlign: 0, width: 80, formatter: '@', readOnly: true},
  2213. {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 230, formatter: '@', readOnly: true},
  2214. {title: '单位', colSpan: '1', rowSpan: '1', field: 'unit', hAlign: 1, width: 60, formatter: '@', readOnly: true},
  2215. ],
  2216. headRows: 1,
  2217. emptyRows: 0,
  2218. headRowHeight: [32],
  2219. defaultRowHeight: 21,
  2220. headerFont: '12px 微软雅黑',
  2221. font: '12px 微软雅黑',
  2222. };
  2223. sjsSettingObj.setFxTreeStyle(setting, sjsSettingObj.FxTreeStyle.jz);
  2224. SpreadJsObj.initSheet(self.gsSpread.getActiveSheet(), setting);
  2225. self.gsSpread.bind(spreadNS.Events.ButtonClicked, function (e, info) {
  2226. function checkParent(node) {
  2227. const parent = self.gsTree.getParent(node);
  2228. if (parent) {
  2229. return parent.check ? parent.check : checkParent(parent);
  2230. } else {
  2231. return false;
  2232. }
  2233. }
  2234. function checkChildren(node) {
  2235. for (const child of node.children) {
  2236. if (child.check) {
  2237. return true;
  2238. } else if (checkChildren(child)) {
  2239. return true;
  2240. }
  2241. }
  2242. return false;
  2243. }
  2244. if (!$('#im-gather-check')[0].checked) { return; }
  2245. const sheet = info.sheet, cellType = sheet.getCellType(info.row, info.col);
  2246. if (cellType instanceof spreadNS.CellTypes.CheckBox) {
  2247. if (sheet.isEditing()) {
  2248. sheet.endEdit(true);
  2249. }
  2250. }
  2251. if (info.sheet.zh_setting) {
  2252. const col = info.sheet.zh_setting.cols[info.col];
  2253. if (col.field !== 'check') {
  2254. return;
  2255. }
  2256. const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
  2257. const node = sortData[info.row];
  2258. if (!node.check) {
  2259. if (checkParent(node)) {
  2260. const rect = info.sheet.getCellRect(info.row, info.col);
  2261. gatherConfirmPopover.check({
  2262. x: rect.x + rect.width / 2 + 25,
  2263. y: rect.y + rect.height / 2 + 3,
  2264. }, '父项已勾选,继续将取消父项勾选。', function () {
  2265. node.check = true;
  2266. const parents = self.gsTree.getFullPathNodes(self.gsTree.getParent(node).full_path);
  2267. const rows = [self.gsTree.nodes.indexOf(node)];
  2268. for (const p of parents) {
  2269. if (p.check) {
  2270. p.check = false;
  2271. rows.push(self.gsTree.nodes.indexOf(p));
  2272. }
  2273. }
  2274. SpreadJsObj.reLoadRowsData(info.sheet, rows);
  2275. });
  2276. } else if (checkChildren(node)) {
  2277. const rect = info.sheet.getCellRect(info.row, info.col);
  2278. gatherConfirmPopover.check({
  2279. x: rect.x + rect.width / 2 + 25,
  2280. y: rect.y + rect.height / 2 + 3,
  2281. }, '子项已勾选,继续将取消子项勾选。', function () {
  2282. node.check = true;
  2283. const posterity = self.gsTree.getPosterity(node);
  2284. const rows = [self.gsTree.nodes.indexOf(node)];
  2285. for (const p of posterity) {
  2286. if (p.check) {
  2287. rows.push(self.gsTree.nodes.indexOf(p));
  2288. p.check = false;
  2289. }
  2290. }
  2291. SpreadJsObj.reLoadRowsData(info.sheet, rows);
  2292. });
  2293. } else {
  2294. node.check = true;
  2295. SpreadJsObj.reLoadRowsData(info.sheet, [self.gsTree.nodes.indexOf(node)]);
  2296. }
  2297. } else {
  2298. node.check = false;
  2299. SpreadJsObj.reLoadRowsData(info.sheet, [self.gsTree.nodes.indexOf(node)]);
  2300. }
  2301. }
  2302. });
  2303. const gatherNodes = stage.im_gather_node ? _.map(stage.im_gather_node.split(',')) : [];
  2304. for (const node of self.gsTree.datas) {
  2305. node.check = gatherNodes.indexOf(node.id + '') !== -1;
  2306. }
  2307. SpreadJsObj.loadSheetData(self.gsSpread.getActiveSheet(), SpreadJsObj.DataType.Tree, self.gsTree);
  2308. self.gsTree.expandByLevel(4);
  2309. SpreadJsObj.refreshTreeRowVisible(self.gsSpread.getActiveSheet());
  2310. SpreadJsObj.resetFieldReadOnly(self.gsSpread.getActiveSheet, 'check', !$('#im-gather-check')[0].checked);
  2311. } else {
  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.reLoadColsData(self.gsSpread.getActiveSheet(), [0]);
  2317. }
  2318. });
  2319. // 提交 高级设置
  2320. $('#choose2-ok').click(() => {
  2321. if (!self.gsTree) { return; }
  2322. const nodes = [];
  2323. for (const node of self.gsTree.datas) {
  2324. if (node.check) {
  2325. nodes.push(node.id);
  2326. }
  2327. }
  2328. const data = {
  2329. im_gather: $('#im-gather-check')[0].checked,
  2330. im_gather_node: nodes.join(','),
  2331. };
  2332. postData(window.location.pathname + '/detail/adv', data, function (result) {
  2333. stage.im_gather = data.im_gather;
  2334. stage.im_gather_node = data.im_gather_node;
  2335. $('#choose2').modal('hide');
  2336. });
  2337. });
  2338. }
  2339. _initLocateRela() {
  2340. const self = this;
  2341. $('#im-locate2bills').click(function () {
  2342. const curIndex = parseInt($('#im-locate-info')[0].innerText.split('/')[0]);
  2343. const select = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  2344. if (select && select.source) {
  2345. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), select.source[curIndex-1].id, true);
  2346. stagePosSpreadObj.loadCurPosData();
  2347. }
  2348. });
  2349. $('#im-locate-pre').click(function () {
  2350. const curIndex = parseInt($('#im-locate-info')[0].innerText.split('/')[0]);
  2351. const select = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  2352. if (select && select.source) {
  2353. const targetIndex = math.max(curIndex-1, 1);
  2354. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), select.source[targetIndex-1].id, true);
  2355. stagePosSpreadObj.loadCurPosData();
  2356. $('#im-locate-info')[0].innerText = targetIndex + '/' + select.source.length;
  2357. }
  2358. });
  2359. $('#im-locate-next').click(function () {
  2360. const curIndex = parseInt($('#im-locate-info')[0].innerText.split('/')[0]);
  2361. const select = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  2362. if (select && select.source) {
  2363. const targetIndex = math.min(curIndex+1, select.source.length);
  2364. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), select.source[targetIndex-1].id, true);
  2365. stagePosSpreadObj.loadCurPosData();
  2366. $('#im-locate-info')[0].innerText = targetIndex + '/' + select.source.length;
  2367. }
  2368. });
  2369. }
  2370. _initModifyDetail() {
  2371. const self = this;
  2372. // 编辑
  2373. $('#edit-detail').click(function () {
  2374. $(this).hide();
  2375. $('#save-detail').show();
  2376. $('#cancel-detail').show();
  2377. $('#detail-show').hide();
  2378. $('#detail-edit').show();
  2379. self.updateImageData = null;
  2380. });
  2381. // 保存
  2382. $('#save-detail').click(() => {
  2383. function check(field, obj, org, update) {
  2384. const newValue = obj.val();
  2385. if (!org[field]) {
  2386. if (newValue !== '') {
  2387. update[field] = newValue;
  2388. if (data.custom_define.indexOf(field) === -1) update.custom_define.push(field);
  2389. }
  2390. } else if (newValue !== org[field]){
  2391. update[field] = newValue;
  2392. if (data.custom_define.indexOf(field) === -1) update.custom_define.push(field);
  2393. }
  2394. }
  2395. const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  2396. const updateData = {lid: data.lid, pid: data.pid};
  2397. if (data.uuid) {
  2398. updateData.uuid = data.uuid;
  2399. updateData.custom_define = data.custom_define;
  2400. } else {
  2401. updateData.code = data.code;
  2402. updateData.name = data.name;
  2403. updateData.unit = data.unit;
  2404. updateData.unit_price = data.unit_price;
  2405. updateData.pid = data.pid;
  2406. updateData.pos_name = data.pos_name;
  2407. updateData.custom_define = [];
  2408. }
  2409. check('bw', $('#bw-name'), data, updateData);
  2410. check('peg', $('#peg'), data, updateData);
  2411. check('xm', $('#xm-name'), data, updateData);
  2412. check('position', $('#position'), data, updateData);
  2413. check('jldy', $('#jldy'), data, updateData);
  2414. check('drawing_code', $('#drawing-code'), data, updateData);
  2415. check('calc_memo', $('#calc-memo'), data, updateData);
  2416. updateData.custom_define = updateData.custom_define.join(',');
  2417. postData(window.location.pathname + '/detail/save', updateData, function (result) {
  2418. stageIm.loadUpdateDetailData(result);
  2419. self.reLoadDetailData();
  2420. if (self.updateImageData && !self.updateImageData.uuid) {
  2421. self.updateImageData.uuid = result.uuid;
  2422. postData(window.location.pathname + '/detail/merge-img', self.updateImageData, function (result) {
  2423. stageIm.loadUpdateDetailData(result);
  2424. self.reLoadDetailData();
  2425. });
  2426. }
  2427. });
  2428. if (self.updateImageData && self.updateImageData.uuid) {
  2429. postData(window.location.pathname + '/detail/merge-img', self.updateImageData, function (result) {
  2430. stageIm.loadUpdateDetailData(result);
  2431. self.reLoadDetailData();
  2432. });
  2433. }
  2434. });
  2435. // 取消
  2436. $('#cancel-detail').click(() => {
  2437. self.reLoadDetailData();
  2438. });
  2439. }
  2440. _initImageRela() {
  2441. const self = this;
  2442. $('#edit-detail').click(function () {
  2443. loadImageItem();
  2444. });
  2445. function setdraggrable(){
  2446. $( ".img-item" ).draggable({ containment: "parent" },{stop: function( event, ui ) {
  2447. }}).resizable({ containment: "parent" },{ handles: 'n, e, s, w, ne, se, sw, nw' },{ maxWidth: parseFloat($('#imgwidth').val())},{maxHeight: parseFloat($('#imgheight').val())},{
  2448. stop: function( event, ui ) {
  2449. }
  2450. });
  2451. }
  2452. // 移动图片
  2453. const moveImageItem = function (ev) {
  2454. const item = this;
  2455. const view = $('.img-view')[0];
  2456. let oEvent = ev;
  2457. // 浏览器有一些图片的默认事件,这里要阻止
  2458. oEvent.preventDefault();
  2459. let disX = oEvent.clientX - item.offsetLeft;
  2460. let disY = oEvent.clientY - item.offsetTop;
  2461. view.onmousemove = function (ev) {
  2462. oEvent = ev;
  2463. oEvent.preventDefault();
  2464. let x = oEvent.clientX -disX;
  2465. let y = oEvent.clientY -disY;
  2466. // 图形移动的边界判断
  2467. x = x <= 0 ? 0 : x;
  2468. x = x >= view.offsetWidth - item.offsetWidth ? view.offsetWidth - item.offsetWidth : x;
  2469. y = y <= 0 ? 0 : y;
  2470. y = y >= view.offsetHeight - item.offsetHeight ? view.offsetHeight - item.offsetHeight : y;
  2471. item.style.left = x + 'px';
  2472. item.style.top = y + 'px';
  2473. };
  2474. // 图形移出父盒子取消移动事件,防止移动过快触发鼠标移出事件,导致鼠标弹起事件失效
  2475. view.onmouseleave = function () {
  2476. view.onmousemove = null;
  2477. view.onmouseup = null;
  2478. };
  2479. // 鼠标弹起后停止移动
  2480. view.onmouseup=function() {
  2481. view.onmousemove = null;
  2482. view.onmouseup = null;
  2483. };
  2484. };
  2485. const removeImageItem = function () {
  2486. $(this).parent().remove();
  2487. };
  2488. // 加载草图组成
  2489. const loadImageItem = function () {
  2490. self.updateImageData = null;
  2491. const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  2492. const items = data.calc_img_org ? JSON.parse(data.calc_img_org) : [];
  2493. const html = [];
  2494. for (const item of items) {
  2495. const itemStyle = 'top:' + item.top + ';' + 'left:' + item.left + ';' + 'width:' + item.width + ';' + 'height:' + item.height + ';';
  2496. html.push('<div class="img-item" style="' + itemStyle + '">');
  2497. html.push('<div class="img-bar">');
  2498. html.push('<a href="javascript: void(0);" class="text-danger" title="删除"><i class="fa fa-remove" style="font-size: 24px"></i></a>');
  2499. html.push('</div>');
  2500. html.push('<div class="focus" style="width:100%; height:100%"><img src="', item.src, '" id="draggable" style="width:100%; height:100%"></div>');
  2501. html.push('</div>');
  2502. }
  2503. $('.img-view').html(html.join(''));
  2504. $('.img-bar').click(removeImageItem);
  2505. setdraggrable();
  2506. };
  2507. // 上传图片
  2508. $('#upload-img').click(function () {
  2509. $('#upload-img-file').trigger('click');
  2510. });
  2511. $('#upload-img-file').change(function () {
  2512. const file = this.files[0];
  2513. const ext = file.name.toLowerCase().split('.').splice(-1)[0];
  2514. const imgStr = /(jpg|jpeg|png|bmp|BMP|JPG|PNG|JPEG)$/;
  2515. if (!imgStr.test(ext)) {
  2516. toastr.error('请上传正确的图片格式文件');
  2517. return
  2518. }
  2519. if ($(this).val()) {
  2520. const formData = new FormData();
  2521. formData.append('file', this.files[0]);
  2522. postDataWithFile(window.location.pathname + '/detail/add-img', formData, function (result) {
  2523. const html = [];
  2524. html.push('<div class="img-item">');
  2525. html.push('<div class="img-bar">');
  2526. html.push('<a href="javascript: void(0);" class="text-danger" title="删除"><i class="fa fa-remove" style="font-size: 24px"></i></a>');
  2527. html.push('</div>');
  2528. html.push('<div class="focus" style="width:100%; height:100%"><img src="', '/' + result, '" id="draggable" style="width:100%; height:100%"></div>');
  2529. html.push('</div>');
  2530. $('.img-view').append(html.join(''));
  2531. $('.img-bar').click(removeImageItem);
  2532. setdraggrable();
  2533. $('#upload-img-file').val('');
  2534. });
  2535. }
  2536. });
  2537. // 保存草图修改结果
  2538. $('#edit-img-ok').click(function () {
  2539. // 记录上传的图片的信息
  2540. const items = $('.img-item');
  2541. const img_remark = $('#text-edit').val()
  2542. const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  2543. if (items.length > 0) {
  2544. const itemInfo = [];
  2545. for (const item of items) {
  2546. const itemData = {
  2547. src: $('img', item).attr('src'),
  2548. left: item.style.left,
  2549. top: item.style.top,
  2550. width: item.style.width,
  2551. height: item.style.height,
  2552. };
  2553. itemInfo.push(itemData);
  2554. }
  2555. // 获取合并好的图片数据
  2556. const canvas = document.createElement('canvas');
  2557. const view = $('.img-view')[0];
  2558. canvas.height = view.clientHeight;
  2559. canvas.width = view.clientWidth;
  2560. const ctx = canvas.getContext('2d');
  2561. ctx.fillStyle = '#ffffff';
  2562. ctx.fillRect(0, 0, canvas.width, canvas.height);
  2563. for (const b of $('.img-item')) {
  2564. const pos = $(b).position();
  2565. const img = $('img', b)[0];
  2566. ctx.drawImage(img, pos.left, pos.top, img.width, img.height);
  2567. }
  2568. // 生成上传数据
  2569. const updateData = {updateType: 'update', lid: data.lid, pid: data.pid};
  2570. if (data.uuid) {
  2571. updateData.uuid = data.uuid;
  2572. }
  2573. if (data.custom_define.indexOf('calc_img') === -1) {
  2574. updateData.custom_define = data.custom_define;
  2575. updateData.custom_define.push('calc_img');
  2576. updateData.custom_define = updateData.custom_define.join(',');
  2577. }
  2578. updateData.img = canvas.toDataURL('image/png');
  2579. updateData.imgInfo = itemInfo;
  2580. updateData.calc_img_remark = img_remark;
  2581. self.updateImageData = updateData;
  2582. $('#calc-img').attr('src', updateData.img);
  2583. $('#view-calc-img').attr('src', updateData.img);
  2584. $('#show-calc-img').attr('src', updateData.img);
  2585. $('#view-calc-remark').text(img_remark);
  2586. $('#edit-img').modal('hide');
  2587. // updateImageData = updateData;
  2588. // $('#edit-img').modal('hide');
  2589. // postData(window.location.pathname + '/detail/merge-img', updateData, function (result) {
  2590. // stageIm.loadUpdateDetailData(result);
  2591. // data.calc_img = result.calc_img;
  2592. // data.calc_img_org = result.calc_img_org;
  2593. // const calcImgSrc = data && data.calc_img ? '/' + data.calc_img : '';
  2594. // $('#show-calc-img').attr('src', calcImgSrc);
  2595. // $('#calc-img').attr('src', calcImgSrc);
  2596. // $('#view-calc-img').attr('src', calcImgSrc);
  2597. // $('#edit-img').modal('hide');
  2598. // });
  2599. } else if (data.calc_img) {
  2600. self.updateImageData = {updateType: 'clear', lid: data.lid, pid: data.pid, uuid: data.uuid};
  2601. $('#show-calc-img').attr('src', '');
  2602. $('#calc-img').attr('src', '');
  2603. $('#view-calc-img').attr('src', '');
  2604. $('#view-calc-remark').val('');
  2605. $('#text-edit').val('')
  2606. $('#edit-img').modal('hide');
  2607. // postData(window.location.pathname + '/detail/merge-img', {updateType: 'clear', lid: data.lid, pid: data.pid, uuid: data.uuid}, function (result) {
  2608. // stageIm.loadUpdateDetailData(result);
  2609. // data.calc_img = result.calc_img;
  2610. // data.calc_img_org = result.calc_img_org;
  2611. // const calcImgSrc = data && data.calc_img ? '/' + data.calc_img : '';
  2612. // $('#show-calc-img').attr('src', calcImgSrc);
  2613. // $('#calc-img').attr('src', calcImgSrc);
  2614. // $('#view-calc-img').attr('src', calcImgSrc);
  2615. // $('#edit-img').modal('hide');
  2616. // });
  2617. } else {
  2618. self.updateImageData = null;
  2619. $('#show-calc-img').attr('src', '');
  2620. $('#calc-img').attr('src', '');
  2621. $('#view-calc-img').attr('src', '');
  2622. $('#view-calc-remark').val('');
  2623. $('#text-edit').val('')
  2624. $('#edit-img').modal('hide');
  2625. }
  2626. });
  2627. }
  2628. reBuildImData() {
  2629. const imData = stageIm.buildImData();
  2630. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  2631. this.reLoadDetailData();
  2632. this.loadLocateInfo();
  2633. }
  2634. loadStageLedgerUpdateData(data) {
  2635. const imData = stageIm.loadUpdateLedgerData(data);
  2636. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  2637. this.reLoadDetailData();
  2638. }
  2639. loadStagePosUpdateData(data) {
  2640. const imData = stageIm.loadUpdatePosData(data);
  2641. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  2642. this.reLoadDetailData();
  2643. }
  2644. loadStageChangeUpdateData(data) {
  2645. const imData = stageIm.loadUpdateChangeData(data);
  2646. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  2647. this.reLoadDetailData();
  2648. }
  2649. loadLocateInfo() {
  2650. const select = SpreadJsObj.getSelectObject(this.sheet);
  2651. if (select && select.source.length > 1) {
  2652. $('#im-locate2bills').next().show();
  2653. } else {
  2654. $('#im-locate2bills').next().hide();
  2655. }
  2656. $('#im-locate-info')[0].innerText = '1/' + (select ? select.source.length : '0');
  2657. }
  2658. reLoadDetailData() {
  2659. const data = SpreadJsObj.getSelectObject(this.spread.getActiveSheet());
  2660. if (data) {
  2661. $('#edit-detail').show();
  2662. $('#modify-img').show();
  2663. } else {
  2664. $('#edit-detail').hide();
  2665. $('#modify-img').hide();
  2666. }
  2667. $('#save-detail').hide();
  2668. $('#cancel-detail').hide();
  2669. $('#detail-show').show();
  2670. $('#detail-edit').hide();
  2671. const contractJl = data && data.contract_jl ? data.contract_jl : '';
  2672. $('#show-contract-jl').text(contractJl);
  2673. $('#contract-jl').val(contractJl);
  2674. const qcJl = data && data.qc_jl ? data.qc_jl : '';
  2675. $('#show-qc-jl').text(qcJl);
  2676. $('#qc-jl').val(qcJl);
  2677. const bglCode = data && data.bgl_code ? data.bgl_code : '';
  2678. $('#show-bgl-code').text(bglCode);
  2679. $('#bgl-code').val(bglCode);
  2680. const bglDrawingCode = data && data.bgl_drawing_code ? data.bgl_drawing_code : '';
  2681. $('#show-bgl-drawing-code').text(bglDrawingCode);
  2682. $('#bgl-drawing-code').val(bglDrawingCode);
  2683. const bwName = data && data.bw ? data.bw : '';
  2684. $('#show-bw-name').text(bwName);
  2685. $('#bw-name').val(bwName);
  2686. const position = data && data.position ? data.position : '';
  2687. $('#show-position').text(position);
  2688. $('#position').val(position);
  2689. const peg = data && data.peg ? data.peg : '';
  2690. $('#show-peg').text(peg);
  2691. $('#peg').val(peg);
  2692. const xmName = data && data.xm ? data.xm: '';
  2693. $('#show-xm-name').text(xmName);
  2694. $('#xm-name').val(xmName);
  2695. const jldy = data && data.jldy ? data.jldy: '';
  2696. $('#show-jldy').text(jldy);
  2697. $('#jldy').val(jldy);
  2698. const drawingCode = data && data.drawing_code ? data.drawing_code: '';
  2699. $('#show-drawing-code').text(drawingCode);
  2700. $('#drawing-code').val(drawingCode);
  2701. const calcMemo = data && data.calc_memo ? data.calc_memo: '';
  2702. $('#show-calc-memo').html(calcMemo.replace(/\n/g, '<br/>'));
  2703. $('#calc-memo').val(calcMemo);
  2704. const calcImgSrc = data && data.calc_img ? '/' + data.calc_img : '';
  2705. $('#show-calc-img').attr('src', calcImgSrc);
  2706. $('#calc-img').attr('src', calcImgSrc);
  2707. $('#view-calc-img').attr('src', calcImgSrc);
  2708. const calcImgRemark = data && data.calc_img_remark || '';
  2709. $('#view-calc-remark').val(calcImgRemark);
  2710. $("#view-calc-remark").attr('readonly', true);
  2711. // 处理 编辑 -> 添加草图中textarea多余的空格
  2712. $('#text-edit').val(calcImgRemark)
  2713. }
  2714. }
  2715. class CheckedChange {
  2716. constructor (setting) {
  2717. const self = this;
  2718. this.changeSpreadSetting = {
  2719. cols: [
  2720. {title: '变更令号', colSpan: '1', rowSpan: '1', field: 'p_code', hAlign: 0, width: 100, formatter: '@'},
  2721. {title: '变更名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 180, formatter: '@'},
  2722. {title: '金额', colSpan: '1', rowSpan: '1', field: 'total_price', hAlign: 2, width: 80, type: 'Number'},
  2723. {title: '批复文号', colSpan: '1', rowSpan: '1', field: 'w_code', hAlign: 0, width: 100, formatter: '@'},
  2724. ],
  2725. emptyRows: 0,
  2726. headRows: 1,
  2727. headRowHeight: [32],
  2728. headColWidth: [30],
  2729. defaultRowHeight: 21,
  2730. headerFont: '12px 微软雅黑',
  2731. font: '12px 微软雅黑',
  2732. readOnly: true,
  2733. };
  2734. this.changeSpread = SpreadJsObj.createNewSpread(setting.changeObj[0]);
  2735. this.changeSheet = this.changeSpread.getActiveSheet();
  2736. SpreadJsObj.initSheet(this.changeSheet, this.changeSpreadSetting);
  2737. this.changeBillsSpreadSetting = {
  2738. cols: [
  2739. {title: '清单编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 80, formatter: '@'},
  2740. {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 150, type: 'Number'},
  2741. {title: '单位', colSpan: '1', rowSpan: '1', field: 'unit', hAlign: 1, width: 50, formatter: '@'},
  2742. {title: '单价', colSpan: '1', rowSpan: '1', field: 'unit_price', hAlign: 2, width: 60, type: 'Number'},
  2743. {title: '数量', colSpan: '1', rowSpan: '1', field: 'qty', hAlign: 2, width: 60, formatter: '@'},
  2744. {title: '金额', colSpan: '1', rowSpan: '1', field: 'tp', hAlign: 2, width: 60, formatter: '@'},
  2745. {title: '变更部位', colSpan: '1', rowSpan: '1', field: 'bwmx', hAlign: 0, width: 100, formatter: '@'},
  2746. ],
  2747. emptyRows: 0,
  2748. headRows: 1,
  2749. headRowHeight: [32],
  2750. defaultRowHeight: 21,
  2751. headerFont: '12px 微软雅黑',
  2752. font: '12px 微软雅黑',
  2753. readOnly: true
  2754. };
  2755. this.changeBillsSpread = SpreadJsObj.createNewSpread(setting.changeBillsObj[0]);
  2756. this.changeBillsSheet = this.changeBillsSpread.getActiveSheet();
  2757. SpreadJsObj.initSheet(this.changeBillsSheet, this.changeBillsSpreadSetting);
  2758. this.changeSheet.bind(spreadNS.Events.SelectionChanged, function (e, info) {
  2759. const change = SpreadJsObj.getSelectObject(self.changeSheet);
  2760. if (change.cid === self.curChangeId) { return; }
  2761. self.curChangeId = change.cid;
  2762. if (change.detail) {
  2763. self.loadChangeDetailData();
  2764. } else {
  2765. postData(window.location.pathname + '/change/detail', {cid: change.cid}, function (result) {
  2766. change.detail = result;
  2767. self.analyzeChange(change);
  2768. self.loadChangeDetailData();
  2769. });
  2770. }
  2771. });
  2772. this.changes = null;
  2773. this.reloadChangeData();
  2774. setting.reloadObj.click(function() {
  2775. self.reloadChangeData();
  2776. });
  2777. }
  2778. loadChangeDetailData() {
  2779. const change = SpreadJsObj.getSelectObject(this.changeSheet);
  2780. if (change) {
  2781. SpreadJsObj.loadSheetData(this.changeBillsSheet, SpreadJsObj.DataType.Data, change.bills);
  2782. } else {
  2783. SpreadJsObj.loadSheetData(this.changeBillsSheet, SpreadJsObj.DataType.Data, []);
  2784. }
  2785. }
  2786. refresh() {
  2787. this.changeSpread.refresh();
  2788. this.changeBillsSpread.refresh();
  2789. }
  2790. reloadChangeData() {
  2791. const self = this;
  2792. postData(window.location.pathname + '/change/data', null, function (result) {
  2793. self.changes = result.changes;
  2794. SpreadJsObj.loadSheetData(self.changeSheet, SpreadJsObj.DataType.Data, self.changes);
  2795. self.changeSheet.setSelection(0, 0, 1, 1);
  2796. if (self.changes.length > 0) self.analyzeChange(result.changes[0]);
  2797. self.loadChangeDetailData();
  2798. });
  2799. }
  2800. analyzeChange(change) {
  2801. change.bills = change.detail.bills;
  2802. for (const b of change.bills) {
  2803. const aub = change.detail.addUsedBills.find(function (x) {
  2804. return x.id === b.id;
  2805. });
  2806. if (aub) {
  2807. b.used_qty = aub.used_qty;
  2808. }
  2809. b.qty = _.toNumber(b.samount);
  2810. b.valid_qty = ZhCalc.sub(b.qty, b.used_qty);
  2811. b.tp = ZhCalc.round(ZhCalc.mul(b.qty, b.unit_price), tenderInfo.decimal.tp);
  2812. b.pos = _.filter(change.detail.curUsedBills, {cbid: b.id});
  2813. b.cur_qty = 0;
  2814. for (const p of b.pos) {
  2815. p.f_qty = p.p_qty ? p.p_qty : p.l_qty;
  2816. b.cur_qty = ZhCalc.add(b.cur_qty, p.qty);
  2817. }
  2818. }
  2819. }
  2820. }
  2821. // 展开收起附件
  2822. $('a', '.right-nav').bind('click', function () {
  2823. //const main = $('#main-view'), tool = $('#tools-view');
  2824. const tab = $(this), tabPanel = $(tab.attr('content'));
  2825. if (!tab.hasClass('active')) {
  2826. $('a', '.side-menu').removeClass('active');
  2827. $('.tab-content .tab-select-show').removeClass('active');
  2828. tab.addClass('active');
  2829. tabPanel.addClass('active');
  2830. showSideTools(tab.hasClass('active'));
  2831. if (tab.attr('content') === '#search' && !searchLedger) {
  2832. searchLedger = $.billsSearch({
  2833. selector: '#search',
  2834. searchSpread: slSpread,
  2835. searchRangeStr: '项目节编号/名称',
  2836. searchOver: true,
  2837. searchEmpty: true,
  2838. resultSpreadSetting: {
  2839. cols: [
  2840. {title: '项目节编号', field: 'code', hAlign: 0, width: 90, formatter: '@'},
  2841. {title: '清单编号', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
  2842. {title: '名称', field: 'name', width: 150, hAlign: 0, formatter: '@'},
  2843. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@'},
  2844. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  2845. {title: '数量', field: 'quantity', hAlign: 2, width: 50},
  2846. {title: '完成率(%)', field: 'complete_percent', hAlign: 2, width: 70},
  2847. ],
  2848. emptyRows: 0,
  2849. headRows: 1,
  2850. headRowHeight: [32],
  2851. headColWidth: [30],
  2852. defaultRowHeight: 21,
  2853. headerFont: '12px 微软雅黑',
  2854. font: '12px 微软雅黑',
  2855. selectedBackColor: '#fffacd',
  2856. },
  2857. afterLocated: function () {
  2858. stagePosSpreadObj.loadCurPosData();
  2859. },
  2860. customSearch: [
  2861. {
  2862. key: 'less', title: '漏计', valid: true,
  2863. check: function (node) {
  2864. if (node.quantity) {
  2865. return ZhCalc.sub(ZhCalc.add(node.quantity, node.end_qc_qty), node.end_gather_qty) > 0;
  2866. } else if (node.total_price) {
  2867. return ZhCalc.sub(ZhCalc.add(node.total_price, node.end_qc_tp), node.end_gather_tp) > 0;
  2868. }
  2869. }
  2870. }, {
  2871. key: 'over', title: '超计', valid: true,
  2872. check: function (node) {
  2873. const posRange = stagePos.ledgerPos[itemsPre + node.id] || [];
  2874. if (posRange.length > 0) {
  2875. for (const p of posRange) {
  2876. if (p.end_contract_qty > p.quantity) return true;
  2877. }
  2878. return false;
  2879. } else if (node.end_gather_qty) {
  2880. return !node.quantity || Math.abs(node.end_gather_qty) > Math.abs(ZhCalc.add(node.quantity, node.end_qc_qty));
  2881. } else if (node.end_gather_tp) {
  2882. return !node.total_price || Math.abs(node.end_gather_tp) > Math.abs(ZhCalc.add(node.total_price, node.end_qc_tp));
  2883. }
  2884. }
  2885. }, {
  2886. key: 'empty', title: '漏计', valid: false,
  2887. check: function (node) {
  2888. if (node.quantity) {
  2889. return !node.end_gather_qty || checkZero(node.end_gather_qty);
  2890. } else if (node.total_price) {
  2891. return !node.end_gather_tp || checkZero(node.end_gather_tp);
  2892. }
  2893. }
  2894. }, {
  2895. key: 'estimate', title: '预计变更', valid: true,
  2896. check: function (node) {
  2897. const posRange = stagePos.ledgerPos[itemsPre + node.id] || [];
  2898. if (posRange.length > 0) {
  2899. for (const p of posRange) {
  2900. if (!checkZero(p.estimate_qty)) return true;
  2901. }
  2902. return false;
  2903. } else {
  2904. return false;
  2905. }
  2906. }
  2907. }
  2908. ],
  2909. });
  2910. searchLedger.spread.refresh();
  2911. }
  2912. if (tab.attr('content') === '#fujian') {
  2913. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2914. getNodeList(node.id);
  2915. }
  2916. if (tab.attr('content') === '#zhongjian') {
  2917. if (!detail) {
  2918. detail = new Detail($('#detail-spread'));
  2919. detail.spread.refresh();
  2920. $('#zhongjian .sjs-bottom').height('400px');
  2921. $('.zhongjian-msg').height($('#zhongjian .sjs-bottom').height());
  2922. } else {
  2923. detail.spread.refresh();
  2924. $('#zhongjian .sjs-bottom').height('400px');
  2925. $('.zhongjian-msg').height($('#zhongjian .sjs-bottom').height());
  2926. }
  2927. }
  2928. if (tab.attr('content') === '#checked-change') {
  2929. if (!checkedChanges) {
  2930. checkedChanges = new CheckedChange({
  2931. changeObj: $('#cc-spread'),
  2932. changeBillsObj: $('#ccb-spread'),
  2933. reloadObj: $('#refresh-cc'),
  2934. });
  2935. checkedChanges.refresh();
  2936. } else {
  2937. $('#ccb-spread').height('400px');
  2938. checkedChanges.refresh();
  2939. }
  2940. }
  2941. if (tab.attr('content') === '#error-list') {
  2942. errorList.spread.refresh();
  2943. }
  2944. } else {
  2945. tab.removeClass('active');
  2946. tabPanel.removeClass('active');
  2947. showSideTools(tab.hasClass('active'));
  2948. }
  2949. slSpread.refresh();
  2950. spSpread.refresh();
  2951. });
  2952. // 切换附件里节点和所有附件
  2953. $('#fujian .nav-link').on('click', function () {
  2954. const tabPanel = $(this).attr('fujian-content');
  2955. if (tabPanel !== 'syfujian') {
  2956. $('#showPage').hide();
  2957. } else {
  2958. $('#showPage').show();
  2959. }
  2960. $('#showAttachment').hide();
  2961. });
  2962. // 上传附件
  2963. $('#upload-file-btn').click(function () {
  2964. if (curAuditor && curAuditor.aid !== parseInt(cur_uid)) {
  2965. return toastr.error('无法上传图片!');
  2966. }
  2967. const files = $('#upload-file')[0].files;
  2968. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2969. const formData = new FormData();
  2970. formData.append('lid', node.id);
  2971. for (const file of files) {
  2972. if (file === undefined) {
  2973. toastr.error('未选择上传文件!');
  2974. return false;
  2975. }
  2976. const filesize = file.size;
  2977. if (filesize > 30 * 1024 * 1024) {
  2978. toastr.error('存在上传文件大小过大!');
  2979. return false;
  2980. }
  2981. const fileext = '.' + file.name.toLowerCase().split('.').splice(-1)[0];
  2982. if (whiteList.indexOf(fileext) === -1) {
  2983. toastr.error('只能上传指定格式的附件!');
  2984. return false;
  2985. }
  2986. formData.append('size', filesize);
  2987. formData.append('file[]', file);
  2988. }
  2989. postDataWithFile('/tender/' + tender.id + '/measure/stage/' + stage.order + '/upload/file', formData, function (data) {
  2990. $('#upload').modal('hide');
  2991. // 插入到attData中
  2992. attData = data.concat(attData);
  2993. // 重新生成List
  2994. getAllList();
  2995. getNodeList(node.id);
  2996. }, function () {
  2997. toastr.error('附件上传失败');
  2998. });
  2999. $('#upload-file').val('');
  3000. });
  3001. // 获取附件信息
  3002. $('body').on('click', '.list-table a', function () {
  3003. const fid = $(this).attr('file-id');
  3004. if ($('#showAttachment').attr('file-id') === fid && !$('#showAttachment').is(":hidden")) {
  3005. return;
  3006. }
  3007. const att = attData.find(function (item) {
  3008. return item.id === parseInt(fid);
  3009. });
  3010. $('#edit-att').hide();
  3011. $('#show-att').show();
  3012. if (att !== undefined) {
  3013. // 进来先把编辑功能隐藏
  3014. $('#btn-att a').eq(3).hide()
  3015. $('#show-att tr').eq(0).children('td').text(att.filename + att.fileext);
  3016. const name = att.code !== null && att.code !== '' ? att.code : (att.b_code !== null ? att.b_code : '');
  3017. $('#show-att tr').eq(1).children('td').text($.trim(name + ' ' + att.lname));
  3018. // $('#show-att tr').eq(2).find('a').attr('href', '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + att.id);
  3019. $('#show-att tr').eq(2).find('a').attr('href', att.filepath);
  3020. $('#show-att tr').eq(3).children('td').eq(0).text(att.username);
  3021. $('#show-att tr').eq(3).children('td').eq(1).text(att.in_time);
  3022. $('#show-att tr').eq(4).children('td').text(att.remark);
  3023. // 附件uid等于当前用户id, 附件上传本人
  3024. if (parseInt(cur_uid) === att.uid) {
  3025. $('#btn-att').show();
  3026. let showDel = false;
  3027. if (!curAuditor) {
  3028. stage.status === auditConst.status.checked && parseInt(att.re_upload) && (showDel = true)
  3029. stage.status === auditConst.status.uncheck && parseInt(cur_uid) === stage.user_id && (showDel = true)
  3030. stage.status === auditConst.status.checkNo && parseInt(cur_uid) === stage.user_id && (showDel = true)
  3031. } else {
  3032. curAuditor.aid === parseInt(cur_uid) && (showDel = true)
  3033. }
  3034. if (showDel) $('#btn-att a').eq(3).show();
  3035. // $('#btn-att a').eq(3).show();
  3036. $('#btn-att a').eq(2).hide();
  3037. $('#btn-att a').eq(4).hide();
  3038. $('#btn-att a').eq(5).hide();
  3039. } else {
  3040. $('#btn-att').hide();
  3041. $('#btn-att a').eq(3).hide();
  3042. $('#btn-att a').eq(2).hide();
  3043. $('#btn-att a').eq(4).hide();
  3044. $('#btn-att a').eq(5).hide();
  3045. }
  3046. $('#showAttachment').attr('file-id', fid);
  3047. $('#showAttachment').show();
  3048. } else {
  3049. $('#showAttachment').hide();
  3050. $('#showAttachment').attr('file-id', '');
  3051. toastr.error('附件信息获取失败');
  3052. }
  3053. });
  3054. // $('body').on('click', '.alllist-table a', handleFileList);
  3055. $('body').on('click', '#btn-att a', function () {
  3056. const content = $(this).attr('content');
  3057. const fid = $('#showAttachment').attr('file-id');
  3058. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  3059. if (content === 'edit') {
  3060. $('#btn-att a').eq(3).hide();
  3061. $('#btn-att a').eq(2).show();
  3062. $('#btn-att a').eq(4).show();
  3063. $('#btn-att a').eq(5).show();
  3064. $('#show-att').hide();
  3065. $('#edit-att').show();
  3066. const att = attData.find(function (item) {
  3067. return item.id === parseInt(fid);
  3068. });
  3069. $('#edit-att .form-group').eq(0).find('input').val(att.filename);
  3070. $('#edit-att .form-group').eq(0).find('span').eq(1).text(att.fileext);
  3071. const name = att.code !== null && att.code !== '' ? att.code : (att.b_code !== null ? att.b_code : '');
  3072. $('#edit-att .form-group').eq(1).find('input').val($.trim(name + ' ' + att.lname));
  3073. $('#edit-att .form-group').eq(2).find('input').val(att.in_time);
  3074. $('#edit-att .form-group').eq(3).find('input').val(att.remark);
  3075. } else if (content === 'cancel') {
  3076. $('#show-att').show();
  3077. $('#edit-att').hide();
  3078. $('#btn-att a').eq(3).show();
  3079. $('#btn-att a').eq(2).hide();
  3080. $('#btn-att a').eq(4).hide();
  3081. $('#btn-att a').eq(5).hide();
  3082. } else if (content === 'save') {
  3083. const formData = new FormData();
  3084. formData.append('id', fid);
  3085. formData.append('filename', $('#edit-att .form-group').eq(0).find('input').val());
  3086. formData.append('fileext', $('#edit-att .form-group').eq(0).find('span').eq(1).text());
  3087. formData.append('remark', $('#edit-att .form-group').eq(3).find('input').val());
  3088. const file = $('#change-att-btn')[0];
  3089. if (file.files[0] !== undefined) {
  3090. const filesize = file.files[0].size;
  3091. formData.append('size', filesize);
  3092. formData.append('file', file.files[0]);
  3093. }
  3094. postDataWithFile('/tender/' + tender.id + '/measure/stage/' + stage.order + '/save/file', formData, function (data) {
  3095. // 替换到attData中
  3096. const att_index = attData.findIndex(function (item) {
  3097. return item.id === parseInt(fid);
  3098. });
  3099. attData.splice(att_index, 1, data);
  3100. // 重新生成List
  3101. getAllList(parseInt($('#currentPage').text()));
  3102. getNodeList(node.id);
  3103. $('#show-att').show();
  3104. $('#edit-att').hide();
  3105. $('#show-att tr').eq(0).children('td').text(data.filename + data.fileext);
  3106. const name = data.code !== null && data.code !== '' ? data.code : (data.b_code !== null ? data.b_code : '');
  3107. $('#show-att tr').eq(1).children('td').text($.trim(name + ' ' + data.lname));
  3108. $('#show-att tr').eq(2).find('a').attr('href', '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + data.id);
  3109. $('#show-att tr').eq(3).children('td').eq(0).text(data.username);
  3110. $('#show-att tr').eq(3).children('td').eq(1).text(data.in_time);
  3111. $('#show-att tr').eq(4).children('td').text(data.remark);
  3112. $('#btn-att a').eq(3).show();
  3113. $('#btn-att a').eq(2).hide();
  3114. $('#btn-att a').eq(4).hide();
  3115. $('#btn-att a').eq(5).hide();
  3116. }, function () {
  3117. toastr.error('附件上传失败');
  3118. });
  3119. $('#change-att-btn').val('');
  3120. } else if (content === 'del') {
  3121. const data = {id: fid};
  3122. postData('/tender/' + tender.id + '/measure/stage/' + stage.order + '/delete/file', data, function (result) {
  3123. // 删除到attData中
  3124. const att_index = attData.findIndex(function (item) {
  3125. return item.id === parseInt(fid);
  3126. });
  3127. attData.splice(att_index, 1);
  3128. // 重新生成List
  3129. if ($('#alllist-table tr').length === 1) {
  3130. getAllList(parseInt($('#currentPage').text()) - 1);
  3131. } else {
  3132. getAllList(parseInt($('#currentPage').text()));
  3133. }
  3134. getNodeList(node.id);
  3135. $('#showAttachment').hide();
  3136. $('#showAttachment').attr('file-id', '');
  3137. });
  3138. } else if (content === 'view') {
  3139. const data = {id: fid};
  3140. postData('/tender/' + tender.id + '/measure/stage/' + stage.order + '/check/file', data, function (result) {
  3141. const { filepath } = result
  3142. $('#show-att tr').eq(2).find('a').attr('href', filepath)
  3143. $('#show-att tr').eq(2).find('a').children('span').eq(0).trigger('click')
  3144. });
  3145. } else if (content === 'location') {
  3146. const att = attData.find(item => item.id === parseInt(fid));
  3147. if (Object.keys(att).length) {
  3148. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), att.ledger_id, true);
  3149. stagePosSpreadObj.loadCurPosData();
  3150. }
  3151. }
  3152. });
  3153. // 替换附件
  3154. $('#change-att-btn').on('change', function () {
  3155. const file = $('#change-att-btn')[0].files[0];
  3156. const name = file.name;
  3157. const filename = name.substring(0, name.lastIndexOf("."));
  3158. const fileext = name.substr(name.indexOf("."));
  3159. const filesize = file.size;
  3160. if (filesize > 10 * 1024 * 1024) {
  3161. toastr.error('文件大小过大!');
  3162. $('#change-att-btn').val('');
  3163. return false;
  3164. }
  3165. if (whiteList.indexOf(fileext) === -1) {
  3166. toastr.error('只能上传指定格式的附件!');
  3167. $('#change-att-btn').val('');
  3168. return false;
  3169. }
  3170. $('#edit-att .form-group').eq(0).find('input').val(filename);
  3171. $('#edit-att .form-group').eq(0).find('span').eq(1).text(fileext);
  3172. });
  3173. // 切换页数
  3174. $('.page-select').on('click', function () {
  3175. const totalPageNum = parseInt($('#totalPage').text());
  3176. const lastPageNum = parseInt($('#currentPage').text());
  3177. const status = $(this).attr('content');
  3178. if (status === 'pre' && lastPageNum > 1) {
  3179. getAllList(lastPageNum-1);
  3180. $('#showAttachment').hide();
  3181. } else if (status === 'next' && lastPageNum < totalPageNum) {
  3182. getAllList(lastPageNum+1);
  3183. $('#showAttachment').hide();
  3184. }
  3185. });
  3186. // 显示层次
  3187. (function (select, sheet) {
  3188. $(select).click(function () {
  3189. if (!sheet.zh_tree) return;
  3190. const tag = $(this).attr('tag');
  3191. const tree = sheet.zh_tree;
  3192. switch (tag) {
  3193. case "1":
  3194. case "2":
  3195. case "3":
  3196. case "4":
  3197. case "5":
  3198. tree.expandByLevel(parseInt(tag));
  3199. SpreadJsObj.refreshTreeRowVisible(sheet);
  3200. break;
  3201. case "last":
  3202. tree.expandByCustom(() => { return true; });
  3203. SpreadJsObj.refreshTreeRowVisible(sheet);
  3204. break;
  3205. case "leafXmj":
  3206. tree.expandToLeafXmj();
  3207. SpreadJsObj.refreshTreeRowVisible(sheet);
  3208. break;
  3209. case "curMeasure":
  3210. tree.expandByCustom(function (node) {
  3211. for (const field of ['contract_tp', 'qc_tp', 'gather_tp']) {
  3212. if (node[field]) {
  3213. return true;
  3214. }
  3215. }
  3216. return false;
  3217. });
  3218. SpreadJsObj.refreshTreeRowVisible(sheet);
  3219. break;
  3220. }
  3221. });
  3222. })('a[name=showLevel]', slSpread.getActiveSheet());
  3223. const dataChecker = DataChecker({
  3224. checkUrl: window.location.pathname + '/check',
  3225. completeData: function (data) {
  3226. stagePos.updateDatas({pos: data.source.pos});
  3227. const refreshData = stageTree.loadPostStageData({bills: data.source.bills});
  3228. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  3229. stagePosSpreadObj.loadCurPosData();
  3230. for (const e of data.error) {
  3231. e.serialNo = stageTree.getNodeIndex(stageTree.getItems(e.ledger_id)) + 1;
  3232. }
  3233. },
  3234. errorList: errorList,
  3235. });
  3236. $('[name=stage-start]').submit(function (e) {
  3237. if (checkAuditorFrom()) {
  3238. $(this).parent().parent().parent().modal('hide');
  3239. dataChecker.checkAndPost(this.action, {});
  3240. $('#hide-all').hide();
  3241. }
  3242. return false;
  3243. });
  3244. $('#audit-check0').submit(function (e) {
  3245. $(this).parent().parent().modal('hide');
  3246. const data = {
  3247. opinion: $('[name=opinion]', this).val().replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' '),
  3248. checkType: parseInt($('[name=checkType]', this).val()),
  3249. };
  3250. dataChecker.checkAndPost(this.action, data);
  3251. $('#hide-all').hide();
  3252. return false;
  3253. });
  3254. $('#audit-check2').submit(function (e) {
  3255. $(this).parent().parent().modal('hide');
  3256. const data = {
  3257. opinion: $('[name=opinion]', this).val().replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' '),
  3258. checkType: parseInt($('[name=checkType]', this).val()),
  3259. };
  3260. dataChecker.checkAndPost(this.action, data);
  3261. $('#hide-all').hide();
  3262. return false;
  3263. });
  3264. $('#exportExcel').click(function () {
  3265. const data = [];
  3266. const setting = {
  3267. cols: [
  3268. {title: '项目节编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 145, formatter: '@', cellType: 'tree'},
  3269. {title: '清单编号', colSpan: '1', rowSpan: '2', field: 'b_code', hAlign: 0, width: 70, formatter: '@'},
  3270. {title: '计量单元', colSpan: '1', rowSpan: '2', field: 'pos_code', hAlign: 0, width: 70, formatter: '@'},
  3271. {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 185, formatter: '@'},
  3272. {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 60, formatter: '@', cellType: 'unit'},
  3273. {title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 60, type: 'Number'},
  3274. {title: '台账|数量', colSpan: '2|1', rowSpan: '1|1', field: 'quantity', hAlign: 2, width: 60, type: 'Number'},
  3275. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'total_price', hAlign: 2, width: 60, type: 'Number'},
  3276. {title: '本期合同计量|数量', colSpan: '2|1', rowSpan: '1|1', field: 'contract_qty', hAlign: 2, width: 60, type: 'Number'},
  3277. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'contract_tp', hAlign: 2, width: 60, type: 'Number'},
  3278. {title: '本期数量变更|数量', colSpan: '2|1', rowSpan: '1|1', field: 'qc_qty', hAlign: 2, width: 60, type: 'Number'},
  3279. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'qc_tp', hAlign: 2, width: 60, type: 'Number'},
  3280. {title: '本期完成计量|数量', colSpan: '2|1', rowSpan: '1|1', field: 'gather_qty', hAlign: 2, width: 60, type: 'Number'},
  3281. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'gather_tp', hAlign: 2, width: 60, type: 'Number'},
  3282. {title: '截止本期合同计量|数量', colSpan: '2|1', rowSpan: '1|1', field: 'end_contract_qty', hAlign: 2, width: 60, type: 'Number'},
  3283. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'end_contract_tp', hAlign: 2, width: 60, type: 'Number'},
  3284. {title: '截止本期数量变更|数量', colSpan: '2|1', rowSpan: '1|1', field: 'end_qc_qty', hAlign: 2, width: 60, type: 'Number'},
  3285. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'end_qc_tp', hAlign: 2, width: 60, type: 'Number'},
  3286. {title: '截止本期完成计量|数量', colSpan: '3|1', rowSpan: '1|1', field: 'end_gather_qty', hAlign: 2, width: 60, type: 'Number'},
  3287. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'end_gather_tp', hAlign: 2, width: 60, type: 'Number'},
  3288. {title: '|完成率(%)', colSpan: '|1', rowSpan: '|1', field: 'end_gather_percent', hAlign: 2, width: 80, type: 'Number'},
  3289. {title: '合同|项目节数量1', colSpan: '2|1', rowSpan: '1|1', field: 'deal_dgn_qty1', hAlign: 2, width: 60, type: 'Number'},
  3290. {title: '|项目节数量2', colSpan: '|1', rowSpan: '|1', field: 'deal_dgn_qty2', hAlign: 2, width: 60, type: 'Number'},
  3291. {title: '变更|项目节数量1', colSpan: '2|1', rowSpan: '1|1', field: 'c_dgn_qty1', hAlign: 2, width: 60, type: 'Number'},
  3292. {title: '|项目节数量2', colSpan: '|1', rowSpan: '|1', field: 'c_dgn_qty2', hAlign: 2, width: 60, type: 'Number'},
  3293. {title: '经济指标', colSpan: '1', rowSpan: '2', field: 'final_dgn_price', hAlign: 2, width: 60, type: 'Number'},
  3294. {title: '本期批注', colSpan: '1', rowSpan: '2', field: 'postil', hAlign: 0, width: 100, formatter: '@', cellType: 'autoTip'},
  3295. {title: '图(册)号', colSpan: '1', rowSpan: '2', field: 'drawing_code', hAlign: 0, width: 80, formatter: '@'},
  3296. {title: '备注', colSpan: '1', rowSpan: '2', field: 'memo', hAlign: 0, width: 100, formatter: '@', cellType: 'ellipsisAutoTip'},
  3297. ],
  3298. headRows: 2,
  3299. headRowHeight: [25, 25],
  3300. defaultRowHeight: 21,
  3301. headerFont: 'bold 10px 微软雅黑',
  3302. font: '10px 微软雅黑'
  3303. };
  3304. for (const node of stageTree.nodes) {
  3305. data.push({
  3306. code: node.code, b_code: node.b_code, name: node.name, unit: node.unit,
  3307. unit_price: node.unit_price, quantity: node.quantity, total_price: node.total_price,
  3308. contract_qty: node.contract_qty, contract_tp: node.contract_tp,
  3309. qc_qty: node.qc_qty, qc_tp: node.qc_tp,
  3310. gather_qty: node.gather_qty, gather_tp: node.gather_tp,
  3311. end_contract_qty: node.end_contract_qty, end_contract_tp: node.end_contract_tp,
  3312. end_qc_qty: node.end_qc_qty, end_qc_tp: node.end_qc_tp,
  3313. end_gather_qty: node.end_gather_qty, end_gather_tp: node.end_gather_tp, end_gather_percent: node.end_gather_percent,
  3314. deal_dgn_qty1: node.deal_dgn_qty1, deal_dgn_qty2: node.deal_dgn_qty2,
  3315. c_dgn_qty1: node.c_dgn_qty1, c_dgn_qty2: node.c_dgn_qty2,
  3316. final_dgn_price: node.final_dgn_price,
  3317. postil: node.postil, drawing_code: node.drawing_code, memo: node.memo,
  3318. });
  3319. const posRange = stagePos.getLedgerPos(node.id);
  3320. if (posRange && posRange.length > 0) {
  3321. for (const [i, p] of posRange.entries()) {
  3322. data.push({
  3323. pos_code: (i + 1) + '', name: p.name,
  3324. quantity: p.quantity,
  3325. contract_qty: p.contract_qty, qc_qty: p.qc_qty, gather_qty: p.gather_qty,
  3326. end_contract_qty: p.end_contract_qty, end_qc_qty: p.end_qc_qty, end_gather_qty: p.end_gather_qty,
  3327. drawing_code: p.drawing_code, memo: p.memo
  3328. });
  3329. }
  3330. }
  3331. }
  3332. SpreadExcelObj.exportSimpleXlsxSheet(setting, data, $('.sidebar-title').attr('data-original-title') + "计量台账.xlsx");
  3333. });
  3334. });