<!--项目输出资料表 -->
<template>
  <div>
    <el-dialog title="项目输出资料表" :model-value="dialogVisible" width="650px" :before-close="handleClose" :center="false"
      class="lcxmzl">
      <el-form :inline="true" :model="data" class="demo-form-inline">
        <el-form-item label="任务名称">
          <el-select v-model="data.task_id" placeholder="请选择">
            <el-option v-for="(it, index) in data.taskList" :key="index" :label="it.name"
              :value="it.basetask_id"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="文件名称">
          <el-input v-model="data.title" placeholder="请输入"></el-input>
        </el-form-item>
        <div class="d_bts">
          <div class="l-button" @click="search">搜索</div>
          <div class="l-button" @click="reset">重置</div>
        </div>
      </el-form>
      <el-table :data="data.tablelist" stripe style="width: 100%" border max-height="600">
        <el-table-column prop="task_name" label="任务名称"> </el-table-column>
        <el-table-column prop="title" label="文件名称"> </el-table-column>
        <el-table-column label="操作" width="100" align="center">
          <template #default="scope">
            <div type="text" size="small" @click="downloadFile(scope.row, scope.$index)"
              style="cursor: pointer;color:#409EFF" v-if="scope.row.url_type == 'file'">下载</div>
            <div type="text" size="small" @click="copyline(scope.row)" style="cursor: pointer;color:#409EFF"
              v-if="scope.row.url_type == 'link'">复制</div>
          </template> </el-table-column>
      </el-table>
    </el-dialog>
  </div>
</template>
<script setup name= "LDialog">
import { defineEmits, reactive, defineProps, inject } from "vue";
import { getProjectfile, getTaskdata, copystr, downloadzl } from "../../utils/lc";
import { ElMessage } from 'element-plus'

/* 数据层 */
const data = reactive({
  tablelist: [],
  taskList: [],// 任务列表
  title: '',// 项目名称
  task_id: '',// 任务名称id
  projectId: '',
  downloadclick: []
})
data.projectId = JSON.parse(JSON.stringify(inject('project_id')))
defineProps(['dialogVisible'])
const emits = defineEmits(['update:dialogVisible'])
/* 初始化 */
//获取任务下拉数据
getTaskdata().then(res => {
  data.taskList = []
  data.taskList = res
})
//获取项目资料列表
getInfo()
/* 方法层 */
//复制
function copyline (it) {
  copystr(it.title)
}
// 下载
function downloadFile (item, index) {
  if (data.downloadclick[index]) {
    data.downloadclick[index] = false;
    if (item.url) {
      // download(item.url, item.title) // 这里改了downloadjs原生方法，本来是三个参数的，第一个参数不接受url所以改动了
      downloadzl(item.url, item.title)
    } else {
      ElMessage.error('没有要下载的内容')
      data.downloadclick[index] = true
    }
    setTimeout(function () {
      data.downloadclick[index] = true
    }, 30000)    //秒内不能再次点击
  } else {
    ElMessage.error('重复点击，请稍后再试')
  }
}

// 获取资料下载表格信息
function getInfo () {
  getProjectfile({ project_id: data.projectId, title: data.title, task_id: data.task_id }).then(res => {
    data.tablelist = []
    data.tablelist = res
    data.downloadclick = []
    data.tablelist.forEach(it => {
      data.downloadclick.push(true)
    })
  })
}
// 搜索
function search () {
  getInfo()
}
// 重置
function reset () {
  data.task_id = ''
  data.title = ''
  getInfo()
}
//关闭的点击事件
function handleClose () {
  emits('update:dialogVisible', false)
}
</script>
<style  scoped lang="scss">
@import '@/assets/style/lc.scss';

.lcxmzl {
  .el-table th.el-table__cell {
    background: #e8eaec;
  }

}

.demo-form-inline {
  ::v-deep(.el-input__icon) {
    line-height: 28px;
    height: 28px;
  }
}
</style>

