bad-in.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. <template>
  2. <view class="common-page" style="padding: 0;">
  3. <!-- 顶部导航栏 -->
  4. <view class="header">
  5. <u-navbar title="不良入库" :border="false" fixed safe-area-inset-top>
  6. <template #left>
  7. <u-icon name="arrow-left" color="#333333" size="20" @click="goBack"></u-icon>
  8. </template>
  9. <template #right>
  10. <u-text type="primary" text="提交" @click="onSubmit"></u-text>
  11. </template>
  12. </u-navbar>
  13. </view>
  14. <!-- 主要内容区域 -->
  15. <view class="content">
  16. <!-- 订单基本信息 -->
  17. <view class="info-section">
  18. <u-form :model="formData" ref="formRef" label-width="80px" label-position="left">
  19. <u-form-item label="订单总数" required>
  20. <span>{{ ordersMap.length }}</span>
  21. </u-form-item>
  22. <u-form-item label="仓库" required>
  23. <view @click="selectWarehouse" style="width: 100%;">
  24. <u-input v-model="formData.godownName" readonly custom-style="font-size:32rpx"
  25. placeholder="请选择仓库" suffixIcon="arrow-right" />
  26. </view>
  27. </u-form-item>
  28. <u-form-item label="库位" required>
  29. <view @click="selectLocation" style="width: 100%;">
  30. <u-input v-model="formData.positionCode" readonly custom-style="font-size:32rpx"
  31. placeholder="请选择库位" suffixIcon="arrow-right" />
  32. </view>
  33. </u-form-item>
  34. </u-form>
  35. </view>
  36. <!-- 订单列表 -->
  37. <view class="order-list">
  38. <bad-item v-for="(order, index) in ordersMap" :key="index" :data="order" @delete="deleteOrder(index)"
  39. @edit="editOrder(index)"></bad-item>
  40. </view>
  41. <!-- 底部扫码输入框 -->
  42. <view class="fixed-bottom pad-20" style="background: #ffffff;">
  43. <u-search placeholder="请输入物流单号" :searchIconSize="24" bgColor="#f6f7f6"
  44. @search="getDetailByCode(waybillCode)" v-model="waybillCode" custom-style="font-size:32rpx"
  45. placeholder-style="font-size:32rpx" :clearabled="true" :focus="false" :showAction="false"
  46. :height="42"></u-search>
  47. <u-icon name="scan" size="32" color="#19be6b" @click="openScan"></u-icon>
  48. </view>
  49. </view>
  50. <!-- 备注弹窗 -->
  51. <remark-dialog v-model:visible="remarkVisible" :initial-value="currentRemark"
  52. @confirm="handleRemarkConfirm"></remark-dialog>
  53. </view>
  54. </template>
  55. <script setup>
  56. import {
  57. ref,
  58. reactive,
  59. onMounted,
  60. onUnmounted
  61. } from 'vue';
  62. import BadItem from './components/BadItem.vue';
  63. import VolumeTTS from '@/utils/VolumeTTS.js'
  64. import RemarkDialog from './components/RemarkDialog.vue'
  65. const waybillCode = ref()
  66. // 表单数据
  67. const formData = reactive({
  68. godownName: '',
  69. godownId: '',
  70. positionCode: ''
  71. });
  72. // 订单列表
  73. const ordersMap = ref([]);
  74. const codeMap = ref([]); // 记录已扫码的物流单号
  75. //根据扫码的物流单号查询订单详情 /app/stock/searchOrder waybillCode
  76. function getDetailByCode(code) {
  77. if (codeMap.value.includes(code)) {
  78. uni.$u.ttsModule.speak('重复扫描')
  79. return
  80. }
  81. uni.$u.http.get("/app/stock/searchOrder?waybillCode=" + code).then(res => {
  82. if (res.code == 200) {
  83. ordersMap.value.unshift(res.data)
  84. codeMap.value.push(code)
  85. } else if (res.code == 601) {
  86. uni.$u.ttsModule.speak(res.msg)
  87. uni.showModal({
  88. title: '提示',
  89. content: res.msg,
  90. showCancel: false,
  91. })
  92. } else {
  93. uni.$u.toast(res.msg)
  94. }
  95. })
  96. }
  97. // 备注弹窗相关
  98. const remarkVisible = ref(false)
  99. const currentRemark = ref('')
  100. const currentEditIndex = ref(-1)
  101. // 方法定义
  102. const goBack = () => {
  103. if (ordersMap.value.length > 0) {
  104. uni.showModal({
  105. title: '退出确认',
  106. content: '是否确认放弃本次入库?',
  107. success: (res) => {
  108. if (res.confirm) {
  109. uni.navigateBack();
  110. }
  111. }
  112. })
  113. } else {
  114. uni.navigateBack();
  115. }
  116. };
  117. const onSubmit = () => {
  118. if (!formData.godownId || !formData.positionCode) {
  119. uni.$u.toast('请先选择仓库和库位')
  120. uni.$u.ttsModule.speak('请先选择仓库和库位')
  121. return
  122. }
  123. uni.showModal({
  124. title: '提交确认',
  125. content: '是否确认提交本次入库?',
  126. success: (res) => {
  127. if (res.confirm) {
  128. handleSubmitConfirm()
  129. }
  130. }
  131. })
  132. }
  133. const handleSubmitConfirm = async () => {
  134. uni.showLoading({
  135. title: '提交中...'
  136. })
  137. let orderInfo = ordersMap.value.map(item => {
  138. return {
  139. orderId: item.orderId,
  140. waybillCode: item.waybillCode,
  141. bookNum: item.badNum,
  142. remark: item.remark
  143. }
  144. })
  145. if (orderInfo.length == 0) {
  146. uni.hideLoading()
  147. uni.$u.ttsModule.speak('请添加订单数据')
  148. return
  149. }
  150. // 提交入库
  151. uni.$u.http.post('/app/stock/addBatch', {
  152. godownId: formData.godownId,
  153. positionCode: formData.positionCode,
  154. orderInfo
  155. }).then(res => {
  156. if (res.code == 200) {
  157. uni.$u.toast('入库成功')
  158. uni.$u.ttsModule.speak('入库成功')
  159. clearData()
  160. } else {
  161. uni.$u.toast(res.msg)
  162. }
  163. }).finally(() => {
  164. uni.hideLoading()
  165. })
  166. }
  167. //成功之后,清空数据
  168. const clearData = () => {
  169. ordersMap.value.length = 0
  170. waybillCode.value = ''
  171. formData.godownName = ''
  172. formData.positionCode = ''
  173. formData.godownId = ''
  174. }
  175. const editOrder = (index) => {
  176. // 编辑订单
  177. openRemarkDialog(index)
  178. };
  179. const openScan = () => {
  180. // 打开扫码器
  181. uni.scanCode({
  182. scanType: ['barCode'],
  183. success: (res) => {
  184. getDetailByCode(res.result)
  185. },
  186. fail: (err) => {
  187. uni.showToast({
  188. title: '扫码失败',
  189. icon: 'error'
  190. });
  191. }
  192. });
  193. };
  194. //选择库位
  195. function selectLocation() {
  196. if (!formData.godownId) {
  197. uni.$u.toast('请先选择仓库')
  198. uni.$u.ttsModule.speak('请先选择仓库')
  199. return
  200. }
  201. //如果有库位,也带过去
  202. uni.navigateTo({
  203. url: "/pages/index/wms/location-select?godownId=" + formData.godownId + "&positionCode=" + formData.positionCode
  204. })
  205. }
  206. // 删除订单
  207. const deleteOrder = (index) => {
  208. ordersMap.value.splice(index, 1);
  209. };
  210. onMounted(() => {
  211. // #ifdef APP-PLUS
  212. uni.$u.useGlobalEvent((e) => {
  213. if (e.barcode) {
  214. getDetailByCode(e.barcode)
  215. }
  216. })
  217. // #endif
  218. // 监听库位选择
  219. uni.$on('updateLocation', (locationCode) => {
  220. formData.positionCode = locationCode
  221. })
  222. // 监听仓库选择
  223. uni.$on('updateWarehouse', (data) => {
  224. formData.godownName = data.godownName
  225. formData.godownId = data.id
  226. })
  227. })
  228. // 记得在页面卸载时移除事件监听
  229. onUnmounted(() => {
  230. uni.$off('updateLocation')
  231. uni.$off('updateWarehouse')
  232. })
  233. // 打开备注弹窗
  234. const openRemarkDialog = (index, remark = '') => {
  235. currentEditIndex.value = index
  236. currentRemark.value = remark
  237. remarkVisible.value = true
  238. }
  239. // 处理备注确认
  240. const handleRemarkConfirm = (remark) => {
  241. if (currentEditIndex.value >= 0) {
  242. ordersMap.value[currentEditIndex.value].remark = remark
  243. }
  244. currentEditIndex.value = -1
  245. currentRemark.value = ''
  246. }
  247. // 打开仓库选择页面
  248. const selectWarehouse = () => {
  249. uni.navigateTo({
  250. url: '/pages/index/wms/warehouse-select?godownId=' + formData.godownId
  251. })
  252. }
  253. </script>
  254. <style scoped>
  255. .content {
  256. padding-top: 44px;
  257. border-radius: 0;
  258. }
  259. .info-section {
  260. background-color: #ffffff;
  261. padding: 15px 20px;
  262. padding-bottom: 5px;
  263. margin-bottom: 12px;
  264. box-sizing: border-box;
  265. }
  266. .order-list {
  267. margin-bottom: 60px;
  268. }
  269. </style>