stage.js 135 KB

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