敢为人鲜小程序前端代码仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

236 lines
5.7 KiB

  1. <template>
  2. <view class="order-item" @click="clickOrder">
  3. <!-- 订单头部 - 商家信息 -->
  4. <view class="order-header">
  5. <view class="shop-info">
  6. <image class="shop-logo" :src="order.shopLogo" mode="aspectFill"></image>
  7. <text class="shop-name">{{ order.shopName }}</text>
  8. </view>
  9. </view>
  10. <!-- 订单内容 - 菜品展示 -->
  11. <view class="order-content">
  12. <view class="food-list">
  13. <view class="food-scroll">
  14. <view class="food-item" v-for="(food, index) in fourImage" :key="index">
  15. <image class="food-image" :src="food.image" mode="aspectFill"></image>
  16. </view>
  17. </view>
  18. <view class="food-count" v-if="order.foodCount > 4">{{ order.foodCount }}</view>
  19. </view>
  20. </view>
  21. <!-- 订单信息 - 下单时间和价格 -->
  22. <view class="order-info">
  23. <view class="order-time">下单时间{{ order.orderTime }}</view>
  24. <view class="order-price">
  25. <text>合计:</text>
  26. <text class="price">{{ order.totalPrice.toFixed(2) }}</text>
  27. </view>
  28. </view>
  29. <!-- 订单操作 -->
  30. <view class="order-actions">
  31. <view
  32. class="order-toast"
  33. v-if="order.status === 'shipping' || order.status === 'delivered'"
  34. :style="{ backgroundColor: order.status === 'shipping' ? '#ECFEF4' : '#FFDBDB', color: order.status === 'shipping' ? '#019245' : '#FF2A2A' }">
  35. <uv-icon name="info-circle" size="34" :color="order.status === 'shipping' ? '#019245' : '#FF2A2A'"></uv-icon>
  36. <text v-show="order.status === 'shipping'">全力奔跑中请耐心等待哦</text>
  37. <text v-show="order.status === 'delivered'">您的餐点已送到取餐点请尽快取餐</text>
  38. </view>
  39. <view class="action-btn cancel" v-show="order.status === 'pending'" @click="cancelOrder">
  40. 取消订单
  41. </view>
  42. <view class="action-btn confirm" v-show="order.status === 'pending'" @click="payOrder">
  43. 立即下单
  44. </view>
  45. <view class="action-btn confirm" v-show="order.status === 'processing' || order.status === 'shipping'"
  46. @click="payOrder">
  47. 查看订单
  48. </view>
  49. <view class="action-btn confirm" v-show="order.status === 'completed'" @click="gotoSale">
  50. 订单售后
  51. </view>
  52. <view class="action-btn confirm" v-show="order.status === 'delivered'" @click="payOrder">
  53. 取餐完成
  54. </view>
  55. </view>
  56. </view>
  57. </template>
  58. <script>
  59. export default {
  60. name: 'OrderItem',
  61. props: {
  62. // 订单数据对象
  63. order: {
  64. type: Object,
  65. required: true,
  66. default: () => ({
  67. id: '',
  68. shopName: '',
  69. shopLogo: '',
  70. foods: [],
  71. foodCount: 0,
  72. orderTime: '',
  73. totalPrice: 0,
  74. status: 'pending' // pending, processing, shipping, completed, delivered, canceled
  75. })
  76. }
  77. },
  78. computed: {
  79. fourImage() {
  80. return this.order.foods.slice(0, 4)
  81. }
  82. },
  83. methods: {
  84. // 取消订单
  85. cancelOrder() {
  86. this.$emit('cancel', this.order.id);
  87. },
  88. // 支付订单
  89. payOrder() {
  90. this.$emit('pay', this.order.id);
  91. },
  92. // 点击整个订单项
  93. clickOrder() {
  94. this.$emit('click', this.order);
  95. },
  96. gotoSale() {
  97. this.$utils.navigateTo({
  98. url: '/pages_order/order/afterSale?id=' + this.order.id
  99. })
  100. }
  101. }
  102. }
  103. </script>
  104. <style lang="scss" scoped>
  105. .order-item {
  106. background-color: #ffffff;
  107. margin: 20rpx 0;
  108. border-radius: 16rpx;
  109. padding: 20rpx;
  110. .order-header {
  111. display: flex;
  112. align-items: center;
  113. justify-content: space-between;
  114. padding-bottom: 20rpx;
  115. border-bottom: 1rpx solid #f5f5f5;
  116. .shop-info {
  117. display: flex;
  118. align-items: center;
  119. .shop-logo {
  120. width: 70rpx;
  121. height: 70rpx;
  122. border-radius: 6rpx;
  123. margin-right: 10rpx;
  124. }
  125. .shop-name {
  126. font-size: 28rpx;
  127. }
  128. }
  129. }
  130. .order-content {
  131. padding: 20rpx 0;
  132. .food-list {
  133. white-space: nowrap;
  134. height: 150rpx;
  135. width: 100%;
  136. display: flex;
  137. align-items: center;
  138. }
  139. .food-scroll {
  140. display: inline-flex;
  141. }
  142. .food-item {
  143. height: 140rpx;
  144. width: 130rpx;
  145. margin-right: 10rpx;
  146. display: inline-block;
  147. .food-image {
  148. width: 100%;
  149. height: 100%;
  150. border-radius: 8rpx;
  151. }
  152. }
  153. .food-count {
  154. flex: 1;
  155. font-size: 24rpx;
  156. color: #666;
  157. text-align: center;
  158. margin-top: 10rpx;
  159. }
  160. }
  161. .order-info {
  162. display: flex;
  163. justify-content: space-between;
  164. align-items: center;
  165. padding: 10rpx 0;
  166. border-top: 1rpx solid #f5f5f5;
  167. .order-time {
  168. font-size: 24rpx;
  169. color: #666;
  170. }
  171. .order-price {
  172. font-size: 24rpx;
  173. .price {
  174. color: #f00;
  175. font-weight: 500;
  176. margin-left: 8rpx;
  177. }
  178. }
  179. }
  180. .order-actions {
  181. display: flex;
  182. justify-content: flex-end;
  183. align-items: center;
  184. padding: 20rpx;
  185. gap: 20rpx;
  186. .order-toast {
  187. display: flex;
  188. align-items: center;
  189. // justify-content: flex-start;
  190. flex: 1;
  191. // text-align: left;
  192. gap: 10rpx;
  193. font-size: 24rpx;
  194. background-color: pink;
  195. border-radius: 10rpx;
  196. padding: 10rpx;
  197. }
  198. .action-btn {
  199. padding: 12rpx 30rpx;
  200. border-radius: 30rpx;
  201. font-size: 24rpx;
  202. font-weight: 500;
  203. &.cancel {
  204. background-color: #fff;
  205. color: $uni-color-third;
  206. border: 3rpx solid $uni-color-third;
  207. }
  208. &.confirm {
  209. background-color: $uni-color;
  210. color: #fff;
  211. }
  212. }
  213. }
  214. }
  215. </style>