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

214 lines
5.8 KiB

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