stage.js 130 KB

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