stage.js 133 KB

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