<template>
    <!-- 新建 -->
    <div class="demo-collapse">
    <el-collapse  class="custom-collapse" v-model="activeNames" @change="handleChange">
      <el-collapse-item title="新建工程" name="1">
        <div class="collapse-list" >
            <div class="list" @click="newclick()">
                <el-image :src="s0" fit="contain" ></el-image>
            </div>
        </div>
    
      </el-collapse-item>
      <el-collapse-item title="工程模板" name="2">
        <div class="collapse-list">
         
            <div class="list"  v-for="(item, index) in collapselist" :key="index"  @click="clickimg(item,'2',index)" >
              <!-- <router-link :to="{ path: '/home', query: { id: index } }"> -->
                <el-image :src="item.image" fit="contain"  ></el-image>  
                   <!-- </router-link> -->
            </div>
   
        </div>
      </el-collapse-item>
    </el-collapse>
  </div>
  <el-dialog v-model="eldialog"  align-center    :append-to-body="true" width="400" class="dialog_class">

 <template #header="{ titleId, titleClass }">
    <div class="my-header ">
        <!-- <el-image :src="icon" fit="contain"></el-image> -->
        <h4 :id="titleId" :class="titleClass">新建</h4>

    </div>
</template>
<div>
  <el-form-item label="名称：" >
        <el-input v-model="newfile.name" class="w-50 m-2" placeholder="请输入" />
    </el-form-item>
    <el-form-item label="描述：">
        <el-input v-model="newfile.remark" class="w-50 m-2" placeholder="请输入" />
    </el-form-item>
</div>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="eldialog = false">取消</el-button>
        <el-button type="primary" @click="saveclick();"
          >确认</el-button
        >
      </span>
    </template>

</el-dialog>
</template>
<script setup>
import { ref, onMounted, reactive, } from "vue";
import {CaretRight } from "@element-plus/icons-vue";
import { RouterView, RouterLink,useRouter } from "vue-router"
import { request, uploadFile } from "@/utils/request";
import { ElMessage, ElButton, ElDialog, ElSelect } from 'element-plus'
import s0 from "@/assets/img/s0.png";
import open2 from "@/assets/img/open2.png";
import open3 from "@/assets/img/open3.png";
let router = useRouter();
let eldialog=ref(false);
const activeNames = ref(['1','2']);
let mid=ref('');
let modelflow=ref();
let gcid=ref('');//工程模版
let mob=ref('');
let pid=ref('');
let newfile=ref({
  name:'',
  remark:'',
});

onMounted(() => {
  modelget();
});
const handleChange = (val) => {
  console.log(val)

}
const newclick = () => {
     sessionStorage.clear();
  eldialog.value=true;


}

let collapselist = ref([
  {img:open2},{img:open3},
 
])
const openclick=()=>{
   // router.replace({ path: key })
}
const saveclick=()=>{
  if(newfile.value.name==''||newfile.value.name==null||newfile.value.name==undefined){
    ElMessage.error('名称不能为空')
  }else if(newfile.value.remark==''||newfile.value.remark==null||newfile.value.remark==undefined){
    ElMessage.error('描述不能为空')
  }
  else{
   
  if(gcid.value=='2'){
    
    modeladd();
  }else{
    newbaocun();
  }
  }

}
//新建的保存
const newbaocun=()=>{
  const params = {
        transCode: 'MDO0002',
        pid: pid.value,
        name: newfile.value.name,
        remark:newfile.value.remark,
        image:'',
        isshare:'1',
        flow:'' 
    }
    request(params)
        .then((res) => {
            console.log(res);
            pid.value=res.pid;
            newfile.value.pid =res.pid;
            newfile.value.flow ="";
            ElMessage({
                  message: res.returnMsg,
                  type: 'success',
              })
              eldialog.value = false;
           router.push({ path: "/home" ,query:{pid: pid.value}});
           sessionStorage.setItem("objlist",JSON.stringify(newfile.value));
        })
        .catch((err) => {
            ElMessage.error(err.returnMsg)
        })
}
//模版添加

// 模版查询
const modelget=()=>{
  const params = {
        transCode: 'MDO0005',
        count:5,
        page:1,
        searchtag:''
    }
    request(params)
        .then((res) => {
            collapselist.value=res.rows;
        })
        .catch((err) => {
            ElMessage.error(err.returnMsg)
        })
}
const modeladd=()=>{
  const params = {
        transCode: 'MDO0004',
        mid:mid.value,
        name:newfile.value.name,
        remark:newfile.value.description
    }
    request(params)
        .then((res) => {
          ElMessage({
                  message: res.returnMsg,
                  type: 'success',
              })
              modelflow.value=res;
              console.log(modelflow.value);
              router.push({ path: "/home",query:{id:'2',pid:res.pid}});
              sessionStorage.setItem("objlist",JSON.stringify(modelflow.value));
        })
        .catch((err) => {
            ElMessage.error(err.returnMsg)
        })
}
const clickimg=(data,index,id)=>{
   mid.value=data.mid;
   mob.value=id;//判断当前点击第几的模版
   gcid.value=index;
eldialog.value=true;

}

</script>
<style lang="scss" scoped>
.collapse-list{
    display: flex;
    .list{
        width: 240px;
        height: 240px;
        border: 2px solid #71AAFF;
        display: flex;
        justify-content: center;
        align-items: center;
        text-align: center;
        margin: 0 10px;
    }
}
</style>
<style>
.custom-collapse .el-collapse-item__header {
    font-family: Inter, Inter;
font-weight: 500;
font-size: 16px;
color: #383838;
line-height: 24px;
text-align: left;
font-style: normal;
text-transform: none;
}
.custom-collapse .el-collapse-item__header {
  align-items: center;
  border: none;
}
 
.custom-collapse .el-collapse-item__arrow {
  order: -1; /* 将箭头元素的顺序设置为最前 */
  margin-right: 10px;
  margin-left: 10px; /* 根据需要调整箭头与标题的间距 */
}
 .custom-collapse .el-collapse-item__wrap,.custom-collapse{
    border: none;
}

</style>

