material.js 104 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091
  1. 'use strict';
  2. /**
  3. * 材料调差 - 调差工料
  4. *
  5. * @author Mai
  6. * @date 2019/1/16
  7. * @version
  8. */
  9. function loadUpdateMaterials(newMaterial, fields) {
  10. const newMaterials = newMaterial instanceof Array ? newMaterial : [newMaterial];
  11. for (const nm of newMaterials) {
  12. const om = _.find(materialBillsData, {id: nm.id});
  13. for (const prop in nm) {
  14. if (!fields || fields.indexOf(prop) >= 0) {
  15. om[prop] = nm[prop];
  16. }
  17. }
  18. }
  19. }
  20. function DatePickerCellType() {
  21. }
  22. DatePickerCellType.prototype = new GC.Spread.Sheets.CellTypes.Base();
  23. DatePickerCellType.prototype.createEditorElement = function () {
  24. //Create input presenter.
  25. var input = document.createElement("input");
  26. return input;
  27. };
  28. DatePickerCellType.prototype.activateEditor = function (editorContext, cellStyle, cellRect) {
  29. //Initialize input editor.
  30. if (editorContext) {
  31. const $editor = $(editorContext);
  32. GC.Spread.Sheets.CellTypes.Base.prototype.activateEditor.apply(this, arguments);
  33. $editor.datepicker({});
  34. $editor.css("position", "absolute");
  35. $editor.attr("gcUIElement", "gcEditingInput");
  36. $(".ui-datepicker").attr("gcUIElement", "gcEditingInput");
  37. }
  38. }
  39. DatePickerCellType.prototype.deactivateEditor = function (editorContext) {
  40. //Remove input editor when end editor status.
  41. if (editorContext) {
  42. var element = editorContext;
  43. // $(element).datepicker().data('datepicker').hide();
  44. // $(element).datepicker().data('datepicker').destroy();
  45. $(element).datepicker("hide");
  46. $(element).datepicker("destroy");
  47. }
  48. GC.Spread.Sheets.CellTypes.Base.prototype.deactivateEditor.apply(this, arguments)
  49. };
  50. DatePickerCellType.prototype.setEditorValue = function (editor, value) {
  51. //Sync value from Cell value to editor value.
  52. // console.log($(editor), value);
  53. $(editor).datepicker("setDate", value);
  54. // $(editor).datepicker().data('datepicker').selectDate(value ? new Date(value) : new Date());
  55. };
  56. DatePickerCellType.prototype.getEditorValue = function (editor, context) {
  57. // console.log($(editor).datepicker().data('datepicker'), context);
  58. //Sync value from editor value to cell value.
  59. // console.log($(editor).datepicker("getDate"));
  60. // return $(editor).datepicker("getDate");
  61. return $(editor).val();
  62. };
  63. DatePickerCellType.prototype.updateEditor = function (editorContext, cellStyle, cellRect) {
  64. if (editorContext) {
  65. const $editor = $(editorContext);
  66. $editor.css("width", cellRect.width - 1);
  67. $editor.css("height", cellRect.height - 3);
  68. }
  69. };
  70. function resetTpTable() {
  71. $('#tp_set').find('td').eq(1).text(ZhCalc.round(m_tp, materialDecimal.tp));
  72. $('#tp_set').find('td').eq(2).text(ZhCalc.add(pre_tp, ZhCalc.round(m_tp, materialDecimal.tp)));
  73. if (materialTax) {
  74. $('#tax_rate_set').find('td').eq(1).text(ZhCalc.round(m_tax_tp, materialDecimal.tp));
  75. $('#tax_rate_set').find('td').eq(2).text(ZhCalc.add(m_tax_pre_tp, ZhCalc.round(m_tax_tp, materialDecimal.tp)));
  76. } else {
  77. const rate = $('#rateInput').val();
  78. const bqhs = ZhCalc.round(ZhCalc.mul(m_tp, 1+rate/100), materialDecimal.tp);
  79. const jzbqhs = ZhCalc.add(pre_tp_hs, bqhs);
  80. $('#rate_set').find('td').eq(1).text(bqhs !== 0 ? bqhs : '');
  81. $('#rate_set').find('td').eq(2).text(jzbqhs !== 0 ? jzbqhs : '');
  82. }
  83. if (isStageSelf) {
  84. let html = '';
  85. for (const ms of materialStageData) {
  86. const taxHtml = materialTax ? ' <td class="text-center">' + (ms.m_tax_tp !== null ? ms.m_tax_tp : '') + '</td>\n' : '';
  87. html += '<tr><td>第' + ms.order + '期</td><td class="text-center">' + (ms.m_tp !== null ? ms.m_tp : '') + '</td>\n' +
  88. taxHtml +
  89. ' </tr>';
  90. }
  91. const allTaxHtml = materialTax ? ' <td class="text-center">' + m_tax_tp + '</td>\n' : '';
  92. html += '<tr><td>合计</td><td class="text-center">' + m_tp + '</td>\n' +
  93. allTaxHtml +
  94. ' </tr>';
  95. $('#materialStageTable').html(html);
  96. }
  97. }
  98. function getPasteHint (str, row = '') {
  99. let returnObj = str;
  100. if (row) {
  101. returnObj.msg = '工料第' + (row+1) + '行' + str.msg;
  102. }
  103. return returnObj;
  104. }
  105. const is_numeric = (value) => {
  106. if (typeof(value) === 'object') {
  107. return false;
  108. } else {
  109. return !Number.isNaN(Number(value)) && value.toString().trim() !== '';
  110. }
  111. };
  112. $(document).ready(() => {
  113. autoFlashHeight();
  114. const materialSpread = SpreadJsObj.createNewSpread($('#material-spread')[0]);
  115. const materialSpreadSetting = {
  116. emptyRows: 0,
  117. headRows: 2,
  118. headRowHeight: [25, 32],
  119. defaultRowHeight: 21,
  120. headerFont: '12px 微软雅黑',
  121. font: '12px 微软雅黑',
  122. readOnly: readOnly,
  123. };
  124. let materialSpreadSettingCols = [
  125. {title: '调差类型', colSpan: '1', rowSpan: '2', field: 't_type', hAlign: 1, width: 60, formatter: '@', readOnly: 'readOnly.isUsed', cellType: 'customizeCombo', comboItems: materialType.t_type, cellTypeKey: 1},
  126. {title: '编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 60, formatter: '@', readOnly: 'readOnly.isUsed'},
  127. {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: 'readOnly.isEdit'},
  128. {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: 'readOnly.isEdit'},
  129. {title: '规格', colSpan: '1', rowSpan: '2', field: 'spec', hAlign: 0, width: 150, formatter: '@', readOnly: 'readOnly.isEdit'},
  130. {title: '工料分类', colSpan: '1', rowSpan: '2', field: 'm_type', hAlign: 1, width: 60, readOnly: 'readOnly.isEdit', cellType: 'customizeCombo', comboItems: materialType.m_type, cellTypeKey: 2},
  131. ];
  132. if (materialTax) {
  133. materialSpreadSettingCols.push({title: '税率(%)', colSpan: '1', rowSpan: '2', field: 'm_tax', hAlign: 2, width: 50, type: 'Number', readOnly: editTaxPermission ? 'readOnly.remark' : 'readOnly.isEdit'});
  134. }
  135. materialSpreadSettingCols = _.concat(materialSpreadSettingCols, [
  136. {title: '上涨 幅度(%)', colSpan: '1', rowSpan: '2', field: 'm_up_risk', hAlign: 2, width: 50, type: 'Number', readOnly: 'readOnly.isEdit'},
  137. {title: '下跌 幅度(%)', colSpan: '1', rowSpan: '2', field: 'm_down_risk', hAlign: 2, width: 50, type: 'Number', readOnly: 'readOnly.isEdit'},
  138. {title: '基准价', colSpan: '1', rowSpan: '2', field: 'basic_price', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.isEdit'},
  139. {title: '基准时间', colSpan: '1', rowSpan: '2', field: 'basic_times', hAlign: 0, width: 70, formatter: '@', readOnly: 'readOnly.isEdit'},
  140. {title: '本期信息价|单价', colSpan: '3|1', rowSpan: '1|1', field: 'msg_tp', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.msg_tp'},
  141. {title: '|时间', colSpan: '|1', rowSpan: '|1', field: 'msg_times', hAlign: 0, width: 80, formatter: '@', readOnly: 'readOnly.remark'},
  142. {title: '|单价差', colSpan: '|1', rowSpan: '|1', field: 'msg_spread', hAlign: 2, width: 60, type: 'Number', readOnly: true, getValue: 'getValue.msg_spread'},]
  143. );
  144. if (materialTax) {
  145. materialSpreadSettingCols = _.concat(materialSpreadSettingCols, [
  146. {title: '本期材料调差|有效价差', colSpan: '4|1', rowSpan: '1|1', field: 'm_spread', hAlign: 2, width: 60, type: 'Number', readOnly: true, getValue: 'getValue.m_spread'},
  147. {title: '|本期应耗数量', colSpan: '|1', rowSpan: '|1', field: 'quantity', hAlign: 2, width: 90, type: 'Number', readOnly: true},
  148. {title: '|调差金额', colSpan: '|1', rowSpan: '|1', field: 'm_tp', hAlign: 2, width: 100, type: 'Number', readOnly: true, getValue: 'getValue.m_tp'},
  149. {title: '|调差金额(材料税)', colSpan: '|1', rowSpan: '|1', field: 'm_tax_tp', hAlign: 2, width: 100, type: 'Number', readOnly: true, getValue: 'getValue.m_tax_tp'},
  150. {title: '截止上期|调差金额', colSpan: '2|1', rowSpan: '1|1', field: 'pre_tp', hAlign: 2, width: 100, type: 'Number', readOnly: true},
  151. {title: '|调差金额(材料税)', colSpan: '|1', rowSpan: '|1', field: 'tax_pre_tp', hAlign: 2, width: 100, type: 'Number', readOnly: true},
  152. {title: '备注', colSpan: '1', rowSpan: '2', field: 'remark', hAlign: 0, width: 50, formatter: '@', cellType: 'ellipsisAutoTip', readOnly: 'readOnly.remark'},
  153. {title: '是否汇总', colSpan: '1', rowSpan: '2', field: 'is_summary', hAlign: 1, width: 60, cellType: 'checkbox', readOnly: 'readOnly.isEdit'}
  154. ])
  155. } else {
  156. materialSpreadSettingCols = _.concat(materialSpreadSettingCols, [
  157. {title: '本期材料调差|有效价差', colSpan: '3|1', rowSpan: '1|1', field: 'm_spread', hAlign: 2, width: 60, type: 'Number', readOnly: true, getValue: 'getValue.m_spread'},
  158. {title: '|本期应耗数量', colSpan: '|1', rowSpan: '|1', field: 'quantity', hAlign: 2, width: 90, type: 'Number', readOnly: true},
  159. {title: '|调差金额', colSpan: '|1', rowSpan: '|1', field: 'm_tp', hAlign: 2, width: 100, type: 'Number', readOnly: true, getValue: 'getValue.m_tp'},
  160. {title: '截止上期|调差金额', colSpan: '1|1', rowSpan: '1|1', field: 'pre_tp', hAlign: 2, width: 100, type: 'Number', readOnly: true},
  161. {title: '备注', colSpan: '1', rowSpan: '2', field: 'remark', hAlign: 0, width: 50, formatter: '@', cellType: 'ellipsisAutoTip', readOnly: 'readOnly.remark'},
  162. {title: '是否汇总', colSpan: '1', rowSpan: '2', field: 'is_summary', hAlign: 1, width: 60, cellType: 'checkbox', readOnly: 'readOnly.isEdit'}
  163. ])
  164. }
  165. materialSpreadSetting.cols = materialSpreadSettingCols;
  166. const spCol = _.find(materialSpreadSetting.cols, {field: 'quantity'});
  167. spCol.readOnly = true;
  168. spCol.cellType = 'activeImageBtn';
  169. spCol.normalImg = '#ellipsis-icon';
  170. spCol.indent = 5;
  171. spCol.showImage = function (data) {
  172. // return !readOnly && data.t_type === 2 && data.mid === materialID;
  173. return data && data.t_type === 2;
  174. };
  175. materialSpreadSetting.imageClick = function (data) {
  176. if (data.t_type === 2) {
  177. $('#bcyy').modal('show');
  178. $('#materialbillsId').val(data.id);
  179. $('#expr').val(data.expr);
  180. if (!readOnly) {
  181. $('#expr').attr('readOnly', false);
  182. $('#expr_btn').show();
  183. $('#expr_select').show();
  184. } else {
  185. $('#expr').attr('readOnly', true);
  186. $('#expr_btn').hide();
  187. $('#expr_select').hide();
  188. }
  189. }
  190. };
  191. const materialBase = {
  192. isUsed: function (data) {
  193. if (data.t_type === 2) {
  194. return data.mid === materialID;
  195. } else {
  196. const mlInfo = _.find(materialListData, { mb_id: data.id });
  197. return data.mid === materialID && mlInfo === undefined;
  198. }
  199. },
  200. isEdit: function (data) {
  201. // if (data.t_type === 2) {
  202. // return data.mid === materialID;
  203. // } else {
  204. // const mlInfo = _.find(materialListData, { mb_id: data.id });
  205. // return data.mid === materialID && mlInfo === undefined;
  206. // }
  207. return data.mid === materialID;
  208. },
  209. // isStage: function (data) {
  210. // return data.mid === materialID;
  211. // }
  212. }
  213. const materialCol = {
  214. getValue: {
  215. msg_spread: function (data) {
  216. return ZhCalc.round(ZhCalc.sub(data.msg_tp, data.basic_price), materialDecimal.up);
  217. },
  218. m_spread : function (data) {
  219. const msg_spread = materialCol.getValue.msg_spread(data);
  220. const cor = msg_spread >= 0 ? ZhCalc.mul(data.basic_price, ZhCalc.div(data.m_up_risk, 100)) : ZhCalc.mul(data.basic_price, ZhCalc.div(data.m_down_risk, 100));
  221. return Math.abs(msg_spread) > Math.abs(cor) ? (msg_spread > 0 ? ZhCalc.round(ZhCalc.sub(msg_spread, cor), materialDecimal.up) : ZhCalc.round(ZhCalc.add(msg_spread, cor), materialDecimal.up)) : 0;
  222. },
  223. m_tp: function (data) {
  224. return ZhCalc.round(ZhCalc.mul(materialCol.getValue.m_spread(data), data.quantity), materialDecimal.tp);
  225. },
  226. m_tax_tp: function (data) {
  227. const m_tp = ZhCalc.round(ZhCalc.mul(materialCol.getValue.m_spread(data), data.quantity), materialDecimal.tp);
  228. return data.m_tax ? ZhCalc.round(ZhCalc.mul(m_tp, (1+ZhCalc.div(data.m_tax, 100))), materialDecimal.tp) : m_tp;
  229. }
  230. },
  231. readOnly: {
  232. isEdit: function (data) {
  233. return !(!readOnly && materialBase.isEdit(data));
  234. },
  235. isUsed: function (data) {
  236. return !(!readOnly && materialBase.isUsed(data));
  237. },
  238. remark: function () {
  239. return readOnly;
  240. },
  241. msg_tp: function () {
  242. return !(!readOnly && months.length === 0);
  243. }
  244. },
  245. };
  246. const needUpdateArray = ['quantity', 'expr', 'msg_tp', 'msg_times', 'msg_spread', 'm_spread', 'm_tp', 'm_tax_tp', 'is_summary', 'remark'];
  247. const materialSpreadObj = {
  248. getMaterialBillsData: function () {
  249. if (isStageSelf) {
  250. // 当前选中nav id
  251. const ms_id = $('#myTab').find('.active').data('msid');
  252. const msbList = _.filter(materialStageBillsData, { ms_id });
  253. for (const mb of materialBillsData) {
  254. mb.ms_id = ms_id;
  255. const msbInfo = _.find(msbList, { mb_id: mb.mb_id ? mb.mb_id : mb.id });
  256. if (msbInfo) {
  257. for (const nu of needUpdateArray) {
  258. mb[nu] = msbInfo[nu];
  259. }
  260. }
  261. }
  262. }
  263. return materialBillsData;
  264. },
  265. updateOneMaterialBill: function (data) {
  266. const ms_id = $('#myTab').find('.active').data('msid');
  267. const msbInfo = _.find(materialStageBillsData, { ms_id, mb_id: data.id });
  268. console.log(msbInfo);
  269. data.ms_id = ms_id;
  270. for (const nu of needUpdateArray) {
  271. data[nu] = msbInfo[nu];
  272. }
  273. return data;
  274. },
  275. updateMaterialData: function (datas) {
  276. if (datas.stageData && datas.stageData.length > 0) {
  277. if (datas.stageData.length === materialStageData.length) {
  278. // 全体替换
  279. materialStageData = datas.stageData;
  280. } else {
  281. // 替换对应的stage数据
  282. for (const s of datas.stageData) {
  283. const index = _.findIndex(materialStageData, { id: s.id });
  284. materialStageData.splice(index, 1, s);
  285. }
  286. }
  287. }
  288. if (datas.pushStageBillsData && datas.pushStageBillsData.length > 0) {
  289. materialStageBillsData = _.concat(materialStageBillsData, datas.pushStageBillsData);
  290. }
  291. if (datas.removeStageBillsData && datas.removeStageBillsData.length > 0) {
  292. materialStageBillsData = _.remove(materialStageBillsData, function (item) {
  293. return _.findIndex(datas.removeStageBillsData, { id: item.mb_id }) === -1
  294. })
  295. }
  296. if (datas.stageBillsData && datas.stageBillsData.length > 0) {
  297. if (datas.stageBillsData.length === materialStageBillsData.length) {
  298. // 全体替换
  299. materialStageBillsData = datas.stageBillsData;
  300. } else {
  301. // 替换对应的stage数据
  302. for (const s of datas.stageBillsData) {
  303. const index = _.findIndex(materialStageBillsData, { id: s.id });
  304. materialStageBillsData.splice(index, 1, s);
  305. }
  306. }
  307. }
  308. if (datas.billsData && datas.billsData.length > 0) {
  309. if (datas.billsData.length === materialBillsData.length) {
  310. // 全体替换
  311. materialBillsData = datas.billsData;
  312. materialSpreadObj.getMaterialBillsData();
  313. } else {
  314. for (const b of datas.billsData) {
  315. const index = _.findIndex(materialBillsData, {id: b.id});
  316. materialBillsData.splice(index, 1, b);
  317. materialSpreadObj.updateOneMaterialBill(materialBillsData[index]);
  318. }
  319. }
  320. }
  321. },
  322. materialSheetReset: function (redo = false) {
  323. let newMaterialBillsData = _.cloneDeep(materialBillsData);
  324. if($('#bills0_list').is(':checked')) {
  325. newMaterialBillsData = _.filter(materialBillsData, function (item) {
  326. return item.quantity !== null && item.quantity !== 0;
  327. });
  328. if (redo) {
  329. materialSpread.getActiveSheet().reset();
  330. SpreadJsObj.initSpreadSettingEvents(materialSpreadSetting, materialCol);
  331. SpreadJsObj.initSheet(materialSpread.getActiveSheet(), materialSpreadSetting);
  332. }
  333. }
  334. console.log(newMaterialBillsData);
  335. SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, newMaterialBillsData);
  336. materialSpreadObj.refreshActn();
  337. },
  338. refreshActn: function (rowCount = 1) {
  339. const setObjEnable = function (obj, enable) {
  340. if (enable) {
  341. obj.removeClass('disabled');
  342. } else {
  343. obj.addClass('disabled');
  344. }
  345. };
  346. const sheet = materialSpread.getActiveSheet();
  347. const select = SpreadJsObj.getSelectObject(sheet);
  348. const selection = sheet.getSelections();
  349. const sel = selection ? selection[0] : sheet.getSelections()[0];
  350. const row = sel ? sel.row : -1;
  351. const first = materialBillsData[row];
  352. let last = first;
  353. if (sel.rowCount > 1 && first) {
  354. for (let r = 1; r < sel.rowCount; r++) {
  355. const rNode = materialBillsData[sel.row + r];
  356. if (!rNode) break;
  357. last = rNode;
  358. }
  359. }
  360. const preNode = materialBillsData[row - 1];
  361. // 还需判断是否已被调差清单调用
  362. setObjEnable($('#del'), !readOnly && select && materialBase.isUsed(select) && rowCount === 1);
  363. setObjEnable($('#up-move'), !readOnly && first && preNode && materialBillsData.indexOf(last) > 0 && sel.row + sel.rowCount <= materialBillsData.length && !$('#bills0_list').is(':checked'));
  364. setObjEnable($('#down-move'), !readOnly && first && materialBillsData.indexOf(last) < materialBillsData.length - 1 && sel.row + sel.rowCount <= materialBillsData.length && !$('#bills0_list').is(':checked'));
  365. },
  366. add: function () {
  367. const sheet = materialSpread.getActiveSheet();
  368. postData(window.location.pathname + '/save', {type: 'add'}, function (result) {
  369. if (result) {
  370. materialBillsData.push(result.info);
  371. if (isStageSelf) {
  372. materialSpreadObj.updateMaterialData(result);
  373. materialSpreadObj.getMaterialBillsData();
  374. }
  375. // sheet.addRows(materialBillsData.length - 1, 1);
  376. // SpreadJsObj.reLoadRowData(sheet, materialBillsData.length - 1);
  377. let newMaterialBillsData = materialBillsData;
  378. if($('#bills0_list').is(':checked')) {
  379. newMaterialBillsData = _.filter(materialBillsData, function (item) {
  380. return item.quantity !== null && item.quantity !== 0;
  381. });
  382. }
  383. SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, newMaterialBillsData);
  384. // materialSpreadObj.materialSheetReset();
  385. sheet.setSelection(newMaterialBillsData.length - 1, 0, 1, 1);
  386. console.log(sheet);
  387. materialSpreadObj.refreshActn();
  388. // 月信息价需要同时添加空白的list
  389. if (months.length > 0) {
  390. const one_month ={ mb_id: result.info.id, code: '', name: null, origin: null, unit: null, order: result.info.order };
  391. for (const m of months) {
  392. one_month[m] = null;
  393. }
  394. monthsList.push(one_month);
  395. // const newMonthsList = _.filter(monthsList, function (item) {
  396. // return _.findIndex(newMaterialBillsData, { code: item.code }) !== -1;
  397. // });
  398. // materialMonthSpread.getActiveSheet().addRows(newMonthsList.length - 1, 1);
  399. // SpreadJsObj.reLoadRowData(materialMonthSpread.getActiveSheet(), newMonthsList.length - 1);
  400. monthFunGather.monthsListSet();
  401. // materialMonthSpreadObj.monthsListSet();
  402. }
  403. }
  404. });
  405. },
  406. del: function () {
  407. const sheet = materialSpread.getActiveSheet();
  408. const select = SpreadJsObj.getSelectObject(sheet);
  409. const sel = sheet.getSelections();
  410. postData(window.location.pathname + '/save', {type: 'del', id: select.id}, function (result) {
  411. m_tp = result.m_tp;
  412. if (materialTax) {
  413. m_tax_tp = result.m_tax_tp;
  414. }
  415. const index = _.findIndex(materialBillsData, { id: select.id });
  416. materialBillsData.splice(index, 1);
  417. if (isStageSelf) {
  418. result.removeStageBillsData = [{ id: select.id }];
  419. materialSpreadObj.updateMaterialData(result);
  420. materialSpreadObj.getMaterialBillsData();
  421. }
  422. let newMaterialBillsData = materialBillsData;
  423. let newIndex = index;
  424. if($('#bills0_list').is(':checked')) {
  425. newMaterialBillsData = _.filter(materialBillsData, function (item) {
  426. return item.quantity !== null && item.quantity !== 0;
  427. });
  428. newIndex = _.findIndex(newMaterialBillsData, { id: select.id });
  429. }
  430. // sheet.deleteRows(newIndex, 1);
  431. // sheet.zh_data.splice(newIndex, 1);
  432. materialSpreadObj.materialSheetReset(true);
  433. resetTpTable();
  434. // SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
  435. sheet.setSelection(newIndex > 0 ? newIndex - 1 : 0, sel.length > 0 ? sel[0].col : 0, 1, 1);
  436. materialSpreadObj.refreshActn();
  437. // 月信息价需要同时删除
  438. if (months.length > 0) {
  439. monthsList.splice(index, 1);
  440. materialMonthSpread.getActiveSheet().deleteRows(newIndex, 1);
  441. // SpreadJsObj.reLoadSheetData(materialMonthSpread.getActiveSheet());
  442. }
  443. });
  444. },
  445. upMove: function () {
  446. if($('#bills0_list').is(':checked')) {
  447. return;
  448. }
  449. const data = {
  450. type: 'changeOrder',
  451. postData: [],
  452. };
  453. const sheet = materialSpread.getActiveSheet();
  454. const selection = sheet.getSelections();
  455. const row = selection[0].row, count = selection[0].rowCount;
  456. const first = sheet.zh_data[row];
  457. if (!first) {
  458. materialSpreadObj.refreshActn();
  459. return false;
  460. }
  461. const pre = sheet.zh_data[row - 1], preUpdate = {id: pre.id};
  462. for (let iRow = 0; iRow < count; iRow++) {
  463. const posData = sheet.zh_data[iRow + row];
  464. if (posData) {
  465. data.postData.push({id: posData.id, order: sheet.zh_data[iRow + row - 1].order});
  466. preUpdate.order = posData.order;
  467. }
  468. }
  469. console.log(monthsList);
  470. data.postData.push(preUpdate);
  471. console.log(data);
  472. if (data.postData.length > 0) {
  473. postData(window.location.pathname + '/save', data, function () {
  474. _.forEach(data.postData, function (item) {
  475. const cl = _.find(materialBillsData, { id: item.id });
  476. cl.order = item.order;
  477. });
  478. materialBillsData.sort(function (a, b) {
  479. return a.order - b.order
  480. });
  481. SpreadJsObj.reLoadSheetData(sheet);
  482. const sel = selection[0];
  483. if (sel) {
  484. sheet.setSelection(sheet.zh_data.indexOf(first), sel.col, sel.rowCount, sel.colCount);
  485. }
  486. if (months.length > 0) {
  487. _.forEach(data.postData, function (item) {
  488. const cl = _.find(monthsList, { mb_id: item.id });
  489. cl.order = item.order;
  490. });
  491. monthsList.sort(function (a, b) {
  492. return a.order - b.order
  493. });
  494. const materialMonthSheet = materialMonthSpread.getActiveSheet();
  495. SpreadJsObj.reLoadSheetData(materialMonthSheet);
  496. }
  497. materialSpreadObj.refreshActn();
  498. });
  499. }
  500. },
  501. downMove: function () {
  502. if($('#bills0_list').is(':checked')) {
  503. return;
  504. }
  505. const data = {
  506. type: 'changeOrder',
  507. postData: [],
  508. };
  509. const sheet = materialSpread.getActiveSheet();
  510. const selection = sheet.getSelections();
  511. const row = selection[0].row, count = selection[0].rowCount;
  512. const first = sheet.zh_data[row];
  513. if (!first) {
  514. materialSpreadObj.refreshActn();
  515. return false;
  516. }
  517. const next = sheet.zh_data[row + count], nextUpdate = {id: next.id};
  518. for (let iRow = count - 1; iRow >= 0; iRow--) {
  519. const posData = sheet.zh_data[iRow + row];
  520. if (posData) {
  521. data.postData.push({id: posData.id, order: sheet.zh_data[iRow + row + 1].order});
  522. nextUpdate.order = posData.order;
  523. }
  524. }
  525. data.postData.push(nextUpdate);
  526. console.log(data);
  527. if (data.postData.length > 0) {
  528. postData(window.location.pathname + '/save', data, function () {
  529. _.forEach(data.postData, function (item) {
  530. const cl = _.find(materialBillsData, { id: item.id });
  531. cl.order = item.order;
  532. });
  533. materialBillsData.sort(function (a, b) {
  534. return a.order - b.order
  535. });
  536. SpreadJsObj.reLoadSheetData(sheet);
  537. const sel = selection[0];
  538. if (sel) {
  539. sheet.setSelection(sheet.zh_data.indexOf(first), sel.col, sel.rowCount, sel.colCount);
  540. }
  541. if (months.length > 0) {
  542. _.forEach(data.postData, function (item) {
  543. const cl = _.find(monthsList, { mb_id: item.id });
  544. cl.order = item.order;
  545. });
  546. monthsList.sort(function (a, b) {
  547. return a.order - b.order
  548. });
  549. const materialMonthSheet = materialMonthSpread.getActiveSheet();
  550. SpreadJsObj.reLoadSheetData(materialMonthSheet);
  551. }
  552. materialSpreadObj.refreshActn();
  553. });
  554. }
  555. },
  556. selectionChanged: function (e, info) {
  557. const sel = info.sheet.getSelections()[0];
  558. const col = info.sheet.zh_setting.cols[sel.col];
  559. materialSpreadObj.refreshActn(sel.rowCount);
  560. const data = SpreadJsObj.getSelectObject(info.sheet);
  561. materialSpreadObj.setReadOnly(true);
  562. // console.log(data);
  563. setCurBillSourceList(data.mb_id || data.id, $('#myTab').find('.active').data('msid') || null);
  564. },
  565. editEnded: function (e, info) {
  566. if (info.sheet.zh_setting) {
  567. const select = SpreadJsObj.getSelectObject(info.sheet);
  568. const col = info.sheet.zh_setting.cols[info.col];
  569. if (col.field === 'is_summary') {
  570. return;
  571. }
  572. // 未改变值则不提交
  573. let validText = is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : null);
  574. const orgValue = select[col.field];
  575. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  576. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  577. return;
  578. }
  579. // 判断部分值是否输入的是数字判断和数据计算
  580. if (col.field === 'basic_price') {
  581. if (isNaN(validText)) {
  582. toastr.error('不能输入其它非数字类型字符');
  583. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  584. return;
  585. }
  586. let num = parseFloat(validText);
  587. const reg = materialDecimal.up ? new RegExp("^\\d+(\\.\\d{1,"+ materialDecimal.up +"})?$") : new RegExp("^\\d+?$");
  588. if (validText !== null && (num < 0 || !reg.test(num))) {
  589. toastr.warning('已保留'+ materialDecimal.up +'位小数');
  590. validText = ZhCalc.round(num, materialDecimal.up);
  591. }
  592. }
  593. if (col.field === 'msg_tp') {
  594. if (isNaN(validText)) {
  595. toastr.error('不能输入其它非数字类型字符');
  596. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  597. return;
  598. }
  599. const num = parseFloat(validText);
  600. const reg = materialDecimal.up ? new RegExp("^\\d+(\\.\\d{1,"+ materialDecimal.up +"})?$") : new RegExp("^\\d+?$");
  601. if (validText !== null && (num < 0 || !reg.test(num))) {
  602. toastr.warning('已保留'+ materialDecimal.up +'位小数');
  603. validText = ZhCalc.round(num, materialDecimal.up);
  604. }
  605. }
  606. if (col.field === 'm_up_risk' || col.field === 'm_down_risk' || col.field === 'm_tax') {
  607. // 只能输入正整数
  608. if (isNaN(validText)) {
  609. toastr.error('不能输入其它非数字类型字符');
  610. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  611. return;
  612. }
  613. const num = parseFloat(validText);
  614. if (validText !== null && (num < 0 || num > 100 || !/^\d+$/.test(num))) {
  615. toastr.error('只能输入0-100的正整数');
  616. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  617. return;
  618. }
  619. }
  620. if (col.field === 't_type') {
  621. if (validText === 1) {
  622. select.quantity = null;
  623. select.expr = null;
  624. select.m_tp = null;
  625. }
  626. }
  627. select[col.field] = validText;
  628. select.msg_spread = materialCol.getValue.msg_spread(select);
  629. select.m_spread = materialCol.getValue.m_spread(select);
  630. select.m_tp = materialCol.getValue.m_tp(select);
  631. select.m_tax_tp = materialCol.getValue.m_tax_tp(select);
  632. delete select.waitingLoading;
  633. // console.log(select);
  634. // 更新至服务器
  635. postData(window.location.pathname + '/save', { type:'update', updateData: select, ms_id: $('#myTab').find('.active').data('msid') || null }, function (result) {
  636. m_tp = result.m_tp;
  637. if (materialTax) {
  638. m_tax_tp = result.m_tax_tp;
  639. }
  640. if (isStageSelf) {
  641. materialSpreadObj.updateMaterialData(result);
  642. }
  643. resetTpTable();
  644. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  645. // 判断如果是更改了编号,名称,单位,月信息价需要跟着改变值
  646. if (months.length > 0 && (col.field === 'code' || col.field === 'name' || col.field === 'unit')) {
  647. const index = _.findIndex(materialBillsData, { id: select.id });
  648. monthsList[index][col.field] = validText;
  649. monthFunGather.monthsListSet();
  650. }
  651. }, function () {
  652. select[col.field] = orgValue;
  653. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  654. });
  655. }
  656. },
  657. buttonClicked: function (e, info) {
  658. if (info.sheet.zh_setting) {
  659. const select = SpreadJsObj.getSelectObject(info.sheet);
  660. const col = info.sheet.zh_setting.cols[info.col];
  661. if (materialCol.readOnly.isEdit(select)) {
  662. return;
  663. }
  664. if (col.field === 'is_summary') {
  665. if (info.sheet.isEditing()) {
  666. info.sheet.endEdit(true);
  667. }
  668. select.is_summary = info.sheet.getValue(info.row, info.col) ? 1 : 0;
  669. delete select.waitingLoading;
  670. // 更新至服务器
  671. postData(window.location.pathname + '/save', { type:'update', updateData: select, ms_id: $('#myTab').find('.active').data('msid') || null }, function (result) {
  672. m_tp = result.m_tp;
  673. if (materialTax) {
  674. m_tax_tp = result.m_tax_tp;
  675. }
  676. if (isStageSelf) {
  677. materialSpreadObj.updateMaterialData(result);
  678. }
  679. resetTpTable();
  680. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  681. }, function () {
  682. select.is_summary = info.sheet.getValue(info.row, info.col) ? 0 : 1;
  683. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  684. });
  685. }
  686. }
  687. },
  688. deletePress: function (sheet) {
  689. return;
  690. },
  691. clipboardPasted(e, info) {
  692. const hint = {
  693. cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
  694. codeEmpty: {type: 'error', msg: '请先输入编号,并且不超过15个字符'},
  695. codeUsed: {type: 'error', msg: '该编号已存在,请重新输入。'},
  696. codeError: {type: 'error', msg: '编号为纯数字时,不能为小数'},
  697. numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
  698. riskCan: {type: 'error', msg: '只能粘贴0-100的正整数'},
  699. numberCan: {type: 'warning', msg: '已保留'+ materialDecimal.up +'位小数'},
  700. };
  701. const range = info.cellRange;
  702. const sortData = info.sheet.zh_data || [];
  703. if (info.cellRange.row + info.cellRange.rowCount > sortData.length) {
  704. toastMessageUniq(hint.cellError);
  705. // SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
  706. SpreadJsObj.reLoadSheetHeader(materialSpread.getActiveSheet());
  707. SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
  708. return;
  709. }
  710. if (sortData.length > 0 && range.col + range.colCount > 18) {
  711. toastMessageUniq(hint.cellError);
  712. SpreadJsObj.reLoadSheetHeader(materialSpread.getActiveSheet());
  713. SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
  714. return;
  715. }
  716. const data = [];
  717. // const rowData = [];
  718. for (let iRow = 0; iRow < range.rowCount; iRow++) {
  719. let bPaste = true;
  720. const curRow = range.row + iRow;
  721. // const materialData = JSON.parse(JSON.stringify(sortData[curRow]));
  722. const materialData = { id: sortData[curRow].id };
  723. const hintRow = range.rowCount > 1 ? curRow : '';
  724. let sameCol = 0;
  725. for (let iCol = 0; iCol < range.colCount; iCol++) {
  726. const curCol = range.col + iCol;
  727. const colSetting = info.sheet.zh_setting.cols[curCol];
  728. if (!colSetting) continue;
  729. let validText = info.sheet.getText(curRow, curCol);
  730. validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : null);
  731. const orgValue = sortData[curRow][colSetting.field];
  732. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  733. sameCol++;
  734. if (range.colCount === sameCol) {
  735. bPaste = false;
  736. }
  737. continue;
  738. }
  739. if (colSetting.field === 'code' && (validText === '' || validText.length > 15)) {
  740. toastMessageUniq(getPasteHint(hint.codeEmpty, hintRow));
  741. bPaste = false;
  742. continue;
  743. }
  744. if (colSetting.field === 'code' && validText.toString().indexOf('.') !== -1) {
  745. toastMessageUniq(getPasteHint(hint.codeError, hintRow));
  746. bPaste = false;
  747. continue;
  748. }
  749. if (colSetting.field === 'code' && _.find(sortData, { code: validText.toString() })) {
  750. toastMessageUniq(getPasteHint(hint.codeUsed, hintRow));
  751. bPaste = false;
  752. continue;
  753. }
  754. if (colSetting.field === 't_type' || colSetting.field === 'm_type') {
  755. continue;
  756. }
  757. if (colSetting.field === 'basic_price' || colSetting.field === 'msg_tp'
  758. || colSetting.field === 'm_up_risk' || colSetting.field === 'm_down_risk') {
  759. if (isNaN(validText)) {
  760. toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
  761. bPaste = false;
  762. continue;
  763. }
  764. const num = parseFloat(validText);
  765. if (colSetting.field === 'basic_price' || colSetting.field === 'msg_tp') {
  766. const reg = materialDecimal.up ? new RegExp("^\\d+(\\.\\d{1,"+ materialDecimal.up +"})?$") : new RegExp("^\\d+?$");
  767. if (validText !== null && (num < 0 || !reg.test(num))) {
  768. toastMessageUniq(getPasteHint(hint.numberCan, hintRow));
  769. validText = ZhCalc.round(num, materialDecimal.up);
  770. }
  771. } else if (colSetting.field === 'm_up_risk' || colSetting.field === 'm_down_risk' || colSetting.field === 'm_tax') {
  772. if (validText !== null && (num < 0 || num > 100 || !/^\d+$/.test(num))) {
  773. toastMessageUniq(getPasteHint(hint.riskCan, hintRow));
  774. bPaste = false;
  775. continue;
  776. }
  777. }
  778. }
  779. materialData[colSetting.field] = validText;
  780. sortData[curRow][colSetting.field] = validText;
  781. }
  782. if (materialData.code === '' || materialData.code === null) {
  783. toastMessageUniq(getPasteHint(hint.codeEmpty, hintRow));
  784. bPaste = false;
  785. }
  786. if (bPaste) {
  787. materialData.msg_spread = materialCol.getValue.msg_spread(sortData[curRow]);
  788. materialData.m_spread = materialCol.getValue.m_spread(sortData[curRow]);
  789. materialData.m_tp = materialCol.getValue.m_tp(sortData[curRow]);
  790. materialData.m_tax_tp = materialCol.getValue.m_tax_tp(sortData[curRow]);
  791. data.push(materialData);
  792. // rowData.push(curRow);
  793. } else {
  794. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  795. }
  796. }
  797. if (data.length === 0) {
  798. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  799. return;
  800. }
  801. // console.log(data);
  802. // 更新至服务器
  803. postData(window.location.pathname + '/save', { type:'paste', updateData: data, ms_id: $('#myTab').find('.active').data('msid') || null }, function (result) {
  804. materialBillsData = result.info;
  805. m_tp = result.m_tp;
  806. if (materialTax) {
  807. m_tax_tp = result.m_tax_tp;
  808. }
  809. if (isStageSelf) {
  810. materialSpreadObj.updateMaterialData(result);
  811. materialSpreadObj.getMaterialBillsData();
  812. }
  813. // SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
  814. materialSpreadObj.materialSheetReset();
  815. // SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
  816. // for (const row in rowData) {
  817. // materialBillsData.splice(index, 1, result.info[row]);
  818. // SpreadJsObj.reLoadRowData(info.sheet, row);
  819. // }
  820. if (months.length > 0) {
  821. for (const [i,m] of monthsList.entries()) {
  822. m.code = materialBillsData[i].code;
  823. m.name = materialBillsData[i].name;
  824. m.unit = materialBillsData[i].unit;
  825. m.origin = materialBillsData[i].origin;
  826. }
  827. // SpreadJsObj.loadSheetData(materialMonthSpread.getActiveSheet(), SpreadJsObj.DataType.Data, monthsList);
  828. monthFunGather.monthsListSet();
  829. // SpreadJsObj.reLoadSheetData(materialMonthSpread.getActiveSheet());
  830. }
  831. resetTpTable();
  832. // materialSpreadObj.refreshActn();
  833. }, function () {
  834. // materialSpreadObj.refreshActn();
  835. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  836. return;
  837. });
  838. },
  839. setReadOnly: function(readOnly) {
  840. // SpreadJsObj.resetFieldReadOnly(materialSpread.getActiveSheet(), 'msg_spread', 'm_spread', 'm_tp', 'pre_tp', readOnly);
  841. }
  842. };
  843. materialSpread.bind(spreadNS.Events.SelectionChanged, materialSpreadObj.selectionChanged);
  844. materialSpread.bind(spreadNS.Events.ClipboardPasted, materialSpreadObj.clipboardPasted);
  845. SpreadJsObj.addDeleteBind(materialSpread, materialSpreadObj.deletePress);
  846. materialSpread.bind(spreadNS.Events.EditEnded, materialSpreadObj.editEnded);
  847. materialSpread.bind(spreadNS.Events.ButtonClicked, materialSpreadObj.buttonClicked);
  848. const sheet = materialSpread.getActiveSheet();
  849. sheet.suspendPaint();
  850. // materialSpreadObj.refreshActn();
  851. // const basic_range = sheet.getRange(-1, 8, -1, 1);
  852. // basic_range.cellType(new DatePickerCellType());
  853. // basic_range.formatter("yyyy-MM-dd");
  854. // const msg_range = sheet.getRange(-1, 10, -1, 1);
  855. // msg_range.cellType(new DatePickerCellType());
  856. // msg_range.formatter("yyyy-MM-dd");
  857. sheet.resumePaint();
  858. const static_cols = [
  859. {title: '编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 60, formatter: '@', readOnly: true},
  860. {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 100, formatter: '@', readOnly: true},
  861. {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true},
  862. {title: '来源地', colSpan: '1', rowSpan: '2', field: 'origin', hAlign: 0, width: 70, formatter: '@', readOnly: 'readOnly.isEdit'},
  863. {title: '平均单价', colSpan: '1', rowSpan: '2', field: 'average_msg_tp', hAlign: 2, width: 60, type: 'Number', readOnly: true, getValue:'getValue.average_msg_tp'},
  864. ];
  865. // 月信息价方法集合
  866. const monthFunGather = {
  867. _setMonthHtml: function() {
  868. let html = '';
  869. let qihtml = '';
  870. for (const m of months) {
  871. html += '<div class="custom-control custom-checkbox mb-2">\n' +
  872. ' <input type="checkbox" name="del_month" value="' + m + '" class="custom-control-input" id="month_' + m + '">\n' +
  873. ' <label class="custom-control-label" for="month_' + m + '">' + m + '月</label>\n' +
  874. ' </div>';
  875. qihtml += parseInt(m.split('-')[1]) + '月,';
  876. }
  877. if (months.length > 0) {
  878. qihtml = '<span class="mx-2 text-muted">/</span>本期月信息价:' + qihtml;
  879. qihtml = qihtml.substring(0, qihtml.length-1);
  880. }
  881. $('#show_month').html(html);
  882. $('#qi-month').html(qihtml);
  883. },
  884. _monthHeaderSet: function() {
  885. const newMonths = [];
  886. for (const m of months) {
  887. const year = m.split('-')[0];
  888. const month = parseInt(m.split('-')[1]);
  889. let one = _.find(newMonths, { 'year': year });
  890. let oneIndex = _.findIndex(newMonths, { 'year': year });
  891. if (one) {
  892. one.month.push(month);
  893. newMonths.splice(oneIndex, 1, one);
  894. } else {
  895. one = {
  896. year: year,
  897. month: [ month ],
  898. };
  899. newMonths.push(one);
  900. }
  901. }
  902. const pushMonth = [];
  903. for(const mo of newMonths) {
  904. for (let i in mo.month) {
  905. i = parseInt(i);
  906. const newCols = {
  907. title: (i === 0 ? mo.year: '') + '|' + mo.month[i] + '月',
  908. colSpan: (i === 0 ? (mo.month.length === 1 ? '0' : mo.month.length) : '') + '|1',
  909. rowSpan: i === 0 ? '1|1' : '|1',
  910. field: mo.year + '-' + (mo.month[i] < 10 ? '0' + mo.month[i] : mo.month[i]),
  911. hAlign: 2, width: 60, type: '@', readOnly: 'readOnly.isEdit'};
  912. pushMonth.push(newCols);
  913. }
  914. }
  915. return pushMonth;
  916. },
  917. monthSheetReset: function (ml = monthsList) {
  918. const monthCols = monthFunGather._monthHeaderSet();
  919. const newMonthSpreadHeaderCols = static_cols.concat(monthCols);
  920. materialMonthSpreadSetting.cols = newMonthSpreadHeaderCols;
  921. // 表头变化需要重新绘制,不然报错;
  922. materialMonthSpread.getActiveSheet().reset();
  923. SpreadJsObj.initSpreadSettingEvents(materialMonthSpreadSetting, materialMonthCol);
  924. SpreadJsObj.initSheet(materialMonthSpread.getActiveSheet(), materialMonthSpreadSetting);
  925. SpreadJsObj.loadSheetData(materialMonthSpread.getActiveSheet(), SpreadJsObj.DataType.Data, ml);
  926. monthFunGather._setMonthHtml();
  927. },
  928. monthsListSet: function (ml = materialBillsData, checked = true) {
  929. if($('#bills0_list').is(':checked') && checked) {
  930. ml = _.filter(materialBillsData, function (item) {
  931. return item.quantity === null || item.quantity === 0;
  932. });
  933. }
  934. const newMonthsList = _.filter(monthsList, function (item) {
  935. return _.findIndex(ml, { code: item.code }) !== -1;
  936. });
  937. monthFunGather.monthSheetReset(newMonthsList);
  938. }
  939. };
  940. const materialMonthSpread = SpreadJsObj.createNewSpread($('#material-month-spread')[0]);
  941. const materialMonthSpreadSetting = {
  942. cols: static_cols,
  943. emptyRows: 0,
  944. headRows: 2,
  945. headRowHeight: [25, 25],
  946. defaultRowHeight: 21,
  947. headerFont: '12px 微软雅黑',
  948. font: '12px 微软雅黑',
  949. readOnly: readOnly,
  950. };
  951. if (months.length > 0) {
  952. const monthCols = monthFunGather._monthHeaderSet();
  953. const monthSpreadHeaderCols = static_cols.concat(monthCols);
  954. materialMonthSpreadSetting.cols = monthSpreadHeaderCols;
  955. }
  956. const materialMonthCol = {
  957. getValue: {
  958. average_msg_tp: function (data) {
  959. let msg_tp = 0;
  960. let hadnum = 0;
  961. for (const m of months) {
  962. msg_tp += data[m];
  963. if (data[m] !== null && data[m] !== '' && data[m] !== 0) {
  964. hadnum++;
  965. }
  966. }
  967. const average_tp = hadnum !== 0 ? ZhCalc.round(ZhCalc.div(msg_tp, hadnum), materialDecimal.up) : ZhCalc.round(ZhCalc.div(msg_tp, months.length), materialDecimal.up);
  968. return average_tp;
  969. },
  970. },
  971. readOnly: {
  972. isEdit: function (data) {
  973. return readOnly;
  974. },
  975. },
  976. };
  977. materialMonthSpread.getActiveSheet().frozenColumnCount(5);
  978. materialMonthSpread.getActiveSheet().options.frozenlineColor = '#f1f1f1';
  979. SpreadJsObj.initSpreadSettingEvents(materialMonthSpreadSetting, materialMonthCol);
  980. SpreadJsObj.initSheet(materialMonthSpread.getActiveSheet(), materialMonthSpreadSetting);
  981. SpreadJsObj.loadSheetData(materialMonthSpread.getActiveSheet(), SpreadJsObj.DataType.Data, monthsList);
  982. const materialMonthSpreadObj = {
  983. editEnded: function (e, info) {
  984. if (info.sheet.zh_setting) {
  985. const select = SpreadJsObj.getSelectObject(info.sheet);
  986. const col = info.sheet.zh_setting.cols[info.col];
  987. // 未改变值则不提交
  988. let validText = is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : null);
  989. const orgValue = select[col.field];
  990. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  991. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  992. return;
  993. }
  994. if (col.field === 'origin') {
  995. select[col.field] = validText;
  996. postData(window.location.pathname + '/month/save', { type:'updateOrigin', updateData: { mb_id: select.mb_id, value: validText } }, function (result) {
  997. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  998. materialBillsData = result.materialBillsData;
  999. materialSpreadObj.materialSheetReset();
  1000. // SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
  1001. }, function () {
  1002. select[col.field] = orgValue;
  1003. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1004. });
  1005. } else {
  1006. // 判断部分值是否输入的是数字判断和数据计算
  1007. if (isNaN(validText)) {
  1008. toastr.error('不能输入其它非数字类型字符');
  1009. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1010. return;
  1011. }
  1012. const num = parseFloat(validText);
  1013. const reg = materialDecimal.up ? new RegExp("^\\d+(\\.\\d{1,"+ materialDecimal.up +"})?$") : new RegExp("^\\d+?$");
  1014. if (validText !== null && (num < 0 || !reg.test(num))) {
  1015. toastr.warning('已保留'+ materialDecimal.up +'位小数');
  1016. validText = ZhCalc.round(num, materialDecimal.up);
  1017. }
  1018. select[col.field] = validText;
  1019. // 更新至服务器
  1020. postData(window.location.pathname + '/month/save', { type:'update', updateData: { mb_id: select.mb_id, yearmonth: col.field, value: validText } }, function (result) {
  1021. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1022. materialBillsData = result.materialBillsData;
  1023. materialSpreadObj.materialSheetReset();
  1024. // SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
  1025. m_tp = result.m_tp;
  1026. if (materialTax) {
  1027. m_tax_tp = result.m_tax_tp;
  1028. }
  1029. resetTpTable();
  1030. }, function () {
  1031. select[col.field] = orgValue;
  1032. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1033. });
  1034. }
  1035. }
  1036. },
  1037. deletePress: function (sheet) {
  1038. // if (sheet.zh_setting && sheet.zh_data) {
  1039. // const sel = sheet.getSelections()[0];
  1040. // if (!sel) return;
  1041. //
  1042. // const col = sheet.zh_setting.cols[sel.col];
  1043. // const select = SpreadJsObj.getSelectObject(sheet);
  1044. // const orgValue = select[col.field];
  1045. // if (sel.colCount > 1 || sel.rowCount > 1) {
  1046. // toastr.warning('请勿同时删除多行或多列数据');
  1047. // }
  1048. // console.log(sel, select, col);
  1049. // if (orgValue === null || col.field === 'type' || col.field === 'is_summary') {
  1050. // return;
  1051. // }
  1052. // select[col.field] = null;
  1053. // select.calc_num = materialExponentCol.getValue.calc_num(select);
  1054. // console.log(select);
  1055. // 更新至服务器
  1056. // postData(window.location.pathname + '/save', { type:'update', updateData: select }, function (result) {
  1057. // ex_tp = result.ex_tp;
  1058. // ex_expr = result.ex_expr;
  1059. // resetExTpTable();
  1060. // SpreadJsObj.reLoadRowData(sheet, sel.row);
  1061. // materialExponentData.splice(sel.row, 1, select);
  1062. // }, function () {
  1063. // select[col.field] = orgValue;
  1064. // SpreadJsObj.reLoadRowData(sheet, sel.row);
  1065. // });
  1066. // }
  1067. return;
  1068. },
  1069. clipboardPasted(e, info) {
  1070. const hint = {
  1071. cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
  1072. numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
  1073. numberCan: {type: 'warning', msg: '已保留'+ materialDecimal.up +'位小数'},
  1074. };
  1075. const range = info.cellRange;
  1076. const sortData = info.sheet.zh_data || [];
  1077. if (info.cellRange.row + info.cellRange.rowCount > sortData.length) {
  1078. toastMessageUniq(hint.cellError);
  1079. SpreadJsObj.reLoadSheetHeader(materialMonthSpread.getActiveSheet());
  1080. SpreadJsObj.reLoadSheetData(materialMonthSpread.getActiveSheet());
  1081. return;
  1082. }
  1083. if (sortData.length > 0 && range.col + range.colCount > 5 + months.length) {
  1084. toastMessageUniq(hint.cellError);
  1085. SpreadJsObj.reLoadSheetHeader(materialMonthSpread.getActiveSheet());
  1086. SpreadJsObj.reLoadSheetData(materialMonthSpread.getActiveSheet());
  1087. return;
  1088. }
  1089. const data = [];
  1090. let pasteOrigin = false;
  1091. for (let iRow = 0; iRow < range.rowCount; iRow++) {
  1092. let bPaste = true;
  1093. const curRow = range.row + iRow;
  1094. const materialMonthData = sortData[curRow];
  1095. const hintRow = range.rowCount > 1 ? curRow : '';
  1096. let sameCol = 0;
  1097. for (let iCol = 0; iCol < range.colCount; iCol++) {
  1098. const curCol = range.col + iCol;
  1099. const colSetting = info.sheet.zh_setting.cols[curCol];
  1100. if (!colSetting) continue;
  1101. let validText = info.sheet.getText(curRow, curCol);
  1102. validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : null);
  1103. const orgValue = sortData[curRow][colSetting.field];
  1104. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  1105. sameCol++;
  1106. if (range.colCount === sameCol) {
  1107. bPaste = false;
  1108. }
  1109. continue;
  1110. }
  1111. if (colSetting.field === 'origin') {
  1112. pasteOrigin = true;
  1113. } else {
  1114. const num = parseFloat(validText);
  1115. if (isNaN(validText)) {
  1116. toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
  1117. bPaste = false;
  1118. continue;
  1119. }
  1120. const reg = materialDecimal.up ? new RegExp("^\\d+(\\.\\d{1,"+ materialDecimal.up +"})?$") : new RegExp("^\\d+?$");
  1121. if (validText !== null && (num < 0 || !reg.test(num))) {
  1122. toastMessageUniq(getPasteHint(hint.numberCan, hintRow));
  1123. validText = ZhCalc.round(num, materialDecimal.up);
  1124. }
  1125. }
  1126. materialMonthData[colSetting.field] = validText;
  1127. sortData[curRow][colSetting.field] = validText;
  1128. }
  1129. if (bPaste) {
  1130. data.push(materialMonthData);
  1131. } else {
  1132. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  1133. }
  1134. }
  1135. if (data.length === 0) {
  1136. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1137. return;
  1138. }
  1139. // console.log(data);
  1140. if (pasteOrigin) {
  1141. // 更新至服务器
  1142. postData(window.location.pathname + '/month/save', { type:'pasteOrigin', updateData: data }, function (result) {
  1143. SpreadJsObj.reLoadSheetData(materialMonthSpread.getActiveSheet());
  1144. materialBillsData = result.materialBillsData;
  1145. }, function () {
  1146. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1147. return;
  1148. });
  1149. } else {
  1150. // 更新至服务器
  1151. postData(window.location.pathname + '/month/save', { type:'paste', updateData: data }, function (result) {
  1152. SpreadJsObj.reLoadSheetData(materialMonthSpread.getActiveSheet());
  1153. materialBillsData = result.materialBillsData;
  1154. materialSpreadObj.materialSheetReset();
  1155. // SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
  1156. m_tp = result.m_tp;
  1157. if (materialTax) {
  1158. m_tax_tp = result.m_tax_tp;
  1159. }
  1160. resetTpTable();
  1161. }, function () {
  1162. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1163. return;
  1164. });
  1165. }
  1166. },
  1167. };
  1168. // 应耗来源sjs
  1169. const material_source_cols = [
  1170. {title: '清单编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 100, formatter: '@'},
  1171. {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 150, formatter: '@'},
  1172. {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 70, formatter: '@'},
  1173. {title: '本期应耗', colSpan: '1', rowSpan: '2', field: 'quantity', hAlign: 0, width: 100, formatter: '@'},
  1174. ];
  1175. const materialSourceSpread = SpreadJsObj.createNewSpread($('#material-source-spread')[0]);
  1176. const materialSourceSpreadSetting = {
  1177. cols: material_source_cols,
  1178. emptyRows: 0,
  1179. headRows: 1,
  1180. headRowHeight: [32],
  1181. defaultRowHeight: 21,
  1182. headerFont: '12px 微软雅黑',
  1183. font: '12px 微软雅黑',
  1184. readOnly: true,
  1185. };
  1186. SpreadJsObj.initSheet(materialSourceSpread.getActiveSheet(), materialSourceSpreadSetting);
  1187. SpreadJsObj.loadSheetData(materialSourceSpread.getActiveSheet(), SpreadJsObj.DataType.Data, []);
  1188. let first = true;
  1189. function setListsData(sid = null, ms_id = null) {
  1190. if (first) {
  1191. // 加载清单数据 - 暂时统一加载,如有需要,切换成动态加载并缓存
  1192. postData(window.location.pathname + '/list/load', {sid}, async function (result) {
  1193. ledger = result.ledger;
  1194. curLedgerData = result.curLedgerData;
  1195. pos = result.pos;
  1196. curPosData = result.curPosData;
  1197. materialListData2 = result.materialListData;
  1198. gclList = result.gclList;
  1199. notJoinList = result.materialNotJoinListData;
  1200. selfList = result.materialSelfListData;
  1201. materialChecklistData = result.materialChecklistData;
  1202. if (isStageSelf) {
  1203. const newGclGatherListData = [];
  1204. for (const [index, s] of result.ledgerListData.entries()) {
  1205. gclGatherModel.loadLedgerData(_.cloneDeep(ledger), s);
  1206. gclGatherModel.loadPosData(_.cloneDeep(pos), result.posListData[index]);
  1207. const oneGclGatherData = gclGatherModel.gatherGclData().filter(item => {
  1208. return item.qc_qty || item.contract_qty
  1209. });
  1210. newGclGatherListData.push(oneGclGatherData);
  1211. }
  1212. gclGatherListData = newGclGatherListData;
  1213. }
  1214. // 解析清单汇总数据
  1215. gclGatherModel.loadLedgerData(_.cloneDeep(ledger), curLedgerData);
  1216. gclGatherModel.loadPosData(_.cloneDeep(pos), curPosData);
  1217. gclGatherData = gclGatherModel.gatherGclData();
  1218. gclGatherData = gclGatherData.filter(item => {
  1219. return item.qc_qty || item.contract_qty
  1220. });
  1221. if (openMaterialChecklist) {
  1222. // 取交集
  1223. const selfListGcl = _.uniq(_.map(selfList, 'gcl_id'));
  1224. gclGatherData = _.filter(gclGatherData, function (item) {
  1225. if (_.find(materialChecklistData, {
  1226. b_code: item.b_code,
  1227. name: item.name,
  1228. unit: item.unit,
  1229. unit_price: item.unit_price
  1230. })) {
  1231. return true;
  1232. } else {
  1233. const gcl_ids = item.leafXmjs ? _.uniq(_.map(item.leafXmjs, 'gcl_id')) : [];
  1234. const jiaoji = _.intersection(gcl_ids, selfListGcl);
  1235. if (jiaoji.length > 0) {
  1236. return true;
  1237. }
  1238. }
  1239. });
  1240. }
  1241. // calculateJiaCha(gclGatherData);
  1242. console.log(gclGatherData);
  1243. setCurBillSourceList(materialBillsData[0] ? materialBillsData[0].mb_id || materialBillsData[0].id : null, ms_id);
  1244. first = false;
  1245. });
  1246. } else {
  1247. const i = _.findIndex(materialStageData, { sid });
  1248. gclGatherData = gclGatherListData[i];
  1249. gclGatherData = gclGatherData.filter(item => {
  1250. return item.qc_qty || item.contract_qty
  1251. });
  1252. if (openMaterialChecklist) {
  1253. // 取交集
  1254. const selfListGcl = _.uniq(_.map(selfList, 'gcl_id'));
  1255. gclGatherData = _.filter(gclGatherData, function (item) {
  1256. if (_.find(materialChecklistData, {
  1257. b_code: item.b_code,
  1258. name: item.name,
  1259. unit: item.unit,
  1260. unit_price: item.unit_price
  1261. })) {
  1262. return true;
  1263. } else {
  1264. const gcl_ids = item.leafXmjs ? _.uniq(_.map(item.leafXmjs, 'gcl_id')) : [];
  1265. const jiaoji = _.intersection(gcl_ids, selfListGcl);
  1266. if (jiaoji.length > 0) {
  1267. return true;
  1268. }
  1269. }
  1270. });
  1271. }
  1272. // calculateJiaCha(gclGatherData);
  1273. console.log(gclGatherData);
  1274. }
  1275. }
  1276. setListsData(isStageSelf ? materialStageData[0].sid : null, isStageSelf ? materialStageData[0].id : null);
  1277. SpreadJsObj.initSpreadSettingEvents(materialSpreadSetting, materialCol);
  1278. SpreadJsObj.initSheet(materialSpread.getActiveSheet(), materialSpreadSetting);
  1279. materialSpreadObj.getMaterialBillsData();
  1280. SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
  1281. materialSpreadObj.refreshActn();
  1282. materialMonthSpread.bind(spreadNS.Events.ClipboardPasted, materialMonthSpreadObj.clipboardPasted);
  1283. SpreadJsObj.addDeleteBind(materialMonthSpread, materialMonthSpreadObj.deletePress);
  1284. materialMonthSpread.bind(spreadNS.Events.EditEnded, materialMonthSpreadObj.editEnded);
  1285. // 期切换
  1286. $('#myTab a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
  1287. e.preventDefault();
  1288. showWaitingView();
  1289. setTimeout(function () {
  1290. materialSpreadObj.getMaterialBillsData();
  1291. materialSpreadObj.materialSheetReset(true);
  1292. // SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
  1293. // 消耗量表格更新
  1294. let html = '';
  1295. calcBase = _.find(calcBaseList, { ms_id: $('#myTab').find('.active').data('msid') }).calcBase;
  1296. for (let iBase = 0; iBase < calcBase.length; iBase++) {
  1297. html += '<tr><td>' + calcBase[iBase].name + '</td><td>' + calcBase[iBase].code + '</td><td>' + calcBase[iBase].value + '</td></tr>';
  1298. }
  1299. $('#calcBase').html(html);
  1300. const ms_id = parseInt($('#myTab').find('.active').data('msid'));
  1301. const msInfo = _.find(materialStageData, { id: ms_id });
  1302. setListsData(msInfo.sid, ms_id);
  1303. const data = SpreadJsObj.getSelectObject(materialSpread.getActiveSheet());
  1304. setCurBillSourceList(data.mb_id || data.id, ms_id);
  1305. closeWaitingView();
  1306. }, 1000);
  1307. });
  1308. // 本条工料应耗来源数据信息
  1309. function setCurBillSourceList(mb_id, ms_id = null) {
  1310. const showSourceList = [];
  1311. if (mb_id) {
  1312. const list = _.filter(materialListData2, { mb_id, ms_id, is_join: 1 });
  1313. console.log(list);
  1314. if (list.length > 0) {
  1315. for (const l of list) {
  1316. const gcl = _.find(gclGatherData, function (item) {
  1317. return item.leafXmjs && item.leafXmjs.length > 0 && _.findIndex(item.leafXmjs, { gcl_id: l.gcl_id }) !== -1;
  1318. });
  1319. console.log(gcl);
  1320. if (gcl) {
  1321. const index = _.findIndex(showSourceList, { code: gcl.b_code, name: gcl.name, unit: gcl.unit });
  1322. if (index === -1) {
  1323. showSourceList.push({
  1324. code: gcl.b_code,
  1325. name: gcl.name,
  1326. unit: gcl.unit,
  1327. quantity: ZhCalc.mul(l.gather_qty, l.quantity),
  1328. });
  1329. } else {
  1330. showSourceList[index].quantity = ZhCalc.add(showSourceList[index].quantity, ZhCalc.mul(l.gather_qty, l.quantity));
  1331. }
  1332. }
  1333. }
  1334. }
  1335. }
  1336. SpreadJsObj.loadSheetData(materialSourceSpread.getActiveSheet(), SpreadJsObj.DataType.Data, showSourceList);
  1337. }
  1338. if (!readOnly || editForAudit) {
  1339. $('#expr_select button').on('click', function () {
  1340. const code = $(this).text();
  1341. // $('#expr').val($('#expr').val() + code);
  1342. $('#expr').insertAtCaret(code);
  1343. });
  1344. const ExprObj = {
  1345. _checkExprValid(expr, invalidParam) {
  1346. if (!expr) return [true, null];
  1347. const param = [];
  1348. let num = '', base = '';
  1349. for (let i = 0, iLen = expr.length; i < iLen; i++) {
  1350. if (/^[\d\.%]+/.test(expr[i])) {
  1351. if (base !== '') {
  1352. param.push({type: 'base', value: base});
  1353. base = '';
  1354. }
  1355. num = num + expr[i];
  1356. } else if (/^[a-z]/.test(expr[i])) {
  1357. if (num !== '') {
  1358. param.push({type: 'num', value: num});
  1359. num = '';
  1360. }
  1361. base = base + expr[i];
  1362. } else if (expr[i] === '(') {
  1363. if (num !== '') {
  1364. param.push({type: 'num', value: num});
  1365. num = '';
  1366. }
  1367. if (base !== '') {
  1368. param.push({type: 'base', value: base});
  1369. base = '';
  1370. }
  1371. param.push({type: 'left', value: '('});
  1372. } else if (expr[i] === ')') {
  1373. if (num !== '') {
  1374. param.push({type: 'num', value: num});
  1375. num = '';
  1376. }
  1377. if (base !== '') {
  1378. param.push({type: 'base', value: base});
  1379. base = '';
  1380. }
  1381. param.push({type: 'right', value: ')'});
  1382. } else if (/^[\+\-*\/]/.test(expr[i])) {
  1383. if (num !== '') {
  1384. param.push({type: 'num', value: num});
  1385. num = '';
  1386. }
  1387. if (base !== '') {
  1388. param.push({type: 'base', value: base});
  1389. base = '';
  1390. }
  1391. param.push({type: 'calc', value: expr[i]});
  1392. } else {
  1393. return [false, '输入的表达式含有非法字符: ' + expr[i]];
  1394. }
  1395. }
  1396. if (num !== '') {
  1397. param.push({type: 'num', value: num});
  1398. num = '';
  1399. }
  1400. if (base !== '') {
  1401. param.push({type: 'base', value: base});
  1402. base = '';
  1403. }
  1404. if (param.length === 0) return true;
  1405. if (param.length > 1) {
  1406. if (param[0].value === '-') {
  1407. param[1].value = '-' + param[1];
  1408. }
  1409. param.unshift();
  1410. }
  1411. const iLen = param.length;
  1412. let iLeftCount = 0, iRightCount = 0;
  1413. for (const [i, p] of param.entries()) {
  1414. if (p.type === 'calc') {
  1415. if (i === 0 || i === iLen - 1)
  1416. return [false, '输入的表达式非法:计算符号' + p.value + '前后应有数字或计算基数'];
  1417. }
  1418. if (p.type === 'num') {
  1419. num = p.value.replace('%', '');
  1420. if (p.value.length - num.length > 1)
  1421. return [false, '输入的表达式非法:' + p.value + '不是一个有效的数字'];
  1422. num = _.toNumber(num);
  1423. if (num === undefined || num === null || _.isNaN(num))
  1424. return [false, '输入的表达式非法:' + p.value + '不是一个有效的数字'];
  1425. if (i > 0) {
  1426. if (param[i - 1].type !== 'calc') {
  1427. return [false, '输入的表达式非法:' + p.value + '前应有运算符'];
  1428. } else if (param[i - 1].value === '/' && num === 0) {
  1429. return [false, '输入的表达式非法:请勿除0'];
  1430. }
  1431. }
  1432. }
  1433. if (p.type === 'base') {
  1434. const baseParam = _.find(calcBase, {code: p.value});
  1435. if (!baseParam)
  1436. return [false, '输入的表达式非法:不存在计算基数' + p.value];
  1437. if (invalidParam && invalidParam.indexOf(p.value) >= 0)
  1438. return [false, '不可使用计算基数' + p.value];
  1439. if (i > 0 && (param[i - 1].type === 'num' || param[i - 1].type === 'right'))
  1440. return [false, '输入的表达式非法:' + p.value + '前应有运算符'];
  1441. }
  1442. if (p.type === 'left') {
  1443. iLeftCount += 1;
  1444. if (i !== 0 && param[i-1].type !== 'calc')
  1445. return [false, '输入的表达式非法:(前应有运算符'];
  1446. }
  1447. if (p.type === 'right') {
  1448. iRightCount += 1;
  1449. if (i !== iLen - 1 && param[i+1].type !== 'calc')
  1450. return [false, '输入的表达式非法:)后应有运算符'];
  1451. if (iRightCount > iLeftCount)
  1452. return [false, '输入的表达式非法:")"前无对应的"("'];
  1453. }
  1454. }
  1455. if (iLeftCount > iRightCount)
  1456. return [false, '输入的表达式非法:"("后无对应的")"'];
  1457. return [true, ''];
  1458. },
  1459. _checkExpr: function (text) {
  1460. if (text) {
  1461. const num = _.toNumber(text);
  1462. if (num) {
  1463. console.log(num);
  1464. } else {
  1465. const expr = text.replace('=', '').toLowerCase();
  1466. const [valid, msg] = this._checkExprValid(expr);
  1467. if (!valid) return [valid, msg];
  1468. }
  1469. }
  1470. return [true, ''];
  1471. },
  1472. };
  1473. $('#expr_btn').click(function () {
  1474. const expr = $('#expr').val();
  1475. // 判断表达式格式
  1476. const [valid, msg] = ExprObj._checkExpr(expr);
  1477. if (!valid) {
  1478. toastr.error(msg);
  1479. return false;
  1480. }
  1481. postData(window.location.pathname + '/save', { type:'expr', id: $('#materialbillsId').val(), expr: expr, ms_id: $('#myTab').find('.active').data('msid') || null }, function (result) {
  1482. m_tp = result.m_tp;
  1483. if (materialTax) {
  1484. m_tax_tp = result.m_tax_tp;
  1485. }
  1486. const sheet = materialSpread.getActiveSheet();
  1487. const select = SpreadJsObj.getSelectObject(sheet);
  1488. const index = _.findIndex(materialBillsData, { id: select.id });
  1489. let newIndex = index;
  1490. if (isStageSelf) {
  1491. materialSpreadObj.updateMaterialData(result);
  1492. result.info = materialSpreadObj.updateOneMaterialBill(result.info);
  1493. }
  1494. if($('#bills0_list').is(':checked')) {
  1495. const newMaterialBillsData = _.filter(materialBillsData, function (item) {
  1496. return item.quantity !== null && item.quantity !== 0;
  1497. });
  1498. newIndex = _.findIndex(newMaterialBillsData, { id: select.id });
  1499. // newIndex = newMaterialBillsData.indexOf(select);
  1500. newMaterialBillsData.splice(newIndex, 1, result.info);
  1501. sheet.zh_data[newIndex] = result.info;
  1502. }
  1503. materialBillsData.splice(index, 1, result.info);
  1504. sheet.zh_data.splice(newIndex, 1, result.info);
  1505. SpreadJsObj.reLoadRowData(sheet, newIndex);
  1506. resetTpTable();
  1507. $('#bcyy').modal('hide');
  1508. });
  1509. });
  1510. }
  1511. if (!readOnly && !editForAudit) {
  1512. $('#add').click(materialSpreadObj.add);
  1513. $('#del').click(materialSpreadObj.del);
  1514. $('#up-move').click(materialSpreadObj.upMove);
  1515. $('#down-move').click(materialSpreadObj.downMove);
  1516. // 右键菜单
  1517. $.contextMenu({
  1518. selector: '#material-spread',
  1519. build: function ($trigger, e) {
  1520. const target = SpreadJsObj.safeRightClickSelection($trigger, e, materialSpread);
  1521. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  1522. },
  1523. items: {
  1524. 'create': {
  1525. name: '新增材料',
  1526. icon: 'fa-sign-in',
  1527. callback: function (key, opt) {
  1528. materialSpreadObj.add(materialSpread.getActiveSheet());
  1529. },
  1530. },
  1531. 'delete': {
  1532. name: '删除材料',
  1533. icon: 'fa-remove',
  1534. callback: function (key, opt) {
  1535. materialSpreadObj.del(materialSpread.getActiveSheet());
  1536. },
  1537. disabled: function (key, opt) {
  1538. const sheet = materialSpread.getActiveSheet();
  1539. const select = SpreadJsObj.getSelectObject(sheet);
  1540. const sel = sheet.getSelections()[0];
  1541. materialSpreadObj.refreshActn(sel.rowCount);
  1542. if (!readOnly && select && materialBase.isUsed(select) && sel.rowCount === 1) {
  1543. return false;
  1544. } else {
  1545. return true;
  1546. }
  1547. }
  1548. },
  1549. }
  1550. });
  1551. $('.changeRate').click(function () {
  1552. $('#rateInput').val(parseInt($(this).data('value')));
  1553. $('#rateInput').siblings('.dropdown-menu').hide();
  1554. });
  1555. $('#rateInput').click(function () {
  1556. $(this).siblings('.dropdown-menu').show();
  1557. })
  1558. // 回车提交
  1559. $('#rateInput').on('keypress', function () {
  1560. if(window.event.keyCode === 13) {
  1561. $(this).blur();
  1562. }
  1563. });
  1564. $('#rateInput').blur(function () {
  1565. const _self = $(this);
  1566. setTimeout(function () {
  1567. let rate = parseFloat(_self.val());
  1568. if (_.isNaN(rate)) {
  1569. toastr.error('请输入0-100之前的整数值');
  1570. $('#rateInput').val(materialRate);
  1571. return;
  1572. }
  1573. rate = _.round(rate);
  1574. if(rate < 0 || rate > 100) {
  1575. toastr.error('请输入0-100之前的整数值');
  1576. $('#rateInput').val(materialRate);
  1577. return;
  1578. }
  1579. $('#rateInput').siblings('.dropdown-menu').hide();
  1580. console.log(rate, materialRate);
  1581. if (rate !== materialRate) {
  1582. postData(window.location.pathname + '/save', { type:'rate', rate: rate }, function (result) {
  1583. const bqhs = ZhCalc.round(ZhCalc.mul(m_tp, 1+rate/100), materialDecimal.tp);
  1584. // const exbqhs = ZhCalc.round(ZhCalc.mul(ex_tp, 1+rate/100), materialDecimal.tp);
  1585. const jzbqhs = ZhCalc.round(ZhCalc.add(pre_tp_hs, bqhs), materialDecimal.tp);
  1586. // const exjzbqhs = ZhCalc.round(ZhCalc.add(ex_pre_tp_hs, exbqhs), materialDecimal.tp);
  1587. $('#rate_set').find('td').eq(1).text(bqhs !== 0 ? bqhs : '');
  1588. $('#rate_set').find('td').eq(2).text(jzbqhs !== 0 ? jzbqhs : '');
  1589. // $('#rate_set').find('td').eq(3).text(exbqhs !== 0 ? exbqhs : '');
  1590. // $('#rate_set').find('td').eq(4).text(exjzbqhs !== 0 ? exjzbqhs : '');
  1591. materialRate = rate;
  1592. $('#rateInput').val(rate);
  1593. });
  1594. } else {
  1595. $('#rateInput').val(rate);
  1596. }
  1597. }, 500);
  1598. });
  1599. // $('#changeRate').change(function () {
  1600. // const rate = parseInt($(this).val());
  1601. // postData(window.location.pathname + '/save', { type:'rate', rate: rate }, function (result) {
  1602. // const bqhs = ZhCalc.round(ZhCalc.mul(m_tp, 1+rate/100), materialDecimal.tp);
  1603. // const exbqhs = ZhCalc.round(ZhCalc.mul(ex_tp, 1+rate/100), materialDecimal.tp);
  1604. // const jzbqhs = ZhCalc.round(ZhCalc.add(pre_tp_hs, bqhs), materialDecimal.tp);
  1605. // const exjzbqhs = ZhCalc.round(ZhCalc.add(ex_pre_tp_hs, exbqhs), materialDecimal.tp);
  1606. // $('#rate_set').find('td').eq(1).text(bqhs !== 0 ? bqhs : '');
  1607. // $('#rate_set').find('td').eq(2).text(jzbqhs !== 0 ? jzbqhs : '');
  1608. // $('#rate_set').find('td').eq(3).text(exbqhs !== 0 ? exbqhs : '');
  1609. // $('#rate_set').find('td').eq(4).text(exjzbqhs !== 0 ? exjzbqhs : '');
  1610. // });
  1611. // });
  1612. // 创建月信息价
  1613. $('#make-month').click(function() {
  1614. const yearmonth = $('#months').val();
  1615. const result = yearmonth.match(/^(\d{1,4})(-|\/)(\d{1,2})$/);
  1616. if (result === null) {
  1617. toastr.error('请选择正确的信息价月份');
  1618. return false;
  1619. }
  1620. //判断是否已存在当前月份
  1621. if (months.indexOf(yearmonth) !== -1) {
  1622. toastr.error('调差期已创建过本月的信息价');
  1623. return false;
  1624. }
  1625. postData(window.location.pathname + '/month/save', { type: 'add', updateData: { yearmonth: yearmonth } }, function (data) {
  1626. months.push(yearmonth);
  1627. months.sort();
  1628. monthsList = data.monthsList;
  1629. monthFunGather.monthsListSet();
  1630. // 工料表单价显示也要更新
  1631. materialBillsData = data.materialBillsData;
  1632. materialSpreadObj.materialSheetReset();
  1633. // SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
  1634. m_tp = data.m_tp;
  1635. if (materialTax) {
  1636. m_tax_tp = data.m_tax_tp;
  1637. }
  1638. resetTpTable();
  1639. $('#add-month').modal('hide');
  1640. });
  1641. });
  1642. // 删除月信息价
  1643. $('#del-month').click(function () {
  1644. const del_month_array = [];
  1645. $("input[name='del_month']:checked").each(function () {
  1646. del_month_array.push($(this).val());
  1647. });
  1648. if (del_month_array.length === 0) {
  1649. toastr.error('请选择要移除的月信息价');
  1650. return false;
  1651. }
  1652. postData(window.location.pathname + '/month/save', { type: 'del', updateData: { del_yearmonth: del_month_array } }, function (data) {
  1653. for (const dm of del_month_array) {
  1654. // _.remove(materialMonthSpreadSetting.cols, function (n) {
  1655. // return n.field === dm;
  1656. // });
  1657. _.remove(months, function (n) {
  1658. return n === dm;
  1659. });
  1660. }
  1661. monthsList = data.monthsList;
  1662. monthFunGather.monthsListSet();
  1663. // 工料表单价显示也要更新
  1664. materialBillsData = data.materialBillsData;
  1665. materialSpreadObj.materialSheetReset();
  1666. // SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
  1667. m_tp = data.m_tp;
  1668. if (materialTax) {
  1669. m_tax_tp = data.m_tax_tp;
  1670. }
  1671. resetTpTable();
  1672. $('#remove-month').modal('hide');
  1673. });
  1674. });
  1675. // 导入功能
  1676. let importFile = null;
  1677. $('#upload-xls-file').change(function () {
  1678. const file = this.files[0];
  1679. importFile = file;
  1680. });
  1681. $('#import-bills-btn').click(function() {
  1682. if (!importFile) {
  1683. toastr.error('请选择excel文件再确定');
  1684. return;
  1685. }
  1686. const ext = importFile.name.toLowerCase().split('.').splice(-1)[0];
  1687. const imgStr = /(xls|xlsx|XLS|XLSX)$/;
  1688. if (!imgStr.test(ext)) {
  1689. toastr.error('请导入正确格式的excel文件。');
  1690. return
  1691. }
  1692. const fileReader = new FileReader();
  1693. fileReader.onload = async function(ev) {
  1694. try{
  1695. const data = ev.target.result;
  1696. let tree = [];
  1697. const includeSpec = $('#xls-spec').is(':checked');
  1698. if (/(xls|xlsx|XLS|XLSX)$/.test(ext)) {
  1699. const workbook = XLSX.read(data, {type: 'binary'}); // 以二进制流方式读取得到整份excel表格对象
  1700. const jsonData = transExcel(XLSX.utils.sheet_to_json(workbook.Sheets[workbook.SheetNames[0]], { defval: null }));
  1701. console.log(jsonData);
  1702. if (!(jsonData[0] && jsonData[0].code !== undefined && jsonData[0].code !== null && jsonData[0].unit !== undefined && jsonData[0].name !== undefined &&
  1703. jsonData[0].spec !== undefined && jsonData[0].msg_tp !== undefined && jsonData[0].msg_times !== undefined)) {
  1704. throw 'excel必须按指定格式内容上传';
  1705. }
  1706. // 去重
  1707. tree = _.unionWith(jsonData, function (item1, item2) {
  1708. return item1.code === item2.code && item1.name === item2.name && item1.unit === item2.unit && (!includeSpec || (includeSpec && item1.spec === item2.spec));
  1709. });
  1710. }
  1711. if (tree.length === 0) {
  1712. throw '该excel不存在导入的数据';
  1713. }
  1714. // 判断msg_tp格式,不符合则无法导入,还有excel日期转换问题
  1715. for (const t of tree) {
  1716. t.code = t.code.toString();
  1717. if (t.msg_tp) {
  1718. if (_.isNumber(t.msg_tp)) {
  1719. const num = parseFloat(t.msg_tp);
  1720. const reg = materialDecimal.up ? new RegExp("^\\d+(\\.\\d{1,"+ materialDecimal.up +"})?$") : new RegExp("^\\d+?$");
  1721. if (num < 0 || !reg.test(num)) {
  1722. t.msg_tp = ZhCalc.round(num, materialDecimal.up);
  1723. }
  1724. } else {
  1725. throw '信息价数据存在非数字字符,无法导入';
  1726. }
  1727. }
  1728. if (_.isNumber(t.msg_times)) {
  1729. t.msg_times = formatDate(t.msg_times, '/');
  1730. }
  1731. t.spec = t.spec === null ? '' : t.spec;
  1732. }
  1733. console.log(tree);
  1734. postData(window.location.pathname + '/save', { type:'export', postData: tree, includeSpec, ms_id: $('#myTab').find('.active').data('msid') || null }, function (result) {
  1735. m_tp = result.m_tp;
  1736. if (materialTax) {
  1737. m_tax_tp = result.m_tax_tp;
  1738. }
  1739. materialBillsData = result.billsData;
  1740. if (isStageSelf) {
  1741. materialStageData = result.stageData;
  1742. materialStageBillsData = result.stageBillsData;
  1743. }
  1744. materialSpreadObj.getMaterialBillsData();
  1745. materialSpreadObj.materialSheetReset(true);
  1746. if (months.length > 0) {
  1747. monthsList = result.monthsList;
  1748. monthFunGather.monthsListSet();
  1749. }
  1750. resetTpTable();
  1751. if (result.addNum || result.updateNum) {
  1752. let msg = [];
  1753. if (result.addNum !== undefined && result.addNum !== 0) {
  1754. msg.push('成功导入工料 ' + result.addNum + ' 条');
  1755. }
  1756. if (result.updateNum !== undefined && result.updateNum !== 0) {
  1757. msg.push('成功更新工料 ' + result.updateNum + ' 条');
  1758. }
  1759. toastr.success(msg.length > 1 ? msg.join(',并') : msg[0]);
  1760. } else {
  1761. toastr.warning('不存在可导入的信息价数据');
  1762. }
  1763. $('#import-info').modal('hide');
  1764. });
  1765. } catch (error) {
  1766. console.log(error);
  1767. toastr.error(error);
  1768. return
  1769. }
  1770. };
  1771. // 以二进制方式打开文件
  1772. fileReader.readAsBinaryString(importFile);
  1773. $('#upload-xls-file').val('');
  1774. importFile = null;
  1775. });
  1776. } else {
  1777. // SpreadJsObj.forbiddenSpreadContextMenu('#material-spread', materialSpread);
  1778. }
  1779. // 筛选调差工料本期应耗数量为0
  1780. $('#bills0_list').click(function () {
  1781. const isCheck = $(this).is(':checked');
  1782. let newMaterialBillsData = materialBillsData;
  1783. if (isCheck) {
  1784. newMaterialBillsData = _.filter(materialBillsData, function (item) {
  1785. return item.quantity !== null && item.quantity !== 0;
  1786. });
  1787. SpreadJsObj.initSpreadSettingEvents(materialSpreadSetting, materialCol);
  1788. SpreadJsObj.initSheet(materialSpread.getActiveSheet(), materialSpreadSetting);
  1789. }
  1790. SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, newMaterialBillsData);
  1791. monthFunGather.monthsListSet(newMaterialBillsData, false);
  1792. materialSpreadObj.refreshActn();
  1793. });
  1794. let gljLib;
  1795. const gljLibCellDoubleClick = function (e, info) {
  1796. if (readOnly || editForAudit) return;
  1797. const gljSheet = info.sheet;
  1798. if (!gljSheet.zh_setting || !gljSheet.zh_tree) { return; }
  1799. const gljTree = gljSheet.zh_tree;
  1800. const gljNode = gljTree.nodes[info.row];
  1801. const sheet = materialSpread.getActiveSheet();
  1802. const select = SpreadJsObj.getSelectObject(sheet);
  1803. if (!gljNode) return;
  1804. if (gljNode && gljNode.is_leaf === 0) {
  1805. toastr.warning('非最底层项目下,不应添加');
  1806. return;
  1807. }
  1808. postData(window.location.pathname + '/save', { type:'add-glj', postData: gljNode, order: select ? select.order : null }, function (result) {
  1809. if (result) {
  1810. // 比order大的+1
  1811. const maxData = select ? _.filter(materialBillsData, (item) => { return item.order > select.order }) : [];
  1812. _.forEach(maxData, function (item) {
  1813. const cl = _.find(materialBillsData, { id: item.id });
  1814. cl.order = item.order + 1;
  1815. });
  1816. materialBillsData.push(result.info);
  1817. materialBillsData.sort(function (a, b) {
  1818. return a.order - b.order
  1819. });
  1820. console.log(materialBillsData);
  1821. if (isStageSelf) {
  1822. materialSpreadObj.updateMaterialData(result);
  1823. materialSpreadObj.getMaterialBillsData();
  1824. }
  1825. // sheet.addRows(materialBillsData.length - 1, 1);
  1826. // SpreadJsObj.reLoadRowData(sheet, materialBillsData.length - 1);
  1827. let newMaterialBillsData = materialBillsData;
  1828. if($('#bills0_list').is(':checked')) {
  1829. newMaterialBillsData = _.filter(materialBillsData, function (item) {
  1830. return item.quantity !== null && item.quantity !== 0;
  1831. });
  1832. }
  1833. SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, newMaterialBillsData);
  1834. // materialSpreadObj.materialSheetReset();
  1835. sheet.setSelection(sheet.zh_data.indexOf(select) + 1, 0, 1, 1);
  1836. materialSpreadObj.refreshActn();
  1837. // 月信息价需要同时添加空白的list
  1838. if (months.length > 0) {
  1839. const one_month ={ mb_id: result.info.id, code: result.info.code, name: result.info.name, origin: result.info.origin, unit: result.info.unit, order: result.info.order };
  1840. for (const m of months) {
  1841. one_month[m] = null;
  1842. }
  1843. _.forEach(maxData, function (item) {
  1844. const cl = _.find(monthsList, { mb_id: item.id });
  1845. cl.order = item.order + 1;
  1846. });
  1847. monthsList.push(one_month);
  1848. monthsList.sort(function (a, b) {
  1849. return a.order - b.order
  1850. });
  1851. console.log(monthsList);
  1852. // const newMonthsList = _.filter(monthsList, function (item) {
  1853. // return _.findIndex(newMaterialBillsData, { code: item.code }) !== -1;
  1854. // });
  1855. // materialMonthSpread.getActiveSheet().addRows(newMonthsList.length - 1, 1);
  1856. // SpreadJsObj.reLoadRowData(materialMonthSpread.getActiveSheet(), newMonthsList.length - 1);
  1857. monthFunGather.monthsListSet();
  1858. // materialMonthSpreadObj.monthsListSet();
  1859. }
  1860. }
  1861. });
  1862. };
  1863. const gljLibSetting = {
  1864. selector: '#material-tab',
  1865. stdType: 'glj',
  1866. libs: gljLists,
  1867. treeSetting: {
  1868. id: 'glj_id',
  1869. pid: 'glj_pid',
  1870. order: 'order',
  1871. level: 'level',
  1872. rootId: -1,
  1873. keys: ['id', 'list_id', 'glj_id'],
  1874. },
  1875. spreadSetting: {
  1876. cols: [
  1877. {title: '编号', field: 'code', hAlign: 0, width: 120, formatter: '@', readOnly: true, cellType: 'tree'},
  1878. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  1879. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true},
  1880. {title: '参考上涨幅度', field: 'rise_range', hAlign: 1, width: 50, formatter: '@', readOnly: true},
  1881. {title: '参考下跌幅度', field: 'fall_range', hAlign: 1, width: 50, formatter: '@', readOnly: true},
  1882. ],
  1883. treeCol: 0,
  1884. emptyRows: 0,
  1885. headRows: 1,
  1886. headRowHeight: [32],
  1887. defaultRowHeight: 21,
  1888. headerFont: '12px 微软雅黑',
  1889. font: '12px 微软雅黑',
  1890. headColWidth: [30],
  1891. selectedBackColor: '#fffacd',
  1892. },
  1893. spreadClassCss: 'sjs-material',
  1894. cellDoubleClick: gljLibCellDoubleClick,
  1895. page: 'material',
  1896. tid: window.location.pathname.split('/')[2],
  1897. };
  1898. $.subMenu({
  1899. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  1900. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  1901. key: 'menu.1.0.0',
  1902. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  1903. callback: function (info) {
  1904. if (info.mini) {
  1905. $('.panel-title').addClass('fluid');
  1906. $('#sub-menu').removeClass('panel-sidebar');
  1907. } else {
  1908. $('.panel-title').removeClass('fluid');
  1909. $('#sub-menu').addClass('panel-sidebar');
  1910. }
  1911. autoFlashHeight();
  1912. materialSpread.refresh();
  1913. }
  1914. });
  1915. $.divResizer({
  1916. select: '#right-spr',
  1917. callback: function () {
  1918. materialSpread.refresh();
  1919. materialMonthSpread.refresh();
  1920. if (gljLib) gljLib.spread.refresh();
  1921. const width = (($('#right-view').width()/$('#right-view').parent('div').width())*100).toFixed();
  1922. setLocalCache('material_month_' + materialID, width);
  1923. }
  1924. });
  1925. $.divResizer({
  1926. select: '#main-resize',
  1927. callback: function () {
  1928. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  1929. $(".sp-wrap").height(bcontent-30);
  1930. const height = $('.bcontent-wrap').height();
  1931. const cutHeight = isStageSelf ? getObjHeight($('#myTab')) : 0;
  1932. $('.sjs-height-material').height($('.sjs-height-1').height() - cutHeight);
  1933. updateSjsHeight();
  1934. materialSpread.refresh();
  1935. materialMonthSpread.refresh();
  1936. if (gljLib) gljLib.spread.refresh();
  1937. setLocalCache('material_bills_' + materialID, height);
  1938. }
  1939. });
  1940. // 展开收起月信息价并浏览器记住本期展开收起
  1941. $('a', '.right-nav').bind('click', function () {
  1942. //const main = $('#main-view'), tool = $('#tools-view');
  1943. const tab = $(this), tabPanel = $(tab.attr('content'));
  1944. if (!tab.hasClass('active')) {
  1945. $('a', '.side-menu').removeClass('active');
  1946. $('#right-view .tab-content .tab-pane').removeClass('active');
  1947. tab.addClass('active');
  1948. tabPanel.addClass('active');
  1949. showSideTools(tab.hasClass('active'));
  1950. if (tab.attr('content') === '#month-tab') {
  1951. const width = (($('#right-view').width()/$('#right-view').parent('div').width())*100).toFixed();
  1952. setLocalCache('material_month_' + materialID, width);
  1953. materialMonthSpread.refresh();
  1954. } else if (tab.attr('content') === '#material-tab') {
  1955. if (!gljLib) {
  1956. gljLib = $.gljLib(gljLibSetting);
  1957. }
  1958. updateSjsHeight();
  1959. gljLib.spread.refresh();
  1960. }
  1961. } else {
  1962. removeLocalCache('material_month_' + materialID);
  1963. tab.removeClass('active');
  1964. tabPanel.removeClass('active');
  1965. showSideTools(tab.hasClass('active'));
  1966. }
  1967. materialSpread.refresh();
  1968. // materialMonthSpread.refresh();
  1969. });
  1970. // 根据浏览器记录展开收起
  1971. if (getLocalCache('material_month_' + materialID) && !isStageSelf) {
  1972. const tab = $('.right-nav a[content="#month-tab"]'), tabPanel = $(tab.attr('content'));
  1973. $('a', '.side-menu').removeClass('active');
  1974. $('.tab-content .tab-pane').removeClass('active');
  1975. tab.addClass('active');
  1976. tabPanel.addClass('active');
  1977. $('#right-view').width(getLocalCache('material_month_' + materialID) + '%');
  1978. showSideTools(tab.hasClass('active'));
  1979. materialSpread.refresh();
  1980. materialMonthSpread.refresh();
  1981. }
  1982. const cutHeight = isStageSelf ? getObjHeight($('#myTab')) : 0;
  1983. if (getLocalCache('material_bills_' + materialID)) {
  1984. $('.bcontent-wrap').height(getLocalCache('material_bills_' + materialID));
  1985. const cHeader = getObjHeight($(".c-header"));
  1986. const bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  1987. $(".sp-wrap").height(bcontent-30);
  1988. $('.sjs-height-1').height($(window).height()-cHeader-bcontent-90+53);
  1989. $('.sjs-height-material').height($('.sjs-height-1').height() - cutHeight);
  1990. updateSjsHeight();
  1991. materialSpread.refresh();
  1992. materialMonthSpread.refresh();
  1993. if (gljLib) gljLib.spread.refresh();
  1994. } else {
  1995. $('.sjs-height-material').height($('.sjs-height-1').height() - cutHeight);
  1996. updateSjsHeight();
  1997. materialSpread.refresh();
  1998. materialMonthSpread.refresh();
  1999. if (gljLib) gljLib.spread.refresh();
  2000. }
  2001. function updateSjsHeight() {
  2002. $('.sjs-height-material-month').height($('.sjs-height-1').height() - getObjHeight($('.sjs-bar-1')));
  2003. $('.material-table-height').height($('.bcontent-wrap').height() - getObjHeight($('.bc-bar')));
  2004. $('.sjs-material').height($('.sjs-height-1').height() - getObjHeight($('.sjs-bar')));
  2005. }
  2006. function getObjHeight(select) {
  2007. return select.length > 0 ? select.height() : 0;
  2008. }
  2009. function formatDate(numb, format) {
  2010. const old = numb - 1;
  2011. const t = Math.round((old - Math.floor(old)) * 24 * 60 * 60);
  2012. const time = new Date(1900, 0, old, 0, 0, t);
  2013. const year = time.getFullYear();
  2014. const month = time.getMonth() + 1;
  2015. const date = time.getDate();
  2016. return year + format + (month < 10 ? '0' + month : month) + format + (date < 10 ? '0' + date : date);
  2017. }
  2018. function transExcel(results) {
  2019. const mapInfo = {
  2020. '编号': 'code',
  2021. '名称': 'name',
  2022. '单位': 'unit',
  2023. '规格': 'spec',
  2024. '信息价': 'msg_tp',
  2025. '时间': 'msg_times',
  2026. };
  2027. return results.map(zhObj => {
  2028. const enObj = {}
  2029. const zhKeys = Object.keys(zhObj);
  2030. zhKeys.forEach(zhKey => {
  2031. const enKey = mapInfo[zhKey];
  2032. enObj[enKey] = zhObj[zhKey] && _.isString(zhObj[zhKey]) ? _.trim(zhObj[zhKey]) : zhObj[zhKey];
  2033. });
  2034. return enObj
  2035. })
  2036. }
  2037. });