DataTable.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. <script lang="ts" setup>
  2. /**
  3. * @Name: DataTable.vue
  4. * @Description:
  5. * @Author: xinyan
  6. */
  7. import { Download, Plus, Refresh, Upload } from '@element-plus/icons-vue';
  8. import { ElMessage } from 'element-plus';
  9. import { usePagination } from '/@/utils/usePagination';
  10. import { useTableData } from '/@/utils/useTableData';
  11. import DataTableSlot from './DataTableSlot.vue';
  12. import { uesDownloadFile } from '/@/utils/useDownload';
  13. import { downloadFile } from '/@/utils/service';
  14. import PermissionButton from '/src/components/PermissionButton/index.vue';
  15. import ImportButton from '/src/components/ImportButton/index.vue';
  16. import VerticalDivider from '/src/components/VerticalDivider/index.vue';
  17. import * as api from '../api';
  18. import { useResponse } from '/@/utils/useResponse';
  19. import {
  20. DirectSalesCheckColumns_Regular, DirectSalesCheckColumns_Special,
  21. } from '/@/views/price-approval/Columns';
  22. import EditDrawer from '/@/views/price-approval/direct-sales/component/EditDrawer.vue';
  23. import router from '/@/router';
  24. interface Parameter {
  25. sku: string;
  26. platform: string;
  27. country_code: string;
  28. sales_mode: string;
  29. }
  30. const queryParameter: Parameter | undefined = inject('query-parameter');
  31. const { tableOptions, handlePageChange } = usePagination(fetchList);
  32. const gridRef = ref();
  33. const gridOptions: any = reactive({
  34. size: 'mini',
  35. border: false,
  36. round: true,
  37. stripe: true,
  38. currentRowHighLight: true,
  39. height: '100%',
  40. toolbarConfig: {
  41. size: 'large',
  42. slots: {
  43. buttons: 'toolbar_buttons',
  44. tools: 'toolbar_tools',
  45. },
  46. },
  47. rowConfig: {
  48. isHover: true,
  49. },
  50. columnConfig: {
  51. resizable: true,
  52. },
  53. pagerConfig: {
  54. total: tableOptions.value.total,
  55. page: tableOptions.value.page,
  56. limit: tableOptions.value.limit,
  57. },
  58. loading: false,
  59. loadingConfig: {
  60. icon: 'vxe-icon-indicator roll',
  61. text: '正在拼命加载中...',
  62. },
  63. columns: '',
  64. data: '',
  65. });
  66. const checkedList = ref<Set<number>>(new Set());
  67. const btnLoading = ref(false);
  68. const editOpen = ref(false);
  69. const rowData = ref({});
  70. const dialogVisible = ref(false);
  71. const templateType = ref('cost');
  72. onBeforeMount(() => {
  73. gridOptions.pagerConfig.limit = 10;
  74. });
  75. onMounted(() => {
  76. fetchList();
  77. });
  78. async function fetchList(isQuery = false) {
  79. if (isQuery) {
  80. gridOptions.pagerConfig.page = 1;
  81. }
  82. gridOptions.data = [];
  83. gridOptions.columns = [];
  84. const query = {
  85. sku: queryParameter?.sku,
  86. platform: queryParameter?.platform,
  87. country_code:queryParameter?.country_code,
  88. sales_mode: queryParameter?.sales_mode,
  89. };
  90. await useTableData(api.getTableData, query, gridOptions);
  91. await gridRef.value.loadColumn(DirectSalesCheckColumns_Special);
  92. gridOptions.showHeader = Boolean(gridOptions.data?.length);
  93. }
  94. function handleRefresh() {
  95. fetchList();
  96. }
  97. async function handleDownload() {
  98. // gridOptions.loading = true;
  99. // try {
  100. // await uesDownloadFile({
  101. // apiMethod: api.exportData, // 调用的 API 方法
  102. // queryParams: {
  103. // sku: queryParameter?.sku,
  104. // platform: queryParameter?.platform,
  105. // country_code:queryParameter?.country_code,
  106. // sales_mode: queryParameter?.sales_mode,
  107. // },
  108. // fileName: '审批查看(直销)数据.xlsx', // 自定义文件名
  109. // successMessage: () => ElMessage.success('数据导出成功!'),
  110. // errorMessage: () => ElMessage.error('数据导出失败,请重试!'),
  111. // });
  112. // } finally {
  113. // gridOptions.loading = false; // 结束加载状态
  114. // }
  115. }
  116. function handleCreate() {
  117. router.push({ name: 'AddPage', query: { type: 'direct' } });
  118. }
  119. function handleEdit(row: any) {
  120. editOpen.value = true;
  121. rowData.value = row;
  122. }
  123. async function singleDelete(row: any) {
  124. const res = await useResponse(api.deleteRow, row);
  125. if (res.code === 2000) {
  126. ElMessage.error({ message: '已删除!', plain: true, icon: 'Delete' });
  127. handleRefresh();
  128. }
  129. }
  130. function downloadTemplate() {
  131. // const url = '/api/choice/reviews_monitor/import_data/';
  132. // const fileName = '审批查看(直销)模板.xlsx';
  133. //
  134. // if (url) {
  135. // downloadFile({
  136. // url,
  137. // method: 'GET',
  138. // filename: fileName,
  139. // });
  140. // } else {
  141. // console.error('未知的模板类型:', templateType.value);
  142. // }
  143. }
  144. const gridEvents = {
  145. custom({ type }: any) {
  146. if (type == 'confirm') {
  147. fetchList();
  148. }
  149. },
  150. };
  151. function cellStyle(){
  152. return{
  153. fontWeight:600,
  154. }
  155. }
  156. defineExpose({ fetchList });
  157. </script>
  158. <template>
  159. <vxe-grid ref="gridRef" v-bind="gridOptions" v-on="gridEvents" @checkbox-change="selectChangeEvent" @checkbox-all="selectAllChangeEvent" :cell-style="cellStyle">
  160. <!-- 工具栏左侧 -->
  161. <template #toolbar_buttons>
  162. <div class="flex gap-2">
  163. <!--<div>-->
  164. <!-- <el-popconfirm :icon="InfoFilled" icon-color="#626AEF" title="你确定要删除此项吗?" width="220" @confirm="batchDelete">-->
  165. <!-- <template #reference>-->
  166. <!-- <PermissionButton :disabled="!checkedList.size" :icon="Delete" plain round type="danger"> 批量删除 </PermissionButton>-->
  167. <!-- </template>-->
  168. <!-- <template #actions="{ confirm, cancel }">-->
  169. <!-- <el-button size="small" @click="cancel">No!</el-button>-->
  170. <!-- <el-button size="small" type="danger" @click="confirm">Yes?</el-button>-->
  171. <!-- </template>-->
  172. <!-- </el-popconfirm>-->
  173. <!--</div>-->
  174. <div>
  175. <PermissionButton :icon="Plus" plain round type="primary" @click="handleCreate">新 增</PermissionButton>
  176. </div>
  177. <div class="custom-el-input">
  178. <el-select v-model="templateType" style="width: 200px">
  179. <template #prefix>
  180. <div class="flex items-center">
  181. <el-button
  182. size="small"
  183. style="margin-left: -7px; font-size: 14px; border-radius: 29px"
  184. text
  185. type="success"
  186. @click.stop="downloadTemplate"
  187. >
  188. 下载
  189. </el-button>
  190. <VerticalDivider style="margin-left: 7px" />
  191. </div>
  192. </template>
  193. <el-option label="审批查看(直销)" value="cost" />
  194. </el-select>
  195. </div>
  196. <VerticalDivider class="px-1" style="margin-left: 7px" />
  197. <ImportButton :icon="Upload" :uploadFunction="api.upload" bg text>导 入</ImportButton>
  198. </div>
  199. </template>
  200. <!-- 工具栏右侧 -->
  201. <template #toolbar_tools>
  202. <el-button circle class="toolbar-btn" @click="handleRefresh">
  203. <el-icon>
  204. <Refresh />
  205. </el-icon>
  206. </el-button>
  207. <el-button circle class="toolbar-btn" @click="handleDownload">
  208. <el-icon>
  209. <Download />
  210. </el-icon>
  211. </el-button>
  212. </template>
  213. <template #top>
  214. <div class="mb-2"></div>
  215. </template>
  216. <!-- 分页 -->
  217. <template #pager>
  218. <vxe-pager
  219. v-model:currentPage="gridOptions.pagerConfig.page"
  220. v-model:pageSize="gridOptions.pagerConfig.limit"
  221. :total="gridOptions.pagerConfig.total"
  222. class="mt-1.5"
  223. @page-change="handlePageChange"
  224. />
  225. </template>
  226. <template #empty>
  227. <el-empty description="暂无数据" />
  228. </template>
  229. <!-- 自定义列插槽 -->
  230. <template v-for="col in DirectSalesCheckColumns_Special" #[`${col.field}`]="{ row }">
  231. <DataTableSlot :field="col.field" :row="row" @edit-row="handleEdit" @handle-delete="singleDelete" />
  232. </template>
  233. </vxe-grid>
  234. <EditDrawer v-if="editOpen" v-model="editOpen" :row-data="rowData" @refresh="handleRefresh" />
  235. </template>
  236. <style scoped>
  237. .toolbar-btn {
  238. width: 34px;
  239. height: 34px;
  240. font-size: 18px;
  241. }
  242. :deep(.custom-el-input .el-select__wrapper) {
  243. border-radius: 20px;
  244. }
  245. </style>