order.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. <template>
  2. <!-- #ifdef MP-WEIXIN -->
  3. <uv-navbar
  4. :fixed="false"
  5. :title="title"
  6. left-arrow
  7. @leftClick="$onClickLeft"
  8. />
  9. <!-- #endif -->
  10. <view class="container">
  11. <view class="bg-white flex px-2 py-1">
  12. <view class="mr-1"><uv-button @click="change('all')" :type="typeStr == 'all' ? 'success' : 'info' " :plain="true" :hairline="true" text="全部订单" size="small"></uv-button></view>
  13. <view class="mr-1"><uv-button @click="change('takein')" :type="typeStr == 'takein' ? 'success' : 'info' " :plain="true" :hairline="true" text="到店自取" size="small"></uv-button></view>
  14. <view class="mr-1"><uv-button @click="change('takeout')" :type="typeStr == 'takeout' ? 'success' : 'info' " :plain="true" :hairline="true" text="外卖到家" size="small"></uv-button></view>
  15. <view><uv-button @click="change('desk')" :type="typeStr == 'desk' ? 'success' : 'info' " :plain="true" :hairline="true" text="堂食就餐" size="small"></uv-button></view>
  16. </view>
  17. <view class="orders-list d-flex flex-column w-100" style="padding: 20rpx; padding-bottom: 0;" v-if="orders.length > 0">
  18. <view class="order-item" v-for="(item, index) in orders" :key="index" style="margin-bottom: 30rpx;" >
  19. <list-cell :hover="false">
  20. <view class="w-100 d-flex align-items-center">
  21. <view class="flex-fill d-flex flex-column">
  22. <view class="font-size-lg text-color-base" style="margin-bottom: 20rpx;">
  23. {{ item.shop.name }}
  24. </view>
  25. <view class="flex align-center">
  26. <view class="mr-1">
  27. <uv-tags text="预约" plain size="mini" type="error" v-if="item.orderType == 'due'"></uv-tags>
  28. <uv-tags text="堂食" plain size="mini" type="error" v-if="item.orderType == 'desk'"></uv-tags>
  29. <uv-tags text="自取" plain size="mini" type="error" v-if="item.orderType == 'takein'"></uv-tags>
  30. <uv-tags text="外卖" plain size="mini" type="error" v-if="item.orderType == 'takeout'"></uv-tags>
  31. </view>
  32. <view class="font-size-sm text-color-assist">订单编号:{{ item.orderId }}</view>
  33. <!-- <view class="font-size-base text-color-assist" v-if="item.orderType == 'desk'">桌号:{{ item.deskNumber }}</view>
  34. <view class="font-size-base text-color-assist" v-else>取餐号:{{ item.numberId }}</view> -->
  35. </view>
  36. </view>
  37. <view class="font-size-medium text-color-primary">
  38. <text>{{ item.statusDto.title }}</text>
  39. </view>
  40. </view>
  41. </list-cell>
  42. <list-cell :hover="false" last>
  43. <view class="w-100 d-flex flex-column">
  44. <block>
  45. <view class="w-100 text-truncate font-size-lg text-color-base" style="margin-bottom: 20rpx;"
  46. v-if="item.cartInfo.length <= 3">
  47. <view class="flex mb-2" v-for="(good,index) in item.cartInfo" :key="index">
  48. <image :src="good.image" mode="aspectFill" class="image"></image>
  49. <view class="flex flex-column">
  50. <view class="font-size-medium mt-1 text-color-base">{{ good.title }}</view>
  51. <view class="font-size-sm mt-1">{{ good.spec }}</view>
  52. <view class="font-size-sm mt-1">×{{ good.number }} ¥{{ good.price }}</view>
  53. </view>
  54. </view>
  55. </view>
  56. <view class="w-100 text-truncate font-size-lg text-color-base flex flex-wrap" style="margin-bottom: 20rpx;" v-else>
  57. <view class="flex mb-2 justify-center" style="margin-right: 3rpx;" v-for="(good,index) in item.cartInfo" :key="index">
  58. <image :src="good.image" mode="aspectFill" class="image"></image>
  59. </view>
  60. </view>
  61. </block>
  62. <view class="d-flex justify-content-between align-items-center" style="margin-bottom: 30rpx;">
  63. <view class="font-size-sm text-color-assist">
  64. {{formatDateTime(item.createTime) }}
  65. </view>
  66. <view class="d-flex font-size-sm text-color-base align-items-center">
  67. <view style="margin-right: 10rpx;">共{{ goodsNum(item.cartInfo) }}件商品,实付</view>
  68. <view class="font-size-lg">¥{{ item.payPrice }}</view>
  69. </view>
  70. </view>
  71. <view class="d-flex align-items-center justify-content-end">
  72. <view>
  73. <button v-if="item.paid > 0 && item.status < 2 && item.refundStatus == 0" class="left-margin" plain size="mini" @tap.stop="receive(item)">确认收到餐</button>
  74. <button class="left-margin" plain size="mini" @tap="detail(item.orderId)">订单详情</button>
  75. </view>
  76. </view>
  77. </view>
  78. </list-cell>
  79. </view>
  80. </view>
  81. <uv-empty v-else mode="order" text="您暂时还没有订单哦~">
  82. <uv-button text="去点单" @click="addFood" color="#059825" shape="circle" customStyle="padding:0 120rpx;margin-top:30rpx"></uv-button>
  83. </uv-empty>
  84. </view>
  85. </template>
  86. <script setup>
  87. import {
  88. ref,
  89. computed
  90. } from 'vue'
  91. import { useMainStore } from '@/store/store'
  92. import { storeToRefs } from 'pinia'
  93. import { onShow,onLoad,onPullDownRefresh,onReachBottom} from '@dcloudio/uni-app'
  94. import { formatDateTime,kmUnit } from '@/utils/util'
  95. import {
  96. orderGetOrders,
  97. orderReceive,
  98. cancelDue
  99. } from '@/api/order'
  100. const main = useMainStore()
  101. const { isLogin } = storeToRefs(main)
  102. const title = ref('我的订单')
  103. const page = ref(1)
  104. const pageSize = ref(10)
  105. const orders = ref([])
  106. const typeStr = ref('all')
  107. const type = ref(-1)
  108. const orderType = ref('all')
  109. const orderGoodsName = computed(() => { //计算单个饮品添加到购物车的数量
  110. return (goods) => {
  111. let arr = []
  112. goods.forEach(good => arr.push(good.title + '*' + good.number))
  113. return arr.join(',')
  114. }
  115. })
  116. const goodsNum = computed(() => { //计算单个饮品添加到购物车的数量
  117. return (goods) => {
  118. let num = 0;
  119. goods.forEach(good => num += parseInt(good.number))
  120. return num;
  121. }
  122. })
  123. onLoad((option) => {
  124. if(!isLogin.value) {
  125. uni.navigateTo({url: '/pages/components/pages/login/login'})
  126. }
  127. getOrders(false)
  128. })
  129. onPullDownRefresh(() => {
  130. getOrders(false)
  131. })
  132. onReachBottom(() => {
  133. getOrders(false)
  134. })
  135. const addFood = () => {
  136. uni.switchTab({
  137. url: '/pages/menu/menu'
  138. })
  139. }
  140. // tab栏切换
  141. const change = (e) => {
  142. typeStr.value = e
  143. orderType.value = e
  144. getOrders(true)
  145. }
  146. const getOrders = async(isRefresh = false) => {
  147. uni.showLoading({
  148. title: '加载中'
  149. })
  150. if(isRefresh) {
  151. orders.value = []
  152. page.value = 1
  153. }
  154. let ordersData = await orderGetOrders({page:page.value, limit:pageSize.value,type:type.value,orderType:orderType.value});
  155. if(ordersData) {
  156. orders.value = orders.value.concat(ordersData)
  157. page.value += 1
  158. }
  159. uni.stopPullDownRefresh();
  160. uni.hideLoading()
  161. }
  162. const detail = (id) => {
  163. uni.navigateTo({
  164. url: '/pages/components/pages/orders/detail?id=' + id
  165. })
  166. }
  167. // 确认收到货
  168. const receive = async(order) => {
  169. let data = await orderReceive({uni:order.orderId});
  170. if (data) {
  171. await getOrders(true)
  172. }
  173. }
  174. const cancelDueOrder = async(id) => {
  175. let data = await cancelDue({id:id});
  176. if (data) {
  177. await getOrders(true)
  178. }
  179. }
  180. </script>
  181. <style lang="scss" scoped>
  182. .left-margin {
  183. margin-left: 10rpx;
  184. }
  185. .image {
  186. width: 130rpx;
  187. height: 130rpx;
  188. margin-right: 30rpx;
  189. border-radius: 8rpx;
  190. }
  191. </style>