zhengyiming
2025-02-10 958b79ed89b9e742540f714a80261d222c0fc09b
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<template>
  <div>
    <label v-for="item in modelValue" :key="item" class="el-checkbox selected-workoftype-label">{{
      getWorkOfTypeNameById(item)
    }}</label>
    <el-button v-if="!disabled" type="primary" link class="workoftype-btn" @click="visible = true"
      >选择工种</el-button
    >
    <ProDialog v-model="visible" destroy-on-close class="workoftype-dialog" @open="handleShow">
      <el-table
        class="workoftype-table"
        :max-height="500"
        :data="workOfTypeList"
        border
        header-cell-class-name="header-cell"
      >
        <el-table-column width="150" property="label" label="已选工种" class-name="label-cell">
          <template #default="{ row }">
            {{ row.name }}
          </template>
        </el-table-column>
        <el-table-column property="selectIds">
          <template #default="{ row }">
            <FieldCheckBox
              v-if="row.children?.length > 0"
              :value-enum="row.children"
              v-model="temporarySelectedWorkOfTypeList"
              enum-label-key="name"
              enum-value-key="id"
              :max="MaxSelectWorkOfTypeLimit"
            ></FieldCheckBox>
          </template>
 
          <template #header>
            <div class="el-checkbox-group">
              <label
                v-for="item in temporarySelectedWorkOfTypeList"
                :key="item"
                class="el-checkbox"
                >{{ getWorkOfTypeNameById(item) }}</label
              >
            </div>
          </template>
        </el-table-column>
      </el-table>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="handleClose">取 消</el-button>
          <el-button type="primary" @click="handleConfirm">确 定</el-button>
        </span>
      </template>
    </ProDialog>
  </div>
</template>
 
<script setup lang="ts">
import { FieldCheckBox, ProDialog } from '@bole-core/components';
import { useWorkOfType } from '@/hooks';
 
defineOptions({
  name: 'WorkOfTypePopover',
});
 
type Props = {
  modelValue: string[];
  disabled?: boolean;
};
 
const props = withDefaults(defineProps<Props>(), {});
 
const emit = defineEmits<{
  (e: 'update:modelValue', value: string[]): void;
}>();
 
const visible = ref(false);
 
const { workOfTypeList, getWorkOfTypeNameById, MaxSelectWorkOfTypeLimit } = useWorkOfType();
 
const temporarySelectedWorkOfTypeList = ref<string[]>([]);
 
function handleShow() {
  temporarySelectedWorkOfTypeList.value = [...props.modelValue];
}
 
function handleConfirm() {
  emit('update:modelValue', temporarySelectedWorkOfTypeList.value);
  handleClose();
}
 
function handleClose() {
  visible.value = false;
}
</script>
 
<style lang="scss" scoped>
@use '@/style/common.scss' as *;
 
.btn-wrapper {
  display: flex;
  justify-content: flex-end;
  padding: 10px;
  border: 1px solid getCssVar('border-color', 'lighter');
  border-top: none;
 
  .el-button {
    padding: 9px 28px;
    font-size: 14px;
    border-radius: 6px;
  }
}
 
.workoftype-table {
  :deep() {
    .header-cell {
      font-weight: 500;
      color: getCssVar('text-color', 'regular');
 
      .cell {
        line-height: 32px;
      }
    }
 
    .label-cell {
      color: getCssVar('text-color', 'primary');
    }
  }
}
 
.selected-workoftype-label {
  vertical-align: middle;
 
  &:last-of-type {
    margin-right: 30px;
  }
}
</style>
<style lang="scss">
.workoftype-dialog {
  .el-dialog__header {
    display: none;
  }
  /* --bole-pro-dialog-padding-vertical: 20px;
  --bole-pro-dialog-padding-horizontal: 20px; */
}
</style>