change_company.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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" 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. addcompanyArr.push($(this).val());
  20. });
  21. var updatecompanyArr = new Array();
  22. var updatecompanyidArr = new Array();
  23. $('#companyshow').find('.form-control').each(function(){
  24. updatecompanyArr.push($(this).val());
  25. updatecompanyidArr.push($(this).attr('id'));
  26. });
  27. //判断是否有重名情况再提交
  28. let flag = isRepeat(addcompanyArr.concat(updatecompanyArr));
  29. if(!flag){
  30. const data = {
  31. tid: $('#tenderId').val(),
  32. uci:updatecompanyidArr.length !== 0 ? updatecompanyidArr : '',
  33. uc:updatecompanyArr.length ? updatecompanyArr : '',
  34. ac:addcompanyArr.length !== 0 ? addcompanyArr : ''
  35. };
  36. postData('/change/update/company', data, function (result) {
  37. $('#companyadddiv').html('');
  38. addCompanyHtml(result);
  39. selectCOmpanyHtml(result);
  40. $('#editcompany').modal('hide');
  41. toastr.success('变更单位已更新');
  42. $('#updatecompany').attr('disabled',false);
  43. });
  44. }else{
  45. toastr.error('变更单位不能同名');
  46. $('#updatecompany').attr('disabled',false);
  47. }
  48. });
  49. });
  50. function isRepeat(arr){
  51. let hash = {};
  52. for(let i in arr) {
  53. if(hash[arr[i]])
  54. return true;
  55. hash[arr[i]] = true;
  56. }
  57. return false;
  58. }
  59. function addCompanyHtml(data) {
  60. const html = [];
  61. for (const a of data.add) {
  62. html.push('<div class="form-group">');
  63. html.push('<input type="text" id="' + a.id +'" class="form-control" value="'+ a.name +'">');
  64. html.push('</div>');
  65. }
  66. $('#companyshow').append(html.join(''));
  67. }
  68. function selectCOmpanyHtml(data) {
  69. const html = [];
  70. for (const s of data.select) {
  71. html.push('<option>'+ s.name +'</option>');
  72. }
  73. $('#company').html(html);
  74. }