228 lines
5.1 KiB
Vue
Raw Normal View History

<template>
2025-07-26 21:29:04 +08:00
<BasicLayout>
2025-08-29 01:27:54 +08:00
<view class="qj-detail">
<!-- 使用公共组件展示请假详情 -->
<JsQjDetail
:qjId="qjId"
:dbFlag="dbFlag"
@loadQjData="handleQjDataLoaded"
@loadDkList="handleDkListLoaded"
/>
</view>
2025-07-26 21:29:04 +08:00
<template #bottom>
<view class="white-bg-color py-5">
<view class="px-15">
<BasicForm @register="register" />
</view>
2025-07-26 21:29:04 +08:00
<view class="flex-row items-center pb-10 pt-5">
<u-button
2025-08-29 01:27:54 +08:00
text="取消"
2025-07-26 21:29:04 +08:00
class="ml-15 mr-7"
:plain="true"
2025-08-29 01:27:54 +08:00
@click="navigateBack"
2025-07-26 21:29:04 +08:00
/>
<u-button
2025-08-29 01:27:54 +08:00
text="提交"
2025-07-26 21:29:04 +08:00
class="mr-15 mr-7"
type="primary"
@click="submit"
/>
</view>
</view>
</template>
</BasicLayout>
</template>
<script setup lang="ts">
2025-08-29 01:27:54 +08:00
import { onLoad } from "@dcloudio/uni-app";
import { useForm } from "@/components/BasicForm/hooks/useForm";
import { navigateBack } from "@/utils/uniapp";
2025-07-27 23:37:02 +08:00
import { jsQjSpApi } from "@/api/base/jsQjApi";
import { useUserStore } from "@/store/modules/user";
2025-08-29 01:27:54 +08:00
import { useDataStore } from "@/store/modules/data";
import { ref, computed } from "vue";
import { xxtsFindByIdApi } from "@/api/base/server";
2025-07-27 23:37:02 +08:00
import JsQjDetail from "./components/jsQjDetail.vue";
2025-08-29 01:27:54 +08:00
2025-08-02 14:23:51 +08:00
const { getJs, loginByOpenId } = useUserStore();
2025-08-29 01:27:54 +08:00
const { getData, setXxts, setData, getXxts } = useDataStore();
const dbFlag = ref(false);
2025-08-29 01:27:54 +08:00
const qjId = ref('');
2025-08-29 01:27:54 +08:00
// 请假基础数据
const qjData = computed(() => getData || {});
2025-07-26 21:29:04 +08:00
2025-08-29 01:27:54 +08:00
const [register, { getValue }] = useForm({
schema: [
{
field: "spStatus",
label: "审批意见",
component: "BasicCheckbox",
required: true,
itemProps: {
labelPosition: "top",
},
componentProps: {
data: [
{ value: 'approved', text: "同意" },
{ value: 'rejected', text: "拒绝" },
],
},
},
{
field: "spYj",
label: "审批说明",
component: "BasicInput",
required: true,
itemProps: {
labelPosition: "top",
},
componentProps: {
type: "textarea",
placeholder: "请输入审批说明",
},
},
],
});
2025-07-26 21:29:04 +08:00
2025-07-26 21:29:04 +08:00
2025-08-29 01:27:54 +08:00
const handleQjDataLoaded = (data: any) => {
setData(data);
2025-07-27 23:37:02 +08:00
};
2025-08-29 01:27:54 +08:00
const handleDkListLoaded = (list: any[]) => {
// 代课明细数据已由JsQjDetail组件处理
2025-07-27 23:37:02 +08:00
};
2025-08-29 01:27:54 +08:00
const submit = async () => {
2025-07-27 23:37:02 +08:00
try {
2025-08-29 01:27:54 +08:00
const formData = await getValue();
if (!formData.spStatus || !formData.spYj) {
uni.showToast({
title: '请填写完整的审批信息',
icon: 'none'
});
return;
}
const params = {
qjId: qjId.value,
2025-08-29 01:27:54 +08:00
jsId: getJs.id,
spStatus: formData.spStatus,
spYj: formData.spYj,
};
uni.showLoading({
title: "提交中...",
});
const res = await jsQjSpApi(params);
2025-07-27 23:37:02 +08:00
uni.hideLoading();
2025-08-29 01:27:54 +08:00
uni.showToast({
title: '审批提交成功',
icon: 'success'
});
2025-07-27 23:37:02 +08:00
setTimeout(() => {
navigateBack();
2025-08-29 01:27:54 +08:00
}, 1500);
} catch (error) {
2025-07-27 23:37:02 +08:00
uni.hideLoading();
2025-08-29 01:27:54 +08:00
uni.showToast({
title: '提交失败,请重试',
icon: 'none'
});
console.error('审批提交失败:', error);
2025-07-27 23:37:02 +08:00
}
};
2025-08-29 01:27:54 +08:00
onLoad(async (data?: any) => {
// 从待办过来的,需要从后端获取数据
console.log(data);
if (data && data.from && data.from == "db") {
dbFlag.value = true;
2025-08-01 20:11:36 +08:00
2025-08-02 14:23:51 +08:00
// 检查登录状态
const isLoggedIn = await loginByOpenId(data.openId);
if (!isLoggedIn) {
console.log("用户未登录,跳过处理");
return;
}
2025-08-01 20:11:36 +08:00
try {
// 优先从后端根据url中的id去查询Xxts
const xxtsRes = await xxtsFindByIdApi({ id: data.id });
if (xxtsRes && xxtsRes.result) {
const xxts = xxtsRes.result;
// 检查待办状态
if (xxts.dbZt === "B") {
setData({ id: xxts.xxzbId });
let url = "/pages/view/hr/jsQj/detail";
uni.navigateTo({ url });
return;
}
setXxts(xxts);
qjId.value = xxts.xxzbId;
}
} catch (error) {
console.error("获取待办信息失败", error);
// 如果获取Xxts失败回退到原来的逻辑
2025-08-29 01:27:54 +08:00
const xxtsData = getXxts;
2025-08-01 20:11:36 +08:00
if (xxtsData && xxtsData.dbZt === "B") {
setData({ id: data.id });
let url = "/pages/view/hr/jsQj/detail";
uni.navigateTo({ url });
return;
}
2025-08-29 01:27:54 +08:00
qjId.value = data.id;
2025-07-27 23:37:02 +08:00
}
} else {
dbFlag.value = false;
2025-08-29 01:27:54 +08:00
// 直接加载请假详情
qjId.value = getData.id || '';
}
});
2025-07-26 21:29:04 +08:00
</script>
2025-07-27 23:37:02 +08:00
2025-08-29 01:27:54 +08:00
<style lang="scss" scoped>
.qj-detail {
background-color: #f5f7fa;
2025-07-27 23:37:02 +08:00
}
2025-08-29 01:27:54 +08:00
.info-card {
margin: 15px;
background-color: #fff;
border-radius: 8px;
padding: 15px;
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
.card-header {
font-size: 16px;
font-weight: bold;
color: #333;
margin-bottom: 10px;
.applicant-name {
font-size: 16px;
font-weight: bold;
color: #333;
}
}
.divider {
height: 1px;
background-color: #eee;
margin-bottom: 15px;
}
.card-body {
padding: 15px;
}
2025-07-27 23:37:02 +08:00
}
</style>