stage.js 179 KB

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