bad-out-order.vue 8.7 KB

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