DataTable.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  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. if (gridOptions && gridOptions.data?.length) 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,
  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({ path: '/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/pricing/price_product_direct/import_data/';
  132. const fileName = '审批查看(直销)模板.xlsx';
  133. if (url) {
  134. downloadFile({
  135. url,
  136. method: 'GET',
  137. filename: fileName,
  138. });
  139. } else {
  140. console.error('未知的模板类型:', templateType.value);
  141. }
  142. }
  143. const gridEvents = {
  144. custom({ type }: any) {
  145. if (type == 'confirm') {
  146. fetchList();
  147. }
  148. }
  149. };
  150. function cellStyle() {
  151. return {
  152. fontWeight: 600
  153. };
  154. }
  155. defineExpose({ fetchList });
  156. </script>
  157. <template>
  158. <vxe-grid ref="gridRef" :cell-style="cellStyle" v-bind="gridOptions" v-on="gridEvents">
  159. <!-- 工具栏左侧 -->
  160. <template #toolbar_buttons>
  161. <div class="flex gap-2">
  162. <!--<div>-->
  163. <!-- <el-popconfirm :icon="InfoFilled" icon-color="#626AEF" title="你确定要删除此项吗?" width="220" @confirm="batchDelete">-->
  164. <!-- <template #reference>-->
  165. <!-- <PermissionButton :disabled="!checkedList.size" :icon="Delete" plain round type="danger"> 批量删除 </PermissionButton>-->
  166. <!-- </template>-->
  167. <!-- <template #actions="{ confirm, cancel }">-->
  168. <!-- <el-button size="small" @click="cancel">No!</el-button>-->
  169. <!-- <el-button size="small" type="danger" @click="confirm">Yes?</el-button>-->
  170. <!-- </template>-->
  171. <!-- </el-popconfirm>-->
  172. <!--</div>-->
  173. <div>
  174. <PermissionButton :icon="Plus" plain round type="primary" @click="handleCreate">新 增</PermissionButton>
  175. </div>
  176. <div class="custom-el-input">
  177. <el-select v-model="templateType" style="width: 200px">
  178. <template #prefix>
  179. <div class="flex items-center">
  180. <el-button
  181. size="small"
  182. style="margin-left: -7px; font-size: 14px; border-radius: 29px"
  183. text
  184. type="success"
  185. @click.stop="downloadTemplate"
  186. >
  187. 下载
  188. </el-button>
  189. <VerticalDivider style="margin-left: 7px" />
  190. </div>
  191. </template>
  192. <el-option label="审批查看(直销)" value="cost" />
  193. </el-select>
  194. </div>
  195. <VerticalDivider class="px-1" style="margin-left: 7px" />
  196. <ImportButton :icon="Upload" :uploadFunction="api.upload" bg text>导 入</ImportButton>
  197. </div>
  198. </template>
  199. <!-- 工具栏右侧 -->
  200. <template #toolbar_tools>
  201. <el-button circle class="toolbar-btn" @click="handleRefresh">
  202. <el-icon>
  203. <Refresh />
  204. </el-icon>
  205. </el-button>
  206. <el-button circle class="toolbar-btn" @click="handleDownload">
  207. <el-icon>
  208. <Download />
  209. </el-icon>
  210. </el-button>
  211. </template>
  212. <template #top>
  213. <div class="mb-2"></div>
  214. </template>
  215. <!-- 分页 -->
  216. <template #pager>
  217. <vxe-pager
  218. v-model:currentPage="gridOptions.pagerConfig.page"
  219. v-model:pageSize="gridOptions.pagerConfig.limit"
  220. :total="gridOptions.pagerConfig.total"
  221. class="mt-1.5"
  222. @page-change="handlePageChange"
  223. />
  224. </template>
  225. <template #empty>
  226. <el-empty description="暂无数据" />
  227. </template>
  228. <!-- 自定义列插槽 -->
  229. <template v-for="col in DirectSalesCheckColumns_Special" #[`${col.field}`]="{ row }">
  230. <DataTableSlot :field="col.field" :row="row" @edit-row="handleEdit" @handle-delete="singleDelete" />
  231. </template>
  232. </vxe-grid>
  233. <EditDrawer v-if="editOpen" v-model="editOpen" :row-data="rowData" @refresh="handleRefresh" />
  234. </template>
  235. <style scoped>
  236. .toolbar-btn {
  237. width: 34px;
  238. height: 34px;
  239. font-size: 18px;
  240. }
  241. :deep(.custom-el-input .el-select__wrapper) {
  242. border-radius: 20px;
  243. }
  244. </style>