建材商城系统20241014
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.

206 lines
5.8 KiB

  1. <template>
  2. <view class="quick-order-container" @click="handleClick">
  3. <view class="new-message" v-if="innerHasNewMessage">
  4. 你有新的快捷下单信息
  5. </view>
  6. <view class="quick-order">
  7. <view class="number-order" v-if="innerMessageCount > 0">
  8. {{ innerMessageCount }}
  9. </view>
  10. <image :src="imageUrl" mode=""></image>
  11. </view>
  12. </view>
  13. </template>
  14. <script>
  15. export default {
  16. name: 'QuickOrderEntry',
  17. props: {
  18. // 图标路径
  19. imageUrl: {
  20. type: String,
  21. default: '/static/image/home/7.png'
  22. },
  23. // 点击跳转的页面
  24. targetUrl: {
  25. type: String,
  26. default: '/pages_order/order/fastCreateOrder'
  27. },
  28. // 是否自动获取快捷下单信息
  29. autoFetch: {
  30. type: Boolean,
  31. default: true
  32. }
  33. },
  34. data() {
  35. return {
  36. orderInfo: null,
  37. innerHasNewMessage: false,
  38. innerMessageCount: 0,
  39. isInitialized: false
  40. }
  41. },
  42. methods: {
  43. // 处理点击事件
  44. handleClick() {
  45. // 发出点击事件,便于父组件监听
  46. this.$emit('click');
  47. // 如果有订单信息,提供订单列表
  48. if (Array.isArray(this.orderInfo) && this.orderInfo.length > 0) {
  49. this.$emit('order-info', this.orderInfo);
  50. }
  51. if(this.orderInfo.length > 0){
  52. this.navigateTo('/pages_order/order/firmOrder');
  53. return
  54. }
  55. // 如果有目标页面,则跳转
  56. if (this.targetUrl) {
  57. this.navigateTo(this.targetUrl);
  58. }
  59. },
  60. // 获取快捷下单的信息
  61. getQuickOrderInfo() {
  62. // 调用接口获取快捷下单信息
  63. this.$api('getOrderInfo', {}, res => {
  64. if (res.code === 200 && res.result) {
  65. // 处理返回的订单列表
  66. const orderList = Array.isArray(res.result) ? res.result : [res.result];
  67. if (orderList.length > 0) {
  68. // 保存订单列表
  69. this.orderInfo = orderList;
  70. // 设置消息数量为订单列表长度
  71. this.innerHasNewMessage = true;
  72. this.innerMessageCount = orderList.length;
  73. // 通知父组件获取到了数据
  74. this.$emit('order-loaded', this.orderInfo);
  75. } else {
  76. this.innerHasNewMessage = false;
  77. this.innerMessageCount = 0;
  78. this.orderInfo = [];
  79. }
  80. } else {
  81. this.innerHasNewMessage = false;
  82. this.innerMessageCount = 0;
  83. this.orderInfo = [];
  84. }
  85. this.isInitialized = true;
  86. }, err => {
  87. console.error('获取快捷下单信息失败', err);
  88. this.innerHasNewMessage = false;
  89. this.innerMessageCount = 0;
  90. this.orderInfo = [];
  91. this.isInitialized = true;
  92. });
  93. },
  94. // 导航到指定页面
  95. navigateTo(url) {
  96. // 如果有订单列表,则优先使用第一个订单的ID
  97. if (Array.isArray(this.orderInfo) && this.orderInfo.length > 0 && this.orderInfo[0].id && url.indexOf('?') === -1) {
  98. url += `?orderId=${this.orderInfo[0].id}`;
  99. }
  100. this.$utils.navigateTo(url);
  101. },
  102. // 刷新快捷下单信息
  103. refresh() {
  104. this.getQuickOrderInfo();
  105. return this; // 链式调用
  106. },
  107. // 清除消息提示
  108. clearMessage() {
  109. this.innerHasNewMessage = false;
  110. this.innerMessageCount = 0;
  111. return this; // 链式调用
  112. },
  113. // 检查是否有新消息
  114. hasNewMessage() {
  115. return this.innerHasNewMessage;
  116. },
  117. // 获取消息数量
  118. getMessageCount() {
  119. return this.innerMessageCount;
  120. },
  121. // 获取当前订单信息
  122. getOrderInfo() {
  123. return this.orderInfo;
  124. }
  125. },
  126. }
  127. </script>
  128. <style scoped lang="scss">
  129. .quick-order-container {
  130. position: fixed;
  131. right: 30rpx;
  132. bottom: 30vh;
  133. z-index: 99;
  134. transition: transform 0.3s;
  135. &:active {
  136. transform: scale(0.95);
  137. }
  138. .new-message {
  139. position: absolute;
  140. top: 50rpx;
  141. right: 100%;
  142. white-space: nowrap;
  143. background-color: #DC2828;
  144. border-radius: 20rpx;
  145. font-size: 25rpx;
  146. color: #ffffff;
  147. padding: 5rpx 15rpx;
  148. margin-bottom: 10rpx;
  149. box-shadow: 0 5rpx 10rpx rgba(220, 40, 40, 0.3);
  150. animation: pulse 2s infinite;
  151. }
  152. .quick-order {
  153. position: relative;
  154. width: 230rpx;
  155. height: 160rpx;
  156. image {
  157. width: 100%;
  158. height: 100%;
  159. }
  160. .number-order {
  161. background-color: #DC2828;
  162. position: absolute;
  163. font-size: 30rpx;
  164. height: 40rpx;
  165. width: 40rpx;
  166. text-align: center;
  167. border-radius: 20rpx;
  168. color: #ffffff;
  169. top: 10rpx;
  170. left: 25rpx;
  171. }
  172. }
  173. }
  174. @keyframes pulse {
  175. 0% {
  176. transform: scale(1);
  177. }
  178. 50% {
  179. transform: scale(1.05);
  180. }
  181. 100% {
  182. transform: scale(1);
  183. }
  184. }
  185. </style>