change_set.js 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728
  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. if (clInfo[0] === '' || clInfo[1] === '' || clInfo[5] === '') {
  175. toastr.error('变更清单第' + (index+1) + '行未完整填写数据(变更部位、变更详情、单位、单价可空)');
  176. returnFlag = true;
  177. }
  178. }
  179. }
  180. if ($('#changeaudit').val() === '') {
  181. toastr.error('请添加审批流程!');
  182. returnFlag = true;
  183. }
  184. if (returnFlag) {
  185. return;
  186. }
  187. $('#change_form').submit();
  188. $(this).attr('disabled', true);
  189. }
  190. });
  191. // 保存修改ajax提交(不刷新页面)
  192. $('#save_change').on('click', function () {
  193. // 保存修改modal
  194. $('#changeStatus').val(2);
  195. // 获取auditlist并填入input中
  196. getAuditList();
  197. if ($('input[name="code"]').val() === '') {
  198. toastr.error('申请编号不能为空!');
  199. return;
  200. }
  201. if ($('input[name="name"]').val() === '') {
  202. toastr.error('工程名称不能为空!');
  203. return;
  204. }
  205. $('#change_form').ajaxSubmit(function (result) {
  206. if ( result.err === 0) {
  207. $('.reduction-code').attr('data-code', $('input[name="code"]').val());
  208. toastr.success(result.msg);
  209. } else {
  210. toastr.error(result.msg);
  211. }
  212. });
  213. return false;
  214. });
  215. // 审批人分组选择
  216. $('#account_group').change(function () {
  217. let account_html = '<option value="0">选择审批人</option>';
  218. for (const account of accountList) {
  219. if (parseInt($(this).val()) === 0 || parseInt($(this).val()) === account.account_group) {
  220. const role = account.role !== '' ? '(' + account.role + ')' : '';
  221. const company = account.company !== '' ? ' -' + account.company : '';
  222. account_html += '<option value="' + account.id + '">' + account.name + role + company + '</option>';
  223. }
  224. }
  225. $('#account_list').html(account_html);
  226. });
  227. $('#hideSp').click(function () {
  228. $('#sub-sp2').modal('hide');
  229. });
  230. // 添加到审批流程中
  231. $('body').on('change', '#account_list', function () {
  232. let id = $(this).val();
  233. id = parseInt(id);
  234. if (id !== 0) {
  235. let auditListIdData = [];
  236. $('#auditList li').each(function () {
  237. let aid = $(this).data('auditid');
  238. auditListIdData.push(aid);
  239. });
  240. if (!in_array(auditListIdData, id)) {
  241. const accountInfo = accountList.find(function (item) {
  242. return item.id === id;
  243. });
  244. const user = accountInfo.id + '/%/' + accountInfo.name + '/%/' + accountInfo.role + '/%/' + accountInfo.company;
  245. const addhtml = '<li class="list-group-item" data-auditmsg="' + user + '"' +
  246. 'data-auditid="' + accountInfo.id + '" >' +
  247. '<a href="javascript:void(0);" class="text-danger pull-right remove_audit_btn">移除</a>' +
  248. '<span>' + (auditListIdData.length+1) + '</span> ' + accountInfo.name + ' <small class="text-muted">' + accountInfo.role + '</small>' +
  249. '<p class="m-0 ml-2"><small class="text-muted">' + accountInfo.company + '</small></p>' +
  250. '</li>';
  251. $('#auditList').append(addhtml);
  252. // 重新上报时。令其它的审批人流程图标转换
  253. $('#shenpi-audit-list li i').removeClass('fa-stop-circle').addClass('fa-chevron-circle-down');
  254. $('#shenpi-audit-list2 li i').removeClass('fa-stop-circle').addClass('fa-chevron-circle-down');
  255. // 添加新审批人
  256. const addhtml1 = '<li class="list-group-item" data-auditid="' + accountInfo.id + '" >' +
  257. '<i class="fa fa-stop-circle"></i> ' +
  258. accountInfo.name + ' <small class="text-muted">' + accountInfo.role + '</small><span class="pull-right">终审</span>' +
  259. '</li>';
  260. const addhtml2 = '<li class="list-group-item" data-auditid="' + accountInfo.id + '" >' +
  261. '<h5 class="card-title"><i class="fa fa-stop-circle"></i> ' +
  262. accountInfo.name + ' <small class="text-muted">' + accountInfo.role + '</small><span class="pull-right">终审</span>' +
  263. '</h5></li>';
  264. for (let i = 0; i < $('#shenpi-audit-list li').length; i++) {
  265. $('#shenpi-audit-list li').eq(i).find('.pull-right').text(transFormToChinese(i) + '审');
  266. $('#shenpi-audit-list2 li').eq(i).find('.pull-right').text(transFormToChinese(i) + '审');
  267. }
  268. $('#shenpi-audit-list li').eq(0).find('.pull-right').text('原报');
  269. $('#shenpi-audit-list2 li').eq(0).find('.pull-right').text('原报');
  270. $('#shenpi-audit-list li i').eq(0).removeClass('fa-chevron-circle-down').addClass('fa-play-circle');
  271. $('#shenpi-audit-list2 li i').eq(0).removeClass('fa-chevron-circle-down').addClass('fa-play-circle');
  272. $('#shenpi-audit-list').append(addhtml1);
  273. $('#shenpi-audit-list2').append(addhtml2);
  274. } else {
  275. toastr.error('审批流程中已存在该用户!');
  276. }
  277. }
  278. });
  279. // 移除审批流程的审批人
  280. $('body').on('click', '.remove_audit_btn', function () {
  281. const uid = $(this).parents('li').attr('data-auditid');
  282. $(this).parents('li').remove();
  283. let index = 1;
  284. $('#auditList li').each(function () {
  285. $(this).children('span').text(index);
  286. index++;
  287. });
  288. if (index === 1) {
  289. $('#account_list').val(0);
  290. }
  291. // 重新上报时。移除审批流程
  292. // 令最后一个图标转换
  293. $('#shenpi-audit-list li[data-auditid="' + uid + '"]').remove();
  294. $('#shenpi-audit-list2 li[data-auditid="' + uid + '"]').remove();
  295. if ($('#shenpi-audit-list li').length !== 0 && !$('#shenpi-audit-list li i').hasClass('fa-stop-circle')) {
  296. $('#shenpi-audit-list li').eq($('#shenpi-audit-list li').length-1).children('i')
  297. .removeClass('fa-chevron-circle-down').addClass('fa-stop-circle');
  298. $('#shenpi-audit-list2 li').eq($('#shenpi-audit-list2 li').length-1).children('i')
  299. .removeClass('fa-chevron-circle-down').addClass('fa-stop-circle');
  300. }
  301. for (let i = 0; i < $('#shenpi-audit-list li').length; i++) {
  302. $('#shenpi-audit-list li').eq(i).find('.pull-right').text((i+1 === $('#shenpi-audit-list li').length ? '终' : transFormToChinese(i+1)) + '审');
  303. $('#shenpi-audit-list2 li').eq(i).find('.pull-right').text((i+1 === $('#shenpi-audit-list2 li').length ? '终' : transFormToChinese(i+1)) + '审');
  304. }
  305. $('#shenpi-audit-list li').eq(0).find('.pull-right').text('原报');
  306. $('#shenpi-audit-list2 li').eq(0).find('.pull-right').text('原报');
  307. $('#shenpi-audit-list li i').eq(0).removeClass('fa-chevron-circle-down').addClass('fa-play-circle');
  308. $('#shenpi-audit-list2 li i').eq(0).removeClass('fa-chevron-circle-down').addClass('fa-play-circle');
  309. });
  310. // 打开签约清单modal并删除之前的操作
  311. $('#open-list-modal').click(function () {
  312. $('#table-list-select tr').removeClass('table-success');
  313. $('#table-list-select tr').attr('data-bwmx', '');
  314. $('#code-list').html('');
  315. });
  316. // 清单选中和移除
  317. $('body').on('click', '#table-list-select tr', function () {
  318. $('#table-list-select tr').removeClass('table-warning');
  319. $(this).addClass('table-warning');
  320. const isCheck = $(this).hasClass('table-success') ? true : false;
  321. const data_bwmx = $(this).attr('data-bwmx').split('$#$');
  322. const isDeal = $(this).data('gcl') !== undefined ? true : false;
  323. let codeHtml = '<tr quantity="0"><td colspan="4" class="colspan_1">&nbsp;</td><td class="colspan_2"><input type="checkbox"></td></tr>';
  324. if (isDeal) {
  325. const gcl = gclGatherData[$(this).data('gcl')];
  326. codeHtml = '';
  327. for (const leaf of gcl.leafXmjs) {
  328. const quantity = leaf.quantity !== undefined && leaf.quantity !== null ? leaf.quantity : 0;
  329. const bwmx = leaf.bwmx !== undefined ? leaf.bwmx : '';
  330. const isChecked = data_bwmx.indexOf(leaf.code + '_' + bwmx + ';' + quantity) !== -1 && isCheck ? 'checked' : '';
  331. codeHtml += '<tr quantity="' + quantity + '"><td>' + leaf.code + '</td>' +
  332. '<td>' + leaf.jldy + '</td>' +
  333. '<td>' + bwmx + '</td>' +
  334. '<td>' + roundnum(quantity, findDecimal(gcl.unit)) + '</td>' +
  335. '<td><input type="checkbox"' + isChecked +
  336. '></td></tr>';
  337. }
  338. } else if (!isDeal && isCheck) {
  339. codeHtml = '<tr quantity="0"><td colspan="4" class="colspan_1">&nbsp;</td><td class="colspan_2"><input type="checkbox" checked></td></tr>';
  340. }
  341. $('#code-list').attr('data-index', $(this).children('td').eq(0).text());
  342. $('#code-list').html(codeHtml);
  343. });
  344. // 右边项目节选择
  345. $('body').on('click', '#code-list input', function () {
  346. let index = $('#code-list').attr('data-index');
  347. if ($(this).is(':checked')) {
  348. // 去除其它可能已选的checked
  349. // $('#code-list input').prop('checked', false);
  350. $(this).prop('checked', true);
  351. // 左边表单传值并添加class
  352. $('#table-list-select tr[data-index="' + index + '"]').addClass('table-success');
  353. // 去除部分data-detail值
  354. let data_bwmx = [];
  355. $('#code-list input:checked').each(function () {
  356. const tr = $(this).parents('tr');
  357. const length = tr.children('td').length;
  358. const bwmx = length === 5 ? tr.children('td').eq(0).text() + '_' + tr.children('td').eq(2).text() : '0';
  359. const quantity = tr.attr('quantity');
  360. const de_qu = bwmx + ';' + quantity;
  361. data_bwmx.push(de_qu);
  362. });
  363. data_bwmx = data_bwmx.join('$#$');
  364. $('#table-list-select tr[data-index="' + index + '"]').attr('data-bwmx', data_bwmx);
  365. } else {
  366. // 判断还有无选中项目节编号
  367. if ($('#code-list input').is(':checked')) {
  368. // 去除部分data-detail值
  369. let data_bwmx = [];
  370. $('#code-list input:checked').each(function () {
  371. const tr = $(this).parents('tr');
  372. const length = tr.children('td').length;
  373. const bwmx = length === 5 ? tr.children('td').eq(0).text() + '_' + tr.children('td').eq(2).text() : '0';
  374. const quantity = tr.attr('quantity');
  375. const de_qu = bwmx + ';' + quantity;
  376. data_bwmx.push(de_qu);
  377. });
  378. data_bwmx = data_bwmx.join('$#$');
  379. $('#table-list-select tr[data-index="' + index + '"]').attr('data-bwmx', data_bwmx);
  380. } else {
  381. $('#table-list-select tr[data-index="' + index + '"]').removeClass('table-success');
  382. $('#table-list-select tr[data-index="' + index + '"]').attr('data-bwmx', '');
  383. }
  384. }
  385. });
  386. // 添加空白清单or签约清单
  387. $('.add-list-btn').on('click', function () {
  388. //生成table清单
  389. if($(this).hasClass('btn-outline-primary')){
  390. maketablelist('addwhite');
  391. }else{
  392. maketablelist();
  393. }
  394. $('#addlist').modal('hide');
  395. });
  396. // 添加空白清单
  397. $('#add-white-btn').on('click', function () {
  398. maketablelist('addwhite');
  399. });
  400. // 选中input所有值
  401. $('body').on('focus', ".clist input", function() {
  402. $(this).select();
  403. });
  404. // 取消选中清单
  405. $('#cancel-list-btn').click(function () {
  406. $('#table-list-select tr').removeClass('table-success');
  407. $('#table-list-select tr').attr('data-bwmx', '');
  408. $('#code-list').html('');
  409. });
  410. // 移除已选清单并重新编号
  411. $('body').on('click', '#list td a', function () {
  412. const index = $(this).parents('tr').data('index');
  413. const lid = $(this).parents('tr').data('lid');
  414. // 判断属于空白还是普通清单,并删除对应的index值
  415. const changelist = isNaN(lid) ? $('#change-list').val().split('^_^') : $('#change-whitelist').val().split('^_^');
  416. if($.trim(changelist) != ''){
  417. changelist.splice(index, 1);
  418. if (isNaN(lid)) {
  419. $('#change-list').val(changelist.join('^_^'));
  420. } else {
  421. $('#change-whitelist').val(changelist.join('^_^'));
  422. }
  423. }
  424. // 重新绘制table
  425. maketablelist();
  426. });
  427. // 清单输入监控并更新
  428. $('body').on('valuechange', '.clist input', function (e, previous) {
  429. const index = $(this).parents('tr').data('index');
  430. const lid = $(this).parents('tr').data('lid');
  431. const isWhite = !isNaN(lid) ? true : false;
  432. const tr = $('#list tr[data-lid="' + lid + '"]').eq(0);
  433. const site = parseInt($(this).parents('td').data('site'));
  434. switch (site) {
  435. case 0:
  436. case 1:
  437. case 2:
  438. case 3:
  439. case 5:
  440. tr.children('td[data-site="' + site + '"]').children('input').val($(this).val());
  441. break;
  442. case 6:
  443. case 8:
  444. default:
  445. break;
  446. }
  447. const code = $.trim(tr.children('td[data-site="0"]').children('input').val()) || $.trim(tr.children('td[data-site="0"]').text());
  448. const name = $.trim(tr.children('td[data-site="1"]').children('input').val()) || $.trim(tr.children('td[data-site="1"]').text());
  449. const bwmx = $.trim(tr.children('td[data-site="2"]').children('input').val()) || $.trim(tr.children('td[data-site="2"]').text());
  450. const unit = $.trim(tr.children('td[data-site="4"]').children('select').val()) || $.trim(tr.children('td[data-site="4"]').text());
  451. 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();
  452. 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();
  453. const scnum = tr.children('td[data-site="8"]').children('input').val() != '-' ? tr.children('td[data-site="8"]').children('input').val() : '';
  454. const detail = $.trim(tr.children('td[data-site="3"]').children('input').val());
  455. const trlist = [code,name,bwmx,unit,price,oamount,scnum,detail];
  456. if (isWhite) {
  457. let changelist = $('#change-whitelist').val().split('^_^');
  458. trlist.push(0);
  459. changelist.splice(index, 1, trlist.join(';'));
  460. $('#change-whitelist').val(changelist.join('^_^'));
  461. } else {
  462. let changelist = $('#change-list').val().split('^_^');
  463. trlist.push(lid.split('_')[0]);
  464. changelist.splice(index, 1, trlist.join(';'));
  465. $('#change-list').val(changelist.join('^_^'));
  466. }
  467. tr.children('td[data-site="7"]').text(price != '' && oamount != '' ? roundnum(parseFloat(price).mul(parseFloat(oamount)),totalPriceUnit) : '');
  468. tr.children('td[data-site="9"]').text(price != '' && scnum != '' ? roundnum(parseFloat(price).mul(parseFloat(scnum)),totalPriceUnit) : '');
  469. totalamount(totalPriceUnit);
  470. });
  471. // 空白清单单位选择监控并更新小数位数
  472. $('body').on("change", '.clist select', function () {
  473. const index = $(this).parents('tr').data('index');
  474. const tr = $('#list tr[data-lid="' + index + '"]');
  475. const code = $.trim(tr.children('td[data-site="0"]').children('input').val());
  476. const name = $.trim(tr.children('td[data-site="1"]').children('input').val());
  477. const bwmx = $.trim(tr.children('td[data-site="2"]').children('input').val());
  478. const unit = $(this).val();
  479. const price = tr.children('td[data-site="5"]').children('input').val() != '-' ? tr.children('td[data-site="5"]').children('input').val() : '';
  480. let oamount = tr.children('td[data-site="6"]').children('input').val() != '-' ? tr.children('td[data-site="6"]').children('input').val() : '';
  481. let scnum = tr.children('td[data-site="8"]').children('input').val() != '-' ? tr.children('td[data-site="8"]').children('input').val() : '';
  482. const detail = $.trim(tr.children('td[data-site="3"]').children('input').val());
  483. // 根据单位更新数量位数和合计
  484. const numdecimal = findDecimal(unit);
  485. oamount = roundnum(oamount, numdecimal);
  486. scnum = roundnum(scnum, numdecimal);
  487. tr.children('td[data-site="6"]').children('input').val(oamount);
  488. tr.children('td[data-site="6"]').children('input').attr('onkeyup','RegNum(this,event,'+ numdecimal +')');
  489. tr.children('td[data-site="8"]').children('input').val(scnum);
  490. tr.children('td[data-site="8"]').children('input').attr('onkeyup','RegNum(this,event,'+ numdecimal +')');
  491. const trlist = [code,name,bwmx,unit,price,oamount,scnum,detail,0];
  492. let changelist = $('#change-whitelist').val().split('^_^');
  493. changelist.splice(index, 1, trlist.join(';'));
  494. $('#change-whitelist').val(changelist.join('^_^'));
  495. tr.children('td[data-site="7"]').text(price != '' && oamount != '' ? roundnum(parseFloat(price).mul(parseFloat(oamount)),totalPriceUnit) : '');
  496. tr.children('td[data-site="9"]').text(price != '' && scnum != '' ? roundnum(parseFloat(price).mul(parseFloat(scnum)),totalPriceUnit) : '');
  497. totalamount(totalPriceUnit);
  498. });
  499. // 自动编号
  500. $('.reduction-code').click(function () {
  501. const code = $(this).attr('data-code');
  502. $('input[name="code"]').val(code);
  503. });
  504. });
  505. //判断元素是否在数组中,相当于php的in_array();
  506. function in_array(arr, obj) {
  507. let i = arr.length;
  508. while (i--) {
  509. if (arr[i] == obj) {
  510. return true;
  511. }
  512. }
  513. return false;
  514. }
  515. // 获取审批流程中审批人列表数据
  516. function getAuditList() {
  517. if ($('#auditList li').length === 0) {
  518. $('#changeaudit').val('');
  519. } else {
  520. let auditInfoArray = [];
  521. $('#auditList li').each(function () {
  522. const aMsg = $(this).data('auditmsg');
  523. auditInfoArray.push(aMsg);
  524. });
  525. $('#changeaudit').val(auditInfoArray.join(','));
  526. }
  527. }
  528. // 重新生成清单
  529. function maketablelist(status){
  530. // 金额位数
  531. const decimal = totalPriceUnit;
  532. // 单价位数
  533. const updecimal = unitPriceUnit;
  534. let html = '';
  535. // 原有清单(不含空白清单)
  536. let radionList = $('#change-list').val() !== '' ? $('#change-list').val().split('^_^') : [];
  537. // 获取选中的签约清单并插入到原有清单中
  538. $('#table-list-select .table-success').each(function(){
  539. let code = $(this).children('td').eq(1).text();
  540. let name = $(this).children('td').eq(2).text();
  541. let unit = $(this).children('td').eq(3).text();
  542. let price = $(this).children('td').eq(4).text();
  543. // let oamount = $(this).children('td').eq(5).text();
  544. // 根据单位获取数量的位数,并得出
  545. let numdecimal = findDecimal(unit);
  546. let scnum = makedecimalzero(numdecimal);
  547. // let detail = $(this).attr('data-detail') != 0 ? $(this).attr('data-detail').split('_')[1] : '';
  548. let lid = $(this).data('lid');
  549. // 原清单和数量改变
  550. let data_bwmx = $(this).attr('data-bwmx').split('$#$');
  551. for (const b of data_bwmx) {
  552. const oamount = b.split(';')[1];
  553. let bwmx = b.split(';')[0] != 0 ? b.split(';')[0].split('_')[1] : '';
  554. let trlist = [code, name, bwmx, unit, price, oamount, scnum, '', lid];
  555. radionList.push(trlist.join(';'));
  556. }
  557. });
  558. // 排序
  559. radionList.sort();
  560. let index = 0;
  561. let whiteIndex = 0;
  562. let deteletr = '<td><a class="text-danger">移除</a></td>';
  563. for (const radion of radionList) {
  564. const radionArray = radion.split(';');
  565. let code = radionArray[0];
  566. let name = radionArray[1];
  567. let bwmx = radionArray[2];
  568. let unit = radionArray[3];
  569. let price = radionArray[4];
  570. let oamount = radionArray[5];
  571. let scnum = radionArray[6];
  572. let detail = radionArray[7];
  573. let lid = radionArray[8];
  574. let sctotal = scnum !== '' && scnum !== '-' ? roundnum(parseFloat(price).mul(parseFloat(scnum)),decimal) : '';
  575. // 根据单位获取数量的位数,并得出
  576. let numdecimal = findDecimal(unit);
  577. html += '<tr class="clist clid" data-lid="' + lid + '_' + index + '" data-index="' + index + '">' +
  578. '<td data-site="0">'+ code +'</td>' +
  579. '<td data-site="1">'+ name +'</td>' +
  580. '<td data-site="2">'+ bwmx +'</td>' +
  581. '<td data-site="3"><input class="form-control input-sm" type="text" placeholder="变更详情" value="' + detail + '"></td>' +
  582. '<td data-site="4">'+ unit +'</td>' +
  583. '<td data-site="5">'+ roundnum(price, updecimal) +'</td>' +
  584. '<td data-site="6">'+ roundnum(oamount, numdecimal) +'</td>' +
  585. '<td data-site="7">'+ roundnum(parseFloat(price).mul(parseFloat(oamount)),decimal) +'</td>' +
  586. '<td data-site="8"><input class="form-control input-sm" type="text" onkeyup="RegNum(this,event,'+ numdecimal +')" placeholder="请输入变更数量" value="'+ (scnum != '-' ? roundnum(scnum, numdecimal) : '') +'"></td>' +
  587. '<td data-site="9">'+ sctotal +'</td>'+
  588. deteletr +'</tr>';
  589. index ++;
  590. }
  591. $('#change-list').val(radionList.join('^_^'));
  592. let radionWhiteList = $('#change-whitelist').val() !== '' ? $('#change-whitelist').val().split('^_^') : [];
  593. //判断是否添加空白清单
  594. if(status == 'addwhite'){
  595. let trlist = ['','','',changeUnits.m.unit,makedecimalzero(decimal),makedecimalzero(findDecimal(changeUnits.m.unit)),makedecimalzero(findDecimal(changeUnits.m.unit)),'',0];
  596. radionWhiteList.push(trlist.join(';'));
  597. }
  598. for (const rw of radionWhiteList) {
  599. const radionArray = rw.split(';');
  600. let code = radionArray[0];
  601. let name = radionArray[1];
  602. let bwmx = radionArray[2];
  603. let unit = radionArray[3];
  604. let price = radionArray[4];
  605. let oamount = radionArray[5];
  606. let scnum = radionArray[6];
  607. let detail = radionArray[7];
  608. let ototal = price != '' && oamount != '' ? roundnum(parseFloat(price).mul(parseFloat(oamount)),decimal) : '';
  609. let sctotal = price != '' && scnum != '' ? roundnum(parseFloat(price).mul(parseFloat(scnum)),decimal) : '';
  610. let optionlist = '';
  611. for (const j in changeUnits) {
  612. if (changeUnits[j].unit !== undefined && changeUnits[j].unit === unit) {
  613. optionlist += '<option selected="selected">'+ changeUnits[j].unit +'</option>';
  614. } else if(changeUnits[j].unit !== undefined) {
  615. optionlist += '<option>'+ changeUnits[j].unit +'</option>';
  616. }
  617. }
  618. // 根据单位获取数量的位数,并得出
  619. let numdecimal = findDecimal(unit);
  620. html += '<tr class="clist" data-lid="' + whiteIndex + '" data-index="' + whiteIndex + '">' +
  621. '<td data-site="0"><input class="form-control input-sm" type="text" value="'+ code +'" placeholder="清单编号"></td>' +
  622. '<td data-site="1"><input class="form-control input-sm" type="text" value="'+ name +'" placeholder="名称"></td>' +
  623. '<td data-site="2"><input class="form-control input-sm" type="text" value="'+ bwmx +'" placeholder="变更部位"></td>' +
  624. '<td data-site="3"><input class="form-control input-sm" type="text" value="'+ detail +'" placeholder="变更详情"></td>' +
  625. '<td data-site="4"><select class="form-control input-sm">'+ optionlist +'</select></td>' +
  626. '<td data-site="5"><input class="form-control input-sm" type="text" onkeyup="RegNum(this,event,'+ updecimal +')" value="'+ roundnum(price, updecimal) +'" placeholder="请输入单价"></td>' +
  627. '<td data-site="6"><input class="form-control input-sm" type="text" onkeyup="RegNum(this,event,'+ numdecimal +')" value="'+ roundnum(oamount, numdecimal) +'" placeholder="请输入数量"></td>' +
  628. '<td data-site="7">'+ ototal +'</td>' +
  629. '<td data-site="8"><input class="form-control input-sm" type="text" onkeyup="RegNum(this,event,'+ numdecimal +')" value="'+ roundnum(scnum, numdecimal) +'" placeholder="请输入变更数量"></td>' +
  630. '<td data-site="9">'+ sctotal +'</td>'+
  631. deteletr +'</tr>';
  632. whiteIndex ++;
  633. }
  634. $('#change-whitelist').val(radionWhiteList.join('^_^'));
  635. table.destroy();
  636. $('#list').html(html);
  637. table = $('#tablelist').removeAttr('width').DataTable({
  638. columnDefs: [
  639. { className: 'allwidth1', width: 100, targets: 0 },
  640. { className: 'allwidth2', width: 150, targets: [1,2,3] },
  641. { className: 'allwidth4', width: 40, targets: 10 },
  642. { className: 'allwidth5', width: 60, targets: 4 },
  643. { className: 'allwidth3',width: 80, targets: '_all' }
  644. ],
  645. fixedColumns: {
  646. leftColumns: 6
  647. }
  648. });
  649. // 判断是否显示变更详情
  650. if (!$('.change-detail-checkbox').is(':checked')) {
  651. const column = table.column(3);
  652. column.visible(!column.visible());
  653. }
  654. totalamount(decimal);
  655. $('#table-list-select tr').removeClass('table-success');
  656. }
  657. //统计合计金额
  658. function totalamount(decimal){
  659. let zero = makedecimalzero(decimal);
  660. let ctotalnum = 0;
  661. let ototalnum = 0;
  662. $('.clist').each(function(){
  663. let ctotal = $(this).children('td[data-site="9"]').text();
  664. ctotalnum = ctotal != '' ? parseFloat(ctotalnum).add(parseFloat(ctotal)) : parseFloat(ctotalnum);
  665. let ototal = $(this).children('td[data-site="7"]').text();
  666. ototalnum = ototal != '' ? parseFloat(ototalnum).add(parseFloat(ototal)) : parseFloat(ototalnum);
  667. });
  668. $('.ctatalamount').eq(1).text(ctotalnum != 0 ? roundnum(ctotalnum,decimal) : zero);
  669. $('.otatalamount').eq(1).text(ototalnum != 0 ? roundnum(ototalnum,decimal) : zero);
  670. }
  671. // 找出单位对应的小数位数值
  672. function findDecimal(unit) {
  673. let value = precision.other.value;
  674. const changeUnits = precision;
  675. for (const d in changeUnits) {
  676. if (changeUnits[d].unit !== undefined && changeUnits[d].unit === unit) {
  677. value = changeUnits[d].value;
  678. break;
  679. }
  680. }
  681. return value;
  682. }