change_set.js 29 KB

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