stage.js 176 KB

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