stage.js 159 KB

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