stage.js 168 KB

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