stage.js 192 KB

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