DataTable.vue 7.8 KB

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