<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="项目名称" prop="projectName">
        <el-input
          v-model="queryParams.projectName"
          placeholder="请输入项目名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建者" prop="ownerId">
        <el-input
          v-model="queryParams.ownerId"
          placeholder="创始人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="完成时间" prop="finishTime">
        <el-date-picker clearable
                        v-model="queryParams.finishTime"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择完成时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="截止日期" prop="deadline">
        <el-date-picker clearable
                        v-model="queryParams.deadline"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择截止日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="项目标签" prop="projectLabel">
        <el-select v-model="queryParams.projectLabel" placeholder="请选择项目标签" clearable>
          <el-option label="项目任务" value="项目任务"/>
          <el-option label="项目研究" value="项目研究"/>
          <el-option label="项目学习" value="项目学习"/>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['project:project:add']"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['project:project:edit']"
        >修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['project:project:remove']"
        >删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :disabled="multiple"
          @click="handleExport"
          v-hasPermi="['project:project:export']"
        >资料下载
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="projectList" @selection-change="handleSelectionChange"
              @row-click="handleRowClick">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="项目名称" align="center" prop="projectName"/>
      <el-table-column label="当前状态" align="center" prop="status">
        <template slot-scope="scope">
          <el-tag
            :type="scope.row.status === '0' ? 'warning' : 'success'"
            disable-transitions
          >
            {{ {0: '进行中', 1: '已完成', 2: '立项中'}[scope.row.status] }}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column label="完成时间" align="center" prop="finishTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.finishTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="截止日期" align="center" prop="deadline" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.deadline, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="项目标签" align="center" prop="projectLabel"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click.stop="handleUpdate(scope.row)"
            v-hasPermi="['project:project:edit']"
          >修改
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click.stop="handleDelete(scope.row)"
            v-hasPermi="['project:project:remove']"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 模块抽屉 -->
    <el-drawer :visible.sync="drawer" title="模块列表" direction="rtl" size="60%">
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="ModelsAdd"
            v-hasPermi="['project:project:add']"
          >新增
          </el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="danger"
            plain
            icon="el-icon-delete"
            size="mini"
            :disabled="moduleMultiple"
            @click="handleModelsDelete"
            v-hasPermi="['project:module:remove']"
          >批量删除
          </el-button>
        </el-col>
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </el-row>
      <el-table :data="moduleList"
                stripe
                @selection-change="handleModuleSelectionChange">
        <!-- 多选列 -->
        <el-table-column type="selection" width="55" align="center"/>
        <el-table-column label="模块名称" prop="moduleName"/>
        <el-table-column label="状态">
          <template #default="{ row }">
            <el-tag :type="row.status === '0' ? 'info' : row.status === '1' ? 'warning' : 'success'">
              {{ {0: '待接取', 1: '进行中', 2: '已完成'}[row.status] }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column label="接取人" prop="assignee"/>
        <el-table-column label="操作">
          <template #default="{ row }">
            <el-button size="mini" type="text" icon="el-icon-edit" @click="editModule(row)" v-hasPermi="['project:module:edit']">修改</el-button>
            <el-button v-if="row.status === '0'" size="mini" type="text" icon="el-icon-delete" @click="deleteModule(row)" v-hasPermi="['project:module:remove']">删除</el-button>
            <el-button v-if="row.status === '0'" size="mini" type="text" icon="el-icon-position" @click="openAssign(row)" v-hasPermi="['project:module:assign']">指派</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-drawer>

    <!-- 指派模块对话框（抽屉内使用） -->
    <el-dialog title="指派模块" :visible.sync="assignOpen" width="500px" append-to-body>
      <el-form ref="assignFormRef" :model="assignForm" label-width="80px">
        <el-form-item label="模块名称">
          <el-input v-model="assignForm.moduleName" disabled />
        </el-form-item>
        <el-form-item label="指派给" prop="assignee">
          <el-select v-model="assignForm.assignee" placeholder="请选择用户" filterable>
            <el-option v-for="item in userOptions" :key="item.userName" :label="item.nickName" :value="item.userName" />
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitAssign">确 定</el-button>
        <el-button @click="assignOpen=false">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 添加或修改项目对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="项目名称" prop="projectName">
          <el-input v-model="form.projectName" placeholder="请输入项目名称"/>
        </el-form-item>
        <el-form-item label="截止日期" prop="deadline">
          <el-date-picker clearable
                          v-model="form.deadline"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择截止日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="项目标签" prop="projectLabel">
          <el-select v-model="form.projectLabel" placeholder="请选择项目标签">
            <el-option label="项目任务" value="项目任务"/>
            <el-option label="项目研究" value="项目研究"/>
            <el-option label="项目学习" value="项目学习"/>
          </el-select>
        </el-form-item>
        <el-form-item label="起始日期" prop="startTime">
          <el-date-picker clearable
                          v-model="form.startTime"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择起始日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="项目状态" prop="status" v-if="!form.projectId">
          <el-input :value="statusText" disabled />
        </el-form-item>
        <el-form-item label="项目状态" prop="status" v-else>
          <el-select v-model="form.status" placeholder="请选择">
            <el-option label="立项中" value="2"/>
            <el-option label="进行中" value="0"/>
            <el-option label="已完成" value="1"/>
          </el-select>
        </el-form-item>        
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 模块添加对话框-->
    <el-dialog :title="title" :visible.sync="Models" width="500px" append-to-body>
      <el-form ref="form" :model="modelsForm" :rules="rules" label-width="80px">
        <el-form-item label="模块名称" prop="ModelName">
          <el-input v-model="modelsForm.moduleName" placeholder="请输入模块名称"/>
        </el-form-item>
        <el-form-item label="截止日期" prop="deadline">
          <el-date-picker clearable
                          v-model="modelsForm.deadline"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择截止日期">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="subMitModel">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 完成模块 + 上传文件弹窗 -->
    <el-dialog title="完成模块并上传附件" :visible.sync="finishDialog" width="500px">
      <el-upload
        ref="uploader"
        class="upload-demo"
        :action="upload.url"
        :headers="upload.headers"
        :file-list="upload.fileList"
        :data="upload.data"
        :before-upload="beforeUpload"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :auto-upload="false"
        accept=".pdf,.doc,.docx,.txt,.md"
      >
        <el-button size="small" type="primary">选择文件</el-button>
        <div slot="tip" class="el-upload__tip">支持 PDF、DOC、DOCX、TXT、MD，单文件≤20MB</div>
      </el-upload>
      <div slot="footer">
        <el-button @click="finishDialog=false">取 消</el-button>
        <el-button type="primary" @click="submitFinish">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {listProject, getProject, delProject, addProject, updateProject} from "@/api/project/project"
import {addModels, delModels, selectbyProjectId, updateModels} from "@/api/models/models";
import { assignModule } from "@/api/project/module";
import { listUser } from "@/api/system/user";
import Cookies from "js-cookie";
import {getUserRole} from "@/api/system/role";
import {getSysUser} from "@/api/system/user";
import moment from "moment";
import { downloadDoc } from "@/api/doc/doc";
import { getToken } from "@/utils/auth";

export default {
  name: "Project",
  data() {
    return {
      //完成模块弹窗:上传文件
      finishDialog: false,
      //模块是否被接取
      isRecv: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 项目表格数据
      projectList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      //是否显示模块添加弹出层
      Models: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        projectName: null,
        ownerId: null,
        status: null,
        finishTime: null,
        deadline: null,
        projectLabel: null
      },
      // 表单参数
      form: {
        status:0,
        finishTime: null,
      },
      // 统一上传配置
      upload: {
        url: process.env.VUE_APP_BASE_API + "/project/doc/upload",
        headers: { Authorization: "Bearer " + getToken() },
        fileList: [],
        data: {}
      },

      //模块校验
      modelsForm: {
        moduleId: null,
        projectId: null,
        ModelName: null,
        status: null,
        assignee: null,
        assignTime: null,
        del_flag: null,
        create_by: null,
        finishTime: null
      },

      // 表单校验
      rules: {
        projectName: [
          {required: true, message: "项目名称不能为空", trigger: "blur"}
        ],
        moduleName: [
          {required: true, message: "模块名称不能为空", trigger: "blur"}
        ],
        deadline: [
          {required: true, message: "截止日期不能为空", trigger: "blur"}
        ]
      },

      //项目ID
      projectId: null,
      projectTitle: null,
      kindType: null, // '0' | '1'

      //当前角色:1-普通用户,100-平台管理员,101-项目管理员
      RoleId: null,

      //模块抽屉
      drawer: false,
      moduleList: [],
      // 多选保存行数据，用于批量删除时判断状态
      selectedModules: [],

      uploadTarget: '',   // 'project' | 'module'

      moduleIds: [],        // 选中的模块 id
      moduleMultiple: true,  // 是否禁用批量删除按钮
      // 指派对话框
      assignOpen: false,
      assignForm: {
        projectId: null,
        moduleId: null,
        moduleName: '',
        assignee: null
      },
      userOptions: []
    }
  },
  created() {
    this.getList()
  },
  computed: {
    statusText() {
      const map = { '0': '进行中', '1': '已完成', '2': '立项中' }
      return map[this.form.status] || ''
    }
  },
  watch: {
    'form.startTime'(nv) {
      const today = moment().startOf('day')
      if (nv) {
        const st = moment(nv, 'YYYY-MM-DD')
        if (this.form.status !== '1') {
          this.form.status = st.isAfter(today) ? '2' : '0'
        }
      } else {
        if (this.form.status !== '1') {
          this.form.status = '0'
        }
      }
    }
  },
  methods: {
    //批量删除模块（仅删除待接取：status === '0'）
    handleModelsDelete() {
      if (this.moduleIds.length === 0) return

      const deletableIds = this.selectedModules
        .filter(item => String(item.status) === '0')
        .map(item => item.moduleId)

      const notDeletableCount = this.selectedModules.length - deletableIds.length

      if (deletableIds.length === 0) {
        this.$modal.msgError('请选择状态为“待接取”的模块进行删除')
        return
      }

      const tip = notDeletableCount > 0
        ? `确定删除选中的 ${deletableIds.length} 条未接取模块？（其中 ${notDeletableCount} 条进行中或已完成，无法删除）`
        : `确定删除选中的 ${deletableIds.length} 条模块？`

      this.$modal.confirm(tip)
        .then(() => {
          const promises = deletableIds.map(id => delModels(id))
          return Promise.all(promises)
        })
        .then(() => {
          this.$message.success('删除成功')
          this.moduleList = this.moduleList.filter(m => !deletableIds.includes(m.moduleId))
          this.moduleIds = []
          this.selectedModules = []
          this.moduleMultiple = true
        })
        .catch(() => {})
    },


// 1. 勾选回调
    handleModuleSelectionChange(selection) {
      this.selectedModules = selection
      this.moduleIds = selection.map(item => item.moduleId)
      this.kindType = 1;
      console.log(this.moduleIds[0])
      this.moduleMultiple = selection.length === 0   // 没勾选就禁用按钮
    },

    // 上传回调
    handleFileUploadProgress() {},
    handleFileSuccess() {
      this.$message.success(this.uploadTarget === 'project' ? '项目文档上传成功' : '模块文档上传成功')
      this.finishDialog = false
      if (this.uploadTarget === 'module') {
        this.getModuleList()
      }
    },

    // 触发上传
    triggerUpload() {
      if (this.$refs.uploader) this.$refs.uploader.submit()
    },

    // 上传前校验
    beforeUpload(file) {
      const isLt20M = file.size / 1024 / 1024 < 20;
      if (!isLt20M) {
        this.$message.error("文件大小不能超过 20MB");
      }
      return isLt20M; // 返回 true 允许上传
    },

    /* 点击弹窗“确定”时调用 */
    submitUploadFiles() {
      this.triggerUpload()
    },

    //上传文件并完成模块
    submitFinish() {
      if (this.uploadTarget === 'module') {
        updateModels(this.modelsForm).then(res => {
          if (res.code === 200) {
            this.$message.success('模块已完成');
          }
        });
      }

      //上传文件
      this.submitUploadFiles();

    },

    //项目上传文件
    openProjectUpload() {
      this.uploadTarget = 'project'
      this.upload.fileList = []
      this.upload.data = { kindType: 0, projectId: this.form.projectId }
      this.finishDialog = true
    },
    //完成模块
    openFinishDialog(row) {
      //获取基本信息
      this.uploadTarget = 'module'
      this.finishDialog = true;
      this.modelsForm.moduleId = row.moduleId
      this.modelsForm.status = 2;
      this.upload.fileList = []
      this.upload.data = { kindType: 1, projectId: this.projectId, moduleId: row.moduleId }
      this.modelsForm.finishTime = moment().format('YYYY-MM-DD HH:mm:ss');
    },

    //放弃模块
    giveMode(row) {
      this.modelsForm.moduleId = row.moduleId
      this.modelsForm.status = 0;//待接取
      updateModels(this.modelsForm).then(res => {
        this.$message.success("已放弃")
        location.reload();
      })
    },

    //添加模块
    subMitModel() {
      this.modelsForm.projectId = this.projectId;
      this.modelsForm.status = 0;//待接取
      getSysUser(Cookies.get("username")).then(res => {
        this.modelsForm.create_by = res.sysUser.nickName;
      })
      addModels(this.modelsForm).then(res => {
        if (res.code === 200) {
          this.$message.success("添加完成");
          location.reload();
        } else {
          this.$message.error("添加失败,请重试")
        }
      })
    },

    //接取模块
    recvModel(row) {
      this.modelsForm.moduleId = row.moduleId
      //修改状态
      this.modelsForm.status = 1; //已接取
      getSysUser(Cookies.get("username")).then(res => {
        this.modelsForm.assignee = res.sysUser.nickName;
        this.modelsForm.assignTime = moment().format('YYYY-MM-DD HH:mm:ss');
        updateModels(this.modelsForm).then(ress => {
          this.$message.success("已接取")
          location.reload();
        })
      })
    },

    //获取当前用户角色
    GetRole() {
      //获取当前登陆账户
      const usercount = Cookies.get("username");
      getUserRole(usercount).then(res => {
        this.RoleId = res.roleId[0]
      })
    },

    //添加模块
    ModelsAdd() {
      // 打开模块添加对话框，并传递projectId
      this.Models = true;
      this.title = "添加模块";
    },

    // 点击行
    handleRowClick(row) {
      if (this.open === false) {
        this.drawer = true;
      }
      this.projectId = row.projectId;
      this.getModuleList()
      this.GetRole()
    },

    //获取模块列表
    getModuleList() {
      selectbyProjectId(this.projectId).then(res => {
        this.moduleList = res.rows;
      });
    },

    /** 查询项目列表 */
    getList() {
      this.loading = true
      listProject(this.queryParams).then(response => {
        this.projectList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.Models = false
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        projectName: null,
        ownerId: null,
        status: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        finishTime: null,
        deadline: null,
        projectLabel: null
      }
      this.resetForm("form")
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm")
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.projectId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
      this.projectId = selection[0].projectId;
      this.kindType = 0;
    },

    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true;
      this.drawer = false;
      if (this.form.startTime) {
        const today = moment().startOf('day')
        const st = moment(this.form.startTime, 'YYYY-MM-DD')
        this.form.status = st.isAfter(today) ? '2' : '0'
      } else {
        this.form.status = '0'
      }
      this.title = "添加项目";
    },

    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      this.open = true;
      this.drawer = false;
      const projectId = row.projectId || this.ids
      getProject(projectId).then(response => {
        this.form = response.data
        this.title = "修改项目"
        this.projectTitle = this.title;
      })
    },

    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        this.finishDialog = false;
        if (valid) {
          if (this.form.projectId != null) {
            console.log(this.form)
            // this.form.status = (this.form.status === '已完成' ? '1' : '0');
            if (this.form.status === '1' && this.form.finishTime == null) {
              this.form.finishTime = moment().format('YYYY-MM-DD HH:mm:ss');
            }
            updateProject(this.form).then(response => {
              this.$modal.msgSuccess("修改成功")
              this.open = false
              this.getList()
            })
          } else {
            const today = moment().startOf('day');
            if (this.form.startTime) {
              const st = moment(this.form.startTime, 'YYYY-MM-DD');
              this.form.status = st.isAfter(today) ? '2' : '0';
            } else {
              this.form.status = '0';
            }
            addProject(this.form).then(response => {
              this.$modal.msgSuccess("新增成功")
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      this.drawer = false;
      const projectIds = row.projectId || this.ids
      this.$modal.confirm('是否确认删除项目编号为"' + projectIds + '"的数据项？').then(function () {
        return delProject(projectIds)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess("删除成功")
      }).catch(() => {
      })
    },

    async downLoadDoc(id, type) {
      try {
        // 1. 调接口（axios 在 responseType:'blob' 时直接返回 Blob）
        const blob = await downloadDoc(id, type);

        // 2. 生成下载地址
        const url = window.URL.createObjectURL(blob);

        // 3. 创建 a 标签并触发下载
        const link = document.createElement('a');
        link.style.display = 'none';
        link.href = url;
        link.download = 'download.zip';   // 也可用后端返回的文件名
        document.body.appendChild(link);
        link.click();
        document.body.removeChild(link);
        window.URL.revokeObjectURL(url);
      } catch (e) {
        console.error(e);
        this.$message.error('下载失败');
      }
    },

    /** 导出按钮操作 */
    async handleExport() {
      this.downLoadDoc(this.projectId, this.kindType);
    },

    async handleModelsExport() {
      this.downLoadDoc(this.moduleIds[0], this.kindType);
    },
    // 打开指派弹窗
    openAssign(row) {
      this.assignForm = { projectId: this.projectId, moduleId: row.moduleId, moduleName: row.moduleName, assignee: null }
      this.assignOpen = true
      this.fetchUsers()
    },
    // 提交指派
    submitAssign() {
      if (!this.assignForm.assignee) {
        this.$modal.msgError('请选择要指派的用户')
        return
      }
      // 复用项目模块接口（与模块管理页一致）
      assignModule(this.assignForm).then(() => {
        this.$modal.msgSuccess('指派成功')
        this.assignOpen = false
        this.getModuleList()
      })
    },
    // 加载可指派用户
    fetchUsers() {
      listUser({ pageNum: 1, pageSize: 100 }).then(res => {
        this.userOptions = res.rows || []
      })
    },
    // 编辑模块
    editModule(row) {
      this.modelsForm = { ...this.modelsForm, ...row }
      this.Models = true
      this.title = '修改模块'
    },
    // 删除模块
    deleteModule(row) {
      if (String(row.status) !== '0') {
        this.$modal.msgError('进行中或已完成的模块无法删除')
        return
      }
      const id = row.moduleId
      this.$modal.confirm('是否确认删除模块编号为"' + id + '"的数据项？').then(() => {
        return delModels(id)
      }).then(() => {
        this.$modal.msgSuccess('删除成功')
        this.getModuleList()
      })
    },
  }
}
</script>
