feat: 2851bug修复

pull/27/head
刘释隆 1 year ago
parent 94b98b31da
commit 7f377fd9df

@ -1,8 +1,8 @@
<script lang="ts" setup>
import { defineEmits, defineProps, onMounted, ref } from 'vue'
import { getAllfieldList, getfieldList, savefield } from '@/api/home/filter'
import { ReportInfoConfig } from '@/config/workorder'
import { useUser } from '@/store/modules/user'
import { computed, defineEmits, defineProps, onMounted, ref } from "vue";
import { getAllfieldList, getfieldList, savefield } from "@/api/home/filter";
import { ReportInfoConfig } from "@/config/workorder";
import { useUser } from "@/store/modules/user";
const props = defineProps({
reviewType: {
@ -10,140 +10,143 @@ const props = defineProps({
default: () => 3,
require: true,
},
})
const emit = defineEmits(['onOk'])
});
const emit = defineEmits(["onOk"]);
onMounted(async () => {
const userStore = useUser()
const userInfo = userStore.getUserInfo
let res
res = await getAllfieldList(props.reviewType) //
const allList = res.data
res = await getfieldList(props.reviewType, userInfo.id) //
const useList = res.data
const userStore = useUser();
const userInfo = userStore.getUserInfo;
let res;
res = await getAllfieldList(props.reviewType); //
const allList = res.data;
res = await getfieldList(props.reviewType, userInfo.id); //
const useList = res.data;
/**
* name 标题
* id 键值
* fix 是否默认
* checked 是否选中
*/
const userFieldFixed = useList.userFieldFixed?.split(',')
const userFieldUnFixed = useList.userFieldUnFixed?.split(',')
const userFieldFixed = useList.userFieldFixed?.split(",");
const userFieldUnFixed = useList.userFieldUnFixed?.split(",");
allList.map((v) => {
const item = {
name: v.fieldDesc,
id: v.name,
fix: v.isrequired == 2,
checked:
v.isrequired == 2
|| Boolean(userFieldFixed?.find(v2 => v2 == v.name))
|| Boolean(userFieldUnFixed?.find(v2 => v2 == v.name)),
}
offList.value.push(item)
})
})
const offList = ref<any[]>([])
v.isrequired == 2 ||
Boolean(userFieldFixed?.find((v2) => v2 == v.name)) ||
Boolean(userFieldUnFixed?.find((v2) => v2 == v.name)),
};
offList.value.push(item);
});
});
const offList = ref<any[]>([]);
function generatList() {
const keys = Object.keys(ReportInfoConfig)
const hideList: object[] = []
const keys = Object.keys(ReportInfoConfig);
const hideList: object[] = [];
for (const key of keys) {
const name = ReportInfoConfig[key]?.label
const isDefault = ReportInfoConfig[key]?.isDefault
const name = ReportInfoConfig[key]?.label;
const isDefault = ReportInfoConfig[key]?.isDefault;
// Y
if (!isDefault) {
hideList.push({
id: key,
name: name || '未配置',
name: name || "未配置",
fix: isDefault,
checked: ReportInfoConfig[key].isDefault,
})
});
}
}
const fixedList = generateDefaultList()
const fixedList = generateDefaultList();
hideList.unshift(...fixedList)
hideList.unshift(...fixedList);
offList.value = hideList
return { hideList }
offList.value = hideList;
return { hideList };
}
function generateDefaultList() {
return Object.keys(ReportInfoConfig).reduce((acc, key) => {
const { label, isDefault } = ReportInfoConfig[key]
const { label, isDefault } = ReportInfoConfig[key];
if (isDefault) {
const config = {
id: key,
name: label || '未配置',
name: label || "未配置",
fix: true,
checked: true,
}
return [...acc, config]
}
else {
return acc
};
return [...acc, config];
} else {
return acc;
}
}, [])
}, []);
}
const show = ref(false)
const checkAll = ref(false)
const show = ref(false);
const checkAll = computed(() => {
return offList.value.length == selectIds.value.length;
});
function showModal() {
show.value = true
show.value = true;
}
function closeModal() {
show.value = false
show.value = false;
}
async function handleSumbit(e: MouseEvent) {
const userStore = useUser()
const userInfo = userStore.getUserInfo
let userField = ''
const userStore = useUser();
const userInfo = userStore.getUserInfo;
let userField = "";
offList.value.map((v) => {
if (v.checked)
userField += `${v.id},`
})
userField = userField.slice(0, userField.length - 1)
savefield(props.reviewType, userInfo.id, userField)
e.preventDefault()
closeModal()
emit('onOk')
if (v.checked) userField += `${v.id},`;
});
userField = userField.slice(0, userField.length - 1);
savefield(props.reviewType, userInfo.id, userField);
e.preventDefault();
closeModal();
emit("onOk");
}
defineExpose({
showModal,
})
});
// generatList();
const selectIds = ref<string[]>([])
const selectIds = ref<string[]>([]);
function onCheckAllChange(value) {
const ids: string[] = []
const ids: string[] = [];
for (const item of offList.value) {
if (!item.fix) {
item.checked = value
ids.push(item.id)
item.checked = value;
ids.push(item.id);
}
}
selectIds.value = value ? ids : []
selectIds.value = value ? ids : [];
}
function onCheckChange(checked: any, item: any) {
const index = selectIds.value.indexOf(item.id)
const index = selectIds.value.indexOf(item.id);
item.checked = checked
item.checked = checked;
if (index === -1 && checked)
selectIds.value.push(item.id)
else selectIds.value.splice(index, 1)
if (index === -1 && checked) selectIds.value.push(item.id);
else selectIds.value.splice(index, 1);
}
const indeterminate = computed(() => {
return offList.value.length > 0 && offList.value.length > selectIds.value.length;
});
</script>
<template>
@ -171,8 +174,10 @@ function onCheckChange(checked: any, item: any) {
<div class="draggable-li" style="background: #f8f8f8">
<n-checkbox
v-model:checked="checkAll"
label="全"
label="全"
@update:checked="onCheckAllChange"
:class="{ checkAll: indeterminate }"
:indeterminate="indeterminate"
/>
</div>
<div class="content">
@ -199,9 +204,7 @@ function onCheckChange(checked: any, item: any) {
</div>
<template #footer>
<div class="wrapper-footer">
<n-button type="info" @click="handleSumbit">
确认
</n-button>
<n-button type="info" @click="handleSumbit"> </n-button>
<n-button secondary style="margin-left: 15px" @click="closeModal">
取消
</n-button>
@ -288,7 +291,7 @@ function onCheckChange(checked: any, item: any) {
color: #333;
display: flex;
align-items: center;
border-bottom: 1px solid #E8E8E8;
border-bottom: 1px solid #e8e8e8;
}
.disable-check {
@ -296,9 +299,7 @@ function onCheckChange(checked: any, item: any) {
}
}
::v-deep(
.n-card.n-card--content-segmented > .n-card__content:not(:first-child)
) {
::v-deep(.n-card.n-card--content-segmented > .n-card__content:not(:first-child)) {
border: 0px;
}
@ -306,5 +307,4 @@ function onCheckChange(checked: any, item: any) {
--n-padding-top: 0px;
--n-padding-bottom: 12px;
}
</style>

Loading…
Cancel
Save