敢为人鲜小程序前端代码仓库
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.

240 lines
5.8 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.stop="cancelOrder">
  40. 取消订单
  41. </view>
  42. <view class="action-btn confirm" v-show="order.status === 'pending'" @click.stop="payOrder">
  43. 立即下单
  44. </view>
  45. <view class="action-btn confirm" v-show="order.status === 'processing' || order.status === 'shipping'"
  46. @click.stop="clickOrder">
  47. 查看订单
  48. </view>
  49. <view class="action-btn confirm" v-show="order.status === 'completed'" @click.stop="gotoSale">
  50. 订单售后
  51. </view>
  52. <view class="action-btn confirm" v-show="order.status === 'delivered'" @click.stop="pickOrder">
  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. pickOrder() {
  103. this.$emit('pick', this.order)
  104. }
  105. }
  106. }
  107. </script>
  108. <style lang="scss" scoped>
  109. .order-item {
  110. background-color: #ffffff;
  111. margin: 20rpx 0;
  112. border-radius: 16rpx;
  113. padding: 20rpx;
  114. .order-header {
  115. display: flex;
  116. align-items: center;
  117. justify-content: space-between;
  118. padding-bottom: 20rpx;
  119. border-bottom: 1rpx solid #f5f5f5;
  120. .shop-info {
  121. display: flex;
  122. align-items: center;
  123. .shop-logo {
  124. width: 70rpx;
  125. height: 70rpx;
  126. border-radius: 6rpx;
  127. margin-right: 10rpx;
  128. }
  129. .shop-name {
  130. font-size: 28rpx;
  131. }
  132. }
  133. }
  134. .order-content {
  135. padding: 20rpx 0;
  136. .food-list {
  137. white-space: nowrap;
  138. height: 150rpx;
  139. width: 100%;
  140. display: flex;
  141. align-items: center;
  142. }
  143. .food-scroll {
  144. display: inline-flex;
  145. }
  146. .food-item {
  147. height: 140rpx;
  148. width: 130rpx;
  149. margin-right: 10rpx;
  150. display: inline-block;
  151. .food-image {
  152. width: 100%;
  153. height: 100%;
  154. border-radius: 8rpx;
  155. }
  156. }
  157. .food-count {
  158. flex: 1;
  159. font-size: 24rpx;
  160. color: #666;
  161. text-align: center;
  162. margin-top: 10rpx;
  163. }
  164. }
  165. .order-info {
  166. display: flex;
  167. justify-content: space-between;
  168. align-items: center;
  169. padding: 10rpx 0;
  170. border-top: 1rpx solid #f5f5f5;
  171. .order-time {
  172. font-size: 24rpx;
  173. color: #666;
  174. }
  175. .order-price {
  176. font-size: 24rpx;
  177. .price {
  178. color: #f00;
  179. font-weight: 500;
  180. margin-left: 8rpx;
  181. }
  182. }
  183. }
  184. .order-actions {
  185. display: flex;
  186. justify-content: flex-end;
  187. align-items: center;
  188. padding: 20rpx;
  189. gap: 20rpx;
  190. .order-toast {
  191. display: flex;
  192. align-items: center;
  193. // justify-content: flex-start;
  194. flex: 1;
  195. // text-align: left;
  196. gap: 10rpx;
  197. font-size: 24rpx;
  198. background-color: pink;
  199. border-radius: 10rpx;
  200. padding: 10rpx;
  201. }
  202. .action-btn {
  203. padding: 12rpx 30rpx;
  204. border-radius: 30rpx;
  205. font-size: 24rpx;
  206. font-weight: 500;
  207. &.cancel {
  208. background-color: #fff;
  209. color: $uni-color-third;
  210. border: 3rpx solid $uni-color-third;
  211. }
  212. &.confirm {
  213. background-color: $uni-color;
  214. color: #fff;
  215. }
  216. }
  217. }
  218. }
  219. </style>