祖安之光
2025-11-18 00bae2110315cf9c9a533afea2c617d950f6768e
src/views/work/sealManagement/proces/index.vue
@@ -1,11 +1,280 @@
<script setup>
</script>
<template>
流程
  <div class="app-container">
    <div style="margin-bottom: 10px">
      <el-form style="display: flex;flex-wrap: wrap;">
        <el-form-item>
          <el-button
              type="primary"
              plain
              icon="Plus"
              @click="addFlow()"
              v-hasPermi="['sealFlow:list:add']"
          >新增</el-button>
        </el-form-item>
        <el-form-item label="单位名称:" v-if="data.isAdmin" style="margin-left: 20px">
          <el-select v-model="data.queryParams.companyId" placeholder="请选择" filterable clearable>
            <el-option
                v-for="item in data.companyList"
                :key="item.id"
                :label="item.name"
                :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item v-if="data.isAdmin">
          <el-button type="primary" style="margin-left: 30px" @click="searchClick">查询</el-button>
          <el-button plain @click="reset">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div style="display: flex;width:100%;flex-wrap: wrap; ">
      <div v-for="(item,index) in dataList" :key="item.id">
        <el-card style="width: 400px;margin-right: 50px;margin-bottom: 30px">
          <span style="font-size: 18px;font-weight: 700">{{index+1}}</span>
          <el-form :model="dataList[index]" size="default" ref="busRef" :rules="data.rules" label-width="100" >
            <div style="display: flex">
              <el-form-item label="流程名称:" prop="flowName" style="flex: 1">
                <el-input  v-model="dataList[index].flowName" placeholder="流程名称" style="width: 100%"></el-input>
              </el-form-item>
              <el-button type="danger" plain style="margin-left: 10px;" @click="delFlow(item,index)">删除</el-button>
            </div>
            <div style="display: flex">
              <el-form-item label="审批人员:" prop="approveUserId" style="flex: 1">
                <el-select clearable v-model="dataList[index].approveUserId"  filterable  style="width: 100%">
                  <el-option
                      v-for="item in data.peopleList"
                      :key="item.id"
                      :label="item.name"
                      :value="item.id"
                  />
                </el-select>
              </el-form-item>
              <el-button type="primary"  style="margin-left: 10px;" @click="saveFlow(item,index)">保存</el-button>
            </div>
          </el-form>
        </el-card>
      </div>
    </div>
  </div>
</template>
<style scoped lang="scss">
<script setup>
import {getCurrentInstance, onMounted, reactive, ref, toRefs} from "vue";
import {ElMessage, ElMessageBox} from "element-plus";
import {getCompany} from "@/api/onlineEducation/company";
import Cookies from "js-cookie";
import {addSealApply, delSealApply, getSealApply, reviewApply} from "@/api/sealManage/apply";
import {addSealFlow, delSealFlow, editSealFlow, getSealFlow} from "@/api/sealManage/process";
import {getUser} from "@/api/onlineEducation/user";
import moment from "moment/moment";
const { proxy } = getCurrentInstance();
const loading = ref(false);
const noticeRef = ref();
const loadingCompany = ref(false)
const choosedData = ref([])
const busRef = ref();
const data = reactive({
  queryParams: {
    companyId: null,
  },
  peopleList:[],
  rules:{
    companyId: [{ required: true, message: '请选择企业', trigger: 'blur' }],
    flowName: [{ required: true, message: '请输入流程名称', trigger: 'blur' }],
    approveUserId: [{ required: true, message: '请选择审核人', trigger: 'blur' }],
  },
  companyList: [],
  isAdmin: false,
  userId: null,
});
const dataList = ref([]);
const { queryParams } = toRefs(data);
onMounted(async () => {
  const userInfo = JSON.parse(Cookies.get('userInfo'))
  console.log("userInfo",userInfo)
  data.isAdmin = userInfo.userType === 0;
  if(data.isAdmin){
    data.queryParams.companyId = null
  }else {
    data.queryParams.companyId = userInfo.companyId
  }
  if(data.isAdmin){
   await getCompanyList()
  }
  await getList();
  await getPeopleList()
});
const getList = async () => {
  loading.value = true;
  const res = await getSealFlow(data.queryParams);
  if(res.code === 200){
    dataList.value = res.data
  }else{
    ElMessage.warning(res.message)
  }
  loading.value = false;
}
const searchClick = () => {
  getList();
  getPeopleList()
}
const openDialog = (type, value) => {
  noticeRef.value.openDialog(type, value,data.companyList);
}
const selectValue = (val) => {
  data.companyList.forEach(item => {
    if(item.name === val){
      data.queryParams.companyId = item.id
    }
  })
}
const getCompanyList = async ()=>{
  const queryParams = {
    pageNum: 1,
    pageSize: 999
  }
  const res = await getCompany(queryParams)
  if (res.code == 200) {
    data.companyList = res.data.list?res.data.list:[]
    data.queryParams.companyId = data.companyList[0].id
  } else {
    ElMessage.warning(res.message)
  }
}
/** 重置新增的表单以及其他数据  */
function reset() {
  if(data.isAdmin){
    data.queryParams = {
      companyId: '',
      pageNum: 1,
      pageSize: 10,
      nextCheck:null,
      applyUserId: null
    }
    choosedData.value = []
    data.companyList = [];
    getCompanyList()
  }else {
    data.queryParams = {
      companyId: data.queryParams.companyId,
      pageNum: 1,
      pageSize: 10,
      nextCheck:null,
      applyUserId: null
    }
  }
  getList();
   getPeopleList()
}
const getPeopleList = async ()=> {
  if(data.isAdmin && (data.queryParams.companyId == 0 || data.queryParams.companyId == null)){
    return
  }
  const queryParams = {
    pageNum: 1,
    pageSize: 9999,
    companyId: data.queryParams.companyId
  }
  const res = await getUser(queryParams)
  if(res.code == 200){
    data.peopleList = res.data.list?res.data.list:[]
  }else{
    ElMessage.warning(res.message)
  }
};
const addFlow = () => {
  const obj = {
    companyId: data.queryParams.companyId,
    flowName: "",
    approveUserId: null
  }
  dataList.value.push(obj)
}
const handleSelectionChange = (val) => {
  choosedData.value = val
}
const delFlow = (item,index) => {
  if(item.id){
    ElMessageBox.confirm(
        '确定删除此条数据?',
        '提示',
        {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
        })
        .then( async() => {
          const res = await delSealFlow(item.id);
          if(res.code === 200){
            ElMessage({
              type: 'success',
              message: '删除成功'
            });
            await getList();
          }else{
            ElMessage.warning(res.message)
          }
        })
  }
  else{
    dataList.value =  dataList.value.filter((i,oldIndex)=> index !== oldIndex )
  }
}
const saveFlow = async (item,index) => {
  const valid = await busRef.value[index].validate();
  if(valid){
    if(item.id){
      const { ...data} = JSON.parse(JSON.stringify(dataList.value[index]))
      const res = await editSealFlow(data)
      if(res.code === 200){
        ElMessage({
          type: 'success',
          message: '编辑成功'
        });
        await getList()
      }else{
        ElMessage.warning(res.message)
      }
      busRef.value[index].clearValidate();
    }else{
      const {id, ...data} = JSON.parse(JSON.stringify(dataList.value[index]))
      const res = await addSealFlow(data)
      if(res.code === 200){
        ElMessage({
          type: 'success',
          message: '新增成功'
        });
       await getList()
      }else{
        ElMessage.warning(res.message)
      }
      busRef.value[index].clearValidate();
    }
  }
}
</script>
<style lang="scss">
.pag-container{
  float: right;
  margin-top: 10px;
}
</style>