vip-table.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  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, 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. /* 获取表格数据 */
  132. const getTableData = async (e: any = undefined) => {
  133. !e && (table.page.PIndex = 1);
  134. table.loading = true;
  135. try {
  136. // 直接使用 status 值,空字符串转为 undefined,其他转为数字
  137. const status = queryData.status === "" ? undefined : Number(queryData.status);
  138. const { res } = await proxy.$interfaceEntry.vip.QueryPatientLevel({
  139. IdLevelName: queryData.benefitName || undefined,
  140. Status: status,
  141. PageIndex: table.page.PIndex,
  142. PageSize: table.page.PSize,
  143. });
  144. if (res.data?.RespCode != 10000) {
  145. proxy.$message.error(res.data?.errorMsg || res.data?.msg || "查询失败");
  146. table.data = [];
  147. table.page.PCount = 0;
  148. return;
  149. }
  150. // 数据结构:res.data.Data[0].DataList 是实际的数据列表
  151. const dataWrapper = res.data.Data?.[0] || {};
  152. const list = dataWrapper.DataList || res.data.Data || res.data.list || res.data.List || [];
  153. // 分页信息:从 Page 对象获取
  154. const pageInfo = res.data.Page || {};
  155. const totalCount = pageInfo.PCount || dataWrapper.Total || res.data.PCount || res.data.total || list.length;
  156. table.page.PCount = totalCount;
  157. table.data = list.map((item: any) => {
  158. // 后端返回的字段可能是 IdLevelIcon(大写)或 idLevelIcon(小写)
  159. const iconPath = item.IdLevelIcon || item.idLevelIcon || "";
  160. return {
  161. levelCode: item.IdLevelCode || item.idLevelCode,
  162. levelIconLabel: iconPath,
  163. levelName: item.IdLevelName || item.idLevelName,
  164. theme: item.Theme || item.theme,
  165. statusLabel: (item.Status || item.status) === 1 ? "上架" : "下架",
  166. // 保存原始数据,编辑时可能需要
  167. rawData: item,
  168. };
  169. });
  170. } catch (err) {
  171. table.data = [];
  172. table.page.PCount = 0;
  173. proxy.$message.error("查询失败");
  174. } finally {
  175. table.loading = false;
  176. }
  177. };
  178. /** 重置搜索条件 */
  179. const resetData = () => {
  180. Object.keys(queryData).forEach((key: any) => {
  181. (queryData as any)[key] = "";
  182. });
  183. getTableData();
  184. };
  185. const handleCreate = () => {
  186. router.push({
  187. name: "vipEdit",
  188. query: {
  189. mode: "create",
  190. },
  191. });
  192. };
  193. // 获取图片完整 URL
  194. const getImageUrl = (iconPath: string) => {
  195. if (!iconPath) return "";
  196. // 如果路径不是以 http:// 或 https:// 或 / 开头,加上 / 前缀
  197. if (!iconPath.startsWith("http://") && !iconPath.startsWith("https://") && !iconPath.startsWith("/")) {
  198. return "/" + iconPath;
  199. }
  200. return iconPath;
  201. };
  202. const handleEdit = (row: any) => {
  203. router.push({
  204. name: "vipEdit",
  205. query: {
  206. mode: "edit",
  207. code: row.levelCode,
  208. name: row.levelName,
  209. theme: row.theme,
  210. status: row.statusLabel === "上架" ? "1" : "0",
  211. icon: row.levelIconLabel,
  212. },
  213. });
  214. };
  215. onMounted(() => {
  216. getTableData();
  217. });
  218. </script>
  219. <style scoped>
  220. .vip-page {
  221. min-height: 100%;
  222. background: #f5f7fb;
  223. padding: 24px 0 32px;
  224. box-sizing: border-box;
  225. }
  226. .page-inner {
  227. width: 1560px;
  228. margin: 0 auto;
  229. display: flex;
  230. flex-direction: column;
  231. gap: 12px;
  232. }
  233. .page-title {
  234. font-size: 20px;
  235. font-weight: 600;
  236. color: var(--el-text-color-primary);
  237. }
  238. .card {
  239. background: #ffffff;
  240. border-radius: 8px;
  241. box-shadow: 0 6px 24px rgba(44, 69, 105, 0.08);
  242. padding: 18px 24px;
  243. box-sizing: border-box;
  244. }
  245. .search-card {
  246. display: flex;
  247. flex-direction: column;
  248. }
  249. .search-fields {
  250. display: flex;
  251. align-items: center;
  252. justify-content: flex-start;
  253. flex-wrap: nowrap;
  254. gap: 16px;
  255. }
  256. .search-form {
  257. display: flex;
  258. align-items: center;
  259. }
  260. .search-form :deep(.el-form-item) {
  261. margin: 0 16px 0 0;
  262. }
  263. .search-form :deep(.el-form-item__label) {
  264. color: #555;
  265. }
  266. .search-form :deep(.el-input__inner) {
  267. width: 220px;
  268. }
  269. .search-actions {
  270. display: flex;
  271. align-items: center;
  272. gap: 12px;
  273. margin-left: auto;
  274. white-space: nowrap;
  275. }
  276. .btn-search {
  277. background: var(--el-color-primary);
  278. border-color: var(--el-color-primary);
  279. color: #fff;
  280. padding: 10px 32px;
  281. }
  282. .btn-create {
  283. background: var(--el-color-primary-light-9);
  284. border-color: var(--el-color-primary-light-7);
  285. color: var(--el-color-primary);
  286. padding: 10px 24px;
  287. }
  288. .table-card {
  289. padding: 0;
  290. overflow: hidden;
  291. flex: 1;
  292. display: flex;
  293. flex-direction: column;
  294. }
  295. .table-card :deep(.el-table) {
  296. width: 100%;
  297. border: none;
  298. flex: 1;
  299. }
  300. .table-card :deep(.el-table__header th),
  301. .table-card :deep(.el-table__body td) {
  302. text-align: center;
  303. font-size: 14px;
  304. }
  305. .table-card :deep(.el-table__body-wrapper),
  306. .table-card :deep(.el-table__header-wrapper) {
  307. padding: 0;
  308. }
  309. /* 按 3:3:8:2:2:2 比例填满整行(共 20 份) */
  310. .table-card :deep(.el-table__header colgroup col:nth-child(1)),
  311. .table-card :deep(.el-table__body colgroup col:nth-child(1)) {
  312. width: 15% !important; /* 3/20 */
  313. }
  314. .table-card :deep(.el-table__header colgroup col:nth-child(2)),
  315. .table-card :deep(.el-table__body colgroup col:nth-child(2)) {
  316. width: 15% !important; /* 3/20 */
  317. }
  318. .table-card :deep(.el-table__header colgroup col:nth-child(3)),
  319. .table-card :deep(.el-table__body colgroup col:nth-child(3)) {
  320. width: 40% !important; /* 8/20 */
  321. }
  322. .table-card :deep(.el-table__header colgroup col:nth-child(4)),
  323. .table-card :deep(.el-table__body colgroup col:nth-child(4)) {
  324. width: 10% !important; /* 2/20 */
  325. }
  326. .table-card :deep(.el-table__header colgroup col:nth-child(5)),
  327. .table-card :deep(.el-table__body colgroup col:nth-child(5)) {
  328. width: 10% !important; /* 2/20 */
  329. }
  330. .table-card :deep(.el-table__header colgroup col:nth-child(6)),
  331. .table-card :deep(.el-table__body colgroup col:nth-child(6)) {
  332. width: 10% !important; /* 2/20 */
  333. }
  334. .level-icon-img {
  335. width: 60px;
  336. height: 60px;
  337. object-fit: contain;
  338. border-radius: 4px;
  339. }
  340. .level-tag {
  341. display: inline-block;
  342. padding: 6px 18px;
  343. border-radius: 6px;
  344. font-size: 14px;
  345. color: #fff;
  346. min-width: 60px;
  347. }
  348. .tag-vip {
  349. background: #f69c45;
  350. }
  351. .tag-svip {
  352. background: #f67f45;
  353. }
  354. .tag-wip {
  355. background: #f45d45;
  356. }
  357. .link-btn {
  358. color: #2e74c6;
  359. }
  360. .pagination-card {
  361. display: flex;
  362. justify-content: center;
  363. padding: 16px;
  364. margin-top: auto;
  365. margin-bottom: 0;
  366. }
  367. .pagination-card :deep(.el-pagination.is-background .el-pager li) {
  368. background-color: #fff;
  369. border: 1px solid #dcdfe6;
  370. color: var(--el-text-color-regular);
  371. margin: 0 6px;
  372. border-radius: 6px;
  373. min-width: 42px;
  374. height: 34px;
  375. line-height: 34px;
  376. }
  377. .pagination-card :deep(.el-pagination.is-background .el-pager li.is-active) {
  378. background-color: var(--el-color-primary);
  379. border-color: var(--el-color-primary);
  380. color: #fff;
  381. }
  382. </style>