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

252 lines
7.1 KiB

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