bad-in.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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 {
  86. uni.$u.toast(res.msg)
  87. uni.$u.ttsModule.speak(res.msg)
  88. }
  89. })
  90. }
  91. // 备注弹窗相关
  92. const remarkVisible = ref(false)
  93. const currentRemark = ref('')
  94. const currentEditIndex = ref(-1)
  95. // 方法定义
  96. const goBack = () => {
  97. uni.showModal({
  98. title: '退出确认',
  99. content: '是否确认放弃本次入库?',
  100. success: (res) => {
  101. if (res.confirm) {
  102. uni.navigateBack();
  103. }
  104. }
  105. })
  106. };
  107. const onSubmit = () => {
  108. if (!formData.godownId || !formData.positionCode) {
  109. uni.$u.toast('请先选择仓库和库位')
  110. uni.$u.ttsModule.speak('请先选择仓库和库位')
  111. return
  112. }
  113. uni.showModal({
  114. title: '提交确认',
  115. content: '是否确认提交本次入库?',
  116. success: (res) => {
  117. if (res.confirm) {
  118. handleSubmitConfirm()
  119. }
  120. }
  121. })
  122. }
  123. const handleSubmitConfirm = async () => {
  124. uni.showLoading({
  125. title: '提交中...'
  126. })
  127. let orderInfo = ordersMap.value.map(item => {
  128. return {
  129. orderId: item.orderId,
  130. waybillCode: item.waybillCode,
  131. bookNum: item.badNum,
  132. remark: item.remark
  133. }
  134. })
  135. if (orderInfo.length == 0) {
  136. uni.hideLoading()
  137. uni.$u.ttsModule.speak('请添加订单数据')
  138. return
  139. }
  140. // 提交入库
  141. uni.$u.http.post('/app/stock/addBatch', {
  142. godownId: formData.godownId,
  143. positionCode: formData.positionCode,
  144. orderInfo
  145. }).then(res => {
  146. if (res.code == 200) {
  147. uni.$u.toast('入库成功')
  148. uni.$u.ttsModule.speak('入库成功')
  149. clearData()
  150. } else {
  151. uni.$u.toast(res.msg)
  152. }
  153. }).finally(() => {
  154. uni.hideLoading()
  155. })
  156. }
  157. //成功之后,清空数据
  158. const clearData = () => {
  159. ordersMap.value.length = 0
  160. waybillCode.value = ''
  161. formData.godownName = ''
  162. formData.positionCode = ''
  163. formData.godownId = ''
  164. }
  165. const editOrder = (index) => {
  166. // 编辑订单
  167. openRemarkDialog(index)
  168. };
  169. const openScan = () => {
  170. // 打开扫码器
  171. uni.scanCode({
  172. scanType: ['barCode'],
  173. success: (res) => {
  174. getDetailByCode(res.result)
  175. },
  176. fail: (err) => {
  177. uni.showToast({
  178. title: '扫码失败',
  179. icon: 'error'
  180. });
  181. }
  182. });
  183. };
  184. //选择库位
  185. function selectLocation() {
  186. if (!formData.godownId) {
  187. uni.$u.toast('请先选择仓库')
  188. uni.$u.ttsModule.speak('请先选择仓库')
  189. return
  190. }
  191. //如果有库位,也带过去
  192. uni.navigateTo({
  193. url: "/pages/index/wms/location-select?godownId=" + formData.godownId + "&positionCode=" + formData.positionCode
  194. })
  195. }
  196. // 删除订单
  197. const deleteOrder = (index) => {
  198. ordersMap.value.splice(index, 1);
  199. };
  200. onMounted(() => {
  201. // #ifdef APP-PLUS
  202. uni.$u.useGlobalEvent((e) => {
  203. if (e.barcode) {
  204. getDetailByCode(e.barcode)
  205. }
  206. })
  207. // #endif
  208. // 监听库位选择
  209. uni.$on('updateLocation', (locationCode) => {
  210. formData.positionCode = locationCode
  211. })
  212. // 监听仓库选择
  213. uni.$on('updateWarehouse', (data) => {
  214. formData.godownName = data.godownName
  215. formData.godownId = data.id
  216. })
  217. })
  218. // 记得在页面卸载时移除事件监听
  219. onUnmounted(() => {
  220. uni.$off('updateLocation')
  221. uni.$off('updateWarehouse')
  222. })
  223. // 打开备注弹窗
  224. const openRemarkDialog = (index, remark = '') => {
  225. currentEditIndex.value = index
  226. currentRemark.value = remark
  227. remarkVisible.value = true
  228. }
  229. // 处理备注确认
  230. const handleRemarkConfirm = (remark) => {
  231. if (currentEditIndex.value >= 0) {
  232. ordersMap.value[currentEditIndex.value].remark = remark
  233. }
  234. currentEditIndex.value = -1
  235. currentRemark.value = ''
  236. }
  237. // 打开仓库选择页面
  238. const selectWarehouse = () => {
  239. uni.navigateTo({
  240. url: '/pages/index/wms/warehouse-select?godownId=' + formData.godownId
  241. })
  242. }
  243. </script>
  244. <style scoped>
  245. .content {
  246. padding-top: 44px;
  247. border-radius: 0;
  248. }
  249. .info-section {
  250. background-color: #ffffff;
  251. padding: 15px 20px;
  252. padding-bottom: 5px;
  253. margin-bottom: 12px;
  254. box-sizing: border-box;
  255. }
  256. .order-list {
  257. margin-bottom: 60px;
  258. }
  259. </style>