stage.js 194 KB

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