ZN
5 天以前 e756e3cc5ddd0ddb42c5f00d6bb3eee76ba73e6f
src/views/projectManagement/projectType/components/ProjectTypeDialog.vue
@@ -32,16 +32,19 @@
        <div class="info-item">
          <span class="item-label">附件</span>
          <el-upload
            v-if="isEdit"
            :action="uploadUrl"
            :headers="uploadHeaders"
            :on-success="handleUploadSuccess"
            :on-remove="handleRemove"
            :file-list="form.attachmentList"
            v-model:file-list="uploadFileList"
            :limit="3"
            name="files"
            multiple
          >
            <el-button type="primary">上传附件</el-button>
          </el-upload>
          <span v-else class="text-gray-400 text-sm">请先保存后再上传附件</span>
        </div>
      </div>
@@ -130,6 +133,11 @@
              <el-input v-model="scope.row.workContent" placeholder="请输入" />
            </template>
          </el-table-column>
          <el-table-column label="操作" min-width="150">
            <template #default="scope">
              <el-button type="danger" size="mini" @click="removeStep(scope.$index)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
        <div class="add-row-btn" @click="addStep">
@@ -151,7 +159,7 @@
import { ref, watch, onMounted, nextTick } from 'vue';
import { Plus, QuestionFilled } from '@element-plus/icons-vue';
import { userListNoPageByTenantId } from '@/api/system/user';
import { ElMessage } from 'element-plus';
import { ElMessage, ElMessageBox } from 'element-plus';
import { getToken } from '@/utils/auth';
import Sortable from 'sortablejs';
@@ -166,6 +174,7 @@
const visible = ref(false);
const formRef = ref(null);
const userOptions = ref([]);
const isEdit = ref(false);
const uploadHeaders = { Authorization: "Bearer " + getToken() };
// 上传地址
const uploadUrl = import.meta.env.VITE_APP_BASE_API + "/basic/customer-follow/upload";
@@ -176,9 +185,9 @@
  name: '',
  description: '',
  attachmentIds: [],
  attachmentList: [],
  savePlanNodeList: []
});
const uploadFileList = ref([]);
const rules = {
  name: [{ required: true, message: '请输入名称', trigger: 'blur' }]
@@ -190,19 +199,16 @@
  if (val) {
    if (props.data) {
      // 编辑模式 - 回显数据
      isEdit.value = true;
      form.value = {
        id: props.data.id,
        name: props.data.name,
        description: props.data.description,
        attachmentIds: [],
        attachmentList: props.data.attachmentList || [],
        attachmentIds: Array.isArray(props.data.attachmentIds)
          ? props.data.attachmentIds
          : (props.data.attachmentList || []).map(f => f.id).filter(Boolean),
        savePlanNodeList: []
      };
      // 回显附件ID
      if (form.value.attachmentList && form.value.attachmentList.length > 0) {
        form.value.attachmentIds = form.value.attachmentList.map(item => item.id);
      }
      
      // 回显步骤节点
      if (props.data.planNodeList && props.data.planNodeList.length > 0) {
@@ -222,6 +228,7 @@
      }
    } else {
      // 新增模式
      isEdit.value = false;
      resetForm();
    }
    // 初始化拖拽
@@ -273,9 +280,9 @@
    name: '',
    description: '',
    attachmentIds: [],
    attachmentList: [],
    savePlanNodeList: [createDefaultNode()]
  };
  uploadFileList.value = [];
  if (formRef.value) {
    formRef.value.resetFields();
  }
@@ -304,19 +311,14 @@
/** 处理文件上传成功 */
function handleUploadSuccess(response, file, fileList) {
  if (response.code === 200) {
    ElMessage.success('上传成功');
    // 假设后端返回的数据结构中包含文件ID和URL等信息
    // 这里需要根据实际接口返回结构进行调整
    // 通常 response.data 包含文件信息
    const newFile = response.data;
    if (newFile && newFile.id) {
       form.value.attachmentIds.push(newFile.id);
       form.value.attachmentList.push({
         name: file.name,
         url: newFile.url,
         id: newFile.id
       });
    }
    const list = Array.isArray(newFile) ? newFile : [newFile];
    list.forEach(element => {
      const id = element?.id;
      if (id && !form.value.attachmentIds.includes(id)) {
        form.value.attachmentIds.push(id);
      }
    });
  } else {
    ElMessage.error(response.msg || '上传失败');
  }
@@ -324,15 +326,9 @@
/** 处理文件移除 */
function handleRemove(file) {
  const index = form.value.attachmentList.findIndex(item => item.name === file.name);
  if (index !== -1) {
    const fileId = form.value.attachmentList[index].id;
    form.value.attachmentList.splice(index, 1);
    const idIndex = form.value.attachmentIds.indexOf(fileId);
    if (idIndex !== -1) {
      form.value.attachmentIds.splice(idIndex, 1);
    }
  }
  const removedId = file?.id || file?.response?.data?.id;
  if (!removedId) return;
  form.value.attachmentIds = form.value.attachmentIds.filter(id => id !== removedId);
}
/** 添加步骤 */
@@ -346,7 +342,14 @@
    ElMessage.warning('至少保留一个步骤');
    return;
  }
  form.value.savePlanNodeList.splice(index, 1);
  ElMessageBox.confirm('是否确认删除该步骤?', '系统提示', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning'
  }).then(() => {
    form.value.savePlanNodeList.splice(index, 1);
  }).catch(() => {});
}
/** 移动步骤 */