stage.js 133 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805
  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. if ((node.pre_used === 1 || !checkZero(node.gather_qty) || !checkZero(node.gather_tp)) && sortData.length === 0) {
  1012. toastr.error('无计量单元的清单,计量后,不可新增计量单元');
  1013. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1014. return;
  1015. }
  1016. const order = (!sortData || sortData.length === 0) ? 1 : Math.max(sortData[sortData.length - 1].porder + 1, sortData.length + 1);
  1017. data.updateData = {name: newText, lid: node.id, tid: tender.id, porder: order};
  1018. } else {
  1019. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1020. return;
  1021. }
  1022. } else {
  1023. data.updateType = 'update';
  1024. data.updateData = {pid: posData.id, lid: posData.lid, name: newText};
  1025. }
  1026. } else if (!posData) {
  1027. toastr.warning('新增部位请先输入名称');
  1028. } else {
  1029. data.updateType = 'update';
  1030. data.updateData = {pid: posData.id, lid: posData.lid};
  1031. if (col.type === 'Number') {
  1032. const num = _.toNumber(newText);
  1033. if (_.isFinite(num)) {
  1034. data.updateData[col.field] = num;
  1035. } else {
  1036. try {
  1037. data.updateData[col.field] = math.evaluate(transExpr(newText));
  1038. } catch(err) {
  1039. toastr.error('输入的表达式非法');
  1040. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1041. return;
  1042. }
  1043. }
  1044. } else {
  1045. data.updateData[col.field] = newText;
  1046. }
  1047. }
  1048. // 提交数据到服务器
  1049. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  1050. if (result.pos) {
  1051. stagePos.updateDatas(result.pos.pos);
  1052. stagePos.loadCurStageData(result.pos.curStageData);
  1053. }
  1054. const refreshData = stageTree.loadPostStageData(result.ledger);
  1055. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  1056. stagePosSpreadObj.loadCurPosData();
  1057. if (detail) {
  1058. detail.loadStagePosUpdateData(result);
  1059. } else {
  1060. stageIm.loadUpdatePosData(result);
  1061. }
  1062. }, function () {
  1063. stagePosSpreadObj.loadCurPosData();
  1064. });
  1065. }
  1066. },
  1067. editStarting: function (e, info) {
  1068. stagePosSpreadObj.stageTreeNode = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1069. },
  1070. clipboardPasting: function (e, info) {
  1071. if (info.sheet.zh_setting) {
  1072. const sortData = info.sheet.zh_data;
  1073. const range = info.cellRange;
  1074. const validField = ['contract_qty', 'qc_qty', 'postil'];
  1075. if (!checkTzMeasureType()) {
  1076. validField.push('name', 'sgfh_qty', 'sjcl_qty', 'qtcl_qty');
  1077. }
  1078. for (let iCol = range.col; iCol < range.col + range.colCount; iCol++) {
  1079. const col = info.sheet.zh_setting.cols[iCol];
  1080. if (validField.indexOf(col.field) === -1) {
  1081. if (checkTzMeasureType()) {
  1082. toastr.error('不可修改此数据');
  1083. info.cancel = true;
  1084. return;
  1085. } else {
  1086. for (let iRow = range.row; iRow < range.row + range.rowCount; iRow) {
  1087. const pos = sortData(iRow);
  1088. if (pos.add_stage !== stage.id || pos.add_times !== stage.times) {
  1089. toastr.error('不可修改此数据');
  1090. info.cancel = true;
  1091. return;
  1092. }
  1093. }
  1094. }
  1095. }
  1096. }
  1097. }
  1098. },
  1099. clipboardPasted: function (e, info) {
  1100. if (info.sheet.zh_setting) {
  1101. const data = { updateType: '', updateData: [], };
  1102. const sortData = info.sheet.zh_data;
  1103. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1104. if (sortData && (info.cellRange.row >= sortData.length)) {
  1105. data.updateType = 'add';
  1106. if (info.cellRange.col !== 0) {
  1107. toastr.warning('新增部位请先输入名称');
  1108. stagePosSpreadObj.loadCurPosData();
  1109. return;
  1110. }
  1111. if ((node.pre_used === 1 || !checkZero(node.gather_qty) || !checkZero(node.gather_tp)) && sortData.length === 0) {
  1112. toastr.error('无计量单元的清单,计量后,不可新增计量单元');
  1113. stagePosSpreadObj.loadCurPosData();
  1114. return;
  1115. }
  1116. const lastOrder = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  1117. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  1118. const curRow = info.cellRange.row + iRow;
  1119. const newData = {lid: node.id, porder: lastOrder + curRow - sortData.length};
  1120. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  1121. const curCol = info.cellRange.col + iCol;
  1122. const colSetting = info.sheet.zh_setting.cols[curCol];
  1123. newData[colSetting.field] = trimInvalidChar(info.sheet.getText(curRow, curCol));
  1124. if (colSetting.type === 'Number') {
  1125. const num = _.toNumber(newData[colSetting.field]);
  1126. if (num) {
  1127. newData[colSetting.field] = num;
  1128. } else {
  1129. try {
  1130. newData[colSetting.field] = math.evaluate(transExpr(newData[colSetting.field]));
  1131. } catch(err) {
  1132. toastr.error('输入的表达式非法');
  1133. stagePosSpreadObj.loadCurPosData();
  1134. return;
  1135. }
  1136. }
  1137. }
  1138. }
  1139. data.updateData.push(newData);
  1140. }
  1141. } else {
  1142. data.updateType = 'update';
  1143. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  1144. const curRow = info.cellRange.row + iRow;
  1145. const curPos = sortData[curRow];
  1146. if (curPos) {
  1147. const newData = {pid: curPos.id, lid: curPos.lid};
  1148. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  1149. const curCol = info.cellRange.col + iCol;
  1150. const colSetting = info.sheet.zh_setting.cols[curCol];
  1151. newData[colSetting.field] = trimInvalidChar(info.sheet.getText(curRow, curCol));
  1152. if (colSetting.type === 'Number') {
  1153. const num = _.toNumber(newData[colSetting.field]);
  1154. if (num) {
  1155. newData[colSetting.field] = num;
  1156. } else {
  1157. try {
  1158. newData[colSetting.field] = math.evaluate(transExpr(newData[colSetting.field]));
  1159. } catch(err) {
  1160. toastr.error('输入的表达式非法');
  1161. stagePosSpreadObj.loadCurPosData();
  1162. return;
  1163. }
  1164. }
  1165. }
  1166. }
  1167. data.updateData.push(newData);
  1168. }
  1169. }
  1170. }
  1171. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  1172. if (result.pos) {
  1173. stagePos.updateDatas(result.pos.pos);
  1174. stagePos.loadCurStageData(result.pos.curStageData);
  1175. }
  1176. const nodes = stageTree.loadPostStageData(result.ledger);
  1177. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1178. stagePosSpreadObj.loadCurPosData();
  1179. if (detail) {
  1180. detail.loadStagePosUpdateData(result);
  1181. } else {
  1182. stageIm.loadUpdatePosData(result);
  1183. }
  1184. }, function () {
  1185. stagePosSpreadObj.loadCurPosData();
  1186. });
  1187. }
  1188. },
  1189. deletePress: function (sheet) {
  1190. if (sheet.zh_setting && sheet.zh_data) {
  1191. const sortData = sheet.zh_data;
  1192. if (!sortData || sortData.length === 0) { return; }
  1193. const sel = sheet.getSelections()[0];
  1194. const validCols = [];
  1195. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  1196. const colSetting = sheet.zh_setting.cols[iCol];
  1197. if (!colSetting.readOnly && colSetting.field !== 'qc_qty') {
  1198. validCols.push(iCol);
  1199. }
  1200. }
  1201. if (validCols.length === 0) { return; }
  1202. const datas = [], posSelects = [];
  1203. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  1204. const node = sortData[iRow];
  1205. if (node) {
  1206. const data = {pid: node.id, lid: node.lid};
  1207. for (const iCol of validCols) {
  1208. const colSetting = sheet.zh_setting.cols[iCol];
  1209. if (colSetting.field === 'name') {
  1210. toastr.error('部位名称不能为空');
  1211. return;
  1212. }
  1213. data[colSetting.field] = null;
  1214. }
  1215. datas.push(data);
  1216. posSelects.push(node);
  1217. }
  1218. }
  1219. if (datas.length > 0) {
  1220. postData(window.location.pathname + '/update', {pos: {updateType: 'update', updateData: datas} }, function (result) {
  1221. if (result.pos) {
  1222. stagePos.updateDatas(result.pos.pos);
  1223. stagePos.loadCurStageData(result.pos.curStageData);
  1224. }
  1225. const nodes = stageTree.loadPostStageData(result.ledger);
  1226. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1227. if (detail) {
  1228. detail.loadStagePosUpdateData(result);
  1229. } else {
  1230. stageIm.loadUpdatePosData(result);
  1231. }
  1232. // todo 只加载改变项
  1233. stagePosSpreadObj.loadCurPosData();
  1234. });
  1235. }
  1236. }
  1237. },
  1238. deletePos: function (sheet) {
  1239. const sels = sheet.getSelections();
  1240. const sel = sels ? sels[0] : null;
  1241. if (sheet.zh_data && sel) {
  1242. const data = {updateType: 'delete', updateData: []};
  1243. for (let iRow = 0; iRow < sel.rowCount; iRow++) {
  1244. const posData = sheet.zh_data[sel.row + iRow];
  1245. if (posData) {
  1246. data.updateData.push(posData.id);
  1247. }
  1248. }
  1249. if (data.updateData.length > 0) {
  1250. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  1251. stagePos.removeDatas(result.pos.pos);
  1252. const refreshData = stageTree.loadPostStageData(result.ledger);
  1253. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  1254. stagePosSpreadObj.loadCurPosData();
  1255. if (detail) {
  1256. detail.loadStagePosUpdateData(result);
  1257. } else {
  1258. stageIm.loadUpdatePosData(result);
  1259. }
  1260. });
  1261. }
  1262. }
  1263. },
  1264. selectionChanged: function (e, info) {
  1265. stagePosSpreadObj.loadExprToInput(info.sheet);
  1266. },
  1267. addPegs: function (pegs) {
  1268. if (!pegs || pegs.length <= 0) return;
  1269. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1270. if (!node) return;
  1271. const sheet = spSpread.getActiveSheet();
  1272. const sortData = sheet.zh_data || [];
  1273. let order = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  1274. pegs.forEach(function (p) {p.porder = ++order; p.lid = node.id});
  1275. postData(window.location.pathname + '/update', {pos: {updateType: 'add', updateData: pegs} }, function (result) {
  1276. if (result.pos) {
  1277. stagePos.updateDatas(result.pos.pos);
  1278. }
  1279. stagePosSpreadObj.loadCurPosData();
  1280. });
  1281. }
  1282. };
  1283. // 加载上下窗口resizer
  1284. $.divResizer({
  1285. select: '#main-resize',
  1286. callback: function () {
  1287. slSpread.refresh();
  1288. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  1289. $(".sp-wrap").height(bcontent-30);
  1290. spSpread.refresh();
  1291. }
  1292. });
  1293. // 加载计量单元数据 - 暂时统一加载,如有需要,切换成动态加载并缓存
  1294. postData(window.location.pathname + '/load', { filter: 'ledger;pos;detail;change' }, function (result) {
  1295. // 加载树结构
  1296. stageTree.loadDatas(result.ledgerData);
  1297. // stageTree.loadCurStageData(curStageData);
  1298. // stageTree.loadPreStageData(preStageData);
  1299. treeCalc.calculateAll(stageTree);
  1300. SpreadJsObj.loadSheetData(slSpread.getActiveSheet(), 'tree', stageTree);
  1301. SpreadJsObj.loadTopAndSelect(slSpread.getActiveSheet(), ckBillsSpread);
  1302. // 加载部位明细
  1303. stagePos.loadDatas(result.posData);
  1304. stagePos.calculateAll();
  1305. stagePosSpreadObj.loadCurPosData();
  1306. SpreadJsObj.resetTopAndSelect(spSpread.getActiveSheet());
  1307. // 加载中间计量
  1308. stageIm.init(stage, imType);
  1309. stageIm.loadData(result.ledgerData, result.posData, result.detailData, result.changeData);
  1310. }, null, true);
  1311. spSpread.bind(spreadNS.Events.EditEnded, stagePosSpreadObj.editEnded);
  1312. spSpread.bind(spreadNS.Events.ClipboardPasting, stagePosSpreadObj.clipboardPasting);
  1313. spSpread.bind(spreadNS.Events.ClipboardPasted, stagePosSpreadObj.clipboardPasted);
  1314. spSpread.bind(spreadNS.Events.EditStarting, stagePosSpreadObj.editStarting);
  1315. spSpread.bind(spreadNS.Events.SelectionChanged, stagePosSpreadObj.selectionChanged);
  1316. SpreadJsObj.addDeleteBind(spSpread, stagePosSpreadObj.deletePress);
  1317. if (!readOnly) {
  1318. $('#pos-expr').bind('change mouseleave', function () {
  1319. if (this.readOnly) return;
  1320. const expr = $(this);
  1321. const posSheet = spSpread.getActiveSheet();
  1322. const select = SpreadJsObj.getSelectObject(posSheet);
  1323. const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = expr.val(), row = expr.attr('row');
  1324. if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
  1325. const data = {pid: select.id, lid: select.lid};
  1326. const num = _.toNumber(newValue);
  1327. if (num) {
  1328. data[field] = num;
  1329. } else {
  1330. try {
  1331. data[field] = math.evaluate(transExpr(newValue));
  1332. } catch (err) {
  1333. toastr.error('输入的表达式非法');
  1334. return;
  1335. }
  1336. }
  1337. // 提交数据到服务器
  1338. postData(window.location.pathname + '/update', {pos: {updateType: 'update', updateData: data}}, function (result) {
  1339. if (result.pos) {
  1340. stagePos.updateDatas(result.pos.pos);
  1341. stagePos.loadCurStageData(result.pos.curStageData);
  1342. expr.val(select[field]);
  1343. SpreadJsObj.reLoadRowData(posSheet, _.toNumber(row));
  1344. }
  1345. const refreshData = stageTree.loadPostStageData(result.ledger);
  1346. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  1347. });
  1348. });
  1349. }
  1350. if (!checkTzMeasureType()) {
  1351. const mergePeg = NewMergePeg({ callback: stagePosSpreadObj.addPegs});
  1352. $.contextMenu({
  1353. selector: '#stage-pos',
  1354. build: function ($trigger, e) {
  1355. const target = SpreadJsObj.safeRightClickSelection($trigger, e, spSpread);
  1356. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  1357. },
  1358. items: {
  1359. 'del': {
  1360. name: '删除',
  1361. icon: 'fa-remove',
  1362. disabled: function (key, opt) {
  1363. const sheet = spSpread.getActiveSheet();
  1364. if (sheet.zh_data && !readOnly) {
  1365. const selection = sheet.getSelections();
  1366. if (selection && selection[0]) {
  1367. let valid = sheet.zh_data.length < selection[0].row + selection[0].rowCount;
  1368. for (let iRow = 0; iRow < selection[0].rowCount; iRow++) {
  1369. const posData = sheet.zh_data[selection[0].row + iRow];
  1370. if (posData) {
  1371. if (posData.add_stage_order < stage.order || ZhCalc.isNonZero(posData.gather_qty) || ZhCalc.isNonZero(posData.end_gather_qty)) {
  1372. valid = true;
  1373. break;
  1374. }
  1375. } else {
  1376. valid = true;
  1377. break;
  1378. }
  1379. }
  1380. return valid;
  1381. } else {
  1382. return true;
  1383. }
  1384. } else {
  1385. return true;
  1386. }
  1387. },
  1388. callback: function (key, opt) {
  1389. stagePosSpreadObj.deletePos(spSpread.getActiveSheet());
  1390. }
  1391. },
  1392. 'merge-peg': {
  1393. name: '合并起讫桩号',
  1394. disabled: function (key, opt) {
  1395. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1396. return _.isNil(node) || _.isNil(node.b_code) || node.b_code === '';
  1397. },
  1398. callback: function (key, opt) {
  1399. mergePeg.show();
  1400. }
  1401. }
  1402. }
  1403. })
  1404. } else {
  1405. SpreadJsObj.forbiddenSpreadContextMenu('#stage-pos', spSpread);
  1406. }
  1407. $.subMenu({
  1408. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  1409. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  1410. key: 'menu.1.0.0',
  1411. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  1412. callback: function (info) {
  1413. if (info.mini) {
  1414. $('.panel-title').addClass('fluid');
  1415. $('#sub-menu').removeClass('panel-sidebar');
  1416. } else {
  1417. $('.panel-title').removeClass('fluid');
  1418. $('#sub-menu').addClass('panel-sidebar');
  1419. }
  1420. autoFlashHeight();
  1421. slSpread.refresh();
  1422. spSpread.refresh();
  1423. if (searchLedger) {
  1424. searchLedger.spread.refresh();
  1425. }
  1426. if (detail) {
  1427. detail.spread.refresh();
  1428. }
  1429. }
  1430. });
  1431. $('#row-view').on('show.bs.modal', function () {
  1432. const html = [], customDisplay = customColDisplay();
  1433. for (const cd of customDisplay) {
  1434. html.push('<tr>');
  1435. html.push('<td>', cd.title, '</td>');
  1436. html.push('<td>', '<input type="checkbox"' + (cd.visible ? ' checked=""' : '') + '>', '</td>');
  1437. html.push('</tr>');
  1438. }
  1439. $('#row-view-list').html(html.join(''));
  1440. });
  1441. $('#row-view-ok').click(function () {
  1442. const customDisplay = customColDisplay();
  1443. const cvl = $('#row-view-list').children();
  1444. for (const cv of cvl) {
  1445. const title = $(cv).children()[0].innerHTML;
  1446. const check = $('input', cv)[0].checked;
  1447. const cd = customDisplay.find(function (c) {
  1448. return c.title === title;
  1449. });
  1450. cd.visible = check;
  1451. }
  1452. customizeStageTreeSetting(ledgerSpreadSetting, customDisplay);
  1453. SpreadJsObj.refreshColumnVisible(slSpread.getActiveSheet());
  1454. Cookies.set(ckColSetting, JSON.stringify(customDisplay), 30*24*60*60*1000);
  1455. $('#row-view').modal('hide');
  1456. });
  1457. class SearchLedger {
  1458. constructor(obj, mainSpread) {
  1459. const self = this;
  1460. this.obj = obj;
  1461. this.mainSpread = mainSpread;
  1462. this.spreadSetting = {
  1463. cols: [
  1464. {title: '项目节编号', field: 'code', hAlign: 0, width: 120, formatter: '@'},
  1465. {title: '清单编号', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
  1466. {title: '名称', field: 'name', width: 150, hAlign: 0, formatter: '@'},
  1467. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@'},
  1468. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  1469. {title: '数量', field: 'quantity', hAlign: 2, width: 50},
  1470. {title: '完成率(%)', field: 'complete_percent', hAlign: 2, width: 70},
  1471. ],
  1472. emptyRows: 0,
  1473. headRows: 1,
  1474. headRowHeight: [32],
  1475. defaultRowHeight: 21,
  1476. headerFont: '12px 微软雅黑',
  1477. font: '12px 微软雅黑',
  1478. readOnly: true
  1479. };
  1480. this.spread = SpreadJsObj.createNewSpread($('#search-result', this.obj)[0]);
  1481. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  1482. $('#keyword', this.obj).bind('keydown', function(e) {
  1483. if (e.keyCode == 13) self.searchText();
  1484. });
  1485. $('#searchLedger', this.obj).bind('click', () => {self.searchText()});
  1486. $('#over', this.obj).bind('change', () => {self.searchOver()});
  1487. $('#empty', this.obj).bind('change', () => {self.searchLess()});
  1488. this.spread.getActiveSheet().bind(GC.Spread.Sheets.Events.CellDoubleClick, function (e, info) {
  1489. const sheet = info.sheet;
  1490. const data = sheet.zh_data;
  1491. if (!data) { return }
  1492. const curBills = data[info.row];
  1493. if (!curBills) { return }
  1494. SpreadJsObj.locateTreeNode(self.mainSpread.getActiveSheet(), curBills.ledger_id, true);
  1495. stagePosSpreadObj.loadCurPosData();
  1496. });
  1497. }
  1498. calculateCompletePercent() {
  1499. if (!this.searchResult) return;
  1500. for (const sr of this.searchResult) {
  1501. const base = ZhCalc.add(sr.total_price, sr.end_qc_tp);
  1502. sr.complete_percent = base !== 0 ? ZhCalc.mul(ZhCalc.div(sr.end_gather_tp, base), 100, 2) : 0;
  1503. }
  1504. }
  1505. searchText() {
  1506. const keyword = $('#keyword', this.obj).val();
  1507. if (keyword !== '') {
  1508. $('#over', this.obj)[0].checked = false;
  1509. $('#empty', this.obj)[0].checked = false;
  1510. this.searchResult = [];
  1511. const sortData = SpreadJsObj.getSortData(this.mainSpread.getActiveSheet());
  1512. for (const node of sortData) {
  1513. if ((node.code && node.code.indexOf(keyword) > -1) ||
  1514. node.b_code && node.b_code.indexOf(keyword) > -1 ||
  1515. node.name && node.name.indexOf(keyword) > -1) {
  1516. const data = JSON.parse(JSON.stringify(node));
  1517. data.visible = true;
  1518. this.searchResult.push(data);
  1519. }
  1520. }
  1521. this.calculateCompletePercent();
  1522. SpreadJsObj.loadSheetData(this.spread.getActiveSheet(), 'data', this.searchResult);
  1523. }
  1524. }
  1525. searchOver() {
  1526. this.searchResult = [];
  1527. const sortData = SpreadJsObj.getSortData(this.mainSpread.getActiveSheet());
  1528. for (const node of sortData) {
  1529. if (node.children && node.children.length > 0) continue;
  1530. if (node.end_gather_qty) {
  1531. if (!node.quantity || Math.abs(node.end_gather_qty) > Math.abs(ZhCalc.add(node.quantity, node.end_qc_qty))) {
  1532. const data = JSON.parse(JSON.stringify(node));
  1533. data.visible = true;
  1534. this.searchResult.push(data);
  1535. }
  1536. } else if (node.end_gather_tp) {
  1537. if (!node.total_price || Math.abs(node.end_gather_tp) > Math.abs(ZhCalc.add(node.total_price, node.end_qc_tp))) {
  1538. const data = JSON.parse(JSON.stringify(node));
  1539. data.visible = true;
  1540. this.searchResult.push(data);
  1541. }
  1542. }
  1543. }
  1544. this.calculateCompletePercent();
  1545. SpreadJsObj.loadSheetData(this.spread.getActiveSheet(), 'data', this.searchResult);
  1546. }
  1547. searchEmpty() {
  1548. this.searchResult = [];
  1549. const sortData = SpreadJsObj.getSortData(this.mainSpread.getActiveSheet());
  1550. for (const node of sortData) {
  1551. if (node.children && node.children.length > 0) continue;
  1552. if (node.quantity) {
  1553. if (!node.end_gather_qty || checkZero(node.end_gather_qty)) {
  1554. const data = JSON.parse(JSON.stringify(node));
  1555. data.visible = true;
  1556. this.searchResult.push(data);
  1557. }
  1558. } else if (node.total_price) {
  1559. if (!node.end_gather_tp || checkZero(node.end_gather_tp)) {
  1560. const data = JSON.parse(JSON.stringify(node));
  1561. data.visible = true;
  1562. this.searchResult.push(data);
  1563. }
  1564. }
  1565. }
  1566. this.calculateCompletePercent();
  1567. SpreadJsObj.loadSheetData(this.spread.getActiveSheet(), 'data', this.searchResult);
  1568. }
  1569. searchLess() {
  1570. this.searchResult = [];
  1571. const sortData = SpreadJsObj.getSortData(this.mainSpread.getActiveSheet());
  1572. for (const node of sortData) {
  1573. if (node.children && node.children.length > 0) continue;
  1574. if (node.quantity) {
  1575. if (ZhCalc.sub(ZhCalc.add(node.quantity, node.end_qc_qty), node.end_gather_qty) > 0) {
  1576. const data = JSON.parse(JSON.stringify(node));
  1577. data.visible = true;
  1578. this.searchResult.push(data);
  1579. }
  1580. } else if (node.total_price) {
  1581. if (ZhCalc.sub(ZhCalc.add(node.total_price, node.end_qc_tp), node.end_gather_tp) > 0) {
  1582. const data = JSON.parse(JSON.stringify(node));
  1583. data.visible = true;
  1584. this.searchResult.push(data);
  1585. }
  1586. }
  1587. }
  1588. this.calculateCompletePercent();
  1589. SpreadJsObj.loadSheetData(this.spread.getActiveSheet(), 'data', this.searchResult);
  1590. }
  1591. }
  1592. const posSearch = (function () {
  1593. let resultArr = [];
  1594. const search = function () {
  1595. resultArr = [];
  1596. const keyword = $('#pos-search-keyword').val();
  1597. const checkOver = $('#pos-over-search')[0].checked;
  1598. const checkEmpty = $('#pos-empty-search')[0].checked;
  1599. const sortData = spSpread.getActiveSheet().zh_data;
  1600. if (checkOver || checkEmpty) {
  1601. if (sortData) {
  1602. for (let i = 0, iLength = sortData.length; i < iLength; i++) {
  1603. const sd = sortData[i];
  1604. let match = false;
  1605. if (checkOver) {
  1606. if (sd.end_gather_qty) {
  1607. if (!sd.quantity || Math.abs(sd.end_gather_qty) > Math.abs(ZhCalc.add(sd.quantity, sd.end_qc_qty))) match = true;
  1608. }
  1609. }
  1610. if (checkEmpty) {
  1611. if (sd.quantity) {
  1612. if (!sd.end_gather_qty || ZhCalc.sub(ZhCalc.add(sd.quantity, sd.end_qc_qty), sd.end_gather_qty) > 0) match = true;
  1613. }
  1614. }
  1615. if (keyword && keyword !== '' && sd.name && sd.name.indexOf(keyword) === -1) match = false;
  1616. if (match) {
  1617. resultArr.push({index: i, data: sd});
  1618. }
  1619. }
  1620. }
  1621. } else if (keyword && keyword !== '') {
  1622. if (sortData) {
  1623. for (let i = 0, iLength = sortData.length; i < iLength; i++) {
  1624. const sd = sortData[i];
  1625. if (sd.name && sd.name.indexOf(keyword) > -1) {
  1626. resultArr.push({index: i, data: sd});
  1627. }
  1628. }
  1629. }
  1630. }
  1631. $('#pos-search-result').html('结果:' + resultArr.length);
  1632. };
  1633. const searchAndLocate = function () {
  1634. search();
  1635. if (resultArr.length > 0) {
  1636. const sheet = spSpread.getActiveSheet();
  1637. const sel = sheet.getSelections()[0];
  1638. const curRow = sel ? sel.row : 0;
  1639. const pos = resultArr[0];
  1640. if (pos.index !== curRow) {
  1641. sheet.setSelection(pos.index, sel ? sel.col : 0, 1, 1);
  1642. sheet.showRow(pos.index, spreadNS.VerticalPosition.center);
  1643. }
  1644. }
  1645. };
  1646. const locateNext = function () {
  1647. if (resultArr.length > 0) {
  1648. const sheet = spSpread.getActiveSheet();
  1649. const sel = sheet.getSelections()[0];
  1650. const curRow = sel ? sel.row : 0;
  1651. let next = _.find(resultArr, function (d) {
  1652. return d.index > curRow;
  1653. });
  1654. if (!next) next = resultArr[0];
  1655. if (next.index !== curRow) {
  1656. sheet.setSelection(next.index, sel ? sel.col : 0, 1, 1);
  1657. sheet.showRow(next.index, spreadNS.VerticalPosition.center);
  1658. }
  1659. }
  1660. };
  1661. const locatePre = function () {
  1662. if (resultArr.length > 0) {
  1663. const sheet = spSpread.getActiveSheet();
  1664. const sel = sheet.getSelections()[0];
  1665. const curRow = sel ? sel.row : 0;
  1666. let next = _.findLast(resultArr, function (d) {
  1667. return d.index < curRow;
  1668. });
  1669. if (!next) next = resultArr[resultArr.length - 1];
  1670. if (next.index !== curRow) {
  1671. sheet.setSelection(next.index, sel ? sel.col : 0, 1, 1);
  1672. sheet.showRow(next.index, spreadNS.VerticalPosition.center);
  1673. }
  1674. }
  1675. };
  1676. return {search, searchAndLocate, locateNext, locatePre};
  1677. })();
  1678. $('#pos-search-keyword').bind('keydown', function(e){
  1679. if (e.keyCode == 13) posSearch.searchAndLocate();
  1680. });
  1681. $('#pos-empty-search').click(function () {
  1682. if (this.checked) {
  1683. $('[for=' + this.id +']').addClass('text-warning');
  1684. } else {
  1685. $('[for=' + this.id +']').removeClass('text-warning');
  1686. }
  1687. if (this.checked) {
  1688. if ($('#pos-over-search')[0].checked) {
  1689. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  1690. } else {
  1691. $('#pos-search-keyword').attr('placeholder', '漏计中按名称查询');
  1692. }
  1693. } else {
  1694. if ($('#pos-over-search')[0].checked) {
  1695. $('#pos-search-keyword').attr('placeholder', '超计中按名称查询');
  1696. } else {
  1697. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  1698. }
  1699. }
  1700. posSearch.searchAndLocate();
  1701. });
  1702. $('#pos-over-search').click(function () {
  1703. if (this.checked) {
  1704. $('[for=' + this.id +']').addClass('text-danger');
  1705. } else {
  1706. $('[for=' + this.id +']').removeClass('text-danger');
  1707. }
  1708. if (this.checked) {
  1709. if ($('#pos-empty-search')[0].checked) {
  1710. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  1711. } else {
  1712. $('#pos-search-keyword').attr('placeholder', '超计中按名称查询');
  1713. }
  1714. } else {
  1715. if ($('#pos-empty-search')[0].checked) {
  1716. $('#pos-search-keyword').attr('placeholder', '漏计中按名称查询');
  1717. } else {
  1718. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  1719. }
  1720. }
  1721. posSearch.searchAndLocate();
  1722. });
  1723. $('#pos-search-next').click(() => {posSearch.locateNext()});
  1724. $('#pos-search-pre').click(() => {posSearch.locatePre()});
  1725. $.divResizer({
  1726. select: '#right-spr',
  1727. callback: function () {
  1728. slSpread.refresh();
  1729. spSpread.refresh();
  1730. if (searchLedger) {
  1731. searchLedger.spread.refresh();
  1732. }
  1733. if (detail) {
  1734. detail.spread.refresh();
  1735. }
  1736. }
  1737. });
  1738. class Detail {
  1739. constructor (obj) {
  1740. const self = this;
  1741. this.spreadSetting = {
  1742. cols: [
  1743. {title: '编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 80, formatter: '@', readOnly: true},
  1744. {title: '中间计量表号', colSpan: '1', rowSpan: '1', field: 'im_code', hAlign: 0, width: 85, formatter: '@', readOnly: true},
  1745. {title: '交工证书/凭证号', colSpan: '1', rowSpan: '1', field: 'doc_code', hAlign: 0, width: 110, formatter: '@'},
  1746. {
  1747. title: stage.im_type === imType.tz.value ? '本期计量金额' : '本期计量数量',
  1748. colSpan: '1', rowSpan: '1', field: 'jl', hAlign: 2, width: 85, formatter: '@', readOnly: true
  1749. },
  1750. ],
  1751. headRows: 1,
  1752. emptyRows: 0,
  1753. headRowHeight: [32],
  1754. defaultRowHeight: 21,
  1755. headerFont: '12px 微软雅黑',
  1756. font: '12px 微软雅黑',
  1757. readOnly: readOnly,
  1758. };
  1759. this.spread = SpreadJsObj.createNewSpread(obj[0]);
  1760. this.sheet = this.spread.getActiveSheet();
  1761. this.spread.options.allowUserDragFill = true;
  1762. this.spread.options.defaultDragFillType = spreadNS.Fill.AutoFillType.fillSeries;
  1763. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  1764. this.detailObj = {
  1765. selectionChanged: function (e, info) {
  1766. self.reLoadDetailData();
  1767. },
  1768. editEnded: function(e, info) {
  1769. if (info.sheet.zh_setting) {
  1770. const col = info.sheet.zh_setting.cols[info.col];
  1771. if (col.field !== 'doc_code') {
  1772. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1773. return;
  1774. }
  1775. const data = SpreadJsObj.getSelectObject(info.sheet);
  1776. if (data) {
  1777. const updateData = {lid: data.lid, pid: data.pid};
  1778. if (data.uuid) {
  1779. updateData.uuid = data.uuid;
  1780. } else {
  1781. updateData.code = data.code;
  1782. updateData.name = data.name;
  1783. updateData.unit = data.unit;
  1784. updateData.unit_price = data.unit_price;
  1785. }
  1786. updateData.doc_code = info.editingText === null ? '' : info.editingText;
  1787. postData(window.location.pathname + '/detail/save', updateData, function (result) {
  1788. stageIm.loadUpdateDetailData(result);
  1789. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1790. }, function () {
  1791. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1792. });
  1793. } else {
  1794. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1795. }
  1796. }
  1797. },
  1798. clipboardPasted: function (e, info) {
  1799. if (info.sheet.zh_setting && info.sheet.zh_data) {
  1800. const col = info.sheet.zh_setting.cols[info.cellRange.col];
  1801. if (info.cellRange.colCount > 1) {
  1802. toastr.warning('请勿同时复制粘贴多列数据');
  1803. SpreadJsObj.reLoadSheetData(paySpread.getActiveSheet());
  1804. return;
  1805. }
  1806. if (col.field !== 'doc_code') {
  1807. SpreadJsObj.reLoadSheetData(paySpread.getActiveSheet());
  1808. return;
  1809. }
  1810. const datas = [];
  1811. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  1812. const curRow = info.cellRange.row + iRow;
  1813. const data = info.sheet.zh_data[curRow];
  1814. if (data) {
  1815. const updateData = {lid: data.lid, pid: data.pid};
  1816. if (data.uuid) {
  1817. updateData.uuid = data.uuid;
  1818. } else {
  1819. updateData.code = data.code;
  1820. updateData.name = data.name;
  1821. updateData.unit = data.unit;
  1822. updateData.unit_price = data.unit_price;
  1823. }
  1824. updateData.doc_code = info.sheet.getText(curRow, info.cellRange.col).replace('\n', '');
  1825. datas.push(updateData);
  1826. }
  1827. }
  1828. if (datas.length > 0) {
  1829. postData(window.location.pathname + '/detail/save', datas, function (result) {
  1830. stageIm.loadUpdateDetailData(result);
  1831. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1832. }, function () {
  1833. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1834. })
  1835. }
  1836. }
  1837. },
  1838. deletePress: function (sheet) {
  1839. if (sheet.zh_setting) {
  1840. const datas = [];
  1841. const sel = sheet.getSelections()[0];
  1842. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  1843. const col = sheet.zh_setting.cols[iCol];
  1844. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  1845. const data = sheet.zh_data[iRow];
  1846. if (col.field === 'doc_code') {
  1847. const updateData = {lid: data.lid};
  1848. if (data.uuid) {
  1849. updateData.uuid = data.uuid;
  1850. updateData.doc_code = '';
  1851. datas.push(updateData);
  1852. }
  1853. }
  1854. }
  1855. }
  1856. if (datas.length > 0) {
  1857. postData(window.location.pathname + '/detail/save', datas, function (result) {
  1858. stageIm.loadUpdateDetailData(result);
  1859. SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
  1860. }, function () {
  1861. SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
  1862. });
  1863. }
  1864. }
  1865. },
  1866. dragFillBlock: function (e, info) {
  1867. info.cancel = true;
  1868. if (!info.sheet.zh_setting || !info.sheet.zh_data) return;
  1869. const sel = info.sheet.getSelections()[0];
  1870. const col = info.sheet.zh_setting.cols[info.fillRange.col];
  1871. if (info.fillRange.colCount > 1 || !sel || col.field !== 'doc_code') return;
  1872. const text = info.sheet.getText(sel.row + sel.rowCount - 1, sel.col);
  1873. if (text === '') return;
  1874. const regRst = /(\d+)$/g.exec(text), datas = [];
  1875. for (let iRow = 0; iRow < info.fillRange.rowCount; iRow++) {
  1876. const curRow = info.fillRange.row + iRow;
  1877. const data = info.sheet.zh_data[curRow];
  1878. if (data) {
  1879. const updateData = {lid: data.lid};
  1880. if (data.uuid) {
  1881. updateData.uuid = data.uuid;
  1882. } else {
  1883. updateData.code = data.code;
  1884. updateData.name = data.name;
  1885. updateData.unit = data.unit;
  1886. updateData.unit_price = data.unit_price;
  1887. }
  1888. if (regRst) {
  1889. updateData.doc_code = text.substr(0, regRst.index) + (parseInt(regRst[0]) + iRow + 1);
  1890. } else {
  1891. updateData.doc_code = text.replace('\n', '');
  1892. }
  1893. datas.push(updateData);
  1894. }
  1895. }
  1896. if (datas.length > 0) {
  1897. postData(window.location.pathname + '/detail/save', datas, function (result) {
  1898. stageIm.loadUpdateDetailData(result);
  1899. SpreadJsObj.reLoadRowData(info.sheet, info.fillRange.row, info.fillRange.rowCount);
  1900. }, function () {
  1901. SpreadJsObj.reLoadRowData(info.sheet, info.fillRange.row, info.fillRange.rowCount);
  1902. })
  1903. }
  1904. },
  1905. };
  1906. this.spread.bind(spreadNS.Events.SelectionChanged, this.detailObj.selectionChanged);
  1907. if (!readOnly) {
  1908. this.spread.bind(spreadNS.Events.EditEnded, this.detailObj.editEnded);
  1909. this.spread.bind(spreadNS.Events.ClipboardPasted, this.detailObj.clipboardPasted);
  1910. this.spread.bind(spreadNS.Events.DragFillBlock, this.detailObj.dragFillBlock);
  1911. SpreadJsObj.addDeleteBind(this.spread, this.detailObj.deletePress);
  1912. }
  1913. this._initImTypeSetRela();
  1914. this._initModifyDetail();
  1915. // 草图相关
  1916. this._initImageRela();
  1917. this.reBuildImData();
  1918. }
  1919. _initImTypeSetRela() {
  1920. const self = this;
  1921. const gatherConfirmPopover = {
  1922. reBind: function (obj, eventName, fun) {
  1923. obj.unbind(eventName);
  1924. obj.bind(eventName, fun);
  1925. },
  1926. check: function (pos, hint, okCallback) {
  1927. const confirmObj = $('#gather-confirm'), hintObj = $('#gather-confirm-hint');
  1928. const okObj = $('#gather-confirm-ok'), cancelObj = $('#gather-confirm-cancel');
  1929. this.reBind(cancelObj, 'click', function () {
  1930. confirmObj.hide();
  1931. });
  1932. this.reBind(okObj, 'click', function () {
  1933. okCallback();
  1934. confirmObj.hide();
  1935. });
  1936. hintObj.text(hint);
  1937. confirmObj.css("top", pos.y).css("left", pos.x).show();
  1938. }
  1939. };
  1940. this.gsTree = stageIm.getGsTree();
  1941. if (stage.im_type === imType.tz.value) {
  1942. $('#type-title-contract').text('本期合同计量金额');
  1943. $('#type-title-qc').text('本期变更计量金额');
  1944. } else {
  1945. $('#type-title-contract').text('本期合同计量数量');
  1946. $('#type-title-qc').text('本期变更计量数量');
  1947. }
  1948. // 选择中间计量模式
  1949. $('div[name="im-type"]').click(function () {
  1950. function chooseType(obj) {
  1951. obj.style.cursor = 'default';
  1952. $(obj).children().addClass('text-primary');
  1953. $('h5', obj).prepend('<i class="fa fa-check pull-right"></i>');
  1954. }
  1955. function validType(obj) {
  1956. obj.style.cursor = 'pointer';
  1957. $(obj).children().removeClass('text-primary');
  1958. $('i', obj).remove();
  1959. }
  1960. if (this.style.cursor === 'pointer') {
  1961. const typeArr = $('div[name="im-type"]');
  1962. for (const t of typeArr) {
  1963. if ($(t).attr('im-type') === $(this).attr('im-type')) {
  1964. chooseType(t);
  1965. } else {
  1966. validType(t)
  1967. }
  1968. }
  1969. }
  1970. });
  1971. $('#choose').on('show.bs.modal', function () {
  1972. function chooseType(obj) {
  1973. obj.style.cursor = 'default';
  1974. $(obj).children().addClass('text-primary');
  1975. $('i', obj).remove();
  1976. $('h5', obj).prepend('<i class="fa fa-check pull-right"></i>');
  1977. }
  1978. function validType(obj) {
  1979. obj.style.cursor = 'pointer';
  1980. $(obj).children().removeClass('text-primary');
  1981. $('i', obj).remove();
  1982. }
  1983. $('#im-pre').val(stage.im_pre ? stage.im_pre : '');
  1984. const typeArr = $('div[name="im-type"]');
  1985. for (const t of typeArr) {
  1986. if (parseInt($(t).attr('im-type')) === stage.im_type) {
  1987. chooseType(t);
  1988. } else {
  1989. validType(t)
  1990. }
  1991. }
  1992. });
  1993. // 提交 中间计量模式
  1994. $('#choose-ok').click(() => {
  1995. const chooseType = _.find($('div[name="im-type"]', '#im-type'), function (it) {
  1996. return it.style.cursor !== 'pointer';
  1997. });
  1998. const data = {
  1999. im_type: parseInt($(chooseType).attr('im-type')),
  2000. im_pre: $('#im-pre').val(),
  2001. };
  2002. postData(window.location.pathname + '/detail/build', data, function (result) {
  2003. stage.im_type = data.im_type;
  2004. stage.im_pre = data.im_pre;
  2005. if (stage.im_type === imType.tz.value) {
  2006. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  2007. jlCol.title = '本期计量金额';
  2008. SpreadJsObj.reLoadSheetHeader(self.sheet);
  2009. $('#type-title-contract').text('本期合同计量金额');
  2010. $('#type-title-qc').text('本期变更计量金额');
  2011. } else {
  2012. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  2013. jlCol.title = '本期计量数量';
  2014. SpreadJsObj.reLoadSheetHeader(self.sheet);
  2015. $('#type-title-contract').text('本期合同计量数量');
  2016. $('#type-title-qc').text('本期变更计量数量');
  2017. }
  2018. // 加载生成数据
  2019. self.reBuildImData();
  2020. $('#choose').modal('hide');
  2021. });
  2022. });
  2023. // 显示树结构信息
  2024. $('#choose2').on('shown.bs.modal', function () {
  2025. if (!self.gsSpread) {
  2026. self.gsSpread = SpreadJsObj.createNewSpread($('#im-gather-spread')[0]);
  2027. SpreadJsObj.initSheet(self.gsSpread.getActiveSheet(), {
  2028. cols: [
  2029. {title: '计量\n汇总', colSpan: '1', rowSpan: '1', field: 'check', hAlign: 1, width: 50, formatter: '@', readOnly: true, cellType: 'checkbox'},
  2030. {title: '项目节编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 150, formatter: '@', readOnly: true, cellType: 'tree'},
  2031. {title: '清单编号', colSpan: '1', rowSpan: '1', field: 'b_code', hAlign: 0, width: 80, formatter: '@', readOnly: true},
  2032. {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 230, formatter: '@', readOnly: true},
  2033. {title: '单位', colSpan: '1', rowSpan: '1', field: 'unit', hAlign: 1, width: 60, formatter: '@', readOnly: true},
  2034. ],
  2035. headRows: 1,
  2036. emptyRows: 0,
  2037. headRowHeight: [32],
  2038. defaultRowHeight: 21,
  2039. headerFont: '12px 微软雅黑',
  2040. font: '12px 微软雅黑',
  2041. });
  2042. self.gsSpread.bind(spreadNS.Events.ButtonClicked, function (e, info) {
  2043. function checkParent(node) {
  2044. const parent = self.gsTree.getParent(node);
  2045. if (parent) {
  2046. return parent.check ? parent.check : checkParent(parent);
  2047. } else {
  2048. return false;
  2049. }
  2050. }
  2051. function checkChildren(node) {
  2052. for (const child of node.children) {
  2053. if (child.check) {
  2054. return true;
  2055. } else if (checkChildren(child)) {
  2056. return true;
  2057. }
  2058. }
  2059. return false;
  2060. }
  2061. if (!$('#im-gather-check')[0].checked) { return; }
  2062. const sheet = info.sheet, cellType = sheet.getCellType(info.row, info.col);
  2063. if (cellType instanceof spreadNS.CellTypes.CheckBox) {
  2064. if (sheet.isEditing()) {
  2065. sheet.endEdit(true);
  2066. }
  2067. }
  2068. if (info.sheet.zh_setting) {
  2069. const col = info.sheet.zh_setting.cols[info.col];
  2070. if (col.field !== 'check') {
  2071. return;
  2072. }
  2073. const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
  2074. const node = sortData[info.row];
  2075. if (!node.check) {
  2076. if (checkParent(node)) {
  2077. const rect = info.sheet.getCellRect(info.row, info.col);
  2078. gatherConfirmPopover.check({
  2079. x: rect.x + rect.width / 2 + 25,
  2080. y: rect.y + rect.height / 2 + 3,
  2081. }, '父项已勾选,继续将取消父项勾选。', function () {
  2082. node.check = true;
  2083. const parents = self.gsTree.getFullPathNodes(self.gsTree.getParent(node).full_path);
  2084. const rows = [self.gsTree.nodes.indexOf(node)];
  2085. for (const p of parents) {
  2086. if (p.check) {
  2087. p.check = false;
  2088. rows.push(self.gsTree.nodes.indexOf(p));
  2089. }
  2090. }
  2091. SpreadJsObj.reLoadRowsData(info.sheet, rows);
  2092. });
  2093. } else if (checkChildren(node)) {
  2094. const rect = info.sheet.getCellRect(info.row, info.col);
  2095. gatherConfirmPopover.check({
  2096. x: rect.x + rect.width / 2 + 25,
  2097. y: rect.y + rect.height / 2 + 3,
  2098. }, '子项已勾选,继续将取消子项勾选。', function () {
  2099. node.check = true;
  2100. const posterity = self.gsTree.getPosterity(node);
  2101. const rows = [self.gsTree.nodes.indexOf(node)];
  2102. for (const p of posterity) {
  2103. if (p.check) {
  2104. rows.push(self.gsTree.nodes.indexOf(p));
  2105. p.check = false;
  2106. }
  2107. }
  2108. SpreadJsObj.reLoadRowsData(info.sheet, rows);
  2109. });
  2110. } else {
  2111. node.check = true;
  2112. SpreadJsObj.reLoadRowsData(info.sheet, [self.gsTree.nodes.indexOf(node)]);
  2113. }
  2114. } else {
  2115. node.check = false;
  2116. SpreadJsObj.reLoadRowsData(info.sheet, [self.gsTree.nodes.indexOf(node)]);
  2117. }
  2118. }
  2119. });
  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.loadSheetData(self.gsSpread.getActiveSheet(), SpreadJsObj.DataType.Tree, self.gsTree);
  2125. self.gsTree.expandByLevel(4);
  2126. SpreadJsObj.refreshTreeRowVisible(self.gsSpread.getActiveSheet());
  2127. SpreadJsObj.resetFieldReadOnly(self.gsSpread.getActiveSheet, 'check', !$('#im-gather-check')[0].checked);
  2128. } else {
  2129. const gatherNodes = stage.im_gather_node ? _.map(stage.im_gather_node.split(',')) : [];
  2130. for (const node of self.gsTree.datas) {
  2131. node.check = gatherNodes.indexOf(node.id + '') !== -1;
  2132. }
  2133. SpreadJsObj.reLoadColsData(self.gsSpread.getActiveSheet(), [0]);
  2134. }
  2135. });
  2136. // 提交 高级设置
  2137. $('#choose2-ok').click(() => {
  2138. if (!self.gsTree) { return; }
  2139. const nodes = [];
  2140. for (const node of self.gsTree.datas) {
  2141. if (node.check) {
  2142. nodes.push(node.id);
  2143. }
  2144. }
  2145. const data = {
  2146. im_gather: $('#im-gather-check')[0].checked,
  2147. im_gather_node: nodes.join(','),
  2148. };
  2149. postData(window.location.pathname + '/detail/adv', data, function (result) {
  2150. stage.im_gather = data.im_gather;
  2151. stage.im_gather_node = data.im_gather_node;
  2152. $('#choose2').modal('hide');
  2153. });
  2154. });
  2155. }
  2156. _initModifyDetail() {
  2157. const self = this;
  2158. // 编辑
  2159. $('#edit-detail').click(function () {
  2160. $(this).hide();
  2161. $('#save-detail').show();
  2162. $('#cancel-detail').show();
  2163. $('#detail-show').hide();
  2164. $('#detail-edit').show();
  2165. });
  2166. // 保存
  2167. $('#save-detail').click(() => {
  2168. function check(field, obj, org, update) {
  2169. const newValue = obj.val();
  2170. if (!org[field]) {
  2171. if (newValue !== '') {
  2172. update[field] = newValue;
  2173. }
  2174. } else if (newValue !== org[field]){
  2175. update[field] = newValue;
  2176. }
  2177. }
  2178. const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  2179. const updateData = {lid: data.lid, pid: data.pid};
  2180. if (data.uuid) {
  2181. updateData.uuid = data.uuid;
  2182. } else {
  2183. updateData.code = data.code;
  2184. updateData.name = data.name;
  2185. updateData.unit = data.unit;
  2186. updateData.unit_price = data.unit_price;
  2187. }
  2188. updateData.bw = $('#bw-name').val();
  2189. updateData.peg = $('#peg').val();
  2190. updateData.xm = $('#xm-name').val();
  2191. updateData.position = $('#position').val();
  2192. updateData.drawing_code = $('#drawing-code').val();
  2193. updateData.calc_memo = $('#calc-memo').val();
  2194. postData(window.location.pathname + '/detail/save', updateData, function (result) {
  2195. stageIm.loadUpdateDetailData(result);
  2196. self.reLoadDetailData();
  2197. });
  2198. });
  2199. // 取消
  2200. $('#cancel-detail').click(() => {
  2201. self.reLoadDetailData();
  2202. });
  2203. }
  2204. _initImageRela() {
  2205. const self = this;
  2206. function setdraggrable(){
  2207. $( ".img-item" ).draggable({ containment: "parent" },{stop: function( event, ui ) {
  2208. }}).resizable({ containment: "parent" },{ handles: 'n, e, s, w, ne, se, sw, nw' },{ maxWidth: parseFloat($('#imgwidth').val())},{maxHeight: parseFloat($('#imgheight').val())},{
  2209. stop: function( event, ui ) {
  2210. }
  2211. });
  2212. }
  2213. // 移动图片
  2214. const moveImageItem = function (ev) {
  2215. const item = this;
  2216. const view = $('.img-view')[0];
  2217. let oEvent = ev;
  2218. // 浏览器有一些图片的默认事件,这里要阻止
  2219. oEvent.preventDefault();
  2220. let disX = oEvent.clientX - item.offsetLeft;
  2221. let disY = oEvent.clientY - item.offsetTop;
  2222. view.onmousemove = function (ev) {
  2223. oEvent = ev;
  2224. oEvent.preventDefault();
  2225. let x = oEvent.clientX -disX;
  2226. let y = oEvent.clientY -disY;
  2227. // 图形移动的边界判断
  2228. x = x <= 0 ? 0 : x;
  2229. x = x >= view.offsetWidth - item.offsetWidth ? view.offsetWidth - item.offsetWidth : x;
  2230. y = y <= 0 ? 0 : y;
  2231. y = y >= view.offsetHeight - item.offsetHeight ? view.offsetHeight - item.offsetHeight : y;
  2232. item.style.left = x + 'px';
  2233. item.style.top = y + 'px';
  2234. };
  2235. // 图形移出父盒子取消移动事件,防止移动过快触发鼠标移出事件,导致鼠标弹起事件失效
  2236. view.onmouseleave = function () {
  2237. view.onmousemove = null;
  2238. view.onmouseup = null;
  2239. };
  2240. // 鼠标弹起后停止移动
  2241. view.onmouseup=function() {
  2242. view.onmousemove = null;
  2243. view.onmouseup = null;
  2244. };
  2245. };
  2246. const removeImageItem = function () {
  2247. $(this).parent().remove();
  2248. };
  2249. // 加载草图组成
  2250. $('#edit-img').on('show.bs.modal', function () {
  2251. const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  2252. const items = data.calc_img_org ? JSON.parse(data.calc_img_org) : [];
  2253. const html = [];
  2254. for (const item of items) {
  2255. const itemStyle = 'top:' + item.top + ';' + 'left:' + item.left + ';' + 'width:' + item.width + ';' + 'height:' + item.height + ';';
  2256. html.push('<div class="img-item" style="' + itemStyle + '">');
  2257. html.push('<div class="img-bar">');
  2258. html.push('<a href="javascript: void(0);" class="text-danger" title="删除"><i class="fa fa-remove" style="font-size: 24px"></i></a>');
  2259. html.push('</div>');
  2260. html.push('<div class="focus" style="width:100%; height:100%"><img src="', item.src, '" id="draggable" style="width:100%; height:100%"></div>');
  2261. html.push('</div>');
  2262. }
  2263. $('.img-view').html(html.join(''));
  2264. $('.img-bar').click(removeImageItem);
  2265. setdraggrable();
  2266. });
  2267. // 上传图片
  2268. $('#upload-img').click(function () {
  2269. $('#upload-img-file').trigger('click');
  2270. });
  2271. $('#upload-img-file').change(function () {
  2272. const file = this.files[0];
  2273. const ext = file.name.toLowerCase().split('.').splice(-1)[0];
  2274. const imgStr = /(jpg|jpeg|png|bmp|BMP|JPG|PNG|JPEG)$/;
  2275. if (!imgStr.test(ext)) {
  2276. toastr.error('请上传正确的图片格式文件');
  2277. return
  2278. }
  2279. if ($(this).val()) {
  2280. const formData = new FormData();
  2281. formData.append('file', this.files[0]);
  2282. postDataWithFile(window.location.pathname + '/detail/add-img', formData, function (result) {
  2283. const html = [];
  2284. html.push('<div class="img-item">');
  2285. html.push('<div class="img-bar">');
  2286. html.push('<a href="javascript: void(0);" class="text-danger" title="删除"><i class="fa fa-remove" style="font-size: 24px"></i></a>');
  2287. html.push('</div>');
  2288. html.push('<div class="focus" style="width:100%; height:100%"><img src="', '/' + result, '" id="draggable" style="width:100%; height:100%"></div>');
  2289. html.push('</div>');
  2290. $('.img-view').append(html.join(''));
  2291. $('.img-bar').click(removeImageItem);
  2292. setdraggrable();
  2293. $('#upload-img-file').val('');
  2294. });
  2295. }
  2296. });
  2297. // 保存草图修改结果
  2298. $('#edit-img-ok').click(function () {
  2299. // 记录上传的图片的信息
  2300. const items = $('.img-item');
  2301. const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  2302. if (items.length > 0) {
  2303. const itemInfo = [];
  2304. for (const item of items) {
  2305. const itemData = {
  2306. src: $('img', item).attr('src'),
  2307. left: item.style.left,
  2308. top: item.style.top,
  2309. width: item.style.width,
  2310. height: item.style.height,
  2311. };
  2312. itemInfo.push(itemData);
  2313. }
  2314. // 获取合并好的图片数据
  2315. const canvas = document.createElement('canvas');
  2316. const view = $('.img-view')[0];
  2317. canvas.height = view.clientHeight;
  2318. canvas.width = view.clientWidth;
  2319. const ctx = canvas.getContext('2d');
  2320. ctx.fillStyle = '#ffffff';
  2321. ctx.fillRect(0, 0, canvas.width, canvas.height);
  2322. for (const b of $('.img-item')) {
  2323. const pos = $(b).position();
  2324. const img = $('img', b)[0];
  2325. ctx.drawImage(img, pos.left, pos.top, img.width, img.height);
  2326. }
  2327. // 生成上传数据
  2328. const updateData = {updateType: 'update', lid: data.lid, pid: data.pid};
  2329. if (data.uuid) {
  2330. updateData.uuid = data.uuid;
  2331. } else {
  2332. updateData.code = data.code;
  2333. updateData.name = data.name;
  2334. updateData.unit = data.unit;
  2335. updateData.unit_price = data.unit_price;
  2336. }
  2337. updateData.img = canvas.toDataURL('image/png');
  2338. updateData.imgInfo = itemInfo;
  2339. postData(window.location.pathname + '/detail/merge-img', updateData, function (result) {
  2340. data.calc_img = result.calc_img;
  2341. data.calc_img_org = result.calc_img_org;
  2342. const calcImgSrc = data && data.calc_img ? '/' + data.calc_img : '';
  2343. $('#show-calc-img').attr('src', calcImgSrc);
  2344. $('#calc-img').attr('src', calcImgSrc);
  2345. $('#view-calc-img').attr('src', calcImgSrc);
  2346. $('#edit-img').modal('hide');
  2347. });
  2348. } else if (data.calc_img) {
  2349. postData(window.location.pathname + '/detail/merge-img', {updateType: 'clear', lid: data.lid, pid: data.pid, uuid: data.uuid}, function (result) {
  2350. data.calc_img = result.calc_img;
  2351. data.calc_img_org = result.calc_img_org;
  2352. const calcImgSrc = data && data.calc_img ? '/' + data.calc_img : '';
  2353. $('#show-calc-img').attr('src', calcImgSrc);
  2354. $('#calc-img').attr('src', calcImgSrc);
  2355. $('#view-calc-img').attr('src', calcImgSrc);
  2356. $('#edit-img').modal('hide');
  2357. });
  2358. }
  2359. });
  2360. }
  2361. reBuildImData() {
  2362. const imData = stageIm.buildImData();
  2363. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  2364. this.reLoadDetailData();
  2365. }
  2366. loadStageLedgerUpdateData(data) {
  2367. const imData = stageIm.loadUpdateLedgerData(data);
  2368. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  2369. this.reLoadDetailData();
  2370. }
  2371. loadStagePosUpdateData(data) {
  2372. const imData = stageIm.loadUpdatePosData(data);
  2373. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  2374. this.reLoadDetailData();
  2375. }
  2376. loadStageChangeUpdateData(data) {
  2377. const imData = stageIm.loadUpdateChangeData(data);
  2378. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  2379. this.reLoadDetailData();
  2380. }
  2381. reLoadDetailData() {
  2382. const data = SpreadJsObj.getSelectObject(this.spread.getActiveSheet());
  2383. if (data) {
  2384. $('#edit-detail').show();
  2385. $('#modify-img').show();
  2386. } else {
  2387. $('#edit-detail').hide();
  2388. $('#modify-img').hide();
  2389. }
  2390. $('#save-detail').hide();
  2391. $('#cancel-detail').hide();
  2392. $('#detail-show').show();
  2393. $('#detail-edit').hide();
  2394. const contractJl = data && data.contract_jl ? data.contract_jl : '';
  2395. $('#show-contract-jl').text(contractJl);
  2396. $('#contract-jl').val(contractJl);
  2397. const qcJl = data && data.qc_jl ? data.qc_jl : '';
  2398. $('#show-qc-jl').text(qcJl);
  2399. $('#qc-jl').val(qcJl);
  2400. const bglCode = data && data.bgl_code ? data.bgl_code : '';
  2401. $('#show-bgl-code').text(bglCode);
  2402. $('#bgl-code').val(bglCode);
  2403. const bglDrawingCode = data && data.bgl_drawing_code ? data.bgl_drawing_code : '';
  2404. $('#show-bgl-drawing-code').text(bglDrawingCode);
  2405. $('#bgl-drawing-code').val(bglDrawingCode);
  2406. const bwName = data && data.bw ? data.bw : '';
  2407. $('#show-bw-name').text(bwName);
  2408. $('#bw-name').val(bwName);
  2409. const position = data && data.position ? data.position : '';
  2410. $('#show-position').text(position);
  2411. $('#position').val(position);
  2412. const peg = data && data.peg ? data.peg : '';
  2413. $('#show-peg').text(peg);
  2414. $('#peg').val(peg);
  2415. const xmName = data && data.xm ? data.xm: '';
  2416. $('#show-xm-name').text(xmName);
  2417. $('#xm-name').val(xmName);
  2418. const drawingCode = data && data.drawing_code ? data.drawing_code: '';
  2419. $('#show-drawing-code').text(drawingCode);
  2420. $('#drawing-code').val(drawingCode);
  2421. const calcMemo = data && data.calc_memo ? data.calc_memo: '';
  2422. $('#show-calc-memo').html(calcMemo.replace(/\n/g, '<br/>'));
  2423. $('#calc-memo').val(calcMemo);
  2424. const calcImgSrc = data && data.calc_img ? '/' + data.calc_img : '';
  2425. $('#show-calc-img').attr('src', calcImgSrc);
  2426. $('#calc-img').attr('src', calcImgSrc);
  2427. $('#view-calc-img').attr('src', calcImgSrc);
  2428. }
  2429. }
  2430. // 展开收起附件
  2431. $('a', '.right-nav').bind('click', function () {
  2432. //const main = $('#main-view'), tool = $('#tools-view');
  2433. const tab = $(this), tabPanel = $(tab.attr('content'));
  2434. const showTools = function (show) {
  2435. const left = $('#main-view'), right = $('#tools-view'), parent = left.parent();
  2436. if (show) {
  2437. right.show();
  2438. autoFlashHeight();
  2439. /**
  2440. * right.show()后, parent被撑开成2倍left.height, 导致parent.width减少了10px
  2441. * 第一次left.width调整后,parent的缩回left.height, 此时parent.width又增加了10px
  2442. * 故需要通过最终的parent.width再计算一次left.width
  2443. *
  2444. * Q: 为什么不通过先计算left.width的宽度,以避免计算两次left.width?
  2445. * A: 右侧工具栏不一定显示,当右侧工具栏显示过一次后,就必须使用parent和right来计算left.width
  2446. *
  2447. */
  2448. //left.css('width', parent.width() - right.outerWidth());
  2449. //left.css('width', parent.width() - right.outerWidth());
  2450. const percent = 100 - right.outerWidth() /parent.width() * 100;
  2451. left.css('width', percent + '%');
  2452. } else {
  2453. right.hide();
  2454. left.css('width', '100%');
  2455. }
  2456. };
  2457. if (!tab.hasClass('active')) {
  2458. $('a', '.side-menu').removeClass('active');
  2459. $('.tab-content .tab-select-show').removeClass('active');
  2460. tab.addClass('active');
  2461. tabPanel.addClass('active');
  2462. showTools(tab.hasClass('active'));
  2463. if (tab.attr('content') === '#search' && !searchLedger) {
  2464. searchLedger = new SearchLedger($('#search'), slSpread);
  2465. searchLedger.spread.refresh();
  2466. }
  2467. if (tab.attr('content') === '#fujian') {
  2468. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2469. getNodeList(node.id);
  2470. }
  2471. if (tab.attr('content') === '#zhongjian') {
  2472. if (!detail) {
  2473. detail = new Detail($('#detail-spread'));
  2474. detail.spread.refresh();
  2475. }
  2476. }
  2477. } else {
  2478. tab.removeClass('active');
  2479. tabPanel.removeClass('active');
  2480. showTools(tab.hasClass('active'));
  2481. }
  2482. slSpread.refresh();
  2483. spSpread.refresh();
  2484. });
  2485. // 切换附件里节点和所有附件
  2486. $('#fujian .nav-link').on('click', function () {
  2487. const tabPanel = $(this).attr('fujian-content');
  2488. if (tabPanel !== 'syfujian') {
  2489. $('#showPage').hide();
  2490. } else {
  2491. $('#showPage').show();
  2492. }
  2493. $('#showAttachment').hide();
  2494. });
  2495. // 上传附件
  2496. $('#upload-file-btn').click(function () {
  2497. const files = $('#upload-file')[0].files;
  2498. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2499. const formData = new FormData();
  2500. formData.append('lid', node.id);
  2501. for (const file of files) {
  2502. if (file === undefined) {
  2503. toastr.error('未选择上传文件!');
  2504. return false;
  2505. }
  2506. const filesize = file.size;
  2507. if (filesize > 10 * 1024 * 1024) {
  2508. toastr.error('存在上传文件大小过大!');
  2509. return false;
  2510. }
  2511. const fileext = '.' + file.name.toLowerCase().split('.').splice(-1)[0];
  2512. if (whiteList.indexOf(fileext) === -1) {
  2513. toastr.error('只能上传指定格式的附件!');
  2514. return false;
  2515. }
  2516. formData.append('size', filesize);
  2517. formData.append('file[]', file);
  2518. }
  2519. postDataWithFile('/tender/' + tender.id + '/measure/stage/' + stage.order + '/upload/file', formData, function (data) {
  2520. $('#upload').modal('hide');
  2521. // 插入到attData中
  2522. attData = data.concat(attData);
  2523. // 重新生成List
  2524. getAllList();
  2525. getNodeList(node.id);
  2526. }, function () {
  2527. toastr.error('附件上传失败');
  2528. });
  2529. $('#upload-file').val('');
  2530. });
  2531. // 获取附件信息
  2532. $('body').on('click', '.list-table a', function () {
  2533. const fid = $(this).attr('file-id');
  2534. if ($('#showAttachment').attr('file-id') === fid && !$('#showAttachment').is(":hidden")) {
  2535. return;
  2536. }
  2537. const att = attData.find(function (item) {
  2538. return item.id === parseInt(fid);
  2539. });
  2540. $('#edit-att').hide();
  2541. $('#show-att').show();
  2542. if (att !== undefined) {
  2543. $('#show-att tr').eq(0).children('td').text(att.filename + att.fileext);
  2544. const name = att.code !== null && att.code !== '' ? att.code : (att.b_code !== null ? att.b_code : '');
  2545. $('#show-att tr').eq(1).children('td').text($.trim(name + ' ' + att.lname));
  2546. $('#show-att tr').eq(2).find('a').attr('href', '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + att.id);
  2547. $('#show-att tr').eq(3).children('td').eq(0).text(att.username);
  2548. $('#show-att tr').eq(3).children('td').eq(1).text(att.in_time);
  2549. $('#show-att tr').eq(4).children('td').text(att.remark);
  2550. if (parseInt(userID) === att.uid) {
  2551. $('#btn-att').show();
  2552. $('#btn-att a').eq(1).show();
  2553. $('#btn-att a').eq(0).hide();
  2554. $('#btn-att a').eq(2).hide();
  2555. $('#btn-att a').eq(3).hide();
  2556. } else {
  2557. $('#btn-att').hide();
  2558. $('#btn-att a').eq(1).hide();
  2559. $('#btn-att a').eq(0).hide();
  2560. $('#btn-att a').eq(2).hide();
  2561. $('#btn-att a').eq(3).hide();
  2562. }
  2563. $('#showAttachment').attr('file-id', fid);
  2564. $('#showAttachment').show();
  2565. } else {
  2566. $('#showAttachment').hide();
  2567. $('#showAttachment').attr('file-id', '');
  2568. toastr.error('附件信息获取失败');
  2569. }
  2570. });
  2571. $('body').on('click', '#btn-att a', function () {
  2572. const content = $(this).attr('content');
  2573. const fid = $('#showAttachment').attr('file-id');
  2574. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2575. if (content === 'edit') {
  2576. $('#btn-att a').eq(1).hide();
  2577. $('#btn-att a').eq(0).show();
  2578. $('#btn-att a').eq(2).show();
  2579. $('#btn-att a').eq(3).show();
  2580. $('#show-att').hide();
  2581. $('#edit-att').show();
  2582. const att = attData.find(function (item) {
  2583. return item.id === parseInt(fid);
  2584. });
  2585. $('#edit-att .form-group').eq(0).find('input').val(att.filename);
  2586. $('#edit-att .form-group').eq(0).find('span').eq(1).text(att.fileext);
  2587. const name = att.code !== null && att.code !== '' ? att.code : (att.b_code !== null ? att.b_code : '');
  2588. $('#edit-att .form-group').eq(1).find('input').val($.trim(name + ' ' + att.lname));
  2589. $('#edit-att .form-group').eq(2).find('input').val(att.in_time);
  2590. $('#edit-att .form-group').eq(3).find('input').val(att.remark);
  2591. } else if (content === 'cancel') {
  2592. $('#show-att').show();
  2593. $('#edit-att').hide();
  2594. $('#btn-att a').eq(1).show();
  2595. $('#btn-att a').eq(0).hide();
  2596. $('#btn-att a').eq(2).hide();
  2597. $('#btn-att a').eq(3).hide();
  2598. } else if (content === 'save') {
  2599. const formData = new FormData();
  2600. formData.append('id', fid);
  2601. formData.append('filename', $('#edit-att .form-group').eq(0).find('input').val());
  2602. formData.append('fileext', $('#edit-att .form-group').eq(0).find('span').eq(1).text());
  2603. formData.append('remark', $('#edit-att .form-group').eq(3).find('input').val());
  2604. const file = $('#change-att-btn')[0];
  2605. if (file.files[0] !== undefined) {
  2606. const filesize = file.files[0].size;
  2607. formData.append('size', filesize);
  2608. formData.append('file', file.files[0]);
  2609. }
  2610. postDataWithFile('/tender/' + tender.id + '/measure/stage/' + stage.order + '/save/file', formData, function (data) {
  2611. // 替换到attData中
  2612. const att_index = attData.findIndex(function (item) {
  2613. return item.id === parseInt(fid);
  2614. });
  2615. attData.splice(att_index, 1, data);
  2616. // 重新生成List
  2617. getAllList(parseInt($('#currentPage').text()));
  2618. getNodeList(node.id);
  2619. $('#show-att').show();
  2620. $('#edit-att').hide();
  2621. $('#show-att tr').eq(0).children('td').text(data.filename + data.fileext);
  2622. const name = data.code !== null && data.code !== '' ? data.code : (data.b_code !== null ? data.b_code : '');
  2623. $('#show-att tr').eq(1).children('td').text($.trim(name + ' ' + data.lname));
  2624. $('#show-att tr').eq(2).find('a').attr('href', '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + data.id);
  2625. $('#show-att tr').eq(3).children('td').eq(0).text(data.username);
  2626. $('#show-att tr').eq(3).children('td').eq(1).text(data.in_time);
  2627. $('#show-att tr').eq(4).children('td').text(data.remark);
  2628. $('#btn-att a').eq(1).show();
  2629. $('#btn-att a').eq(0).hide();
  2630. $('#btn-att a').eq(2).hide();
  2631. $('#btn-att a').eq(3).hide();
  2632. }, function () {
  2633. toastr.error('附件上传失败');
  2634. });
  2635. $('#change-att-btn').val('');
  2636. } else if (content === 'del') {
  2637. const data = {id: fid};
  2638. postData('/tender/' + tender.id + '/measure/stage/' + stage.order + '/delete/file', data, function (result) {
  2639. // 删除到attData中
  2640. const att_index = attData.findIndex(function (item) {
  2641. return item.id === parseInt(fid);
  2642. });
  2643. attData.splice(att_index, 1);
  2644. // 重新生成List
  2645. getAllList();
  2646. getNodeList(node.id);
  2647. $('#showAttachment').hide();
  2648. $('#showAttachment').attr('file-id', '');
  2649. });
  2650. }
  2651. });
  2652. // 替换附件
  2653. $('#change-att-btn').on('change', function () {
  2654. const file = $('#change-att-btn')[0].files[0];
  2655. const name = file.name;
  2656. const filename = name.substring(0, name.lastIndexOf("."));
  2657. const fileext = name.substr(name.indexOf("."));
  2658. const filesize = file.size;
  2659. if (filesize > 10 * 1024 * 1024) {
  2660. toastr.error('文件大小过大!');
  2661. $('#change-att-btn').val('');
  2662. return false;
  2663. }
  2664. if (whiteList.indexOf(fileext) === -1) {
  2665. toastr.error('只能上传指定格式的附件!');
  2666. $('#change-att-btn').val('');
  2667. return false;
  2668. }
  2669. $('#edit-att .form-group').eq(0).find('input').val(filename);
  2670. $('#edit-att .form-group').eq(0).find('span').eq(1).text(fileext);
  2671. });
  2672. // 切换页数
  2673. $('.page-select').on('click', function () {
  2674. const totalPageNum = $('#totalPage').text();
  2675. const lastPageNum = $('#currentPage').text();
  2676. const status = $(this).attr('content');
  2677. if (status === 'pre' && lastPageNum > 1) {
  2678. getAllList(parseInt(lastPageNum)-1);
  2679. $('#showAttachment').hide();
  2680. } else if (status === 'next' && lastPageNum < totalPageNum) {
  2681. getAllList(parseInt(lastPageNum)+1);
  2682. $('#showAttachment').hide();
  2683. }
  2684. });
  2685. // 显示层次
  2686. (function (select, sheet) {
  2687. $(select).click(function () {
  2688. if (!sheet.zh_tree) return;
  2689. const tag = $(this).attr('tag');
  2690. const tree = sheet.zh_tree;
  2691. switch (tag) {
  2692. case "1":
  2693. case "2":
  2694. case "3":
  2695. case "4":
  2696. case "5":
  2697. tree.expandByLevel(parseInt(tag));
  2698. SpreadJsObj.refreshTreeRowVisible(sheet);
  2699. break;
  2700. case "last":
  2701. tree.expandByCustom(() => { return true; });
  2702. SpreadJsObj.refreshTreeRowVisible(sheet);
  2703. break;
  2704. case "leafXmj":
  2705. tree.expandToLeafXmj();
  2706. SpreadJsObj.refreshTreeRowVisible(sheet);
  2707. break;
  2708. case "curMeasure":
  2709. tree.expandByCustom(function (node) {
  2710. for (const field of ['contract_tp', 'qc_tp', 'gather_tp']) {
  2711. if (node[field]) {
  2712. return true;
  2713. }
  2714. }
  2715. return false;
  2716. });
  2717. SpreadJsObj.refreshTreeRowVisible(sheet);
  2718. break;
  2719. }
  2720. });
  2721. })('a[name=showLevel]', slSpread.getActiveSheet());
  2722. });