bad-in.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. <template>
  2. <view class="common-page" style="padding: 0;" @click="playGlobalSound">
  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" v-permission="'app:wms:badIn:submit'"></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 { onShow } from '@dcloudio/uni-app';
  63. import BadItem from './components/BadItem.vue';
  64. import VolumeTTS from '@/utils/VolumeTTS.js'
  65. import RemarkDialog from './components/RemarkDialog.vue'
  66. const waybillCode = ref()
  67. // 表单数据
  68. const formData = reactive({
  69. godownName: '',
  70. godownId: '',
  71. positionCode: ''
  72. });
  73. //点击全局音效
  74. function playGlobalSound(){
  75. uni.$u.playClickSound()
  76. }
  77. // 订单列表
  78. const ordersMap = ref([]);
  79. const codeMap = ref([]); // 记录已扫码的物流单号
  80. //根据扫码的物流单号查询订单详情 /app/stock/searchOrder waybillCode
  81. function getDetailByCode(code) {
  82. if (codeMap.value.includes(code)) {
  83. uni.$u.ttsModule.speak('重复扫描')
  84. return
  85. }
  86. uni.$u.http.get("/app/stock/searchOrder?waybillCode=" + code).then(res => {
  87. if (res.code == 200) {
  88. ordersMap.value.unshift(res.data)
  89. codeMap.value.push(code)
  90. } else if (res.code == 601) {
  91. uni.$u.ttsModule.speak(res.msg)
  92. uni.showModal({
  93. title: '提示',
  94. content: res.msg,
  95. showCancel: false,
  96. success: () => {
  97. playGlobalSound()
  98. }
  99. })
  100. } else {
  101. uni.$u.toast(res.msg)
  102. }
  103. })
  104. }
  105. // 备注弹窗相关
  106. const remarkVisible = ref(false)
  107. const currentRemark = ref('')
  108. const currentEditIndex = ref(-1)
  109. // 方法定义
  110. const goBack = () => {
  111. if (ordersMap.value.length > 0) {
  112. uni.showModal({
  113. title: '退出确认',
  114. content: '是否确认放弃本次入库?',
  115. success: (res) => {
  116. playGlobalSound()
  117. if (res.confirm) {
  118. uni.navigateBack();
  119. }
  120. }
  121. })
  122. } else {
  123. uni.navigateBack();
  124. }
  125. };
  126. const onSubmit = () => {
  127. if (!formData.godownId || !formData.positionCode) {
  128. uni.$u.toast('请先选择仓库和库位')
  129. uni.$u.ttsModule.speak('请先选择仓库和库位')
  130. return
  131. }
  132. uni.showModal({
  133. title: '提交确认',
  134. content: '是否确认提交本次入库?',
  135. success: (res) => {
  136. playGlobalSound()
  137. if (res.confirm) {
  138. handleSubmitConfirm()
  139. }
  140. }
  141. })
  142. }
  143. const handleSubmitConfirm = async () => {
  144. uni.showLoading({
  145. title: '提交中...'
  146. })
  147. let orderInfo = ordersMap.value.map(item => {
  148. return {
  149. orderId: item.orderId,
  150. waybillCode: item.waybillCode,
  151. bookNum: item.badNum,
  152. remark: item.remark
  153. }
  154. })
  155. if (orderInfo.length == 0) {
  156. uni.hideLoading()
  157. uni.$u.ttsModule.speak('请添加订单数据')
  158. return
  159. }
  160. // 提交入库
  161. uni.$u.http.post('/app/stock/addBatch', {
  162. godownId: formData.godownId,
  163. positionCode: formData.positionCode,
  164. orderInfo
  165. }).then(res => {
  166. if (res.code == 200) {
  167. uni.$u.toast('入库成功')
  168. uni.$u.ttsModule.speak('入库成功')
  169. clearData()
  170. } else {
  171. uni.$u.toast(res.msg)
  172. }
  173. }).finally(() => {
  174. uni.hideLoading()
  175. })
  176. }
  177. //成功之后,清空数据
  178. const clearData = () => {
  179. ordersMap.value.length = 0
  180. waybillCode.value = ''
  181. formData.godownName = ''
  182. formData.positionCode = ''
  183. formData.godownId = ''
  184. }
  185. const editOrder = (index) => {
  186. // 编辑订单
  187. openRemarkDialog(index)
  188. };
  189. const openScan = () => {
  190. // 打开扫码器
  191. uni.scanCode({
  192. success: (res) => {
  193. waybillCode.value = res.result
  194. getDetailByCode(res.result)
  195. },
  196. fail: (err) => {
  197. uni.showToast({
  198. title: '扫码失败',
  199. icon: 'error'
  200. });
  201. }
  202. });
  203. };
  204. //选择库位
  205. function selectLocation() {
  206. if (!formData.godownId) {
  207. uni.$u.toast('请先选择仓库')
  208. uni.$u.ttsModule.speak('请先选择仓库')
  209. return
  210. }
  211. //如果有库位,也带过去
  212. uni.navigateTo({
  213. url: "/pages/index/wms/location-select?godownId=" + formData.godownId + "&positionCode=" + formData.positionCode
  214. })
  215. }
  216. // 删除订单
  217. const deleteOrder = (index) => {
  218. ordersMap.value.splice(index, 1);
  219. };
  220. onMounted(() => {
  221. // #ifdef APP-PLUS
  222. uni.$u.useGlobalEvent((e) => {
  223. if (e.barcode) {
  224. waybillCode.value = e.barcode
  225. getDetailByCode(e.barcode)
  226. }
  227. })
  228. // #endif
  229. // 监听库位选择
  230. uni.$on('updateLocation', (locationCode) => {
  231. formData.positionCode = locationCode
  232. })
  233. // 监听仓库选择
  234. uni.$on('updateWarehouse', (data) => {
  235. formData.godownName = data.godownName
  236. formData.godownId = data.id
  237. })
  238. })
  239. onShow(() => {
  240. uni.$u.updateActivePageOnShow()
  241. })
  242. // 记得在页面卸载时移除事件监听
  243. onUnmounted(() => {
  244. uni.$off('updateLocation')
  245. uni.$off('updateWarehouse')
  246. })
  247. // 打开备注弹窗
  248. const openRemarkDialog = (index, remark = '') => {
  249. currentEditIndex.value = index
  250. currentRemark.value = remark
  251. remarkVisible.value = true
  252. }
  253. // 处理备注确认
  254. const handleRemarkConfirm = (remark) => {
  255. if (currentEditIndex.value >= 0) {
  256. ordersMap.value[currentEditIndex.value].remark = remark
  257. }
  258. currentEditIndex.value = -1
  259. currentRemark.value = ''
  260. }
  261. // 打开仓库选择页面
  262. const selectWarehouse = () => {
  263. uni.navigateTo({
  264. url: '/pages/index/wms/warehouse-select?godownId=' + formData.godownId
  265. })
  266. }
  267. </script>
  268. <style scoped>
  269. .content {
  270. padding-top: 44px;
  271. border-radius: 0;
  272. /* #ifdef APP-PLUS */
  273. padding-top: 100px;
  274. /* #endif */
  275. }
  276. .info-section {
  277. background-color: #ffffff;
  278. padding: 15px 20px;
  279. padding-bottom: 5px;
  280. margin-bottom: 12px;
  281. box-sizing: border-box;
  282. }
  283. .order-list {
  284. margin-bottom: 60px;
  285. }
  286. </style>