change_set.js 41 KB

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