DataTable.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <script lang="ts" setup>
  2. /**
  3. * @Name: Table.vue
  4. * @Description: 商品列表表格
  5. * @Author: Cheney
  6. */
  7. import { Download, Message, Money, Open, Operation, Refresh } from '@element-plus/icons-vue';
  8. import * as api from '/@/views/product-list/api';
  9. import PermissionButton from '/@/components/PermissionButton/index.vue';
  10. import EditDrawer from '/@/views/product-list/component/EditDrawer.vue';
  11. import NoticeDialog from '/@/views/product-list/component/NoticeDialog.vue';
  12. import ImportButton from '/@/components/ImportButton/index.vue';
  13. import VerticalDivider from '/@/components/VerticalDivider/index.vue';
  14. import { productColumns } from '/@/views/product-list/ColumnsTsx';
  15. const { tableOptions, handlePageChange } = usePagination(fetchList);
  16. const gridRef = ref();
  17. const gridOptions: any = reactive({
  18. border: false,
  19. round: true,
  20. stripe: true,
  21. currentRowHighLight: true,
  22. height: '100%',
  23. toolbarConfig: {
  24. custom: true,
  25. slots: {
  26. buttons: 'toolbar_buttons',
  27. tools: 'toolbar_tools'
  28. }
  29. },
  30. rowConfig: {
  31. isHover: true
  32. },
  33. columnConfig: {
  34. resizable: true
  35. },
  36. pagerConfig: {
  37. total: tableOptions.value.total,
  38. page: tableOptions.value.page,
  39. limit: tableOptions.value.limit
  40. },
  41. loading: false,
  42. loadingConfig: {
  43. icon: 'vxe-icon-indicator roll',
  44. text: '正在拼命加载中...'
  45. },
  46. columns: productColumns,
  47. data: ''
  48. });
  49. const checkedList = ref<Set<number>>(new Set());
  50. const editOpen = ref(false);
  51. const rowData = ref({});
  52. const dialogVisible = ref(false);
  53. const templateType = ref();
  54. onBeforeMount(() => {
  55. fetchList();
  56. });
  57. async function fetchList() {
  58. const query = {
  59. page: gridOptions.pagerConfig.page,
  60. limit: gridOptions.pagerConfig.limit
  61. };
  62. await useTableData(api.getTableData, query, gridOptions);
  63. }
  64. function handleRefresh() {
  65. fetchList();
  66. }
  67. async function batchOpen() {
  68. const ids = Array.from(checkedList.value);
  69. await useResponse(api.updateShopDetail, { ids, status: 1 });
  70. checkedList.value.clear();
  71. await fetchList();
  72. }
  73. function selectChangeEvent({ checked, row }: any) {
  74. if (checked) {
  75. checkedList.value.add(row.id); // 获取单个数据
  76. } else {
  77. checkedList.value.delete(row.id);
  78. }
  79. }
  80. function selectAllChangeEvent({ checked }: any) {
  81. const $grid = gridRef.value;
  82. if ($grid) {
  83. const records = $grid.getData(); // 获取所有数据
  84. if (checked) {
  85. records.forEach((item: any) => {
  86. checkedList.value.add(item.id);
  87. });
  88. } else {
  89. checkedList.value.clear();
  90. }
  91. }
  92. }
  93. function handleEdit(row: any) {
  94. editOpen.value = true;
  95. rowData.value = row;
  96. }
  97. function handleNotice(row: any) {
  98. dialogVisible.value = true;
  99. rowData.value = row;
  100. }
  101. function downloadTemplate() {
  102. // console.log('111=> ');
  103. }
  104. </script>
  105. <template>
  106. <vxe-grid ref="gridRef" v-bind="gridOptions"
  107. @checkbox-change="selectChangeEvent"
  108. @checkbox-all="selectAllChangeEvent">
  109. <template #toolbar_buttons>
  110. <div class="flex gap-2">
  111. <PermissionButton :disabled="!checkedList.size" :icon="Open" plain round type="primary" @click="batchOpen">
  112. 批量开启
  113. </PermissionButton>
  114. <VerticalDivider class="px-1" style="margin-left: 7px;" />
  115. <div class="custom-el-input">
  116. <el-select v-model="templateType" placeholder="Select" style="width: 190px">
  117. <template #prefix>
  118. <div class="flex items-center">
  119. <el-button bg size="small" style="margin-left: -7px; font-size: 14px; border-radius: 29px;" text
  120. type="success"
  121. @click.stop="downloadTemplate">下载
  122. </el-button>
  123. <VerticalDivider style="margin-left: 7px" />
  124. </div>
  125. </template>
  126. <el-option label="商品通知模板" value="item1" />
  127. <el-option label="商品模板" value="item2" />
  128. <el-option label="指导价格模板" value="item3" />
  129. </el-select>
  130. </div>
  131. <ImportButton :icon="Message" bg text>变更通知导入</ImportButton>
  132. <ImportButton bg text>
  133. <i class="bi bi-box-seam mr-3"></i>
  134. 商品导入
  135. </ImportButton>
  136. <ImportButton :icon="Money" bg text>指导价格导入</ImportButton>
  137. </div>
  138. </template>
  139. <template #toolbar_tools>
  140. <el-button circle class="toolbar-btn" @click="handleRefresh">
  141. <el-icon>
  142. <Refresh />
  143. </el-icon>
  144. </el-button>
  145. <el-button circle class="mr-3 toolbar-btn">
  146. <el-icon>
  147. <Download />
  148. </el-icon>
  149. </el-button>
  150. </template>
  151. <template #top>
  152. <div class="mb-2"></div>
  153. </template>
  154. <template #pager>
  155. <vxe-pager
  156. v-model:currentPage="gridOptions.pagerConfig.page"
  157. v-model:pageSize="gridOptions.pagerConfig.limit"
  158. :total="gridOptions.pagerConfig.total"
  159. class="mt-1.5"
  160. @page-change="handlePageChange"
  161. />
  162. </template>
  163. <template #operate="{ row }">
  164. <div class="flex justify-center gap-2">
  165. <PermissionButton circle plain type="warning" @click="handleEdit(row)">
  166. <el-icon>
  167. <Operation />
  168. </el-icon>
  169. </PermissionButton>
  170. <PermissionButton circle plain type="info" @click="handleNotice(row)">
  171. <el-icon>
  172. <Message />
  173. </el-icon>
  174. </PermissionButton>
  175. </div>
  176. </template>
  177. </vxe-grid>
  178. <EditDrawer v-if="editOpen" v-model="editOpen" :row-data="rowData" />
  179. <NoticeDialog v-if="dialogVisible" v-model="dialogVisible" :row-data="rowData" />
  180. </template>
  181. <style scoped>
  182. .toolbar-btn {
  183. width: 34px;
  184. height: 34px;
  185. font-size: 18px
  186. }
  187. :deep(.custom-el-input .el-select__wrapper) {
  188. border-radius: 20px;
  189. }
  190. </style>