change_set.js 44 KB

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