change_company.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. changeInfo.company = $('#company').val();
  46. judgeChange();
  47. });
  48. }else{
  49. toastr.error('变更单位不能同名');
  50. $('#updatecompany').attr('disabled',false);
  51. }
  52. });
  53. });
  54. function isRepeat(arr){
  55. let hash = {};
  56. for(let i in arr) {
  57. if($.trim(arr[i]) !== '' && hash[arr[i]])
  58. return true;
  59. hash[arr[i]] = true;
  60. }
  61. return false;
  62. }
  63. function updateCompanyHtml(data) {
  64. const html = [];
  65. for (const a of data.select) {
  66. html.push('<div class="form-group">');
  67. html.push('<input type="text" id="' + a.id +'" class="form-control form-control-sm" value="'+ a.name +'">');
  68. html.push('</div>');
  69. }
  70. $('#companyshow').html(html.join(''));
  71. }
  72. function selectCompanyHtml(data) {
  73. const html = [];
  74. for (const s of data.select) {
  75. html.push('<option>'+ s.name +'</option>');
  76. }
  77. $('#company').html(html);
  78. }