|
|
@@ -89,6 +89,23 @@
|
|
|
:disabledDate="disabledDate" placeholder="请选择预计归还时间" style="width: 100%" :disabled="isView"/>
|
|
|
</el-form-item>
|
|
|
</el-col>
|
|
|
+ <el-col :span="24" v-if="!isView">
|
|
|
+ <el-alert
|
|
|
+ v-if="matchedWorkflowName"
|
|
|
+ type="info"
|
|
|
+ :closable="false"
|
|
|
+ show-icon
|
|
|
+ >
|
|
|
+ <template #title>将使用审批流程:{{ matchedWorkflowName }}</template>
|
|
|
+ </el-alert>
|
|
|
+ <el-alert
|
|
|
+ v-else-if="workflowsLoadDone && form.expected_end_time"
|
|
|
+ type="warning"
|
|
|
+ :closable="false"
|
|
|
+ show-icon
|
|
|
+ title="当前条件未匹配到启用中的审批流程,提交后将由后台默认规则处理;请检查流程管理中的天数区间、借用类型(含特殊借用)等配置"
|
|
|
+ />
|
|
|
+ </el-col>
|
|
|
<el-col :span="4">
|
|
|
<el-form-item label="个人/团队" prop="team_type" >
|
|
|
<el-select v-model="form.team_type" placeholder="请选择" :disabled="isView">
|
|
|
@@ -138,7 +155,7 @@
|
|
|
</el-table-column>
|
|
|
<!-- <el-table-column prop="location" label="存放仓库" /> -->
|
|
|
<el-table-column label="操作" width="80">
|
|
|
- <template #default="{ row, $index }">
|
|
|
+ <template #default="{ $index }">
|
|
|
<el-button type="text" style="color: red" @click="removeItem($index)" :disabled="isView">移除</el-button>
|
|
|
</template>
|
|
|
</el-table-column>
|
|
|
@@ -190,12 +207,12 @@
|
|
|
<SelectCatgory
|
|
|
v-model:visible="showSelectDeviceDialog"
|
|
|
@confirm="onDeviceSelected"
|
|
|
- :disabled-ids="form.items.map((item: any) => item.device_category).filter(Boolean)"
|
|
|
+ :disabled-ids="form.items.map((item) => item.device_category).filter(Boolean)"
|
|
|
/>
|
|
|
</template>
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
-import { ref, watch, defineProps, defineEmits, onMounted,computed } from 'vue';
|
|
|
+import { ref, watch, onMounted, computed } from 'vue';
|
|
|
import SelectDeviceDialog from './SelectDeviceDialog/index.vue';
|
|
|
import dayjs from 'dayjs';
|
|
|
import { ElMessage ,UploadProps, UploadUserFile } from 'element-plus';
|
|
|
@@ -205,6 +222,12 @@ import { request } from '/@/utils/service';
|
|
|
import { Plus } from '@element-plus/icons-vue';
|
|
|
import SelectCatgory from '../SelectCatgory/index.vue';
|
|
|
import { getUserInfo } from '../../../login/api';
|
|
|
+import * as workflowApi from '../../workflow/api';
|
|
|
+import {
|
|
|
+ pickWorkflowIdForSpecialBorrow,
|
|
|
+ findWorkflowNameById,
|
|
|
+ type SpecialBorrowMatchInput,
|
|
|
+} from '../../utils/matchBorrowWorkflow';
|
|
|
|
|
|
// 定义用户和管理员接口
|
|
|
interface User {
|
|
|
@@ -540,6 +563,54 @@ const form = ref({
|
|
|
});
|
|
|
const showSelectDeviceDialog = ref(false);
|
|
|
|
|
|
+/** 用于按「流程管理」中的条件自动匹配 workflow id */
|
|
|
+const workflowsForMatch = ref<Record<string, any>[]>([]);
|
|
|
+const workflowsLoadDone = ref(false);
|
|
|
+
|
|
|
+async function loadWorkflowsForMatch() {
|
|
|
+ workflowsLoadDone.value = false;
|
|
|
+ try {
|
|
|
+ const res: any = await workflowApi.GetList({ page: 1, limit: 999 } as any);
|
|
|
+ workflowsForMatch.value = Array.isArray(res?.data) ? res.data : [];
|
|
|
+ } catch {
|
|
|
+ workflowsForMatch.value = [];
|
|
|
+ } finally {
|
|
|
+ workflowsLoadDone.value = true;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+const resolvedAppUserType = computed(() => {
|
|
|
+ if (form.value.borrower_type !== 1 || form.value.app_user_borrower == null) return null;
|
|
|
+ const u = allUserList.value.find((x) => Number(x.id) === Number(form.value.app_user_borrower));
|
|
|
+ return u != null ? (u as any).user_type ?? null : null;
|
|
|
+});
|
|
|
+
|
|
|
+const specialBorrowMatchInput = computed((): SpecialBorrowMatchInput => ({
|
|
|
+ borrow_type: 2,
|
|
|
+ borrower_type: form.value.borrower_type,
|
|
|
+ team_type: form.value.team_type,
|
|
|
+ expected_start_time: form.value.expected_start_time || undefined,
|
|
|
+ expected_end_time: form.value.expected_end_time || undefined,
|
|
|
+ app_user_type: resolvedAppUserType.value,
|
|
|
+}));
|
|
|
+
|
|
|
+const matchedWorkflowId = computed(() => {
|
|
|
+ if (!workflowsForMatch.value.length) return null;
|
|
|
+ return pickWorkflowIdForSpecialBorrow(workflowsForMatch.value, specialBorrowMatchInput.value);
|
|
|
+});
|
|
|
+
|
|
|
+const matchedWorkflowName = computed(() =>
|
|
|
+ findWorkflowNameById(workflowsForMatch.value, matchedWorkflowId.value)
|
|
|
+);
|
|
|
+
|
|
|
+watch(
|
|
|
+ () => props.visible,
|
|
|
+ (v) => {
|
|
|
+ if (v && !isView.value) {
|
|
|
+ void loadWorkflowsForMatch();
|
|
|
+ }
|
|
|
+ }
|
|
|
+);
|
|
|
|
|
|
const rules = {
|
|
|
external_borrower_name: [
|
|
|
@@ -790,30 +861,43 @@ function onCancel() {
|
|
|
emit('update:visible', false);
|
|
|
}
|
|
|
function onSubmit() {
|
|
|
-
|
|
|
- formRef.value.validate((valid: boolean) => {
|
|
|
- if (valid) {
|
|
|
- form.value.items = form.value.items.map((item: any) => ({
|
|
|
- ...item,
|
|
|
- quantity: Number(item.quantity) || 0 ,
|
|
|
- }));
|
|
|
- const firstLocation = form.value.items[0]?.location || '';
|
|
|
- form.value.return_location = firstLocation;
|
|
|
- form.value.expected_start_time = now;
|
|
|
- form.value.expected_end_time = form.value.expected_end_time
|
|
|
- ? dayjs(form.value.expected_end_time).endOf('day').format('YYYY-MM-DD HH:mm:ss')
|
|
|
- : dayjs().endOf('day').format('YYYY-MM-DD HH:mm:ss');
|
|
|
- form.value.team_members_count=Number(form.value.team_members_count)||1;
|
|
|
- form.value.mode = isEdit.value ? 'edit' : 'add';
|
|
|
- // 确保 borrow_type 设置为 2(特殊借用)
|
|
|
- form.value.borrow_type = 2;
|
|
|
- // return
|
|
|
- emit('submit', { ...form.value });
|
|
|
- emit('update:visible', false);
|
|
|
- // ElMessage.success("添加成功!");
|
|
|
+ formRef.value.validate(async (valid: boolean) => {
|
|
|
+ if (!valid) return;
|
|
|
+ if (!workflowsForMatch.value.length) {
|
|
|
+ await loadWorkflowsForMatch();
|
|
|
}
|
|
|
+ form.value.items = form.value.items.map((item: any) => ({
|
|
|
+ ...item,
|
|
|
+ quantity: Number(item.quantity) || 0,
|
|
|
+ }));
|
|
|
+ const firstLocation = form.value.items[0]?.location || '';
|
|
|
+ form.value.return_location = firstLocation;
|
|
|
+ form.value.expected_start_time = now;
|
|
|
+ const endDay = form.value.expected_end_time;
|
|
|
+ form.value.expected_end_time = endDay
|
|
|
+ ? dayjs(endDay).endOf('day').format('YYYY-MM-DD HH:mm:ss')
|
|
|
+ : dayjs().endOf('day').format('YYYY-MM-DD HH:mm:ss');
|
|
|
+ form.value.team_members_count = Number(form.value.team_members_count) || 1;
|
|
|
+ form.value.mode = isEdit.value ? 'edit' : 'add';
|
|
|
+ form.value.borrow_type = 2;
|
|
|
+
|
|
|
+ const matchPayload: SpecialBorrowMatchInput = {
|
|
|
+ borrow_type: 2,
|
|
|
+ borrower_type: form.value.borrower_type,
|
|
|
+ team_type: form.value.team_type,
|
|
|
+ expected_start_time: form.value.expected_start_time,
|
|
|
+ expected_end_time: endDay || undefined,
|
|
|
+ app_user_type: resolvedAppUserType.value,
|
|
|
+ };
|
|
|
+ const workflowId = pickWorkflowIdForSpecialBorrow(workflowsForMatch.value, matchPayload);
|
|
|
+
|
|
|
+ const submitBody: Record<string, any> = { ...form.value };
|
|
|
+ if (workflowId != null) {
|
|
|
+ submitBody.workflow = workflowId;
|
|
|
+ }
|
|
|
+ emit('submit', submitBody);
|
|
|
+ emit('update:visible', false);
|
|
|
});
|
|
|
-
|
|
|
}
|
|
|
|
|
|
</script>
|