stage.js 196 KB

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