change_plan_information.js 42 KB

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