advice.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. let fileArray = [];
  2. function openApply() {
  3. const manual = document.getElementById('advice_manual');
  4. const manualHead = document.getElementById('advice_manual_header');
  5. const apply = document.getElementById('advice_apply');
  6. const applyHead = document.getElementById('advice_apply_header');
  7. manual.style.display = 'none';
  8. manualHead.style.display = 'none';
  9. apply.style.display = 'block';
  10. applyHead.style.display = 'block';
  11. }
  12. async function dupleNickCheck() {
  13. const nicknameInput = document.getElementById('lg_nickname');
  14. const nickname = nicknameInput.value;
  15. if (nickname.length > 0) {
  16. const res = await axios.post('api/v1/board/nickname', {nickname})
  17. if (res.data.checkCount > 0) {
  18. alert('중복된 닉네임입니다.');
  19. nicknameInput.value = null;
  20. } else {
  21. alert('사용 가능한 닉네임입니다.');
  22. nicknameInput.disabled = true;
  23. }
  24. }
  25. }
  26. function subForm() {
  27. if (validationCheck()) {
  28. const form = document.getElementById('logi_ad_form')
  29. const formData = new FormData(form);
  30. formData.append('userName', document.getElementById('lg_name').value);
  31. formData.append('phoneNum', document.getElementById('lg_phone').value);
  32. formData.append('email', document.getElementById('lg_email').value);
  33. formData.append('nickname', document.getElementById('lg_nickname').value);
  34. if (fileArray.length > 0) {
  35. console.log(fileArray)
  36. for (let file of fileArray) {
  37. formData.append('files', file[0]);
  38. }
  39. }
  40. axios.post('api/v1/board/add', formData)
  41. .then(function (res) {
  42. alert('신청이 완료되었습니다.');
  43. clearApply();
  44. clearModal();
  45. })
  46. .catch(function (e) {
  47. console.log(e)
  48. })
  49. }
  50. }
  51. function clearApply() {
  52. const div = document.getElementById('advice_apply');
  53. const inputElements = div.querySelectorAll('input');
  54. const btnElements = div.querySelectorAll('button');
  55. inputElements.forEach(input => {
  56. input.value = '';
  57. });
  58. btnElements.forEach(btn=>{
  59. btn.disabled = false;
  60. })
  61. const ul = document.getElementById('lg_file_list');
  62. ul.innerHTML = '';
  63. fileArray = [];
  64. }
  65. function clearModal() {
  66. const form = document.getElementById('check_info');
  67. const inputElements = form.querySelectorAll('input');
  68. inputElements.forEach(input => {
  69. input.value = '';
  70. });
  71. const timer = document.getElementById('timer');
  72. timer.innerHTML = '';
  73. }
  74. /*
  75. document.getElementById('lg_file').addEventListener('change', (event)=>{
  76. const files = event.target.files;
  77. let html = '';
  78. if (fileArray.length > 5) {
  79. alert('파일은 5개까지 업로드 가능합니다.')
  80. } else {
  81. fileArray.push(files);
  82. }
  83. const ul = document.getElementById('lg_file_list');
  84. const textNode = document.createTextNode(files[0].name);
  85. const li = document.createElement('li');
  86. li.setAttribute('class', 'list-group-item')
  87. li.appendChild(textNode);
  88. ul.appendChild(li);
  89. })
  90. */
  91. function initFile (input) {
  92. const files = input.files;
  93. let html = '';
  94. if (fileArray.length > 5) {
  95. alert('파일은 5개까지 업로드 가능합니다.')
  96. } else {
  97. fileArray.push(files);
  98. }
  99. const ul = document.getElementById('lg_file_list');
  100. const textNode = document.createTextNode(files[0].name);
  101. const li = document.createElement('li');
  102. li.setAttribute('class', 'list-group-item')
  103. li.appendChild(textNode);
  104. ul.appendChild(li);
  105. }