stage.js 130 KB

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