广丰卷烟厂数采质量分析系统
zhuguifei
2026-03-02 80ff784bf60637cd348ae665fc907f7b1e527dd8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<script setup lang="ts">
import { ref, useAttrs, watch } from 'vue';
import type { SelectProps } from 'naive-ui';
import { useLoading } from '@sa/hooks';
import { fetchGetPostSelect } from '@/service/api/system';
 
defineOptions({
  name: 'PostSelect'
});
 
interface Props {
  deptId?: CommonType.IdType | null;
  [key: string]: any;
}
 
const props = defineProps<Props>();
 
const value = defineModel<CommonType.IdType[] | null>('value', { required: false });
 
const attrs: SelectProps = useAttrs();
 
const { loading: postLoading, startLoading: startPostLoading, endLoading: endPostLoading } = useLoading();
 
/** the enabled post options */
const postOptions = ref<CommonType.Option<CommonType.IdType>[]>([]);
 
watch(
  () => props.deptId,
  () => {
    if (!props.deptId) {
      postOptions.value = [];
      return;
    }
    getPostOptions();
  },
  { immediate: true }
);
 
async function getPostOptions() {
  startPostLoading();
  const { error, data } = await fetchGetPostSelect(props.deptId!);
 
  if (!error) {
    postOptions.value = data.map(item => ({
      label: item.postName,
      value: item.postId
    }));
  }
  endPostLoading();
}
</script>
 
<template>
  <NSelect
    v-model:value="value"
    :loading="postLoading"
    :options="postOptions"
    v-bind="attrs"
    placeholder="请选择岗位"
  />
</template>
 
<style scoped></style>