bad-out-order.vue 7.7 KB

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