choice-user.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <template>
  2. <div class="hc-choice-user">
  3. <!-- 表单回显 -->
  4. <div class="choice-user-box hc-flex w-full cursor-pointer bg-white">
  5. <div class="tag-user-list" @click="showModalClick">
  6. <template v-for="(item, index) in UserDataList" :key="index">
  7. <el-tag>{{ item.name }}</el-tag>
  8. </template>
  9. <div v-if="UserDataList.length <= 0">点击这里选择用户</div>
  10. </div>
  11. </div>
  12. <!-- 选择用户的弹窗 -->
  13. <hc-new-dialog ui="hc-choice-user-dialog" is-table widths="62rem" :show="userModalShow" title="选择用户" @save="userModalSave" @close="userModalClose">
  14. <div class="relative h-full flex">
  15. <div class="relative h-full flex-1 p-2" hc-border-r="1px solid #eee">
  16. <el-scrollbar>
  17. <hc-data-tree :h-props="treeProps" :datas="treeLoadNode" />
  18. </el-scrollbar>
  19. </div>
  20. <div class="relative h-full h-full flex flex-[2] flex-col">
  21. <div class="relative flex flex-1 flex-col">
  22. <div class="hc-flex bg-gray-2 p-2 text-black">可选择的用户</div>
  23. <div class="user-list relative flex-1 p-2">
  24. <el-scrollbar>
  25. <el-checkbox-group v-model="checkboxUserList">
  26. <template v-for="item in signUserList" :key="item.id">
  27. <div class="user-item checkbox-li">
  28. <el-checkbox :label="`${item.name}-${item.id}`">
  29. <div class="item-user-name">{{ item.name }}</div>
  30. </el-checkbox>
  31. </div>
  32. </template>
  33. </el-checkbox-group>
  34. </el-scrollbar>
  35. </div>
  36. </div>
  37. <div class="relative flex flex-col">
  38. <div class="hc-flex bg-gray-2 p-2 text-black">已选择({{ checkboxUserList.length }})</div>
  39. <div class="user-list h-24">
  40. <el-scrollbar>
  41. <template v-for="(item, index) in checkboxUserList" :key="index">
  42. <el-tag closable @close="delCheckboxUser(index)">
  43. {{ item.name }}
  44. </el-tag>
  45. </template>
  46. </el-scrollbar>
  47. </div>
  48. </div>
  49. </div>
  50. </div>
  51. </hc-new-dialog>
  52. </div>
  53. </template>
  54. <script setup>
  55. import { ref } from 'vue'
  56. defineOptions({
  57. name: 'HcChoiceUser',
  58. })
  59. const UserDataList = ref([])
  60. //选择用户
  61. const userModalShow = ref(false)
  62. const showModalClick = () => {
  63. userModalShow.value = true
  64. }
  65. //数据格式
  66. const treeProps = {
  67. label: 'label',
  68. children: 'children',
  69. }
  70. //数据
  71. const treeLoadNode = ref([
  72. {
  73. label: 'Level one 1',
  74. children: [
  75. {
  76. label: 'Level two 1-1',
  77. children: [
  78. { label: 'Level three 1-1-1' },
  79. ],
  80. },
  81. {
  82. label: 'Level two 2-1',
  83. children: [
  84. { label: 'Level three 2-1-1' },
  85. ],
  86. },
  87. {
  88. label: 'Level two 2-2',
  89. children: [
  90. { label: 'Level three 2-2-1' },
  91. ],
  92. },
  93. {
  94. label: 'Level two 3-1',
  95. children: [
  96. { label: 'Level three 3-1-1' },
  97. ],
  98. },
  99. {
  100. label: 'Level two 3-2',
  101. children: [
  102. { label: 'Level three 3-2-1' },
  103. ],
  104. },
  105. ],
  106. },
  107. ])
  108. //选择用户
  109. const checkboxUserList = ref([])
  110. const signUserList = ref([
  111. { id: 1, name: '名称1' },
  112. { id: 2, name: '名称2' },
  113. { id: 3, name: '名称3' },
  114. ])
  115. const delCheckboxUser = (index) => {
  116. }
  117. const userModalSave = () => {
  118. userModalClose()
  119. }
  120. const userModalClose = () => {
  121. userModalShow.value = false
  122. }
  123. </script>
  124. <style scoped lang="scss">
  125. .hc-choice-user {
  126. position: relative;
  127. width: 100%;
  128. --cubic-bezier: cubic-bezier(.645,.045,.355,1);
  129. .choice-user-box {
  130. border-radius: 4px;
  131. color: #606266;
  132. font-size: 14px;
  133. min-height: 40px;
  134. padding: 0 12px;
  135. border: 1px dashed #dddfe6;
  136. transition: border .2s var(--cubic-bezier);
  137. .tag-user-list {
  138. position: relative;
  139. }
  140. }
  141. }
  142. </style>
  143. <style lang="scss">
  144. .el-dialog.hc-choice-user-dialog {
  145. .el-dialog__body {
  146. padding: 0 !important;
  147. }
  148. .el-tree.hc-tree-node-v2 .data-custom-tree-node .label,
  149. .hc-tree-node .data-custom-tree-node .label {
  150. font-size: 15px;
  151. }
  152. .el-tree.hc-tree-node-v2 .data-custom-tree-node .label.level-name,
  153. .hc-tree-node .data-custom-tree-node .label.level-name {
  154. font-size: 15px;
  155. font-weight: initial;
  156. }
  157. .hc-tasks-user .tasks-user-box .tag-user-list {
  158. .el-tag {
  159. --el-icon-size: 14px;
  160. padding: 0 10px;
  161. height: 26px;
  162. margin: 4px 0;
  163. }
  164. }
  165. .user-list {
  166. .el-tag {
  167. margin-right: 10px;
  168. margin-top: 12px;
  169. }
  170. .user-item {
  171. position: relative;
  172. padding: 4px 0;
  173. }
  174. .user-item + .user-item {
  175. border-top: 1px dashed #EEEEEE;
  176. }
  177. .checkbox-li .el-checkbox {
  178. width: 100%;
  179. .el-checkbox__input {
  180. position: absolute;
  181. right: 0;
  182. .el-checkbox__inner {
  183. width: 18px;
  184. height: 18px;
  185. &:after {
  186. height: 9px;
  187. left: 6px;
  188. top: 2px;
  189. }
  190. }
  191. }
  192. .el-checkbox__label {
  193. flex: 1;
  194. padding-left: 0;
  195. padding-right: 20px;
  196. }
  197. }
  198. }
  199. }
  200. </style>