stage.js 153 KB

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