index.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. <template>
  2. <div class="page-container">
  3. <header class="page-header">
  4. <h1 class="main-title">商品渠道透视</h1>
  5. <p class="subtitle">分析商品在不同销售渠道的覆盖广度</p>
  6. </header>
  7. <div class="chart-card">
  8. <h3 class="chart-title">商品渠道覆盖 Top 20 趋势</h3>
  9. <OrderLoadingPanel
  10. v-if="loading"
  11. title="正在加载商品渠道数据"
  12. detail="正在读取商品在各销售渠道的覆盖情况"
  13. />
  14. <div ref="channelChartRef" style="width: 100%; height: 500px;"></div>
  15. </div>
  16. <div class="table-card">
  17. <OrderLoadingPanel
  18. v-if="loading"
  19. title="正在加载渠道明细"
  20. detail="正在生成商品覆盖平台排名"
  21. />
  22. <div class="table-header">
  23. <h3 class="chart-title">商品渠道覆盖明细</h3>
  24. <div class="search-box">
  25. <el-input
  26. v-model.trim="skuKeyword"
  27. clearable
  28. placeholder="输入 SKU 搜索"
  29. @keyup.enter.native="applySkuSearch"
  30. @clear="applySkuSearch"
  31. >
  32. <el-button slot="append" icon="el-icon-search" @click="applySkuSearch" />
  33. </el-input>
  34. </div>
  35. </div>
  36. <table class="data-table">
  37. <thead>
  38. <tr>
  39. <th>排名</th>
  40. <th>商品编码</th>
  41. <th>覆盖平台数</th>
  42. </tr>
  43. </thead>
  44. <tbody>
  45. <tr v-for="(item, index) in paginatedData" :key="item.productCode">
  46. <td>{{ (currentPage - 1) * itemsPerPage + index + 1 }}</td>
  47. <td>{{ item.productCode }}</td>
  48. <td>{{ item.platformCount }}</td>
  49. </tr>
  50. <tr v-if="loading">
  51. <td colspan="3">正在加载数据...</td>
  52. </tr>
  53. <tr v-else-if="!paginatedData.length">
  54. <td colspan="3">没有找到符合条件的数据</td>
  55. </tr>
  56. </tbody>
  57. </table>
  58. <div class="pagination-controls">
  59. <button @click="prevPage" :disabled="currentPage === 1">上一页</button>
  60. <span>第 {{ currentPage }} / {{ totalPages }} 页</span>
  61. <button @click="nextPage" :disabled="currentPage === totalPages">下一页</button>
  62. </div>
  63. </div>
  64. </div>
  65. </template>
  66. <script>
  67. import * as echarts from 'echarts'
  68. import OrderLoadingPanel from '../components/OrderLoadingPanel.vue'
  69. import { getShopCrossSellingProducts } from '@/api/order'
  70. export default {
  71. name: 'OrderChannel',
  72. components: {
  73. OrderLoadingPanel
  74. },
  75. data() {
  76. return {
  77. allProducts: [],
  78. currentPage: 1,
  79. itemsPerPage: 10,
  80. skuKeyword: '',
  81. loading: true,
  82. chartInstance: null
  83. }
  84. },
  85. computed: {
  86. paginatedData() {
  87. const start = (this.currentPage - 1) * this.itemsPerPage
  88. return this.allProducts.slice(start, start + this.itemsPerPage)
  89. },
  90. totalPages() {
  91. return Math.max(1, Math.ceil(this.allProducts.length / this.itemsPerPage))
  92. }
  93. },
  94. mounted() {
  95. this.fetchData()
  96. window.addEventListener('resize', this.handleResize)
  97. },
  98. beforeDestroy() {
  99. window.removeEventListener('resize', this.handleResize)
  100. this.chartInstance?.dispose()
  101. },
  102. methods: {
  103. handleResize() {
  104. this.chartInstance?.resize()
  105. },
  106. applySkuSearch() {
  107. this.currentPage = 1
  108. this.fetchData()
  109. },
  110. initLineChart() {
  111. const chartEl = this.$refs.channelChartRef
  112. if (!chartEl) return
  113. if (this.chartInstance) {
  114. this.chartInstance.dispose()
  115. }
  116. this.chartInstance = echarts.init(chartEl)
  117. const top20Data = this.allProducts.slice(0, 20)
  118. this.chartInstance.setOption({
  119. tooltip: { trigger: 'axis' },
  120. grid: { left: '3%', right: '4%', bottom: '3%', containLabel: true },
  121. xAxis: {
  122. type: 'category',
  123. boundaryGap: false,
  124. data: top20Data.map(item => item.productCode),
  125. axisLabel: { interval: 0, rotate: 30 }
  126. },
  127. yAxis: {
  128. type: 'value',
  129. name: '覆盖平台数'
  130. },
  131. series: [{
  132. name: '覆盖平台数',
  133. type: 'line',
  134. smooth: true,
  135. data: top20Data.map(item => item.platformCount),
  136. itemStyle: { color: '#5470C6' },
  137. areaStyle: {
  138. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  139. { offset: 0, color: 'rgba(84, 112, 198, 0.5)' },
  140. { offset: 1, color: 'rgba(84, 112, 198, 0)' }
  141. ])
  142. }
  143. }]
  144. }, true)
  145. },
  146. async fetchData() {
  147. this.loading = true
  148. try {
  149. const response = await getShopCrossSellingProducts({
  150. skuKeyword: this.skuKeyword || undefined
  151. })
  152. if (response?.success) {
  153. this.allProducts = response.data || []
  154. this.initLineChart()
  155. return
  156. }
  157. this.allProducts = []
  158. this.initLineChart()
  159. } catch (error) {
  160. console.error('获取商品渠道数据失败:', error)
  161. this.allProducts = []
  162. this.initLineChart()
  163. } finally {
  164. this.loading = false
  165. }
  166. },
  167. nextPage() {
  168. if (this.currentPage < this.totalPages) {
  169. this.currentPage += 1
  170. }
  171. },
  172. prevPage() {
  173. if (this.currentPage > 1) {
  174. this.currentPage -= 1
  175. }
  176. }
  177. }
  178. }
  179. </script>
  180. <style scoped>
  181. .page-container {
  182. padding: 20px;
  183. display: flex;
  184. flex-direction: column;
  185. gap: 20px;
  186. background-color: #f0f2f5;
  187. }
  188. .page-header {
  189. margin-bottom: 10px;
  190. }
  191. .main-title {
  192. font-size: 24px;
  193. font-weight: 600;
  194. color: #333;
  195. }
  196. .subtitle {
  197. font-size: 14px;
  198. color: #999;
  199. }
  200. .chart-card,
  201. .table-card {
  202. position: relative;
  203. background-color: #fff;
  204. padding: 20px;
  205. border-radius: 8px;
  206. box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  207. }
  208. .table-header {
  209. display: flex;
  210. justify-content: space-between;
  211. align-items: center;
  212. gap: 16px;
  213. margin-bottom: 20px;
  214. }
  215. .search-box {
  216. width: 280px;
  217. }
  218. .chart-title {
  219. font-size: 18px;
  220. color: #333;
  221. }
  222. .data-table {
  223. width: 100%;
  224. border-collapse: collapse;
  225. }
  226. .data-table th,
  227. .data-table td {
  228. padding: 12px 15px;
  229. border: 1px solid #e0e0e0;
  230. text-align: left;
  231. }
  232. .data-table th {
  233. background-color: #f7f7f7;
  234. font-weight: 600;
  235. }
  236. .pagination-controls {
  237. margin-top: 20px;
  238. display: flex;
  239. justify-content: flex-end;
  240. align-items: center;
  241. gap: 15px;
  242. }
  243. .pagination-controls button {
  244. padding: 8px 12px;
  245. border: 1px solid #ccc;
  246. background-color: #fff;
  247. border-radius: 4px;
  248. cursor: pointer;
  249. transition: all 0.2s;
  250. }
  251. .pagination-controls button:hover:not(:disabled) {
  252. border-color: #5470C6;
  253. color: #5470C6;
  254. }
  255. .pagination-controls button:disabled {
  256. cursor: not-allowed;
  257. opacity: 0.5;
  258. }
  259. </style>