change_apply_information.js 41 KB

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