stage.js 183 KB

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