EmployeeDetail.vue 5.8 KB

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