stage.js 183 KB

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