change_apply_information.js 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867
  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 )
  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. // 未改变值则不提交
  309. let validText = is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : '');
  310. const orgValue = type === 'update' ? select[col.field] : '';
  311. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  312. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  313. return;
  314. }
  315. if (col.field === 'oa_tp' || col.field === 'ca_tp') {
  316. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  317. return;
  318. }
  319. // 判断部分值是否输入的是数字判断和数据计算
  320. if (col.type === 'Number') {
  321. if (isNaN(validText)) {
  322. toastr.error('不能输入其它非数字类型字符');
  323. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  324. return;
  325. }
  326. if (col.field === 'unit_price') {
  327. validText = ZhCalc.round(validText, unitPriceUnit);
  328. } else {
  329. validText = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
  330. }
  331. }
  332. if (col.field === 'unit') {
  333. select.camount = ZhCalc.round(select.camount, findDecimal(validText)) || 0;
  334. select.oamount = ZhCalc.round(select.oamount, findDecimal(validText)) || 0;
  335. }
  336. select[col.field] = validText;
  337. console.log(select, type);
  338. delete select.waitingLoading;
  339. // 更新至服务器
  340. postData(preUrl + '/list/save', { type, updateData: select }, function (result) {
  341. if(type === 'update') {
  342. changeList.splice(info.row, 1, select);
  343. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  344. changeSpreadObj.countSum();
  345. } else {
  346. changeList.push(result);
  347. changeSpreadSheet.addRows(changeList.length - 1, 1);
  348. SpreadJsObj.reLoadRowData(changeSpreadSheet, changeList.length - 1);
  349. changeSpreadSheet.setStyle(changeSpreadSheet.getRowCount() - 1, -1, style1);
  350. // changeSpreadSheet.setSelection(changeList.length - 1, 0, 1, 1);
  351. }
  352. }, function () {
  353. select[col.field] = orgValue;
  354. if(col.field === 'camount') {
  355. select.spamount = orgValue;
  356. }
  357. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  358. });
  359. }
  360. };
  361. changeSpreadObj.clipboardPasted = function(e, info, cellRange) {
  362. if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
  363. info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
  364. }
  365. const hint = {
  366. cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
  367. numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
  368. };
  369. if (info.sheet.zh_setting) {
  370. const sortData = info.sheet.zh_data || [];
  371. const range = info.cellRange;
  372. const data = [];
  373. let haveNew = false;
  374. for (let iRow = 0; iRow < range.rowCount; iRow++) {
  375. let bPaste = true;
  376. const curRow = range.row + iRow;
  377. // const materialData = JSON.parse(JSON.stringify(sortData[curRow]));
  378. const cLData = curRow >= sortData.length ? {unit: ''} : {id: sortData[curRow].id};
  379. haveNew = curRow >= sortData.length ? curRow : false;
  380. const hintRow = range.rowCount > 1 ? curRow : '';
  381. let sameCol = 0;
  382. for (let iCol = 0; iCol < range.colCount; iCol++) {
  383. const curCol = range.col + iCol;
  384. const colSetting = info.sheet.zh_setting.cols[curCol];
  385. if (!colSetting) continue;
  386. // cLData[colSetting.field] = trimInvalidChar(info.sheet.getText(curRow, curCol));
  387. let validText = info.sheet.getText(curRow, curCol);
  388. validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : '');
  389. const orgValue = curRow >= sortData.length ? '' : sortData[curRow][colSetting.field];
  390. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  391. sameCol++;
  392. if (range.colCount === sameCol) {
  393. bPaste = false;
  394. }
  395. continue;
  396. }
  397. if (colSetting.type === 'Number') {
  398. if (isNaN(validText)) {
  399. // toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
  400. toastMessageUniq(hint.numberExpr);
  401. bPaste = false;
  402. continue;
  403. }
  404. if (colSetting.field === 'unit_price') {
  405. validText = ZhCalc.round(validText, unitPriceUnit);
  406. } else {
  407. validText = ZhCalc.round(validText, findDecimal(cLData.unit)) || 0;
  408. }
  409. }
  410. let unitdecimal = validText;
  411. if (colSetting.field === 'unit') {
  412. //粘贴内容要为下拉列表里所有的单位,不然为空
  413. if (changeUnits.indexOf(validText) === -1) {
  414. unitdecimal = '';
  415. // validText = null;
  416. }
  417. cLData.camount = curRow >= sortData.length ? 0 : ZhCalc.round(sortData[curRow].camount, findDecimal(unitdecimal)) || 0;
  418. cLData.oamount = curRow >= sortData.length ? 0 : ZhCalc.round(sortData[curRow].oamount, findDecimal(unitdecimal)) || 0;
  419. }
  420. cLData[colSetting.field] = validText;
  421. }
  422. if (bPaste) {
  423. delete cLData.oa_tp;
  424. delete cLData.ca_tp;
  425. data.push(cLData);
  426. // rowData.push(curRow);
  427. } else {
  428. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  429. }
  430. }
  431. if (data.length === 0) {
  432. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  433. return;
  434. }
  435. console.log(data);
  436. // 更新至服务器
  437. postData(preUrl + '/list/save', { type:'paste', updateData: data }, function (result) {
  438. changeList = result;
  439. SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
  440. changeSpreadObj.makeSjsFooter();
  441. }, function () {
  442. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  443. return;
  444. });
  445. }
  446. };
  447. changeSpreadObj.updateOamount = function () {
  448. const dataSource = listRule.source === 1 ? gclGatherData : dealBillList;
  449. const updateList = [];
  450. for (const c of changeList) {
  451. const source = _.find(dataSource, function (item) {
  452. if (((item.b_code && item.b_code === c.code) || (item.code && item.code === c.code)) && item.name === c.name) {
  453. if (listRule.rule.length > 0) {
  454. for(const r of listRule.rule) {
  455. if (item[r] !== c[r]) {
  456. return false;
  457. }
  458. }
  459. }
  460. return true;
  461. }
  462. return false;
  463. });
  464. if (source && source.quantity !== c.oamount) {
  465. updateList.push({ id: c.id, oamount: source.quantity });
  466. }
  467. }
  468. console.log(updateList);
  469. if(updateList.length > 0) {
  470. postData(preUrl + '/list/save', { type:'paste', updateData: updateList }, function (result) {
  471. changeList = result;
  472. SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
  473. changeSpreadObj.makeSjsFooter();
  474. });
  475. }
  476. };
  477. changeSpreadObj.buttonClicked = function (e, info) {
  478. if (info.sheet.zh_setting) {
  479. const select = SpreadJsObj.getSelectObject(info.sheet);
  480. const col = info.sheet.zh_setting.cols[info.col];
  481. if(!select) {
  482. toastr.error('请添加清单编号再勾选');
  483. if (info.sheet.isEditing()) {
  484. info.sheet.endEdit(true);
  485. }
  486. return;
  487. } else if (col.field === 'new_up') {
  488. if (info.sheet.isEditing()) {
  489. info.sheet.endEdit(true);
  490. }
  491. select.new_up = info.sheet.getValue(info.row, info.col) ? 0 : 1;
  492. postData(preUrl + '/list/save', { type: 'update', updateData: { id: select.id, new_up: select.new_up } }, function (result) {
  493. changeList.splice(info.row, 1, select);
  494. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  495. changeSpreadObj.countSum();
  496. }, function () {
  497. select.new_up = info.sheet.getValue(info.row, info.col) ? 1 : 0;
  498. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  499. });
  500. }
  501. }
  502. };
  503. // changeSpread.bind(spreadNS.Events.CellChanged, changeSpreadObj.cellChanged);
  504. changeSpread.bind(spreadNS.Events.EditEnded, changeSpreadObj.editEnded);
  505. changeSpread.bind(spreadNS.Events.ButtonClicked, changeSpreadObj.buttonClicked);
  506. changeSpread.bind(spreadNS.Events.ClipboardPasted, changeSpreadObj.clipboardPasted);
  507. changeSpread.bind(spreadNS.Events.ValueChanged, changeSpreadObj.valueChanged);
  508. SpreadJsObj.addDeleteBind(changeSpread, changeSpreadObj.deletePress);
  509. let batchInsertObj;
  510. $.contextMenu.types.batchInsert = function (item, opt, root) {
  511. const self = this;
  512. if ($.isFunction(item.icon)) {
  513. item._icon = item.icon.call(this, this, $t, key, item);
  514. } else {
  515. if (typeof(item.icon) === 'string' && item.icon.substring(0, 3) === 'fa-') {
  516. // to enable font awesome
  517. item._icon = root.classNames.icon + ' ' + root.classNames.icon + '--fa fa ' + item.icon;
  518. } else {
  519. item._icon = root.classNames.icon + ' ' + root.classNames.icon + '-' + item.icon;
  520. }
  521. }
  522. this.addClass(item._icon);
  523. 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>')
  524. .appendTo(this);
  525. const $input = $obj.find('input');
  526. const event = () => {
  527. if (self.hasClass('context-menu-disabled')) return;
  528. item.batchInsert($input[0], root);
  529. };
  530. $obj.on('click', event).keypress(function (e) {if (e.keyCode === 13) { event(); }});
  531. $input.click((e) => {e.stopPropagation();})
  532. .keyup((e) => {if (e.keyCode === 13) item.batchInsert($input[0], root);})
  533. .on('input', function () {this.value = this.value.replace(/[^\d]/g, '');});
  534. };
  535. // 右键菜单
  536. $.contextMenu({
  537. selector: '#apply-spread',
  538. build: function ($trigger, e) {
  539. const target = SpreadJsObj.safeRightClickSelection($trigger, e, changeSpread);
  540. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  541. },
  542. items: {
  543. 'updateOamount': {
  544. name: '原设计数量读取',
  545. icon: '',
  546. callback: function (key, opt) {
  547. changeSpreadObj.updateOamount(changeSpreadSheet);
  548. },
  549. disabled: function (key, opt) {
  550. const select = SpreadJsObj.getSelectObject(changeSpreadSheet);
  551. const sel = changeSpreadSheet.getSelections()[0];
  552. // console.log(select, sel);
  553. if (!readOnly && select && sel.row !== changeSpreadSheet.getRowCount() - 1) {
  554. return false;
  555. } else {
  556. return true;
  557. }
  558. }
  559. },
  560. sprDel: '------------',
  561. 'createAdd': {
  562. name: '添加行',
  563. icon: 'fa-sign-in',
  564. callback: function (key, opt) {
  565. changeSpreadObj.add(changeSpreadSheet);
  566. },
  567. },
  568. 'batchInsert': {
  569. name: '批量添加行',
  570. type: 'batchInsert',
  571. value: '2',
  572. icon: 'fa-sign-in',
  573. batchInsert: function (obj, root) {
  574. if (_.toNumber(obj.value) > _.toNumber(obj.max)) {
  575. obj.value = obj.max;
  576. toastr.warning('批量添加不可多于' + obj.max);
  577. } else if(_.toNumber(obj.value) < _.toNumber(obj.min)) {
  578. obj.value = obj.min;
  579. toastr.warning('批量添加不可少于' + obj.min);
  580. } else {
  581. // treeOperationObj.addNode(ledgerSpread.getActiveSheet(), parseInt(obj.value));
  582. changeSpreadObj.batchAdd(obj.value);
  583. root.$menu.trigger('contextmenu:hide');
  584. }
  585. },
  586. },
  587. 'delete': {
  588. name: '删除',
  589. icon: 'fa-remove',
  590. callback: function (key, opt) {
  591. changeSpreadObj.del(changeSpreadSheet);
  592. },
  593. disabled: function (key, opt) {
  594. // const select = SpreadJsObj.getSelectObject(changeSpreadSheet);
  595. if (changeSpreadSheet.zh_data) {
  596. const selection = changeSpreadSheet.getSelections();
  597. // return changeSpreadSheet.zh_data.length < selection[0].row + selection[0].rowCount;
  598. return changeSpreadSheet.getRowCount() - 1 < selection[0].row + selection[0].rowCount;
  599. } else {
  600. return true;
  601. }
  602. // const sel = changeSpreadSheet.getSelections()[0];
  603. // // console.log(select, sel);
  604. // if (!readOnly && select && sel.row !== changeSpreadSheet.getRowCount() - 1) {
  605. // return false;
  606. // } else {
  607. // return true;
  608. // }
  609. }
  610. },
  611. }
  612. });
  613. $('#shuliangguize').on('show.bs.modal', function () {
  614. $('#shuliangguize input[name="data_source"][value="'+ listRule.source +'"]').prop('checked', true);
  615. $('#shuliangguize input[name="data_rule"]').prop('checked', false);
  616. for(const r of listRule.rule) {
  617. $('#shuliangguize input[name="data_rule"][value="' + r +'"]').prop('checked', true);
  618. }
  619. });
  620. // 设置原设计数量读取
  621. $('#setListRule').click(function () {
  622. const rule = [];
  623. $('#shuliangguize input[name="data_rule"]:checked').each(function () {
  624. rule.push($(this).val());
  625. });
  626. const newListRule = {
  627. source: parseInt($('#shuliangguize input[name="data_source"]:checked').val()),
  628. rule,
  629. };
  630. postData(preUrl + '/list/save', { type: 'list_rule', postData: JSON.stringify(newListRule) }, function (result) {
  631. listRule = newListRule;
  632. $('#shuliangguize').modal('hide');
  633. });
  634. })
  635. }
  636. if (change.shenpiPower) {
  637. changeSpreadObj.editEnded = function (e, info) {
  638. if (info.sheet.zh_setting) {
  639. const select = SpreadJsObj.getSelectObject(info.sheet);
  640. const col = info.sheet.zh_setting.cols[info.col];
  641. // 未改变值则不提交
  642. let validText = is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : '');
  643. const orgValue = select[col.field];
  644. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  645. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  646. return;
  647. }
  648. select[col.field] = validText;
  649. const data = {
  650. id: select.id,
  651. };
  652. if (col.field === 'ex_memo1' || col.field === 'ex_memo2') {
  653. data[col.field] = select[col.field];
  654. }
  655. console.log(data);
  656. // 更新至服务器
  657. postData(preUrl + '/list/save', { type:'update', updateData: data }, function (result) {
  658. changeList.splice(info.row, 1, select);
  659. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  660. }, function () {
  661. select[col.field] = orgValue;
  662. if (col.field !== 'ex_memo1' && col.field !== 'ex_memo2') {
  663. select.spamount = orgValue;
  664. }
  665. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  666. });
  667. }
  668. };
  669. changeSpreadObj.clipboardPasted = function(e, info) {
  670. const hint = {
  671. cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
  672. numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
  673. };
  674. const range = info.cellRange;
  675. const sortData = info.sheet.zh_data || [];
  676. const data = [];
  677. for (let iRow = 0; iRow < range.rowCount; iRow++) {
  678. let bPaste = true;
  679. const curRow = range.row + iRow;
  680. // const materialData = JSON.parse(JSON.stringify(sortData[curRow]));
  681. const cLData = { id: sortData[curRow].id };
  682. const hintRow = range.rowCount > 1 ? curRow : '';
  683. let sameCol = 0;
  684. for (let iCol = 0; iCol < range.colCount; iCol++) {
  685. const curCol = range.col + iCol;
  686. const colSetting = info.sheet.zh_setting.cols[curCol];
  687. if (!colSetting) continue;
  688. let validText = info.sheet.getText(curRow, curCol);
  689. validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : null);
  690. const orgValue = sortData[curRow][colSetting.field];
  691. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  692. sameCol++;
  693. if (range.colCount === sameCol) {
  694. bPaste = false;
  695. }
  696. continue;
  697. }
  698. sortData[curRow][colSetting.field] = validText;
  699. if (colSetting.field === 'ex_memo1' || colSetting.field === 'ex_memo2') {
  700. cLData[colSetting.field] = validText;
  701. }
  702. }
  703. if (bPaste) {
  704. data.push(cLData);
  705. // rowData.push(curRow);
  706. } else {
  707. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  708. }
  709. }
  710. if (data.length === 0) {
  711. return;
  712. }
  713. console.log(data);
  714. // 更新至服务器
  715. postData(preUrl + '/list/save', { type:'paste_amount_rows', updateData: data }, function (result) {
  716. changeList = result;
  717. SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
  718. changeSpreadObj.makeSjsFooter();
  719. }, function () {
  720. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  721. return;
  722. });
  723. };
  724. changeSpread.bind(spreadNS.Events.EditEnded, changeSpreadObj.editEnded);
  725. changeSpread.bind(spreadNS.Events.ClipboardPasted, changeSpreadObj.clipboardPasted);
  726. changeSpread.bind(spreadNS.Events.ValueChanged, changeSpreadObj.valueChanged);
  727. SpreadJsObj.addDeleteBind(changeSpread, changeSpreadObj.deletePress);
  728. }
  729. let changeListData;
  730. let gclGatherData;
  731. let dealBillList;
  732. const billUrl = window.location.pathname.split('/').slice(0, 4).join('/');
  733. postData(billUrl + '/defaultBills', {}, function (result) {
  734. gclGatherModel.loadLedgerData(result.bills);
  735. gclGatherModel.loadPosData(result.pos);
  736. gclGatherData = gclGatherModel.gatherGclData();
  737. gclGatherData = _.filter(gclGatherData, function (item) {
  738. return item.leafXmjs && item.leafXmjs.length !== 0;
  739. });
  740. // 数组去重
  741. dealBillList = result.dealBills;
  742. changeListData = gclGatherData;
  743. console.log(changeListData, dealBillList);
  744. SpreadJsObj.initSpreadSettingEvents(changeSpreadSetting, changeCol);
  745. SpreadJsObj.initSheet(changeSpreadSheet, changeSpreadSetting);
  746. SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
  747. changeSpreadObj.makeSjsFooter();
  748. // 计算最新的变更总额和change的total_price是否一致,不一致则更新
  749. if (change.status !== auditConst.status.checked) {
  750. // let new_tp = 0;
  751. const updateArray = [];
  752. for (const c of changeList) {
  753. const oneUpdate = {};
  754. console.log(ZhCalc.round(c.camount, findDecimal(c.unit)), c.camount);
  755. if (ZhCalc.round(c.oamount, findDecimal(c.unit)) !== c.oamount) oneUpdate.oamount = ZhCalc.round(c.oamount, findDecimal(c.unit));
  756. if (ZhCalc.round(c.camount, findDecimal(c.unit)) !== c.camount) oneUpdate.camount = ZhCalc.round(c.camount, findDecimal(c.unit));
  757. if (ZhCalc.round(c.unit_price, unitPriceUnit) !== c.unit_price) oneUpdate.unit_price = ZhCalc.round(c.unit_price, unitPriceUnit);
  758. if (!_.isEmpty(oneUpdate)) {
  759. oneUpdate.id = c.id;
  760. updateArray.push(oneUpdate);
  761. }
  762. // new_tp = ZhCalc.add(new_tp, ZhCalc.round(ZhCalc.mul(ZhCalc.round(c.spamount, findDecimal(c.unit)), ZhCalc.round(c.unit_price, unitPriceUnit)), totalPriceUnit));
  763. }
  764. console.log(updateArray);
  765. if (updateArray.length > 0) {
  766. // 更新至服务器
  767. postData(preUrl + '/list/save', { type:'paste', updateData: updateArray }, function (result) {
  768. changeList = result;
  769. SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
  770. changeSpreadObj.makeSjsFooter();
  771. });
  772. }
  773. // if (change.total_price && change.total_price !== new_tp) {
  774. // postData(preUrl + '/list/save', {type: 'update_tp', updateData: new_tp}, function (result) {
  775. // });
  776. // }
  777. }
  778. });
  779. // let timer = null
  780. // const handleScroll = function (e) {
  781. // timer && clearTimeout(timer)
  782. // timer = setTimeout(() => {
  783. // console.log('hello');
  784. //
  785. // // SpreadJsObj.initSpreadSettingEvents(changeSpreadSetting, changeCol);
  786. // // SpreadJsObj.initSheet(changeSpreadSheet, changeSpreadSetting);
  787. // // SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
  788. // // changeSpreadObj.makeSjsFooter();
  789. // }, 400);
  790. // }
  791. //
  792. // document.querySelector('.sjs-height-0').addEventListener('scroll', handleScroll);
  793. });
  794. /**
  795. * 校验文件大小、格式
  796. * @param {Array} files 文件数组
  797. */
  798. function validateFiles(files) {
  799. if (files.length > 10) {
  800. toastr.error('至多同时上传10个文件');
  801. return false
  802. }
  803. return files.every(file => {
  804. if (file.size > 1024 * 1024 * 30) {
  805. toastr.error('文件大小限制为30MB');
  806. return false
  807. }
  808. if (whiteList.indexOf('.' + file.ext) === -1) {
  809. toastr.error('请上传正确的格式文件');
  810. return false
  811. }
  812. return true
  813. })
  814. }
  815. function findDecimal(unit) {
  816. let value = precision.other.value;
  817. const changeUnits = precision;
  818. for (const d in changeUnits) {
  819. if (changeUnits[d].unit !== undefined && changeUnits[d].unit === unit) {
  820. value = changeUnits[d].value;
  821. break;
  822. }
  823. }
  824. return value;
  825. }
  826. const is_numeric = (value) => {
  827. if (typeof(value) === 'object') {
  828. return false;
  829. } else {
  830. return !Number.isNaN(Number(value)) && value.toString().trim() !== '';
  831. }
  832. };