EmployeeDetail.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <script lang="ts" setup>
  2. /**
  3. * @Name: EmployeeDetail.vue
  4. * @Description: 电脑信息-当前
  5. * @Author: xinyan
  6. */
  7. import { useResponse } from '/@/utils/useResponse';
  8. import { EmployeeShopColumns, EmployeeComputerColumns } from '/@/views/employee-information/useColumns';
  9. import * as api from '../api';
  10. import { Edit, Picture as IconPicture } from '@element-plus/icons-vue';
  11. import { useTableData } from '/@/utils/useTableData';
  12. import { usePagination } from '/@/utils/usePagination';
  13. import EditEmployeeInfo from '/@/views/employee-information/components/EditEmployeeInfo.vue';
  14. import { ref } from 'vue';
  15. const route = useRoute();
  16. const id = route.query.id;
  17. const employeeOverview: any = ref([]);
  18. const overviewLoading = ref();
  19. const isDrawerVisible = ref(false);
  20. const currentView = ref('shop');
  21. const { tableOptions, handlePageChange } = usePagination(fetchEmployeeData);
  22. const gridOptions: any = reactive({
  23. border: 'inner',
  24. round: true,
  25. stripe: true,
  26. shopRowHighLight: true,
  27. height: 700,
  28. toolbarConfig: {
  29. custom: true,
  30. slots: {
  31. buttons: 'toolbar_buttons',
  32. // tools: 'toolbar_tools'
  33. },
  34. },
  35. rowConfig: {
  36. isHover: true,
  37. },
  38. columnConfig: {
  39. resizable: true,
  40. },
  41. // pagerConfig: {
  42. // total: tableOptions.value.total,
  43. // page: tableOptions.value.page,
  44. // limit: tableOptions.value.limit,
  45. // },
  46. loading: false,
  47. loadingConfig: {
  48. icon: 'vxe-icon-indicator roll',
  49. text: '正在拼命加载中...',
  50. },
  51. columns: EmployeeShopColumns,
  52. data: [],
  53. });
  54. // function pageChange({ pageSize, shopPage }: any) {
  55. // gridOptions.pagerConfig.limit = pageSize;
  56. // gridOptions.pagerConfig.page = shopPage;
  57. // fetchEmployeeData();
  58. // }
  59. // 当前信息、历史记录
  60. async function fetchEmployeeData(view) { // 默认为当前视图
  61. const query = {
  62. // page: gridOptions.pagerConfig.page,
  63. // limit: gridOptions.pagerConfig.limit,
  64. };
  65. switch (view) {
  66. case 'shop':
  67. gridOptions.columns = EmployeeShopColumns;
  68. currentView.value = 'shop';
  69. query.id = id;
  70. await useTableData(api.getShopTableData, query, gridOptions);
  71. break;
  72. case 'computer':
  73. gridOptions.columns = EmployeeComputerColumns;
  74. currentView.value = 'computer';
  75. query.id = id;
  76. await useTableData(api.getComputerTableData, query, gridOptions);
  77. break;
  78. }
  79. }
  80. function switchView(view) {
  81. if (view !== currentView.value) { // 只有在不同的视图时才切换
  82. fetchEmployeeData(view); // 调用 fetchEmployeeData 来加载新的视图数据
  83. }
  84. }
  85. async function editItem() {
  86. isDrawerVisible.value = true; // 显示 Drawer
  87. }
  88. async function fetchEmployeeDetailOverview() {
  89. const res = await useResponse(id, api.getEmployeeDetailOverview, overviewLoading);
  90. employeeOverview.value = res.data;
  91. }
  92. const getImageSrc = () => {
  93. // 如果 `images` 有值,则返回第一张图片的 URL;否则返回占位图
  94. return employeeOverview.value.images && employeeOverview.value.images.length > 0
  95. ? employeeOverview.value.images[0].image_url
  96. : '';
  97. };
  98. // 表格样式
  99. const cellStyle = () => {
  100. return {
  101. fontSize: '12px',
  102. fontWeight: '600',
  103. };
  104. };
  105. const headerCellStyle = () => {
  106. return {
  107. fontSize: '12px',
  108. };
  109. };
  110. function handleRefresh() {
  111. fetchEmployeeDetailOverview();
  112. fetchEmployeeData(currentView.value);
  113. }
  114. onMounted(() => {
  115. fetchEmployeeDetailOverview();
  116. fetchEmployeeData(currentView.value);
  117. });
  118. </script>
  119. <template>
  120. <div class="p-2.5">
  121. <!-- overview-card -->
  122. <el-card v-loading="overviewLoading" body-class="flex items-center" shadow="hover" style="border: none">
  123. <el-image :src="getImageSrc()" class="mr-7 rounded-2xl" style="height: 100px; width: 100px; object-fit: contain">
  124. <template #error>
  125. <div class="mr-3.5 flex items-center justify-center text-5xl" style="height: 100px; width: 100px; background-color: #f5f5f5">
  126. <el-icon>
  127. <icon-picture />
  128. </el-icon>
  129. </div>
  130. </template>
  131. </el-image>
  132. <el-button :icon="Edit" link type="warning" @click="editItem"></el-button>
  133. <el-col :span="18">
  134. <div class="info-container text-lg">
  135. <div class="info-column">
  136. <div class="font-semibold">
  137. 姓名:
  138. <span class="font-medium italic ml-1.5" style="color: #64748b">{{ employeeOverview.name }}</span>
  139. </div>
  140. <div class="font-semibold">
  141. 所属部门:
  142. <span class="font-medium italic ml-1.5" style="color: #64748b">{{ employeeOverview.department }}</span>
  143. </div>
  144. <div class="font-semibold">
  145. 电话:
  146. <span class="font-medium italic ml-1.5" style="color: #64748b">{{ employeeOverview.phone }}</span>
  147. </div>
  148. <div class="font-semibold">
  149. 邮箱:
  150. <span class="font-medium italic ml-1.5" style="color: #64748b">{{ employeeOverview.email }}</span>
  151. </div>
  152. </div>
  153. </div>
  154. </el-col>
  155. </el-card>
  156. <!-- table-card -->
  157. <el-card body-style="padding-top: 10px" class="mt-2.5" shadow="hover" style="border: none">
  158. <vxe-grid :cell-style="cellStyle" :header-cell-style="headerCellStyle" v-bind="gridOptions">
  159. <template #toolbar_buttons>
  160. <el-button :type="currentView === 'shop' ? 'primary' : 'default'" @click="switchView('shop')"> 店铺信息 </el-button>
  161. <el-button :type="currentView === 'computer' ? 'primary' : 'default'" @click="switchView('computer')"> 电脑信息 </el-button>
  162. </template>
  163. <!--<template #pager>-->
  164. <!-- <vxe-pager-->
  165. <!-- v-model:currentPage="gridOptions.pagerConfig.page"-->
  166. <!-- v-model:pageSize="gridOptions.pagerConfig.limit"-->
  167. <!-- :total="gridOptions.pagerConfig.total"-->
  168. <!-- size="small"-->
  169. <!-- @page-change="handlePageChange"-->
  170. <!-- >-->
  171. <!-- </vxe-pager>-->
  172. <!--</template>-->
  173. </vxe-grid>
  174. </el-card>
  175. <!-- 编辑 Drawer -->
  176. <EditEmployeeInfo v-if="isDrawerVisible" v-model="isDrawerVisible" :employeeOverview :name="employeeOverview.name" @refresh="handleRefresh" />
  177. </div>
  178. </template>
  179. <style lang="scss" scoped>
  180. .info-container {
  181. display: flex;
  182. justify-content: space-between;
  183. }
  184. .info-column {
  185. flex: 1;
  186. padding: 0 10px;
  187. }
  188. p {
  189. margin: 5px 0;
  190. }
  191. </style>