index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. <template>
  2. <div class="p-2">
  3. <!-- 搜索区域 -->
  4. <transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
  5. <div v-show="showSearch" class="mb-[10px]">
  6. <el-card shadow="hover">
  7. <el-form ref="queryFormRef" :model="queryParams" label-width="80px">
  8. <el-row :gutter="10">
  9. <el-col :span="6">
  10. <el-form-item label="站点名称" prop="siteName">
  11. <el-input v-model="queryParams.siteName" placeholder="请输入站点名称" clearable style="width: 100%" @keyup.enter="handleQuery" />
  12. </el-form-item>
  13. </el-col>
  14. <el-col :span="6">
  15. <el-form-item label="客户名称" prop="clientId">
  16. <el-select
  17. v-model="queryParams.clientId"
  18. filterable
  19. remote
  20. reserve-keyword
  21. :remote-method="searchQueryCustomer"
  22. :loading="queryCustomerLoading"
  23. placeholder="请选择客户"
  24. clearable
  25. style="width: 100%"
  26. @focus="handleQueryCustomerFocus"
  27. >
  28. <el-option v-for="item in queryCustomerList" :key="item.id" :label="`${item.customerNo} ${item.customerName}`" :value="item.id" />
  29. </el-select>
  30. </el-form-item>
  31. </el-col>
  32. <el-col :span="6">
  33. <el-form-item label="状态" prop="status">
  34. <el-select v-model="queryParams.status" placeholder="请选择" clearable style="width: 100%">
  35. <el-option label="启用" value="0" />
  36. <el-option label="禁用" value="1" />
  37. </el-select>
  38. </el-form-item>
  39. </el-col>
  40. <el-col :span="6">
  41. <el-form-item label="发布时间" prop="startTimeRange">
  42. <el-date-picker
  43. v-model="queryParams.startTimeRange"
  44. type="daterange"
  45. range-separator="至"
  46. start-placeholder="开始时间"
  47. end-placeholder="结束时间"
  48. value-format="YYYY-MM-DD"
  49. style="width: 100%"
  50. />
  51. </el-form-item>
  52. </el-col>
  53. <el-col :span="6">
  54. <el-form-item label="截止时间" prop="endTimeRange">
  55. <el-date-picker
  56. v-model="queryParams.endTimeRange"
  57. type="daterange"
  58. range-separator="至"
  59. start-placeholder="开始时间"
  60. end-placeholder="结束时间"
  61. value-format="YYYY-MM-DD"
  62. style="width: 100%"
  63. />
  64. </el-form-item>
  65. </el-col>
  66. <el-col :span="18">
  67. <el-form-item>
  68. <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
  69. <el-button icon="Refresh" @click="resetQuery">重置</el-button>
  70. <el-button type="primary" icon="Plus" @click="handleAdd">新增</el-button>
  71. </el-form-item>
  72. </el-col>
  73. </el-row>
  74. </el-form>
  75. </el-card>
  76. </div>
  77. </transition>
  78. <!-- 表格区域 -->
  79. <el-card shadow="never">
  80. <template #header>
  81. <div class="flex justify-between items-center">
  82. <span class="font-bold text-[#409EFF]">大客户专属站点信息列表</span>
  83. <right-toolbar v-model:showSearch="showSearch" @queryTable="getList" />
  84. </div>
  85. </template>
  86. <el-table v-loading="loading" border :data="siteList">
  87. <el-table-column label="客户编号" align="center" prop="clientNo" width="100" />
  88. <el-table-column label="客户名称" align="center" prop="clientName" min-width="100" />
  89. <el-table-column label="站点名称" align="center" prop="siteName" min-width="180" />
  90. <el-table-column label="站点域名" align="center" prop="siteDomain" min-width="220">
  91. <template #default="scope">
  92. <el-link type="primary" :href="scope.row.siteDomain" target="_blank">{{ scope.row.siteDomain }}</el-link>
  93. </template>
  94. </el-table-column>
  95. <el-table-column label="状态" align="center" width="80">
  96. <template #default="scope">
  97. <el-tag :type="scope.row.status === '0' ? 'success' : 'info'" size="small">
  98. {{ scope.row.status === '0' ? '启用' : '禁用' }}
  99. </el-tag>
  100. </template>
  101. </el-table-column>
  102. <el-table-column label="开始时间" align="center" prop="startTime" width="120">
  103. <template #default="scope">
  104. <span>{{ parseTime(scope.row.startTime, '{y}-{m}-{d}') }}</span>
  105. </template>
  106. </el-table-column>
  107. <el-table-column label="结束时间" align="center" prop="endTime" width="120">
  108. <template #default="scope">
  109. <span>{{ parseTime(scope.row.endTime, '{y}-{m}-{d}') }}</span>
  110. </template>
  111. </el-table-column>
  112. <el-table-column label="操作" align="center" width="200" fixed="right">
  113. <template #default="scope">
  114. <div class="flex flex-col items-center gap-1">
  115. <el-link type="primary" :underline="false" @click="handleSiteConfig(scope.row)">站点配置</el-link>
  116. <el-link type="primary" :underline="false" @click="handleProductConfig(scope.row)">商品配置</el-link>
  117. <el-link type="primary" :underline="false" @click="handleStyleDesign(scope.row)">样式设计</el-link>
  118. <el-link type="primary" :underline="false" @click="handleDiy(scope.row)">diy设计</el-link>
  119. <el-link :type="scope.row.status === '0' ? 'danger' : 'success'" :underline="false" @click="handleStatusChange(scope.row)">
  120. {{ scope.row.status === '0' ? '停 用' : '启 用' }}
  121. </el-link>
  122. </div>
  123. </template>
  124. </el-table-column>
  125. </el-table>
  126. <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" />
  127. </el-card>
  128. </div>
  129. </template>
  130. <script setup name="VipSite" lang="ts">
  131. import { listSite, getSite, delSite, addSite, updateSite } from '@/api/product/site';
  132. import { SiteVO, SiteQuery } from '@/api/product/site/types';
  133. import { getCustomerList, getCustomerInfo } from '@/api/customerOperation/customerList';
  134. import { useRouter } from 'vue-router';
  135. const { proxy } = getCurrentInstance() as ComponentInternalInstance;
  136. const router = useRouter();
  137. const siteList = ref<SiteVO[]>([]);
  138. const loading = ref(true);
  139. const showSearch = ref(true);
  140. const total = ref(0);
  141. const queryFormRef = ref<ElFormInstance>();
  142. // 搜索框客户下拉数据
  143. const queryCustomerList = ref<any[]>([]);
  144. const queryCustomerLoading = ref(false);
  145. // 搜索框客户远程搜索
  146. const searchQueryCustomer = async (query: string) => {
  147. queryCustomerLoading.value = true;
  148. try {
  149. const params: any = { pageSize: 20, pageNum: 1 };
  150. if (query) params.clientName = query;
  151. const res = await getCustomerList(params);
  152. queryCustomerList.value = res.rows || [];
  153. } catch (error) {
  154. queryCustomerList.value = [];
  155. } finally {
  156. queryCustomerLoading.value = false;
  157. }
  158. };
  159. // 搜索框客户聚焦时加载
  160. const handleQueryCustomerFocus = () => {
  161. if (queryCustomerList.value.length === 0) {
  162. searchQueryCustomer('');
  163. }
  164. };
  165. // 查询参数
  166. const queryParams = ref<SiteQuery & { startTimeRange?: string[]; endTimeRange?: string[] }>({
  167. pageNum: 1,
  168. pageSize: 10,
  169. siteName: undefined,
  170. clientId: undefined,
  171. status: undefined,
  172. startTimeRange: undefined,
  173. endTimeRange: undefined,
  174. params: {}
  175. });
  176. /** 通过客户接口回显列表中的客户编号和名称 */
  177. const enrichListWithCustomerInfo = async () => {
  178. const uniqueClientIds = [...new Set(siteList.value.map((item) => item.clientId).filter(Boolean))];
  179. if (uniqueClientIds.length === 0) return;
  180. const customerMap = new Map<string, any>();
  181. await Promise.all(
  182. uniqueClientIds.map(async (clientId) => {
  183. try {
  184. const res = await getCustomerInfo(clientId as string | number);
  185. if (res.data) {
  186. customerMap.set(String(clientId), res.data);
  187. }
  188. } catch {}
  189. })
  190. );
  191. siteList.value = siteList.value.map((item) => {
  192. const customer = customerMap.get(String(item.clientId));
  193. if (customer) {
  194. return { ...item, clientNo: customer.customerNo || item.clientNo, clientName: customer.customerName || item.clientName };
  195. }
  196. return item;
  197. });
  198. };
  199. /** 查询客户站点配置列表 */
  200. const getList = async () => {
  201. loading.value = true;
  202. try {
  203. // 处理日期范围参数
  204. const params: any = { ...queryParams.value };
  205. if (queryParams.value.startTimeRange && queryParams.value.startTimeRange.length === 2) {
  206. params.params = {
  207. ...params.params,
  208. beginStartTime: queryParams.value.startTimeRange[0],
  209. endStartTime: queryParams.value.startTimeRange[1]
  210. };
  211. }
  212. if (queryParams.value.endTimeRange && queryParams.value.endTimeRange.length === 2) {
  213. params.params = {
  214. ...params.params,
  215. beginEndTime: queryParams.value.endTimeRange[0],
  216. endEndTime: queryParams.value.endTimeRange[1]
  217. };
  218. }
  219. delete params.startTimeRange;
  220. delete params.endTimeRange;
  221. const res = await listSite(params);
  222. siteList.value = res.rows;
  223. total.value = res.total;
  224. await enrichListWithCustomerInfo();
  225. } catch (error) {
  226. console.error('获取站点列表失败:', error);
  227. } finally {
  228. loading.value = false;
  229. }
  230. };
  231. /** 搜索按钮操作 */
  232. const handleQuery = () => {
  233. queryParams.value.pageNum = 1;
  234. getList();
  235. };
  236. /** 重置按钮操作 */
  237. const resetQuery = () => {
  238. queryFormRef.value?.resetFields();
  239. queryParams.value = {
  240. pageNum: 1,
  241. pageSize: 10,
  242. siteName: undefined,
  243. clientId: undefined,
  244. status: undefined,
  245. startTimeRange: undefined,
  246. endTimeRange: undefined,
  247. params: {}
  248. };
  249. handleQuery();
  250. };
  251. /** 新增按钮操作 */
  252. const handleAdd = () => {
  253. router.push('/customerOperation/vipSite/siteConfig');
  254. };
  255. /** 站点配置 */
  256. const handleSiteConfig = (row: SiteVO) => {
  257. router.push({
  258. path: '/customerOperation/vipSite/siteConfig',
  259. query: { id: row.id }
  260. });
  261. };
  262. /** 商品配置 */
  263. const handleProductConfig = (row: SiteVO) => {
  264. router.push({
  265. path: '/customerOperation/vipSite/productConfig',
  266. query: { siteId: row.id, siteName: row.siteName, clientNo: row.clientNo, clientName: row.clientName }
  267. });
  268. };
  269. /** 样式设计 */
  270. const handleStyleDesign = (row: SiteVO) => {
  271. router.push({
  272. path: '/customerOperation/vipSite/styleDesign',
  273. query: { siteId: row.id, siteName: row.siteName }
  274. });
  275. };
  276. const handleDiy = (row: any) => {
  277. router.push({
  278. path: '/customerOperation/pcList',
  279. query: { id: row.id, clientId: row.clientId }
  280. });
  281. };
  282. /** 状态切换 */
  283. const handleStatusChange = async (row: SiteVO) => {
  284. const newStatus = row.status === '0' ? '1' : '0';
  285. const text = newStatus === '0' ? '启用' : '停用';
  286. try {
  287. await proxy?.$modal.confirm(`确认要"${text}"站点"${row.siteName}"吗?`);
  288. await updateSite({ id: row.id, status: newStatus });
  289. proxy?.$modal.msgSuccess(`${text}成功`);
  290. await getList();
  291. } catch (error) {
  292. // 用户取消操作
  293. }
  294. };
  295. onMounted(() => {
  296. getList();
  297. });
  298. </script>