material.js 89 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794
  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. // console.log(data, data.t_type);
  173. // return !readOnly && data.t_type === 2 && data.mid === materialID;
  174. return data.t_type === 2;
  175. };
  176. materialSpreadSetting.imageClick = function (data) {
  177. if (data.t_type === 2) {
  178. $('#bcyy').modal('show');
  179. $('#materialbillsId').val(data.id);
  180. $('#expr').val(data.expr);
  181. if (!readOnly) {
  182. $('#expr').attr('readOnly', false);
  183. $('#expr_btn').show();
  184. $('#expr_select').show();
  185. } else {
  186. $('#expr').attr('readOnly', true);
  187. $('#expr_btn').hide();
  188. $('#expr_select').hide();
  189. }
  190. }
  191. };
  192. const materialBase = {
  193. isUsed: function (data) {
  194. if (data.t_type === 2) {
  195. return data.mid === materialID;
  196. } else {
  197. const mlInfo = _.find(materialListData, { mb_id: data.id });
  198. return data.mid === materialID && mlInfo === undefined;
  199. }
  200. },
  201. isEdit: function (data) {
  202. // if (data.t_type === 2) {
  203. // return data.mid === materialID;
  204. // } else {
  205. // const mlInfo = _.find(materialListData, { mb_id: data.id });
  206. // return data.mid === materialID && mlInfo === undefined;
  207. // }
  208. return data.mid === materialID;
  209. },
  210. // isStage: function (data) {
  211. // return data.mid === materialID;
  212. // }
  213. }
  214. const materialCol = {
  215. getValue: {
  216. msg_spread: function (data) {
  217. return ZhCalc.round(ZhCalc.sub(data.msg_tp, data.basic_price), materialDecimal.up);
  218. },
  219. m_spread : function (data) {
  220. const msg_spread = materialCol.getValue.msg_spread(data);
  221. 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));
  222. 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;
  223. },
  224. m_tp: function (data) {
  225. return ZhCalc.round(ZhCalc.mul(materialCol.getValue.m_spread(data), data.quantity), materialDecimal.tp);
  226. },
  227. m_tax_tp: function (data) {
  228. const m_tp = ZhCalc.round(ZhCalc.mul(materialCol.getValue.m_spread(data), data.quantity), materialDecimal.tp);
  229. return data.m_tax ? ZhCalc.round(ZhCalc.mul(m_tp, (1+ZhCalc.div(data.m_tax, 100))), materialDecimal.tp) : m_tp;
  230. }
  231. },
  232. readOnly: {
  233. isEdit: function (data) {
  234. return !(!readOnly && materialBase.isEdit(data));
  235. },
  236. isUsed: function (data) {
  237. return !(!readOnly && materialBase.isUsed(data));
  238. },
  239. remark: function () {
  240. return readOnly;
  241. },
  242. msg_tp: function () {
  243. return !(!readOnly && months.length === 0);
  244. }
  245. },
  246. };
  247. const needUpdateArray = ['quantity', 'expr', 'msg_tp', 'msg_times', 'msg_spread', 'm_spread', 'm_tp', 'm_tax_tp', 'is_summary', 'remark'];
  248. const materialSpreadObj = {
  249. getMaterialBillsData: function () {
  250. if (isStageSelf) {
  251. // 当前选中nav id
  252. const ms_id = $('#myTab').find('.active').data('msid');
  253. const msbList = _.filter(materialStageBillsData, { ms_id });
  254. for (const mb of materialBillsData) {
  255. mb.ms_id = ms_id;
  256. const msbInfo = _.find(msbList, { mb_id: mb.mb_id ? mb.mb_id : mb.id });
  257. if (msbInfo) {
  258. for (const nu of needUpdateArray) {
  259. mb[nu] = msbInfo[nu];
  260. }
  261. }
  262. }
  263. }
  264. return materialBillsData;
  265. },
  266. updateOneMaterialBill: function (data) {
  267. const ms_id = $('#myTab').find('.active').data('msid');
  268. const msbInfo = _.find(materialStageBillsData, { ms_id, mb_id: data.id });
  269. console.log(msbInfo);
  270. data.ms_id = ms_id;
  271. for (const nu of needUpdateArray) {
  272. data[nu] = msbInfo[nu];
  273. }
  274. return data;
  275. },
  276. updateMaterialData: function (datas) {
  277. if (datas.billsData && datas.billsData.length > 0) {
  278. if (datas.billsData.length === materialBillsData.length) {
  279. // 全体替换
  280. materialBillsData = datas.billsData;
  281. } else {
  282. for (const b of datas.billsData) {
  283. const index = _.findIndex(materialBillsData, {id: b.id});
  284. materialBillsData.splice(index, 1, b);
  285. }
  286. }
  287. }
  288. if (datas.stageData && datas.stageData.length > 0) {
  289. if (datas.stageData.length === materialStageData.length) {
  290. // 全体替换
  291. materialStageData = datas.stageData;
  292. } else {
  293. // 替换对应的stage数据
  294. for (const s of datas.stageData) {
  295. const index = _.findIndex(materialStageData, { id: s.id });
  296. materialStageData.splice(index, 1, s);
  297. }
  298. }
  299. }
  300. if (datas.pushStageBillsData && datas.pushStageBillsData.length > 0) {
  301. materialStageBillsData = _.concat(materialStageBillsData, datas.pushStageBillsData);
  302. }
  303. if (datas.stageBillsData && datas.stageBillsData.length > 0) {
  304. if (datas.stageBillsData.length === materialStageBillsData.length) {
  305. // 全体替换
  306. materialStageBillsData = datas.stageBillsData;
  307. } else {
  308. // 替换对应的stage数据
  309. for (const s of datas.stageBillsData) {
  310. const index = _.findIndex(materialStageBillsData, { id: s.id });
  311. materialStageBillsData.splice(index, 1, s);
  312. }
  313. }
  314. }
  315. },
  316. materialSheetReset: function (redo = false) {
  317. let newMaterialBillsData = _.cloneDeep(materialBillsData);
  318. if($('#bills0_list').is(':checked')) {
  319. newMaterialBillsData = _.filter(materialBillsData, function (item) {
  320. return item.quantity !== null && item.quantity !== 0;
  321. });
  322. if (redo) {
  323. SpreadJsObj.initSpreadSettingEvents(materialSpreadSetting, materialCol);
  324. SpreadJsObj.initSheet(materialSpread.getActiveSheet(), materialSpreadSetting);
  325. }
  326. }
  327. console.log(newMaterialBillsData);
  328. SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, newMaterialBillsData);
  329. materialSpreadObj.refreshActn();
  330. },
  331. refreshActn: function (rowCount = 1) {
  332. const setObjEnable = function (obj, enable) {
  333. if (enable) {
  334. obj.removeClass('disabled');
  335. } else {
  336. obj.addClass('disabled');
  337. }
  338. };
  339. const sheet = materialSpread.getActiveSheet();
  340. const select = SpreadJsObj.getSelectObject(sheet);
  341. const selection = sheet.getSelections();
  342. const sel = selection ? selection[0] : sheet.getSelections()[0];
  343. const row = sel ? sel.row : -1;
  344. const first = materialBillsData[row];
  345. let last = first;
  346. if (sel.rowCount > 1 && first) {
  347. for (let r = 1; r < sel.rowCount; r++) {
  348. const rNode = materialBillsData[sel.row + r];
  349. if (!rNode) break;
  350. last = rNode;
  351. }
  352. }
  353. const preNode = materialBillsData[row - 1];
  354. // 还需判断是否已被调差清单调用
  355. setObjEnable($('#del'), !readOnly && select && materialBase.isUsed(select) && rowCount === 1);
  356. setObjEnable($('#up-move'), !readOnly && first && preNode && materialBillsData.indexOf(last) > 0 && sel.row + sel.rowCount <= materialBillsData.length && !$('#bills0_list').is(':checked'));
  357. setObjEnable($('#down-move'), !readOnly && first && materialBillsData.indexOf(last) < materialBillsData.length - 1 && sel.row + sel.rowCount <= materialBillsData.length && !$('#bills0_list').is(':checked'));
  358. },
  359. add: function () {
  360. const sheet = materialSpread.getActiveSheet();
  361. postData(window.location.pathname + '/save', {type: 'add'}, function (result) {
  362. if (result) {
  363. materialBillsData.push(result.info);
  364. if (isStageSelf) {
  365. materialSpreadObj.updateMaterialData(result);
  366. materialSpreadObj.getMaterialBillsData();
  367. }
  368. // sheet.addRows(materialBillsData.length - 1, 1);
  369. // SpreadJsObj.reLoadRowData(sheet, materialBillsData.length - 1);
  370. let newMaterialBillsData = materialBillsData;
  371. if($('#bills0_list').is(':checked')) {
  372. newMaterialBillsData = _.filter(materialBillsData, function (item) {
  373. return item.quantity !== null && item.quantity !== 0;
  374. });
  375. }
  376. SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, newMaterialBillsData);
  377. // materialSpreadObj.materialSheetReset();
  378. sheet.setSelection(newMaterialBillsData.length - 1, 0, 1, 1);
  379. materialSpreadObj.refreshActn();
  380. // 月信息价需要同时添加空白的list
  381. if (months.length > 0) {
  382. const one_month ={ mb_id: result.info.id, code: '', name: null, origin: null, unit: null, order: result.info.order };
  383. for (const m of months) {
  384. one_month[m] = null;
  385. }
  386. monthsList.push(one_month);
  387. // const newMonthsList = _.filter(monthsList, function (item) {
  388. // return _.findIndex(newMaterialBillsData, { code: item.code }) !== -1;
  389. // });
  390. // materialMonthSpread.getActiveSheet().addRows(newMonthsList.length - 1, 1);
  391. // SpreadJsObj.reLoadRowData(materialMonthSpread.getActiveSheet(), newMonthsList.length - 1);
  392. monthFunGather.monthsListSet();
  393. // materialMonthSpreadObj.monthsListSet();
  394. }
  395. }
  396. });
  397. },
  398. del: function () {
  399. const sheet = materialSpread.getActiveSheet();
  400. const select = SpreadJsObj.getSelectObject(sheet);
  401. postData(window.location.pathname + '/save', {type: 'del', id: select.id}, function (result) {
  402. m_tp = result.m_tp;
  403. if (materialTax) {
  404. m_tax_tp = result.m_tax_tp;
  405. }
  406. const index = materialBillsData.indexOf(select);
  407. let newMaterialBillsData = materialBillsData;
  408. let newIndex = index;
  409. if($('#bills0_list').is(':checked')) {
  410. newMaterialBillsData = _.filter(materialBillsData, function (item) {
  411. return item.quantity !== null && item.quantity !== 0;
  412. });
  413. newIndex = newMaterialBillsData.indexOf(select);
  414. }
  415. materialBillsData.splice(index, 1);
  416. sheet.deleteRows(newIndex, 1);
  417. if (isStageSelf) {
  418. materialSpreadObj.updateMaterialData(result);
  419. materialSpreadObj.getMaterialBillsData();
  420. }
  421. resetTpTable();
  422. // SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
  423. const sel = sheet.getSelections();
  424. sheet.setSelection(newIndex > 0 ? newIndex - 1 : 0, sel.length > 0 ? sel[0].col : 0, 1, 1);
  425. materialSpreadObj.refreshActn();
  426. // 月信息价需要同时删除
  427. if (months.length > 0) {
  428. monthsList.splice(index, 1);
  429. materialMonthSpread.getActiveSheet().deleteRows(newIndex, 1);
  430. // SpreadJsObj.reLoadSheetData(materialMonthSpread.getActiveSheet());
  431. }
  432. });
  433. },
  434. upMove: function () {
  435. if($('#bills0_list').is(':checked')) {
  436. return;
  437. }
  438. const data = {
  439. type: 'changeOrder',
  440. postData: [],
  441. };
  442. const sheet = materialSpread.getActiveSheet();
  443. const selection = sheet.getSelections();
  444. const row = selection[0].row, count = selection[0].rowCount;
  445. const first = sheet.zh_data[row];
  446. if (!first) {
  447. materialSpreadObj.refreshActn();
  448. return false;
  449. }
  450. const pre = sheet.zh_data[row - 1], preUpdate = {id: pre.id};
  451. for (let iRow = 0; iRow < count; iRow++) {
  452. const posData = sheet.zh_data[iRow + row];
  453. if (posData) {
  454. data.postData.push({id: posData.id, order: sheet.zh_data[iRow + row - 1].order});
  455. preUpdate.order = posData.order;
  456. }
  457. }
  458. console.log(monthsList);
  459. data.postData.push(preUpdate);
  460. console.log(data);
  461. if (data.postData.length > 0) {
  462. postData(window.location.pathname + '/save', data, function () {
  463. _.forEach(data.postData, function (item) {
  464. const cl = _.find(materialBillsData, { id: item.id });
  465. cl.order = item.order;
  466. });
  467. materialBillsData.sort(function (a, b) {
  468. return a.order - b.order
  469. });
  470. SpreadJsObj.reLoadSheetData(sheet);
  471. const sel = selection[0];
  472. if (sel) {
  473. sheet.setSelection(sheet.zh_data.indexOf(first), sel.col, sel.rowCount, sel.colCount);
  474. }
  475. if (months.length > 0) {
  476. _.forEach(data.postData, function (item) {
  477. const cl = _.find(monthsList, { mb_id: item.id });
  478. cl.order = item.order;
  479. });
  480. monthsList.sort(function (a, b) {
  481. return a.order - b.order
  482. });
  483. const materialMonthSheet = materialMonthSpread.getActiveSheet();
  484. SpreadJsObj.reLoadSheetData(materialMonthSheet);
  485. }
  486. materialSpreadObj.refreshActn();
  487. });
  488. }
  489. },
  490. downMove: function () {
  491. if($('#bills0_list').is(':checked')) {
  492. return;
  493. }
  494. const data = {
  495. type: 'changeOrder',
  496. postData: [],
  497. };
  498. const sheet = materialSpread.getActiveSheet();
  499. const selection = sheet.getSelections();
  500. const row = selection[0].row, count = selection[0].rowCount;
  501. const first = sheet.zh_data[row];
  502. if (!first) {
  503. materialSpreadObj.refreshActn();
  504. return false;
  505. }
  506. const next = sheet.zh_data[row + count], nextUpdate = {id: next.id};
  507. for (let iRow = count - 1; iRow >= 0; iRow--) {
  508. const posData = sheet.zh_data[iRow + row];
  509. if (posData) {
  510. data.postData.push({id: posData.id, order: sheet.zh_data[iRow + row + 1].order});
  511. nextUpdate.order = posData.order;
  512. }
  513. }
  514. data.postData.push(nextUpdate);
  515. console.log(data);
  516. if (data.postData.length > 0) {
  517. postData(window.location.pathname + '/save', data, function () {
  518. _.forEach(data.postData, function (item) {
  519. const cl = _.find(materialBillsData, { id: item.id });
  520. cl.order = item.order;
  521. });
  522. materialBillsData.sort(function (a, b) {
  523. return a.order - b.order
  524. });
  525. SpreadJsObj.reLoadSheetData(sheet);
  526. const sel = selection[0];
  527. if (sel) {
  528. sheet.setSelection(sheet.zh_data.indexOf(first), sel.col, sel.rowCount, sel.colCount);
  529. }
  530. if (months.length > 0) {
  531. _.forEach(data.postData, function (item) {
  532. const cl = _.find(monthsList, { mb_id: item.id });
  533. cl.order = item.order;
  534. });
  535. monthsList.sort(function (a, b) {
  536. return a.order - b.order
  537. });
  538. const materialMonthSheet = materialMonthSpread.getActiveSheet();
  539. SpreadJsObj.reLoadSheetData(materialMonthSheet);
  540. }
  541. materialSpreadObj.refreshActn();
  542. });
  543. }
  544. },
  545. selectionChanged: function (e, info) {
  546. const sel = info.sheet.getSelections()[0];
  547. const col = info.sheet.zh_setting.cols[sel.col];
  548. materialSpreadObj.refreshActn(sel.rowCount);
  549. const data = SpreadJsObj.getSelectObject(info.sheet);
  550. materialSpreadObj.setReadOnly(true);
  551. // console.log(data);
  552. },
  553. editEnded: function (e, info) {
  554. if (info.sheet.zh_setting) {
  555. const select = SpreadJsObj.getSelectObject(info.sheet);
  556. const col = info.sheet.zh_setting.cols[info.col];
  557. if (col.field === 'is_summary') {
  558. return;
  559. }
  560. // 未改变值则不提交
  561. let validText = is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : null);
  562. const orgValue = select[col.field];
  563. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  564. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  565. return;
  566. }
  567. // 判断部分值是否输入的是数字判断和数据计算
  568. if (col.field === 'basic_price') {
  569. if (isNaN(validText)) {
  570. toastr.error('不能输入其它非数字类型字符');
  571. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  572. return;
  573. }
  574. let num = parseFloat(validText);
  575. const reg = materialDecimal.up ? new RegExp("^\\d+(\\.\\d{1,"+ materialDecimal.up +"})?$") : new RegExp("^\\d+?$");
  576. if (validText !== null && (num < 0 || !reg.test(num))) {
  577. toastr.warning('已保留'+ materialDecimal.up +'位小数');
  578. validText = ZhCalc.round(num, materialDecimal.up);
  579. }
  580. }
  581. if (col.field === 'msg_tp') {
  582. if (isNaN(validText)) {
  583. toastr.error('不能输入其它非数字类型字符');
  584. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  585. return;
  586. }
  587. const num = parseFloat(validText);
  588. const reg = materialDecimal.up ? new RegExp("^\\d+(\\.\\d{1,"+ materialDecimal.up +"})?$") : new RegExp("^\\d+?$");
  589. if (validText !== null && (num < 0 || !reg.test(num))) {
  590. toastr.warning('已保留'+ materialDecimal.up +'位小数');
  591. validText = ZhCalc.round(num, materialDecimal.up);
  592. }
  593. }
  594. if (col.field === 'm_up_risk' || col.field === 'm_down_risk' || col.field === 'm_tax') {
  595. // 只能输入正整数
  596. if (isNaN(validText)) {
  597. toastr.error('不能输入其它非数字类型字符');
  598. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  599. return;
  600. }
  601. const num = parseFloat(validText);
  602. if (validText !== null && (num < 0 || num > 100 || !/^\d+$/.test(num))) {
  603. toastr.error('只能输入0-100的正整数');
  604. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  605. return;
  606. }
  607. }
  608. if (col.field === 't_type') {
  609. if (validText === 1) {
  610. select.quantity = null;
  611. select.expr = null;
  612. select.m_tp = null;
  613. }
  614. }
  615. select[col.field] = validText;
  616. select.msg_spread = materialCol.getValue.msg_spread(select);
  617. select.m_spread = materialCol.getValue.m_spread(select);
  618. select.m_tp = materialCol.getValue.m_tp(select);
  619. select.m_tax_tp = materialCol.getValue.m_tax_tp(select);
  620. delete select.waitingLoading;
  621. // console.log(select);
  622. // 更新至服务器
  623. postData(window.location.pathname + '/save', { type:'update', updateData: select, ms_id: $('#myTab').find('.active').data('msid') || null }, function (result) {
  624. m_tp = result.m_tp;
  625. if (materialTax) {
  626. m_tax_tp = result.m_tax_tp;
  627. }
  628. if (isStageSelf) {
  629. materialSpreadObj.updateMaterialData(result);
  630. }
  631. resetTpTable();
  632. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  633. // 判断如果是更改了编号,名称,单位,月信息价需要跟着改变值
  634. if (months.length > 0 && (col.field === 'code' || col.field === 'name' || col.field === 'unit')) {
  635. const index = materialBillsData.indexOf(select);
  636. monthsList[index][col.field] = validText;
  637. monthFunGather.monthsListSet();
  638. }
  639. }, function () {
  640. select[col.field] = orgValue;
  641. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  642. });
  643. }
  644. },
  645. buttonClicked: function (e, info) {
  646. if (info.sheet.zh_setting) {
  647. const select = SpreadJsObj.getSelectObject(info.sheet);
  648. const col = info.sheet.zh_setting.cols[info.col];
  649. if (materialCol.readOnly.isEdit(select)) {
  650. return;
  651. }
  652. if (col.field === 'is_summary') {
  653. if (info.sheet.isEditing()) {
  654. info.sheet.endEdit(true);
  655. }
  656. select.is_summary = info.sheet.getValue(info.row, info.col) ? 1 : 0;
  657. delete select.waitingLoading;
  658. // 更新至服务器
  659. postData(window.location.pathname + '/save', { type:'update', updateData: select, ms_id: $('#myTab').find('.active').data('msid') || null }, function (result) {
  660. m_tp = result.m_tp;
  661. if (materialTax) {
  662. m_tax_tp = result.m_tax_tp;
  663. }
  664. if (isStageSelf) {
  665. materialSpreadObj.updateMaterialData(result);
  666. }
  667. resetTpTable();
  668. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  669. }, function () {
  670. select.is_summary = info.sheet.getValue(info.row, info.col) ? 0 : 1;
  671. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  672. });
  673. }
  674. }
  675. },
  676. deletePress: function (sheet) {
  677. return;
  678. },
  679. clipboardPasted(e, info) {
  680. const hint = {
  681. cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
  682. codeEmpty: {type: 'error', msg: '请先输入编号,并且不超过15个字符'},
  683. codeUsed: {type: 'error', msg: '该编号已存在,请重新输入。'},
  684. codeError: {type: 'error', msg: '编号为纯数字时,不能为小数'},
  685. numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
  686. riskCan: {type: 'error', msg: '只能粘贴0-100的正整数'},
  687. numberCan: {type: 'warning', msg: '已保留'+ materialDecimal.up +'位小数'},
  688. };
  689. const range = info.cellRange;
  690. const sortData = info.sheet.zh_data || [];
  691. if (info.cellRange.row + info.cellRange.rowCount > sortData.length) {
  692. toastMessageUniq(hint.cellError);
  693. // SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
  694. SpreadJsObj.reLoadSheetHeader(materialSpread.getActiveSheet());
  695. SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
  696. return;
  697. }
  698. if (sortData.length > 0 && range.col + range.colCount > 18) {
  699. toastMessageUniq(hint.cellError);
  700. SpreadJsObj.reLoadSheetHeader(materialSpread.getActiveSheet());
  701. SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
  702. return;
  703. }
  704. const data = [];
  705. // const rowData = [];
  706. for (let iRow = 0; iRow < range.rowCount; iRow++) {
  707. let bPaste = true;
  708. const curRow = range.row + iRow;
  709. // const materialData = JSON.parse(JSON.stringify(sortData[curRow]));
  710. const materialData = { id: sortData[curRow].id };
  711. const hintRow = range.rowCount > 1 ? curRow : '';
  712. let sameCol = 0;
  713. for (let iCol = 0; iCol < range.colCount; iCol++) {
  714. const curCol = range.col + iCol;
  715. const colSetting = info.sheet.zh_setting.cols[curCol];
  716. if (!colSetting) continue;
  717. let validText = info.sheet.getText(curRow, curCol);
  718. validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : null);
  719. const orgValue = sortData[curRow][colSetting.field];
  720. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  721. sameCol++;
  722. if (range.colCount === sameCol) {
  723. bPaste = false;
  724. }
  725. continue;
  726. }
  727. if (colSetting.field === 'code' && (validText === '' || validText.length > 15)) {
  728. toastMessageUniq(getPasteHint(hint.codeEmpty, hintRow));
  729. bPaste = false;
  730. continue;
  731. }
  732. if (colSetting.field === 'code' && validText.toString().indexOf('.') !== -1) {
  733. toastMessageUniq(getPasteHint(hint.codeError, hintRow));
  734. bPaste = false;
  735. continue;
  736. }
  737. if (colSetting.field === 'code' && _.find(sortData, { code: validText.toString() })) {
  738. toastMessageUniq(getPasteHint(hint.codeUsed, hintRow));
  739. bPaste = false;
  740. continue;
  741. }
  742. if (colSetting.field === 't_type' || colSetting.field === 'm_type') {
  743. continue;
  744. }
  745. if (colSetting.field === 'basic_price' || colSetting.field === 'msg_tp'
  746. || colSetting.field === 'm_up_risk' || colSetting.field === 'm_down_risk') {
  747. if (isNaN(validText)) {
  748. toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
  749. bPaste = false;
  750. continue;
  751. }
  752. const num = parseFloat(validText);
  753. if (colSetting.field === 'basic_price' || colSetting.field === 'msg_tp') {
  754. const reg = materialDecimal.up ? new RegExp("^\\d+(\\.\\d{1,"+ materialDecimal.up +"})?$") : new RegExp("^\\d+?$");
  755. if (validText !== null && (num < 0 || !reg.test(num))) {
  756. toastMessageUniq(getPasteHint(hint.numberCan, hintRow));
  757. validText = ZhCalc.round(num, materialDecimal.up);
  758. }
  759. } else if (colSetting.field === 'm_up_risk' || colSetting.field === 'm_down_risk' || colSetting.field === 'm_tax') {
  760. if (validText !== null && (num < 0 || num > 100 || !/^\d+$/.test(num))) {
  761. toastMessageUniq(getPasteHint(hint.riskCan, hintRow));
  762. bPaste = false;
  763. continue;
  764. }
  765. }
  766. }
  767. materialData[colSetting.field] = validText;
  768. sortData[curRow][colSetting.field] = validText;
  769. }
  770. if (materialData.code === '' || materialData.code === null) {
  771. toastMessageUniq(getPasteHint(hint.codeEmpty, hintRow));
  772. bPaste = false;
  773. }
  774. if (bPaste) {
  775. materialData.msg_spread = materialCol.getValue.msg_spread(sortData[curRow]);
  776. materialData.m_spread = materialCol.getValue.m_spread(sortData[curRow]);
  777. materialData.m_tp = materialCol.getValue.m_tp(sortData[curRow]);
  778. materialData.m_tax_tp = materialCol.getValue.m_tax_tp(sortData[curRow]);
  779. data.push(materialData);
  780. // rowData.push(curRow);
  781. } else {
  782. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  783. }
  784. }
  785. if (data.length === 0) {
  786. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  787. return;
  788. }
  789. // console.log(data);
  790. // 更新至服务器
  791. postData(window.location.pathname + '/save', { type:'paste', updateData: data, ms_id: $('#myTab').find('.active').data('msid') || null }, function (result) {
  792. materialBillsData = result.info;
  793. m_tp = result.m_tp;
  794. if (materialTax) {
  795. m_tax_tp = result.m_tax_tp;
  796. }
  797. if (isStageSelf) {
  798. materialSpreadObj.updateMaterialData(result);
  799. materialSpreadObj.getMaterialBillsData();
  800. }
  801. // SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
  802. materialSpreadObj.materialSheetReset();
  803. // SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
  804. // for (const row in rowData) {
  805. // materialBillsData.splice(index, 1, result.info[row]);
  806. // SpreadJsObj.reLoadRowData(info.sheet, row);
  807. // }
  808. if (months.length > 0) {
  809. for (const [i,m] of monthsList.entries()) {
  810. m.code = materialBillsData[i].code;
  811. m.name = materialBillsData[i].name;
  812. m.unit = materialBillsData[i].unit;
  813. m.origin = materialBillsData[i].origin;
  814. }
  815. // SpreadJsObj.loadSheetData(materialMonthSpread.getActiveSheet(), SpreadJsObj.DataType.Data, monthsList);
  816. monthFunGather.monthsListSet();
  817. // SpreadJsObj.reLoadSheetData(materialMonthSpread.getActiveSheet());
  818. }
  819. resetTpTable();
  820. // materialSpreadObj.refreshActn();
  821. }, function () {
  822. // materialSpreadObj.refreshActn();
  823. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  824. return;
  825. });
  826. },
  827. setReadOnly: function(readOnly) {
  828. // SpreadJsObj.resetFieldReadOnly(materialSpread.getActiveSheet(), 'msg_spread', 'm_spread', 'm_tp', 'pre_tp', readOnly);
  829. }
  830. };
  831. materialSpread.bind(spreadNS.Events.SelectionChanged, materialSpreadObj.selectionChanged);
  832. materialSpread.bind(spreadNS.Events.ClipboardPasted, materialSpreadObj.clipboardPasted);
  833. SpreadJsObj.addDeleteBind(materialSpread, materialSpreadObj.deletePress);
  834. materialSpread.bind(spreadNS.Events.EditEnded, materialSpreadObj.editEnded);
  835. materialSpread.bind(spreadNS.Events.ButtonClicked, materialSpreadObj.buttonClicked);
  836. const sheet = materialSpread.getActiveSheet();
  837. sheet.suspendPaint();
  838. // materialSpreadObj.refreshActn();
  839. // const basic_range = sheet.getRange(-1, 8, -1, 1);
  840. // basic_range.cellType(new DatePickerCellType());
  841. // basic_range.formatter("yyyy-MM-dd");
  842. // const msg_range = sheet.getRange(-1, 10, -1, 1);
  843. // msg_range.cellType(new DatePickerCellType());
  844. // msg_range.formatter("yyyy-MM-dd");
  845. sheet.resumePaint();
  846. const static_cols = [
  847. {title: '编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 60, formatter: '@', readOnly: true},
  848. {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 100, formatter: '@', readOnly: true},
  849. {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true},
  850. {title: '来源地', colSpan: '1', rowSpan: '2', field: 'origin', hAlign: 0, width: 70, formatter: '@', readOnly: 'readOnly.isEdit'},
  851. {title: '平均单价', colSpan: '1', rowSpan: '2', field: 'average_msg_tp', hAlign: 2, width: 60, type: 'Number', readOnly: true, getValue:'getValue.average_msg_tp'},
  852. ];
  853. // 月信息价方法集合
  854. const monthFunGather = {
  855. _setMonthHtml: function() {
  856. let html = '';
  857. let qihtml = '';
  858. for (const m of months) {
  859. html += '<div class="custom-control custom-checkbox mb-2">\n' +
  860. ' <input type="checkbox" name="del_month" value="' + m + '" class="custom-control-input" id="month_' + m + '">\n' +
  861. ' <label class="custom-control-label" for="month_' + m + '">' + m + '月</label>\n' +
  862. ' </div>';
  863. qihtml += parseInt(m.split('-')[1]) + '月,';
  864. }
  865. if (months.length > 0) {
  866. qihtml = '<span class="mx-2 text-muted">/</span>本期月信息价:' + qihtml;
  867. qihtml = qihtml.substring(0, qihtml.length-1);
  868. }
  869. $('#show_month').html(html);
  870. $('#qi-month').html(qihtml);
  871. },
  872. _monthHeaderSet: function() {
  873. const newMonths = [];
  874. for (const m of months) {
  875. const year = m.split('-')[0];
  876. const month = parseInt(m.split('-')[1]);
  877. let one = _.find(newMonths, { 'year': year });
  878. let oneIndex = _.findIndex(newMonths, { 'year': year });
  879. if (one) {
  880. one.month.push(month);
  881. newMonths.splice(oneIndex, 1, one);
  882. } else {
  883. one = {
  884. year: year,
  885. month: [ month ],
  886. };
  887. newMonths.push(one);
  888. }
  889. }
  890. const pushMonth = [];
  891. for(const mo of newMonths) {
  892. for (let i in mo.month) {
  893. i = parseInt(i);
  894. const newCols = {
  895. title: (i === 0 ? mo.year: '') + '|' + mo.month[i] + '月',
  896. colSpan: (i === 0 ? (mo.month.length === 1 ? '0' : mo.month.length) : '') + '|1',
  897. rowSpan: i === 0 ? '1|1' : '|1',
  898. field: mo.year + '-' + (mo.month[i] < 10 ? '0' + mo.month[i] : mo.month[i]),
  899. hAlign: 2, width: 60, type: '@', readOnly: 'readOnly.isEdit'};
  900. pushMonth.push(newCols);
  901. }
  902. }
  903. return pushMonth;
  904. },
  905. monthSheetReset: function (ml = monthsList) {
  906. const monthCols = monthFunGather._monthHeaderSet();
  907. const newMonthSpreadHeaderCols = static_cols.concat(monthCols);
  908. materialMonthSpreadSetting.cols = newMonthSpreadHeaderCols;
  909. // 表头变化需要重新绘制,不然报错;
  910. materialMonthSpread.getActiveSheet().reset();
  911. SpreadJsObj.initSpreadSettingEvents(materialMonthSpreadSetting, materialMonthCol);
  912. SpreadJsObj.initSheet(materialMonthSpread.getActiveSheet(), materialMonthSpreadSetting);
  913. SpreadJsObj.loadSheetData(materialMonthSpread.getActiveSheet(), SpreadJsObj.DataType.Data, ml);
  914. monthFunGather._setMonthHtml();
  915. },
  916. monthsListSet: function (ml = materialBillsData, checked = true) {
  917. if($('#bills0_list').is(':checked') && checked) {
  918. ml = _.filter(materialBillsData, function (item) {
  919. return item.quantity === null || item.quantity === 0;
  920. });
  921. }
  922. const newMonthsList = _.filter(monthsList, function (item) {
  923. return _.findIndex(ml, { code: item.code }) !== -1;
  924. });
  925. monthFunGather.monthSheetReset(newMonthsList);
  926. }
  927. };
  928. const materialMonthSpread = SpreadJsObj.createNewSpread($('#material-month-spread')[0]);
  929. const materialMonthSpreadSetting = {
  930. cols: static_cols,
  931. emptyRows: 0,
  932. headRows: 2,
  933. headRowHeight: [25, 25],
  934. defaultRowHeight: 21,
  935. headerFont: '12px 微软雅黑',
  936. font: '12px 微软雅黑',
  937. readOnly: readOnly,
  938. };
  939. if (months.length > 0) {
  940. const monthCols = monthFunGather._monthHeaderSet();
  941. const monthSpreadHeaderCols = static_cols.concat(monthCols);
  942. materialMonthSpreadSetting.cols = monthSpreadHeaderCols;
  943. }
  944. const materialMonthCol = {
  945. getValue: {
  946. average_msg_tp: function (data) {
  947. let msg_tp = 0;
  948. let hadnum = 0;
  949. for (const m of months) {
  950. msg_tp += data[m];
  951. if (data[m] !== null && data[m] !== '' && data[m] !== 0) {
  952. hadnum++;
  953. }
  954. }
  955. const average_tp = hadnum !== 0 ? ZhCalc.round(ZhCalc.div(msg_tp, hadnum), materialDecimal.up) : ZhCalc.round(ZhCalc.div(msg_tp, months.length), materialDecimal.up);
  956. return average_tp;
  957. },
  958. },
  959. readOnly: {
  960. isEdit: function (data) {
  961. return readOnly;
  962. },
  963. },
  964. };
  965. materialMonthSpread.getActiveSheet().frozenColumnCount(5);
  966. materialMonthSpread.getActiveSheet().options.frozenlineColor = '#f1f1f1';
  967. SpreadJsObj.initSpreadSettingEvents(materialMonthSpreadSetting, materialMonthCol);
  968. SpreadJsObj.initSheet(materialMonthSpread.getActiveSheet(), materialMonthSpreadSetting);
  969. SpreadJsObj.loadSheetData(materialMonthSpread.getActiveSheet(), SpreadJsObj.DataType.Data, monthsList);
  970. const materialMonthSpreadObj = {
  971. editEnded: function (e, info) {
  972. if (info.sheet.zh_setting) {
  973. const select = SpreadJsObj.getSelectObject(info.sheet);
  974. const col = info.sheet.zh_setting.cols[info.col];
  975. // 未改变值则不提交
  976. let validText = is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : null);
  977. const orgValue = select[col.field];
  978. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  979. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  980. return;
  981. }
  982. if (col.field === 'origin') {
  983. select[col.field] = validText;
  984. postData(window.location.pathname + '/month/save', { type:'updateOrigin', updateData: { mb_id: select.mb_id, value: validText } }, function (result) {
  985. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  986. materialBillsData = result.materialBillsData;
  987. materialSpreadObj.materialSheetReset();
  988. // SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
  989. }, function () {
  990. select[col.field] = orgValue;
  991. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  992. });
  993. } else {
  994. // 判断部分值是否输入的是数字判断和数据计算
  995. if (isNaN(validText)) {
  996. toastr.error('不能输入其它非数字类型字符');
  997. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  998. return;
  999. }
  1000. const num = parseFloat(validText);
  1001. const reg = materialDecimal.up ? new RegExp("^\\d+(\\.\\d{1,"+ materialDecimal.up +"})?$") : new RegExp("^\\d+?$");
  1002. if (validText !== null && (num < 0 || !reg.test(num))) {
  1003. toastr.warning('已保留'+ materialDecimal.up +'位小数');
  1004. validText = ZhCalc.round(num, materialDecimal.up);
  1005. }
  1006. select[col.field] = validText;
  1007. // 更新至服务器
  1008. postData(window.location.pathname + '/month/save', { type:'update', updateData: { mb_id: select.mb_id, yearmonth: col.field, value: validText } }, function (result) {
  1009. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1010. materialBillsData = result.materialBillsData;
  1011. materialSpreadObj.materialSheetReset();
  1012. // SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
  1013. m_tp = result.m_tp;
  1014. if (materialTax) {
  1015. m_tax_tp = result.m_tax_tp;
  1016. }
  1017. resetTpTable();
  1018. }, function () {
  1019. select[col.field] = orgValue;
  1020. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1021. });
  1022. }
  1023. }
  1024. },
  1025. deletePress: function (sheet) {
  1026. // if (sheet.zh_setting && sheet.zh_data) {
  1027. // const sel = sheet.getSelections()[0];
  1028. // if (!sel) return;
  1029. //
  1030. // const col = sheet.zh_setting.cols[sel.col];
  1031. // const select = SpreadJsObj.getSelectObject(sheet);
  1032. // const orgValue = select[col.field];
  1033. // if (sel.colCount > 1 || sel.rowCount > 1) {
  1034. // toastr.warning('请勿同时删除多行或多列数据');
  1035. // }
  1036. // console.log(sel, select, col);
  1037. // if (orgValue === null || col.field === 'type' || col.field === 'is_summary') {
  1038. // return;
  1039. // }
  1040. // select[col.field] = null;
  1041. // select.calc_num = materialExponentCol.getValue.calc_num(select);
  1042. // console.log(select);
  1043. // 更新至服务器
  1044. // postData(window.location.pathname + '/save', { type:'update', updateData: select }, function (result) {
  1045. // ex_tp = result.ex_tp;
  1046. // ex_expr = result.ex_expr;
  1047. // resetExTpTable();
  1048. // SpreadJsObj.reLoadRowData(sheet, sel.row);
  1049. // materialExponentData.splice(sel.row, 1, select);
  1050. // }, function () {
  1051. // select[col.field] = orgValue;
  1052. // SpreadJsObj.reLoadRowData(sheet, sel.row);
  1053. // });
  1054. // }
  1055. return;
  1056. },
  1057. clipboardPasted(e, info) {
  1058. const hint = {
  1059. cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
  1060. numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
  1061. numberCan: {type: 'warning', msg: '已保留'+ materialDecimal.up +'位小数'},
  1062. };
  1063. const range = info.cellRange;
  1064. const sortData = info.sheet.zh_data || [];
  1065. if (info.cellRange.row + info.cellRange.rowCount > sortData.length) {
  1066. toastMessageUniq(hint.cellError);
  1067. SpreadJsObj.reLoadSheetHeader(materialMonthSpread.getActiveSheet());
  1068. SpreadJsObj.reLoadSheetData(materialMonthSpread.getActiveSheet());
  1069. return;
  1070. }
  1071. if (sortData.length > 0 && range.col + range.colCount > 5 + months.length) {
  1072. toastMessageUniq(hint.cellError);
  1073. SpreadJsObj.reLoadSheetHeader(materialMonthSpread.getActiveSheet());
  1074. SpreadJsObj.reLoadSheetData(materialMonthSpread.getActiveSheet());
  1075. return;
  1076. }
  1077. const data = [];
  1078. let pasteOrigin = false;
  1079. for (let iRow = 0; iRow < range.rowCount; iRow++) {
  1080. let bPaste = true;
  1081. const curRow = range.row + iRow;
  1082. const materialMonthData = sortData[curRow];
  1083. const hintRow = range.rowCount > 1 ? curRow : '';
  1084. let sameCol = 0;
  1085. for (let iCol = 0; iCol < range.colCount; iCol++) {
  1086. const curCol = range.col + iCol;
  1087. const colSetting = info.sheet.zh_setting.cols[curCol];
  1088. if (!colSetting) continue;
  1089. let validText = info.sheet.getText(curRow, curCol);
  1090. validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : null);
  1091. const orgValue = sortData[curRow][colSetting.field];
  1092. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  1093. sameCol++;
  1094. if (range.colCount === sameCol) {
  1095. bPaste = false;
  1096. }
  1097. continue;
  1098. }
  1099. if (colSetting.field === 'origin') {
  1100. pasteOrigin = true;
  1101. } else {
  1102. const num = parseFloat(validText);
  1103. if (isNaN(validText)) {
  1104. toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
  1105. bPaste = false;
  1106. continue;
  1107. }
  1108. const reg = materialDecimal.up ? new RegExp("^\\d+(\\.\\d{1,"+ materialDecimal.up +"})?$") : new RegExp("^\\d+?$");
  1109. if (validText !== null && (num < 0 || !reg.test(num))) {
  1110. toastMessageUniq(getPasteHint(hint.numberCan, hintRow));
  1111. validText = ZhCalc.round(num, materialDecimal.up);
  1112. }
  1113. }
  1114. materialMonthData[colSetting.field] = validText;
  1115. sortData[curRow][colSetting.field] = validText;
  1116. }
  1117. if (bPaste) {
  1118. data.push(materialMonthData);
  1119. } else {
  1120. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  1121. }
  1122. }
  1123. if (data.length === 0) {
  1124. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1125. return;
  1126. }
  1127. // console.log(data);
  1128. if (pasteOrigin) {
  1129. // 更新至服务器
  1130. postData(window.location.pathname + '/month/save', { type:'pasteOrigin', updateData: data }, function (result) {
  1131. SpreadJsObj.reLoadSheetData(materialMonthSpread.getActiveSheet());
  1132. materialBillsData = result.materialBillsData;
  1133. }, function () {
  1134. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1135. return;
  1136. });
  1137. } else {
  1138. // 更新至服务器
  1139. postData(window.location.pathname + '/month/save', { type:'paste', updateData: data }, function (result) {
  1140. SpreadJsObj.reLoadSheetData(materialMonthSpread.getActiveSheet());
  1141. materialBillsData = result.materialBillsData;
  1142. materialSpreadObj.materialSheetReset();
  1143. // SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
  1144. m_tp = result.m_tp;
  1145. if (materialTax) {
  1146. m_tax_tp = result.m_tax_tp;
  1147. }
  1148. resetTpTable();
  1149. }, function () {
  1150. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1151. return;
  1152. });
  1153. }
  1154. },
  1155. };
  1156. SpreadJsObj.initSpreadSettingEvents(materialSpreadSetting, materialCol);
  1157. SpreadJsObj.initSheet(materialSpread.getActiveSheet(), materialSpreadSetting);
  1158. materialSpreadObj.getMaterialBillsData();
  1159. SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
  1160. materialSpreadObj.refreshActn();
  1161. materialMonthSpread.bind(spreadNS.Events.ClipboardPasted, materialMonthSpreadObj.clipboardPasted);
  1162. SpreadJsObj.addDeleteBind(materialMonthSpread, materialMonthSpreadObj.deletePress);
  1163. materialMonthSpread.bind(spreadNS.Events.EditEnded, materialMonthSpreadObj.editEnded);
  1164. // 期切换
  1165. $('#myTab a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
  1166. e.preventDefault();
  1167. showWaitingView();
  1168. setTimeout(function () {
  1169. materialSpreadObj.getMaterialBillsData();
  1170. materialSpreadObj.materialSheetReset(true);
  1171. // SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
  1172. // 消耗量表格更新
  1173. let html = '';
  1174. calcBase = _.find(calcBaseList, { ms_id: $('#myTab').find('.active').data('msid') }).calcBase;
  1175. for (let iBase = 0; iBase < calcBase.length; iBase++) {
  1176. html += '<tr><td>' + calcBase[iBase].name + '</td><td>' + calcBase[iBase].code + '</td><td>' + calcBase[iBase].value + '</td></tr>';
  1177. }
  1178. $('#calcBase').html(html);
  1179. closeWaitingView();
  1180. }, 1000);
  1181. });
  1182. if (!readOnly || editForAudit) {
  1183. $('#expr_select button').on('click', function () {
  1184. const code = $(this).text();
  1185. // $('#expr').val($('#expr').val() + code);
  1186. $('#expr').insertAtCaret(code);
  1187. });
  1188. const ExprObj = {
  1189. _checkExprValid(expr, invalidParam) {
  1190. if (!expr) return [true, null];
  1191. const param = [];
  1192. let num = '', base = '';
  1193. for (let i = 0, iLen = expr.length; i < iLen; i++) {
  1194. if (/^[\d\.%]+/.test(expr[i])) {
  1195. if (base !== '') {
  1196. param.push({type: 'base', value: base});
  1197. base = '';
  1198. }
  1199. num = num + expr[i];
  1200. } else if (/^[a-z]/.test(expr[i])) {
  1201. if (num !== '') {
  1202. param.push({type: 'num', value: num});
  1203. num = '';
  1204. }
  1205. base = base + expr[i];
  1206. } else if (expr[i] === '(') {
  1207. if (num !== '') {
  1208. param.push({type: 'num', value: num});
  1209. num = '';
  1210. }
  1211. if (base !== '') {
  1212. param.push({type: 'base', value: base});
  1213. base = '';
  1214. }
  1215. param.push({type: 'left', value: '('});
  1216. } else if (expr[i] === ')') {
  1217. if (num !== '') {
  1218. param.push({type: 'num', value: num});
  1219. num = '';
  1220. }
  1221. if (base !== '') {
  1222. param.push({type: 'base', value: base});
  1223. base = '';
  1224. }
  1225. param.push({type: 'right', value: ')'});
  1226. } else if (/^[\+\-*\/]/.test(expr[i])) {
  1227. if (num !== '') {
  1228. param.push({type: 'num', value: num});
  1229. num = '';
  1230. }
  1231. if (base !== '') {
  1232. param.push({type: 'base', value: base});
  1233. base = '';
  1234. }
  1235. param.push({type: 'calc', value: expr[i]});
  1236. } else {
  1237. return [false, '输入的表达式含有非法字符: ' + expr[i]];
  1238. }
  1239. }
  1240. if (num !== '') {
  1241. param.push({type: 'num', value: num});
  1242. num = '';
  1243. }
  1244. if (base !== '') {
  1245. param.push({type: 'base', value: base});
  1246. base = '';
  1247. }
  1248. if (param.length === 0) return true;
  1249. if (param.length > 1) {
  1250. if (param[0].value === '-') {
  1251. param[1].value = '-' + param[1];
  1252. }
  1253. param.unshift();
  1254. }
  1255. const iLen = param.length;
  1256. let iLeftCount = 0, iRightCount = 0;
  1257. for (const [i, p] of param.entries()) {
  1258. if (p.type === 'calc') {
  1259. if (i === 0 || i === iLen - 1)
  1260. return [false, '输入的表达式非法:计算符号' + p.value + '前后应有数字或计算基数'];
  1261. }
  1262. if (p.type === 'num') {
  1263. num = p.value.replace('%', '');
  1264. if (p.value.length - num.length > 1)
  1265. return [false, '输入的表达式非法:' + p.value + '不是一个有效的数字'];
  1266. num = _.toNumber(num);
  1267. if (num === undefined || num === null || _.isNaN(num))
  1268. return [false, '输入的表达式非法:' + p.value + '不是一个有效的数字'];
  1269. if (i > 0) {
  1270. if (param[i - 1].type !== 'calc') {
  1271. return [false, '输入的表达式非法:' + p.value + '前应有运算符'];
  1272. } else if (param[i - 1].value === '/' && num === 0) {
  1273. return [false, '输入的表达式非法:请勿除0'];
  1274. }
  1275. }
  1276. }
  1277. if (p.type === 'base') {
  1278. const baseParam = _.find(calcBase, {code: p.value});
  1279. if (!baseParam)
  1280. return [false, '输入的表达式非法:不存在计算基数' + p.value];
  1281. if (invalidParam && invalidParam.indexOf(p.value) >= 0)
  1282. return [false, '不可使用计算基数' + p.value];
  1283. if (i > 0 && (param[i - 1].type === 'num' || param[i - 1].type === 'right'))
  1284. return [false, '输入的表达式非法:' + p.value + '前应有运算符'];
  1285. }
  1286. if (p.type === 'left') {
  1287. iLeftCount += 1;
  1288. if (i !== 0 && param[i-1].type !== 'calc')
  1289. return [false, '输入的表达式非法:(前应有运算符'];
  1290. }
  1291. if (p.type === 'right') {
  1292. iRightCount += 1;
  1293. if (i !== iLen - 1 && param[i+1].type !== 'calc')
  1294. return [false, '输入的表达式非法:)后应有运算符'];
  1295. if (iRightCount > iLeftCount)
  1296. return [false, '输入的表达式非法:")"前无对应的"("'];
  1297. }
  1298. }
  1299. if (iLeftCount > iRightCount)
  1300. return [false, '输入的表达式非法:"("后无对应的")"'];
  1301. return [true, ''];
  1302. },
  1303. _checkExpr: function (text) {
  1304. if (text) {
  1305. const num = _.toNumber(text);
  1306. if (num) {
  1307. console.log(num);
  1308. } else {
  1309. const expr = text.replace('=', '').toLowerCase();
  1310. const [valid, msg] = this._checkExprValid(expr);
  1311. if (!valid) return [valid, msg];
  1312. }
  1313. }
  1314. return [true, ''];
  1315. },
  1316. };
  1317. $('#expr_btn').click(function () {
  1318. const expr = $('#expr').val();
  1319. // 判断表达式格式
  1320. const [valid, msg] = ExprObj._checkExpr(expr);
  1321. if (!valid) {
  1322. toastr.error(msg);
  1323. return false;
  1324. }
  1325. postData(window.location.pathname + '/save', { type:'expr', id: $('#materialbillsId').val(), expr: expr, ms_id: $('#myTab').find('.active').data('msid') || null }, function (result) {
  1326. m_tp = result.m_tp;
  1327. if (materialTax) {
  1328. m_tax_tp = result.m_tax_tp;
  1329. }
  1330. const sheet = materialSpread.getActiveSheet();
  1331. const select = SpreadJsObj.getSelectObject(sheet);
  1332. const index = _.findIndex(materialBillsData, { id: select.id });
  1333. let newIndex = index;
  1334. if (isStageSelf) {
  1335. materialSpreadObj.updateMaterialData(result);
  1336. result.info = materialSpreadObj.updateOneMaterialBill(result.info);
  1337. }
  1338. if($('#bills0_list').is(':checked')) {
  1339. const newMaterialBillsData = _.filter(materialBillsData, function (item) {
  1340. return item.quantity !== null && item.quantity !== 0;
  1341. });
  1342. newIndex = newMaterialBillsData.indexOf(select);
  1343. newMaterialBillsData.splice(newIndex, 1, result.info);
  1344. sheet.zh_data[newIndex] = result.info;
  1345. }
  1346. materialBillsData.splice(index, 1, result.info);
  1347. sheet.zh_data.splice(newIndex, 1, result.info);
  1348. SpreadJsObj.reLoadRowData(sheet, newIndex);
  1349. resetTpTable();
  1350. $('#bcyy').modal('hide');
  1351. });
  1352. });
  1353. }
  1354. if (!readOnly && !editForAudit) {
  1355. $('#add').click(materialSpreadObj.add);
  1356. $('#del').click(materialSpreadObj.del);
  1357. $('#up-move').click(materialSpreadObj.upMove);
  1358. $('#down-move').click(materialSpreadObj.downMove);
  1359. // 右键菜单
  1360. $.contextMenu({
  1361. selector: '#material-spread',
  1362. build: function ($trigger, e) {
  1363. const target = SpreadJsObj.safeRightClickSelection($trigger, e, materialSpread);
  1364. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  1365. },
  1366. items: {
  1367. 'create': {
  1368. name: '新增材料',
  1369. icon: 'fa-sign-in',
  1370. callback: function (key, opt) {
  1371. materialSpreadObj.add(materialSpread.getActiveSheet());
  1372. },
  1373. },
  1374. 'delete': {
  1375. name: '删除材料',
  1376. icon: 'fa-remove',
  1377. callback: function (key, opt) {
  1378. materialSpreadObj.del(materialSpread.getActiveSheet());
  1379. },
  1380. disabled: function (key, opt) {
  1381. const sheet = materialSpread.getActiveSheet();
  1382. const select = SpreadJsObj.getSelectObject(sheet);
  1383. const sel = sheet.getSelections()[0];
  1384. materialSpreadObj.refreshActn(sel.rowCount);
  1385. if (!readOnly && select && materialBase.isUsed(select) && sel.rowCount === 1) {
  1386. return false;
  1387. } else {
  1388. return true;
  1389. }
  1390. }
  1391. },
  1392. }
  1393. });
  1394. $('.changeRate').click(function () {
  1395. $('#rateInput').val(parseInt($(this).data('value')));
  1396. $('#rateInput').siblings('.dropdown-menu').hide();
  1397. });
  1398. $('#rateInput').click(function () {
  1399. $(this).siblings('.dropdown-menu').show();
  1400. })
  1401. // 回车提交
  1402. $('#rateInput').on('keypress', function () {
  1403. if(window.event.keyCode === 13) {
  1404. $(this).blur();
  1405. }
  1406. });
  1407. $('#rateInput').blur(function () {
  1408. const _self = $(this);
  1409. setTimeout(function () {
  1410. let rate = parseFloat(_self.val());
  1411. if (_.isNaN(rate)) {
  1412. toastr.error('请输入0-100之前的整数值');
  1413. $('#rateInput').val(materialRate);
  1414. return;
  1415. }
  1416. rate = _.round(rate);
  1417. if(rate < 0 || rate > 100) {
  1418. toastr.error('请输入0-100之前的整数值');
  1419. $('#rateInput').val(materialRate);
  1420. return;
  1421. }
  1422. $('#rateInput').siblings('.dropdown-menu').hide();
  1423. console.log(rate, materialRate);
  1424. if (rate !== materialRate) {
  1425. postData(window.location.pathname + '/save', { type:'rate', rate: rate }, function (result) {
  1426. const bqhs = ZhCalc.round(ZhCalc.mul(m_tp, 1+rate/100), materialDecimal.tp);
  1427. // const exbqhs = ZhCalc.round(ZhCalc.mul(ex_tp, 1+rate/100), materialDecimal.tp);
  1428. const jzbqhs = ZhCalc.round(ZhCalc.add(pre_tp_hs, bqhs), materialDecimal.tp);
  1429. // const exjzbqhs = ZhCalc.round(ZhCalc.add(ex_pre_tp_hs, exbqhs), materialDecimal.tp);
  1430. $('#rate_set').find('td').eq(1).text(bqhs !== 0 ? bqhs : '');
  1431. $('#rate_set').find('td').eq(2).text(jzbqhs !== 0 ? jzbqhs : '');
  1432. // $('#rate_set').find('td').eq(3).text(exbqhs !== 0 ? exbqhs : '');
  1433. // $('#rate_set').find('td').eq(4).text(exjzbqhs !== 0 ? exjzbqhs : '');
  1434. materialRate = rate;
  1435. $('#rateInput').val(rate);
  1436. });
  1437. } else {
  1438. $('#rateInput').val(rate);
  1439. }
  1440. }, 500);
  1441. });
  1442. // $('#changeRate').change(function () {
  1443. // const rate = parseInt($(this).val());
  1444. // postData(window.location.pathname + '/save', { type:'rate', rate: rate }, function (result) {
  1445. // const bqhs = ZhCalc.round(ZhCalc.mul(m_tp, 1+rate/100), materialDecimal.tp);
  1446. // const exbqhs = ZhCalc.round(ZhCalc.mul(ex_tp, 1+rate/100), materialDecimal.tp);
  1447. // const jzbqhs = ZhCalc.round(ZhCalc.add(pre_tp_hs, bqhs), materialDecimal.tp);
  1448. // const exjzbqhs = ZhCalc.round(ZhCalc.add(ex_pre_tp_hs, exbqhs), materialDecimal.tp);
  1449. // $('#rate_set').find('td').eq(1).text(bqhs !== 0 ? bqhs : '');
  1450. // $('#rate_set').find('td').eq(2).text(jzbqhs !== 0 ? jzbqhs : '');
  1451. // $('#rate_set').find('td').eq(3).text(exbqhs !== 0 ? exbqhs : '');
  1452. // $('#rate_set').find('td').eq(4).text(exjzbqhs !== 0 ? exjzbqhs : '');
  1453. // });
  1454. // });
  1455. // 创建月信息价
  1456. $('#make-month').click(function() {
  1457. const yearmonth = $('#months').val();
  1458. const result = yearmonth.match(/^(\d{1,4})(-|\/)(\d{1,2})$/);
  1459. if (result === null) {
  1460. toastr.error('请选择正确的信息价月份');
  1461. return false;
  1462. }
  1463. //判断是否已存在当前月份
  1464. if (months.indexOf(yearmonth) !== -1) {
  1465. toastr.error('调差期已创建过本月的信息价');
  1466. return false;
  1467. }
  1468. postData(window.location.pathname + '/month/save', { type: 'add', updateData: { yearmonth: yearmonth } }, function (data) {
  1469. months.push(yearmonth);
  1470. months.sort();
  1471. monthsList = data.monthsList;
  1472. monthFunGather.monthsListSet();
  1473. // 工料表单价显示也要更新
  1474. materialBillsData = data.materialBillsData;
  1475. materialSpreadObj.materialSheetReset();
  1476. // SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
  1477. m_tp = data.m_tp;
  1478. if (materialTax) {
  1479. m_tax_tp = data.m_tax_tp;
  1480. }
  1481. resetTpTable();
  1482. $('#add-month').modal('hide');
  1483. });
  1484. });
  1485. // 删除月信息价
  1486. $('#del-month').click(function () {
  1487. const del_month_array = [];
  1488. $("input[name='del_month']:checked").each(function () {
  1489. del_month_array.push($(this).val());
  1490. });
  1491. if (del_month_array.length === 0) {
  1492. toastr.error('请选择要移除的月信息价');
  1493. return false;
  1494. }
  1495. postData(window.location.pathname + '/month/save', { type: 'del', updateData: { del_yearmonth: del_month_array } }, function (data) {
  1496. for (const dm of del_month_array) {
  1497. // _.remove(materialMonthSpreadSetting.cols, function (n) {
  1498. // return n.field === dm;
  1499. // });
  1500. _.remove(months, function (n) {
  1501. return n === dm;
  1502. });
  1503. }
  1504. monthsList = data.monthsList;
  1505. monthFunGather.monthsListSet();
  1506. // 工料表单价显示也要更新
  1507. materialBillsData = data.materialBillsData;
  1508. materialSpreadObj.materialSheetReset();
  1509. // SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
  1510. m_tp = data.m_tp;
  1511. if (materialTax) {
  1512. m_tax_tp = data.m_tax_tp;
  1513. }
  1514. resetTpTable();
  1515. $('#remove-month').modal('hide');
  1516. });
  1517. });
  1518. } else {
  1519. // SpreadJsObj.forbiddenSpreadContextMenu('#material-spread', materialSpread);
  1520. }
  1521. // 筛选调差工料本期应耗数量为0
  1522. $('#bills0_list').click(function () {
  1523. const isCheck = $(this).is(':checked');
  1524. let newMaterialBillsData = materialBillsData;
  1525. if (isCheck) {
  1526. newMaterialBillsData = _.filter(materialBillsData, function (item) {
  1527. return item.quantity !== null && item.quantity !== 0;
  1528. });
  1529. SpreadJsObj.initSpreadSettingEvents(materialSpreadSetting, materialCol);
  1530. SpreadJsObj.initSheet(materialSpread.getActiveSheet(), materialSpreadSetting);
  1531. }
  1532. SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, newMaterialBillsData);
  1533. monthFunGather.monthsListSet(newMaterialBillsData, false);
  1534. materialSpreadObj.refreshActn();
  1535. });
  1536. let gljLib;
  1537. const gljLibCellDoubleClick = function (e, info) {
  1538. if (readOnly || editForAudit) return;
  1539. const gljSheet = info.sheet;
  1540. if (!gljSheet.zh_setting || !gljSheet.zh_tree) { return; }
  1541. const gljTree = gljSheet.zh_tree;
  1542. const gljNode = gljTree.nodes[info.row];
  1543. const sheet = materialSpread.getActiveSheet();
  1544. const select = SpreadJsObj.getSelectObject(sheet);
  1545. if (!gljNode) return;
  1546. if (gljNode && gljNode.is_leaf === 0) {
  1547. toastr.warning('非最底层项目下,不应添加');
  1548. return;
  1549. }
  1550. postData(window.location.pathname + '/save', { type:'add-glj', postData: gljNode, order: select ? select.order : null }, function (result) {
  1551. if (result) {
  1552. // 比order大的+1
  1553. const maxData = select ? _.filter(materialBillsData, (item) => { return item.order > select.order }) : [];
  1554. _.forEach(maxData, function (item) {
  1555. const cl = _.find(materialBillsData, { id: item.id });
  1556. cl.order = item.order + 1;
  1557. });
  1558. materialBillsData.push(result.info);
  1559. materialBillsData.sort(function (a, b) {
  1560. return a.order - b.order
  1561. });
  1562. console.log(materialBillsData);
  1563. if (isStageSelf) {
  1564. materialSpreadObj.updateMaterialData(result);
  1565. materialSpreadObj.getMaterialBillsData();
  1566. }
  1567. // sheet.addRows(materialBillsData.length - 1, 1);
  1568. // SpreadJsObj.reLoadRowData(sheet, materialBillsData.length - 1);
  1569. let newMaterialBillsData = materialBillsData;
  1570. if($('#bills0_list').is(':checked')) {
  1571. newMaterialBillsData = _.filter(materialBillsData, function (item) {
  1572. return item.quantity !== null && item.quantity !== 0;
  1573. });
  1574. }
  1575. SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, newMaterialBillsData);
  1576. // materialSpreadObj.materialSheetReset();
  1577. sheet.setSelection(sheet.zh_data.indexOf(select) + 1, 0, 1, 1);
  1578. materialSpreadObj.refreshActn();
  1579. // 月信息价需要同时添加空白的list
  1580. if (months.length > 0) {
  1581. 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 };
  1582. for (const m of months) {
  1583. one_month[m] = null;
  1584. }
  1585. _.forEach(maxData, function (item) {
  1586. const cl = _.find(monthsList, { mb_id: item.id });
  1587. cl.order = item.order + 1;
  1588. });
  1589. monthsList.push(one_month);
  1590. monthsList.sort(function (a, b) {
  1591. return a.order - b.order
  1592. });
  1593. console.log(monthsList);
  1594. // const newMonthsList = _.filter(monthsList, function (item) {
  1595. // return _.findIndex(newMaterialBillsData, { code: item.code }) !== -1;
  1596. // });
  1597. // materialMonthSpread.getActiveSheet().addRows(newMonthsList.length - 1, 1);
  1598. // SpreadJsObj.reLoadRowData(materialMonthSpread.getActiveSheet(), newMonthsList.length - 1);
  1599. monthFunGather.monthsListSet();
  1600. // materialMonthSpreadObj.monthsListSet();
  1601. }
  1602. }
  1603. });
  1604. };
  1605. const gljLibSetting = {
  1606. selector: '#material-tab',
  1607. stdType: 'glj',
  1608. libs: gljLists,
  1609. treeSetting: {
  1610. id: 'glj_id',
  1611. pid: 'glj_pid',
  1612. order: 'order',
  1613. level: 'level',
  1614. rootId: -1,
  1615. keys: ['id', 'list_id', 'glj_id'],
  1616. },
  1617. spreadSetting: {
  1618. cols: [
  1619. {title: '编号', field: 'code', hAlign: 0, width: 120, formatter: '@', readOnly: true, cellType: 'tree'},
  1620. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  1621. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true},
  1622. {title: '参考上涨幅度', field: 'rise_range', hAlign: 1, width: 50, formatter: '@', readOnly: true},
  1623. {title: '参考下跌幅度', field: 'fall_range', hAlign: 1, width: 50, formatter: '@', readOnly: true},
  1624. ],
  1625. treeCol: 0,
  1626. emptyRows: 0,
  1627. headRows: 1,
  1628. headRowHeight: [32],
  1629. defaultRowHeight: 21,
  1630. headerFont: '12px 微软雅黑',
  1631. font: '12px 微软雅黑',
  1632. headColWidth: [30],
  1633. selectedBackColor: '#fffacd',
  1634. },
  1635. spreadClassCss: 'sjs-material',
  1636. cellDoubleClick: gljLibCellDoubleClick,
  1637. page: 'material',
  1638. tid: window.location.pathname.split('/')[2],
  1639. };
  1640. $.subMenu({
  1641. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  1642. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  1643. key: 'menu.1.0.0',
  1644. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  1645. callback: function (info) {
  1646. if (info.mini) {
  1647. $('.panel-title').addClass('fluid');
  1648. $('#sub-menu').removeClass('panel-sidebar');
  1649. } else {
  1650. $('.panel-title').removeClass('fluid');
  1651. $('#sub-menu').addClass('panel-sidebar');
  1652. }
  1653. autoFlashHeight();
  1654. materialSpread.refresh();
  1655. }
  1656. });
  1657. $.divResizer({
  1658. select: '#right-spr',
  1659. callback: function () {
  1660. materialSpread.refresh();
  1661. materialMonthSpread.refresh();
  1662. if (gljLib) gljLib.spread.refresh();
  1663. const width = (($('#right-view').width()/$('#right-view').parent('div').width())*100).toFixed();
  1664. setLocalCache('material_month_' + materialID, width);
  1665. }
  1666. });
  1667. $.divResizer({
  1668. select: '#main-resize',
  1669. callback: function () {
  1670. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  1671. $(".sp-wrap").height(bcontent-30);
  1672. const height = $('.bcontent-wrap').height();
  1673. const cutHeight = isStageSelf ? getObjHeight($('#myTab')) : 0;
  1674. $('.sjs-height-material').height($('.sjs-height-1').height() - cutHeight);
  1675. updateSjsHeight();
  1676. materialSpread.refresh();
  1677. materialMonthSpread.refresh();
  1678. if (gljLib) gljLib.spread.refresh();
  1679. setLocalCache('material_bills_' + materialID, height);
  1680. }
  1681. });
  1682. // 展开收起月信息价并浏览器记住本期展开收起
  1683. $('a', '.right-nav').bind('click', function () {
  1684. //const main = $('#main-view'), tool = $('#tools-view');
  1685. const tab = $(this), tabPanel = $(tab.attr('content'));
  1686. if (!tab.hasClass('active')) {
  1687. $('a', '.side-menu').removeClass('active');
  1688. $('.tab-content .tab-pane').removeClass('active');
  1689. tab.addClass('active');
  1690. tabPanel.addClass('active');
  1691. showSideTools(tab.hasClass('active'));
  1692. if (tab.attr('content') === '#month-tab') {
  1693. const width = (($('#right-view').width()/$('#right-view').parent('div').width())*100).toFixed();
  1694. setLocalCache('material_month_' + materialID, width);
  1695. materialMonthSpread.refresh();
  1696. } else if (tab.attr('content') === '#material-tab') {
  1697. if (!gljLib) {
  1698. gljLib = $.gljLib(gljLibSetting);
  1699. }
  1700. updateSjsHeight();
  1701. gljLib.spread.refresh();
  1702. }
  1703. } else {
  1704. removeLocalCache('material_month_' + materialID);
  1705. tab.removeClass('active');
  1706. tabPanel.removeClass('active');
  1707. showSideTools(tab.hasClass('active'));
  1708. }
  1709. materialSpread.refresh();
  1710. // materialMonthSpread.refresh();
  1711. });
  1712. // 根据浏览器记录展开收起
  1713. if (getLocalCache('material_month_' + materialID) && !isStageSelf) {
  1714. const tab = $('.right-nav a[content="#month-tab"]'), tabPanel = $(tab.attr('content'));
  1715. $('a', '.side-menu').removeClass('active');
  1716. $('.tab-content .tab-pane').removeClass('active');
  1717. tab.addClass('active');
  1718. tabPanel.addClass('active');
  1719. $('#right-view').width(getLocalCache('material_month_' + materialID) + '%');
  1720. showSideTools(tab.hasClass('active'));
  1721. materialSpread.refresh();
  1722. materialMonthSpread.refresh();
  1723. }
  1724. const cutHeight = isStageSelf ? getObjHeight($('#myTab')) : 0;
  1725. if (getLocalCache('material_bills_' + materialID)) {
  1726. $('.bcontent-wrap').height(getLocalCache('material_bills_' + materialID));
  1727. const cHeader = getObjHeight($(".c-header"));
  1728. const bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  1729. $(".sp-wrap").height(bcontent-30);
  1730. $('.sjs-height-1').height($(window).height()-cHeader-bcontent-90+53);
  1731. $('.sjs-height-material').height($('.sjs-height-1').height() - cutHeight);
  1732. updateSjsHeight();
  1733. materialSpread.refresh();
  1734. materialMonthSpread.refresh();
  1735. if (gljLib) gljLib.spread.refresh();
  1736. } else {
  1737. $('.sjs-height-material').height($('.sjs-height-1').height() - cutHeight);
  1738. updateSjsHeight();
  1739. materialSpread.refresh();
  1740. materialMonthSpread.refresh();
  1741. if (gljLib) gljLib.spread.refresh();
  1742. }
  1743. function updateSjsHeight() {
  1744. $('.sjs-height-material-month').height($('.sjs-height-1').height() - getObjHeight($('.sjs-bar-1')));
  1745. $('.material-table-height').height($('.bcontent-wrap').height() - getObjHeight($('.bc-bar')));
  1746. $('.sjs-material').height($('.sjs-height-1').height() - getObjHeight($('.sjs-bar')));
  1747. }
  1748. function getObjHeight(select) {
  1749. return select.length > 0 ? select.height() : 0;
  1750. }
  1751. });