DataTable.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. <script lang="ts" setup>
  2. /**
  3. * @Name: DataTable.vue
  4. * @Description:
  5. * @Author: Cheney
  6. */
  7. import { usePagination } from '/@/utils/usePagination';
  8. import { shopInfoColumns } from '/@/views/shop-information/useColumns';
  9. import * as api from '../api';
  10. import { useTableData } from '/@/utils/useTableData';
  11. import { useResponse } from '/@/utils/useResponse';
  12. import { Link } from '@element-plus/icons-vue';
  13. import router from '/@/router';
  14. const { tableOptions, handlePageChange } = usePagination(fetchList);
  15. const gridRef = ref();
  16. const gridOptions: any = reactive({
  17. // size: 'small',
  18. border: false,
  19. round: true,
  20. stripe: true,
  21. currentRowHighLight: true,
  22. height: 1000,
  23. toolbarConfig: {
  24. size: 'large',
  25. custom: true,
  26. slots: {
  27. buttons: 'toolbar_buttons'
  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: '',
  47. data: '',
  48. });
  49. const platformNumber = ref('');
  50. const platform = ref('');
  51. const operatorName = ref('');
  52. const country = ref('');
  53. const company = ref('');
  54. const splitOperator = ref('');
  55. const splitCountry = ref('');
  56. const tempOperator = ref('');
  57. const tempCountry = ref('');
  58. const countryOption = ref([]);
  59. const platformOption = ref([]);
  60. const operatorOption = ref([]);
  61. onBeforeMount(() => {
  62. gridOptions.pagerConfig.limit = 20;
  63. fetchFilterOptions();
  64. });
  65. onMounted(() => {
  66. fetchList();
  67. });
  68. async function fetchFilterOptions() {
  69. const res = await useResponse({}, api.getFilterOptions);
  70. countryOption.value = res.data.country;
  71. platformOption.value = res.data.platform;
  72. operatorOption.value = res.data.operatorName;
  73. }
  74. async function fetchList() {
  75. gridOptions.data = [];
  76. gridOptions.columns = [];
  77. const query = {
  78. platformNumber: platformNumber.value,
  79. platform: platform.value,
  80. operatorName: splitOperator.value,
  81. country: splitCountry.value,
  82. company: company.value
  83. };
  84. tempOperator.value = query.operatorName;
  85. tempCountry.value = query.country;
  86. await useTableData(api.getInfoTableData, query, gridOptions);
  87. await gridRef.value.loadColumn(shopInfoColumns);
  88. gridOptions.showHeader = Boolean(gridOptions.data?.length);
  89. }
  90. async function processParameter() {
  91. if (operatorName.value) {
  92. splitOperator.value = operatorName.value ? operatorName.value + ',' : '';
  93. splitOperator.value = splitOperator.value.slice(0, -1);
  94. }
  95. if (country.value) {
  96. splitCountry.value = country.value ? country.value + ',' : '';
  97. splitCountry.value = splitCountry.value.slice(0, -1);
  98. }
  99. }
  100. function parameterChange() {
  101. if (operatorName.value.toString() != tempOperator.value || country.value.toString() != tempCountry.value) {
  102. gridOptions.pagerConfig.page = 1;
  103. fetchList();
  104. }
  105. }
  106. function handleInputQuery() {
  107. gridOptions.pagerConfig.page = 1;
  108. fetchList()
  109. }
  110. function handleNavigate(item: any) {
  111. router.push({
  112. path: '/shop/detail',
  113. query: { platformNumber: item.platformNumber }
  114. });
  115. }
  116. </script>
  117. <template>
  118. <vxe-grid ref="gridRef" v-bind="gridOptions">
  119. <template #toolbar_buttons>
  120. <el-row :gutter="20" class="w-full whitespace-nowrap">
  121. <el-col :span="4">
  122. <div class="flex items-center gap-1.5">
  123. <span class="font-medium">运 营</span>
  124. <el-select v-model="operatorName" clearable collapse-tags collapse-tags-tooltip filterable multiple
  125. @blur="parameterChange"
  126. @change="processParameter">
  127. <el-option v-for="item in operatorOption" :label="item" :value="item" />
  128. </el-select>
  129. </div>
  130. </el-col>
  131. <el-col :span="4">
  132. <div class="flex items-center gap-1.5">
  133. <span class="font-medium">国 家</span>
  134. <el-select v-model="country" clearable collapse-tags collapse-tags-tooltip multiple
  135. @blur="parameterChange"
  136. @change="processParameter">
  137. <el-option v-for="item in countryOption" :label="item" :value="item" />
  138. </el-select>
  139. </div>
  140. </el-col>
  141. <el-col :span="4">
  142. <div class="flex items-center gap-1.5">
  143. <span class="font-medium">平 台</span>
  144. <el-select v-model="platform" clearable @change="handleInputQuery">
  145. <el-option v-for="item in platformOption" :label="item" :value="item" />
  146. </el-select>
  147. </div>
  148. </el-col>
  149. <el-col :span="4">
  150. <div class="flex items-center gap-1.5">
  151. <span class="font-medium">店铺编号</span>
  152. <el-input v-model="platformNumber" clearable placeholder="请输入店铺编号" @change="handleInputQuery" />
  153. </div>
  154. </el-col>
  155. <el-col :span="5">
  156. <div class="flex items-center gap-1.5">
  157. <span class="font-medium">公 司</span>
  158. <el-input v-model="company" clearable placeholder="请输入公司名称" @change="handleInputQuery" />
  159. </div>
  160. </el-col>
  161. </el-row>
  162. </template>
  163. <template #platformNumber="{ row }">
  164. <el-button link style="font-weight: 700" type="primary" @click="handleNavigate(row)">
  165. <el-icon>
  166. <Link />
  167. </el-icon>
  168. {{ row.platformNumber ? row.platformNumber : '--' }}
  169. </el-button>
  170. </template>
  171. <template #pager>
  172. <vxe-pager
  173. v-model:currentPage="gridOptions.pagerConfig.page"
  174. v-model:pageSize="gridOptions.pagerConfig.limit"
  175. :total="gridOptions.pagerConfig.total"
  176. class="mt-1.5"
  177. @page-change="handlePageChange"
  178. />
  179. </template>
  180. </vxe-grid>
  181. </template>
  182. <style scoped>
  183. </style>