materialsDetail.vue 8.5 KB

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