change_apply_information.js 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author EllisRan
  6. * @date 2022/01/21
  7. * @version
  8. */
  9. $(document).ready(() => {
  10. $.subMenu({
  11. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  12. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  13. key: 'menu.1.0.0',
  14. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  15. callback: function (info) {
  16. if (info.mini) {
  17. $('.panel-title').addClass('fluid');
  18. $('#sub-menu').removeClass('panel-sidebar');
  19. } else {
  20. $('.panel-title').removeClass('fluid');
  21. $('#sub-menu').addClass('panel-sidebar');
  22. }
  23. autoFlashHeight();
  24. }
  25. });
  26. handleFileList(fileList);
  27. $('#file-ok').click(function () {
  28. const files = Array.from($('#file-modal')[0].files)
  29. const valiData = files.map(v => {
  30. const ext = v.name.substring(v.name.lastIndexOf('.') + 1)
  31. return {
  32. size: v.size,
  33. ext
  34. }
  35. });
  36. console.log(!$('#addfujian input[name="type"]:checked').val());
  37. if (!$('#addfujian input[name="type"]:checked').val()) {
  38. toastr.error('请选择资料类型');
  39. return false;
  40. }
  41. if (validateFiles(valiData)) {
  42. if (files.length) {
  43. const formData = new FormData();
  44. formData.append('type', $('#addfujian input[name="type"]:checked').val());
  45. files.forEach(file => {
  46. formData.append('name', file.name);
  47. formData.append('size', file.size);
  48. formData.append('file', file);
  49. })
  50. postDataWithFile(preUrl + '/file/upload', formData, function (result) {
  51. handleFileList(result);
  52. $('#file-cancel').click();
  53. });
  54. }
  55. }
  56. })
  57. function handleFileList(files = []) {
  58. $('#file-content').empty();
  59. // const { uncheck, checkNo } = auditConst.status
  60. const newFiles = files.map(file => {
  61. let showDel = false;
  62. if (file.uid === cur_uid) {
  63. // if (!curAuditor) {
  64. // advance.status === uncheck && cur_uid === advance.uid && (showDel = true)
  65. // advance.status === checkNo && cur_uid === advance.uid && (showDel = true)
  66. // } else {
  67. // curAuditor.audit_id === cur_uid && (showDel = true)
  68. // }
  69. if (change.status === auditConst.status.checked) {
  70. showDel = Boolean(file.extra_upload ) || deleteFilePermission
  71. } else {
  72. showDel = true
  73. }
  74. }
  75. return {...file, showDel}
  76. })
  77. let html = change.filePermission ? `<tr><td colspan="6"><a href="#addfujian" data-toggle="modal" class="btn btn-primary btn-sm" data-placement="bottom" title="">上传附件</a></td></tr>` : '';
  78. newFiles.forEach((file, idx) => {
  79. if (file.showDel) {
  80. html += `<tr><td>${idx + 1}</td><td><a href="${file.filepath}" target="_blank">${file.filename}</a></td><td>${file.username}</td><td>${file.type ? _.find(fileTypeConst, {key: file.type }).value : ''}</td><td>${moment(file.upload_time).format('YYYY-MM-DD HH:mm:ss')}</td><td><a href="/tender/${file.tid}/change/apply/${file.caid}/information/file/${file.id}/download" class="mr-2"><i class="fa fa-download"></i></a><a href="javascript: void(0);" class="text-danger file-del" data-id="${file.id}"><i class="fa fa-remove"></i></a></td></tr>`
  81. } else {
  82. html += `<tr><td width="70">${idx + 1}</td><td><a href="${file.filepath}" target="_blank">${file.filename}</a></td><td>${file.username}</td><td>${file.type ? _.find(fileTypeConst, {key: file.type }).value : ''}</td><td>${moment(file.upload_time).format('YYYY-MM-DD HH:mm:ss')}</td><td><a href="/tender/${file.tid}/change/apply/${file.caid}/information/file/${file.id}/download" class="mr-2"><i class="fa fa-download"></i></a></td></tr>`
  83. }
  84. })
  85. $('#file-content').append(html);
  86. }
  87. $('#file-content').on('click', 'a', function () {
  88. if ($(this).hasClass('file-del')) {
  89. const id = $(this).data('id');
  90. postData(preUrl + '/file/delete', {id}, (result) => {
  91. handleFileList(result);
  92. })
  93. }
  94. });
  95. // 回车提交
  96. $('#apply-table input').on('keypress', function () {
  97. if(window.event.keyCode === 13) {
  98. $(this).blur();
  99. }
  100. });
  101. $('#apply-table input').blur(function () {
  102. const val_name = $(this).data('name');
  103. let val = _.trim($(this).val()) !== '' ? _.trim($(this).val()) : null;
  104. switch(val_name) {
  105. case 'code':
  106. if(!val) {
  107. toastr.error('申请编号不能为空');
  108. $(this).val(change[val_name]);
  109. return false;
  110. }
  111. break;
  112. case 'name':
  113. if(val && val.length > 100) {
  114. toastr.error('名称超过100个字,请缩减名称');
  115. $(this).val(change[val_name]);
  116. return false;
  117. }
  118. break;
  119. case 'org_price':
  120. case 'change_price':
  121. case 'crease_price':
  122. val = val ? parseFloat(val) : null;
  123. if(val && !_.isNumber(val)) {
  124. toastr.error('请输入数字');
  125. $(this).val(change[val_name]);
  126. return false;
  127. }
  128. break;
  129. default:
  130. if(val && val.length > 255) {
  131. toastr.error('超出字段范围,请缩减');
  132. $(this).val(change[val_name]);
  133. return false;
  134. }
  135. break;
  136. }
  137. if(change[val_name] !== val) {
  138. const _self = $(this);
  139. postData(preUrl + '/save', { name: val_name, val}, function (result) {
  140. change[val_name] = val;
  141. _self.val(change[val_name]);
  142. if (val_name === 'code') {
  143. $('#change-apply-code').text(change[val_name]);
  144. }
  145. }, function () {
  146. _self.val(change[val_name]);
  147. })
  148. } else {
  149. $(this).val(change[val_name]);
  150. }
  151. });
  152. $('#apply-table textarea').blur(function () {
  153. const val_name = $(this).data('name');
  154. let val = _.trim($(this).val()) !== '' ? _.trim($(this).val()) : null;
  155. if(change[val_name] !== val) {
  156. const _self = $(this);
  157. postData(preUrl + '/save', { name: val_name, val}, function (result) {
  158. change[val_name] = val;
  159. _self.val(change[val_name]);
  160. }, function () {
  161. _self.val(change[val_name]);
  162. })
  163. } else {
  164. $(this).val(change[val_name]);
  165. }
  166. });
  167. $('#apply-table select').change(function () {
  168. const val_name = $(this).attr('data-name');
  169. let val = _.trim($(this).val()) !== '' ? _.trim($(this).val()) : null;
  170. if(change[val_name] !== val) {
  171. const _self = $(this);
  172. postData(preUrl + '/save', { name: val_name, val}, function (result) {
  173. change[val_name] = val;
  174. _self.val(change[val_name]);
  175. }, function () {
  176. _self.val(change[val_name]);
  177. })
  178. } else {
  179. $(this).val(change[val_name]);
  180. }
  181. });
  182. const changeSpread = SpreadJsObj.createNewSpread($('#apply-spread')[0]);
  183. const changeSpreadSheet = changeSpread.getActiveSheet();
  184. const style1 = new GC.Spread.Sheets.Style();
  185. style1.locked = true;
  186. const changeSpreadSetting = {
  187. cols: [
  188. {title: '新增单价', colSpan: '1', rowSpan: '2', field: 'new_up', hAlign: 1, width: 35, cellType: 'checkbox', readOnly: 'readOnly.isEdit'},
  189. {title: '清单编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 110, formatter: '@', readOnly: 'readOnly.isEdit'},
  190. {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 130, formatter: '@', readOnly: 'readOnly.isEdit'},
  191. {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 60, formatter: '@', readOnly: 'readOnly.isEdit', cellType: 'unit', comboItems: changeUnits, comboEdit: true},
  192. {title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.isEdit', getValue: 'getValue.unit_price'},
  193. {title: '原设计|数量', colSpan: '2|1', rowSpan: '1|1', field: 'oamount', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.isEdit', getValue: 'getValue.oamount'},
  194. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'oa_tp', hAlign: 2, width: 80, type: 'Number', readOnly: true, getValue: 'getValue.oa_tp'},
  195. {title: '申请变更增(+)减(-)|数量', colSpan: '2|1', rowSpan: '1|1', field: 'camount', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.isEdit', getValue: 'getValue.camount'},
  196. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'ca_tp', hAlign: 2, width: 80, type: 'Number', readOnly: true, getValue: 'getValue.ca_tp'},
  197. {title: '备注1', colSpan: '1', rowSpan: '2', field: 'ex_memo1', hAlign: 0, width: 110, formatter: '@', readOnly: 'readOnly.isEdit2', cellType: 'ellipsisAutoTip', scrollHeightClass: '.sjs-height-0'},
  198. {title: '备注2', colSpan: '1', rowSpan: '2', field: 'ex_memo2', hAlign: 0, width: 110, formatter: '@', readOnly: 'readOnly.isEdit2', cellType: 'ellipsisAutoTip', scrollHeightClass: '.sjs-height-0'},
  199. ],
  200. emptyRows: !readOnly ? 3 : 0,
  201. headRows: 2,
  202. headRowHeight: [25, 25],
  203. defaultRowHeight: 21,
  204. headerFont: '12px 微软雅黑',
  205. font: '12px 微软雅黑',
  206. readOnly: change.status === auditConst.status.checking ? false : readOnly,
  207. localCache: {
  208. key: 'changes-apply-list-spread',
  209. colWidth: true,
  210. }
  211. };
  212. console.log(changeList);
  213. const changeCol = {
  214. getValue: {
  215. unit_price: function(data) {
  216. return ZhCalc.round(data.unit_price, unitPriceUnit);
  217. },
  218. oa_tp: function (data) {
  219. return ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), ZhCalc.round(data.oamount, findDecimal(data.unit))), totalPriceUnit);
  220. },
  221. ca_tp: function (data) {
  222. return ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), ZhCalc.round(data.camount, findDecimal(data.unit))), totalPriceUnit);
  223. },
  224. oamount: function (data) {
  225. return ZhCalc.round(data.oamount, findDecimal(data.unit));
  226. },
  227. camount: function (data) {
  228. return ZhCalc.round(data.camount, findDecimal(data.unit));
  229. },
  230. },
  231. readOnly: {
  232. isEdit: function (data) {
  233. return readOnly;
  234. },
  235. isEdit2: function (data) {
  236. return !(!readOnly || change.shenpiPower);
  237. },
  238. },
  239. };
  240. const changeSpreadObj = {
  241. makeSjsFooter: function() {
  242. // 增加汇总行并设为锁定禁止编辑状态
  243. changeSpreadSheet.addRows(changeSpreadSheet.getRowCount(), 1);
  244. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 0, '合计');
  245. const cellType1 = new GC.Spread.Sheets.CellTypes.Text();
  246. changeSpreadSheet.getCell(changeSpreadSheet.getRowCount() - 1, 0).cellType(cellType1);
  247. changeSpreadSheet.setStyle(changeSpreadSheet.getRowCount() - 1, -1, style1);
  248. changeSpreadObj.countSum();
  249. },
  250. countSum: function() {
  251. const rowCount = changeSpreadSheet.getRowCount();
  252. let oSum = 0,
  253. cSum = 0;
  254. for (let i = 0; i < rowCount - 1; i++) {
  255. oSum = ZhCalc.add(oSum, changeSpreadSheet.getValue(i, 6));
  256. cSum = ZhCalc.add(cSum, changeSpreadSheet.getValue(i, 8));
  257. }
  258. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 6, oSum !== 0 ? oSum : null);
  259. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 8, cSum !== 0 ? cSum : null);
  260. },
  261. deletePress: function (sheet) {
  262. return;
  263. },
  264. valueChanged: function (e, info) {
  265. // 防止ctrl+z撤销数据
  266. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  267. }
  268. };
  269. if (!readOnly) {
  270. changeSpreadObj.add = function () {
  271. changeSpreadSheet.addRows(changeSpreadSheet.getRowCount() - 1, 1);
  272. changeSpreadSheet.setStyle(changeSpreadSheet.getRowCount() - 1, -1, style1);
  273. // changeSpreadSheet.setSelection(changeList.length - 1, 0, 1, 1);
  274. };
  275. changeSpreadObj.batchAdd = function (num) {
  276. changeSpreadSheet.addRows(changeSpreadSheet.getRowCount() - 1, parseInt(num));
  277. changeSpreadSheet.setStyle(changeSpreadSheet.getRowCount() - 1, -1, style1);
  278. };
  279. changeSpreadObj.del = function (sheet) {
  280. const selection = sheet.getSelections();
  281. const row = selection[0].row, count = selection[0].rowCount;
  282. const sortData = sheet.zh_data;
  283. const ids = [];
  284. let emptyRowNum = 0;
  285. for (let iRow = 0; iRow < count; iRow++) {
  286. if (sortData[iRow + row]) {
  287. ids.push(sortData[iRow + row].id);
  288. } else {
  289. emptyRowNum++;
  290. }
  291. }
  292. if (ids.length > 0) {
  293. postData(preUrl + '/list/save', {type: 'del', ids}, function (result) {
  294. changeList = result;
  295. SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
  296. changeSpreadObj.makeSjsFooter();
  297. });
  298. } else if (emptyRowNum > 0) {
  299. changeSpreadSheet.deleteRows(changeList.length, emptyRowNum);
  300. changeSpreadSheet.setSelection(changeList.length - 1, 0, 1, 1);
  301. }
  302. };
  303. changeSpreadObj.editEnded = function (e, info) {
  304. if (info.sheet.zh_setting) {
  305. const type = SpreadJsObj.getSelectObject(info.sheet) ? 'update' : 'add';
  306. const select = type === 'update' ? SpreadJsObj.getSelectObject(info.sheet) : {unit: ''};
  307. const col = info.sheet.zh_setting.cols[info.col];
  308. if (col.field === 'new_up') return;
  309. // 未改变值则不提交
  310. let validText = (col.type === 'Number' || col.field === 'new_up') && is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : '');
  311. const orgValue = type === 'update' ? select[col.field] : '';
  312. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  313. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  314. return;
  315. }
  316. if (col.field === 'oa_tp' || col.field === 'ca_tp') {
  317. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  318. return;
  319. }
  320. // 判断部分值是否输入的是数字判断和数据计算
  321. if (col.type === 'Number') {
  322. if (isNaN(validText)) {
  323. toastr.error('不能输入其它非数字类型字符');
  324. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  325. return;
  326. }
  327. if (col.field === 'unit_price') {
  328. validText = ZhCalc.round(validText, unitPriceUnit);
  329. } else {
  330. validText = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
  331. }
  332. }
  333. if (col.field === 'unit') {
  334. select.camount = ZhCalc.round(select.camount, findDecimal(validText)) || 0;
  335. select.oamount = ZhCalc.round(select.oamount, findDecimal(validText)) || 0;
  336. }
  337. select[col.field] = validText;
  338. console.log(select, type);
  339. delete select.waitingLoading;
  340. // 更新至服务器
  341. postData(preUrl + '/list/save', { type, updateData: select }, function (result) {
  342. if(type === 'update') {
  343. changeList.splice(info.row, 1, select);
  344. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  345. changeSpreadObj.countSum();
  346. } else {
  347. changeList.push(result);
  348. changeSpreadSheet.addRows(changeList.length - 1, 1);
  349. SpreadJsObj.reLoadRowData(changeSpreadSheet, changeList.length - 1);
  350. changeSpreadSheet.setStyle(changeSpreadSheet.getRowCount() - 1, -1, style1);
  351. // changeSpreadSheet.setSelection(changeList.length - 1, 0, 1, 1);
  352. }
  353. }, function () {
  354. select[col.field] = orgValue;
  355. if(col.field === 'camount') {
  356. select.spamount = orgValue;
  357. }
  358. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  359. });
  360. }
  361. };
  362. changeSpreadObj.clipboardPasted = function(e, info, cellRange) {
  363. if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
  364. info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
  365. }
  366. const hint = {
  367. cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
  368. numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
  369. };
  370. if (info.sheet.zh_setting) {
  371. const sortData = info.sheet.zh_data || [];
  372. const range = info.cellRange;
  373. const data = [];
  374. let haveNew = false;
  375. for (let iRow = 0; iRow < range.rowCount; iRow++) {
  376. let bPaste = true;
  377. const curRow = range.row + iRow;
  378. // const materialData = JSON.parse(JSON.stringify(sortData[curRow]));
  379. const cLData = curRow >= sortData.length ? {unit: ''} : {id: sortData[curRow].id};
  380. haveNew = curRow >= sortData.length ? curRow : false;
  381. const hintRow = range.rowCount > 1 ? curRow : '';
  382. let sameCol = 0;
  383. for (let iCol = 0; iCol < range.colCount; iCol++) {
  384. const curCol = range.col + iCol;
  385. const colSetting = info.sheet.zh_setting.cols[curCol];
  386. if (!colSetting) continue;
  387. // cLData[colSetting.field] = trimInvalidChar(info.sheet.getText(curRow, curCol));
  388. let validText = info.sheet.getText(curRow, curCol);
  389. validText = (colSetting.type === 'Number' || colSetting.field === 'new_up') && is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : '');
  390. const orgValue = curRow >= sortData.length ? '' : sortData[curRow][colSetting.field];
  391. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  392. sameCol++;
  393. if (range.colCount === sameCol) {
  394. bPaste = false;
  395. }
  396. continue;
  397. }
  398. if (colSetting.type === 'Number') {
  399. if (isNaN(validText)) {
  400. // toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
  401. toastMessageUniq(hint.numberExpr);
  402. bPaste = false;
  403. continue;
  404. }
  405. if (colSetting.field === 'unit_price') {
  406. validText = ZhCalc.round(validText, unitPriceUnit);
  407. } else {
  408. validText = ZhCalc.round(validText, findDecimal(cLData.unit)) || 0;
  409. }
  410. }
  411. let unitdecimal = validText;
  412. if (colSetting.field === 'unit') {
  413. //粘贴内容要为下拉列表里所有的单位,不然为空
  414. if (changeUnits.indexOf(validText) === -1) {
  415. unitdecimal = '';
  416. // validText = null;
  417. }
  418. cLData.camount = curRow >= sortData.length ? 0 : ZhCalc.round(sortData[curRow].camount, findDecimal(unitdecimal)) || 0;
  419. cLData.oamount = curRow >= sortData.length ? 0 : ZhCalc.round(sortData[curRow].oamount, findDecimal(unitdecimal)) || 0;
  420. }
  421. cLData[colSetting.field] = validText;
  422. }
  423. if (bPaste) {
  424. delete cLData.oa_tp;
  425. delete cLData.ca_tp;
  426. data.push(cLData);
  427. // rowData.push(curRow);
  428. } else {
  429. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  430. }
  431. }
  432. if (data.length === 0) {
  433. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  434. return;
  435. }
  436. console.log(data);
  437. // 更新至服务器
  438. postData(preUrl + '/list/save', { type:'paste', updateData: data }, function (result) {
  439. changeList = result;
  440. SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
  441. changeSpreadObj.makeSjsFooter();
  442. }, function () {
  443. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  444. return;
  445. });
  446. }
  447. };
  448. changeSpreadObj.updateOamount = function () {
  449. const dataSource = listRule.source === 1 ? gclGatherData : dealBillList;
  450. const updateList = [];
  451. for (const c of changeList) {
  452. const source = _.find(dataSource, function (item) {
  453. if (((item.b_code && item.b_code === c.code) || (item.code && item.code === c.code)) && item.name === c.name) {
  454. if (listRule.rule.length > 0) {
  455. for(const r of listRule.rule) {
  456. if (item[r] !== c[r]) {
  457. return false;
  458. }
  459. }
  460. }
  461. return true;
  462. }
  463. return false;
  464. });
  465. if (source && source.quantity !== c.oamount) {
  466. updateList.push({ id: c.id, oamount: source.quantity });
  467. }
  468. }
  469. console.log(updateList);
  470. if(updateList.length > 0) {
  471. postData(preUrl + '/list/save', { type:'paste', updateData: updateList }, function (result) {
  472. changeList = result;
  473. SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
  474. changeSpreadObj.makeSjsFooter();
  475. });
  476. }
  477. };
  478. changeSpreadObj.buttonClicked = function (e, info) {
  479. if (info.sheet.zh_setting) {
  480. const select = SpreadJsObj.getSelectObject(info.sheet);
  481. const col = info.sheet.zh_setting.cols[info.col];
  482. if(!select) {
  483. toastr.error('请添加清单编号再勾选');
  484. if (info.sheet.isEditing()) {
  485. info.sheet.endEdit(true);
  486. }
  487. return;
  488. } else if (col.field === 'new_up') {
  489. if (info.sheet.isEditing()) {
  490. info.sheet.endEdit(true);
  491. }
  492. select.new_up = info.sheet.getValue(info.row, info.col) ? 0 : 1;
  493. postData(preUrl + '/list/save', { type: 'update', updateData: { id: select.id, new_up: select.new_up } }, function (result) {
  494. changeList.splice(info.row, 1, select);
  495. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  496. changeSpreadObj.countSum();
  497. }, function () {
  498. select.new_up = info.sheet.getValue(info.row, info.col) ? 1 : 0;
  499. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  500. });
  501. }
  502. }
  503. };
  504. // changeSpread.bind(spreadNS.Events.CellChanged, changeSpreadObj.cellChanged);
  505. changeSpread.bind(spreadNS.Events.EditEnded, changeSpreadObj.editEnded);
  506. changeSpread.bind(spreadNS.Events.ButtonClicked, changeSpreadObj.buttonClicked);
  507. changeSpread.bind(spreadNS.Events.ClipboardPasted, changeSpreadObj.clipboardPasted);
  508. changeSpread.bind(spreadNS.Events.ValueChanged, changeSpreadObj.valueChanged);
  509. SpreadJsObj.addDeleteBind(changeSpread, changeSpreadObj.deletePress);
  510. let batchInsertObj;
  511. $.contextMenu.types.batchInsert = function (item, opt, root) {
  512. const self = this;
  513. if ($.isFunction(item.icon)) {
  514. item._icon = item.icon.call(this, this, $t, key, item);
  515. } else {
  516. if (typeof(item.icon) === 'string' && item.icon.substring(0, 3) === 'fa-') {
  517. // to enable font awesome
  518. item._icon = root.classNames.icon + ' ' + root.classNames.icon + '--fa fa ' + item.icon;
  519. } else {
  520. item._icon = root.classNames.icon + ' ' + root.classNames.icon + '-' + item.icon;
  521. }
  522. }
  523. this.addClass(item._icon);
  524. const $obj = $('<div>' + item.name + '<input class="text-right ml-1 mr-1" type="tel" max="100" min="1" value="' + item.value + '" style="width: 30px; height: 18px; padding-right: 4px;">行</div>')
  525. .appendTo(this);
  526. const $input = $obj.find('input');
  527. const event = () => {
  528. if (self.hasClass('context-menu-disabled')) return;
  529. item.batchInsert($input[0], root);
  530. };
  531. $obj.on('click', event).keypress(function (e) {if (e.keyCode === 13) { event(); }});
  532. $input.click((e) => {e.stopPropagation();})
  533. .keyup((e) => {if (e.keyCode === 13) item.batchInsert($input[0], root);})
  534. .on('input', function () {this.value = this.value.replace(/[^\d]/g, '');});
  535. };
  536. // 右键菜单
  537. $.contextMenu({
  538. selector: '#apply-spread',
  539. build: function ($trigger, e) {
  540. const target = SpreadJsObj.safeRightClickSelection($trigger, e, changeSpread);
  541. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  542. },
  543. items: {
  544. 'updateOamount': {
  545. name: '原设计数量读取',
  546. icon: '',
  547. callback: function (key, opt) {
  548. changeSpreadObj.updateOamount(changeSpreadSheet);
  549. },
  550. disabled: function (key, opt) {
  551. const select = SpreadJsObj.getSelectObject(changeSpreadSheet);
  552. const sel = changeSpreadSheet.getSelections()[0];
  553. // console.log(select, sel);
  554. if (!readOnly && select && sel.row !== changeSpreadSheet.getRowCount() - 1) {
  555. return false;
  556. } else {
  557. return true;
  558. }
  559. }
  560. },
  561. sprDel: '------------',
  562. 'createAdd': {
  563. name: '添加行',
  564. icon: 'fa-sign-in',
  565. callback: function (key, opt) {
  566. changeSpreadObj.add(changeSpreadSheet);
  567. },
  568. },
  569. 'batchInsert': {
  570. name: '批量添加行',
  571. type: 'batchInsert',
  572. value: '2',
  573. icon: 'fa-sign-in',
  574. batchInsert: function (obj, root) {
  575. if (_.toNumber(obj.value) > _.toNumber(obj.max)) {
  576. obj.value = obj.max;
  577. toastr.warning('批量添加不可多于' + obj.max);
  578. } else if(_.toNumber(obj.value) < _.toNumber(obj.min)) {
  579. obj.value = obj.min;
  580. toastr.warning('批量添加不可少于' + obj.min);
  581. } else {
  582. // treeOperationObj.addNode(ledgerSpread.getActiveSheet(), parseInt(obj.value));
  583. changeSpreadObj.batchAdd(obj.value);
  584. root.$menu.trigger('contextmenu:hide');
  585. }
  586. },
  587. },
  588. 'delete': {
  589. name: '删除',
  590. icon: 'fa-remove',
  591. callback: function (key, opt) {
  592. changeSpreadObj.del(changeSpreadSheet);
  593. },
  594. disabled: function (key, opt) {
  595. // const select = SpreadJsObj.getSelectObject(changeSpreadSheet);
  596. if (changeSpreadSheet.zh_data) {
  597. const selection = changeSpreadSheet.getSelections();
  598. // return changeSpreadSheet.zh_data.length < selection[0].row + selection[0].rowCount;
  599. return changeSpreadSheet.getRowCount() - 1 < selection[0].row + selection[0].rowCount;
  600. } else {
  601. return true;
  602. }
  603. // const sel = changeSpreadSheet.getSelections()[0];
  604. // // console.log(select, sel);
  605. // if (!readOnly && select && sel.row !== changeSpreadSheet.getRowCount() - 1) {
  606. // return false;
  607. // } else {
  608. // return true;
  609. // }
  610. }
  611. },
  612. }
  613. });
  614. $('#shuliangguize').on('show.bs.modal', function () {
  615. $('#shuliangguize input[name="data_source"][value="'+ listRule.source +'"]').prop('checked', true);
  616. $('#shuliangguize input[name="data_rule"]').prop('checked', false);
  617. for(const r of listRule.rule) {
  618. $('#shuliangguize input[name="data_rule"][value="' + r +'"]').prop('checked', true);
  619. }
  620. });
  621. // 设置原设计数量读取
  622. $('#setListRule').click(function () {
  623. const rule = [];
  624. $('#shuliangguize input[name="data_rule"]:checked').each(function () {
  625. rule.push($(this).val());
  626. });
  627. const newListRule = {
  628. source: parseInt($('#shuliangguize input[name="data_source"]:checked').val()),
  629. rule,
  630. };
  631. postData(preUrl + '/list/save', { type: 'list_rule', postData: JSON.stringify(newListRule) }, function (result) {
  632. listRule = newListRule;
  633. $('#shuliangguize').modal('hide');
  634. });
  635. })
  636. }
  637. if (change.shenpiPower) {
  638. changeSpreadObj.editEnded = function (e, info) {
  639. if (info.sheet.zh_setting) {
  640. const select = SpreadJsObj.getSelectObject(info.sheet);
  641. const col = info.sheet.zh_setting.cols[info.col];
  642. // 未改变值则不提交
  643. let validText = info.editingText ? trimInvalidChar(info.editingText) : '';
  644. const orgValue = select[col.field];
  645. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  646. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  647. return;
  648. }
  649. select[col.field] = validText;
  650. const data = {
  651. id: select.id,
  652. };
  653. if (col.field === 'ex_memo1' || col.field === 'ex_memo2') {
  654. data[col.field] = select[col.field];
  655. }
  656. console.log(data);
  657. // 更新至服务器
  658. postData(preUrl + '/list/save', { type:'update', updateData: data }, function (result) {
  659. changeList.splice(info.row, 1, select);
  660. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  661. }, function () {
  662. select[col.field] = orgValue;
  663. if (col.field !== 'ex_memo1' && col.field !== 'ex_memo2') {
  664. select.spamount = orgValue;
  665. }
  666. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  667. });
  668. }
  669. };
  670. changeSpreadObj.clipboardPasted = function(e, info) {
  671. const hint = {
  672. cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
  673. numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
  674. };
  675. const range = info.cellRange;
  676. const sortData = info.sheet.zh_data || [];
  677. const data = [];
  678. for (let iRow = 0; iRow < range.rowCount; iRow++) {
  679. let bPaste = true;
  680. const curRow = range.row + iRow;
  681. // const materialData = JSON.parse(JSON.stringify(sortData[curRow]));
  682. const cLData = { id: sortData[curRow].id };
  683. const hintRow = range.rowCount > 1 ? curRow : '';
  684. let sameCol = 0;
  685. for (let iCol = 0; iCol < range.colCount; iCol++) {
  686. const curCol = range.col + iCol;
  687. const colSetting = info.sheet.zh_setting.cols[curCol];
  688. if (!colSetting) continue;
  689. let validText = info.sheet.getText(curRow, curCol);
  690. validText = validText ? trimInvalidChar(validText) : null;
  691. const orgValue = sortData[curRow][colSetting.field];
  692. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  693. sameCol++;
  694. if (range.colCount === sameCol) {
  695. bPaste = false;
  696. }
  697. continue;
  698. }
  699. sortData[curRow][colSetting.field] = validText;
  700. if (colSetting.field === 'ex_memo1' || colSetting.field === 'ex_memo2') {
  701. cLData[colSetting.field] = validText;
  702. }
  703. }
  704. if (bPaste) {
  705. data.push(cLData);
  706. // rowData.push(curRow);
  707. } else {
  708. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  709. }
  710. }
  711. if (data.length === 0) {
  712. return;
  713. }
  714. console.log(data);
  715. // 更新至服务器
  716. postData(preUrl + '/list/save', { type:'paste_amount_rows', updateData: data }, function (result) {
  717. changeList = result;
  718. SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
  719. changeSpreadObj.makeSjsFooter();
  720. }, function () {
  721. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  722. return;
  723. });
  724. };
  725. changeSpread.bind(spreadNS.Events.EditEnded, changeSpreadObj.editEnded);
  726. changeSpread.bind(spreadNS.Events.ClipboardPasted, changeSpreadObj.clipboardPasted);
  727. changeSpread.bind(spreadNS.Events.ValueChanged, changeSpreadObj.valueChanged);
  728. SpreadJsObj.addDeleteBind(changeSpread, changeSpreadObj.deletePress);
  729. }
  730. let changeListData;
  731. let gclGatherData;
  732. let dealBillList;
  733. const billUrl = window.location.pathname.split('/').slice(0, 4).join('/');
  734. postData(billUrl + '/defaultBills', {}, function (result) {
  735. gclGatherModel.loadLedgerData(result.bills);
  736. gclGatherModel.loadPosData(result.pos);
  737. gclGatherData = gclGatherModel.gatherGclData();
  738. gclGatherData = _.filter(gclGatherData, function (item) {
  739. return item.leafXmjs && item.leafXmjs.length !== 0;
  740. });
  741. // 数组去重
  742. dealBillList = result.dealBills;
  743. changeListData = gclGatherData;
  744. // console.log(changeListData, dealBillList);
  745. SpreadJsObj.initSpreadSettingEvents(changeSpreadSetting, changeCol);
  746. SpreadJsObj.initSheet(changeSpreadSheet, changeSpreadSetting);
  747. SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
  748. changeSpreadObj.makeSjsFooter();
  749. // 计算最新的变更总额和change的total_price是否一致,不一致则更新
  750. if (change.status !== auditConst.status.checked) {
  751. // let new_tp = 0;
  752. const updateArray = [];
  753. for (const c of changeList) {
  754. const oneUpdate = {};
  755. console.log(ZhCalc.round(c.camount, findDecimal(c.unit)), c.camount);
  756. if (ZhCalc.round(c.oamount, findDecimal(c.unit)) !== c.oamount) oneUpdate.oamount = ZhCalc.round(c.oamount, findDecimal(c.unit));
  757. if (ZhCalc.round(c.camount, findDecimal(c.unit)) !== c.camount) oneUpdate.camount = ZhCalc.round(c.camount, findDecimal(c.unit));
  758. if (ZhCalc.round(c.unit_price, unitPriceUnit) !== c.unit_price) oneUpdate.unit_price = ZhCalc.round(c.unit_price, unitPriceUnit);
  759. if (!_.isEmpty(oneUpdate)) {
  760. oneUpdate.id = c.id;
  761. updateArray.push(oneUpdate);
  762. }
  763. // new_tp = ZhCalc.add(new_tp, ZhCalc.round(ZhCalc.mul(ZhCalc.round(c.spamount, findDecimal(c.unit)), ZhCalc.round(c.unit_price, unitPriceUnit)), totalPriceUnit));
  764. }
  765. console.log(updateArray);
  766. if (updateArray.length > 0) {
  767. // 更新至服务器
  768. postData(preUrl + '/list/save', { type:'paste', updateData: updateArray }, function (result) {
  769. changeList = result;
  770. SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
  771. changeSpreadObj.makeSjsFooter();
  772. });
  773. }
  774. // if (change.total_price && change.total_price !== new_tp) {
  775. // postData(preUrl + '/list/save', {type: 'update_tp', updateData: new_tp}, function (result) {
  776. // });
  777. // }
  778. }
  779. });
  780. // let timer = null
  781. // const handleScroll = function (e) {
  782. // timer && clearTimeout(timer)
  783. // timer = setTimeout(() => {
  784. // console.log('hello');
  785. //
  786. // // SpreadJsObj.initSpreadSettingEvents(changeSpreadSetting, changeCol);
  787. // // SpreadJsObj.initSheet(changeSpreadSheet, changeSpreadSetting);
  788. // // SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
  789. // // changeSpreadObj.makeSjsFooter();
  790. // }, 400);
  791. // }
  792. //
  793. // document.querySelector('.sjs-height-0').addEventListener('scroll', handleScroll);
  794. });
  795. /**
  796. * 校验文件大小、格式
  797. * @param {Array} files 文件数组
  798. */
  799. function validateFiles(files) {
  800. if (files.length > 10) {
  801. toastr.error('至多同时上传10个文件');
  802. return false
  803. }
  804. return files.every(file => {
  805. if (file.size > 1024 * 1024 * 30) {
  806. toastr.error('文件大小限制为30MB');
  807. return false
  808. }
  809. if (whiteList.indexOf('.' + file.ext.toLowerCase()) === -1) {
  810. toastr.error('请上传正确的格式文件');
  811. return false
  812. }
  813. return true
  814. })
  815. }
  816. function findDecimal(unit) {
  817. let value = precision.other.value;
  818. const changeUnits = precision;
  819. for (const d in changeUnits) {
  820. if (changeUnits[d].unit !== undefined && changeUnits[d].unit === unit) {
  821. value = changeUnits[d].value;
  822. break;
  823. }
  824. }
  825. return value;
  826. }
  827. const is_numeric = (value) => {
  828. if (typeof(value) === 'object') {
  829. return false;
  830. } else {
  831. return !Number.isNaN(Number(value)) && value.toString().trim() !== '';
  832. }
  833. };