stage.js 171 KB

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