stage.js 127 KB

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