stage.js 160 KB

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