materialsDetail.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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. onBeforeMount(() => {
  78. detailId.value = JSON.parse(parentRow)?.id
  79. })
  80. onMounted(() => {
  81. search()
  82. })
  83. const search = () => {
  84. uni.$reqGet('getScannedInSendResourcePage', { ...queryParams.value, id: detailId.value }).then(
  85. ({ data }) => {
  86. cardList.value = data?.inRequestSubdetailList ?? []
  87. }
  88. )
  89. }
  90. const goBack = () => {
  91. uni.removeStorageSync('mixMaterialDetail')
  92. uni.$goBack('/pages/workbranch/warehouse/scanInOut/In/scannedMaterials')
  93. }
  94. /* ===== 左滑删除 ===== */
  95. const touchStart = e => {
  96. const idx = e.currentTarget.dataset.index
  97. cardList.value.forEach((v, i) => {
  98. if (i !== idx) v.slideX = 0
  99. })
  100. const row = cardList.value[idx]
  101. row.startX = e.touches[0].pageX
  102. row.slideX = row.slideX || 0
  103. }
  104. const touchMove = e => {
  105. const idx = e.currentTarget.dataset.index
  106. const row = cardList.value[idx]
  107. const delta = e.touches[0].pageX - row.startX
  108. row.slideX = delta < 0 ? Math.max(delta, -70) : Math.min(delta, 0)
  109. }
  110. const touchEnd = e => {
  111. const idx = e.currentTarget.dataset.index
  112. const row = cardList.value[idx]
  113. row.slideX = row.slideX <= -35 ? -70 : 0
  114. }
  115. const deleteItem = (item, idx) => {
  116. // 调用删除接口
  117. uni.$reqDelete('deleteScanInMaterial', { id: item.id }).then(res => {
  118. if (res.code === 0) {
  119. // 后端返回成功,删除本地数据
  120. cardList.value.splice(idx, 1)
  121. uni.showToast({
  122. title: '删除成功',
  123. icon: 'success'
  124. })
  125. } else {
  126. // 后端返回失败,提示错误信息
  127. uni.showToast({
  128. title: res.data || '删除失败',
  129. icon: 'none'
  130. })
  131. }
  132. }).catch(err => {
  133. uni.showToast({
  134. title: '网络错误',
  135. icon: 'none'
  136. })
  137. })
  138. }
  139. /* 下拉加载更多 */
  140. onReachBottom(() => {
  141. queryParams.value.pageNo += 1
  142. uni.$reqGet('getScannedInSendResourcePage', { ...queryParams.value, id: detailId.value }).then(
  143. ({ data }) => {
  144. cardList.value.push(...(data?.inRequestSubdetailList ?? []))
  145. }
  146. )
  147. })
  148. return { goBack, cardList, touchStart, touchMove, touchEnd, deleteItem }
  149. }
  150. })
  151. </script>
  152. <style lang="scss" scoped>
  153. .gui-header-leader-btns {
  154. color: black;
  155. font-size: 24px !important;
  156. margin-left: 24rpx;
  157. }
  158. .list-content {
  159. margin-top: 80px;
  160. background-color: #edeeee;
  161. }
  162. .card-list-flexbox {
  163. display: flex;
  164. flex-direction: row;
  165. align-items: center;
  166. flex-wrap: wrap;
  167. margin: 3px 2px;
  168. .card-list-item {
  169. width: 750rpx;
  170. min-height: 40px;
  171. margin: 2rpx 0;
  172. display: flex;
  173. flex-direction: row;
  174. align-items: center;
  175. justify-content: space-between;
  176. background-color: #fff;
  177. uni-text {
  178. font-size: 14px;
  179. min-height: 40px;
  180. text-align: left;
  181. padding: 0 12px;
  182. display: flex;
  183. flex-direction: row;
  184. align-items: center;
  185. }
  186. .text-1 {
  187. flex: 1;
  188. min-height: 40px;
  189. justify-content: flex-start;
  190. }
  191. .text-2 {
  192. flex: 3;
  193. min-height: 40px;
  194. justify-content: flex-end;
  195. margin-right: 4px;
  196. padding: 2px 6px;
  197. }
  198. }
  199. .card-list-item:nth-of-type(1) {
  200. .text-1 {
  201. flex: 9;
  202. font-weight: bold;
  203. color: black !important;
  204. }
  205. .text-2 {
  206. flex: 4;
  207. display: flex;
  208. flex-direction: row;
  209. justify-content: flex-end;
  210. align-items: center;
  211. color: limegreen !important;
  212. }
  213. }
  214. }
  215. .font-icons {
  216. width: 40px;
  217. font-size: 20px;
  218. }
  219. .table-title {
  220. height: 40px;
  221. line-height: 40px;
  222. margin: 0 0 4px 0;
  223. padding: 0 12px;
  224. font-size: 16px;
  225. font-weight: bold;
  226. background-color: white;
  227. }
  228. /* 左滑删除样式 */
  229. .scroll-box{ padding: 0 12px; }
  230. .swipe-card {
  231. position: relative;
  232. overflow: hidden; // ✅ 关键
  233. margin-bottom: 8px;
  234. border-radius: 6px;
  235. }
  236. .card-content {
  237. position: relative; // ✅ 关键
  238. z-index: 2;
  239. background: #fff;
  240. transition: transform 0.25s;
  241. width: 100%;
  242. }
  243. .btn-delete {
  244. position: absolute;
  245. right: 0;
  246. top: 0;
  247. bottom: 0;
  248. margin: auto 0; // 上下 auto → 垂直居中
  249. width: 70px;
  250. height: 80rpx; // ✅ 固定高度
  251. display: flex;
  252. align-items: center;
  253. justify-content: center;
  254. background: #e54d42;
  255. color: #fff;
  256. font-size: 14px;
  257. border-radius: 0 6px 6px 0;
  258. z-index: 1;
  259. }
  260. </style>