change_set.js 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727
  1. 'use strict';
  2. /**
  3. * 变更令上报和重新上报功能js
  4. *
  5. * @author EllisRan.
  6. * @date 2018/11/22
  7. * @version
  8. */
  9. $(document).ready(() => {
  10. // 编号排序,多重判断
  11. function sortByCode(a, b) {
  12. let code1 = a.code.split('-');
  13. let code2 = b.code.split('-');
  14. let code1length = code1.length;
  15. let code2length = code2.length;
  16. for (let i = 0; i < code1length; i ++) {
  17. if (i+1 <= code2length) {
  18. if (code1[i] != code2[i]) {
  19. if (!/^\d+$/.test(code1[i])) {
  20. return code1[i].charCodeAt() - code2[i].charCodeAt();
  21. } else {
  22. return parseInt(code1[i]) - parseInt(code2[i]);
  23. }
  24. } else if (i+1 == code1length && code1[i] == code2[i]) {
  25. if (code1length == code2length) {
  26. return 0;
  27. } else {
  28. return code1length - code2length;
  29. }
  30. }
  31. } else {
  32. if (i+1 >= code1length) {
  33. return 1;
  34. } else {
  35. return -1;
  36. }
  37. }
  38. }
  39. }
  40. gclGatherModel.loadLedgerData(ledger);
  41. gclGatherModel.loadPosData(pos);
  42. const gclGatherData = gclGatherModel.gatherGclData();
  43. for (const ggd in gclGatherData) {
  44. gclGatherData[ggd].code = gclGatherData[ggd].b_code;
  45. }
  46. console.log(gclGatherData);
  47. // 数组去重
  48. for (const db of gclGatherData) {
  49. const exist_index = dealBillList.findIndex(function (item) {
  50. return item.code === db.code && item.name === db.name && item.unit === db.unit && item.unit_price === db.unit_price;
  51. });
  52. if (exist_index !== -1) {
  53. dealBillList.splice(exist_index, 1);
  54. }
  55. }
  56. const changeListData = gclGatherData.concat(dealBillList).sort(sortByCode);
  57. // 先加载台账数据
  58. let listHtml = '';
  59. let list_index = 1;
  60. let gcl_index = 0;
  61. for (const gcl of changeListData) {
  62. const unit = gcl.unit !== undefined && gcl.unit !== null ? gcl.unit : '';
  63. const quantity = gcl.quantity !== null && gcl.quantity !== undefined ? (unit !== '' ? roundnum(gcl.quantity, findDecimal(gcl.unit)) : gcl.quantity) : 0;
  64. const unit_price = gcl.unit_price !== null && gcl.unit_price !== undefined ? gcl.unit_price : 0;
  65. let gclhtml = gcl.leafXmjs !== undefined && gcl.leafXmjs !== null ? ' data-gcl="' + gcl_index + '"': '';
  66. gcl_index = gclhtml !== '' ? ++gcl_index : gcl_index;
  67. listHtml += '<tr data-lid="' + list_index + '"'+ gclhtml +' data-index="' + list_index + '" data-bwmx="">' +
  68. '<td>' + list_index + '</td>' +
  69. '<td>' + gcl.code + '</td>' +
  70. '<td>' + gcl.name + '</td>' +
  71. '<td>' + unit + '</td>' +
  72. '<td>' + roundnum(unit_price, unitPriceUnit) + '</td>' +
  73. '<td>' + quantity + '</td>' +
  74. // '<td>' + roundnum(parseFloat(gcl.unit_price).mul(parseFloat(gcl.quantity)), totalPriceUnit) + '</td>' +
  75. '</tr>';
  76. list_index++;
  77. }
  78. // // 再加载签约清单
  79. // for (const db of dealBillList) {
  80. // const unit = db.unit !== undefined && db.unit !== null ? db.unit : '';
  81. // const quantity = db.quantity !== null && db.quantity !== undefined ? (unit !== '' ? roundnum(db.quantity, findDecimal(db.unit)) : db.quantity) : 0;
  82. // const unit_price = db.unit_price !== null && db.unit_price !== undefined ? db.unit_price : 0;
  83. // listHtml += '<tr data-lid="' + db.id + '" data-index="' + list_index + '" data-bwmx="">' +
  84. // '<td>' + list_index + '</td>' +
  85. // '<td>' + db.code + '</td>' +
  86. // '<td>' + db.name + '</td>' +
  87. // '<td>' + unit + '</td>' +
  88. // '<td>' + roundnum(unit_price, unitPriceUnit) + '</td>' +
  89. // '<td>' + quantity + '</td>' +
  90. // // '<td>' + roundnum(parseFloat(db.unit_price).mul(parseFloat(db.quantity)), totalPriceUnit) + '</td>' +
  91. // '</tr>';
  92. // list_index++;
  93. // }
  94. $('#table-list-select').html(listHtml);
  95. // 上报时按钮点击
  96. $('a[data-target="#sub-ap"]').on('click', function () {
  97. let category = $(this).attr('data-category');
  98. if (category === 'save_change') {
  99. // 保存修改modal
  100. $('.up-change').hide();
  101. $('.save-change').show();
  102. } else {
  103. // 上报审批modal
  104. $('.up-change').show();
  105. $('.save-change').hide();
  106. }
  107. });
  108. // 重新上报时按钮点击
  109. $('a[data-target="#sub-sp2"]').on('click', function () {
  110. let category = $(this).data('category');
  111. if (category === 'save_change') {
  112. // 保存修改modal
  113. $('.up-change').hide();
  114. $('.save-change').show();
  115. } else {
  116. // 上报审批modal
  117. $('.up-change').show();
  118. $('.save-change').hide();
  119. }
  120. $('#hideSp').attr('data-category', category);
  121. });
  122. // 提交表单
  123. // 上报时按钮点击
  124. $('button[data-sumbit="sumbit_change"]').on('click', function () {
  125. let category = $(this).data('category');
  126. if (category === 'save_change') {
  127. // 保存修改modal
  128. $('#changeStatus').val(2);
  129. // 获取auditlist并填入input中
  130. getAuditList();
  131. if ($('input[name="code"]').val() === '') {
  132. toastr.error('申请编号不能为空!');
  133. return;
  134. }
  135. if ($('input[name="name"]').val() === '') {
  136. toastr.error('工程名称不能为空!');
  137. return;
  138. }
  139. $('#change_form').submit();
  140. } else {
  141. // 上报审批modal
  142. $('#changeStatus').val(1);
  143. getAuditList();
  144. let returnFlag = false;
  145. // 表单判断
  146. if ($('input[name="code"]').val() === '') {
  147. toastr.error('申请编号不能为空!');
  148. returnFlag = true;
  149. }
  150. if ($('input[name="name"]').val() === '') {
  151. toastr.error('工程名称不能为空!');
  152. returnFlag = true;
  153. }
  154. if ($('textarea[name="content"]').val() === '') {
  155. toastr.error('工程变更理由及内容不能为空!');
  156. returnFlag = true;
  157. }
  158. if ($('#change-list').val() === '' && $('#change-whitelist').val() === '') {
  159. toastr.error('请添加变更清单!');
  160. returnFlag = true;
  161. } else {
  162. let changeList = [];
  163. if ($('#change-list').val() !== '') {
  164. changeList = $('#change-list').val().split('^_^');
  165. }
  166. let changeWhiteList = [];
  167. if ($('#change-whitelist').val() !== '') {
  168. changeWhiteList = $('#change-whitelist').val().split('^_^');
  169. }
  170. changeList.push.apply(changeList, changeWhiteList);
  171. for (const [index, cl] of changeList.entries()) {
  172. const clInfo = cl.split(';');
  173. if (clInfo[0] === '' || clInfo[1] === '' || clInfo[3] === '' || clInfo[4] === '' || clInfo[5] === '') {
  174. toastr.error('变更清单第' + (index+1) + '行未完整填写数据(变更部位、变更详情可空)');
  175. returnFlag = true;
  176. }
  177. }
  178. }
  179. if ($('#changeaudit').val() === '') {
  180. toastr.error('请添加审批流程!');
  181. returnFlag = true;
  182. }
  183. if (returnFlag) {
  184. return;
  185. }
  186. $('#change_form').submit();
  187. $(this).attr('disabled', true);
  188. }
  189. });
  190. // 保存修改ajax提交(不刷新页面)
  191. $('#save_change').on('click', function () {
  192. // 保存修改modal
  193. $('#changeStatus').val(2);
  194. // 获取auditlist并填入input中
  195. getAuditList();
  196. if ($('input[name="code"]').val() === '') {
  197. toastr.error('申请编号不能为空!');
  198. return;
  199. }
  200. if ($('input[name="name"]').val() === '') {
  201. toastr.error('工程名称不能为空!');
  202. return;
  203. }
  204. $('#change_form').ajaxSubmit(function (result) {
  205. if ( result.err === 0) {
  206. $('.reduction-code').attr('data-code', $('input[name="code"]').val());
  207. toastr.success(result.msg);
  208. } else {
  209. toastr.error(result.msg);
  210. }
  211. });
  212. return false;
  213. });
  214. // 审批人分组选择
  215. $('#account_group').change(function () {
  216. let account_html = '<option value="0">选择审批人</option>';
  217. for (const account of accountList) {
  218. if (parseInt($(this).val()) === 0 || parseInt($(this).val()) === account.account_group) {
  219. const role = account.role !== '' ? '(' + account.role + ')' : '';
  220. const company = account.company !== '' ? ' -' + account.company : '';
  221. account_html += '<option value="' + account.id + '">' + account.name + role + company + '</option>';
  222. }
  223. }
  224. $('#account_list').html(account_html);
  225. });
  226. $('#hideSp').click(function () {
  227. $('#sub-sp2').modal('hide');
  228. });
  229. // 添加到审批流程中
  230. $('body').on('change', '#account_list', function () {
  231. let id = $(this).val();
  232. id = parseInt(id);
  233. if (id !== 0) {
  234. let auditListIdData = [];
  235. $('#auditList li').each(function () {
  236. let aid = $(this).data('auditid');
  237. auditListIdData.push(aid);
  238. });
  239. if (!in_array(auditListIdData, id)) {
  240. const accountInfo = accountList.find(function (item) {
  241. return item.id === id;
  242. });
  243. const user = accountInfo.id + '/%/' + accountInfo.name + '/%/' + accountInfo.role + '/%/' + accountInfo.company;
  244. const addhtml = '<li class="list-group-item" data-auditmsg="' + user + '"' +
  245. 'data-auditid="' + accountInfo.id + '" >' +
  246. '<a href="javascript:void(0);" class="text-danger pull-right remove_audit_btn">移除</a>' +
  247. '<span>' + (auditListIdData.length+1) + '</span> ' + accountInfo.name + ' <small class="text-muted">' + accountInfo.role + '</small>' +
  248. '<p class="m-0 ml-2"><small class="text-muted">' + accountInfo.company + '</small></p>' +
  249. '</li>';
  250. $('#auditList').append(addhtml);
  251. // 重新上报时。令其它的审批人流程图标转换
  252. $('#shenpi-audit-list li i').removeClass('fa-stop-circle').addClass('fa-chevron-circle-down');
  253. $('#shenpi-audit-list2 li i').removeClass('fa-stop-circle').addClass('fa-chevron-circle-down');
  254. // 添加新审批人
  255. const addhtml1 = '<li class="list-group-item" data-auditid="' + accountInfo.id + '" >' +
  256. '<i class="fa fa-stop-circle"></i> ' +
  257. accountInfo.name + ' <small class="text-muted">' + accountInfo.role + '</small><span class="pull-right">终审</span>' +
  258. '</li>';
  259. const addhtml2 = '<li class="list-group-item" data-auditid="' + accountInfo.id + '" >' +
  260. '<h5 class="card-title"><i class="fa fa-stop-circle"></i> ' +
  261. accountInfo.name + ' <small class="text-muted">' + accountInfo.role + '</small><span class="pull-right">终审</span>' +
  262. '</h5></li>';
  263. for (let i = 0; i < $('#shenpi-audit-list li').length; i++) {
  264. $('#shenpi-audit-list li').eq(i).find('.pull-right').text(transFormToChinese(i) + '审');
  265. $('#shenpi-audit-list2 li').eq(i).find('.pull-right').text(transFormToChinese(i) + '审');
  266. }
  267. $('#shenpi-audit-list li').eq(0).find('.pull-right').text('原报');
  268. $('#shenpi-audit-list2 li').eq(0).find('.pull-right').text('原报');
  269. $('#shenpi-audit-list li i').eq(0).removeClass('fa-chevron-circle-down').addClass('fa-play-circle');
  270. $('#shenpi-audit-list2 li i').eq(0).removeClass('fa-chevron-circle-down').addClass('fa-play-circle');
  271. $('#shenpi-audit-list').append(addhtml1);
  272. $('#shenpi-audit-list2').append(addhtml2);
  273. } else {
  274. toastr.error('审批流程中已存在该用户!');
  275. }
  276. }
  277. });
  278. // 移除审批流程的审批人
  279. $('body').on('click', '.remove_audit_btn', function () {
  280. const uid = $(this).parents('li').attr('data-auditid');
  281. $(this).parents('li').remove();
  282. let index = 1;
  283. $('#auditList li').each(function () {
  284. $(this).children('span').text(index);
  285. index++;
  286. });
  287. if (index === 1) {
  288. $('#account_list').val(0);
  289. }
  290. // 重新上报时。移除审批流程
  291. // 令最后一个图标转换
  292. $('#shenpi-audit-list li[data-auditid="' + uid + '"]').remove();
  293. $('#shenpi-audit-list2 li[data-auditid="' + uid + '"]').remove();
  294. if ($('#shenpi-audit-list li').length !== 0 && !$('#shenpi-audit-list li i').hasClass('fa-stop-circle')) {
  295. $('#shenpi-audit-list li').eq($('#shenpi-audit-list li').length-1).children('i')
  296. .removeClass('fa-chevron-circle-down').addClass('fa-stop-circle');
  297. $('#shenpi-audit-list2 li').eq($('#shenpi-audit-list2 li').length-1).children('i')
  298. .removeClass('fa-chevron-circle-down').addClass('fa-stop-circle');
  299. }
  300. for (let i = 0; i < $('#shenpi-audit-list li').length; i++) {
  301. $('#shenpi-audit-list li').eq(i).find('.pull-right').text((i+1 === $('#shenpi-audit-list li').length ? '终' : transFormToChinese(i+1)) + '审');
  302. $('#shenpi-audit-list2 li').eq(i).find('.pull-right').text((i+1 === $('#shenpi-audit-list2 li').length ? '终' : transFormToChinese(i+1)) + '审');
  303. }
  304. $('#shenpi-audit-list li').eq(0).find('.pull-right').text('原报');
  305. $('#shenpi-audit-list2 li').eq(0).find('.pull-right').text('原报');
  306. $('#shenpi-audit-list li i').eq(0).removeClass('fa-chevron-circle-down').addClass('fa-play-circle');
  307. $('#shenpi-audit-list2 li i').eq(0).removeClass('fa-chevron-circle-down').addClass('fa-play-circle');
  308. });
  309. // 打开签约清单modal并删除之前的操作
  310. $('#open-list-modal').click(function () {
  311. $('#table-list-select tr').removeClass('table-success');
  312. $('#table-list-select tr').attr('data-bwmx', '');
  313. $('#code-list').html('');
  314. });
  315. // 清单选中和移除
  316. $('body').on('click', '#table-list-select tr', function () {
  317. $('#table-list-select tr').removeClass('table-warning');
  318. $(this).addClass('table-warning');
  319. const isCheck = $(this).hasClass('table-success') ? true : false;
  320. const data_bwmx = $(this).attr('data-bwmx').split('$#$');
  321. const isDeal = $(this).data('gcl') !== undefined ? true : false;
  322. let codeHtml = '<tr quantity="0"><td colspan="4" class="colspan_1">&nbsp;</td><td class="colspan_2"><input type="checkbox"></td></tr>';
  323. if (isDeal) {
  324. const gcl = gclGatherData[$(this).data('gcl')];
  325. codeHtml = '';
  326. for (const leaf of gcl.leafXmjs) {
  327. const quantity = leaf.quantity !== undefined && leaf.quantity !== null ? leaf.quantity : 0;
  328. const bwmx = leaf.bwmx !== undefined ? leaf.bwmx : '';
  329. const isChecked = data_bwmx.indexOf(leaf.code + '_' + bwmx + ';' + quantity) !== -1 && isCheck ? 'checked' : '';
  330. codeHtml += '<tr quantity="' + quantity + '"><td>' + leaf.code + '</td>' +
  331. '<td>' + leaf.jldy + '</td>' +
  332. '<td>' + bwmx + '</td>' +
  333. '<td>' + roundnum(quantity, findDecimal(gcl.unit)) + '</td>' +
  334. '<td><input type="checkbox"' + isChecked +
  335. '></td></tr>';
  336. }
  337. } else if (!isDeal && isCheck) {
  338. codeHtml = '<tr quantity="0"><td colspan="4" class="colspan_1">&nbsp;</td><td class="colspan_2"><input type="checkbox" checked></td></tr>';
  339. }
  340. $('#code-list').attr('data-index', $(this).children('td').eq(0).text());
  341. $('#code-list').html(codeHtml);
  342. });
  343. // 右边项目节选择
  344. $('body').on('click', '#code-list input', function () {
  345. let index = $('#code-list').attr('data-index');
  346. if ($(this).is(':checked')) {
  347. // 去除其它可能已选的checked
  348. // $('#code-list input').prop('checked', false);
  349. $(this).prop('checked', true);
  350. // 左边表单传值并添加class
  351. $('#table-list-select tr[data-index="' + index + '"]').addClass('table-success');
  352. // 去除部分data-detail值
  353. let data_bwmx = [];
  354. $('#code-list input:checked').each(function () {
  355. const tr = $(this).parents('tr');
  356. const length = tr.children('td').length;
  357. const bwmx = length === 5 ? tr.children('td').eq(0).text() + '_' + tr.children('td').eq(2).text() : '0';
  358. const quantity = tr.attr('quantity');
  359. const de_qu = bwmx + ';' + quantity;
  360. data_bwmx.push(de_qu);
  361. });
  362. data_bwmx = data_bwmx.join('$#$');
  363. $('#table-list-select tr[data-index="' + index + '"]').attr('data-bwmx', data_bwmx);
  364. } else {
  365. // 判断还有无选中项目节编号
  366. if ($('#code-list input').is(':checked')) {
  367. // 去除部分data-detail值
  368. let data_bwmx = [];
  369. $('#code-list input:checked').each(function () {
  370. const tr = $(this).parents('tr');
  371. const length = tr.children('td').length;
  372. const bwmx = length === 5 ? tr.children('td').eq(0).text() + '_' + tr.children('td').eq(2).text() : '0';
  373. const quantity = tr.attr('quantity');
  374. const de_qu = bwmx + ';' + quantity;
  375. data_bwmx.push(de_qu);
  376. });
  377. data_bwmx = data_bwmx.join('$#$');
  378. $('#table-list-select tr[data-index="' + index + '"]').attr('data-bwmx', data_bwmx);
  379. } else {
  380. $('#table-list-select tr[data-index="' + index + '"]').removeClass('table-success');
  381. $('#table-list-select tr[data-index="' + index + '"]').attr('data-bwmx', '');
  382. }
  383. }
  384. });
  385. // 添加空白清单or签约清单
  386. $('.add-list-btn').on('click', function () {
  387. //生成table清单
  388. if($(this).hasClass('btn-outline-primary')){
  389. maketablelist('addwhite');
  390. }else{
  391. maketablelist();
  392. }
  393. $('#addlist').modal('hide');
  394. });
  395. // 添加空白清单
  396. $('#add-white-btn').on('click', function () {
  397. maketablelist('addwhite');
  398. });
  399. // 选中input所有值
  400. $('body').on('focus', ".clist input", function() {
  401. $(this).select();
  402. });
  403. // 取消选中清单
  404. $('#cancel-list-btn').click(function () {
  405. $('#table-list-select tr').removeClass('table-success');
  406. $('#table-list-select tr').attr('data-bwmx', '');
  407. $('#code-list').html('');
  408. });
  409. // 移除已选清单并重新编号
  410. $('body').on('click', '#list td a', function () {
  411. const index = $(this).parents('tr').data('index');
  412. const lid = $(this).parents('tr').data('lid');
  413. // 判断属于空白还是普通清单,并删除对应的index值
  414. const changelist = isNaN(lid) ? $('#change-list').val().split('^_^') : $('#change-whitelist').val().split('^_^');
  415. if($.trim(changelist) != ''){
  416. changelist.splice(index, 1);
  417. if (isNaN(lid)) {
  418. $('#change-list').val(changelist.join('^_^'));
  419. } else {
  420. $('#change-whitelist').val(changelist.join('^_^'));
  421. }
  422. }
  423. // 重新绘制table
  424. maketablelist();
  425. });
  426. // 清单输入监控并更新
  427. $('body').on('valuechange', '.clist input', function (e, previous) {
  428. const index = $(this).parents('tr').data('index');
  429. const lid = $(this).parents('tr').data('lid');
  430. const isWhite = !isNaN(lid) ? true : false;
  431. const tr = $('#list tr[data-lid="' + lid + '"]').eq(0);
  432. const site = parseInt($(this).parents('td').data('site'));
  433. switch (site) {
  434. case 0:
  435. case 1:
  436. case 2:
  437. case 3:
  438. case 5:
  439. tr.children('td[data-site="' + site + '"]').children('input').val($(this).val());
  440. break;
  441. case 6:
  442. case 8:
  443. default:
  444. break;
  445. }
  446. const code = $.trim(tr.children('td[data-site="0"]').children('input').val()) || $.trim(tr.children('td[data-site="0"]').text());
  447. const name = $.trim(tr.children('td[data-site="1"]').children('input').val()) || $.trim(tr.children('td[data-site="1"]').text());
  448. const bwmx = $.trim(tr.children('td[data-site="2"]').children('input').val()) || $.trim(tr.children('td[data-site="2"]').text());
  449. const unit = $.trim(tr.children('td[data-site="4"]').children('select').val()) || $.trim(tr.children('td[data-site="4"]').text());
  450. const price = (tr.children('td[data-site="5"]').children('input').val() != '-' ? tr.children('td[data-site="5"]').children('input').val() : '') || tr.children('td[data-site="5"]').text();
  451. const oamount = (tr.children('td[data-site="6"]').children('input').val() != '-' ? tr.children('td[data-site="6"]').children('input').val() : '') || tr.children('td[data-site="6"]').text();
  452. const scnum = tr.children('td[data-site="8"]').children('input').val() != '-' ? tr.children('td[data-site="8"]').children('input').val() : '';
  453. const detail = $.trim(tr.children('td[data-site="3"]').children('input').val());
  454. const trlist = [code,name,bwmx,unit,price,oamount,scnum,detail];
  455. if (isWhite) {
  456. let changelist = $('#change-whitelist').val().split('^_^');
  457. trlist.push(0);
  458. changelist.splice(index, 1, trlist.join(';'));
  459. $('#change-whitelist').val(changelist.join('^_^'));
  460. } else {
  461. let changelist = $('#change-list').val().split('^_^');
  462. trlist.push(lid.split('_')[0]);
  463. changelist.splice(index, 1, trlist.join(';'));
  464. $('#change-list').val(changelist.join('^_^'));
  465. }
  466. tr.children('td[data-site="7"]').text(price != '' && oamount != '' ? roundnum(parseFloat(price).mul(parseFloat(oamount)),totalPriceUnit) : '');
  467. tr.children('td[data-site="9"]').text(price != '' && scnum != '' ? roundnum(parseFloat(price).mul(parseFloat(scnum)),totalPriceUnit) : '');
  468. totalamount(totalPriceUnit);
  469. });
  470. // 空白清单单位选择监控并更新小数位数
  471. $('body').on("change", '.clist select', function () {
  472. const index = $(this).parents('tr').data('index');
  473. const tr = $('#list tr[data-lid="' + index + '"]');
  474. const code = $.trim(tr.children('td[data-site="0"]').children('input').val());
  475. const name = $.trim(tr.children('td[data-site="1"]').children('input').val());
  476. const bwmx = $.trim(tr.children('td[data-site="2"]').children('input').val());
  477. const unit = $(this).val();
  478. const price = tr.children('td[data-site="5"]').children('input').val() != '-' ? tr.children('td[data-site="5"]').children('input').val() : '';
  479. let oamount = tr.children('td[data-site="6"]').children('input').val() != '-' ? tr.children('td[data-site="6"]').children('input').val() : '';
  480. let scnum = tr.children('td[data-site="8"]').children('input').val() != '-' ? tr.children('td[data-site="8"]').children('input').val() : '';
  481. const detail = $.trim(tr.children('td[data-site="3"]').children('input').val());
  482. // 根据单位更新数量位数和合计
  483. const numdecimal = findDecimal(unit);
  484. oamount = roundnum(oamount, numdecimal);
  485. scnum = roundnum(scnum, numdecimal);
  486. tr.children('td[data-site="6"]').children('input').val(oamount);
  487. tr.children('td[data-site="6"]').children('input').attr('onkeyup','RegNum(this,event,'+ numdecimal +')');
  488. tr.children('td[data-site="8"]').children('input').val(scnum);
  489. tr.children('td[data-site="8"]').children('input').attr('onkeyup','RegNum(this,event,'+ numdecimal +')');
  490. const trlist = [code,name,bwmx,unit,price,oamount,scnum,detail,0];
  491. let changelist = $('#change-whitelist').val().split('^_^');
  492. changelist.splice(index, 1, trlist.join(';'));
  493. $('#change-whitelist').val(changelist.join('^_^'));
  494. tr.children('td[data-site="7"]').text(price != '' && oamount != '' ? roundnum(parseFloat(price).mul(parseFloat(oamount)),totalPriceUnit) : '');
  495. tr.children('td[data-site="9"]').text(price != '' && scnum != '' ? roundnum(parseFloat(price).mul(parseFloat(scnum)),totalPriceUnit) : '');
  496. totalamount(totalPriceUnit);
  497. });
  498. // 自动编号
  499. $('.reduction-code').click(function () {
  500. const code = $(this).attr('data-code');
  501. $('input[name="code"]').val(code);
  502. });
  503. });
  504. //判断元素是否在数组中,相当于php的in_array();
  505. function in_array(arr, obj) {
  506. let i = arr.length;
  507. while (i--) {
  508. if (arr[i] == obj) {
  509. return true;
  510. }
  511. }
  512. return false;
  513. }
  514. // 获取审批流程中审批人列表数据
  515. function getAuditList() {
  516. if ($('#auditList li').length === 0) {
  517. $('#changeaudit').val('');
  518. } else {
  519. let auditInfoArray = [];
  520. $('#auditList li').each(function () {
  521. const aMsg = $(this).data('auditmsg');
  522. auditInfoArray.push(aMsg);
  523. });
  524. $('#changeaudit').val(auditInfoArray.join(','));
  525. }
  526. }
  527. // 重新生成清单
  528. function maketablelist(status){
  529. // 金额位数
  530. const decimal = totalPriceUnit;
  531. // 单价位数
  532. const updecimal = unitPriceUnit;
  533. let html = '';
  534. // 原有清单(不含空白清单)
  535. let radionList = $('#change-list').val() !== '' ? $('#change-list').val().split('^_^') : [];
  536. // 获取选中的签约清单并插入到原有清单中
  537. $('#table-list-select .table-success').each(function(){
  538. let code = $(this).children('td').eq(1).text();
  539. let name = $(this).children('td').eq(2).text();
  540. let unit = $(this).children('td').eq(3).text();
  541. let price = $(this).children('td').eq(4).text();
  542. // let oamount = $(this).children('td').eq(5).text();
  543. // 根据单位获取数量的位数,并得出
  544. let numdecimal = findDecimal(unit);
  545. let scnum = makedecimalzero(numdecimal);
  546. // let detail = $(this).attr('data-detail') != 0 ? $(this).attr('data-detail').split('_')[1] : '';
  547. let lid = $(this).data('lid');
  548. // 原清单和数量改变
  549. let data_bwmx = $(this).attr('data-bwmx').split('$#$');
  550. for (const b of data_bwmx) {
  551. const oamount = b.split(';')[1];
  552. let bwmx = b.split(';')[0] != 0 ? b.split(';')[0].split('_')[1] : '';
  553. let trlist = [code, name, bwmx, unit, price, oamount, scnum, '', lid];
  554. radionList.push(trlist.join(';'));
  555. }
  556. });
  557. // 排序
  558. radionList.sort();
  559. let index = 0;
  560. let whiteIndex = 0;
  561. let deteletr = '<td><a class="text-danger">移除</a></td>';
  562. for (const radion of radionList) {
  563. const radionArray = radion.split(';');
  564. let code = radionArray[0];
  565. let name = radionArray[1];
  566. let bwmx = radionArray[2];
  567. let unit = radionArray[3];
  568. let price = radionArray[4];
  569. let oamount = radionArray[5];
  570. let scnum = radionArray[6];
  571. let detail = radionArray[7];
  572. let lid = radionArray[8];
  573. let sctotal = scnum !== '' && scnum !== '-' ? roundnum(parseFloat(price).mul(parseFloat(scnum)),decimal) : '';
  574. // 根据单位获取数量的位数,并得出
  575. let numdecimal = findDecimal(unit);
  576. html += '<tr class="clist clid" data-lid="' + lid + '_' + index + '" data-index="' + index + '">' +
  577. '<td data-site="0">'+ code +'</td>' +
  578. '<td data-site="1">'+ name +'</td>' +
  579. '<td data-site="2">'+ bwmx +'</td>' +
  580. '<td data-site="3"><input class="form-control input-sm" type="text" placeholder="变更详情" value="' + detail + '"></td>' +
  581. '<td data-site="4">'+ unit +'</td>' +
  582. '<td data-site="5">'+ roundnum(price, updecimal) +'</td>' +
  583. '<td data-site="6">'+ roundnum(oamount, numdecimal) +'</td>' +
  584. '<td data-site="7">'+ roundnum(parseFloat(price).mul(parseFloat(oamount)),decimal) +'</td>' +
  585. '<td data-site="8"><input class="form-control input-sm" type="text" onkeyup="RegNum(this,event,'+ numdecimal +')" placeholder="请输入变更数量" value="'+ (scnum != '-' ? roundnum(scnum, numdecimal) : '') +'"></td>' +
  586. '<td data-site="9">'+ sctotal +'</td>'+
  587. deteletr +'</tr>';
  588. index ++;
  589. }
  590. $('#change-list').val(radionList.join('^_^'));
  591. let radionWhiteList = $('#change-whitelist').val() !== '' ? $('#change-whitelist').val().split('^_^') : [];
  592. //判断是否添加空白清单
  593. if(status == 'addwhite'){
  594. let trlist = ['','','',changeUnits.m.unit,makedecimalzero(decimal),makedecimalzero(findDecimal(changeUnits.m.unit)),makedecimalzero(findDecimal(changeUnits.m.unit)),'',0];
  595. radionWhiteList.push(trlist.join(';'));
  596. }
  597. for (const rw of radionWhiteList) {
  598. const radionArray = rw.split(';');
  599. let code = radionArray[0];
  600. let name = radionArray[1];
  601. let bwmx = radionArray[2];
  602. let unit = radionArray[3];
  603. let price = radionArray[4];
  604. let oamount = radionArray[5];
  605. let scnum = radionArray[6];
  606. let detail = radionArray[7];
  607. let ototal = price != '' && oamount != '' ? roundnum(parseFloat(price).mul(parseFloat(oamount)),decimal) : '';
  608. let sctotal = price != '' && scnum != '' ? roundnum(parseFloat(price).mul(parseFloat(scnum)),decimal) : '';
  609. let optionlist = '';
  610. for (const j in changeUnits) {
  611. if (changeUnits[j].unit !== undefined && changeUnits[j].unit === unit) {
  612. optionlist += '<option selected="selected">'+ changeUnits[j].unit +'</option>';
  613. } else if(changeUnits[j].unit !== undefined) {
  614. optionlist += '<option>'+ changeUnits[j].unit +'</option>';
  615. }
  616. }
  617. // 根据单位获取数量的位数,并得出
  618. let numdecimal = findDecimal(unit);
  619. html += '<tr class="clist" data-lid="' + whiteIndex + '" data-index="' + whiteIndex + '">' +
  620. '<td data-site="0"><input class="form-control input-sm" type="text" value="'+ code +'" placeholder="清单编号"></td>' +
  621. '<td data-site="1"><input class="form-control input-sm" type="text" value="'+ name +'" placeholder="名称"></td>' +
  622. '<td data-site="2"><input class="form-control input-sm" type="text" value="'+ bwmx +'" placeholder="变更部位"></td>' +
  623. '<td data-site="3"><input class="form-control input-sm" type="text" value="'+ detail +'" placeholder="变更详情"></td>' +
  624. '<td data-site="4"><select class="form-control input-sm">'+ optionlist +'</select></td>' +
  625. '<td data-site="5"><input class="form-control input-sm" type="text" onkeyup="RegNum(this,event,'+ updecimal +')" value="'+ roundnum(price, updecimal) +'" placeholder="请输入单价"></td>' +
  626. '<td data-site="6"><input class="form-control input-sm" type="text" onkeyup="RegNum(this,event,'+ numdecimal +')" value="'+ roundnum(oamount, numdecimal) +'" placeholder="请输入数量"></td>' +
  627. '<td data-site="7">'+ ototal +'</td>' +
  628. '<td data-site="8"><input class="form-control input-sm" type="text" onkeyup="RegNum(this,event,'+ numdecimal +')" value="'+ roundnum(scnum, numdecimal) +'" placeholder="请输入变更数量"></td>' +
  629. '<td data-site="9">'+ sctotal +'</td>'+
  630. deteletr +'</tr>';
  631. whiteIndex ++;
  632. }
  633. $('#change-whitelist').val(radionWhiteList.join('^_^'));
  634. table.destroy();
  635. $('#list').html(html);
  636. table = $('#tablelist').removeAttr('width').DataTable({
  637. columnDefs: [
  638. { className: 'allwidth1', width: 100, targets: 0 },
  639. { className: 'allwidth2', width: 150, targets: [1,2,3] },
  640. { className: 'allwidth4', width: 40, targets: 10 },
  641. { className: 'allwidth5', width: 60, targets: 4 },
  642. { className: 'allwidth3',width: 80, targets: '_all' }
  643. ],
  644. fixedColumns: {
  645. leftColumns: 6
  646. }
  647. });
  648. // 判断是否显示变更详情
  649. if (!$('.change-detail-checkbox').is(':checked')) {
  650. const column = table.column(3);
  651. column.visible(!column.visible());
  652. }
  653. totalamount(decimal);
  654. $('#table-list-select tr').removeClass('table-success');
  655. }
  656. //统计合计金额
  657. function totalamount(decimal){
  658. let zero = makedecimalzero(decimal);
  659. let ctotalnum = 0;
  660. let ototalnum = 0;
  661. $('.clist').each(function(){
  662. let ctotal = $(this).children('td[data-site="9"]').text();
  663. ctotalnum = ctotal != '' ? parseFloat(ctotalnum).add(parseFloat(ctotal)) : parseFloat(ctotalnum);
  664. let ototal = $(this).children('td[data-site="7"]').text();
  665. ototalnum = ototal != '' ? parseFloat(ototalnum).add(parseFloat(ototal)) : parseFloat(ototalnum);
  666. });
  667. $('.ctatalamount').eq(1).text(ctotalnum != 0 ? roundnum(ctotalnum,decimal) : zero);
  668. $('.otatalamount').eq(1).text(ototalnum != 0 ? roundnum(ototalnum,decimal) : zero);
  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. }