change_apply_information.js 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718
  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: 'code', hAlign: 0, width: 110, formatter: '@', readOnly: 'readOnly.isEdit'},
  189. {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 130, formatter: '@', readOnly: 'readOnly.isEdit'},
  190. {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 60, formatter: '@', readOnly: 'readOnly.isEdit', cellType: 'unit', comboItems: changeUnits, comboEdit: true},
  191. {title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.isEdit', getValue: 'getValue.unit_price'},
  192. {title: '原设计|数量', colSpan: '2|1', rowSpan: '1|1', field: 'oamount', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.isEdit', getValue: 'getValue.oamount'},
  193. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'oa_tp', hAlign: 2, width: 80, type: 'Number', readOnly: true, getValue: 'getValue.oa_tp'},
  194. {title: '申请变更增(+)减(-)|数量', colSpan: '2|1', rowSpan: '1|1', field: 'camount', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.isEdit', getValue: 'getValue.camount'},
  195. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'ca_tp', hAlign: 2, width: 80, type: 'Number', readOnly: true, getValue: 'getValue.ca_tp'},
  196. ],
  197. emptyRows: !readOnly ? 3 : 0,
  198. headRows: 2,
  199. headRowHeight: [25, 25],
  200. defaultRowHeight: 21,
  201. headerFont: '12px 微软雅黑',
  202. font: '12px 微软雅黑',
  203. readOnly: readOnly,
  204. localCache: {
  205. key: 'changes-apply-list-spread',
  206. colWidth: true,
  207. }
  208. };
  209. console.log(changeList);
  210. const changeCol = {
  211. getValue: {
  212. unit_price: function(data) {
  213. return ZhCalc.round(data.unit_price, unitPriceUnit);
  214. },
  215. oa_tp: function (data) {
  216. return ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), ZhCalc.round(data.oamount, findDecimal(data.unit))), totalPriceUnit);
  217. },
  218. ca_tp: function (data) {
  219. return ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), ZhCalc.round(data.camount, findDecimal(data.unit))), totalPriceUnit);
  220. },
  221. oamount: function (data) {
  222. return ZhCalc.round(data.oamount, findDecimal(data.unit));
  223. },
  224. camount: function (data) {
  225. return ZhCalc.round(data.camount, findDecimal(data.unit));
  226. },
  227. },
  228. readOnly: {
  229. isEdit: function (data) {
  230. return readOnly;
  231. },
  232. },
  233. };
  234. const changeSpreadObj = {
  235. makeSjsFooter: function() {
  236. // 增加汇总行并设为锁定禁止编辑状态
  237. changeSpreadSheet.addRows(changeSpreadSheet.getRowCount(), 1);
  238. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 0, '合计');
  239. changeSpreadSheet.setStyle(changeSpreadSheet.getRowCount() - 1, -1, style1);
  240. changeSpreadObj.countSum();
  241. },
  242. countSum: function() {
  243. const rowCount = changeSpreadSheet.getRowCount();
  244. let oSum = 0,
  245. cSum = 0;
  246. for (let i = 0; i < rowCount - 1; i++) {
  247. oSum = ZhCalc.add(oSum, changeSpreadSheet.getValue(i, 5));
  248. cSum = ZhCalc.add(cSum, changeSpreadSheet.getValue(i, 7));
  249. }
  250. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 5, oSum !== 0 ? oSum : null);
  251. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 7, cSum !== 0 ? cSum : null);
  252. },
  253. deletePress: function (sheet) {
  254. return;
  255. },
  256. valueChanged: function (e, info) {
  257. // 防止ctrl+z撤销数据
  258. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  259. }
  260. };
  261. if (!readOnly) {
  262. changeSpreadObj.add = function () {
  263. changeSpreadSheet.addRows(changeSpreadSheet.getRowCount() - 1, 1);
  264. changeSpreadSheet.setStyle(changeSpreadSheet.getRowCount() - 1, -1, style1);
  265. // changeSpreadSheet.setSelection(changeList.length - 1, 0, 1, 1);
  266. };
  267. changeSpreadObj.batchAdd = function (num) {
  268. changeSpreadSheet.addRows(changeSpreadSheet.getRowCount() - 1, parseInt(num));
  269. changeSpreadSheet.setStyle(changeSpreadSheet.getRowCount() - 1, -1, style1);
  270. };
  271. changeSpreadObj.del = function (sheet) {
  272. const selection = sheet.getSelections();
  273. const row = selection[0].row, count = selection[0].rowCount;
  274. const sortData = sheet.zh_data;
  275. const ids = [];
  276. let emptyRowNum = 0;
  277. for (let iRow = 0; iRow < count; iRow++) {
  278. if (sortData[iRow + row]) {
  279. ids.push(sortData[iRow + row].id);
  280. } else {
  281. emptyRowNum++;
  282. }
  283. }
  284. if (ids.length > 0) {
  285. postData(preUrl + '/list/save', {type: 'del', ids}, function (result) {
  286. changeList = result;
  287. SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
  288. changeSpreadObj.makeSjsFooter();
  289. });
  290. } else if (emptyRowNum > 0) {
  291. changeSpreadSheet.deleteRows(changeList.length, emptyRowNum);
  292. changeSpreadSheet.setSelection(changeList.length - 1, 0, 1, 1);
  293. }
  294. };
  295. changeSpreadObj.editEnded = function (e, info) {
  296. if (info.sheet.zh_setting) {
  297. const type = SpreadJsObj.getSelectObject(info.sheet) ? 'update' : 'add';
  298. const select = type === 'update' ? SpreadJsObj.getSelectObject(info.sheet) : {unit: ''};
  299. const col = info.sheet.zh_setting.cols[info.col];
  300. // 未改变值则不提交
  301. let validText = is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : '');
  302. const orgValue = type === 'update' ? select[col.field] : '';
  303. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  304. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  305. return;
  306. }
  307. if (col.field === 'oa_tp' || col.field === 'ca_tp') {
  308. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  309. return;
  310. }
  311. // 判断部分值是否输入的是数字判断和数据计算
  312. if (col.type === 'Number') {
  313. if (isNaN(validText)) {
  314. toastr.error('不能输入其它非数字类型字符');
  315. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  316. return;
  317. }
  318. if (col.field === 'unit_price') {
  319. validText = ZhCalc.round(validText, unitPriceUnit);
  320. } else {
  321. validText = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
  322. }
  323. }
  324. if (col.field === 'unit') {
  325. select.camount = ZhCalc.round(select.camount, findDecimal(validText)) || 0;
  326. select.oamount = ZhCalc.round(select.oamount, findDecimal(validText)) || 0;
  327. }
  328. select[col.field] = validText;
  329. console.log(select, type);
  330. delete select.waitingLoading;
  331. // 更新至服务器
  332. postData(preUrl + '/list/save', { type, updateData: select }, function (result) {
  333. if(type === 'update') {
  334. changeList.splice(info.row, 1, select);
  335. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  336. changeSpreadObj.countSum();
  337. } else {
  338. changeList.push(result);
  339. changeSpreadSheet.addRows(changeList.length - 1, 1);
  340. SpreadJsObj.reLoadRowData(changeSpreadSheet, changeList.length - 1);
  341. changeSpreadSheet.setStyle(changeSpreadSheet.getRowCount() - 1, -1, style1);
  342. // changeSpreadSheet.setSelection(changeList.length - 1, 0, 1, 1);
  343. }
  344. }, function () {
  345. select[col.field] = orgValue;
  346. if(col.field === 'camount') {
  347. select.spamount = orgValue;
  348. }
  349. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  350. });
  351. }
  352. };
  353. changeSpreadObj.clipboardPasted = function(e, info, cellRange) {
  354. if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
  355. info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
  356. }
  357. const hint = {
  358. cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
  359. numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
  360. };
  361. if (info.sheet.zh_setting) {
  362. const sortData = info.sheet.zh_data || [];
  363. const range = info.cellRange;
  364. const data = [];
  365. for (let iRow = 0; iRow < range.rowCount; iRow++) {
  366. let bPaste = true;
  367. const curRow = range.row + iRow;
  368. // const materialData = JSON.parse(JSON.stringify(sortData[curRow]));
  369. const cLData = curRow >= sortData.length ? {unit: ''} : {id: sortData[curRow].id};
  370. const hintRow = range.rowCount > 1 ? curRow : '';
  371. let sameCol = 0;
  372. for (let iCol = 0; iCol < range.colCount; iCol++) {
  373. const curCol = range.col + iCol;
  374. const colSetting = info.sheet.zh_setting.cols[curCol];
  375. if (!colSetting) continue;
  376. // cLData[colSetting.field] = trimInvalidChar(info.sheet.getText(curRow, curCol));
  377. let validText = info.sheet.getText(curRow, curCol);
  378. validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : '');
  379. const orgValue = curRow >= sortData.length ? '' : sortData[curRow][colSetting.field];
  380. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  381. sameCol++;
  382. if (range.colCount === sameCol) {
  383. bPaste = false;
  384. }
  385. continue;
  386. }
  387. if (colSetting.type === 'Number') {
  388. if (isNaN(validText)) {
  389. // toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
  390. toastMessageUniq(hint.numberExpr);
  391. bPaste = false;
  392. continue;
  393. }
  394. if (colSetting.field === 'unit_price') {
  395. validText = ZhCalc.round(validText, unitPriceUnit);
  396. } else {
  397. validText = ZhCalc.round(validText, findDecimal(cLData.unit)) || 0;
  398. }
  399. }
  400. let unitdecimal = validText;
  401. if (colSetting.field === 'unit') {
  402. //粘贴内容要为下拉列表里所有的单位,不然为空
  403. if (changeUnits.indexOf(validText) === -1) {
  404. unitdecimal = '';
  405. // validText = null;
  406. }
  407. cLData.camount = curRow >= sortData.length ? 0 : ZhCalc.round(sortData[curRow].camount, findDecimal(unitdecimal)) || 0;
  408. cLData.oamount = curRow >= sortData.length ? 0 : ZhCalc.round(sortData[curRow].oamount, findDecimal(unitdecimal)) || 0;
  409. }
  410. cLData[colSetting.field] = validText;
  411. }
  412. if (bPaste) {
  413. delete cLData.oa_tp;
  414. delete cLData.ca_tp;
  415. data.push(cLData);
  416. // rowData.push(curRow);
  417. } else {
  418. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  419. }
  420. }
  421. if (data.length === 0) {
  422. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  423. return;
  424. }
  425. console.log(data);
  426. // 更新至服务器
  427. postData(preUrl + '/list/save', { type:'paste', updateData: data }, function (result) {
  428. changeList = result;
  429. SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
  430. changeSpreadObj.makeSjsFooter();
  431. }, function () {
  432. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  433. return;
  434. });
  435. }
  436. };
  437. changeSpreadObj.updateOamount = function () {
  438. const dataSource = listRule.source === 1 ? gclGatherData : dealBillList;
  439. const updateList = [];
  440. for (const c of changeList) {
  441. const source = _.find(dataSource, function (item) {
  442. if (((item.b_code && item.b_code === c.code) || (item.code && item.code === c.code)) && item.name === c.name) {
  443. if (listRule.rule.length > 0) {
  444. for(const r of listRule.rule) {
  445. if (item[r] !== c[r]) {
  446. return false;
  447. }
  448. }
  449. }
  450. return true;
  451. }
  452. return false;
  453. });
  454. if (source && source.quantity !== c.oamount) {
  455. updateList.push({ id: c.id, oamount: source.quantity });
  456. }
  457. }
  458. console.log(updateList);
  459. if(updateList.length > 0) {
  460. postData(preUrl + '/list/save', { type:'paste', updateData: updateList }, function (result) {
  461. changeList = result;
  462. SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
  463. changeSpreadObj.makeSjsFooter();
  464. });
  465. }
  466. };
  467. // changeSpread.bind(spreadNS.Events.CellChanged, changeSpreadObj.cellChanged);
  468. changeSpread.bind(spreadNS.Events.EditEnded, changeSpreadObj.editEnded);
  469. changeSpread.bind(spreadNS.Events.ClipboardPasted, changeSpreadObj.clipboardPasted);
  470. changeSpread.bind(spreadNS.Events.ValueChanged, changeSpreadObj.valueChanged);
  471. SpreadJsObj.addDeleteBind(changeSpread, changeSpreadObj.deletePress);
  472. let batchInsertObj;
  473. $.contextMenu.types.batchInsert = function (item, opt, root) {
  474. const self = this;
  475. if ($.isFunction(item.icon)) {
  476. item._icon = item.icon.call(this, this, $t, key, item);
  477. } else {
  478. if (typeof(item.icon) === 'string' && item.icon.substring(0, 3) === 'fa-') {
  479. // to enable font awesome
  480. item._icon = root.classNames.icon + ' ' + root.classNames.icon + '--fa fa ' + item.icon;
  481. } else {
  482. item._icon = root.classNames.icon + ' ' + root.classNames.icon + '-' + item.icon;
  483. }
  484. }
  485. this.addClass(item._icon);
  486. 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>')
  487. .appendTo(this);
  488. const $input = $obj.find('input');
  489. const event = () => {
  490. if (self.hasClass('context-menu-disabled')) return;
  491. item.batchInsert($input[0], root);
  492. };
  493. $obj.on('click', event).keypress(function (e) {if (e.keyCode === 13) { event(); }});
  494. $input.click((e) => {e.stopPropagation();})
  495. .keyup((e) => {if (e.keyCode === 13) item.batchInsert($input[0], root);})
  496. .on('input', function () {this.value = this.value.replace(/[^\d]/g, '');});
  497. };
  498. // 右键菜单
  499. $.contextMenu({
  500. selector: '#apply-spread',
  501. build: function ($trigger, e) {
  502. const target = SpreadJsObj.safeRightClickSelection($trigger, e, changeSpread);
  503. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  504. },
  505. items: {
  506. 'updateOamount': {
  507. name: '原设计数量读取',
  508. icon: '',
  509. callback: function (key, opt) {
  510. changeSpreadObj.updateOamount(changeSpreadSheet);
  511. },
  512. disabled: function (key, opt) {
  513. const select = SpreadJsObj.getSelectObject(changeSpreadSheet);
  514. const sel = changeSpreadSheet.getSelections()[0];
  515. // console.log(select, sel);
  516. if (!readOnly && select && sel.row !== changeSpreadSheet.getRowCount() - 1) {
  517. return false;
  518. } else {
  519. return true;
  520. }
  521. }
  522. },
  523. sprDel: '------------',
  524. 'createAdd': {
  525. name: '添加行',
  526. icon: 'fa-sign-in',
  527. callback: function (key, opt) {
  528. changeSpreadObj.add(changeSpreadSheet);
  529. },
  530. },
  531. 'batchInsert': {
  532. name: '批量添加行',
  533. type: 'batchInsert',
  534. value: '2',
  535. icon: 'fa-sign-in',
  536. batchInsert: function (obj, root) {
  537. if (_.toNumber(obj.value) > _.toNumber(obj.max)) {
  538. obj.value = obj.max;
  539. toastr.warning('批量添加不可多于' + obj.max);
  540. } else if(_.toNumber(obj.value) < _.toNumber(obj.min)) {
  541. obj.value = obj.min;
  542. toastr.warning('批量添加不可少于' + obj.min);
  543. } else {
  544. // treeOperationObj.addNode(ledgerSpread.getActiveSheet(), parseInt(obj.value));
  545. changeSpreadObj.batchAdd(obj.value);
  546. root.$menu.trigger('contextmenu:hide');
  547. }
  548. },
  549. },
  550. 'delete': {
  551. name: '删除',
  552. icon: 'fa-remove',
  553. callback: function (key, opt) {
  554. changeSpreadObj.del(changeSpreadSheet);
  555. },
  556. disabled: function (key, opt) {
  557. // const select = SpreadJsObj.getSelectObject(changeSpreadSheet);
  558. if (changeSpreadSheet.zh_data) {
  559. const selection = changeSpreadSheet.getSelections();
  560. // return changeSpreadSheet.zh_data.length < selection[0].row + selection[0].rowCount;
  561. return changeSpreadSheet.getRowCount() - 1 < selection[0].row + selection[0].rowCount;
  562. } else {
  563. return true;
  564. }
  565. // const sel = changeSpreadSheet.getSelections()[0];
  566. // // console.log(select, sel);
  567. // if (!readOnly && select && sel.row !== changeSpreadSheet.getRowCount() - 1) {
  568. // return false;
  569. // } else {
  570. // return true;
  571. // }
  572. }
  573. },
  574. }
  575. });
  576. $('#shuliangguize').on('show.bs.modal', function () {
  577. $('#shuliangguize input[name="data_source"][value="'+ listRule.source +'"]').prop('checked', true);
  578. $('#shuliangguize input[name="data_rule"]').prop('checked', false);
  579. for(const r of listRule.rule) {
  580. $('#shuliangguize input[name="data_rule"][value="' + r +'"]').prop('checked', true);
  581. }
  582. });
  583. // 设置原设计数量读取
  584. $('#setListRule').click(function () {
  585. const rule = [];
  586. $('#shuliangguize input[name="data_rule"]:checked').each(function () {
  587. rule.push($(this).val());
  588. });
  589. const newListRule = {
  590. source: parseInt($('#shuliangguize input[name="data_source"]:checked').val()),
  591. rule,
  592. };
  593. postData(preUrl + '/list/save', { type: 'list_rule', postData: JSON.stringify(newListRule) }, function (result) {
  594. listRule = newListRule;
  595. $('#shuliangguize').modal('hide');
  596. });
  597. })
  598. }
  599. let changeListData;
  600. let gclGatherData;
  601. let dealBillList;
  602. const billUrl = window.location.pathname.split('/').slice(0, 4).join('/');
  603. postData(billUrl + '/defaultBills', {}, function (result) {
  604. gclGatherModel.loadLedgerData(result.bills);
  605. gclGatherModel.loadPosData(result.pos);
  606. gclGatherData = gclGatherModel.gatherGclData();
  607. gclGatherData = _.filter(gclGatherData, function (item) {
  608. return item.leafXmjs && item.leafXmjs.length !== 0;
  609. });
  610. // 数组去重
  611. dealBillList = result.dealBills;
  612. changeListData = gclGatherData;
  613. console.log(changeListData, dealBillList);
  614. SpreadJsObj.initSpreadSettingEvents(changeSpreadSetting, changeCol);
  615. SpreadJsObj.initSheet(changeSpreadSheet, changeSpreadSetting);
  616. SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
  617. changeSpreadObj.makeSjsFooter();
  618. // 计算最新的变更总额和change的total_price是否一致,不一致则更新
  619. if (change.status !== auditConst.status.checked) {
  620. // let new_tp = 0;
  621. const updateArray = [];
  622. for (const c of changeList) {
  623. const oneUpdate = {};
  624. console.log(ZhCalc.round(c.camount, findDecimal(c.unit)), c.camount);
  625. if (ZhCalc.round(c.oamount, findDecimal(c.unit)) !== c.oamount) oneUpdate.oamount = ZhCalc.round(c.oamount, findDecimal(c.unit));
  626. if (ZhCalc.round(c.camount, findDecimal(c.unit)) !== c.camount) oneUpdate.camount = ZhCalc.round(c.camount, findDecimal(c.unit));
  627. if (ZhCalc.round(c.unit_price, unitPriceUnit) !== c.unit_price) oneUpdate.unit_price = ZhCalc.round(c.unit_price, unitPriceUnit);
  628. if (!_.isEmpty(oneUpdate)) {
  629. oneUpdate.id = c.id;
  630. updateArray.push(oneUpdate);
  631. }
  632. // new_tp = ZhCalc.add(new_tp, ZhCalc.round(ZhCalc.mul(ZhCalc.round(c.spamount, findDecimal(c.unit)), ZhCalc.round(c.unit_price, unitPriceUnit)), totalPriceUnit));
  633. }
  634. console.log(updateArray);
  635. if (updateArray.length > 0) {
  636. // 更新至服务器
  637. postData(preUrl + '/list/save', { type:'paste', updateData: updateArray }, function (result) {
  638. changeList = result;
  639. SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
  640. changeSpreadObj.makeSjsFooter();
  641. });
  642. }
  643. // if (change.total_price && change.total_price !== new_tp) {
  644. // postData(preUrl + '/list/save', {type: 'update_tp', updateData: new_tp}, function (result) {
  645. // });
  646. // }
  647. }
  648. });
  649. });
  650. /**
  651. * 校验文件大小、格式
  652. * @param {Array} files 文件数组
  653. */
  654. function validateFiles(files) {
  655. if (files.length > 10) {
  656. toastr.error('至多同时上传10个文件');
  657. return false
  658. }
  659. return files.every(file => {
  660. if (file.size > 1024 * 1024 * 30) {
  661. toastr.error('文件大小限制为30MB');
  662. return false
  663. }
  664. if (whiteList.indexOf('.' + file.ext) === -1) {
  665. toastr.error('请上传正确的格式文件');
  666. return false
  667. }
  668. return true
  669. })
  670. }
  671. function findDecimal(unit) {
  672. let value = precision.other.value;
  673. const changeUnits = precision;
  674. for (const d in changeUnits) {
  675. if (changeUnits[d].unit !== undefined && changeUnits[d].unit === unit) {
  676. value = changeUnits[d].value;
  677. break;
  678. }
  679. }
  680. return value;
  681. }
  682. const is_numeric = (value) => {
  683. if (typeof(value) === 'object') {
  684. return false;
  685. } else {
  686. return !Number.isNaN(Number(value)) && value.toString().trim() !== '';
  687. }
  688. };