stage.js 189 KB

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