stage.js 127 KB

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