project-select.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <template>
  2. <el-dialog
  3. v-model="state.showDialog"
  4. destroy-on-close
  5. :title="title"
  6. append-to-body
  7. draggable
  8. :close-on-click-modal="false"
  9. :close-on-press-escape="false"
  10. width="780px"
  11. >
  12. <div style="padding: 0px 0px 8px 8px; background-color: var(--ba-bg-color)">
  13. <el-card shadow="never" :body-style="{ paddingBottom: '0' }" style="margin-top: 8px">
  14. <el-form :model="state.filter" :inline="true" @submit.stop.prevent>
  15. <el-form-item label="企业名" prop="name">
  16. <el-input v-model="state.filter.name" placeholder="企业名" @keyup.enter="onQuery" />
  17. </el-form-item>
  18. <el-form-item>
  19. <el-button type="primary" icon="ele-Search" @click="onQuery"> 查询 </el-button>
  20. </el-form-item>
  21. </el-form>
  22. </el-card>
  23. <el-card shadow="never" style="margin-top: 8px">
  24. <el-table
  25. ref="tenantTableRef"
  26. :data="state.tenantListData"
  27. style="width: 100%"
  28. v-loading="state.loading"
  29. row-key="id"
  30. default-expand-all
  31. :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
  32. :highlight-current-row="!multiple"
  33. @row-click="onRowClick"
  34. @row-dblclick="onRowDbClick"
  35. >
  36. <el-table-column v-if="multiple" type="selection" width="55" />
  37. <el-table-column prop="name" label="企业名" min-width="80" show-overflow-tooltip />
  38. <el-table-column prop="code" label="企业编码" min-width="120" show-overflow-tooltip />
  39. <!-- <el-table-column prop="email" label="邮箱" min-width="120" show-overflow-tooltip /> -->
  40. </el-table>
  41. <div class="my-flex my-flex-end" style="margin-top: 20px">
  42. <el-pagination
  43. v-model:currentPage="state.pageInput.currentPage"
  44. v-model:page-size="state.pageInput.pageSize"
  45. :total="state.total"
  46. :page-sizes="[10, 20, 50, 100]"
  47. small
  48. background
  49. @size-change="onSizeChange"
  50. @current-change="onCurrentChange"
  51. layout="total, sizes, prev, pager, next"
  52. />
  53. </div>
  54. </el-card>
  55. </div>
  56. <template #footer>
  57. <span class="dialog-footer">
  58. <el-button @click="onCancel" size="default">取 消</el-button>
  59. <el-button type="primary" @click="onSure" size="default" :loading="sureLoading">确 定</el-button>
  60. </span>
  61. </template>
  62. </el-dialog>
  63. </template>
  64. <script lang="ts" setup name="admin/tenant/components/tenant-select">
  65. import { ref, reactive } from 'vue'
  66. import { ElTable } from 'element-plus'
  67. import { TenantListOutput, PageInputTenantGetPageDto } from '/@/api/admin/data-contracts'
  68. import { TenantApi } from '/@/api/admin/Tenant'
  69. const props = defineProps({
  70. title: {
  71. type: String,
  72. default: '',
  73. },
  74. multiple: {
  75. type: Boolean,
  76. default: false,
  77. },
  78. sureLoading: {
  79. type: Boolean,
  80. default: false,
  81. },
  82. })
  83. const emits = defineEmits(['sure'])
  84. const tenantTableRef = ref<InstanceType<typeof ElTable>>()
  85. const state = reactive({
  86. showDialog: false,
  87. loading: false,
  88. filter: {
  89. name: '',
  90. },
  91. total: 0,
  92. pageInput: {
  93. currentPage: 1,
  94. pageSize: 20,
  95. filter: {
  96. name: '',
  97. },
  98. } as PageInputTenantGetPageDto,
  99. tenantListData: [] as Array<TenantListOutput>,
  100. })
  101. // 打开对话框
  102. const open = () => {
  103. state.showDialog = true
  104. onQuery()
  105. }
  106. // 关闭对话框
  107. const close = () => {
  108. state.showDialog = false
  109. }
  110. const onQuery = async () => {
  111. state.loading = true
  112. state.pageInput.filter = state.filter
  113. const res = await new TenantApi().getPage(state.pageInput).catch(() => {
  114. state.loading = false
  115. })
  116. state.tenantListData = res?.data?.list ?? []
  117. state.total = res?.data?.total ?? 0
  118. state.loading = false
  119. }
  120. const onSizeChange = (val: number) => {
  121. state.pageInput.pageSize = val
  122. onQuery()
  123. }
  124. const onCurrentChange = (val: number) => {
  125. state.pageInput.currentPage = val
  126. onQuery()
  127. }
  128. const onRowClick = (row: TenantListOutput) => {
  129. // TODO: improvement typing when refactor table
  130. // eslint-disable-next-line @typescript-eslint/ban-ts-comment
  131. // @ts-expect-error
  132. tenantTableRef.value!.toggleRowSelection(row, props.multiple ? undefined : true)
  133. }
  134. const onRowDbClick = () => {
  135. if (!props.multiple) {
  136. onSure()
  137. }
  138. }
  139. // 取消
  140. const onCancel = () => {
  141. state.showDialog = false
  142. }
  143. // 确定
  144. const onSure = () => {
  145. const selectionRows = tenantTableRef.value!.getSelectionRows() as TenantListOutput[]
  146. emits('sure', props.multiple ? selectionRows : selectionRows.length > 0 ? selectionRows[0] : null)
  147. }
  148. defineExpose({
  149. open,
  150. close,
  151. })
  152. </script>
  153. <style scoped lang="scss">
  154. :deep(.el-dialog__body) {
  155. padding: 5px 10px;
  156. }
  157. </style>