stage.js 198 KB

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