vip-table.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  1. <template>
  2. <div class="vip-page">
  3. <div class="page-inner">
  4. <div class="page-title">患者身份等级管理</div>
  5. <!-- 搜索模块 -->
  6. <div class="card search-card">
  7. <div class="search-fields">
  8. <zy-form inline class="fw search-form">
  9. <zy-form-item label="权益名称:">
  10. <zy-input
  11. v-model="queryData.benefitName"
  12. placeholder="请输入权益名称"
  13. clearable
  14. />
  15. </zy-form-item>
  16. <zy-form-item label="当前状态:">
  17. <zy-select
  18. v-model="queryData.status"
  19. placeholder="全部"
  20. clearable
  21. >
  22. <zy-option
  23. v-for="item in statusOptions"
  24. :key="item.value"
  25. :label="item.label"
  26. :value="item.value"
  27. />
  28. </zy-select>
  29. </zy-form-item>
  30. </zy-form>
  31. <div class="search-actions">
  32. <zy-button class="btn-search" type="primary" @click="getTableData()">
  33. 查询
  34. </zy-button>
  35. <zy-button class="btn-create" @click="handleCreate">
  36. + 新建服务权益包
  37. </zy-button>
  38. </div>
  39. </div>
  40. </div>
  41. <!-- 表格模块 -->
  42. <div class="card table-card" v-loading="table.loading">
  43. <zy-table
  44. height="100%"
  45. :data="table.data"
  46. header-align="center"
  47. align="center"
  48. :border="true"
  49. :fit="true"
  50. >
  51. <zy-table-column
  52. prop="levelCode"
  53. label="身份等级编号"
  54. />
  55. <zy-table-column
  56. prop="levelIconLabel"
  57. label="身份等级图标"
  58. >
  59. <template #default="{ row }">
  60. <img
  61. v-if="row.levelIconLabel"
  62. :src="getImageUrl(row.levelIconLabel)"
  63. class="level-icon-img"
  64. alt="身份等级图标"
  65. />
  66. <span v-else class="level-tag" :class="row.iconTheme">{{ row.levelIconLabel || "VIP" }}</span>
  67. </template>
  68. </zy-table-column>
  69. <zy-table-column
  70. prop="levelName"
  71. label="身份等级名称"
  72. />
  73. <zy-table-column
  74. prop="theme"
  75. label="主题"
  76. />
  77. <zy-table-column
  78. prop="statusLabel"
  79. label="当前状态"
  80. />
  81. <zy-table-column
  82. label="操作"
  83. >
  84. <template #default="{ row }">
  85. <zy-button type="text" class="link-btn" @click="handleEdit(row)">编辑</zy-button>
  86. </template>
  87. </zy-table-column>
  88. </zy-table>
  89. </div>
  90. <!-- 分页 -->
  91. <div class="card pagination-card">
  92. <zy-pagination
  93. :page-size="table.page.PSize"
  94. :total="table.page.PCount"
  95. :pager-count="7"
  96. layout="pager"
  97. v-model:currentPage="table.page.PIndex"
  98. @current-change="getTableData"
  99. ></zy-pagination>
  100. </div>
  101. </div>
  102. </div>
  103. </template>
  104. <script setup lang="ts">
  105. import { getCurrentInstance, reactive, ref, onMounted } from "vue";
  106. import { useStore } from "vuex";
  107. import { useRoute, useRouter } from "vue-router";
  108. const { proxy } = getCurrentInstance() as any;
  109. const store = useStore();
  110. const route = useRoute();
  111. const router = useRouter();
  112. // 搜索条件
  113. let queryData = reactive({
  114. benefitName: "",
  115. status: "",
  116. });
  117. const statusOptions = [
  118. { label: "全部", value: "" },
  119. { label: "上架", value: "1" },
  120. { label: "下架", value: "0" },
  121. ];
  122. const table = reactive({
  123. loading: false,
  124. data: [] as any[],
  125. page: {
  126. PIndex: 1,
  127. PSize: 10,
  128. PCount: 0,
  129. },
  130. });
  131. const defaultThemeOptions = [
  132. { label: "金色", value: "gold" },
  133. { label: "银色", value: "silver" },
  134. { label: "蓝色", value: "blue" },
  135. ];
  136. const themeOptions = ref<Array<{ label: string; value: string }>>([...defaultThemeOptions]);
  137. const themeMap = ref<Record<string, string>>(
  138. defaultThemeOptions.reduce((acc, cur) => {
  139. acc[cur.value] = cur.label;
  140. return acc;
  141. }, {} as Record<string, string>)
  142. );
  143. const fillThemeMap = (options: Array<{ label: string; value: string }>) => {
  144. themeMap.value = options.reduce((acc, cur) => {
  145. if (cur?.value) {
  146. acc[cur.value] = cur.label;
  147. }
  148. return acc;
  149. }, {} as Record<string, string>);
  150. };
  151. const queryTheme = async () => {
  152. try {
  153. const { res } = await proxy.$interfaceEntry.vip.QueryDictList({
  154. dictType: "VipColor",
  155. });
  156. const data = res.data || {};
  157. const list =
  158. data.Data ||
  159. data.data ||
  160. data.result ||
  161. data.list ||
  162. [];
  163. if (Array.isArray(list) && list.length) {
  164. const parsed = list.map((item: any) => ({
  165. label: item.dictLabel,
  166. value: item.dictValue,
  167. }));
  168. themeOptions.value = parsed;
  169. fillThemeMap(parsed);
  170. } else {
  171. themeOptions.value = [...defaultThemeOptions];
  172. fillThemeMap(defaultThemeOptions);
  173. }
  174. } catch (e) {
  175. themeOptions.value = [...defaultThemeOptions];
  176. fillThemeMap(defaultThemeOptions);
  177. }
  178. };
  179. /* 获取表格数据 */
  180. const getTableData = async (e: any = undefined) => {
  181. !e && (table.page.PIndex = 1);
  182. table.loading = true;
  183. try {
  184. // 直接使用 status 值,空字符串转为 undefined,其他转为数字
  185. const status = queryData.status === "" ? undefined : Number(queryData.status);
  186. const { res } = await proxy.$interfaceEntry.vip.QueryPatientLevel({
  187. IdLevelName: queryData.benefitName || undefined,
  188. Status: status,
  189. PageIndex: table.page.PIndex,
  190. PageSize: table.page.PSize,
  191. });
  192. if (res.data?.RespCode != 10000) {
  193. proxy.$message.error(res.data?.errorMsg || res.data?.msg || "查询失败");
  194. table.data = [];
  195. table.page.PCount = 0;
  196. return;
  197. }
  198. // 数据结构:res.data.Data[0].DataList 是实际的数据列表
  199. const dataWrapper = res.data.Data?.[0] || {};
  200. const list = dataWrapper.DataList || res.data.Data || res.data.list || res.data.List || [];
  201. // 分页信息:从 Page 对象获取
  202. const pageInfo = res.data.Page || {};
  203. const totalCount = pageInfo.PCount || dataWrapper.Total || res.data.PCount || res.data.total || list.length;
  204. table.page.PCount = totalCount;
  205. table.data = list.map((item: any) => {
  206. // 后端返回的字段可能是 IdLevelIcon(大写)或 idLevelIcon(小写)
  207. const iconPath = item.IdLevelIcon || item.idLevelIcon || "";
  208. const themeValue = item.Theme || item.theme;
  209. return {
  210. levelCode: item.IdLevelCode || item.idLevelCode,
  211. levelIconLabel: iconPath,
  212. levelName: item.IdLevelName || item.idLevelName,
  213. theme: themeMap.value[themeValue] || themeValue || "-",
  214. statusLabel: (item.Status || item.status) === 1 ? "上架" : "下架",
  215. // 保存原始数据,编辑时可能需要
  216. rawData: item,
  217. };
  218. });
  219. } catch (err) {
  220. table.data = [];
  221. table.page.PCount = 0;
  222. proxy.$message.error("查询失败");
  223. } finally {
  224. table.loading = false;
  225. }
  226. };
  227. /** 重置搜索条件 */
  228. const resetData = () => {
  229. Object.keys(queryData).forEach((key: any) => {
  230. (queryData as any)[key] = "";
  231. });
  232. getTableData();
  233. };
  234. const handleCreate = () => {
  235. router.push({
  236. name: "vipEdit",
  237. query: {
  238. mode: "create",
  239. },
  240. });
  241. };
  242. // 获取图片完整 URL
  243. const getImageUrl = (iconPath: string) => {
  244. if (!iconPath) return "";
  245. // 如果路径不是以 http:// 或 https:// 或 / 开头,加上 / 前缀
  246. if (!iconPath.startsWith("http://") && !iconPath.startsWith("https://") && !iconPath.startsWith("/")) {
  247. return "/" + iconPath;
  248. }
  249. return iconPath;
  250. };
  251. const handleEdit = (row: any) => {
  252. router.push({
  253. name: "vipEdit",
  254. query: {
  255. mode: "edit",
  256. code: row.levelCode,
  257. name: row.levelName,
  258. theme: row.theme,
  259. status: row.statusLabel === "上架" ? "1" : "0",
  260. icon: row.levelIconLabel,
  261. },
  262. });
  263. };
  264. onMounted(async () => {
  265. await queryTheme();
  266. getTableData();
  267. });
  268. </script>
  269. <style scoped>
  270. .vip-page {
  271. min-height: 100%;
  272. background: #f5f7fb;
  273. padding: 24px 0 32px;
  274. box-sizing: border-box;
  275. }
  276. .page-inner {
  277. width: 1560px;
  278. margin: 0 auto;
  279. display: flex;
  280. flex-direction: column;
  281. gap: 12px;
  282. }
  283. .page-title {
  284. font-size: 20px;
  285. font-weight: 600;
  286. color: var(--el-text-color-primary);
  287. }
  288. .card {
  289. background: #ffffff;
  290. border-radius: 8px;
  291. box-shadow: 0 6px 24px rgba(44, 69, 105, 0.08);
  292. padding: 18px 24px;
  293. box-sizing: border-box;
  294. }
  295. .search-card {
  296. display: flex;
  297. flex-direction: column;
  298. }
  299. .search-fields {
  300. display: flex;
  301. align-items: center;
  302. justify-content: flex-start;
  303. flex-wrap: nowrap;
  304. gap: 16px;
  305. }
  306. .search-form {
  307. display: flex;
  308. align-items: center;
  309. }
  310. .search-form :deep(.el-form-item) {
  311. margin: 0 16px 0 0;
  312. }
  313. .search-form :deep(.el-form-item__label) {
  314. color: #555;
  315. }
  316. .search-form :deep(.el-input__inner) {
  317. width: 220px;
  318. }
  319. .search-actions {
  320. display: flex;
  321. align-items: center;
  322. gap: 12px;
  323. margin-left: auto;
  324. white-space: nowrap;
  325. }
  326. .btn-search {
  327. background: var(--el-color-primary);
  328. border-color: var(--el-color-primary);
  329. color: #fff;
  330. padding: 10px 32px;
  331. }
  332. .btn-create {
  333. background: var(--el-color-primary-light-9);
  334. border-color: var(--el-color-primary-light-7);
  335. color: var(--el-color-primary);
  336. padding: 10px 24px;
  337. }
  338. .table-card {
  339. padding: 0;
  340. overflow: hidden;
  341. flex: 1;
  342. display: flex;
  343. flex-direction: column;
  344. }
  345. .table-card :deep(.el-table) {
  346. width: 100%;
  347. border: none;
  348. flex: 1;
  349. }
  350. .table-card :deep(.el-table__header th),
  351. .table-card :deep(.el-table__body td) {
  352. text-align: center;
  353. font-size: 14px;
  354. }
  355. .table-card :deep(.el-table__body-wrapper),
  356. .table-card :deep(.el-table__header-wrapper) {
  357. padding: 0;
  358. }
  359. /* 按 3:3:8:2:2:2 比例填满整行(共 20 份) */
  360. .table-card :deep(.el-table__header colgroup col:nth-child(1)),
  361. .table-card :deep(.el-table__body colgroup col:nth-child(1)) {
  362. width: 15% !important; /* 3/20 */
  363. }
  364. .table-card :deep(.el-table__header colgroup col:nth-child(2)),
  365. .table-card :deep(.el-table__body colgroup col:nth-child(2)) {
  366. width: 15% !important; /* 3/20 */
  367. }
  368. .table-card :deep(.el-table__header colgroup col:nth-child(3)),
  369. .table-card :deep(.el-table__body colgroup col:nth-child(3)) {
  370. width: 40% !important; /* 8/20 */
  371. }
  372. .table-card :deep(.el-table__header colgroup col:nth-child(4)),
  373. .table-card :deep(.el-table__body colgroup col:nth-child(4)) {
  374. width: 10% !important; /* 2/20 */
  375. }
  376. .table-card :deep(.el-table__header colgroup col:nth-child(5)),
  377. .table-card :deep(.el-table__body colgroup col:nth-child(5)) {
  378. width: 10% !important; /* 2/20 */
  379. }
  380. .table-card :deep(.el-table__header colgroup col:nth-child(6)),
  381. .table-card :deep(.el-table__body colgroup col:nth-child(6)) {
  382. width: 10% !important; /* 2/20 */
  383. }
  384. .level-icon-img {
  385. width: 60px;
  386. height: 60px;
  387. object-fit: contain;
  388. border-radius: 4px;
  389. }
  390. .level-tag {
  391. display: inline-block;
  392. padding: 6px 18px;
  393. border-radius: 6px;
  394. font-size: 14px;
  395. color: #fff;
  396. min-width: 60px;
  397. }
  398. .tag-vip {
  399. background: #f69c45;
  400. }
  401. .tag-svip {
  402. background: #f67f45;
  403. }
  404. .tag-wip {
  405. background: #f45d45;
  406. }
  407. .link-btn {
  408. color: #2e74c6;
  409. }
  410. .pagination-card {
  411. display: flex;
  412. justify-content: center;
  413. padding: 16px;
  414. margin-top: auto;
  415. margin-bottom: 0;
  416. }
  417. .pagination-card :deep(.el-pagination.is-background .el-pager li) {
  418. background-color: #fff;
  419. border: 1px solid #dcdfe6;
  420. color: var(--el-text-color-regular);
  421. margin: 0 6px;
  422. border-radius: 6px;
  423. min-width: 42px;
  424. height: 34px;
  425. line-height: 34px;
  426. }
  427. .pagination-card :deep(.el-pagination.is-background .el-pager li.is-active) {
  428. background-color: var(--el-color-primary);
  429. border-color: var(--el-color-primary);
  430. color: #fff;
  431. }
  432. </style>