stage.js 131 KB

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