sub_project_list.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. function addSubProject() {
  2. const editBox = document.querySelector('div.edit-box')
  3. const inputs = editBox.querySelectorAll('.form-control')
  4. inputs.forEach((input) => {
  5. input.value = ''
  6. })
  7. // 移除已存在的delete_old_data复选框
  8. const existingCheckbox = document.getElementById('delete_old_data')
  9. if (existingCheckbox) {
  10. existingCheckbox.parentNode.remove()
  11. }
  12. const file = document.getElementById('sub_project_file').parentNode
  13. file.innerHTML = `<label for="sub_project_file">工程数据:</label><input type="file" id="sub_project_file" class="form-control" accept=".xlsx,.xls,.csv" multiple>`
  14. editBox.classList.add('show')
  15. }
  16. function updateSubProject(row, id) {
  17. document.getElementById('sub_id').value = id
  18. document.getElementById('sub_project_name').value = row.querySelector('.sub_project_name .form-control').value
  19. document.getElementById('work_catalog').value = row.querySelector('.work_catalog .form-control').value
  20. document.getElementById('work_content').value = row.querySelector('.work_content .form-control').value
  21. const file = document.getElementById('sub_project_file').parentNode
  22. file.innerHTML = `<label for="sub_project_file">工程数据:</label><input type="file" id="sub_project_file" class="form-control" accept=".xlsx,.xls,.csv" multiple>`
  23. // 移除已存在的delete_old_data复选框
  24. const existingCheckbox = document.getElementById('delete_old_data')
  25. if (existingCheckbox) {
  26. existingCheckbox.parentNode.remove()
  27. }
  28. const checkboxDiv = document.createElement('div')
  29. checkboxDiv.innerHTML = `<label for="delete_old_data">删除原数据:</label><input type="checkbox" id="delete_old_data" class="form-control" style="width: auto;flex: 0;">`
  30. file.parentNode.insertBefore(checkboxDiv, file.nextSibling)
  31. // document.getElementById('new_standard_version').value = row.querySelector('.standard_version .form-control').value
  32. const editBox = document.querySelector('div.edit-box')
  33. editBox.classList.add('show')
  34. }
  35. function saveSubProject() {
  36. const id = document.getElementById('sub_id').value
  37. const project_id = document.getElementById('project_id').value
  38. const name = document.getElementById('sub_project_name').value
  39. const files = document.getElementById('sub_project_file').files
  40. const catalog = document.getElementById('work_catalog').value
  41. // const version = document.getElementById('new_standard_version').value
  42. const version = '2'
  43. const content = document.getElementById('work_content').value
  44. if (name === '') {
  45. alert('工程名称不能为空')
  46. return
  47. }
  48. if (files.length === 0 && !id) {
  49. alert('请选择工程数据文件')
  50. return
  51. }
  52. // if (catalog === '') {
  53. // alert('工作目录不能为空')
  54. // return
  55. // }
  56. if (content === '') {
  57. alert('工作内容不能为空')
  58. return
  59. }
  60. const formData = new FormData()
  61. formData.append('id', id)
  62. formData.append('project_id', project_id)
  63. formData.append('sub_project_name', name)
  64. for (let i = 0; i < files.length; i++) {
  65. formData.append('project_files', files[i])
  66. }
  67. formData.append('work_catalog', catalog)
  68. formData.append('work_content', content)
  69. formData.append('standard_version', version)
  70. if (document.getElementById('delete_old_data')) {
  71. formData.append('delete_old_data', document.getElementById('delete_old_data').checked)
  72. }
  73. fetch('/save_sub_project', {
  74. method: 'POST',
  75. body: formData,
  76. })
  77. .then((response) => response.json())
  78. .then((data) => {
  79. if (data.success) {
  80. alert('保存成功')
  81. window.location.reload()
  82. } else {
  83. alert('保存失败:' + data.error)
  84. }
  85. })
  86. .catch((error) => {
  87. console.error('保存失败:', error)
  88. alert('保存失败')
  89. })
  90. }
  91. function cancelAdd() {
  92. const editBox = document.querySelector('div.edit-box')
  93. editBox.classList.remove('show')
  94. }
  95. function saveProjectUpdate(row, id) {
  96. const no = row.querySelector('.project_no .form-control').value
  97. const name = row.querySelector('.project_name .form-control').value
  98. const work_catalog = row.querySelector('.work_catalog .form-control').value
  99. const work_content = row.querySelector('.work_content .form-control').value
  100. const version = row.querySelector('.standard_version .form-control').value
  101. if (no === '') {
  102. alert('名称不能为空')
  103. return
  104. }
  105. if (name === '') {
  106. alert('名称不能为空')
  107. return
  108. }
  109. if (version === '') {
  110. alert('版本不能为空')
  111. return
  112. }
  113. fetch('/update_sub_project', {
  114. method: 'POST',
  115. headers: {
  116. 'Content-Type': 'application/json',
  117. },
  118. body: JSON.stringify({
  119. id: id,
  120. project_no: no,
  121. project_name: name,
  122. work_catalog: work_catalog,
  123. work_content: work_content,
  124. standard_version: version,
  125. }),
  126. })
  127. .then((response) => response.json())
  128. .then((data) => {
  129. if (data.success) {
  130. alert('更新成功')
  131. window.location.reload()
  132. } else {
  133. alert('更新失败:' + data.error)
  134. }
  135. })
  136. .catch((error) => {
  137. console.error('更新失败:', error)
  138. alert('更新失败')
  139. })
  140. }
  141. function confirmStartTask(id) {
  142. _confirm('确定要开始任务吗?', `/start_sub_project_task/${id}`)
  143. }
  144. function confirmReStartTask(id) {
  145. _confirm('确定要重新采集数据吗?', `/start_sub_project_task/${id}`)
  146. }
  147. function confirmReProcessData(id) {
  148. _confirm('确定要重新处理数据吗?', `/start_process_sub_project/${id}`)
  149. }
  150. function confirmSendData(id) {
  151. _confirm('确定要开始上传数据吗?', `/start_send_sub_project/${id}`)
  152. }
  153. function _confirm(text, url) {
  154. if (confirm(text)) {
  155. fetch(url, {
  156. method: 'POST',
  157. headers: {
  158. 'Content-Type': 'application/json',
  159. },
  160. })
  161. .then((response) => response.json())
  162. .then((data) => {
  163. if (data.success) {
  164. alert('操作成功')
  165. window.location.reload()
  166. } else {
  167. alert('操作失败:' + data.error)
  168. }
  169. })
  170. .catch((error) => {})
  171. }
  172. }
  173. function confirmProjectDelete(id) {
  174. if (confirm('确定要删除该工程吗?')) {
  175. fetch(`/delete_sub_project/${id}`, {
  176. method: 'POST',
  177. headers: {
  178. 'Content-Type': 'application/json',
  179. },
  180. })
  181. .then((response) => response.json())
  182. .then((data) => {
  183. if (data.success) {
  184. alert('删除成功')
  185. window.location.reload()
  186. } else {
  187. alert('删除失败:' + data.error)
  188. }
  189. })
  190. .catch((error) => {
  191. console.error('删除失败:', error)
  192. alert('删除失败')
  193. })
  194. }
  195. }