stage.js 130 KB

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