stage.js 140 KB

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