speedy-check-add.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <template>
  2. <view class="container" style="padding-top: 84px;padding-bottom: 10px;">
  3. <u-navbar title="选择商品" :border="false" fixed safe-area-inset-top bgColor="#22ac38"
  4. titleStyle="font-size:36rpx;color:#fff">
  5. <template #left>
  6. <u-icon name="arrow-left" color="#fff" size="20" @click="goBack"></u-icon>
  7. </template>
  8. <template #right>
  9. <text style="color: #ffffff;" @click="onSubmit">确定</text>
  10. </template>
  11. </u-navbar>
  12. <!-- 库位显示 -->
  13. <view class="location-info">
  14. <text>库位: {{ location }}</text>
  15. <text v-if="godownName">仓库: {{ godownName }}</text>
  16. <text v-if="orderNum">订单号: {{ orderNum }}</text>
  17. </view>
  18. <!-- 订单列表 -->
  19. <view class="product-details">
  20. <LocationOrderItem isCheck v-for="(item, index) in products" :key="index" :item="item"
  21. @select="toggleItemSelect" :isLink="false" />
  22. </view>
  23. <!-- 底部全选栏 -->
  24. <view class="fixed-bottom">
  25. <view class="select-all" @click="toggleSelectAll">
  26. <u-icon :name="isAllSelected ? 'checkmark-circle-fill' : 'checkmark-circle'"
  27. :color="isAllSelected ? '#19be6b' : '#c8c9cc'" size="28"></u-icon>
  28. <text class="select-text">全选</text>
  29. </view>
  30. <text class="order-count">订单总数: {{ products.length }}</text>
  31. </view>
  32. </view>
  33. </template>
  34. <script setup>
  35. import {
  36. ref,
  37. computed,
  38. onUnmounted
  39. } from 'vue'
  40. import { onLoad } from "@dcloudio/uni-app";
  41. import LocationOrderItem from './components/LocationOrderItem.vue'
  42. // 库位相关
  43. const location = ref('')
  44. const products = ref([])
  45. const orderNum = ref('')
  46. const godownName = ref('')
  47. // 获取库位订单
  48. const getOrderByPositionCode = (positionCode) => {
  49. uni.$u.http.get('/app/stock/getOrderByPositionCode?positionCode=' + positionCode).then(res => {
  50. if (res.code === 200) {
  51. const data = res.data
  52. orderNum.value = data.orderNum
  53. godownName.value = data.godownName
  54. products.value = data.godownStockLogResults || []
  55. // 初始化选中状态
  56. products.value.forEach(item => {
  57. item.checked = false
  58. })
  59. } else {
  60. uni.$u.toast(res.msg)
  61. }
  62. })
  63. }
  64. onLoad((options) => {
  65. if (options.location) {
  66. location.value = options.location
  67. getOrderByPositionCode(options.location)
  68. }
  69. // #ifdef APP-PLUS
  70. uni.$u.useGlobalEvent((e) => {
  71. if (e.barcode) {
  72. handleScan(e.barcode);
  73. }
  74. });
  75. // #endif
  76. })
  77. onUnmounted(() => {
  78. uni.$u.cleanupOnPageUnload();
  79. })
  80. // 计算是否全选
  81. const isAllSelected = computed(() => {
  82. return products.value.length > 0 && products.value.every(item => item.checked)
  83. })
  84. // 切换单个选择
  85. const toggleItemSelect = (item) => {
  86. item.checked = !item.checked
  87. }
  88. // 切换全选
  89. const toggleSelectAll = () => {
  90. const newState = !isAllSelected.value
  91. products.value.forEach(item => {
  92. item.checked = newState
  93. })
  94. }
  95. // 确认选择
  96. const onSubmit = () => {
  97. const selectedItems = products.value.filter(item => item.checked)
  98. // 这里可以通过 uni.$emit 传递选中的数据到上一页
  99. uni.$emit('selectedProducts', selectedItems)
  100. goBack()
  101. }
  102. // 返回上一页
  103. const goBack = () => {
  104. uni.navigateBack({
  105. delta: 1
  106. })
  107. }
  108. </script>
  109. <style lang="scss" scoped>
  110. .location-info {
  111. background-color: #fff;
  112. padding: 20rpx;
  113. text-align: left;
  114. font-size: 32rpx;
  115. margin-bottom: 16rpx;
  116. text {
  117. display: block;
  118. margin-bottom: 10rpx;
  119. &:last-child {
  120. margin-bottom: 0;
  121. }
  122. }
  123. }
  124. .product-details {
  125. margin-bottom: 100rpx;
  126. }
  127. .fixed-bottom {
  128. position: fixed;
  129. bottom: 0;
  130. left: 0;
  131. right: 0;
  132. height: 100rpx;
  133. background: #ffffff;
  134. display: flex;
  135. justify-content: space-between;
  136. align-items: center;
  137. padding: 0 30rpx;
  138. box-shadow: 0 -2rpx 6rpx rgba(0, 0, 0, 0.1);
  139. }
  140. .select-all {
  141. display: flex;
  142. align-items: center;
  143. .select-text {
  144. margin-left: 12rpx;
  145. font-size: 28rpx;
  146. }
  147. }
  148. .order-count {
  149. font-size: 28rpx;
  150. color: #666;
  151. }
  152. </style>