Families.vue 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  1. <template>
  2. <div class="page-container">
  3. <el-card>
  4. <div slot="header">
  5. <span>家庭管理</span>
  6. <el-button
  7. type="primary"
  8. size="small"
  9. style="float: right"
  10. @click="handleRefresh"
  11. :loading="loading"
  12. >
  13. 刷新
  14. </el-button>
  15. </div>
  16. <!-- 搜索 -->
  17. <el-form :inline="true" :model="searchForm" style="margin-bottom: 20px">
  18. <el-form-item label="家庭名称">
  19. <el-input
  20. v-model="searchForm.name"
  21. placeholder="请输入家庭名称"
  22. clearable
  23. @keyup.enter.native="handleSearch"
  24. ></el-input>
  25. </el-form-item>
  26. <el-form-item>
  27. <el-button type="primary" @click="handleSearch">搜索</el-button>
  28. <el-button @click="handleReset">重置</el-button>
  29. </el-form-item>
  30. </el-form>
  31. <!-- 家庭列表 -->
  32. <div class="adm-table-wrap">
  33. <el-table
  34. :data="tableData"
  35. border
  36. v-loading="loading"
  37. style="width: 100%"
  38. height="100%"
  39. >
  40. <el-table-column prop="id" label="ID" width="80">
  41. <template slot="header">
  42. <span class="sort-header" @click.stop="onSortClick('id', $event)">ID<span v-if="sortIndex('id') !== null" class="sort-index" :class="sortClass('id') === 'sort-asc' ? 'sort-asc-badge' : 'sort-desc-badge'">{{ sortIndex('id') }}</span>{{ sortIcon('id') }}</span>
  43. </template>
  44. </el-table-column>
  45. <el-table-column prop="name" label="家庭名称" width="200">
  46. <template slot="header">
  47. <span class="sort-header" @click.stop="onSortClick('name', $event)">家庭名称<span v-if="sortIndex('name') !== null" class="sort-index" :class="sortClass('name') === 'sort-asc' ? 'sort-asc-badge' : 'sort-desc-badge'">{{ sortIndex('name') }}</span>{{ sortIcon('name') }}</span>
  48. </template>
  49. </el-table-column>
  50. <el-table-column prop="inviteCode" label="邀请码" width="150">
  51. <template slot="header">
  52. <span class="sort-header" @click.stop="onSortClick('inviteCode', $event)">邀请码<span v-if="sortIndex('inviteCode') !== null" class="sort-index" :class="sortClass('inviteCode') === 'sort-asc' ? 'sort-asc-badge' : 'sort-desc-badge'">{{ sortIndex('inviteCode') }}</span>{{ sortIcon('inviteCode') }}</span>
  53. </template>
  54. </el-table-column>
  55. <el-table-column prop="createdAt" label="创建时间" width="180">
  56. <template slot-scope="scope">
  57. {{ formatDate(scope.row.createdAt) }}
  58. </template>
  59. <template slot="header">
  60. <span class="sort-header" @click.stop="onSortClick('createdAt', $event)">创建时间<span v-if="sortIndex('createdAt') !== null" class="sort-index" :class="sortClass('createdAt') === 'sort-asc' ? 'sort-asc-badge' : 'sort-desc-badge'">{{ sortIndex('createdAt') }}</span>{{ sortIcon('createdAt') }}</span>
  61. </template>
  62. </el-table-column>
  63. <el-table-column label="操作" width="250" fixed="right">
  64. <template slot-scope="{ row }">
  65. <el-button size="mini" type="primary" @click="handleEdit(row)">编辑</el-button>
  66. <el-dropdown trigger="hover" @command="(cmd) => handleActionCmd(row, cmd)">
  67. <el-button size="mini">
  68. 更多<i class="el-icon-arrow-down el-icon--right"></i>
  69. </el-button>
  70. <el-dropdown-menu slot="dropdown">
  71. <el-dropdown-item command="viewMembers" icon="el-icon-user">查看成员</el-dropdown-item>
  72. <el-dropdown-item command="viewCoupons" icon="el-icon-ticket">优惠券列表</el-dropdown-item>
  73. <el-dropdown-item command="viewUsage" icon="el-icon-document">使用记录</el-dropdown-item>
  74. <el-dropdown-item command="issueCoupon" icon="el-icon-ticket">发放优惠券</el-dropdown-item>
  75. <el-dropdown-item command="delete" icon="el-icon-delete">删除</el-dropdown-item>
  76. </el-dropdown-menu>
  77. </el-dropdown>
  78. </template>
  79. </el-table-column>
  80. </el-table>
  81. </div>
  82. <!-- 分页 -->
  83. <el-pagination
  84. style="margin-top: 20px; text-align: right"
  85. @size-change="handleSizeChange"
  86. @current-change="handleCurrentChange"
  87. :current-page="pagination.current"
  88. :page-sizes="[10, 20, 50, 100]"
  89. :page-size="pagination.size"
  90. :total="pagination.total"
  91. layout="total, sizes, prev, pager, next, jumper"
  92. ></el-pagination>
  93. </el-card>
  94. <!-- 编辑家庭弹窗 -->
  95. <el-dialog
  96. title="编辑家庭"
  97. :visible.sync="editDialogVisible"
  98. width="500px"
  99. >
  100. <el-form :model="editForm" :rules="editRules" ref="editForm" label-width="100px">
  101. <el-form-item label="家庭名称" prop="name">
  102. <el-input v-model="editForm.name" placeholder="请输入家庭名称"></el-input>
  103. </el-form-item>
  104. </el-form>
  105. <div slot="footer">
  106. <el-button @click="editDialogVisible = false">取消</el-button>
  107. <el-button type="primary" @click="submitEdit" :loading="submitting">确定</el-button>
  108. </div>
  109. </el-dialog>
  110. <!-- 查看成员弹窗 -->
  111. <el-dialog
  112. title="家庭成员"
  113. :visible.sync="membersDialogVisible"
  114. width="900px"
  115. >
  116. <div v-if="membersData.family">
  117. <el-descriptions :column="2" border style="margin-bottom: 20px">
  118. <el-descriptions-item label="家庭名称">{{ membersData.family.name }}</el-descriptions-item>
  119. <el-descriptions-item label="邀请码">{{ membersData.family.inviteCode }}</el-descriptions-item>
  120. </el-descriptions>
  121. <el-divider content-position="left">成员列表(仅区分管理员 / 成员)</el-divider>
  122. <el-table
  123. :data="membersData.members"
  124. border
  125. style="width: 100%"
  126. :max-height="350"
  127. v-if="membersData.members && membersData.members.length > 0"
  128. >
  129. <el-table-column prop="nickname" label="昵称" width="150"></el-table-column>
  130. <el-table-column prop="phone" label="手机号" width="150"></el-table-column>
  131. <el-table-column prop="gender" label="性别" width="80">
  132. <template slot-scope="scope">
  133. {{ scope.row.gender === 'male' ? '男' : scope.row.gender === 'female' ? '女' : '-' }}
  134. </template>
  135. </el-table-column>
  136. <el-table-column prop="age" label="年龄" width="80">
  137. <template slot-scope="scope">
  138. {{ scope.row.age || '-' }}
  139. </template>
  140. </el-table-column>
  141. <el-table-column prop="totalPoints" label="总积分" width="90">
  142. <template slot-scope="scope">
  143. <el-tag type="success">{{ scope.row.totalPoints || 0 }}</el-tag>
  144. </template>
  145. </el-table-column>
  146. <el-table-column label="角色" width="100">
  147. <template slot-scope="scope">
  148. <el-tag :type="scope.row.role === 'admin' ? 'danger' : 'info'" size="small">
  149. {{ scope.row.role === 'admin' ? '管理员' : '成员' }}
  150. </el-tag>
  151. </template>
  152. </el-table-column>
  153. <el-table-column label="操作" width="140">
  154. <template slot-scope="scope">
  155. <el-button
  156. size="mini"
  157. :type="scope.row.role === 'admin' ? '' : 'primary'"
  158. @click="toggleAdmin(scope.row)"
  159. >
  160. {{ scope.row.role === 'admin' ? '撤销管理员' : '设为管理员' }}
  161. </el-button>
  162. </template>
  163. </el-table-column>
  164. <el-empty v-else description="暂无成员" :image-size="60"></el-empty>
  165. </el-table>
  166. </div>
  167. </el-dialog>
  168. <!-- 发放优惠券弹窗 -->
  169. <el-dialog
  170. title="发放优惠券"
  171. :visible.sync="issueDialogVisible"
  172. width="500px"
  173. >
  174. <el-form :model="couponForm" label-width="100px">
  175. <el-form-item label="家庭">
  176. <el-input :value="couponForm.familyName" disabled></el-input>
  177. </el-form-item>
  178. <el-form-item label="优惠券" required>
  179. <el-select v-model="couponForm.couponId" placeholder="请选择优惠券" style="width: 100%">
  180. <el-option
  181. v-for="c in couponOptions"
  182. :key="c.id"
  183. :label="couponLabel(c)"
  184. :value="c.id"
  185. ></el-option>
  186. </el-select>
  187. </el-form-item>
  188. <el-form-item label="发放数量">
  189. <el-input-number v-model="couponForm.quantity" :min="1" :max="100" :step="1"></el-input-number>
  190. </el-form-item>
  191. </el-form>
  192. <div slot="footer">
  193. <el-button @click="issueDialogVisible = false">取消</el-button>
  194. <el-button type="primary" @click="confirmIssueCoupon" :loading="couponSubmitting">确认发放</el-button>
  195. </div>
  196. </el-dialog>
  197. <!-- 优惠券列表弹窗 -->
  198. <el-dialog
  199. title="优惠券列表"
  200. :visible.sync="couponDialogVisible"
  201. width="900px"
  202. >
  203. <el-form :inline="true" style="margin-bottom: 12px">
  204. <el-form-item label="状态">
  205. <el-select v-model="couponStatusFilter" placeholder="全部" clearable size="small" style="width:120px">
  206. <el-option label="可用" value="AVAILABLE"></el-option>
  207. <el-option label="已使用" value="USED"></el-option>
  208. </el-select>
  209. </el-form-item>
  210. <el-form-item>
  211. <el-button size="small" @click="loadCoupons(currentRow.id)">刷新</el-button>
  212. </el-form-item>
  213. </el-form>
  214. <el-table :data="couponListData" border v-loading="couponLoading" style="width:100%" max-height="400">
  215. <el-table-column prop="name" label="券名称" min-width="140"></el-table-column>
  216. <el-table-column prop="type" label="类型" width="80">
  217. <template slot-scope="scope">
  218. <el-tag size="mini" :type="scope.row.type === 'DISCOUNT' ? '' : 'success'">{{ scope.row.type === 'DISCOUNT' ? '折扣' : '满减' }}</el-tag>
  219. </template>
  220. </el-table-column>
  221. <el-table-column label="面值/折扣" width="100">
  222. <template slot-scope="scope">
  223. <span v-if="scope.row.type === 'DISCOUNT' && scope.row.discountRate">{{ (scope.row.discountRate / 100).toFixed(1) }}折</span>
  224. <span v-else-if="scope.row.value">{{ (scope.row.value / 100).toFixed(2) }}元</span>
  225. <span v-else>-</span>
  226. </template>
  227. </el-table-column>
  228. <el-table-column label="状态" width="80">
  229. <template slot-scope="scope">
  230. <el-tag size="mini" :type="scope.row.status === 'AVAILABLE' ? 'success' : 'info'">{{ scope.row.status === 'AVAILABLE' ? '可用' : '已使用' }}</el-tag>
  231. </template>
  232. </el-table-column>
  233. <el-table-column prop="receivedAt" label="领取时间" width="160">
  234. <template slot-scope="scope">{{ formatTime(scope.row.receivedAt) }}</template>
  235. </el-table-column>
  236. <el-table-column prop="usedAt" label="使用时间" width="160">
  237. <template slot-scope="scope">{{ formatTime(scope.row.usedAt) }}</template>
  238. </el-table-column>
  239. <el-pagination
  240. style="margin-top: 12px; text-align: right"
  241. @size-change="onCouponSizeChange"
  242. @current-change="onCouponPageChange"
  243. :current-page="couponPagination.current"
  244. :page-sizes="[10, 20, 50]"
  245. :page-size="couponPagination.size"
  246. :total="couponPagination.total"
  247. layout="total, sizes, prev, pager, next"
  248. ></el-pagination>
  249. </el-dialog>
  250. <!-- 使用记录弹窗 -->
  251. <el-dialog
  252. title="使用记录"
  253. :visible.sync="usageDialogVisible"
  254. width="800px"
  255. >
  256. <el-table :data="usageListData" border v-loading="usageLoading" style="width:100%" max-height="400">
  257. <el-table-column prop="name" label="券名称" min-width="140"></el-table-column>
  258. <el-table-column prop="type" label="类型" width="80">
  259. <template slot-scope="scope">
  260. <el-tag size="mini" :type="scope.row.type === 'DISCOUNT' ? '' : 'success'">{{ scope.row.type === 'DISCOUNT' ? '折扣' : '满减' }}</el-tag>
  261. </template>
  262. </el-table-column>
  263. <el-table-column label="面值/折扣" width="100">
  264. <template slot-scope="scope">
  265. <span v-if="scope.row.type === 'DISCOUNT' && scope.row.discountRate">{{ (scope.row.discountRate / 100).toFixed(1) }}折</span>
  266. <span v-else-if="scope.row.value">{{ (scope.row.value / 100).toFixed(2) }}元</span>
  267. <span v-else>-</span>
  268. </template>
  269. </el-table-column>
  270. <el-table-column prop="orderId" label="订单号" width="120">
  271. <template slot-scope="scope">{{ scope.row.orderId || '-' }}</template>
  272. </el-table-column>
  273. <el-table-column prop="usedAt" label="使用时间" width="160">
  274. <template slot-scope="scope">{{ formatTime(scope.row.usedAt) }}</template>
  275. </el-table-column>
  276. <el-pagination
  277. style="margin-top: 12px; text-align: right"
  278. @size-change="onUsageSizeChange"
  279. @current-change="onUsagePageChange"
  280. :current-page="usagePagination.current"
  281. :page-sizes="[10, 20, 50]"
  282. :page-size="usagePagination.size"
  283. :total="usagePagination.total"
  284. layout="total, sizes, prev, pager, next"
  285. ></el-pagination>
  286. </el-dialog>
  287. </el-table>
  288. </el-table>
  289. </div>
  290. </template>
  291. <script>
  292. import SortMixin from '@/mixins/SortMixin'
  293. import { getFamilyList, getFamilyMembers, updateFamily, deleteFamily, setMemberAdminRole } from '@/api/admin'
  294. import { getCouponList, issueFamilyCoupon, getFamilyCoupons, getFamilyCouponUsage } from '@/api/coupon'
  295. export default {
  296. name: 'Families',
  297. mixins: [SortMixin],
  298. computed: {
  299. tableHeight() {
  300. return window.innerHeight - 340
  301. }
  302. },
  303. data() {
  304. return {
  305. loading: false,
  306. submitting: false,
  307. tableData: [],
  308. sortableColumns: { id: 'ID', name: '家庭名称', inviteCode: '邀请码', createdAt: '创建时间' },
  309. searchForm: {
  310. name: ''
  311. },
  312. pagination: {
  313. current: 1,
  314. size: 10,
  315. total: 0
  316. },
  317. editDialogVisible: false,
  318. editForm: {
  319. id: null,
  320. name: ''
  321. },
  322. editRules: {
  323. name: [
  324. { required: true, message: '请输入家庭名称', trigger: 'blur' }
  325. ]
  326. },
  327. membersDialogVisible: false,
  328. membersData: {
  329. family: null,
  330. members: []
  331. },
  332. couponDialogVisible: false,
  333. issueDialogVisible: false,
  334. couponForm: {
  335. familyId: null,
  336. couponId: null,
  337. quantity: 1
  338. },
  339. couponOptions: [],
  340. couponSubmitting: false,
  341. currentRow: null,
  342. couponListData: [],
  343. couponLoading: false,
  344. couponPagination: { current: 1, size: 20, total: 0 },
  345. couponStatusFilter: '',
  346. usageListData: [],
  347. usageLoading: false,
  348. usagePagination: { current: 1, size: 20, total: 0 },
  349. usageDialogVisible: false
  350. }
  351. },
  352. mounted() {
  353. // 检查是否有从用户管理跳转过来的familyId参数
  354. const familyId = this.$route.query.familyId
  355. if (familyId) {
  356. this.handleViewMembersById(parseInt(familyId))
  357. }
  358. this.loadFamilies()
  359. },
  360. methods: {
  361. loadList() {
  362. this.loadFamilies()
  363. },
  364. handleActionCmd(row, cmd) {
  365. switch (cmd) {
  366. case 'viewMembers': this.handleViewMembers(row); break;
  367. case 'viewCoupons': this.handleViewCoupons(row); break;
  368. case 'viewUsage': this.handleViewUsage(row); break;
  369. case 'issueCoupon': this.handleIssueCoupon(row); break;
  370. case 'edit': this.handleEdit(row); break;
  371. case 'delete': this.handleDelete(row); break;
  372. }
  373. },
  374. async loadFamilies() {
  375. this.loading = true
  376. try {
  377. const params = {
  378. page: this.pagination.current,
  379. size: this.pagination.size,
  380. ...this.searchForm
  381. }
  382. if (this.sortState.length > 0) params.sort = this.sortState
  383. const res = await getFamilyList(params)
  384. this.tableData = res.data.records || res.data || []
  385. this.pagination.total = res.data.total || this.tableData.length
  386. } catch (error) {
  387. this.$message.error(error.message || '加载家庭列表失败')
  388. } finally {
  389. this.loading = false
  390. }
  391. },
  392. handleSearch() {
  393. this.pagination.current = 1
  394. this.loadFamilies()
  395. },
  396. handleReset() {
  397. this.searchForm = {
  398. name: ''
  399. }
  400. this.handleSearch()
  401. },
  402. handleRefresh() {
  403. this.loadFamilies()
  404. },
  405. handleSizeChange(val) {
  406. this.pagination.size = val
  407. this.pagination.current = 1
  408. this.loadFamilies()
  409. },
  410. handleCurrentChange(val) {
  411. this.pagination.current = val
  412. this.loadFamilies()
  413. },
  414. handleEdit(row) {
  415. this.editForm = {
  416. id: row.id,
  417. name: row.name
  418. }
  419. this.editDialogVisible = true
  420. },
  421. async submitEdit() {
  422. this.$refs.editForm.validate(async (valid) => {
  423. if (valid) {
  424. this.submitting = true
  425. try {
  426. await updateFamily(this.editForm.id, this.editForm)
  427. this.$message.success('更新成功')
  428. this.editDialogVisible = false
  429. this.loadFamilies()
  430. } catch (error) {
  431. this.$message.error(error.message || '更新失败')
  432. } finally {
  433. this.submitting = false
  434. }
  435. }
  436. })
  437. },
  438. handleDelete(row) {
  439. this.$confirm(`确定要删除家庭 "${row.name}" 吗?`, '提示', {
  440. confirmButtonText: '确定',
  441. cancelButtonText: '取消',
  442. type: 'warning'
  443. }).then(async () => {
  444. try {
  445. await deleteFamily(row.id)
  446. this.$message.success('删除成功')
  447. this.loadFamilies()
  448. } catch (error) {
  449. this.$message.error(error.message || '删除失败')
  450. }
  451. }).catch(() => {})
  452. },
  453. async handleViewMembers(row) {
  454. await this.handleViewMembersById(row.id)
  455. },
  456. async handleViewMembersById(familyId) {
  457. this.loading = true
  458. try {
  459. const res = await getFamilyMembers(familyId)
  460. this.membersData = {
  461. family: res.data.family,
  462. members: res.data.members || []
  463. }
  464. this.membersDialogVisible = true
  465. } catch (error) {
  466. this.$message.error(error.message || '加载家庭成员失败')
  467. } finally {
  468. this.loading = false
  469. }
  470. },
  471. async toggleAdmin(row) {
  472. if (!this.membersData.family) return
  473. const targetIsAdmin = row.role !== 'admin'
  474. try {
  475. await setMemberAdminRole(this.membersData.family.id, row.memberId, targetIsAdmin)
  476. this.$message.success(targetIsAdmin ? '已设为管理员' : '已撤销管理员')
  477. await this.handleViewMembersById(this.membersData.family.id)
  478. } catch (error) {
  479. this.$message.error(error.message || '操作失败')
  480. }
  481. },
  482. async handleIssueCoupon(row) {
  483. this.couponForm = {
  484. familyId: row.id,
  485. familyName: row.name,
  486. couponId: null,
  487. quantity: 1
  488. }
  489. this.issueDialogVisible = true
  490. try {
  491. const res = await getCouponList({ page: 1, size: 999 })
  492. this.couponOptions = res.data.records || res.data.list || res.data || []
  493. } catch (error) {
  494. this.$message.error(error.message || '加载优惠券列表失败')
  495. }
  496. },
  497. couponLabel(c) {
  498. if (c.type === 'DISCOUNT') {
  499. return `${c.name}(${(c.discountRate / 100).toFixed(1)}折)`
  500. }
  501. return `${c.name}(${(c.value / 100).toFixed(2)}元)`
  502. },
  503. async confirmIssueCoupon() {
  504. if (!this.couponForm.couponId) {
  505. this.$message.warning('请选择优惠券')
  506. return
  507. }
  508. this.couponSubmitting = true
  509. try {
  510. await issueFamilyCoupon({
  511. familyId: this.couponForm.familyId,
  512. couponId: this.couponForm.couponId,
  513. quantity: this.couponForm.quantity
  514. })
  515. this.$message.success('发放成功')
  516. this.issueDialogVisible = false
  517. } catch (error) {
  518. this.$message.error(error.message || '发放失败')
  519. } finally {
  520. this.couponSubmitting = false
  521. }
  522. },
  523. formatDate(dateStr) {
  524. if (!dateStr) return '-'
  525. const date = new Date(dateStr)
  526. return date.toLocaleString('zh-CN')
  527. },
  528. formatTime(t) {
  529. return t ? t.replace('T', ' ').substring(0, 19) : '-'
  530. },
  531. handleViewCoupons(row) {
  532. this.currentRow = row
  533. this.couponPagination = { current: 1, size: 20, total: 0 }
  534. this.couponStatusFilter = ''
  535. this.couponListData = []
  536. this.couponDialogVisible = true
  537. this.loadCoupons()
  538. },
  539. async loadCoupons() {
  540. if (!this.currentRow) return
  541. this.couponLoading = true
  542. try {
  543. const res = await getFamilyCoupons({
  544. familyId: this.currentRow.id,
  545. status: this.couponStatusFilter || undefined,
  546. page: this.couponPagination.current,
  547. size: this.couponPagination.size
  548. })
  549. this.couponListData = res.data.records || []
  550. this.couponPagination.total = res.data.total || 0
  551. } catch (error) {
  552. this.$message.error(error.message || '加载优惠券列表失败')
  553. } finally {
  554. this.couponLoading = false
  555. }
  556. },
  557. onCouponPageChange(val) {
  558. this.couponPagination.current = val
  559. this.loadCoupons()
  560. },
  561. onCouponSizeChange(val) {
  562. this.couponPagination.size = val
  563. this.couponPagination.current = 1
  564. this.loadCoupons()
  565. },
  566. handleViewUsage(row) {
  567. this.currentRow = row
  568. this.usagePagination = { current: 1, size: 20, total: 0 }
  569. this.usageListData = []
  570. this.usageDialogVisible = true
  571. this.loadUsage()
  572. },
  573. async loadUsage() {
  574. if (!this.currentRow) return
  575. this.usageLoading = true
  576. try {
  577. const res = await getFamilyCouponUsage({
  578. familyId: this.currentRow.id,
  579. page: this.usagePagination.current,
  580. size: this.usagePagination.size
  581. })
  582. this.usageListData = res.data.records || []
  583. this.usagePagination.total = res.data.total || 0
  584. } catch (error) {
  585. this.$message.error(error.message || '加载使用记录失败')
  586. } finally {
  587. this.usageLoading = false
  588. }
  589. },
  590. onUsagePageChange(val) {
  591. this.usagePagination.current = val
  592. this.loadUsage()
  593. },
  594. onUsageSizeChange(val) {
  595. this.usagePagination.size = val
  596. this.usagePagination.current = 1
  597. this.loadUsage()
  598. }
  599. }
  600. }
  601. </script>
  602. <style scoped>
  603. .sort-header {
  604. cursor: pointer;
  605. user-select: none;
  606. font-weight: 500;
  607. font-size: 12px;
  608. white-space: nowrap;
  609. }
  610. .sort-header:hover {
  611. color: #409eff;
  612. }
  613. </style>