<!--
 * @Description : 输出文件
 * @Author      : jinxin
 * @Date        : 2023-02-17 17:03:54
-->
<template>
    <el-dialog :model-value="isShowDialog" :close-on-click-modal="false" :close-on-press-escape="false" :show-close="true" :title="title" width="630px" center>
        <div class="btn_group">
            <el-form :model="data.form">
                <el-form-item label="任务名称">
                    <el-select placeholder="请选择" v-model="data.form.taskName" filterable style="width: 100%;">
                        <el-option v-for="(item,index) in list" :key="index" :label="item.name" :value="item.basetask_id" />
                    </el-select>
                </el-form-item>
                <el-form-item label="文件名称">
                    <el-input v-model="data.form.fileName" @keydown.enter.prevent="searchCom()"/>
                </el-form-item>
                <el-form-item>
                    <div class="btns">
                        <el-button @click="searchCom">搜索</el-button>
                        <el-button @click="resetCom">重置</el-button>
                    </div>
                </el-form-item>
            </el-form>
        </div>
        <div class="dialogTable">
            <JxOricoTable
                v-model:loading="data.loading"
                v-model:tableHeigth="data.tableHeigth"
                v-model:listHeader="data.listHeader"
                v-model:defaultRow="data.defaultRow"  
                v-model:tableHeader="data.tableHeader"
                v-model:notShowCol="data.notShowCol"
                v-model:staticList="data.staticList"
                v-model:beforeStrList="data.beforeStrList"
                @getClickBtnType="getClickBtnType" 
            />
        </div>
    </el-dialog>
</template>

<script>
import { defineComponent,getCurrentInstance,onMounted,reactive } from 'vue'
export default defineComponent({
    props:{
        isShowDialog:Boolean,
        title:String,
        list:Array,
        projectList:Array,
        project_id:Number
    },
    setup(props,context){
        let { proxy } = getCurrentInstance()
        onMounted(()=>{
            data.defaultRow = addUrlType(props.projectList)
            data.project_id = props.project_id
        })
        let data = reactive({
            // 顶部
            form:{
                taskName:null,
                fileName:''
            },
            // 表格
            table_title:'输出文件',
            listHeader:[
                { type: 'text', field: 'task_name', title: '任务名称', width: '155', align: 'center' },
                { type: 'text', field: 'title', title: '文件名称', width: '155', align: 'center' },
                { type: 'text', field: 'remark', title: '备注', width: '155', align: 'center' },
                { type: 'downLoadUrl',field:'downLoadUrl',title:'操作',width:'120',align: 'center' },
            ],
            defaultRow:[],
            tableHeader:[],
            notShowCol:[],
            staticList:[],
            beforeStrList:[],
            tableHeigth:400,
            loading:false
        })
        const addUrlType = (list) => {
            if(list && list.length > 0){
                let arr = list
                arr.forEach(el => {
                    el.downLoadUrl = el.url
                    if(el.url_type == 'link'){
                        el.isShowCopy = true
                    }else{
                        el.isShowCopy = false
                    }
                });
                return arr
            }else{
                return []
            }
        }
        const resetCom = () => {
            data.form.taskName = null
            data.form.fileName = ''
            requestCom()
        }
        const searchCom = () => {
            requestCom()
        }
        const requestCom = () => {
            data.loading = true
            proxy.$http.showLoading(false).get('project/project/file',{project_id:data.project_id,title:data.form.fileName,task_id:data.form.taskName}).then(r => {
                if(r.errno == 200){
                    data.loading = false
                    data.defaultRow = r.data
                }else{
                    proxy.$message.error(r.errmsg)
                }
            })
        }
        const getClickBtnType = (type,selRow) => {}
        return{
            data,
            props,
            getClickBtnType,
            addUrlType,
            searchCom,
            resetCom,
            requestCom
        }
    }
})
</script>

<style scoped>
::v-deep(.el-form){
    display:flex;
}

::v-deep(.el-form .el-form-item){
    margin-right: 10px;
}
::v-deep(.el-form .el-form-item:last-child){
    margin-right: 0px!important;
    flex: 1;
    margin-left: 16px!important;
}
::v-deep(.el-dialog__body){
    text-align: center;
}
.btns{
    display: flex;
}
</style>
