stage.js 132 KB

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