materialsDetail.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. <template>
  2. <gui-page :custom-header="true" :header-class="['gui-theme-background-color']">
  3. <template #gHeader>
  4. <view style="height:44px;" class="gui-flex gui-nowrap gui-rows gui-align-items-center">
  5. <text
  6. style="font-size:44rpx;"
  7. class="gui-header-leader-btns gui-color-white font-icons"
  8. @tap="goBack"
  9. >&#xe6c5;</text>
  10. <text
  11. class="gui-h4 gui-blod gui-flex1 gui-text-center gui-ellipsis gui-color-white gui-primary-text"
  12. >扫描清单资源档</text>
  13. <view style="width:40px;" />
  14. </view>
  15. </template>
  16. <template #gBody>
  17. <view class="list-content">
  18. <view class="table-title">
  19. <span>已扫物料资源清单</span>
  20. </view>
  21. <!-- 数据列表 -->
  22. <view v-if="cardList?.length" class="scroll-box">
  23. <view
  24. v-for="(item, idx) in cardList"
  25. :key="item.id"
  26. class="swipe-card"
  27. :data-index="idx"
  28. @touchstart="touchStart"
  29. @touchmove="touchMove"
  30. @touchend="touchEnd"
  31. >
  32. <!-- 原来整套卡片结构原封不动 -->
  33. <view class="card-content" :style="{ transform: `translateX(${item.slideX || 0}px)` }">
  34. <view class="card-list-flexbox">
  35. <view class="card-list-item">
  36. <text class="text-1 gui-color-gray">物料号</text>
  37. <text class="text-2 gui-color-gray">{{ item.materialNo }}</text>
  38. </view>
  39. <view class="card-list-item">
  40. <text class="text-1 gui-color-gray">物料名称</text>
  41. <text class="text-2 gui-color-gray">{{ item.materialName }}</text>
  42. </view>
  43. <view class="card-list-item">
  44. <text class="text-1 gui-color-gray">数量</text>
  45. <text class="text-2" style="color: orange;font-weight: bold;">{{ item.batchQty }}</text>
  46. </view>
  47. <view class="card-list-item">
  48. <text class="text-1 gui-color-gray">批号</text>
  49. <text class="text-2" style="color: orange;font-weight: bold;">{{ item.batchNumber }}</text>
  50. </view>
  51. </view>
  52. </view>
  53. <!-- 删除按钮移出来,和card-content同级 -->
  54. <view class="btn-delete" @tap.stop="deleteItem(item, idx)">删除</view>
  55. </view>
  56. </view>
  57. <!-- 空态 -->
  58. <view v-else>
  59. <view class="bg-image">
  60. <image src="@/static/empty.png" mode="heightFix" />
  61. <text>这里什么都没有...</text>
  62. </view>
  63. </view>
  64. </view>
  65. </template>
  66. </gui-page>
  67. </template>
  68. <script>
  69. import { onReachBottom } from '@dcloudio/uni-app'
  70. import { ref, defineComponent, onMounted, onBeforeMount } from 'vue'
  71. export default defineComponent({
  72. setup() {
  73. const parentRow = uni.getStorageSync('mixMaterialDetail') ?? {}
  74. const detailId = ref('')
  75. const queryParams = ref({ pageSize: 10, pageNo: 1, id: '' })
  76. const cardList = ref([])
  77. const hasMore = ref(true)
  78. onBeforeMount(() => {
  79. detailId.value = JSON.parse(parentRow)?.id
  80. })
  81. onMounted(() => {
  82. search()
  83. })
  84. const search = () => {
  85. // uni.$reqGet('getScannedOutSendResourcePage', { ...queryParams.value, id: detailId.value }).then(
  86. uni.$reqGet('getScannedOutSendResourcePage', { id: detailId.value }).then(
  87. ({ data }) => {
  88. const list = data?.inoutRequestSubdetailList ?? []
  89. cardList.value = list
  90. console.log('返回数据:', list) // ← 添加调试,看数据是否存在
  91. console.log('数据长度:', list.length)
  92. // 如果首次加载不足10条,标记为没有更多数据
  93. hasMore.value = list.length >= queryParams.value.pageSize
  94. }
  95. )
  96. }
  97. const goBack = () => {
  98. uni.removeStorageSync('mixMaterialDetail')
  99. uni.$goBack('/pages/workbranch/warehouse/scanInOut/Out/scannedMaterials')
  100. }
  101. /* ===== 左滑删除 ===== */
  102. const touchStart = e => {
  103. const idx = e.currentTarget.dataset.index
  104. cardList.value.forEach((v, i) => {
  105. if (i !== idx) v.slideX = 0
  106. })
  107. const row = cardList.value[idx]
  108. row.startX = e.touches[0].pageX
  109. row.slideX = row.slideX || 0
  110. }
  111. const touchMove = e => {
  112. const idx = e.currentTarget.dataset.index
  113. const row = cardList.value[idx]
  114. const delta = e.touches[0].pageX - row.startX
  115. row.slideX = delta < 0 ? Math.max(delta, -70) : Math.min(delta, 0)
  116. }
  117. const touchEnd = e => {
  118. const idx = e.currentTarget.dataset.index
  119. const row = cardList.value[idx]
  120. row.slideX = row.slideX <= -35 ? -70 : 0
  121. }
  122. const deleteItem = (item, idx) => {
  123. // 调用删除接口
  124. uni.$reqDelete('deleteScanOutMaterial', { id: item.id }).then(res => {
  125. if (res.code === 0) {
  126. // 后端返回成功,删除本地数据
  127. cardList.value.splice(idx, 1)
  128. uni.showToast({
  129. title: '删除成功',
  130. icon: 'success'
  131. })
  132. } else {
  133. // 后端返回失败,提示错误信息
  134. uni.showToast({
  135. title: res.data || '删除失败',
  136. icon: 'none'
  137. })
  138. }
  139. }).catch(err => {
  140. uni.showToast({
  141. title: '网络错误',
  142. icon: 'none'
  143. })
  144. })
  145. }
  146. /* 下拉加载更多 */
  147. // onReachBottom(() => {
  148. // // 如果没有更多数据,直接返回不调用接口
  149. // if (!hasMore.value) return
  150. // queryParams.value.pageNo += 1
  151. // uni.$reqGet('getScannedOutSendResourcePage', { ...queryParams.value, id: detailId.value }).then(
  152. // ({ data }) => {
  153. // const list = data?.inoutRequestSubdetailList ?? []
  154. // cardList.value.push(...list)
  155. // // 如果本次返回数据不足10条,标记为没有更多数据
  156. // hasMore.value = list.length >= queryParams.value.pageSize
  157. // }
  158. // )
  159. // })
  160. return { goBack, cardList, touchStart, touchMove, touchEnd, deleteItem }
  161. }
  162. })
  163. </script>
  164. <style lang="scss" scoped>
  165. .gui-header-leader-btns {
  166. color: black;
  167. font-size: 24px !important;
  168. margin-left: 24rpx;
  169. }
  170. .list-content {
  171. margin-top: 80px;
  172. background-color: #edeeee;
  173. }
  174. .card-list-flexbox {
  175. display: flex;
  176. flex-direction: row;
  177. align-items: center;
  178. flex-wrap: wrap;
  179. margin: 3px 2px;
  180. .card-list-item {
  181. width: 750rpx;
  182. min-height: 40px;
  183. margin: 2rpx 0;
  184. display: flex;
  185. flex-direction: row;
  186. align-items: center;
  187. justify-content: space-between;
  188. background-color: #fff;
  189. uni-text {
  190. font-size: 14px;
  191. min-height: 40px;
  192. text-align: left;
  193. padding: 0 12px;
  194. display: flex;
  195. flex-direction: row;
  196. align-items: center;
  197. }
  198. .text-1 {
  199. flex: 1;
  200. min-height: 40px;
  201. justify-content: flex-start;
  202. }
  203. .text-2 {
  204. flex: 3;
  205. min-height: 40px;
  206. justify-content: flex-end;
  207. margin-right: 4px;
  208. padding: 2px 6px;
  209. }
  210. }
  211. .card-list-item:nth-of-type(1) {
  212. .text-1 {
  213. flex: 9;
  214. font-weight: bold;
  215. color: black !important;
  216. }
  217. .text-2 {
  218. flex: 4;
  219. display: flex;
  220. flex-direction: row;
  221. justify-content: flex-end;
  222. align-items: center;
  223. color: limegreen !important;
  224. }
  225. }
  226. }
  227. .font-icons {
  228. width: 40px;
  229. font-size: 20px;
  230. }
  231. .table-title {
  232. height: 40px;
  233. line-height: 40px;
  234. margin: 0 0 4px 0;
  235. padding: 0 12px;
  236. font-size: 16px;
  237. font-weight: bold;
  238. background-color: white;
  239. }
  240. /* 左滑删除样式 */
  241. .scroll-box{ padding: 0 12px; }
  242. .swipe-card {
  243. position: relative;
  244. overflow: hidden; // ✅ 关键
  245. margin-bottom: 8px;
  246. border-radius: 6px;
  247. }
  248. .card-content {
  249. position: relative; // ✅ 关键
  250. z-index: 2;
  251. background: #fff;
  252. transition: transform 0.25s;
  253. width: 100%;
  254. }
  255. .btn-delete {
  256. position: absolute;
  257. right: 0;
  258. top: 0;
  259. bottom: 0;
  260. margin: auto 0; // 上下 auto → 垂直居中
  261. width: 70px;
  262. height: 80rpx; // ✅ 固定高度
  263. display: flex;
  264. align-items: center;
  265. justify-content: center;
  266. background: #e54d42;
  267. color: #fff;
  268. font-size: 14px;
  269. border-radius: 0 6px 6px 0;
  270. z-index: 1;
  271. }
  272. </style>