index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  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" width="80">
  91. <template #default="scope">
  92. <el-tag :type="scope.row.status === '0' ? 'success' : 'info'" size="small">
  93. {{ scope.row.status === '0' ? '启用' : '禁用' }}
  94. </el-tag>
  95. </template>
  96. </el-table-column>
  97. <el-table-column label="开始时间" align="center" prop="startTime" width="120">
  98. <template #default="scope">
  99. <span>{{ parseTime(scope.row.startTime, '{y}-{m}-{d}') }}</span>
  100. </template>
  101. </el-table-column>
  102. <el-table-column label="结束时间" align="center" prop="endTime" width="120">
  103. <template #default="scope">
  104. <span>{{ parseTime(scope.row.endTime, '{y}-{m}-{d}') }}</span>
  105. </template>
  106. </el-table-column>
  107. <el-table-column label="操作" align="center" width="200" fixed="right">
  108. <template #default="scope">
  109. <div class="flex flex-col items-center gap-1">
  110. <el-link type="primary" :underline="false" @click="handleSiteConfig(scope.row)">站点配置</el-link>
  111. <!-- <el-link type="primary" :underline="false" @click="handleProductConfig(scope.row)">商品配置</el-link>
  112. <el-link type="primary" :underline="false" @click="handleStyleDesign(scope.row)">样式设计</el-link> -->
  113. <el-link type="primary" :underline="false" @click="handleDiy(scope.row)">diy设计</el-link>
  114. <el-link :type="scope.row.status === '0' ? 'danger' : 'success'" :underline="false" @click="handleStatusChange(scope.row)">
  115. {{ scope.row.status === '0' ? '停 用' : '启 用' }}
  116. </el-link>
  117. </div>
  118. </template>
  119. </el-table-column>
  120. </el-table>
  121. <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" />
  122. </el-card>
  123. </div>
  124. </template>
  125. <script setup name="VipSite" lang="ts">
  126. import { listSite, getSite, delSite, addSite, updateSite } from '@/api/product/site';
  127. import { SiteVO, SiteQuery } from '@/api/product/site/types';
  128. import { getCustomerList, getCustomerInfo } from '@/api/customerOperation/customerList';
  129. import { useRouter } from 'vue-router';
  130. const { proxy } = getCurrentInstance() as ComponentInternalInstance;
  131. const router = useRouter();
  132. const siteList = ref<SiteVO[]>([]);
  133. const loading = ref(true);
  134. const showSearch = ref(true);
  135. const total = ref(0);
  136. const queryFormRef = ref<ElFormInstance>();
  137. // 搜索框客户下拉数据
  138. const queryCustomerList = ref<any[]>([]);
  139. const queryCustomerLoading = ref(false);
  140. // 搜索框客户远程搜索
  141. const searchQueryCustomer = async (query: string) => {
  142. queryCustomerLoading.value = true;
  143. try {
  144. const params: any = { pageSize: 20, pageNum: 1 };
  145. if (query) params.clientName = query;
  146. const res = await getCustomerList(params);
  147. queryCustomerList.value = res.rows || [];
  148. } catch (error) {
  149. queryCustomerList.value = [];
  150. } finally {
  151. queryCustomerLoading.value = false;
  152. }
  153. };
  154. // 搜索框客户聚焦时加载
  155. const handleQueryCustomerFocus = () => {
  156. if (queryCustomerList.value.length === 0) {
  157. searchQueryCustomer('');
  158. }
  159. };
  160. // 查询参数
  161. const queryParams = ref<SiteQuery & { startTimeRange?: string[]; endTimeRange?: string[] }>({
  162. pageNum: 1,
  163. pageSize: 10,
  164. siteName: undefined,
  165. clientId: undefined,
  166. status: undefined,
  167. startTimeRange: undefined,
  168. endTimeRange: undefined,
  169. params: {}
  170. });
  171. /** 通过客户接口回显列表中的客户编号和名称 */
  172. const enrichListWithCustomerInfo = async () => {
  173. const uniqueClientIds = [...new Set(siteList.value.map((item) => item.clientId).filter(Boolean))];
  174. if (uniqueClientIds.length === 0) return;
  175. const customerMap = new Map<string, any>();
  176. await Promise.all(
  177. uniqueClientIds.map(async (clientId) => {
  178. try {
  179. const res = await getCustomerInfo(clientId as string | number);
  180. if (res.data) {
  181. customerMap.set(String(clientId), res.data);
  182. }
  183. } catch {}
  184. })
  185. );
  186. siteList.value = siteList.value.map((item) => {
  187. const customer = customerMap.get(String(item.clientId));
  188. if (customer) {
  189. return { ...item, clientNo: customer.customerNo || item.clientNo, clientName: customer.customerName || item.clientName };
  190. }
  191. return item;
  192. });
  193. };
  194. /** 查询客户站点配置列表 */
  195. const getList = async () => {
  196. loading.value = true;
  197. try {
  198. // 处理日期范围参数
  199. const params: any = { ...queryParams.value };
  200. if (queryParams.value.startTimeRange && queryParams.value.startTimeRange.length === 2) {
  201. params.params = {
  202. ...params.params,
  203. beginStartTime: queryParams.value.startTimeRange[0],
  204. endStartTime: queryParams.value.startTimeRange[1]
  205. };
  206. }
  207. if (queryParams.value.endTimeRange && queryParams.value.endTimeRange.length === 2) {
  208. params.params = {
  209. ...params.params,
  210. beginEndTime: queryParams.value.endTimeRange[0],
  211. endEndTime: queryParams.value.endTimeRange[1]
  212. };
  213. }
  214. delete params.startTimeRange;
  215. delete params.endTimeRange;
  216. const res = await listSite(params);
  217. siteList.value = res.rows;
  218. total.value = res.total;
  219. await enrichListWithCustomerInfo();
  220. } catch (error) {
  221. console.error('获取站点列表失败:', error);
  222. } finally {
  223. loading.value = false;
  224. }
  225. };
  226. /** 搜索按钮操作 */
  227. const handleQuery = () => {
  228. queryParams.value.pageNum = 1;
  229. getList();
  230. };
  231. /** 重置按钮操作 */
  232. const resetQuery = () => {
  233. queryFormRef.value?.resetFields();
  234. queryParams.value = {
  235. pageNum: 1,
  236. pageSize: 10,
  237. siteName: undefined,
  238. clientId: undefined,
  239. status: undefined,
  240. startTimeRange: undefined,
  241. endTimeRange: undefined,
  242. params: {}
  243. };
  244. handleQuery();
  245. };
  246. /** 新增按钮操作 */
  247. const handleAdd = () => {
  248. router.push('/customerOperation/vipSite/siteConfig');
  249. };
  250. /** 站点配置 */
  251. const handleSiteConfig = (row: SiteVO) => {
  252. router.push({
  253. path: '/customerOperation/vipSite/siteConfig',
  254. query: { id: row.id }
  255. });
  256. };
  257. /** 商品配置 */
  258. const handleProductConfig = (row: SiteVO) => {
  259. router.push({
  260. path: '/customerOperation/vipSite/productConfig',
  261. query: { siteId: row.id, siteName: row.siteName, clientNo: row.clientNo, clientName: row.clientName }
  262. });
  263. };
  264. /** 样式设计 */
  265. const handleStyleDesign = (row: SiteVO) => {
  266. router.push({
  267. path: '/customerOperation/vipSite/styleDesign',
  268. query: { siteId: row.id, siteName: row.siteName }
  269. });
  270. };
  271. const handleDiy = (row: any) => {
  272. router.push({
  273. path: '/customerOperation/pcList',
  274. query: { id: row.id, clientId: row.clientId }
  275. });
  276. };
  277. /** 状态切换 */
  278. const handleStatusChange = async (row: SiteVO) => {
  279. const newStatus = row.status === '0' ? '1' : '0';
  280. const text = newStatus === '0' ? '启用' : '停用';
  281. try {
  282. await proxy?.$modal.confirm(`确认要"${text}"站点"${row.siteName}"吗?`);
  283. await updateSite({ id: row.id, status: newStatus });
  284. proxy?.$modal.msgSuccess(`${text}成功`);
  285. await getList();
  286. } catch (error) {
  287. // 用户取消操作
  288. }
  289. };
  290. onMounted(() => {
  291. getList();
  292. });
  293. </script>