StockOutBack.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <template>
  2. <van-nav-bar
  3. title="待返回出库单" left-arrow left-text="返回" fixed placeholder @click-left="goBack()"
  4. />
  5. <van-search v-model="stockBackSearch" placeholder="请输入搜索关键词" @search="searchStockBack" />
  6. <div class="content">
  7. <div class="van-list-stock-in">
  8. <van-list
  9. v-model:loading="loading" class="list-stock-in" :finished="finished" finished-text=""
  10. :immediate-check="false" @load="loadStockOutBackList"
  11. >
  12. <div v-for="(item, index) in stockBackList" :key="item.id" class="list-container">
  13. <van-form :scroll-to-error="true">
  14. <div class="in-header">
  15. <strong>{{ index + 1 }}. {{ item.inventoryName }}</strong>
  16. <van-button type="primary" plain @click="stockOutConfirm(item)">返回</van-button>
  17. </div>
  18. <van-field v-model="item.inventoryNo" name="inventoryNo" label="物料编号:" readonly />
  19. <van-field v-model="item.inventoryName" name="inventoryName" label="物料名称:" readonly />
  20. <van-field v-model="item.inventoryType" name="inventoryType" label="规格型号:" readonly />
  21. <van-field v-model="item.quantity" name="quantity" label="数量:" readonly />
  22. <van-field v-model="item.batchNo" name="batchNo" label="批号:" readonly />
  23. <van-field v-model="item.positionName" name="positionName" label="货位:" readonly />
  24. </van-form>
  25. </div>
  26. </van-list>
  27. </div>
  28. <van-empty v-if="stockBackList.length === 0" description="暂无待返回出库单" />
  29. </div>
  30. </template>
  31. <script setup>
  32. import { ref, onMounted } from 'vue';
  33. import { useRouter } from 'vue-router';
  34. import { processException } from '../common/Common.js';
  35. import { ajaxApiGet, ajaxApiPost } from '../common/utils.js';
  36. import { showFailToast, showSuccessToast, showConfirmDialog } from 'vant';
  37. const router = useRouter();
  38. const stockBackSearch = ref('');
  39. const stockBackList = ref([]);
  40. const loading = ref(false);
  41. const finished = ref(false);
  42. const page = ref(1);
  43. const total = ref(0);
  44. const pageSize = ref(10);
  45. const goBack = () => {
  46. router.push('/app-menus');
  47. };
  48. // 搜索返回物料
  49. const searchStockBack = value => {
  50. page.value = 1;
  51. total.value = 0;
  52. stockBackList.value = [];
  53. loadStockOutBackList();
  54. };
  55. // 返回确认
  56. const stockOutConfirm = item => {
  57. console.log(item, '返回确认');
  58. showConfirmDialog({
  59. title: '确认要返回吗?',
  60. message: '如果确认要返回,请点击【确认】按钮,否则点击【取消】按钮。',
  61. })
  62. .then(() => {
  63. submitStockBack(item.stockOutId);
  64. })
  65. .catch(() => {
  66. console.log('取消');
  67. });
  68. };
  69. // 加载返回出库单列表
  70. const loadStockOutBackList = async () => {
  71. try {
  72. const res = await getList(page.value, pageSize.value);
  73. // 搜索时替换数据,上拉加载时追加数据
  74. stockBackList.value =
  75. page.value === 1
  76. ? res.data
  77. : [...stockBackList.value, ...res.data];
  78. total.value = res.total;
  79. // 检查是否已加载全部数据
  80. if (stockBackList.value.length >= total.value) {
  81. finished.value = true;
  82. } else {
  83. page.value++; // 只有在成功加载后才增加页码
  84. }
  85. } catch (error) {
  86. finished.value = true;
  87. if(error.responseText === '未查询出部分出库的出库单') return;
  88. processException(error);
  89. } finally {
  90. loading.value = false;
  91. }
  92. };
  93. // 获取返回出库单列表API
  94. const getList = (page, pageSize) => {
  95. const start = (page - 1) * pageSize;
  96. const length = pageSize;
  97. const filter = stockBackSearch.value;
  98. const url = `/api/StockOutResource/queryReturnStockOut?start=${start}&length=${length}&filter=${filter}`;
  99. return new Promise((resolve, reject) => {
  100. ajaxApiGet(url).then(
  101. success => {
  102. const { errorCode, errorMessage, datas, total } = success;
  103. if (errorCode === 0) {
  104. if (datas && datas.length) {
  105. resolve({ data: datas, total: total });
  106. } else {
  107. resolve({ data: [], total: 0 });
  108. }
  109. } else {
  110. const error = { status: 200, responseText: errorMessage };
  111. reject(error);
  112. }
  113. },
  114. error => {
  115. reject(error);
  116. },
  117. );
  118. });
  119. };
  120. // 返回API
  121. const submitStockBack = stockOutId => {
  122. const url = `/api/StockOutResource/generateTask?stockOutId=${stockOutId}`;
  123. ajaxApiGet(url).then(
  124. success => {
  125. if (success.errorCode === 0) {
  126. searchStockBack(stockBackSearch.value);
  127. showSuccessToast('返回成功');
  128. } else {
  129. showFailToast(success.errorMessage);
  130. }
  131. },
  132. error => {
  133. processException(error);
  134. },
  135. );
  136. };
  137. onMounted(() => {
  138. loadStockOutBackList();
  139. });
  140. </script>
  141. <style scoped>
  142. .van-search {
  143. padding-bottom: 4px !important;
  144. }
  145. .list-container {
  146. padding: 3px 10px;
  147. border: 1px solid #ccc;
  148. border-radius: 4px;
  149. margin: 6px 12px;
  150. }
  151. .in-header {
  152. display: flex;
  153. justify-content: space-between;
  154. align-items: center;
  155. border-bottom: 1px solid #ccc;
  156. padding-bottom: 3px;
  157. }
  158. .footer-btn {
  159. display: flex;
  160. justify-content: space-around;
  161. align-items: center;
  162. margin-bottom: 10px;
  163. }
  164. </style>