112 lines
3.6 KiB
Vue
112 lines
3.6 KiB
Vue
<template>
|
|
<span v-if="actionShow"><el-button
|
|
v-for="item in transitions"
|
|
:key="item.id"
|
|
:type="item.attribute_type === 2 ? 'danger' : 'primary'"
|
|
:loading="isSaveing"
|
|
:disabled="isSaveing"
|
|
@click="submit(item.id)"
|
|
style="margin-right: 2px"
|
|
>{{ item.name }}</el-button></span>
|
|
</template>
|
|
<script setup>
|
|
import { ref, reactive, onMounted, defineEmits } from 'vue'
|
|
import { ElMessage } from 'element-plus'
|
|
import API from '@/api';
|
|
import TOOL from "@/utils/tool.js";
|
|
|
|
|
|
const props = defineProps({
|
|
workflow_key: {type: String, default: null, required: false},
|
|
ticket_: {type: Object, default: null, required: false},
|
|
t_id: {type: String, default: null, required: true},
|
|
title: {type: String, default: null, required: false},
|
|
submit_b_func: {type: Function, default: null, required: false},
|
|
ticket_data: {type: Object, default: null, required: false},
|
|
})
|
|
|
|
const workflow = ref(null);
|
|
const transitions = ref([]);
|
|
onMounted(async () => {
|
|
init()
|
|
})
|
|
const ticketId = ref(null);
|
|
const actionShow = ref(false);
|
|
const init = async () => {
|
|
if (props.ticket_ != null && props.ticket_ != undefined) {
|
|
const isParticipant =
|
|
(props.ticket_.participant_type === 1 && props.ticket_.participant === currentUser.value) ||
|
|
(props.ticket_.participant_type === 2 && props.ticket_.participant.includes(currentUser.value))
|
|
if (isParticipant) {
|
|
actionShow.value = true;
|
|
}
|
|
ticketId.value = props.ticket_.id;
|
|
transitions.value = await API.wf.ticket.ticketTransitions.req(ticketId.value);
|
|
}else if (props.workflow_key !=null && props.workflow_key != undefined) {
|
|
let res = await API.wf.workflow.initkey.req(props.workflow_key);
|
|
actionShow.value = true
|
|
transitions.value = res.transitions;
|
|
workflow.value = res.workflow
|
|
}else{
|
|
ElMessage.error("缺少workflow_key或ticketId");
|
|
}
|
|
}
|
|
const currentUser = ref(TOOL.data.get("USER_INFO").id)
|
|
|
|
const isSaveing = ref(false);
|
|
|
|
const emit = defineEmits(["success"]);
|
|
const submit = async (transition_id) => {
|
|
isSaveing.value = true;
|
|
if (props.submit_b_func) {
|
|
try{
|
|
await props.submit_b_func();
|
|
}catch (e) {
|
|
isSaveing.value = false;
|
|
return;
|
|
}
|
|
}
|
|
if (ticketId.value) {
|
|
let params = new Object();
|
|
params.transition = transition_id;
|
|
if (props.ticket_data) {
|
|
params.ticket_data = props.ticket_data;
|
|
}else{
|
|
params.ticket_data = {};
|
|
}
|
|
try{
|
|
let res = await API.wf.ticket.ticketHandle.req(ticketId.value, params);
|
|
isSaveing.value = false;
|
|
ElMessage.success("提交成功");
|
|
emit("success", ticketId.value)
|
|
} catch (e) {
|
|
isSaveing.value = false;
|
|
return;
|
|
}
|
|
} else {
|
|
let ticket = {};
|
|
ticket.title = props.title;
|
|
ticket.workflow = workflow.value;
|
|
if (props.t_id != null && props.t_id != undefined) {
|
|
ticket.ticket_data = {
|
|
t_id: props.t_id,
|
|
};
|
|
} else {
|
|
ElMessage.error("缺少t_id");
|
|
isSaveing.value = false;
|
|
return;
|
|
}
|
|
|
|
ticket.transition = transition_id;
|
|
try {
|
|
let res = await API.wf.ticket.create.req(ticket);
|
|
isSaveing.value = false;
|
|
ElMessage.success("提交成功");
|
|
emit("success", res.id)
|
|
} catch (e) {
|
|
isSaveing.value = false;
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
</script> |