change_set.js 44 KB

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