bad-out-order.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  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, computed, onUnmounted } from "vue";
  58. import BadOutCard from "./components/BadOutCard.vue";
  59. import RemarkDialog from "./components/RemarkDialog.vue";
  60. import { onLoad, onShow } 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. });
  87. // #ifdef APP-PLUS
  88. const { unregister } = uni.$u.useEventListener((e) => {
  89. if (e.barcode) {
  90. searchText.value = e.barcode;
  91. onSearch();
  92. }
  93. });
  94. // #endif
  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. onUnmounted(() => {
  165. // #ifdef APP-PLUS
  166. unregister();
  167. // #endif
  168. });
  169. // 确认出库
  170. const onConfirm = () => {
  171. uni.showModal({
  172. title: "确认提示",
  173. content: "是否确认出库?",
  174. success: async (res) => {
  175. if (res.confirm) {
  176. uni.$u.http
  177. .post("/app/stock/outStock", {
  178. orderId: locationInfo.value.orderId,
  179. positionCode: locationInfo.value.positionCode,
  180. outputRemark: locationInfo.value.remark,
  181. })
  182. .then((res) => {
  183. if (res.code == 200) {
  184. uni.showToast({
  185. title: "出库成功",
  186. icon: "success",
  187. });
  188. uni.$u.ttsModule.speak("出库成功");
  189. // 清空数据
  190. searchText.value = "";
  191. locationInfo.value = {
  192. positionCode: "",
  193. waybillCode: "",
  194. orderId: "",
  195. badNum: "",
  196. remark: "",
  197. };
  198. badList.value = [];
  199. } else {
  200. uni.showToast({
  201. title: res.msg,
  202. icon: "none",
  203. });
  204. uni.$u.ttsModule.speak(res.msg);
  205. }
  206. });
  207. }
  208. },
  209. });
  210. };
  211. // 备注弹窗相关
  212. const remarkVisible = ref(false);
  213. const currentRemark = ref("");
  214. const currentEditIndex = ref(-1);
  215. // 打开备注弹窗
  216. const openRemarkDialog = (index, remark = "") => {
  217. currentEditIndex.value = index;
  218. currentRemark.value = remark;
  219. remarkVisible.value = true;
  220. };
  221. // 处理备注确认
  222. const handleRemarkConfirm = (remark) => {
  223. if (currentEditIndex.value >= 0) {
  224. orders.value[currentEditIndex.value].remark = remark;
  225. }
  226. currentEditIndex.value = -1;
  227. currentRemark.value = "";
  228. };
  229. </script>
  230. <style scoped>
  231. .container {
  232. padding-bottom: 120rpx;
  233. }
  234. .error-section {
  235. background-color: #fef0f0;
  236. padding: 20rpx;
  237. border-radius: 8rpx;
  238. margin-bottom: 20rpx;
  239. display: flex;
  240. align-items: center;
  241. }
  242. .error-text {
  243. color: #fa3534;
  244. margin-left: 10rpx;
  245. font-size: 28rpx;
  246. }
  247. .info-section {
  248. background-color: #fff;
  249. padding: 20rpx;
  250. border-radius: 8rpx;
  251. margin-bottom: 20rpx;
  252. }
  253. .info-item {
  254. line-height: 1.8;
  255. }
  256. .list-title {
  257. font-size: 32rpx;
  258. font-weight: bold;
  259. background-color: rgb(222, 134, 143, 0.5);
  260. padding: 10rpx 0;
  261. padding-left: 30rpx;
  262. }
  263. .bad-list {
  264. margin-bottom: 20rpx;
  265. }
  266. .footer {
  267. position: fixed;
  268. bottom: 100rpx;
  269. left: 0;
  270. right: 0;
  271. background-color: #fff;
  272. padding: 20rpx;
  273. }
  274. .btn-group {
  275. display: flex;
  276. justify-content: space-around;
  277. }
  278. .search-wrapper {
  279. position: fixed;
  280. bottom: 0;
  281. left: 0;
  282. right: 0;
  283. background-color: #fff;
  284. padding: 20rpx;
  285. box-shadow: 0 -2rpx 10rpx rgba(0, 0, 0, 0.05);
  286. }
  287. </style>