158 lines
4.7 KiB
Vue
158 lines
4.7 KiB
Vue
<template>
|
|
<span v-if="actionShow">
|
|
<view style="width: 100%; display: flex;">
|
|
<view style="width: 100rpx;">意见</view>
|
|
<view style="flex:1">
|
|
<uni-easyinput v-model="suggestion"></uni-easyinput>
|
|
</view>
|
|
</view>
|
|
<view style="height: 6rpx;margin-top:6rpx;border-top: 1px solid #000;"></view>
|
|
<view style="display:flex">
|
|
<view style="margin:auto">
|
|
<button
|
|
v-for="item in transitions"
|
|
:key="item.id"
|
|
:type="item.attribute_type === 2 ? 'warn' : 'primary'"
|
|
:loading="isSaveing"
|
|
:disabled="isSaveing"
|
|
@click="submit(item.id)"
|
|
style="margin-right: 2px"
|
|
size="mini"
|
|
>{{ item.name }}</button>
|
|
</view>
|
|
<!-- <view style="margin-left:auto">
|
|
<button v-if="props.ticket_?.state_.enable_retreat && isOwn" type="warn" size="mini"
|
|
@click="handleRetreat">撤回</button>
|
|
</view> -->
|
|
</view>
|
|
</span>
|
|
</template>
|
|
<script setup>
|
|
import { ref, reactive, onMounted, defineEmits, watch } from 'vue'
|
|
import API from '@/utils/api';
|
|
|
|
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 () => {
|
|
await getUser()
|
|
await init()
|
|
})
|
|
watch(
|
|
() => props.ticket_,
|
|
async (newVal) => {
|
|
if (newVal && Object.keys(newVal).length > 0) {
|
|
await init()
|
|
}
|
|
},
|
|
{ immediate: false }
|
|
)
|
|
const actionShow = ref(false);
|
|
const suggestion = ref(null)
|
|
const isOwn = ref(false)
|
|
const init = async () => {
|
|
transitions.value = [];
|
|
actionShow.value = false;
|
|
if (props.ticket_ != null && props.ticket_ != undefined) {
|
|
isOwn.value = props.ticket_.create_by === currentUser.value;
|
|
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;
|
|
transitions.value = await API.getTransition(props.ticket_.id);
|
|
}
|
|
}else if (props.workflow_key !=null && props.workflow_key != undefined) {
|
|
let res = await API.workflowInitkey(props.workflow_key);
|
|
actionShow.value = true
|
|
transitions.value = res.transitions;
|
|
workflow.value = res.workflow
|
|
}else{
|
|
uni.showToast({
|
|
icon:"error",
|
|
title:"缺少workflow_key或ticketId"
|
|
})
|
|
}
|
|
}
|
|
const currentUser = ref(null);
|
|
const getUser = async() =>{
|
|
currentUser.value = uni.getStorageSync("userInfo").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 (props.ticket_?.id) {
|
|
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.ticketHandle(props.ticket_.id, params);
|
|
isSaveing.value = false;
|
|
uni.showToast({
|
|
title: '提交成功',
|
|
icon: 'success'
|
|
});
|
|
emit("success", props.ticket_.id)
|
|
} 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 {
|
|
uni.showToast({
|
|
title: '缺少t_id',
|
|
icon: 'error'
|
|
});
|
|
isSaveing.value = false;
|
|
return;
|
|
}
|
|
|
|
ticket.transition = transition_id;
|
|
try {
|
|
let res = await API.ticketCreate(ticket);
|
|
isSaveing.value = false;
|
|
uni.showToast({
|
|
title: '提交成功',
|
|
icon: 'success'
|
|
});
|
|
emit("success", res.id)
|
|
} catch (e) {
|
|
isSaveing.value = false;
|
|
return;
|
|
}
|
|
}
|
|
};
|
|
const handleRetreat = async () =>{
|
|
await API.ticketRetreat(props.ticket_.id, {"suggestion": suggestion.value});
|
|
}
|
|
</script> |