change_company.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. 'use strict';
  2. /**
  3. * 变更令公司编辑js
  4. *
  5. * @author EllisRan.
  6. * @date 2018/11/26
  7. * @version
  8. */
  9. $(document).ready(() => {
  10. //提出单位编辑
  11. $('#addcompany').click(function(){
  12. let newinput = '<div class="form-group"><input type="text" class="form-control form-control-sm" placeholder="请输入名称"></div>';
  13. $('#companyadddiv').append(newinput);
  14. });
  15. $('#updatecompany').click(function(){
  16. $(this).attr('disabled','disabled');
  17. let addcompanyArr = new Array();
  18. $('#companyadddiv').find('.form-control').each(function(){
  19. if ($.trim($(this).val()) !== '') {
  20. addcompanyArr.push($(this).val());
  21. }
  22. });
  23. var updatecompanyArr = new Array();
  24. var updatecompanyidArr = new Array();
  25. $('#companyshow').find('.form-control').each(function(){
  26. updatecompanyArr.push($(this).val());
  27. updatecompanyidArr.push($(this).attr('id'));
  28. });
  29. //判断是否有重名情况再提交
  30. let flag = isRepeat(addcompanyArr.concat(updatecompanyArr));
  31. if(!flag){
  32. const data = {
  33. tid: $('#tenderId').val(),
  34. uci:updatecompanyidArr.length !== 0 ? updatecompanyidArr : '',
  35. uc:updatecompanyArr.length ? updatecompanyArr : '',
  36. ac:addcompanyArr.length !== 0 ? addcompanyArr : ''
  37. };
  38. postData('/change/update/company', data, function (result) {
  39. $('#companyadddiv').html('');
  40. updateCompanyHtml(result);
  41. selectCompanyHtml(result);
  42. $('#editcompany').modal('hide');
  43. toastr.success('变更单位已更新');
  44. $('#updatecompany').attr('disabled',false);
  45. let hadChange = true;
  46. $('#company option').each(function(){
  47. if ($(this).val() === changeInfo.company) {
  48. hadChange = false;
  49. return;
  50. }
  51. });
  52. if (hadChange) {
  53. changeInfo.company = $('#company').val();
  54. } else {
  55. $('#company').val(changeInfo.company);
  56. }
  57. judgeChange();
  58. });
  59. }else{
  60. toastr.error('变更单位不能同名');
  61. $('#updatecompany').attr('disabled',false);
  62. }
  63. });
  64. });
  65. function isRepeat(arr){
  66. let hash = {};
  67. for(let i in arr) {
  68. if($.trim(arr[i]) !== '' && hash[arr[i]])
  69. return true;
  70. hash[arr[i]] = true;
  71. }
  72. return false;
  73. }
  74. function updateCompanyHtml(data) {
  75. const html = [];
  76. for (const a of data.select) {
  77. html.push('<div class="form-group">');
  78. html.push('<input type="text" id="' + a.id +'" class="form-control form-control-sm" value="'+ a.name +'">');
  79. html.push('</div>');
  80. }
  81. $('#companyshow').html(html.join(''));
  82. }
  83. function selectCompanyHtml(data) {
  84. const html = [];
  85. for (const s of data.select) {
  86. html.push('<option>'+ s.name +'</option>');
  87. }
  88. for (const u of unitList) {
  89. html.push('<option>'+ u.name +'</option>');
  90. }
  91. $('#company').html(html);
  92. }