change_company.js 2.6 KB

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