stage.js 130 KB

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