stage.js 131 KB

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