financial_pay_detail.js 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748
  1. $(function () {
  2. autoFlashHeight();
  3. handleFileList(fileList);
  4. $('#file-ok').click(function () {
  5. const files = Array.from($('#file-modal')[0].files)
  6. const valiData = files.map(v => {
  7. const ext = v.name.substring(v.name.lastIndexOf('.') + 1)
  8. return {
  9. size: v.size,
  10. ext
  11. }
  12. });
  13. if (validateFiles(valiData)) {
  14. if (files.length) {
  15. const formData = new FormData();
  16. files.forEach(file => {
  17. formData.append('name', file.name);
  18. formData.append('size', file.size);
  19. formData.append('file', file);
  20. })
  21. postDataWithFile(preUrl + '/file/upload', formData, function (result) {
  22. handleFileList(result);
  23. $('#file-cancel').click();
  24. });
  25. }
  26. }
  27. })
  28. function handleFileList(files = []) {
  29. $('#file-content').empty();
  30. // const { uncheck, checkNo } = auditConst.status
  31. const newFiles = files.map(file => {
  32. let showDel = false;
  33. if (file.uid === cur_uid) {
  34. if (financialPay.status === auditConst.status.checked) {
  35. showDel = false
  36. } else {
  37. showDel = true
  38. }
  39. }
  40. return {...file, showDel}
  41. })
  42. let html = financialPay.filePermission ? `<tr><td colspan="5"><a href="#addfujian" data-toggle="modal" class="btn btn-primary btn-sm" data-placement="bottom" title="">上传附件</a></td></tr>` : '';
  43. newFiles.forEach((file, idx) => {
  44. if (file.showDel) {
  45. 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="/financial/${file.spid}/pay/${file.fpid}/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>`
  46. } else {
  47. 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="/financial/${file.spid}/pay/${file.fpid}/file/${file.id}/download" class="mr-2"><i class="fa fa-download"></i></a></td></tr>`
  48. }
  49. })
  50. $('#file-content').append(html);
  51. }
  52. $('#file-content').on('click', 'a', function () {
  53. if ($(this).hasClass('file-del')) {
  54. const id = $(this).data('id');
  55. postData(preUrl + '/file/delete', {id}, (result) => {
  56. handleFileList(result);
  57. })
  58. }
  59. });
  60. // 回车提交
  61. $('#pay-table input').on('keypress', function () {
  62. if(window.event.keyCode === 13) {
  63. $(this).blur();
  64. }
  65. });
  66. $('#pay-table input').blur(function () {
  67. const val_name = $(this).data('name');
  68. let val = _.trim($(this).val()) !== '' ? _.trim($(this).val()) : null;
  69. switch(val_name) {
  70. default:
  71. if(val && val.length > 255) {
  72. toastr.error('超出字段范围,请缩减');
  73. $(this).val(financialPay[val_name]);
  74. return false;
  75. }
  76. break;
  77. }
  78. updatePayMsg(val_name, val, $(this));
  79. });
  80. $('#pay-table textarea').blur(function () {
  81. const val_name = $(this).data('name');
  82. let val = _.trim($(this).val()) !== '' ? _.trim($(this).val()) : null;
  83. updatePayMsg(val_name, val, $(this));
  84. });
  85. $('#pay-table select').change(function () {
  86. const val_name = $(this).attr('data-name');
  87. let val = _.trim($(this).val()) !== '' ? _.trim($(this).val()) : null;
  88. updatePayMsg(val_name, val, $(this));
  89. });
  90. function updatePayMsg(val_name, val, _self) {
  91. if(financialPay[val_name] !== val) {
  92. postData(preUrl + '/save', { type: 'pay_save', name: val_name, val}, function (result) {
  93. financialPay[val_name] = val;
  94. _self.val(financialPay[val_name]);
  95. }, function () {
  96. _self.val(financialPay[val_name]);
  97. })
  98. } else {
  99. $(this).val(financialPay[val_name]);
  100. }
  101. }
  102. const payContractSpread = SpreadJsObj.createNewSpread($('#pay-contract-spread')[0]);
  103. const payContractSpreadSheet = payContractSpread.getActiveSheet();
  104. const payContractSpreadSetting = {
  105. cols: [
  106. {title: '合同编号', colSpan: '1', rowSpan: '2', field: 'c_code', hAlign: 0, width: 110, formatter: '@', readOnly: true, backColor2: 'backColor.fromContract'},
  107. {title: '合同名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 130, formatter: '@', readOnly: true, backColor2: 'backColor.fromContract'},
  108. {title: '合同金额', colSpan: '1', rowSpan: '2', field: 'total_price', hAlign: 2, width: 80, type: 'Number', readOnly: 'readOnly.isEdit'},
  109. {title: '收款单位', colSpan: '1', rowSpan: '2', field: 'entity', hAlign: 1, width: 130, formatter: '@', readOnly: 'readOnly.isEdit', cellType: 'ellipsisAutoTip', scrollHeightClass: '.sjs-height-0'},
  110. {title: '收款单位账号', colSpan: '1', rowSpan: '2', field: 'bank_account', hAlign: 1, formatter: '@', width: 130, readOnly: 'readOnly.isEdit', cellType: 'ellipsisAutoTip', scrollHeightClass: '.sjs-height-0'},
  111. {title: '收款单位开户行', colSpan: '1', rowSpan: '2', field: 'bank', hAlign: 1, formatter: '@', width: 130, readOnly: 'readOnly.isEdit', cellType: 'ellipsisAutoTip', scrollHeightClass: '.sjs-height-0'},
  112. {title: '小额支出', colSpan: '1', rowSpan: '2', field: 'small_expenses', cellType: 'checkbox', hAlign: 1, width: 60, readOnly: 'readOnly.isEdit2'},
  113. {title: '支付金额', colSpan: '1', rowSpan: '2', field: 'pay_price', hAlign: 2, width: 80, type: 'Number', readOnly: 'readOnly.isEdit2'},
  114. {title: '累计支付', colSpan: '1', rowSpan: '2', field: 'accumulate_pay_price', getValue: 'getValue.accumulate_pay_price', hAlign: 2, width: 80, type: 'Number', readOnly: true },
  115. {title: '结算金额', colSpan: '1', rowSpan: '2', field: 'settle_price', hAlign: 2, width: 80, type: 'Number', readOnly: 'readOnly.isEdit2'},
  116. {title: '累计结算', colSpan: '1', rowSpan: '2', field: 'accumulate_settle_price', getValue: 'getValue.accumulate_settle_price', hAlign: 2, width: 80, type: 'Number', readOnly: true },
  117. {title: '未结算', colSpan: '1', rowSpan: '2', field: 'not_pay_price', getValue: 'getValue.not_pay_price', hAlign: 2, width: 80, type: 'Number', readOnly: true },
  118. {title: '支付方式', colSpan: '1', rowSpan: '2', field: 'pay_type', hAlign: 1, width: 80, readOnly: 'readOnly.isEdit2', cellType: 'unit', comboItems: payTypeList },
  119. {title: '发票', colSpan: '1', rowSpan: '2', field: 'bill', hAlign: 1, cellType: 'checkbox', width: 60, readOnly: 'readOnly.isEdit2' },
  120. {title: '附件', colSpan: '1', rowSpan: '2', field: 'attachment', hAlign: 0, width: 60, readOnly: true, cellType: 'imageBtn',
  121. normalImg: '#rela-file-icon', hoverImg: '#rela-file-hover', getValue: 'getValue.attachment' },
  122. ],
  123. emptyRows: 0,
  124. headRows: 2,
  125. headRowHeight: [25, 25],
  126. defaultRowHeight: 21,
  127. headerFont: '12px 微软雅黑',
  128. font: '12px 微软雅黑',
  129. // readOnly: readOnly,
  130. localCache: {
  131. key: 'pay-contract-spread',
  132. colWidth: true,
  133. }
  134. };
  135. payContractSpreadSetting.imageClick = function (data) {
  136. makeAttTable(data);
  137. $('#pay-contract-file').modal('show');
  138. };
  139. const payContractCol = {
  140. getValue: {
  141. attachment: function (data) {
  142. return data.files ? data.files.length : 0;
  143. },
  144. accumulate_pay_price: function (data) {
  145. return !data.cid ? data.pay_price : data.accumulate_pay_price;
  146. },
  147. accumulate_settle_price: function (data) {
  148. return !data.cid ? data.settle_price : data.accumulate_settle_price;
  149. },
  150. not_pay_price: function (data) {
  151. return ZhCalc.sub(data.total_price || 0, data.accumulate_settle_price || 0);
  152. },
  153. },
  154. readOnly: {
  155. isEdit: function (data) {
  156. return data.c_code || readOnly;
  157. },
  158. isEdit2: function (data) {
  159. return readOnly;
  160. },
  161. },
  162. backColor: {
  163. fromContract: function (data) {
  164. if (!data.cid) {
  165. return '#f8f9fa';
  166. }
  167. },
  168. }
  169. }
  170. const payContractSpreadObj = {
  171. deletePress: function (sheet) {
  172. return;
  173. },
  174. valueChanged: function (e, info) {
  175. // 防止ctrl+z撤销数据
  176. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  177. },
  178. };
  179. if (!readOnly) {
  180. payContractSpreadObj.add = function () {
  181. postData(preUrl + '/save', { type: 'contract_white_add' }, function (data) {
  182. contractList.push(data);
  183. SpreadJsObj.loadSheetData(payContractSpreadSheet, SpreadJsObj.DataType.Data, contractList);
  184. });
  185. };
  186. payContractSpreadObj.del = function (sheet) {
  187. const selection = sheet.getSelections();
  188. const row = selection[0].row, count = selection[0].rowCount;
  189. const sortData = sheet.zh_data;
  190. const ids = [];
  191. for (let iRow = 0; iRow < count; iRow++) {
  192. if (sortData[iRow + row]) {
  193. ids.push(sortData[iRow + row].id);
  194. }
  195. }
  196. if (ids.length > 0) {
  197. postData(preUrl + '/save', {type: 'contract_del', ids}, function (result) {
  198. contractList = result.contractList;
  199. $('#pay-total-price').val(result.tp || 0);
  200. SpreadJsObj.loadSheetData(payContractSpreadSheet, SpreadJsObj.DataType.Data, contractList);
  201. });
  202. }
  203. };
  204. payContractSpreadObj.editEnded = function (e, info) {
  205. if (info.sheet.zh_setting) {
  206. const type = SpreadJsObj.getSelectObject(info.sheet) ? 'contract_update' : false;
  207. if (!type) {
  208. toastr.error('该数据不存在');
  209. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  210. return;
  211. }
  212. const select = type === 'contract_update' ? SpreadJsObj.getSelectObject(info.sheet) : {};
  213. const col = info.sheet.zh_setting.cols[info.col];
  214. if (col.field === 'small_expenses' || col.field === 'bill' || col.field === 'attachment') {
  215. return;
  216. }
  217. // 未改变值则不提交
  218. let validText = col.type === 'Number' ? (is_numeric(info.editingText) ? parseFloat(info.editingText) : 0) : (info.editingText ? trimInvalidChar(info.editingText) : '');
  219. const orgValue = type === 'contract_update' ? select[col.field] : '';
  220. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  221. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  222. return;
  223. }
  224. if (col.field === 'accumulate_pay_price' || col.field === 'accumulate_settle_price' || col.field === 'not_pay_price') {
  225. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  226. return;
  227. }
  228. // 判断部分值是否输入的是数字判断和数据计算
  229. if (col.type === 'Number') {
  230. if (isNaN(validText)) {
  231. toastr.error('不能输入其它非数字类型字符');
  232. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  233. return;
  234. }
  235. }
  236. if (col.field === 'pay_price') {
  237. select.accumulate_pay_price = ZhCalc.add(ZhCalc.sub(select.accumulate_pay_price, select.pay_price), validText);
  238. }
  239. if (col.field === 'settle_price') {
  240. select.accumulate_settle_price = ZhCalc.add(ZhCalc.sub(select.accumulate_settle_price, select.settle_price), validText);
  241. }
  242. select[col.field] = validText;
  243. const uData = {
  244. id: select.id,
  245. };
  246. uData[col.field] = validText;
  247. console.log(select, type);
  248. delete select.waitingLoading;
  249. // 更新至服务器
  250. postData(preUrl + '/save', { type, updateData: uData }, function (result) {
  251. if(type === 'contract_update') {
  252. contractList.splice(info.row, 1, select);
  253. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  254. $('#pay-total-price').val(result.tp || 0);
  255. }
  256. }, function () {
  257. select[col.field] = orgValue;
  258. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  259. });
  260. }
  261. };
  262. payContractSpreadObj.clipboardPasted = function(e, info, cellRange) {
  263. if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
  264. info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
  265. }
  266. const hint = {
  267. cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
  268. numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
  269. };
  270. if (info.sheet.zh_setting) {
  271. const sortData = info.sheet.zh_data || [];
  272. const range = info.cellRange;
  273. const data = [];
  274. let haveNew = false;
  275. for (let iRow = 0; iRow < range.rowCount; iRow++) {
  276. let bPaste = true;
  277. const curRow = range.row + iRow;
  278. // const materialData = JSON.parse(JSON.stringify(sortData[curRow]));
  279. const cLData = curRow >= sortData.length ? {} : {id: sortData[curRow].id};
  280. haveNew = curRow >= sortData.length ? curRow : false;
  281. const hintRow = range.rowCount > 1 ? curRow : '';
  282. let sameCol = 0;
  283. for (let iCol = 0; iCol < range.colCount; iCol++) {
  284. const curCol = range.col + iCol;
  285. const colSetting = info.sheet.zh_setting.cols[curCol];
  286. if (!colSetting) continue;
  287. // cLData[colSetting.field] = trimInvalidChar(info.sheet.getText(curRow, curCol));
  288. let validText = info.sheet.getText(curRow, curCol);
  289. validText = colSetting.type === 'Number' ? (is_numeric(validText) ? parseFloat(validText) : 0) : (validText ? trimInvalidChar(validText) : '');
  290. const orgValue = curRow >= sortData.length ? '' : sortData[curRow][colSetting.field];
  291. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  292. sameCol++;
  293. if (range.colCount === sameCol) {
  294. bPaste = false;
  295. }
  296. continue;
  297. }
  298. if (colSetting.type === 'Number') {
  299. if (isNaN(validText)) {
  300. // toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
  301. toastMessageUniq(hint.numberExpr);
  302. bPaste = false;
  303. continue;
  304. }
  305. }
  306. cLData[colSetting.field] = validText;
  307. }
  308. if (bPaste) {
  309. data.push(cLData);
  310. // rowData.push(curRow);
  311. } else {
  312. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  313. }
  314. }
  315. if (data.length === 0) {
  316. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  317. return;
  318. }
  319. console.log(data);
  320. // 更新至服务器
  321. postData(preUrl + '/save', { type:'contract_paste', updateData: data }, function (result) {
  322. contractList = result.contractList;
  323. if (haveNew) {
  324. SpreadJsObj.initSheet(payContractSpreadSheet, payContractSpreadSetting);
  325. }
  326. SpreadJsObj.loadSheetData(payContractSpreadSheet, SpreadJsObj.DataType.Data, contractList);
  327. if (haveNew) {
  328. payContractSpreadSheet.setSelection(haveNew, 1, 1, 1);
  329. payContractSpreadSheet.getParent().focus();
  330. payContractSpreadSheet.showRow(haveNew, spreadNS.VerticalPosition.center);
  331. }
  332. $('#pay-total-price').val(result.tp || 0);
  333. }, function () {
  334. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  335. return;
  336. });
  337. }
  338. };
  339. payContractSpreadObj.buttonClicked = function (e, info) {
  340. if (info.sheet.zh_setting) {
  341. const select = SpreadJsObj.getSelectObject(info.sheet);
  342. const col = info.sheet.zh_setting.cols[info.col];
  343. if (!select) {
  344. toastr.error('请添加合同金额再勾选');
  345. if (info.sheet.isEditing()) {
  346. info.sheet.endEdit(true);
  347. }
  348. return;
  349. } else if (col.field === 'small_expenses' || col.field === 'bill') {
  350. if (info.sheet.isEditing()) {
  351. info.sheet.endEdit(true);
  352. }
  353. const is_select = info.sheet.getValue(info.row, info.col) ? 0 : 1;
  354. if (select[col.field] !== is_select) {
  355. const uData = { id: select.id };
  356. select[col.field] = is_select;
  357. uData[col.field] = select[col.field];
  358. console.log(uData);
  359. postData(preUrl + '/save', { type: 'contract_update', updateData: uData }, function (result) {
  360. contractList.splice(info.row, 1, select);
  361. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  362. }, function () {
  363. select[col.field] = info.sheet.getValue(info.row, info.col) ? 1 : 0;
  364. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  365. });
  366. }
  367. }
  368. }
  369. };
  370. payContractSpread.bind(spreadNS.Events.EditEnded, payContractSpreadObj.editEnded);
  371. payContractSpread.bind(spreadNS.Events.ButtonClicked, payContractSpreadObj.buttonClicked);
  372. payContractSpread.bind(spreadNS.Events.ClipboardPasted, payContractSpreadObj.clipboardPasted);
  373. payContractSpread.bind(spreadNS.Events.ValueChanged, payContractSpreadObj.valueChanged);
  374. SpreadJsObj.addDeleteBind(payContractSpread, payContractSpreadObj.deletePress);
  375. // 右键菜单
  376. $.contextMenu({
  377. selector: '#pay-contract-spread',
  378. build: function ($trigger, e) {
  379. const target = SpreadJsObj.safeRightClickSelection($trigger, e, payContractSpread);
  380. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  381. },
  382. items: {
  383. 'createAdd': {
  384. name: '添加',
  385. icon: 'fa-sign-in',
  386. callback: function (key, opt) {
  387. payContractSpreadObj.add(payContractSpreadSheet);
  388. },
  389. },
  390. 'createAdd2': {
  391. name: '添加合同',
  392. icon: 'fa-sign-in',
  393. callback: function (key, opt) {
  394. $('#add-deal').modal('show');
  395. },
  396. },
  397. 'delete': {
  398. name: '删除',
  399. icon: 'fa-remove',
  400. callback: function (key, opt) {
  401. payContractSpreadObj.del(payContractSpreadSheet);
  402. },
  403. disabled: function (key, opt) {
  404. if (payContractSpreadSheet.zh_data) {
  405. const selection = payContractSpreadSheet.getSelections();
  406. // return changeSpreadSheet.zh_data.length < selection[0].row + selection[0].rowCount;
  407. return payContractSpreadSheet.getRowCount() < selection[0].row + selection[0].rowCount;
  408. } else {
  409. return true;
  410. }
  411. }
  412. },
  413. }
  414. });
  415. $('#add-white-contract').click(function () {
  416. payContractSpreadObj.add(payContractSpreadSheet);
  417. });
  418. let contracts = [];
  419. let contractTrees = [];
  420. const sqTreeSetting = {
  421. id: 'contract_id',
  422. pid: 'contract_pid',
  423. order: 'order',
  424. level: 'level',
  425. rootId: -1,
  426. keys: ['id', 'tid', 'spid'],
  427. };
  428. const sqTree = createNewPathTree('base', sqTreeSetting);
  429. $('#add-deal').on('show.bs.modal', function () {
  430. $('#contract-tree').val('0');
  431. $('#contract-keyword').val('');
  432. $('#select-all-contract').prop('checked', false);
  433. postData(preUrl + '/save', { type: 'contract_list' }, function (result) {
  434. contracts = result.contracts;
  435. contractTrees = result.contractTrees;
  436. sqTree.loadDatas(contractTrees.concat(contracts));
  437. const level2Tree = _.filter(sqTree.nodes, function (item) {
  438. return item.level === 2 && !item.c_code;
  439. });
  440. contracts = _.filter(sqTree.nodes, function (item) {
  441. return item.c_code && item.c_code !== '';
  442. });
  443. makeContractListHtml(contracts);
  444. let html2 = '<option value="0">全部</option>';
  445. for (const t of level2Tree) {
  446. html2 += `<option value="${t.contract_id}">${t.name}</option>`;
  447. }
  448. $('#contract-tree').html(html2);
  449. });
  450. });
  451. function makeContractListHtml(list, hide = false) {
  452. let html = '';
  453. if (!hide) {
  454. for (const c of list) {
  455. const tree = _.find(contractTrees, function (item) {
  456. return item.contract_id === parseInt(c.full_path.split('-')[1] || 0);
  457. });
  458. html += `<tr class="text-center tr-show" data-id="${c.id}">
  459. <td><input type="checkbox" data-contract-id="${c.id}" ${_.findIndex(contractList, { cid: c.id }) !== -1 ? 'checked disabled' : ''}></td>
  460. <td>${tree ? tree.name : ''}</td>
  461. <td class="text-left">${c.c_code}</td>
  462. <td class="text-left">${c.name}</td>
  463. <td class="text-right">${c.total_price}</td>
  464. <td>${c.entity}</td>
  465. <td>${c.bank_account}</td>
  466. </tr>`;
  467. }
  468. $('#contract-list').html(html);
  469. } else {
  470. $('#contract-list tr').removeClass('tr-show').hide();
  471. for (const c of list) {
  472. $(`#contract-list tr[data-id="${c.id}"]`).addClass('tr-show').show();
  473. }
  474. }
  475. }
  476. $('body').on('change', '#contract-tree', function () {
  477. searchContracts();
  478. });
  479. $('#search-contract-btn').click(function () {
  480. searchContracts();
  481. });
  482. // 回车提交
  483. $('#contract-keyword').on('keypress', function () {
  484. if(window.event.keyCode === 13) {
  485. searchContracts();
  486. }
  487. });
  488. function searchContracts() {
  489. $('#select-all-contract').prop('checked', false);
  490. const keyword = $('#contract-keyword').val();
  491. const selectTree = $('#contract-tree').val();
  492. const list = _.filter(contracts, function (item) {
  493. return (selectTree !== '0' ? _.includes(item.full_path, '-' + selectTree + '-') : true) && (keyword !== '' ? (item.c_code.indexOf(keyword) > -1 || item.name.indexOf(keyword) > -1) : true);
  494. });
  495. makeContractListHtml(list, true);
  496. }
  497. $('#select-all-contract').click(function () {
  498. $('#contract-list tr[class*="tr-show"] input:not(:disabled)').prop('checked', $(this).prop('checked'));
  499. });
  500. $('#add-contract-btn').click(function () {
  501. const selects = [];
  502. $('#contract-list input:checked:not(:disabled)').each(function () {
  503. selects.push($(this).data('contract-id'));
  504. });
  505. if (selects.length === 0) {
  506. toastr.warning('请选择合同再添加');
  507. return;
  508. }
  509. console.log(selects);
  510. postData(preUrl + '/save', { type: 'contract_add', contract_ids: selects }, function (result) {
  511. $('#add-deal').modal('hide');
  512. contractList = result.contractList;
  513. SpreadJsObj.loadSheetData(payContractSpreadSheet, SpreadJsObj.DataType.Data, contractList);
  514. // $('#pay-total-price').val(result.tp || 0);
  515. });
  516. });
  517. }
  518. SpreadJsObj.initSpreadSettingEvents(payContractSpreadSetting, payContractCol);
  519. SpreadJsObj.initSheet(payContractSpreadSheet, payContractSpreadSetting);
  520. postData(preUrl + '/save', { type: 'pay_contract_list' }, function (result) {
  521. contractList = result;
  522. SpreadJsObj.loadSheetData(payContractSpreadSheet, SpreadJsObj.DataType.Data, result);
  523. });
  524. // 上传附件
  525. $('#pay-contract-file input[type="file"]').change(function () {
  526. const files = Array.from(this.files);
  527. const valiData = files.map(v => {
  528. const ext = v.name.substring(v.name.lastIndexOf('.') + 1)
  529. return {
  530. size: v.size,
  531. ext
  532. }
  533. });
  534. const fpcid = $('#file-contract-id').val();
  535. if (!$('#pay-contract-file input[name="type"]:checked').val()) {
  536. toastr.error('请选择资料类型');
  537. return false;
  538. }
  539. const fpcInfo = _.find(contractList, { id: parseInt(fpcid) });
  540. if (!fpcInfo) {
  541. toastr.warning('不存在该资金支付明细');
  542. $('#pay-contract-file input[type="file"]').val('');
  543. return;
  544. }
  545. if (validateFiles(valiData)) {
  546. if (files.length) {
  547. const formData = new FormData()
  548. formData.append('type', $('#pay-contract-file input[name="type"]:checked').val());
  549. formData.append('fpcid', fpcInfo.id);
  550. files.forEach(file => {
  551. formData.append('name', file.name)
  552. formData.append('size', file.size)
  553. formData.append('file', file)
  554. })
  555. postDataWithFile(preUrl + '/file/upload', formData, function (result) {
  556. fpcInfo.files = result;
  557. makeAttTable(fpcInfo);
  558. SpreadJsObj.reLoadRowData(payContractSpreadSheet, contractList.indexOf(fpcInfo));
  559. });
  560. }
  561. }
  562. $('#transfer-file input[type="file"]').val('');
  563. });
  564. $('body').on('click', '#pay-contract-file .file-del', function () {
  565. const fpcid = $('#file-contract-id').val();
  566. const fpcInfo = _.find(contractList, { id: parseInt(fpcid) });
  567. if (!fpcInfo) {
  568. toastr.warning('不存在该资金支付明细');
  569. return;
  570. }
  571. const fid = $(this).data('id');
  572. deleteAfterHint(function () {
  573. postData(preUrl + '/file/delete', { fpcid: fpcInfo.id, id: fid }, (result) => {
  574. fpcInfo.files = result;
  575. makeAttTable(fpcInfo);
  576. SpreadJsObj.reLoadRowData(payContractSpreadSheet, contractList.indexOf(fpcInfo));
  577. });
  578. }, '确认删除该文件?');
  579. });
  580. function makeAttTable(payNode) {
  581. $('#file-contract-id').val(payNode.id);
  582. const files = payNode.files;
  583. let filesHtml = '';
  584. const newFiles = files.map(file => {
  585. let showDel = false;
  586. if (file.uid === cur_uid) {
  587. if (file.type === 1 && financialPay.readOnly) {
  588. showDel = false;
  589. } else {
  590. showDel = true;
  591. }
  592. }
  593. return {...file, showDel}
  594. });
  595. newFiles.forEach((file, idx) => {
  596. filesHtml += `<tr class="text-center">
  597. <td>${idx + 1}</td><td class="text-left"><a href="${file.filepath}" target="_blank">${file.filename}</a></td>
  598. <td>${file.username}</td>
  599. <td>${file.type === 1 ? (financialPay.status !== auditConst.status.checked && file.uid === cur_uid ? '<input type="text" data-id="' + file.id + '" class="file-bill form-control form-control-sm" value="' + file.bill + '" />' : file.bill) : '' }</td>
  600. <td>${moment(file.upload_time).format('YYYY-MM-DD HH:mm:ss')}</td>
  601. <td>
  602. <div class="btn-group-table">
  603. ${file.viewpath ? `<a href="${file.viewpath}" target="_blank" class="mr-1"><i class="fa fa-eye fa-fw"></i></a>` : ''}
  604. <a href="/financial/${payNode.spid}/pay/${payNode.fpid}/file/${file.id}/download" class="mr-1"><i class="fa fa-download fa-fw"></i></a>
  605. ${file.showDel ? `<a href="javascript: void(0);" class="text-danger file-del mr-1" data-id="${file.id}"><i class="fa fa-trash-o fa-fw text-danger"></i></a>` : ''}
  606. </div>
  607. </td>
  608. </tr>`;
  609. });
  610. $('#contract-files').html(filesHtml);
  611. }
  612. $('body').on('change', '#contract-files .file-bill', function () {
  613. const bill = $(this).val();
  614. const fid = $(this).data('id');
  615. saveBills(bill, fid);
  616. });
  617. function saveBills(bill, fid) {
  618. const fpcid = $('#file-contract-id').val();
  619. const fpcInfo = _.find(contractList, { id: parseInt(fpcid) });
  620. if (!fpcInfo) {
  621. toastr.warning('不存在该资金支付明细');
  622. return;
  623. }
  624. postData(preUrl + '/save', { type: 'file_bill', id: fid, bill }, function (result) {
  625. const fileInfo = _.find(fpcInfo.files, { id: fid });
  626. fileInfo.bill = bill;
  627. });
  628. }
  629. $.subMenu({
  630. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  631. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  632. key: 'menu.1.0.0',
  633. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  634. callback: function (info) {
  635. if (info.mini) {
  636. $('.panel-title').addClass('fluid');
  637. $('#sub-menu').removeClass('panel-sidebar');
  638. } else {
  639. $('.panel-title').removeClass('fluid');
  640. $('#sub-menu').addClass('panel-sidebar');
  641. }
  642. autoFlashHeight();
  643. }
  644. });
  645. });
  646. function checkStartFrom() {
  647. // 判断发票是否已上传
  648. if (!contractList || contractList.length === 0) {
  649. toastr.error('请添加合同再上报');
  650. return false;
  651. }
  652. let notBills = [];
  653. for (const c of contractList) {
  654. if (c.bill && _.findIndex(c.files, { type: 1 }) === -1) {
  655. notBills.push(c);
  656. }
  657. }
  658. if (notBills.length > 0) {
  659. for (const c of notBills) {
  660. if (c.cid) {
  661. toastr.error(`合同 ${c.c_code} 未上传发票`);
  662. } else {
  663. toastr.error(`收款单位 ${c.entity} 未上传发票`);
  664. }
  665. }
  666. return false;
  667. }
  668. return true;
  669. }
  670. // texterea换行
  671. function auditCheck(i) {
  672. // const inlineRadio1 = $('#inlineRadio1:checked').val()
  673. // const inlineRadio2 = $('#inlineRadio2:checked').val()
  674. const opinion = $('textarea[name="opinion"]').eq(i).val().replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' ');
  675. $('textarea[name="opinion"]').eq(i).val(opinion);
  676. // if (i === 1) {
  677. // if (!inlineRadio1 && !inlineRadio2) {
  678. // if (!$('#warning-text').length) {
  679. // $('#reject-process').prepend('<p id="warning-text" style="color: red; margin: 0;">请选择退回流程</p>');
  680. // }
  681. // return false;
  682. // }
  683. // if ($('#warning-text').length) $('#warning-text').remove()
  684. // }
  685. return true;
  686. }
  687. /**
  688. * 校验文件大小、格式
  689. * @param {Array} files 文件数组
  690. */
  691. function validateFiles(files) {
  692. if (files.length > 10) {
  693. toastr.error('至多同时上传10个文件');
  694. return false
  695. }
  696. return files.every(file => {
  697. if (file.size > 1024 * 1024 * 30) {
  698. toastr.error('文件大小限制为30MB');
  699. return false
  700. }
  701. if (whiteList.indexOf('.' + file.ext.toLowerCase()) === -1) {
  702. toastr.error('请上传正确的格式文件');
  703. return false
  704. }
  705. return true
  706. })
  707. }
  708. const is_numeric = (value) => {
  709. if (typeof(value) === 'object') {
  710. return false;
  711. } else {
  712. return !Number.isNaN(Number(value)) && value.toString().trim() !== '';
  713. }
  714. };