index.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <template>
  2. <div>
  3. <v-tabs v-model="tab" align-tabs="start" color="primary" :bg-color="props.tabListBg ? '#f7f8fa': '#fff'" @update:modelValue="queryParams.pageNo = 1, getOrderPage()">
  4. <v-tab v-for="(val, i) in tabList" :key="i" :value="val.value">{{ val.title }}</v-tab>
  5. </v-tabs>
  6. <div v-if="orderList.length" class="mt-3">
  7. <div v-for="val in orderList" :key="val.id" class="order-item mb-3">
  8. <div class="order-item-header px-5">
  9. <div style="width: 40%;">
  10. <span>订单号:{{ val.no }}</span>
  11. <span class="ml-5">{{ timesTampChange(val.createTime) }}</span>
  12. </div>
  13. <div class="text-end color-warning" :class="formatOrderColor(val)" style="flex: 1">
  14. {{ formatOrderStatus(val) }}
  15. </div>
  16. </div>
  17. <!-- 商品列表 -->
  18. <GoodsItem v-for="k in val.items" :key="k.id" :item="k" />
  19. <!-- 操作按钮 -->
  20. <div class="text-end pa-3 font-size-13 color-666">
  21. <div>共{{ val.productCount }}件商品,合计:¥{{ fen2yuan(val.payPrice) }}</div>
  22. <v-btn class="mt-2" variant="tonal" rounded="xl" @click.stop="handleDetail(val)">查看详情</v-btn>
  23. <v-btn v-if="val.buttons.includes('confirm')" class="mt-2 ml-3" variant="tonal" color="success" rounded="xl" @click.stop="handleConfirm(val)">确认收货</v-btn>
  24. <!-- <v-btn v-if="val.buttons.includes('comment')" class="mt-2" variant="tonal" rounded="xl" @click.stop="handleComment(val)">评价</v-btn> -->
  25. <!-- <v-btn v-if="val.buttons.includes('express')" class="mt-2" variant="tonal" rounded="xl">查看物流</v-btn> -->
  26. <v-btn v-if="val.buttons.includes('cancel')" class="mt-2 ml-3" variant="tonal" rounded="xl" @click.stop="handleCancel(val)">取消订单</v-btn>
  27. <v-btn v-if="val.buttons.includes('delete')" class="mt-2 ml-3" variant="tonal" color="error" rounded="xl" @click.stop="handleDelete(val)">删除订单</v-btn>
  28. <v-btn v-if="val.buttons.includes('pay')" class="mt-2 ml-3" variant="tonal" color="primary" rounded="xl" @click.stop="handlePay(val)">继续支付</v-btn>
  29. </div>
  30. </div>
  31. <CtPagination :total="total" :page="queryParams.pageNo" :limit="queryParams.pageSize" @handleChange="handleChangePage"></CtPagination>
  32. </div>
  33. <Empty v-else :elevation="false" :message="tab === -1 ? '暂无订单' : '暂无' + tabList.find(e => e.value === tab).title + '订单'"></Empty>
  34. </div>
  35. <!-- <CtDialog :visible="showDialog" titleClass="text-h6" :footer="true" :widthType="3" title="商品评论" @submit="handleSubmit" @close="handleClose">
  36. <CommentForm ref="commentFormRef" v-if="showDialog" :orderId="commentOrderId" />
  37. </CtDialog> -->
  38. <!-- 支付 -->
  39. <CtDialog :visible="showPay" titleClass="text-h6" :widthType="3" title="收银台" :footer="false" @close="payCancel">
  40. <pay ref="payRef" :id="payOrderId" @paySuccess="paySuccess"></pay>
  41. </CtDialog>
  42. </template>
  43. <script setup>
  44. defineOptions({ name: 'mall-user-order-index'})
  45. import { ref } from 'vue'
  46. import { getMallOrderPage, receiveOrder, deleteTradeOrder, cancelTradeOrder, createOrderItemComment } from '@/api/mall/user'
  47. import { timesTampChange } from '@/utils/date'
  48. import { fen2yuan, handleOrderButtons, formatOrderStatus, formatOrderColor } from '@/hooks/web/useGoods'
  49. import Confirm from '@/plugins/confirm'
  50. import Snackbar from '@/plugins/snackbar'
  51. import GoodsItem from '../../components/GoodsItem/index.vue'
  52. import CommentForm from './commentForm.vue'
  53. import pay from '@/views/mall/components/details/order/pay.vue'
  54. import { useRoute } from 'vue-router'; const route = useRoute()
  55. import { useRouter } from 'vue-router'; const router = useRouter()
  56. const props = defineProps({
  57. tabListBg: {
  58. type: Boolean,
  59. default: true
  60. },
  61. })
  62. const tab = ref(route?.query?.tab ? (route.query.tab)-0 : -1)
  63. const tabList = [
  64. { title: '全部', value: -1 },
  65. { title: '待付款', value: 0 },
  66. { title: '待发货', value: 10 },
  67. { title: '待收货', value: 20 },
  68. { title: '已完成', value: 30 },
  69. { title: '已取消', value: 40 },
  70. // { title: '待评价', value: 30 }
  71. ]
  72. const total = ref(0)
  73. const queryParams = ref({
  74. pageNo: 1,
  75. pageSize: 10
  76. })
  77. // 获取订单列表
  78. const orderList = ref([])
  79. const getOrderPage = async () => {
  80. queryParams.value.status = tab.value
  81. if (tab.value === -1) delete queryParams.value.status
  82. if (tab.value === 30) queryParams.value.commentStatus = false
  83. const result = await getMallOrderPage(queryParams.value)
  84. result.list.forEach(order => handleOrderButtons(order))
  85. orderList.value = result.list
  86. total.value = result.total
  87. }
  88. getOrderPage()
  89. // 分页
  90. const handleChangePage = (e) => {
  91. queryParams.value.pageNo = e
  92. getOrderPage()
  93. }
  94. // 查看详情
  95. const handleDetail = ({ id }) => {
  96. window.open(`/mall/user/order/detail/${id}`)
  97. }
  98. // 删除订单
  99. const handleDelete = async ({ id }) => {
  100. Confirm('系统提示', '是否确认删除该订单?').then(async () => {
  101. await deleteTradeOrder(id)
  102. Snackbar.success('删除成功')
  103. await getOrderPage()
  104. })
  105. }
  106. // 取消订单
  107. const handleCancel = async ({ id }) => {
  108. Confirm('系统提示', '是否确认取消该订单?').then(async () => {
  109. await cancelTradeOrder(id)
  110. Snackbar.success('取消成功')
  111. await getOrderPage()
  112. })
  113. }
  114. // 商品评论
  115. // const showDialog = ref(false)
  116. // const commentOrderId = ref(null) // 订单id
  117. // const commentFormRef = ref()
  118. // const handleComment = (val) => {
  119. // commentOrderId.value = val.id
  120. // showDialog.value = true
  121. // }
  122. // const handleClose = () => {
  123. // commentOrderId.value = null
  124. // showDialog.value = false
  125. // }
  126. // const handleSubmit = async () => {
  127. // const commentList = commentFormRef.value.commentList
  128. // for (const comment of commentList) {
  129. // await createOrderItemComment(comment)
  130. // }
  131. // Snackbar.success('评论成功')
  132. // handleClose()
  133. // getOrderPage()
  134. // }
  135. // // 收货成功后提示去评论
  136. // const handlePromptComment = (id) => {
  137. // Confirm('确认收货成功', '是否前往评价?', { sureText: '立即评价', cancelText: '关闭' }).then(() => {
  138. // handleComment({ id })
  139. // })
  140. // }
  141. // 确认收货
  142. const handleConfirm = ({ id }) => {
  143. if (!id) return
  144. Confirm('系统提示', '是否确认收货?').then(async () => {
  145. await receiveOrder(id)
  146. Snackbar.success('收货成功')
  147. queryParams.value.pageNo = 1
  148. await getOrderPage()
  149. handlePromptComment(id) // 收货成功后提示去评论
  150. })
  151. }
  152. const showPay = ref(false)
  153. const payOrderId = ref('')
  154. const handlePay = (val) => {
  155. if (!payOrderId) return Snackbar.success('订单错误!')
  156. payOrderId.value = val.payOrderId
  157. showPay.value = true
  158. }
  159. //
  160. const payCancel = () => {
  161. Snackbar.warning('您已取消支付!')
  162. showPay.value = false
  163. // router.push({ path: '/mall/user/order', query: { tab: 0 } })
  164. }
  165. const paySuccess = (e) => {
  166. // Snackbar.success('支付成功!')
  167. // showPay.value = false
  168. // getOrderPage()
  169. router.push({ path: '/mall/payOver', query: { price: e.price }})
  170. }
  171. </script>
  172. <style scoped lang="scss">
  173. .order-item {
  174. border: 1px solid #dbdbdb;
  175. &-header {
  176. display: flex;
  177. background-color: #f2f4f7;
  178. height: 36px;
  179. line-height: 36px;
  180. font-size: 13px;
  181. color: #666;
  182. }
  183. }
  184. </style>