| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- function addSubProject() {
- const editBox = document.querySelector('div.edit-box')
- const inputs = editBox.querySelectorAll('.form-control')
- inputs.forEach((input) => {
- input.value = ''
- })
- // 移除已存在的delete_old_data复选框
- const existingCheckbox = document.getElementById('delete_old_data')
- if (existingCheckbox) {
- existingCheckbox.parentNode.remove()
- }
- const file = document.getElementById('sub_project_file').parentNode
- file.innerHTML = `<label for="sub_project_file">工程数据:</label><input type="file" id="sub_project_file" class="form-control" accept=".xlsx,.xls,.csv" multiple>`
- editBox.classList.add('show')
- }
- function updateSubProject(row, id) {
- document.getElementById('sub_id').value = id
- document.getElementById('sub_project_name').value = row.querySelector('.sub_project_name .form-control').value
- document.getElementById('work_catalog').value = row.querySelector('.work_catalog .form-control').value
- document.getElementById('work_content').value = row.querySelector('.work_content .form-control').value
- const file = document.getElementById('sub_project_file').parentNode
- file.innerHTML = `<label for="sub_project_file">工程数据:</label><input type="file" id="sub_project_file" class="form-control" accept=".xlsx,.xls,.csv" multiple>`
- // 移除已存在的delete_old_data复选框
- const existingCheckbox = document.getElementById('delete_old_data')
- if (existingCheckbox) {
- existingCheckbox.parentNode.remove()
- }
- const checkboxDiv = document.createElement('div')
- checkboxDiv.innerHTML = `<label for="delete_old_data">删除原数据:</label><input type="checkbox" id="delete_old_data" class="form-control" style="width: auto;flex: 0;">`
- file.parentNode.insertBefore(checkboxDiv, file.nextSibling)
- // document.getElementById('new_standard_version').value = row.querySelector('.standard_version .form-control').value
- const editBox = document.querySelector('div.edit-box')
- editBox.classList.add('show')
- }
- function saveSubProject() {
- const id = document.getElementById('sub_id').value
- const project_id = document.getElementById('project_id').value
- const name = document.getElementById('sub_project_name').value
- const files = document.getElementById('sub_project_file').files
- const catalog = document.getElementById('work_catalog').value
- // const version = document.getElementById('new_standard_version').value
- const version = '2'
- const content = document.getElementById('work_content').value
- if (name === '') {
- alert('工程名称不能为空')
- return
- }
- if (files.length === 0 && !id) {
- alert('请选择工程数据文件')
- return
- }
- // if (catalog === '') {
- // alert('工作目录不能为空')
- // return
- // }
- if (content === '') {
- alert('工作内容不能为空')
- return
- }
- const formData = new FormData()
- formData.append('id', id)
- formData.append('project_id', project_id)
- formData.append('sub_project_name', name)
- for (let i = 0; i < files.length; i++) {
- formData.append('project_files', files[i])
- }
- formData.append('work_catalog', catalog)
- formData.append('work_content', content)
- formData.append('standard_version', version)
- if (document.getElementById('delete_old_data')) {
- formData.append('delete_old_data', document.getElementById('delete_old_data').checked)
- }
- fetch('/save_sub_project', {
- method: 'POST',
- body: formData,
- })
- .then((response) => response.json())
- .then((data) => {
- if (data.success) {
- alert('保存成功')
- window.location.reload()
- } else {
- alert('保存失败:' + data.error)
- }
- })
- .catch((error) => {
- console.error('保存失败:', error)
- alert('保存失败')
- })
- }
- function cancelAdd() {
- const editBox = document.querySelector('div.edit-box')
- editBox.classList.remove('show')
- }
- function saveProjectUpdate(row, id) {
- const no = row.querySelector('.project_no .form-control').value
- const name = row.querySelector('.project_name .form-control').value
- const work_catalog = row.querySelector('.work_catalog .form-control').value
- const work_content = row.querySelector('.work_content .form-control').value
- const version = row.querySelector('.standard_version .form-control').value
- if (no === '') {
- alert('名称不能为空')
- return
- }
- if (name === '') {
- alert('名称不能为空')
- return
- }
- if (version === '') {
- alert('版本不能为空')
- return
- }
- fetch('/update_sub_project', {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- },
- body: JSON.stringify({
- id: id,
- project_no: no,
- project_name: name,
- work_catalog: work_catalog,
- work_content: work_content,
- standard_version: version,
- }),
- })
- .then((response) => response.json())
- .then((data) => {
- if (data.success) {
- alert('更新成功')
- window.location.reload()
- } else {
- alert('更新失败:' + data.error)
- }
- })
- .catch((error) => {
- console.error('更新失败:', error)
- alert('更新失败')
- })
- }
- function confirmStartTask(id) {
- _confirm('确定要开始任务吗?', `/start_sub_project_task/${id}`)
- }
- function confirmReStartTask(id) {
- _confirm('确定要重新采集数据吗?', `/start_sub_project_task/${id}`)
- }
- function confirmReProcessData(id) {
- _confirm('确定要重新处理数据吗?', `/start_process_sub_project/${id}`)
- }
- function confirmSendData(id) {
- _confirm('确定要开始上传数据吗?', `/start_send_sub_project/${id}`)
- }
- function _confirm(text, url) {
- if (confirm(text)) {
- fetch(url, {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- },
- })
- .then((response) => response.json())
- .then((data) => {
- if (data.success) {
- alert('操作成功')
- window.location.reload()
- } else {
- alert('操作失败:' + data.error)
- }
- })
- .catch((error) => {})
- }
- }
- function confirmProjectDelete(id) {
- if (confirm('确定要删除该工程吗?')) {
- fetch(`/delete_sub_project/${id}`, {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- },
- })
- .then((response) => response.json())
- .then((data) => {
- if (data.success) {
- alert('删除成功')
- window.location.reload()
- } else {
- alert('删除失败:' + data.error)
- }
- })
- .catch((error) => {
- console.error('删除失败:', error)
- alert('删除失败')
- })
- }
- }
|