bad-out-order.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. <template>
  2. <view class="container" @click="playGlobalSound">
  3. <!-- 搜索框 -->
  4. <u-sticky>
  5. <view class="search-area flex-c mb-20">
  6. <u-search
  7. v-model="searchText"
  8. :placeholder="searchType == '1' ? '请输入订单编号' : '请输入运单号'"
  9. :show-action="false"
  10. :clearabled="true"
  11. @search="onSearch"
  12. height="40"
  13. >
  14. </u-search>
  15. <u-icon name="scan" size="28" color="#19be6b" @click="openScan"></u-icon>
  16. </view>
  17. </u-sticky>
  18. <view class="content">
  19. <!-- 错误提示 -->
  20. <view v-if="errorMsg" class="error-section">
  21. <u-icon name="info-circle" color="#fa3534" size="20"></u-icon>
  22. <text class="error-text">{{ errorMsg }}</text>
  23. </view>
  24. <!-- 基本信息 -->
  25. <template v-if="hasData">
  26. <view class="info-section">
  27. <view class="info-item">库位:{{ locationInfo.positionCode }}</view>
  28. <view class="info-item">物流单号:{{ locationInfo.waybillCode || "-" }}</view>
  29. <view class="info-item">退回物流:{{ locationInfo.refundWaybillCode || "-" }}</view>
  30. <view class="info-item">订单编号:{{ locationInfo.orderId }}</view>
  31. <view class="info-item">订单商品:{{ locationInfo.badNum }}</view>
  32. <view class="info-item">备注信息:{{ locationInfo.remark || "-" }}</view>
  33. </view>
  34. <!-- 极差商品列表 -->
  35. <view class="bad-list">
  36. <view class="list-title mb-6">极差</view>
  37. <view v-for="(item, index) in badList" :key="index">
  38. <BadOutCard :item="item" :index="index" />
  39. </view>
  40. </view>
  41. </template>
  42. </view>
  43. <!-- 底部按钮 -->
  44. <view class="fixed-bottom">
  45. <u-button size="large" type="warning" text="反馈" @click="openRemarkDialog" />
  46. <u-button size="large" type="primary" text="确定出库" @click="onConfirm" />
  47. </view>
  48. <!-- 备注弹窗 -->
  49. <remark-dialog
  50. v-model:visible="remarkVisible"
  51. :initial-value="currentRemark"
  52. @confirm="handleRemarkConfirm"
  53. ></remark-dialog>
  54. </view>
  55. </template>
  56. <script setup>
  57. import { ref, onMounted } from "vue";
  58. import BadOutCard from "./components/BadOutCard.vue";
  59. import RemarkDialog from "./components/RemarkDialog.vue";
  60. import { onLoad, onShow, onUnload } from "@dcloudio/uni-app";
  61. const searchText = ref("");
  62. const searchType = ref("1");
  63. const errorMsg = ref("");
  64. const hasData = ref(false);
  65. // 点击全局音效
  66. function playGlobalSound(){
  67. uni.$u.playClickSound()
  68. }
  69. // 位置信息
  70. const locationInfo = ref({
  71. positionCode: "",
  72. waybillCode: "",
  73. orderId: "",
  74. badNum: "",
  75. remark: "",
  76. refundWaybillCode: "",
  77. });
  78. // 极差商品列表
  79. const badList = ref([]);
  80. onLoad((options) => {
  81. searchType.value = options.searchType || "1";
  82. if (options.searchText) {
  83. searchText.value = options.searchText;
  84. onSearch();
  85. }
  86. // #ifdef APP-PLUS
  87. uni.$u.useGlobalEvent((e) => {
  88. if (e.barcode) {
  89. searchText.value = e.barcode;
  90. onSearch();
  91. }
  92. });
  93. // #endif
  94. });
  95. // 判断搜索类型
  96. const getSearchType = (text) => {
  97. // 这里可以根据实际业务逻辑调整判断条件
  98. // 假设订单号都是纯数字,物流号包含字母
  99. return /^[0-9]+$/.test(text) ? 1 : 2;
  100. };
  101. // 搜索处理
  102. const onSearch = async () => {
  103. if (!searchText.value) {
  104. errorMsg.value = "请输入运单号或订单编号";
  105. hasData.value = false;
  106. return;
  107. }
  108. try {
  109. const res = await uni.$u.http.post("/app/stock/findOrderOutStock", {
  110. search: searchText.value,
  111. searchType: searchType.value,
  112. });
  113. if (res.code == 200) {
  114. const data = res.data;
  115. errorMsg.value = "";
  116. hasData.value = true;
  117. // 更新页面数据
  118. locationInfo.value = {
  119. positionCode: data.positionCode || "",
  120. waybillCode: data.waybillCode || "",
  121. orderId: data.orderId || "",
  122. badNum: data.badNum || "",
  123. remark: data.remark || "",
  124. refundWaybillCode: data.refundWaybillCode || "",
  125. };
  126. badList.value = data.detailVoList || [];
  127. } else {
  128. errorMsg.value = res.msg || "未找到相关数据";
  129. hasData.value = false;
  130. return;
  131. }
  132. } catch (error) {
  133. errorMsg.value = error.message || "获取数据失败";
  134. hasData.value = false;
  135. uni.showToast({
  136. title: "获取数据失败",
  137. icon: "none",
  138. });
  139. }
  140. };
  141. // 打开扫码
  142. const openScan = () => {
  143. // #ifdef APP-PLUS || MP-WEIXIN
  144. uni.scanCode({
  145. success: (res) => {
  146. searchText.value = res.result;
  147. onSearch();
  148. },
  149. fail: (err) => {
  150. uni.showToast({
  151. title: "扫码失败",
  152. icon: "error",
  153. });
  154. },
  155. });
  156. // #endif
  157. // #ifdef H5
  158. uni.showToast({
  159. title: "H5环境不支持扫码",
  160. icon: "none",
  161. });
  162. // #endif
  163. };
  164. onShow(() => {
  165. uni.$u.updateActivePageOnShow();
  166. });
  167. onUnload(() => {
  168. uni.$u.cleanupOnPageUnload();
  169. });
  170. // 确认出库
  171. const onConfirm = () => {
  172. uni.showModal({
  173. title: "确认提示",
  174. content: "是否确认出库?",
  175. success: async (res) => {
  176. if (res.confirm) {
  177. uni.$u.http
  178. .post("/app/stock/outStock", {
  179. orderId: locationInfo.value.orderId,
  180. positionCode: locationInfo.value.positionCode,
  181. outputRemark: locationInfo.value.remark,
  182. })
  183. .then((res) => {
  184. if (res.code == 200) {
  185. uni.showToast({
  186. title: "出库成功",
  187. icon: "success",
  188. });
  189. uni.$u.ttsModule.speak("出库成功");
  190. // 清空数据
  191. searchText.value = "";
  192. locationInfo.value = {
  193. positionCode: "",
  194. waybillCode: "",
  195. orderId: "",
  196. badNum: "",
  197. remark: "",
  198. };
  199. badList.value = [];
  200. } else {
  201. uni.showToast({
  202. title: res.msg,
  203. icon: "none",
  204. });
  205. uni.$u.ttsModule.speak(res.msg);
  206. }
  207. });
  208. }
  209. },
  210. });
  211. };
  212. // 备注弹窗相关
  213. const remarkVisible = ref(false);
  214. const currentRemark = ref("");
  215. const currentEditIndex = ref(-1);
  216. // 打开备注弹窗
  217. const openRemarkDialog = (index, remark = "") => {
  218. currentEditIndex.value = index;
  219. currentRemark.value = remark;
  220. remarkVisible.value = true;
  221. };
  222. // 处理备注确认
  223. const handleRemarkConfirm = (remark) => {
  224. if (currentEditIndex.value >= 0) {
  225. orders.value[currentEditIndex.value].remark = remark;
  226. }
  227. currentEditIndex.value = -1;
  228. currentRemark.value = "";
  229. };
  230. </script>
  231. <style scoped>
  232. .container {
  233. padding-bottom: 120rpx;
  234. }
  235. .error-section {
  236. background-color: #fef0f0;
  237. padding: 20rpx;
  238. border-radius: 8rpx;
  239. margin-bottom: 20rpx;
  240. display: flex;
  241. align-items: center;
  242. }
  243. .error-text {
  244. color: #fa3534;
  245. margin-left: 10rpx;
  246. font-size: 28rpx;
  247. }
  248. .info-section {
  249. background-color: #fff;
  250. padding: 20rpx;
  251. border-radius: 8rpx;
  252. margin-bottom: 20rpx;
  253. }
  254. .info-item {
  255. line-height: 1.8;
  256. }
  257. .list-title {
  258. font-size: 32rpx;
  259. font-weight: bold;
  260. background-color: rgb(222, 134, 143, 0.5);
  261. padding: 10rpx 0;
  262. padding-left: 30rpx;
  263. }
  264. .bad-list {
  265. margin-bottom: 20rpx;
  266. }
  267. .footer {
  268. position: fixed;
  269. bottom: 100rpx;
  270. left: 0;
  271. right: 0;
  272. background-color: #fff;
  273. padding: 20rpx;
  274. }
  275. .btn-group {
  276. display: flex;
  277. justify-content: space-around;
  278. }
  279. .search-wrapper {
  280. position: fixed;
  281. bottom: 0;
  282. left: 0;
  283. right: 0;
  284. background-color: #fff;
  285. padding: 20rpx;
  286. box-shadow: 0 -2rpx 10rpx rgba(0, 0, 0, 0.05);
  287. }
  288. </style>