change_set.js 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087
  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. const preUrl = window.location.pathname.split('/').slice(0, 4).join('/');
  41. let changeListData;
  42. let gclGatherData;
  43. postData(preUrl + '/defaultBills', {}, function (result) {
  44. gclGatherModel.loadLedgerData(result.bills);
  45. gclGatherModel.loadPosData(result.pos);
  46. gclGatherData = gclGatherModel.gatherGclData();
  47. gclGatherData = _.filter(gclGatherData, function (item) {
  48. return item.leafXmjs && item.leafXmjs.length !== 0;
  49. });
  50. for (const ggd in gclGatherData) {
  51. if (gclGatherData[ggd].leafXmjs && gclGatherData[ggd].leafXmjs.length === 0) {
  52. gclGatherData.splice(ggd, 1);
  53. }
  54. gclGatherData[ggd].code = gclGatherData[ggd].b_code;
  55. }
  56. // 数组去重
  57. const dealBillList = result.dealBills;
  58. for (const db of gclGatherData) {
  59. const exist_index = dealBillList.findIndex(function (item) {
  60. return item.code === db.code && item.name === db.name && item.unit === db.unit && item.unit_price === db.unit_price;
  61. });
  62. if (exist_index !== -1) {
  63. dealBillList.splice(exist_index, 1);
  64. }
  65. }
  66. changeListData = gclGatherData.concat(dealBillList).sort(sortByCode);
  67. console.log(changeListData);
  68. // 先加载台账数据
  69. let listHtml = '';
  70. let list_index = 1;
  71. let gcl_index = 0;
  72. for (const gcl of changeListData) {
  73. const unit = gcl.unit !== undefined && gcl.unit !== null ? gcl.unit : '';
  74. const quantity = gcl.quantity !== null && gcl.quantity !== undefined ? (unit !== '' ? roundnum(gcl.quantity, findDecimal(gcl.unit)) : gcl.quantity) : 0;
  75. const unit_price = gcl.unit_price !== null && gcl.unit_price !== undefined ? gcl.unit_price : 0;
  76. let gclhtml = gcl.leafXmjs !== undefined && gcl.leafXmjs !== null ? ' data-gcl="' + gcl_index + '"': '';
  77. gcl_index = gclhtml !== '' ? ++gcl_index : gcl_index;
  78. const lid = gcl.leafXmjs !== undefined && gcl.leafXmjs !== null ? (gcl.leafXmjs.length !== 0 ? gcl.leafXmjs[0].gcl_id : false) : gcl.id;
  79. if (lid) {
  80. listHtml += '<tr data-lid="' + lid + '"'+ gclhtml +' data-index="' + list_index + '" data-bwmx="">' +
  81. '<td class="text-center">' + list_index + '</td>' +
  82. '<td>' + gcl.code + '</td>' +
  83. '<td class="text-left">' + gcl.name + '</td>' +
  84. '<td class="text-center">' + unit + '</td>' +
  85. '<td class="text-right">' + roundnum(unit_price, unitPriceUnit) + '</td>' +
  86. '<td class="text-right">' + quantity + '</td>' +
  87. '</tr>';
  88. list_index++;
  89. }
  90. }
  91. $('#table-list-select').html(listHtml);
  92. tableDataRemake(changeListData);
  93. maketablelist();
  94. });
  95. // 多层modal关闭后的滚动bug修复
  96. $('#sub-sp2').on('hidden.bs.modal', function (e) {
  97. $(document.body).addClass('modal-open');
  98. });
  99. // 重新上报时按钮点击
  100. $('a[data-target="#sub-sp2"]').on('click', function () {
  101. let category = $(this).data('category');
  102. if (category === 'save_change') {
  103. // 保存修改modal
  104. $('.up-change').hide();
  105. $('.save-change').show();
  106. } else {
  107. // 上报审批modal
  108. $('.up-change').show();
  109. $('.save-change').hide();
  110. }
  111. $('#hideSp').attr('data-category', category);
  112. });
  113. // 提交表单
  114. // 上报时按钮点击
  115. $('button[data-sumbit="sumbit_change"]').on('click', function () {
  116. let category = $(this).data('category');
  117. if (category === 'save_change') {
  118. // 保存修改modal
  119. $('#changeStatus').val(2);
  120. // 获取auditlist并填入input中
  121. getAuditList();
  122. if ($('input[name="code"]').val() === '') {
  123. toastr.error('申请编号不能为空!');
  124. return;
  125. }
  126. if ($('input[name="name"]').val() === '') {
  127. toastr.error('工程名称不能为空!');
  128. return;
  129. }
  130. $('#change_form').submit();
  131. } else {
  132. // 上报审批modal
  133. $('#changeStatus').val(1);
  134. getAuditList();
  135. let returnFlag = false;
  136. // 表单判断
  137. if ($('input[name="code"]').val() === '') {
  138. toastr.error('申请编号不能为空!');
  139. returnFlag = true;
  140. }
  141. if ($('input[name="name"]').val() === '') {
  142. toastr.error('工程名称不能为空!');
  143. returnFlag = true;
  144. }
  145. if ($('textarea[name="content"]').val() === '') {
  146. toastr.error('工程变更理由及内容不能为空!');
  147. returnFlag = true;
  148. }
  149. if ($('#change-list').val() === '' && $('#change-whitelist').val() === '') {
  150. toastr.error('请添加变更清单!');
  151. returnFlag = true;
  152. } else {
  153. let changeList = [];
  154. if ($('#change-list').val() !== '') {
  155. changeList = $('#change-list').val().split('^_^');
  156. }
  157. let changeWhiteList = [];
  158. if ($('#change-whitelist').val() !== '') {
  159. changeWhiteList = $('#change-whitelist').val().split('^_^');
  160. }
  161. changeList.push.apply(changeList, changeWhiteList);
  162. for (const [index, cl] of changeList.entries()) {
  163. const clInfo = cl.split('*;*');
  164. // if (clInfo[0] === '' || clInfo[1] === '' || clInfo[3] === '' || clInfo[4] === '' || clInfo[5] === '') {
  165. if (clInfo[0] === '' || clInfo[1] === '' || clInfo[5] === '') {
  166. toastr.error('变更清单第' + (index+1) + '行未完整填写数据(变更部位、变更详情、单位、单价可空)');
  167. returnFlag = true;
  168. }
  169. }
  170. }
  171. if ($('#changeaudit').val() === '') {
  172. toastr.error('请添加审批流程!');
  173. returnFlag = true;
  174. }
  175. if (returnFlag) {
  176. return;
  177. }
  178. $('#change_form').submit();
  179. $(this).attr('disabled', true);
  180. }
  181. });
  182. // 保存修改ajax提交(不刷新页面)
  183. $('.save_change_btn').on('click', function () {
  184. // 保存修改modal
  185. $('#changeStatus').val(2);
  186. // 获取auditlist并填入input中
  187. getAuditList();
  188. if ($('input[name="code"]').val() === '') {
  189. toastr.error('申请编号不能为空!');
  190. return;
  191. }
  192. if ($('input[name="name"]').val() === '') {
  193. toastr.error('工程名称不能为空!');
  194. return;
  195. }
  196. $('#change_form').ajaxSubmit(function (result) {
  197. if ( result.err === 0) {
  198. $('.reduction-code').attr('data-code', $('input[name="code"]').val());
  199. toastr.success(result.msg);
  200. $('#show-save-btn').hide();
  201. $('.title-main').removeClass('bg-warning');
  202. $('#back-change-list').val($('#change-list').val());
  203. $('#back-change-whitelist').val($('#change-whitelist').val());
  204. back_changeInfo = Object.assign({}, changeInfo);
  205. } else {
  206. toastr.error(result.msg);
  207. }
  208. });
  209. return false;
  210. });
  211. $('#cancel_change').on('click', function () {
  212. $('#show-save-btn').hide();
  213. $('.title-main').removeClass('bg-warning');
  214. if (!isObjEqual(changeInfo, back_changeInfo)) {
  215. changeFormRemake();
  216. }
  217. if ($('#change-list').val() !== $('#back-change-list').val() || $('#change-whitelist').val() !== $('#back-change-whitelist').val()) {
  218. $('#change-list').val($('#back-change-list').val());
  219. $('#change-whitelist').val($('#back-change-whitelist').val());
  220. tableDataRemake(changeListData);
  221. // 重新绘制table
  222. maketablelist();
  223. if(!$('#bills').hasClass('first-bill-pane') && !$('a[aria-controls="bills"]').hasClass('active')) {
  224. $('#bills').addClass('first-bill-pane');
  225. }
  226. }
  227. toastr.success('已还原到上次保存状态');
  228. });
  229. let timer = null
  230. let oldSearchVal = null
  231. // 获取审核相关url
  232. function getUrlPre () {
  233. const path = window.location.pathname.split('/');
  234. return _.take(path, 6).join('/');
  235. }
  236. $('#gr-search').bind('input propertychange', function(e) {
  237. oldSearchVal = e.target.value
  238. timer && clearTimeout(timer)
  239. timer = setTimeout(() => {
  240. const newVal = $('#gr-search').val()
  241. let html = ''
  242. if (newVal && newVal === oldSearchVal) {
  243. accountList.filter(item => item && (item.name.indexOf(newVal) !== -1 || (item.mobile && item.mobile.indexOf(newVal) !== -1))).forEach(item => {
  244. html += `<dd class="border-bottom p-2 mb-0 " data-id="${item.id}" >
  245. <p class="mb-0 d-flex"><span class="text-primary">${item.name}</span><span
  246. class="ml-auto">${item.mobile || ''}</span></p>
  247. <span class="text-muted">${item.role || ''}</span>
  248. </dd>`
  249. })
  250. $('.book-list').empty()
  251. $('.book-list').append(html)
  252. } else {
  253. if (!$('.acc-btn').length) {
  254. accountGroup.forEach((group, idx) => {
  255. if (!group) return
  256. html += `<dt><a href="javascript: void(0);" class="acc-btn" data-groupid="${idx}" data-type="hide"><i class="fa fa-plus-square"></i>
  257. </a> ${group.groupName}</dt>
  258. <div class="dd-content" data-toggleid="${idx}">`
  259. group.groupList.forEach(item => {
  260. // if (item.id !== changesUid) {
  261. html += `<dd class="border-bottom p-2 mb-0 " data-id="${item.id}" >
  262. <p class="mb-0 d-flex"><span class="text-primary">${item.name}</span><span
  263. class="ml-auto">${item.mobile || ''}</span></p>
  264. <span class="text-muted">${item.role || ''}</span>
  265. </dd>`
  266. // }
  267. });
  268. html += '</div>'
  269. })
  270. $('.book-list').empty()
  271. $('.book-list').append(html)
  272. }
  273. }
  274. }, 400);
  275. })
  276. // 添加审批流程按钮逻辑
  277. $('.book-list').on('click', 'dt', function () {
  278. const idx = $(this).find('.acc-btn').attr('data-groupid')
  279. const type = $(this).find('.acc-btn').attr('data-type')
  280. if (type === 'hide') {
  281. $(this).parent().find(`div[data-toggleid="${idx}"]`).show(() => {
  282. $(this).children().find('i').removeClass('fa-plus-square').addClass('fa-minus-square-o')
  283. $(this).find('.acc-btn').attr('data-type', 'show')
  284. })
  285. } else {
  286. $(this).parent().find(`div[data-toggleid="${idx}"]`).hide(() => {
  287. $(this).children().find('i').removeClass('fa-minus-square-o').addClass('fa-plus-square')
  288. $(this).find('.acc-btn').attr('data-type', 'hide')
  289. })
  290. }
  291. return false
  292. });
  293. $('#hideSp').click(function () {
  294. $('#sub-sp2').modal('hide');
  295. });
  296. // 添加到审批流程中
  297. $('dl').on('click', 'dd', function () {
  298. const id = parseInt($(this).data('id'));
  299. if (id) {
  300. const auditListIdData = [];
  301. $('#auditList li').each(function () {
  302. const aid = $(this).data('auditid');
  303. auditListIdData.push(aid);
  304. });
  305. if (!in_array(auditListIdData, id)) {
  306. if (shenpi_status === shenpiConst.sp_status.gdzs) {
  307. auditListIdData.splice(-1,0,id);
  308. } else {
  309. auditListIdData.push(id);
  310. }
  311. const html = [];
  312. const auditorshtml = [];
  313. auditListIdData.unshift(changesUid);
  314. for (const [index,ids] of auditListIdData.entries()) {
  315. const accountInfo = _.find(accountList, { 'id': ids });
  316. if (index !== 0) {
  317. const user = accountInfo.id + '/%/' + accountInfo.name + '/%/' + accountInfo.role + '/%/' + accountInfo.company;
  318. html.push('<li class="list-group-item" data-auditmsg="' + user + '" data-auditid="'+ ids +'">');
  319. if (shenpi_status === shenpiConst.sp_status.sqspr || (shenpi_status === shenpiConst.sp_status.gdzs && index+1 !== auditListIdData.length)) {
  320. html.push('<a href="javascript:void(0);" class="text-danger pull-right remove_audit_btn">移除</a>');
  321. }
  322. html.push('<span>');
  323. html.push(index + ' ');
  324. html.push('</span> ');
  325. html.push(accountInfo.name + ' ');
  326. html.push('<small class="text-muted">');
  327. html.push(accountInfo.role);
  328. html.push('</small>');
  329. html.push('<p class="m-0 ml-2"><small class="text-muted">' + accountInfo.company + '</small></p>');
  330. html.push('</li>');
  331. }
  332. // 添加新审批人流程修改
  333. auditorshtml.push('<li class="list-group-item" ' + (index !== 0 ? 'data-auditid="' + accountInfo.id + '"' : '') + '>');
  334. auditorshtml.push('<i class="fa ' + (index+1 === auditListIdData.length ? 'fa-stop-circle' : 'fa-chevron-circle-down') + '"></i> ');
  335. auditorshtml.push(accountInfo.name + ' <small class="text-muted">' + accountInfo.role + '</small>');
  336. if (index === 0) {
  337. auditorshtml.push('<span class="pull-right">原报</span>');
  338. } else if (index+1 === auditListIdData.length) {
  339. auditorshtml.push('<span class="pull-right">终审</span>');
  340. } else {
  341. auditorshtml.push('<span class="pull-right">'+ transFormToChinese(index) +'审</span>');
  342. }
  343. auditorshtml.push('</li>');
  344. }
  345. $('#auditList').html(html.join(''));
  346. $('#shenpi-audit-list').html(auditorshtml.join(''));
  347. } else {
  348. toastr.error('审批流程中已存在该用户!');
  349. }
  350. }
  351. });
  352. // 移除审批流程的审批人
  353. $('body').on('click', '.remove_audit_btn', function () {
  354. const uid = $(this).parents('li').attr('data-auditid');
  355. $(this).parents('li').remove();
  356. let index = 1;
  357. $('#auditList li').each(function () {
  358. $(this).children('span').text(index);
  359. index++;
  360. });
  361. if (index === 1) {
  362. $('#account_list').val(0);
  363. }
  364. // 重新上报时。移除审批流程
  365. // 令最后一个图标转换
  366. $('#shenpi-audit-list li[data-auditid="' + uid + '"]').remove();
  367. if ($('#shenpi-audit-list li').length !== 0 && !$('#shenpi-audit-list li i').hasClass('fa-stop-circle')) {
  368. $('#shenpi-audit-list li').eq($('#shenpi-audit-list li').length-1).children('i')
  369. .removeClass('fa-chevron-circle-down').addClass('fa-stop-circle');
  370. }
  371. for (let i = 0; i < $('#shenpi-audit-list li').length; i++) {
  372. $('#shenpi-audit-list li').eq(i).find('.pull-right').text(i === 0 ? '原报' : (i+1 === $('#shenpi-audit-list li').length ? '终' : transFormToChinese(i)) + '审');
  373. }
  374. $('#shenpi-audit-list li i').eq(0).removeClass('fa-chevron-circle-down').addClass('fa-play-circle');
  375. });
  376. // 打开签约清单modal并删除之前的操作
  377. $('#open-list-modal').click(function () {
  378. autoFlashHeight()
  379. // tableDataRemake(changeListData);
  380. });
  381. // 清单选中和移除
  382. $('body').on('click', '#table-list-select tr', function () {
  383. $('#table-list-select tr').removeClass('table-warning');
  384. $(this).addClass('table-warning');
  385. const isCheck = $(this).hasClass('table-success') ? true : false;
  386. const data_bwmx = $(this).attr('data-bwmx').split('$#$');
  387. const isDeal = $(this).data('gcl') !== undefined ? true : false;
  388. let codeHtml = '<tr quantity="'+ $(this).children('td').eq(5).text() +'"><td colspan="7" class="colspan_1">&nbsp;</td><td class="colspan_2"><input type="checkbox"></td></tr>';
  389. if (isDeal) {
  390. const lid = $(this).data('lid');
  391. let gcl = _.find(gclGatherData, function (item) {
  392. return item.leafXmjs && item.leafXmjs[0].gcl_id === lid;
  393. });
  394. if (!gcl) {
  395. gcl = gclGatherData[$(this).data('gcl')];
  396. }
  397. codeHtml = '';
  398. for (const leaf of gcl.leafXmjs) {
  399. const quantity = leaf.quantity !== undefined && leaf.quantity !== null ? leaf.quantity : 0;
  400. const bwmx = leaf.bwmx !== undefined ? leaf.bwmx : '';
  401. const isChecked = data_bwmx.indexOf(leaf.code + '!_!' + (leaf.jldy ? leaf.jldy : '') + '!_!' + (bwmx !== '' ? bwmx : leaf.jldy ? leaf.jldy : '') + '*;*' + quantity) !== -1 && isCheck ? 'checked' : '';
  402. codeHtml += '<tr quantity="' + quantity + '"><td>' + leaf.code + '</td>' +
  403. '<td>' + (leaf.jldy ? leaf.jldy: '') + '</td>' +
  404. '<td>' + (leaf.dwgc ? leaf.dwgc : '') + '</td>' +
  405. '<td>' + (leaf.fbgc ? leaf.fbgc : '') + '</td>' +
  406. '<td>' + (leaf.fxgc ? leaf.fxgc : '') + '</td>' +
  407. '<td>' + bwmx + '</td>' +
  408. '<td class="text-right">' + roundnum(quantity, findDecimal(gcl.unit)) + '</td>' +
  409. '<td class="text-center"><input type="checkbox"' + isChecked +
  410. '></td></tr>';
  411. }
  412. } else if (!isDeal && isCheck) {
  413. codeHtml = '<tr quantity="'+ $(this).children('td').eq(5).text() +'"><td colspan="7" class="colspan_1">&nbsp;</td><td class="colspan_2"><input type="checkbox" checked></td></tr>';
  414. }
  415. $('#code-list').attr('data-index', $(this).children('td').eq(0).text());
  416. $('#code-input').val('');
  417. $('#code-input').siblings('a').hide();
  418. $('#code-list').html(codeHtml);
  419. });
  420. // 右边项目节选择
  421. $('body').on('click', '#code-list input', function () {
  422. let index = $('#code-list').attr('data-index');
  423. if ($(this).is(':checked')) {
  424. // 去除其它可能已选的checked
  425. // $('#code-list input').prop('checked', false);
  426. $(this).prop('checked', true);
  427. // 左边表单传值并添加class
  428. $('#table-list-select tr[data-index="' + index + '"]').addClass('table-success');
  429. // 去除部分data-detail值
  430. let data_bwmx = [];
  431. $('#code-list input:checked').each(function () {
  432. const tr = $(this).parents('tr');
  433. const length = tr.children('td').length;
  434. const bwmx = length === 8 ? tr.children('td').eq(0).text() + '!_!' + tr.children('td').eq(1).text() + '!_!' + (tr.children('td').eq(5).text() !== '' ? tr.children('td').eq(5).text() : tr.children('td').eq(1).text()) : '0';
  435. const quantity = tr.attr('quantity');
  436. const de_qu = bwmx + '*;*' + quantity;
  437. data_bwmx.push(de_qu);
  438. });
  439. data_bwmx = data_bwmx.join('$#$');
  440. $('#table-list-select tr[data-index="' + index + '"]').attr('data-bwmx', data_bwmx);
  441. } else {
  442. // 判断还有无选中项目节编号
  443. if ($('#code-list input').is(':checked')) {
  444. // 去除部分data-detail值
  445. let data_bwmx = [];
  446. $('#code-list input:checked').each(function () {
  447. const tr = $(this).parents('tr');
  448. const length = tr.children('td').length;
  449. const bwmx = length === 8 ? tr.children('td').eq(0).text() + '!_!'+ tr.children('td').eq(1).text() + '!_!' + (tr.children('td').eq(5).text() !== '' ? tr.children('td').eq(5).text() : tr.children('td').eq(1).text()) : '0';
  450. const quantity = tr.attr('quantity');
  451. const de_qu = bwmx + '*;*' + quantity;
  452. data_bwmx.push(de_qu);
  453. });
  454. data_bwmx = data_bwmx.join('$#$');
  455. $('#table-list-select tr[data-index="' + index + '"]').attr('data-bwmx', data_bwmx);
  456. } else {
  457. $('#table-list-select tr[data-index="' + index + '"]').removeClass('table-success');
  458. $('#table-list-select tr[data-index="' + index + '"]').attr('data-bwmx', '');
  459. }
  460. }
  461. });
  462. // 添加空白清单or签约清单
  463. $('.add-list-btn').on('click', function () {
  464. //生成table清单
  465. if($(this).hasClass('btn-outline-primary')){
  466. maketablelist('addwhite');
  467. }else{
  468. maketablelist();
  469. }
  470. $('#addlist').modal('hide');
  471. });
  472. // 添加空白清单
  473. $('#add-white-btn').on('click', function () {
  474. maketablelist('addwhite');
  475. });
  476. // 选中input所有值
  477. $('body').on('focus', ".clist input", function() {
  478. $(this).select();
  479. });
  480. // 取消选中清单
  481. $('#cancel-list-btn').click(function () {
  482. // $('#table-list-select tr').removeClass('table-success');
  483. // $('#table-list-select tr').attr('data-bwmx', '');
  484. // $('#code-list').html('');
  485. tableDataRemake(changeListData);
  486. });
  487. // 移除已选清单并重新编号
  488. $('body').on('click', '#list td a', function () {
  489. const index = $(this).parents('tr').data('index');
  490. const lid = $(this).parents('tr').data('lid');
  491. // 判断属于空白还是普通清单,并删除对应的index值
  492. const changelist = isNaN(lid) ? $('#change-list').val().split('^_^') : $('#change-whitelist').val().split('^_^');
  493. if($.trim(changelist) != ''){
  494. changelist.splice(index, 1);
  495. if (isNaN(lid)) {
  496. $('#change-list').val(changelist.join('^_^'));
  497. } else {
  498. $('#change-whitelist').val(changelist.join('^_^'));
  499. }
  500. }
  501. tableDataRemake(changeListData);
  502. // 重新绘制table
  503. maketablelist();
  504. });
  505. // 清单输入监控并更新
  506. $('body').on('valuechange', '.clist input', function (e, previous) {
  507. const index = $(this).parents('tr').data('index');
  508. const lid = $(this).parents('tr').data('lid');
  509. const xmj_code = $(this).parents('tr').data('xmjcode') || '';
  510. const xmj_jldy = $(this).parents('tr').data('xmjjldy') || '';
  511. const isWhite = !isNaN(lid) ? true : false;
  512. const tr = $('#list tr[data-lid="' + lid + '"]').eq(0);
  513. const site = parseInt($(this).parents('td').data('site'));
  514. switch (site) {
  515. case 0:
  516. case 1:
  517. case 2:
  518. case 3:
  519. case 5:
  520. tr.children('td[data-site="' + site + '"]').children('input').val($(this).val());
  521. break;
  522. case 6:
  523. case 8:
  524. default:
  525. break;
  526. }
  527. const code = $.trim(tr.children('td[data-site="0"]').children('input').val()) || $.trim(tr.children('td[data-site="0"]').text());
  528. const name = $.trim(tr.children('td[data-site="1"]').children('input').val()) || $.trim(tr.children('td[data-site="1"]').text());
  529. const bwmx = $.trim(tr.children('td[data-site="2"]').children('input').val()) || $.trim(tr.children('td[data-site="2"]').text());
  530. const unit = tr.children('td[data-site="4"]').children('select').val() === '' ? tr.children('td[data-site="4"]').children('select').val() : $.trim(tr.children('td[data-site="4"]').children('select').val()) || $.trim(tr.children('td[data-site="4"]').text());
  531. 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();
  532. 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();
  533. const scnum = tr.children('td[data-site="8"]').children('input').val() != '-' ? tr.children('td[data-site="8"]').children('input').val() : '';
  534. const detail = $.trim(tr.children('td[data-site="3"]').children('input').val());
  535. const trlist = [code,name,bwmx,unit,price,oamount,scnum,detail];
  536. if (isWhite) {
  537. let changelist = $('#change-whitelist').val().split('^_^');
  538. trlist.push(0);
  539. trlist.push(xmj_code);
  540. trlist.push(xmj_jldy);
  541. changelist.splice(index, 1, trlist.join('*;*'));
  542. $('#change-whitelist').val(changelist.join('^_^'));
  543. } else {
  544. let changelist = $('#change-list').val().split('^_^');
  545. trlist.push(lid.split('_')[0]);
  546. trlist.push(xmj_code);
  547. trlist.push(xmj_jldy);
  548. changelist.splice(index, 1, trlist.join('*;*'));
  549. $('#change-list').val(changelist.join('^_^'));
  550. }
  551. tr.children('td[data-site="7"]').text(price != '' && oamount != '' ? roundnum(parseFloat(price).mul(parseFloat(oamount)),totalPriceUnit) : '');
  552. tr.children('td[data-site="9"]').text(price != '' && scnum != '' ? roundnum(parseFloat(price).mul(parseFloat(scnum)),totalPriceUnit) : '');
  553. totalamount(totalPriceUnit);
  554. });
  555. // 空白清单单位选择监控并更新小数位数
  556. $('body').on("change", '.clist select', function () {
  557. const index = $(this).parents('tr').data('index');
  558. const tr = $('#list tr[data-lid="' + index + '"]');
  559. const code = $.trim(tr.children('td[data-site="0"]').children('input').val());
  560. const name = $.trim(tr.children('td[data-site="1"]').children('input').val());
  561. const bwmx = $.trim(tr.children('td[data-site="2"]').children('input').val());
  562. const unit = $(this).val();
  563. tr.children('td[data-site="4"]').children('select').val($(this).val());
  564. const price = tr.children('td[data-site="5"]').children('input').val() != '-' ? tr.children('td[data-site="5"]').children('input').val() : '';
  565. let oamount = tr.children('td[data-site="6"]').children('input').val() != '-' ? tr.children('td[data-site="6"]').children('input').val() : '';
  566. let scnum = tr.children('td[data-site="8"]').children('input').val() != '-' ? tr.children('td[data-site="8"]').children('input').val() : '';
  567. const detail = $.trim(tr.children('td[data-site="3"]').children('input').val());
  568. // 根据单位更新数量位数和合计
  569. const numdecimal = findDecimal(unit);
  570. oamount = roundnum(oamount, numdecimal);
  571. scnum = roundnum(scnum, numdecimal);
  572. tr.children('td[data-site="6"]').children('input').val(oamount);
  573. tr.children('td[data-site="6"]').children('input').attr('onkeyup','RegNum(this,event,'+ numdecimal +')');
  574. tr.children('td[data-site="8"]').children('input').val(scnum);
  575. tr.children('td[data-site="8"]').children('input').attr('onkeyup','RegNum(this,event,'+ numdecimal +')');
  576. const trlist = [code,name,bwmx,unit,price,oamount,scnum,detail,0,'',''];
  577. let changelist = $('#change-whitelist').val().split('^_^');
  578. changelist.splice(index, 1, trlist.join('*;*'));
  579. $('#change-whitelist').val(changelist.join('^_^'));
  580. tr.children('td[data-site="7"]').text(price != '' && oamount != '' ? roundnum(parseFloat(price).mul(parseFloat(oamount)),totalPriceUnit) : '');
  581. tr.children('td[data-site="9"]').text(price != '' && scnum != '' ? roundnum(parseFloat(price).mul(parseFloat(scnum)),totalPriceUnit) : '');
  582. totalamount(totalPriceUnit);
  583. });
  584. // 自动编号
  585. $('.reduction-code').click(function () {
  586. const code = $(this).attr('data-code');
  587. $('input[name="code"]').val(code);
  588. });
  589. // 记录变更信息操作
  590. $('body').on('valuechange', '#change_form input[type="text"]', function (e, previous) {
  591. changeInfo[$(this).attr('name')] = $(this).val();
  592. judgeChange();
  593. });
  594. $('body').on('valuechange', '#change_form textarea', function (e, previous) {
  595. changeInfo[$(this).attr('name')] = $(this).val().replace(/[\r\n]/g, '<br><br>');
  596. judgeChange();
  597. });
  598. $('body').on('change', '#change_form select', function (e, previous) {
  599. changeInfo[$(this).attr('name')] = $(this).val();
  600. judgeChange();
  601. });
  602. $('body').on('click', '#change_form input[type="radio"]', function (e, previous) {
  603. changeInfo[$(this).attr('name')] = $(this).val();
  604. judgeChange();
  605. });
  606. $('body').on('click', '#change_form input[type="checkbox"]', function (e, previous) {
  607. const typecheck = [];
  608. $.each($('#change_form input[name="type[]"]:checked'), function () {
  609. typecheck.push($(this).val());
  610. });
  611. changeInfo.type = typecheck.join(',');
  612. judgeChange();
  613. });
  614. $('#list-input').on('valuechange', function (e, previous) {
  615. const value = $(this).val();
  616. let showListData = changeListData;
  617. if (value !== '') {
  618. $(this).siblings('a').show();
  619. showListData = _.filter(changeListData, function (c) {
  620. return (c.code && c.code.indexOf(value) !== -1) || (c.name && c.name.indexOf(value) !== -1);
  621. });
  622. } else {
  623. $(this).siblings('a').hide();
  624. }
  625. makeListTable(changeListData, showListData);
  626. $('#table-list-select tr').removeClass('table-warning');
  627. $('#code-input').val('');
  628. $('#code-input').siblings('a').hide();
  629. $('#code-list').html('');
  630. });
  631. $('#code-input').on('valuechange', function (e, previous) {
  632. const value = $(this).val();
  633. if (value !== '') {
  634. $(this).siblings('a').show();
  635. } else {
  636. $(this).siblings('a').hide();
  637. }
  638. makeCodeTable($(this).val());
  639. });
  640. $('.remove-btn').on('click', function () {
  641. $(this).hide();
  642. $(this).siblings('input').val('');
  643. if ($(this).data('btn') === 'list') {
  644. makeListTable(changeListData);
  645. $('#table-list-select tr').removeClass('table-warning');
  646. $('#code-list').html('');
  647. } else {
  648. makeCodeTable();
  649. }
  650. })
  651. });
  652. function tableDataRemake(changeListData) {
  653. $('#table-list-select tr').removeClass('table-warning');
  654. $('#table-list-select tr').removeClass('table-success');
  655. $('#table-list-select tr').attr('data-bwmx', '');
  656. $('#code-list').html('');
  657. // 根据已添加的清单显示
  658. const changeList = $('#change-list').val().split('^_^');
  659. if (changeList.length > 0 && changeList[0]) {
  660. for (const [index,cl] of changeList.entries()) {
  661. const clinfo = cl.split('*;*');
  662. // const listinfo = changeListData[clinfo[8] - 1];
  663. let listinfo = changeListData.find(function (item) {
  664. return (item.id !== undefined && item.id == clinfo[8]) || (item.id === undefined && item.leafXmjs !== undefined && item.leafXmjs.length !== 0 && item.leafXmjs[0].gcl_id == clinfo[8]);
  665. });
  666. // if (listinfo === undefined) {
  667. // toastr.warning('台账清单列表已不存在'+ clinfo[0] +',故删除之');
  668. // continue;
  669. // }
  670. if (listinfo === undefined) {
  671. // 针对旧数据获取清单信息
  672. listinfo = changeListData[clinfo[8] - 1];
  673. if (listinfo === undefined) {
  674. toastr.warning('台账清单列表已不存在'+ clinfo[0] +',已更新变更清单列表');
  675. changeList.splice(index, 1);
  676. continue;
  677. }
  678. $('#table-list-select tr[data-index="'+ clinfo[8] +'"]').addClass('table-success');
  679. let pushbwmx = '0*;*0';
  680. if (listinfo.leafXmjs !== undefined) {
  681. const leafInfo = listinfo.leafXmjs.find(function (item) {
  682. return (item.bwmx === undefined || item.bwmx === clinfo[2]) && (item.quantity !== null ? item.quantity === parseFloat(clinfo[5]) : 0 === parseFloat(clinfo[5]));
  683. });
  684. console.log(leafInfo);
  685. if (leafInfo) {
  686. pushbwmx = leafInfo.code + '!_!' + (leafInfo.jldy !== undefined ? leafInfo.jldy : '') + '!_!' + (leafInfo.bwmx !== undefined ? leafInfo.bwmx : '') + '*;*' + (leafInfo.quantity !== null ? leafInfo.quantity : 0);
  687. } else {
  688. toastr.warning('台账清单列表已不存在'+ clinfo[0] +',已更新变更清单列表');
  689. changeList.splice(index, 1);
  690. continue;
  691. }
  692. } else {
  693. pushbwmx = '0*;*' + (listinfo.quantity !== null ? listinfo.quantity : 0);
  694. }
  695. const bwmx = $('#table-list-select tr[data-index="'+ clinfo[8] +'"]').attr('data-bwmx');
  696. if (bwmx) {
  697. const bwmxArray = bwmx.split('$#$');
  698. bwmxArray.push(pushbwmx);
  699. $('#table-list-select tr[data-index="'+ clinfo[8] +'"]').attr('data-bwmx', bwmxArray.join('$#$'));
  700. } else {
  701. $('#table-list-select tr[data-index="'+ clinfo[8] +'"]').attr('data-bwmx', pushbwmx);
  702. }
  703. } else {
  704. $('#table-list-select tr[data-lid="'+ clinfo[8] +'"]').addClass('table-success');
  705. let pushbwmx = '0*;*0';
  706. if (listinfo.leafXmjs !== undefined) {
  707. const leafInfo = listinfo.leafXmjs.find(function (item) {
  708. return (item.bwmx === undefined || item.bwmx === clinfo[2] || item.jldy === clinfo[2]) && (item.quantity !== null ? item.quantity === parseFloat(clinfo[5]) : 0 === parseFloat(clinfo[5]));
  709. });
  710. if (leafInfo) {
  711. pushbwmx = leafInfo.code + '!_!' + (leafInfo.jldy !== undefined ? leafInfo.jldy : '') + '!_!' + (leafInfo.bwmx !== undefined ? leafInfo.bwmx : (leafInfo.jldy ? leafInfo.jldy : '')) + '*;*' + (leafInfo.quantity !== null ? leafInfo.quantity : 0);
  712. } else {
  713. toastr.warning('台账清单列表已不存在'+ clinfo[0] +',已更新变更清单列表');
  714. changeList.splice(index, 1);
  715. continue;
  716. }
  717. } else {
  718. pushbwmx = '0*;*' + (listinfo.quantity !== null ? listinfo.quantity : 0);
  719. }
  720. const bwmx = $('#table-list-select tr[data-lid="'+ clinfo[8] +'"]').attr('data-bwmx');
  721. if (bwmx) {
  722. const bwmxArray = bwmx.split('$#$');
  723. bwmxArray.push(pushbwmx);
  724. $('#table-list-select tr[data-lid="'+ clinfo[8] +'"]').attr('data-bwmx', bwmxArray.join('$#$'));
  725. } else {
  726. $('#table-list-select tr[data-lid="'+ clinfo[8] +'"]').attr('data-bwmx', pushbwmx);
  727. }
  728. }
  729. }
  730. $('#change-list').val(changeList.join('^_^'));
  731. }
  732. }
  733. function changeFormRemake() {
  734. changeInfo = Object.assign({}, back_changeInfo);
  735. $('#change_form input[name="code"]').val(changeInfo.code);
  736. $('#change_form input[name="name"]').val(changeInfo.name);
  737. $('#change_form input[name="peg"]').val(changeInfo.peg);
  738. $('#change_form input[name="org_name"]').val(changeInfo.org_name);
  739. $('#change_form input[name="org_code"]').val(changeInfo.org_code);
  740. $('#change_form input[name="new_name"]').val(changeInfo.new_name);
  741. $('#change_form input[name="new_code"]').val(changeInfo.new_code);
  742. $('#change_form textarea[name="content"]').val(changeInfo.content.replace(/<br><br>/g, '\r\n'));
  743. $('#change_form textarea[name="basis"]').val(changeInfo.basis.replace(/<br><br>/g, '\r\n'));
  744. $('#change_form textarea[name="expr"]').val(changeInfo.expr.replace(/<br><br>/g, '\r\n'));
  745. $('#change_form textarea[name="memo"]').val(changeInfo.memo.replace(/<br><br>/g, '\r\n'));
  746. $('#change_form select[name="type"]').val(changeInfo.type);
  747. $('#change_form select[name="class"]').val(changeInfo.class);
  748. $('#change_form select[name="quality"]').val(changeInfo.quality);
  749. $('#change_form select[name="company"]').val(changeInfo.company);
  750. $('#change_form input[name="charge"][value="'+ changeInfo.charge +'"]').prop('checked', true);
  751. $('#change_form input[name="type[]"]').prop('checked', false);
  752. const typecheck = changeInfo.type.split(',');
  753. for (const type of typecheck) {
  754. $('#change_form input[name="type[]"][value="'+ type +'"]').prop('checked', true);
  755. }
  756. }
  757. //判断元素是否在数组中,相当于php的in_array();
  758. function in_array(arr, obj) {
  759. let i = arr.length;
  760. while (i--) {
  761. if (arr[i] == obj) {
  762. return true;
  763. }
  764. }
  765. return false;
  766. }
  767. // 获取审批流程中审批人列表数据
  768. function getAuditList() {
  769. if ($('#auditList li').length === 0) {
  770. $('#changeaudit').val('');
  771. } else {
  772. let auditInfoArray = [];
  773. $('#auditList li').each(function () {
  774. const aMsg = $(this).data('auditmsg');
  775. auditInfoArray.push(aMsg);
  776. });
  777. $('#changeaudit').val(auditInfoArray.join(','));
  778. }
  779. }
  780. // 清单搜索隐藏清单table部分值
  781. function makeListTable(changeListData, showListData = changeListData) {
  782. // 先加载台账数据
  783. let listHtml = '';
  784. let list_index = 1;
  785. let gcl_index = 0;
  786. for (const [index,gcl] of changeListData.entries()) {
  787. const isShow = _.find(showListData, gcl);
  788. $('#table-list-select tr').eq(index).css('display', (isShow ? 'table-row' : 'none'));
  789. }
  790. }
  791. // 项目节搜索隐藏code-table部分值
  792. function makeCodeTable(search = '') {
  793. if (search === '') {
  794. $('#code-list tr').css('display', 'table-row');
  795. return;
  796. }
  797. for(let i = 0; i < $('#code-list tr').length; i++) {
  798. const length = $('#code-list tr').eq(i).children('td').length;
  799. if (length === 8) {
  800. const code = $('#code-list tr').eq(i).children('td').eq(0).text();
  801. const name = $('#code-list tr').eq(i).children('td').eq(1).text();
  802. const jldy = $('#code-list tr').eq(i).children('td').eq(5).text();
  803. console.log(code, name, jldy, search, code.indexOf(search) !== -1 || name.indexOf(search) !== -1 || jldy.indexOf(search) !== -1);
  804. const isShow = code.indexOf(search) !== -1 || name.indexOf(search) !== -1 || jldy.indexOf(search) !== -1;
  805. $('#code-list tr').eq(i).css('display', (isShow ? 'table-row' : 'none'));
  806. } else {
  807. return;
  808. }
  809. }
  810. }
  811. // 上报时按钮点击
  812. $('a[data-target="#sub-ap"]').on('click', function () {
  813. let category = $(this).attr('data-category');
  814. if (category === 'save_change') {
  815. // 保存修改modal
  816. $('.up-change').hide();
  817. $('.save-change').show();
  818. } else {
  819. // 上报审批modal
  820. $('.up-change').show();
  821. $('.save-change').hide();
  822. }
  823. });
  824. // 重新生成清单
  825. function maketablelist(status){
  826. // 金额位数
  827. const decimal = totalPriceUnit;
  828. // 单价位数
  829. const updecimal = unitPriceUnit;
  830. let html = '';
  831. // 原有清单(不含空白清单)
  832. let radionList = $('#change-list').val() !== '' ? $('#change-list').val().split('^_^') : [];
  833. const newTableList = [];
  834. // 获取选中的签约清单判断并插入到原有清单中
  835. $('#table-list-select .table-success').each(function(){
  836. let code = $(this).children('td').eq(1).text();
  837. let name = $(this).children('td').eq(2).text();
  838. let unit = $(this).children('td').eq(3).text();
  839. let price = $(this).children('td').eq(4).text();
  840. // let oamount = $(this).children('td').eq(5).text();
  841. // 根据单位获取数量的位数,并得出
  842. // let numdecimal = findDecimal(unit);
  843. // let scnum = makedecimalzero(numdecimal);
  844. let scnum = 0;
  845. // let detail = $(this).attr('data-detail') != 0 ? $(this).attr('data-detail').split('_')[1] : '';
  846. let lid = $(this).data('lid');
  847. let lindex = $(this).data('index');
  848. // 原清单和数量改变
  849. let data_bwmx = $(this).attr('data-bwmx').split('$#$');
  850. for (const b of data_bwmx) {
  851. const oamount = b.split('*;*')[1] != '' ? b.split('*;*')[1] : 0;
  852. let bwmx = b.split('*;*')[0] != 0 ? b.split('*;*')[0].split('!_!')[2] : '';
  853. let xmj_code = b.split('*;*')[0] != 0 ? b.split('*;*')[0].split('!_!')[0] : '';
  854. let xmj_jldy = b.split('*;*')[0] != 0 ? b.split('*;*')[0].split('!_!')[1] : '';
  855. let trlist = [code, name, bwmx, unit, price, oamount, scnum, '', lid, xmj_code, xmj_jldy];
  856. const radionInfo = radionList.find(function (item) {
  857. const info = item.split('*;*');
  858. return info[0] === code && (info[8] == lid || parseInt(info[8]) === parseInt(lindex)) && info[2] === bwmx;
  859. });
  860. if (radionInfo) {
  861. trlist[6] = radionInfo.split('*;*')[6];
  862. trlist[7] = radionInfo.split('*;*')[7];
  863. }
  864. newTableList.push(trlist.join('*;*'));
  865. }
  866. });
  867. // 排序
  868. // radionList.sort();
  869. let index = 0;
  870. let whiteIndex = 0;
  871. let deteletr = '<td><a class="text-danger">移除</a></td>';
  872. for (const radion of newTableList) {
  873. const radionArray = radion.split('*;*');
  874. let code = radionArray[0];
  875. let name = radionArray[1];
  876. let bwmx = radionArray[2];
  877. let unit = radionArray[3];
  878. let price = radionArray[4];
  879. let oamount = radionArray[5];
  880. let scnum = radionArray[6];
  881. let detail = radionArray[7];
  882. let lid = radionArray[8];
  883. let xmj_code = radionArray[9];
  884. let xmj_jldy = radionArray[10];
  885. let sctotal = scnum !== '' && scnum !== '-' ? roundnum(parseFloat(price).mul(parseFloat(scnum)),decimal) : '';
  886. // 根据单位获取数量的位数,并得出
  887. let numdecimal = findDecimal(unit);
  888. html += '<tr class="clist clid" data-lid="' + lid + '_' + index + '" data-index="' + index + '" data-xmjcode="'+ xmj_code +'" data-xmjjldy="'+ xmj_jldy +'">' +
  889. '<td data-site="0">'+ code +'</td>' +
  890. '<td data-site="1">'+ name +'</td>' +
  891. '<td data-site="2">'+ bwmx +'</td>' +
  892. '<td data-site="3"><input class="form-control form-control-sm" type="text" placeholder="变更详情" value="' + detail + '"></td>' +
  893. '<td data-site="4">'+ unit +'</td>' +
  894. '<td data-site="5">'+ roundnum(price, updecimal) +'</td>' +
  895. '<td data-site="6">'+ roundnum(oamount, numdecimal) +'</td>' +
  896. '<td data-site="7">'+ roundnum(parseFloat(price).mul(parseFloat(oamount)),decimal) +'</td>' +
  897. '<td data-site="8"><input class="form-control form-control-sm" type="text" onkeyup="RegNum(this,event,'+ numdecimal +')" placeholder="请输入变更数量" value="'+ (scnum != '-' ? roundnum(scnum, numdecimal) : '') +'"></td>' +
  898. '<td data-site="9">'+ sctotal +'</td>'+
  899. deteletr +'</tr>';
  900. index ++;
  901. }
  902. $('#change-list').val(newTableList.join('^_^'));
  903. let radionWhiteList = $('#change-whitelist').val() !== '' ? $('#change-whitelist').val().split('^_^') : [];
  904. //判断是否添加空白清单
  905. if(status == 'addwhite'){
  906. let trlist = ['','','','','',makedecimalzero(findDecimal(3)),makedecimalzero(findDecimal(3)),'',0, '', ''];
  907. radionWhiteList.push(trlist.join('*;*'));
  908. }
  909. for (const rw of radionWhiteList) {
  910. const radionArray = rw.split('*;*');
  911. let code = radionArray[0];
  912. let name = radionArray[1];
  913. let bwmx = radionArray[2];
  914. let unit = radionArray[3];
  915. let price = radionArray[4];
  916. let oamount = radionArray[5];
  917. let scnum = radionArray[6];
  918. let detail = radionArray[7];
  919. let ototal = price != '' && oamount != '' ? roundnum(parseFloat(price).mul(parseFloat(oamount)),decimal) : '';
  920. let sctotal = price != '' && scnum != '' ? roundnum(parseFloat(price).mul(parseFloat(scnum)),decimal) : '';
  921. let optionlist = '<option></option>';
  922. for (const j in changeUnits) {
  923. if (changeUnits[j].unit !== undefined && changeUnits[j].unit === unit) {
  924. optionlist += '<option selected="selected">'+ changeUnits[j].unit +'</option>';
  925. } else if(changeUnits[j].unit !== undefined) {
  926. optionlist += '<option>'+ changeUnits[j].unit +'</option>';
  927. }
  928. }
  929. // 根据单位获取数量的位数,并得出
  930. let numdecimal = findDecimal(unit);
  931. html += '<tr class="clist" data-lid="' + whiteIndex + '" data-index="' + whiteIndex + '">' +
  932. '<td data-site="0"><input class="form-control form-control-sm" type="text" value="'+ code +'" placeholder="清单编号"></td>' +
  933. '<td data-site="1"><input class="form-control form-control-sm" type="text" value="'+ name +'" placeholder="名称"></td>' +
  934. '<td data-site="2"><input class="form-control form-control-sm" type="text" value="'+ bwmx +'" placeholder="变更部位"></td>' +
  935. '<td data-site="3"><input class="form-control form-control-sm" type="text" value="'+ detail +'" placeholder="变更详情"></td>' +
  936. '<td data-site="4"><select class="form-control form-control-sm">'+ optionlist +'</select></td>' +
  937. '<td data-site="5"><input class="form-control form-control-sm" type="text" onkeyup="RegNum(this,event,'+ updecimal +')" value="'+ roundnum(price, updecimal) +'" placeholder="请输入单价"></td>' +
  938. '<td data-site="6"><input class="form-control form-control-sm" type="text" onkeyup="RegNum(this,event,'+ numdecimal +')" value="'+ roundnum(oamount, numdecimal) +'" placeholder="请输入数量"></td>' +
  939. '<td data-site="7">'+ ototal +'</td>' +
  940. '<td data-site="8"><input class="form-control form-control-sm" type="text" onkeyup="RegNum(this,event,'+ numdecimal +')" value="'+ roundnum(scnum, numdecimal) +'" placeholder="请输入变更数量"></td>' +
  941. '<td data-site="9">'+ sctotal +'</td>'+
  942. deteletr +'</tr>';
  943. whiteIndex ++;
  944. }
  945. $('#change-whitelist').val(radionWhiteList.join('^_^'));
  946. if (table) {
  947. table.destroy();
  948. }
  949. $('#list').html(html);
  950. table = $('#tablelist').removeAttr('width').DataTable({
  951. columnDefs: [
  952. { className: 'allwidth1', width: 100, targets: 0 },
  953. { className: 'allwidth2', width: 150, targets: [1,2,3] },
  954. { className: 'allwidth4', width: 40, targets: 10 },
  955. { className: 'allwidth5', width: 60, targets: 4 },
  956. { className: 'allwidth3',width: 80, targets: '_all' }
  957. ],
  958. fixedColumns: {
  959. leftColumns: 6
  960. }
  961. });
  962. // 判断是否显示变更详情
  963. if (!$('.change-detail-checkbox').is(':checked')) {
  964. const column = table.column(3);
  965. column.visible(!column.visible());
  966. }
  967. totalamount(decimal);
  968. // $('#table-list-select tr').removeClass('table-success');
  969. }
  970. //统计合计金额
  971. function totalamount(decimal){
  972. let zero = makedecimalzero(decimal);
  973. let ctotalnum = 0;
  974. let ototalnum = 0;
  975. $('.clist').each(function(){
  976. let ctotal = $(this).children('td[data-site="9"]').text();
  977. ctotalnum = ctotal != '' ? parseFloat(ctotalnum).add(parseFloat(ctotal)) : parseFloat(ctotalnum);
  978. let ototal = $(this).children('td[data-site="7"]').text();
  979. ototalnum = ototal != '' ? parseFloat(ototalnum).add(parseFloat(ototal)) : parseFloat(ototalnum);
  980. });
  981. $('.ctatalamount').eq(1).text(ctotalnum != 0 ? roundnum(ctotalnum,decimal) : zero);
  982. $('.otatalamount').eq(1).text(ototalnum != 0 ? roundnum(ototalnum,decimal) : zero);
  983. judgeChange();
  984. }
  985. // 找出单位对应的小数位数值
  986. function findDecimal(unit) {
  987. let value = precision.other.value;
  988. const changeUnits = precision;
  989. for (const d in changeUnits) {
  990. if (changeUnits[d].unit !== undefined && changeUnits[d].unit === unit) {
  991. value = changeUnits[d].value;
  992. break;
  993. }
  994. }
  995. return value;
  996. }
  997. // 判断是否有更改过
  998. function judgeChange() {
  999. let change = false;
  1000. if ($('#change-list').val() !== $('#back-change-list').val()) {
  1001. change = true;
  1002. }
  1003. if ($('#change-whitelist').val() !== $('#back-change-whitelist').val()) {
  1004. change = true;
  1005. }
  1006. if (!isObjEqual(changeInfo, back_changeInfo)) {
  1007. change = true;
  1008. }
  1009. if (change) {
  1010. $('#show-save-btn').show();
  1011. $('.title-main').addClass('bg-warning');
  1012. } else {
  1013. $('#show-save-btn').hide();
  1014. $('.title-main').removeClass('bg-warning');
  1015. }
  1016. }
  1017. function isObjEqual(o1,o2){
  1018. var props1 = Object.getOwnPropertyNames(o1);
  1019. var props2 = Object.getOwnPropertyNames(o2);
  1020. if (props1.length != props2.length) {
  1021. return false;
  1022. }
  1023. for (var i = 0,max = props1.length; i < max; i++) {
  1024. var propName = props1[i];
  1025. if (o1[propName] !== o2[propName]) {
  1026. return false;
  1027. }
  1028. }
  1029. return true;
  1030. }