DataTable.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. <script lang="ts" setup>
  2. /**
  3. * @Name: Table.vue
  4. * @Description: 竞品监控表格
  5. * @Author: Cheney
  6. */
  7. import { Download, InfoFilled, Plus, Refresh, RefreshRight, Search } 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 { CompetitorMonitorCommentColumns } from '/@/views/product-manage/Columns';
  12. import DataTableSlot from './DataTableSlot.vue';
  13. import PermissionButton from '/src/components/PermissionButton/index.vue';
  14. import VerticalDivider from '/src/components/VerticalDivider/index.vue';
  15. import * as api from '../api';
  16. import CreateDialog from '/@/views/product-manage/comment-detail/component/CreateDialog.vue';
  17. import { DictionaryStore } from '/@/stores/dictionary';
  18. import { useScoreEnum, useTivEnum } from '/@/views/product-manage/comment-detail/enum';
  19. import NegativeLabel from '/@/views/product-manage/comment-detail/component/NegativeLabel.vue';
  20. const { data: staticData } = DictionaryStore();
  21. const btnLoading = ref(false);
  22. const formInline = reactive<any>({
  23. country: '',
  24. score: '',
  25. tiv: ''
  26. });
  27. const props = defineProps({
  28. asin: String
  29. });
  30. const { asin } = props;
  31. const { tableOptions, handlePageChange } = usePagination(fetchList);
  32. const gridRef = ref();
  33. const gridOptions: any = reactive({
  34. // id: 'competitor-monitor-comment',
  35. // keepSource: true,
  36. size: 'mini',
  37. border: false,
  38. round: true,
  39. stripe: true,
  40. showHeader: true,
  41. currentRowHighLight: true,
  42. height: 650,
  43. // customConfig: {
  44. // storage: {
  45. // visible: true,
  46. // resizable:false,
  47. // }
  48. // },
  49. toolbarConfig: {
  50. size: 'large',
  51. // custom: true,
  52. slots: {
  53. buttons: 'toolbar_buttons',
  54. tools: 'toolbar_tools'
  55. }
  56. },
  57. rowConfig: {
  58. isHover: true
  59. },
  60. columnConfig: {
  61. // resizable: true
  62. },
  63. pagerConfig: {
  64. total: tableOptions.value.total,
  65. page: tableOptions.value.page,
  66. limit: tableOptions.value.limit
  67. },
  68. loading: false,
  69. loadingConfig: {
  70. icon: 'vxe-icon-indicator roll',
  71. text: '正在拼命加载中...'
  72. },
  73. columns: '',
  74. data: ''
  75. });
  76. const createOpen = ref(false);
  77. const rowData = ref<any>({});
  78. const isShowLabel = ref(false);
  79. onMounted(() => {
  80. fetchList();
  81. });
  82. // TODO: 删除goods
  83. async function fetchList() {
  84. gridOptions.data = [];
  85. gridOptions.columns = [];
  86. const query = {
  87. asin: asin,
  88. country_code: formInline?.country,
  89. score: formInline?.score,
  90. tiv: formInline?.tiv
  91. };
  92. await useTableData(api.getTableData, query, gridOptions);
  93. await gridRef.value.loadColumn(CompetitorMonitorCommentColumns);
  94. // gridOptions.showHeader = Boolean(gridOptions.data?.length);
  95. }
  96. function handleRefresh() {
  97. fetchList();
  98. }
  99. async function handleDownload() {
  100. gridOptions.loading = true;
  101. try {
  102. const query = {
  103. asin: asin,
  104. country_code: formInline?.country,
  105. score: formInline?.score,
  106. tiv: formInline?.tiv
  107. };
  108. const response = await api.exportData(query);
  109. const url = window.URL.createObjectURL(new Blob([ response.data ]));
  110. const link = document.createElement('a');
  111. link.href = url;
  112. link.setAttribute('download', '评论详情数据.xlsx');
  113. document.body.appendChild(link);
  114. link.click();
  115. ElMessage.success('数据导出成功!');
  116. } catch (error) {
  117. ElMessage.error('数据导出失败,请重试!');
  118. console.error(error);
  119. } finally {
  120. gridOptions.loading = false;
  121. }
  122. }
  123. function handleCreate() {
  124. createOpen.value = true;
  125. }
  126. function showLabel(row: any) {
  127. isShowLabel.value = true;
  128. rowData.value = row;
  129. }
  130. async function handleQuery() {
  131. btnLoading.value = true;
  132. await fetchList();
  133. btnLoading.value = false;
  134. }
  135. function resetParameter() {
  136. for (const key in formInline) {
  137. formInline[key] = '';
  138. }
  139. }
  140. defineExpose({ fetchList });
  141. </script>
  142. <template>
  143. <!--查询条件-->
  144. <div ref="queryContainer" class="flex justify-between">
  145. <div class="flex flex-1">
  146. <div class="w-full whitespace-nowrap">
  147. <el-row :gutter="20" style="margin-bottom: 5px;">
  148. <el-col :span="6">
  149. <div class="flex items-center">
  150. <span class="mr-2">国 家</span>
  151. <el-select v-model="formInline.country" clearable placeholder="请选择国家">
  152. <el-option v-for="item in staticData.country_code" :key="item.value" :label="item.label"
  153. :value="item.value" />
  154. </el-select>
  155. </div>
  156. </el-col>
  157. <el-col :span="6">
  158. <div class="flex items-center">
  159. <span class="mr-2">用户评分</span>
  160. <el-select v-model="formInline.score" clearable placeholder="请选择用户评分">
  161. <el-option v-for="item in useScoreEnum" :key="item.value" :label="item.label"
  162. :value="item.value" />
  163. </el-select>
  164. </div>
  165. </el-col>
  166. <el-col :span="6">
  167. <div class="flex items-center">
  168. <span class="mr-2">评论类型</span>
  169. <el-select v-model="formInline.tiv" clearable placeholder="请选择评论类型">
  170. <el-option v-for="item in useTivEnum" :key="item.value" :label="item.label"
  171. :value="item.value" />
  172. </el-select>
  173. </div>
  174. </el-col>
  175. </el-row>
  176. </div>
  177. </div>
  178. <div class="flex gap-1.5 ml-5">
  179. <el-button :icon="Search" :loading="btnLoading" type="primary" @click="handleQuery">
  180. 查 询
  181. </el-button>
  182. <el-button :icon="RefreshRight" color="#ECECF1C9" style="width: 88px; color: #3c3c3c;" @click="resetParameter">
  183. 重 置
  184. </el-button>
  185. </div>
  186. </div>
  187. <el-divider ref="dividerContainer" style="margin: 20px 0 12px 0;" />
  188. <vxe-grid ref="gridRef" class="z-0" v-bind="gridOptions">
  189. <template #toolbar_buttons>
  190. <div class="flex gap-2">
  191. <PermissionButton :icon="Plus" plain round type="primary" @click="handleCreate">
  192. 新 增
  193. </PermissionButton>
  194. <VerticalDivider class="px-1" style="margin-left: 7px;" />
  195. </div>
  196. </template>
  197. <template #toolbar_tools>
  198. <el-button circle class="toolbar-btn" @click="handleRefresh">
  199. <el-icon>
  200. <Refresh />
  201. </el-icon>
  202. </el-button>
  203. <el-popconfirm
  204. :icon="InfoFilled"
  205. icon-color="#626AEF"
  206. title="是否确认导出所有数据项?"
  207. width="220"
  208. @confirm="handleDownload"
  209. >
  210. <template #reference>
  211. <el-button circle class="mr-3 toolbar-btn">
  212. <el-icon>
  213. <Download />
  214. </el-icon>
  215. </el-button>
  216. </template>
  217. <template #actions="{ confirm, cancel }">
  218. <el-button size="small" @click="cancel">No!</el-button>
  219. <el-button size="small" type="danger" @click="confirm">
  220. Yes?
  221. </el-button>
  222. </template>
  223. </el-popconfirm>
  224. </template>
  225. <template #top>
  226. <div class="mb-2"></div>
  227. </template>
  228. <template #pager>
  229. <vxe-pager
  230. v-model:currentPage="gridOptions.pagerConfig.page"
  231. v-model:pageSize="gridOptions.pagerConfig.limit"
  232. :total="gridOptions.pagerConfig.total"
  233. class="mt-1.5"
  234. @page-change="handlePageChange"
  235. />
  236. </template>
  237. <!-- 自定义列插槽 -->
  238. <template v-for="col in CompetitorMonitorCommentColumns" #[`${col.field}`]="{ row }">
  239. <DataTableSlot :key="row.id" :field="col.field" :row="row" @open-negativeLabel="showLabel" />
  240. </template>
  241. </vxe-grid>
  242. <CreateDialog v-if="createOpen" v-model="createOpen" @refresh="fetchList" />
  243. <NegativeLabel v-if="isShowLabel" v-model="isShowLabel" :rowData="rowData" />
  244. </template>
  245. <style scoped>
  246. .toolbar-btn {
  247. width: 34px;
  248. height: 34px;
  249. font-size: 18px
  250. }
  251. :deep(.custom-el-input .el-select__wrapper) {
  252. border-radius: 20px;
  253. }
  254. </style>