myPrize.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <template>
  2. <CtTable
  3. :items="items"
  4. class="mt-3"
  5. :headers="headers"
  6. :loading="false"
  7. :elevation="0"
  8. :isTools="false"
  9. :total="total"
  10. :showPage="true"
  11. :itemsPerPage="5"
  12. :showSelect="false"
  13. :page-info="queryParams"
  14. itemKey="id"
  15. @pageHandleChange="handleChangePage"
  16. >
  17. <template #prize="{ item }">
  18. <div class="d-flex align-center my-1">
  19. <div style="width: 80px; height: 80px">
  20. <v-img :src="item.prize.image" width="80px" height="80px"></v-img>
  21. </div>
  22. <div class="ml-1">{{ item.prize.name }}</div>
  23. </div>
  24. </template>
  25. <template #receiveInfo="{ item }">
  26. <div class="ellipsis" style="max-width: 180px;" v-ellipse-tooltip>
  27. {{ orderReceiveInfo(item) }}
  28. </div>
  29. </template>
  30. <template #deliverInfo="{ item }">
  31. <div class="ellipsis" style="max-width: 180px;" v-ellipse-tooltip>
  32. {{ item.record.deliverInfo ? JSON.parse(item.record.deliverInfo).name + '-' + JSON.parse(item.record.deliverInfo).no : ''}}
  33. </div>
  34. </template>
  35. <template #actions="{ item }">
  36. <div v-if="!item.record.isReceive && !item.record.receiveInfo">
  37. <v-btn color="primary" @click.stop="handleReceive(item)" variant="text">领取</v-btn>
  38. <v-btn color="error" @click.stop="handleGiveUp(item)" variant="text">放弃</v-btn>
  39. </div>
  40. <span v-else class="color-666">{{ item.record.deliverInfo ? '已发货' : '等待发货' }}</span>
  41. </template>
  42. </CtTable>
  43. <CtDialog :visible="showDialog" titleClass="text-h6" :footer="true" :widthType="1" title="选择收货地址" @submit="handleSubmit" @close="showDialog = false">
  44. <div style="min-height: 60vh;">
  45. <SelectAddress ref="selectAddressRef" showSelect></SelectAddress>
  46. </div>
  47. </CtDialog>
  48. </template>
  49. <script setup>
  50. defineOptions({ name: 'mall-user-prize-index' })
  51. import { ref, computed } from 'vue'
  52. import SelectAddress from '@/views/recruit/personal/PersonalCenter/shippingAddress/index.vue'
  53. import Snackbar from '@/plugins/snackbar'
  54. import { getLuckLotteryRecordPage, luckyLotteryRecordReceive, luckyLotteryRecordGiveUp } from '@/api/mall/prize'
  55. import { timesTampChange } from '@/utils/date'
  56. import Confirm from '@/plugins/confirm'
  57. const queryParams = ref({
  58. pageNo: 1,
  59. pageSize: 5,
  60. })
  61. const total = ref(0)
  62. const items = ref([])
  63. const headers = [
  64. { title: '奖品信息', key: 'prize', sortable: false },
  65. { title: '收货信息', key: 'receiveInfo', sortable: false },
  66. { title: '发货信息', key: 'deliverInfo', sortable: false },
  67. { title: '中奖时间', key: 'record.createTime', sortable: false, value: item => timesTampChange(item.record.createTime) },
  68. { title: '操作', key: 'actions', sortable: false }
  69. ]
  70. // 获取中奖记录
  71. const getLuckLotteryRecordList = async () => {
  72. const result = await getLuckLotteryRecordPage(queryParams.value)
  73. items.value = result?.list || []
  74. total.value = result?.total || 0
  75. }
  76. getLuckLotteryRecordList()
  77. // 收货信息
  78. const orderReceiveInfo = computed(() => (item) => {
  79. const info = item.record.receiveInfo ? JSON.parse(item.record.receiveInfo) : {}
  80. if (!info || !Object.keys(info).length) return ''
  81. return `${info.name},${info.mobile},${info.areaName} ${info.detailAddress}`
  82. })
  83. const handleChangePage = (e) => {
  84. queryParams.value.pageNo = e
  85. getLuckLotteryRecordList()
  86. }
  87. // 领取
  88. const selectAddressRef = ref()
  89. const showDialog = ref(false)
  90. const recordId = ref('')
  91. const handleReceive = (item) => {
  92. recordId.value = item.record.id
  93. showDialog.value = true
  94. }
  95. const handleSubmit = async () => {
  96. const receive = selectAddressRef.value.getSelected() || {}
  97. if (!receive || !Object.keys(receive).length) return Snackbar.warning('请选择您的收货地址')
  98. await luckyLotteryRecordReceive({ id: recordId.value, receiveInfo: JSON.stringify(receive) })
  99. showDialog.value = false
  100. recordId.value = null
  101. Snackbar.success('领取成功,待商家发货')
  102. getLuckLotteryRecordList()
  103. }
  104. // 放弃领取
  105. const handleGiveUp = async (item) => {
  106. Confirm('系统提示', `是否确定放弃领取${item.prize.name}?`).then(async () => {
  107. await luckyLotteryRecordGiveUp(item.record.id)
  108. Snackbar.success('放弃成功')
  109. getLuckLotteryRecordList()
  110. })
  111. }
  112. </script>
  113. <style scoped lang="scss">
  114. </style>