index.vue 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857
  1. <template>
  2. <div class="container">
  3. <van-nav-bar title="智能仓收货" left-arrow fixed placeholder @click-left="goBack">
  4. <template #left>
  5. <van-icon name="arrow-left" size="25" />
  6. <div style="color: #fff">返回</div>
  7. </template>
  8. </van-nav-bar>
  9. <div class="take-delivery">
  10. <div class="take-info">
  11. <div class="take-info-no">
  12. <div class="info-no-title">
  13. <div>任务号:{{ taskInfo.taskNo || '--' }}</div>
  14. <div>
  15. <van-button type="primary" size="mini" plain @click="switchTask">切换任务</van-button>
  16. </div>
  17. </div>
  18. <div class="info-no-tips">
  19. <div>货主:<span style="color: #333;font-weight: bold;">{{ taskInfo.customerName || '--' }}</span></div>
  20. <div>任务数:<span style="color: #0077ff;font-weight: bold;">{{ taskInfo.receivedQty || 0 }}/{{ taskInfo.expectedQty || 0}}</span></div>
  21. </div>
  22. </div>
  23. <div class="take-info-number">
  24. <div class="info-number-left">
  25. <div class="number-left-box">
  26. <div>开始时间:</div>
  27. <div class="left-box-title">{{ currentTime }}</div>
  28. </div>
  29. <div class="number-left-box">
  30. <div>已用时:</div>
  31. <div class="left-box-title">{{ formattedTime }}</div>
  32. </div>
  33. </div>
  34. </div>
  35. </div>
  36. <van-progress v-if="taskInfo.receivedQty/taskInfo.expectedQty>=0" :percentage="((taskInfo.receivedQty/taskInfo.expectedQty)*100).toFixed(2)" stroke-width="4" />
  37. <div class="take-barcode">
  38. <div class="barcode-input">
  39. <van-search
  40. ref="searchRef"
  41. v-model.lazy="searchBarcode"
  42. placeholder="请扫描商品条码"
  43. @search="_handlerScan(searchBarcode)"
  44. label="商品条码:"
  45. left-icon=""
  46. :class="[scanType===2?'search-input-barcode':'','van-hairline--bottom']"
  47. @focus="scanType=2"
  48. autocomplete="off"
  49. @input="onAsnCancel"
  50. @clear="reset"
  51. >
  52. </van-search>
  53. </div>
  54. <div class="barcode-input">
  55. <van-search
  56. ref="containerNoRef"
  57. v-model.lazy="containerNo"
  58. placeholder="请扫描库位号"
  59. @search="_handlerScan(containerNo)"
  60. label="&nbsp;&nbsp;&nbsp;&nbsp;库位号:"
  61. left-icon=""
  62. :class="[scanType===5?'search-input-barcode':'','van-hairline--bottom']"
  63. @focus="scanType=5"
  64. autocomplete="off"
  65. @input="onAsnCancel"
  66. >
  67. </van-search>
  68. </div>
  69. <div class="barcode-input">
  70. <van-search
  71. ref="numberRef"
  72. v-model="searchCount"
  73. placeholder="请输入收货数量"
  74. type="number"
  75. label="收货数量:"
  76. left-icon=""
  77. autocomplete="off"
  78. show-action
  79. :min="1"
  80. :max="asnInfo.asnNo?asnInfo.expectedQuantity-asnInfo.receivedQuantity:10000"
  81. @search="isCheck()"
  82. :class="[scanType===4?'search-input-barcode':'','van-hairline--bottom']"
  83. @focus="scanType=4"
  84. >
  85. <template #action>
  86. <div style="display: flex; align-items: center;flex-direction: column;margin-left: 20px"
  87. v-if="asnInfo.asnNo">
  88. <div style="height: 20px;font-size: 12px">已收/预计</div>
  89. <div style="font-size: 16px;font-weight: bold">{{ asnInfo.receivedQuantity}}/{{ asnInfo.expectedQuantity }}
  90. </div>
  91. </div>
  92. </template>
  93. </van-search>
  94. </div>
  95. </div>
  96. <div class="take-lot" v-if="lotData.length>0">
  97. <van-cell-group>
  98. <div class="take-lot-title">批次信息</div>
  99. <van-cell v-for="(item,i) in lotData" :key="i" :is-link="item.field!=='lotAtt05'"
  100. @click="onLot(item)">
  101. <template #title>
  102. <van-icon v-if="item.require" name="warning-o" color="#ed6a0c" />
  103. <span class="custom-title">{{ item.label }}</span>
  104. </template>
  105. <template #value>
  106. <div>{{ item.mapping }}</div>
  107. </template>
  108. </van-cell>
  109. </van-cell-group>
  110. </div>
  111. <div class="take-button">
  112. <van-button type="primary" size="large" round style="height: 36px" @click="onConfirm">完成收货</van-button>
  113. </div>
  114. </div>
  115. </div>
  116. <!-- 条码输入组件 -->
  117. <input-barcode :back="back" @setBarcode="setBarcode" ref="inputBarcodeRef" />
  118. <!-- 单据选择-->
  119. <van-action-sheet v-model:show="asnDetailsTrueFalseBy" cancel-text="取消" description="请选择具体单据" close-on-click-action>
  120. <van-cell-group>
  121. <van-cell v-for="item in asnDetailsList" @click="onDetailActive(item)">
  122. <template #title>
  123. {{ item.asnNo }}({{ item.customerId }}-{{ item.expectedQuantity }}件)
  124. </template>
  125. </van-cell>
  126. </van-cell-group>
  127. </van-action-sheet>
  128. <!-- 商品物理属性-->
  129. <attribute ref="attributeRef" @set-attribute="setAttribute" />
  130. <!-- 商品批次属性-->
  131. <lot-date ref="lotDateRef" @select-lot-date="selectLotDate" />
  132. <!-- 唯一码-->
  133. <unique-code-input ref="uniqueCodeRef"
  134. v-model:uniqueCodeList="uniqueCodeList"
  135. v-model:scanType="scanType"
  136. v-model:checkAllType="checkAllType"
  137. :searchCount="searchCount"
  138. :asnInfo="asnInfo"
  139. @setUniqueCode="onConfirm"
  140. />
  141. <van-action-sheet
  142. v-model:show="lotQualityTrueFalseBy"
  143. cancel-text="取消"
  144. close-on-click-action
  145. description="请选择质量状态"
  146. >
  147. <van-cell-group>
  148. <van-cell v-for="(value,key) in lotQualityMap" @click="onSelectLotQuality(key)">
  149. <template #title>
  150. {{value}}
  151. </template>
  152. </van-cell>
  153. </van-cell-group>
  154. </van-action-sheet>
  155. </template>
  156. <script setup>
  157. import { onMounted, onUnmounted, ref } from 'vue'
  158. import { androidFocus, getHeader, goBack, scanError, scanSuccess } from '@/utils/android'
  159. import InputBarcode from '@/views/outbound/picking/components/InputBarcode.vue'
  160. import { closeListener, openListener, scanInit } from '@/utils/keydownListener'
  161. import { useRouter } from 'vue-router'
  162. import {
  163. calculateShelfLife, getCommodityRule,
  164. getIReceivingTask,
  165. getProductAttribute, getProductLot,
  166. getReceivingAsnDetails, setBotReceiving,
  167. setProductAttribute,
  168. } from '@/api/takeDelivery/index'
  169. import { closeLoading, showLoading } from '@/utils/loading'
  170. import { useStore } from '@/store/modules/user'
  171. import { showNotify, showToast } from 'vant'
  172. import { isAttribute } from '@/views/inbound/takeDelivery/task/hooks/attribute'
  173. import Attribute from '@/views/inbound/takeDelivery/components/Attribute.vue'
  174. import LotDate from '@/views/inbound/takeDelivery/components/LotDate.vue'
  175. import UniqueCodeInput from '@/views/inbound/takeDelivery/components/UniqueCodeInput.vue'
  176. import { barcodeToUpperCase, toMap } from '@/utils/dataType'
  177. import { getCurrentTime } from '@/utils/date'
  178. const router = useRouter()
  179. const store = useStore()
  180. try {
  181. getHeader()
  182. androidFocus()
  183. } catch (error) {
  184. router.push('/login')
  185. }
  186. const warehouse = store.warehouse
  187. //开单任务号
  188. const taskNo = ref('')
  189. //容器号
  190. const containerNo = ref('')
  191. //商品条码
  192. const searchBarcode = ref('')
  193. //收货数量
  194. const searchCount = ref('')
  195. //收货详情
  196. const taskInfo = ref({ receivedQty: 0, expectedQty: 0 })
  197. //开始时间
  198. const currentTime = ref('--')
  199. const scanType = ref(2)
  200. const type=localStorage.getItem('checkAllType')?JSON.parse(localStorage.getItem('checkAllType')):true
  201. const checkAllType=ref(type)
  202. // 页面初始化
  203. onMounted(() => {
  204. openListener()
  205. scanInit(_handlerScan)
  206. loadData()
  207. })
  208. /**
  209. * 计算时分秒
  210. */
  211. // 时器的总秒数
  212. let totalSeconds = ref(0)
  213. //时分秒
  214. const formattedTime = ref('00:00:00')
  215. let windowTimer = null // 计时器的引用
  216. const updateFormattedTime = () => {
  217. let hours = Math.floor(totalSeconds.value / 3600)
  218. let minutes = Math.floor((totalSeconds.value % 3600) / 60)
  219. let seconds = totalSeconds.value % 60
  220. formattedTime.value = `${String(hours).padStart(2, '0')}:${String(minutes).padStart(2, '0')}:${String(seconds).padStart(2, '0')}`
  221. }
  222. // 启动计时器
  223. const startTimer = () => {
  224. if (!windowTimer) {
  225. windowTimer = setInterval(() => {
  226. totalSeconds.value++
  227. updateFormattedTime()
  228. }, 1000)
  229. }
  230. }
  231. // 停止计时器
  232. const stopTimer = () => {
  233. if (windowTimer) {
  234. clearInterval(windowTimer)
  235. windowTimer = null
  236. }
  237. }
  238. const back = ref(true)
  239. const inputBarcodeType = ref('task')
  240. //输入框组件
  241. const inputBarcodeRef = ref(null)
  242. const oldSearchBarcode = ref('')
  243. // 设置容器号
  244. const setBarcode = (code, type) => {
  245. if (inputBarcodeType.value === 'lot') {
  246. lotData.value.forEach((lot) => {
  247. if (lot.field == lotField.value) {
  248. lot.mapping = code
  249. }
  250. })
  251. return
  252. }
  253. showLoading()
  254. if(!type){ //切换任务时初始化计时器
  255. stopTimer()
  256. formattedTime.value="00:00:00"
  257. totalSeconds.value=0
  258. }
  259. getIReceivingTask({ taskNo:code,version:'V6',warehouse }).then(res=>{
  260. back.value = true
  261. if(res.data.receivedQty==res.data.expectedQty && res.data.expectedQty>0 ){
  262. if(type){
  263. reset()
  264. taskNo.value=''
  265. taskInfo.value={}
  266. switchTask()
  267. }else {
  268. taskInfo.value=res.data
  269. taskNo.value=code
  270. }
  271. containerNo.value=''
  272. stopTimer()
  273. }else {
  274. if(!type){//切换任务成功重启计时器
  275. currentTime.value=getCurrentTime()
  276. startTimer()
  277. containerNo.value=''
  278. }
  279. taskInfo.value=res.data
  280. taskNo.value=code
  281. }
  282. scanType.value=2
  283. uniqueCodeList.value=[]
  284. scanSuccess()
  285. }).catch(err=>{
  286. inputBarcodeRef.value?.show('', '请扫描开单任务号',err.message)
  287. scanError()
  288. }).finally(()=>{
  289. reset()
  290. closeLoading()
  291. })
  292. }
  293. // setBarcode('BSSH20250605000006')
  294. //切换任务
  295. const switchTask = () => {
  296. inputBarcodeType.value = 'switchTask'
  297. back.value = false
  298. inputBarcodeRef.value?.show('', `请扫描开单任务号`,'')
  299. }
  300. //asn单多条明细展示
  301. const asnDetailsTrueFalseBy = ref(false)
  302. const asnDetailsList = ref([])
  303. const asnInfo = ref({})
  304. const reset = () => {
  305. asnInfo.value = {}
  306. lotData.value = []
  307. searchCount.value = ''
  308. searchBarcode.value = ''
  309. oldSearchBarcode.value = ''
  310. containerNo.value=''
  311. uniqueCodeList.value = []
  312. }
  313. // 选择单据
  314. const onDetailActive = (item) => {
  315. asnInfo.value = item
  316. asnDetailsTrueFalseBy.value = false
  317. searchCount.value=1
  318. scanType.value=5
  319. // searchCount.value = asnInfo.value.expectedQuantity - asnInfo.value.receivedQuantity
  320. _getProductAttribute(item)
  321. _getProductLot(item)
  322. _getCommodityRule(item)
  323. }
  324. const onAsnCancel = () => {
  325. if (searchBarcode.value === '' || (oldSearchBarcode.value.length != searchBarcode.value.length && oldSearchBarcode.value != '')) {
  326. asnInfo.value = {}
  327. lotData.value = []
  328. searchCount.value = ''
  329. containerNo.value=''
  330. }
  331. }
  332. const uniqueCodeList = ref([])
  333. // 扫描条码监听
  334. const _handlerScan = (code) => {
  335. if (scanType.value == 2) {
  336. searchBarcode.value = code
  337. oldSearchBarcode.value = code
  338. const params = { warehouse, barcode: code, asnNos: taskInfo.value?.asnNos.join(',') }
  339. showLoading()
  340. getReceivingAsnDetails(params).then(res => {
  341. uniqueCodeList.value=[]
  342. asnDetailsList.value = res.data
  343. if (res.data.length > 0) {
  344. scanSuccess()
  345. closeLoading()
  346. if (res.data.length == 1) {
  347. const item = res.data[0]
  348. asnInfo.value = item
  349. // searchCount.value = item.expectedQuantity - item.receivedQuantity
  350. searchCount.value=1
  351. _getProductAttribute(item)
  352. _getProductLot(item)
  353. _getCommodityRule(item)
  354. scanType.value=5
  355. }
  356. if (res.data.length > 1) {
  357. asnInfo.value = {}
  358. lotData.value = []
  359. searchCount.value = ''
  360. uniqueCodeList.value = []
  361. asnDetailsTrueFalseBy.value = true
  362. }
  363. } else {
  364. scanError()
  365. showNotify({ type: 'danger', duration: 3000, message: `暂未查询到条码《${code}》信息请重试` })
  366. reset()
  367. closeLoading()
  368. }
  369. }).catch(() => {
  370. scanError()
  371. closeLoading()
  372. })
  373. } else if (scanType.value == 3) {
  374. if (code) {
  375. const uniqueCodeScanType = uniqueCodeRef.value?.uniqueCodeScanType
  376. if (checkAllType.value && uniqueCodeScanType === 'barcode') {
  377. const barcode = Array.from(new Set([asnInfo.value.barcode, asnInfo.value.barcode2, asnInfo.value.sku].filter(Boolean)));
  378. if (barcode.some(item => barcodeToUpperCase(item) === barcodeToUpperCase(code))) {
  379. scanSuccess();
  380. uniqueCodeRef.value.uniqueCodeScanType = 'unique'
  381. uniqueCodeRef.value.uniqueBarcode = code
  382. return;
  383. } else {
  384. showNotify({ type: 'danger', duration: 3000, message: `${code}-商品条码不匹配,请重新扫描` })
  385. uniqueCodeRef.value.uniqueBarcode = ''
  386. scanError();
  387. return;
  388. }
  389. }
  390. // 如果是通过唯一码扫描,并且没有扫描条码
  391. if (uniqueCodeScanType === 'unique' && ( uniqueCodeRef.value.uniqueBarcode == '' && checkAllType.value)) {
  392. showNotify({ type: 'danger', duration: 3000, message: '请先扫描商品条码' });
  393. uniqueCodeRef.value.uniqueCodeScanType = 'barcode';
  394. scanError();
  395. return;
  396. }
  397. const uniqueRegExp = uniqueRuleMap.value['sku'] ? uniqueRuleMap.value['sku'] : uniqueRuleMap.value['all']
  398. const isValidCode = new RegExp(uniqueRegExp).test(code)
  399. if (!isValidCode) {
  400. scanError()
  401. showNotify({ type: 'danger', duration: 3000, message: `唯一码《${code}》不符合规则、请重新扫描` })
  402. return
  403. }
  404. if (uniqueCodeList.value.includes(code)) {
  405. scanError()
  406. showNotify({ type: 'danger', duration: 3000, message: `唯一码《${code}》已存在列表内请重新扫描` })
  407. return
  408. }
  409. scanSuccess()
  410. uniqueCodeList.value.unshift(code)
  411. uniqueCodeRef.value.uniqueBarcode=''
  412. if(checkAllType.value){
  413. uniqueCodeRef.value.uniqueCodeScanType='barcode'
  414. }else {
  415. uniqueCodeRef.value.uniqueCodeScanType='unique'
  416. }
  417. }
  418. }else if(scanType.value==5){
  419. containerNo.value=barcodeToUpperCase(code)
  420. scanSuccess()
  421. // isCheck()
  422. }
  423. }
  424. /**
  425. * 物理属性
  426. */
  427. const attributeRef = ref(null)
  428. const attributeMap = ref({})
  429. const attributeTrueFalseBy = ref(true)
  430. // 获取商品物理属性
  431. const _getProductAttribute = (item) => {
  432. const params = { warehouse: item.warehouse, owner: item.customerId, barcode: item.sku }
  433. getProductAttribute(params).then(res => {
  434. attributeMap.value = res.data
  435. const isAttributeInfo = isAttribute(res.data)
  436. if (isAttributeInfo.length > 0) {
  437. attributeTrueFalseBy.value = false
  438. attributeRef.value?.show(isAttributeInfo, res.data)
  439. } else {
  440. attributeTrueFalseBy.value = true
  441. }
  442. })
  443. }
  444. // 设置商品物理属性
  445. const setAttribute = (data) => {
  446. const params = { warehouse, owner: taskInfo.value.customerId, sku: attributeMap.value.sku }
  447. showLoading()
  448. setProductAttribute(params, { ...attributeMap.value, ...data }).then(res => {
  449. showToast({ duration: 3000, message: '商品物理属性设置成功' })
  450. attributeTrueFalseBy.value = true
  451. scanSuccess()
  452. }).catch(err => {
  453. closeLoading()
  454. scanError()
  455. })
  456. }
  457. /**
  458. * 物理属性 end
  459. */
  460. /**
  461. * 商品批次属性
  462. */
  463. // 获取商品批次属性
  464. const lotData = ref([])
  465. const _getProductLot = (item) => {
  466. const params = { warehouse: item.warehouse, owner: item.customerId, barcode: item.sku }
  467. getProductLot(params).then(res => {
  468. res.data.forEach((lot) => {
  469. const lotField = lot.field
  470. if (lotField.startsWith('lotAtt') && lotField.length === 8) {
  471. lot.mapping = item[lotField]
  472. }
  473. })
  474. lotData.value = res.data
  475. _calculateShelfLife(item, lotData.value)
  476. })
  477. }
  478. // 计算效期
  479. const _calculateShelfLife = (item, lotData) => {
  480. if ((item.lotAtt01 && item.lotAtt02) || (!item.lotAtt01 && !item.lotAtt02)) return
  481. const params = {
  482. customer: item.customerId,
  483. barcode: item.sku,
  484. date: item.lotAtt01 || item.lotAtt02,
  485. isExpiryDate: item.lotAtt01 ? true : false,
  486. }
  487. calculateShelfLife(params).then(date => {
  488. lotData.forEach((lot) => {
  489. if ((lot.field === 'lotAtt01' && !params.isExpiryDate) ||
  490. (lot.field === 'lotAtt02' && params.isExpiryDate)) {
  491. lot.mapping = date.data
  492. }
  493. })
  494. })
  495. }
  496. //日期选择
  497. const lotField = ref('')
  498. const lotDateRef = ref(null)
  499. const lotQualityTrueFalseBy=ref(false)
  500. const lotQualityMap=ref({})
  501. const onLot = (item) => {
  502. lotField.value = item.field
  503. if (item.field == 'lotAtt05' ) return
  504. if ( item.field == 'lotAtt08'){
  505. lotQualityMap.value=JSON.parse(item.format)
  506. lotQualityTrueFalseBy.value = true
  507. return
  508. }
  509. if (item.type == 'Date') {
  510. lotDateRef.value?.show(item.label, item.mapping)
  511. return
  512. }
  513. if (item.type == 'String') {
  514. inputBarcodeType.value = 'lot'
  515. back.value = false
  516. inputBarcodeRef.value?.show('', `请扫描${item.label}`,'')
  517. return
  518. }
  519. }
  520. //设置质量状态
  521. const onSelectLotQuality=(key)=>{
  522. lotData.value.forEach((lot) => {
  523. if (lot.field == lotField.value) {
  524. lot.mapping = key
  525. }
  526. })
  527. lotQualityTrueFalseBy.value=false
  528. }
  529. // 设置日期
  530. const selectLotDate = (date) => {
  531. const lotMap = toMap(lotData.value, 'field', 'mapping')
  532. if ((lotField.value === 'lotAtt01' || lotField.value === 'lotAtt02') &&
  533. lotMap['lotAtt01'] == '' || lotMap['lotAtt01'] == null && lotMap['lotAtt02'] == '' || lotMap['lotAtt02'] == null) {
  534. const params = {
  535. customer: asnInfo.value.customerId,
  536. barcode: asnInfo.value.sku,
  537. date,
  538. isExpiryDate: lotField.value === 'lotAtt01' ? true : false,
  539. }
  540. calculateShelfLife(params).then(res => {
  541. if(res.data){
  542. lotData.value.forEach((lot) => {
  543. if (lot.field === 'lotAtt01') {
  544. lot.mapping = (lotField.value === 'lotAtt01') ? date : res.data
  545. } else if (lot.field === 'lotAtt02') {
  546. lot.mapping = (lotField.value === 'lotAtt02') ? date : res.data
  547. }
  548. })
  549. }else {
  550. lotData.value.forEach((lot) => {
  551. if (lot.field === lotField.value) {
  552. lot.mapping = date
  553. }
  554. })
  555. }
  556. })
  557. }
  558. lotData.value.forEach((lot) => {
  559. if (lot.field === lotField.value) {
  560. lot.mapping = date
  561. }
  562. })
  563. inputBarcodeType.value = 'task'
  564. }
  565. /**
  566. * 商品批次属性end
  567. */
  568. /**
  569. * 唯一码
  570. */
  571. const uniqueCodeRef = ref(null)
  572. //规则列表
  573. const uniqueRuleList = ref([])
  574. const uniqueRuleMap = ref({})
  575. // 获取商品规则
  576. const _getCommodityRule = (item) => {
  577. const params = { customer: item.customerId, sku: item.sku, input: 'RECEIVING' }
  578. getCommodityRule(params).then(res => {
  579. uniqueRuleList.value = res.data
  580. res.data.forEach((item, index) => {
  581. if (item.sku == '') {
  582. item.type = 'all'
  583. } else {
  584. item.type = 'sku'
  585. }
  586. })
  587. uniqueRuleMap.value = toMap(res.data, 'type', 'uniqueRegExp')
  588. })
  589. }
  590. /**
  591. * 唯一码end
  592. */
  593. const containerNoRef = ref(null)
  594. const numberRef = ref(null)
  595. // 完成收货校验
  596. const isCheck = () => {
  597. if (!asnInfo.value.asnNo) {
  598. scanError()
  599. showToast({ duration: 3000, message: '请先查询商品收货信息' })
  600. return false
  601. }
  602. //商品物理属性判断
  603. if (!attributeTrueFalseBy.value) {
  604. const isAttributeInfo = isAttribute(attributeMap.value)
  605. if (isAttributeInfo.length > 0) {
  606. attributeTrueFalseBy.value = false
  607. attributeRef.value?.show(isAttributeInfo, attributeMap.value)
  608. }
  609. return false
  610. }
  611. // //商品批次属性判断
  612. const incompleteLot = lotData.value.find(lot => lot.require && !lot.mapping)
  613. if (incompleteLot) {
  614. scanError()
  615. showToast({ duration: 3000, message: `请先补充${incompleteLot.label}` })
  616. return false
  617. }
  618. const lotMap = toMap(lotData.value, 'field', 'mapping')
  619. const productionDate = lotMap['lotAtt01'] ? new Date(lotMap['lotAtt01']) : null
  620. const expirationDate = lotMap['lotAtt02'] ? new Date(lotMap['lotAtt02']) : null
  621. const currentDate = new Date()
  622. // 如果存在失效日期
  623. if (expirationDate) {
  624. // 如果有生产日期,进行有效性检查
  625. if (productionDate && expirationDate <= productionDate) {
  626. scanError()
  627. showToast({ duration: 3000, message: `失效日期不能小于等于生产日期` })
  628. return false
  629. }
  630. // 检查失效日期是否小于当前日期
  631. if (expirationDate <= currentDate) {
  632. scanError()
  633. showToast({ duration: 3000, message: `失效日期不能小于等于当前日期` })
  634. return false
  635. }
  636. }
  637. if(productionDate){
  638. // 如果有生产日期,进行有效性检查
  639. if (expirationDate && productionDate >= expirationDate) {
  640. scanError()
  641. showToast({ duration: 3000, message: `生产日期不能大于失效日期` })
  642. return false
  643. }
  644. // 检查生产日期是否小于当前日期
  645. if (productionDate >= currentDate) {
  646. scanError()
  647. showToast({ duration: 3000, message: `生产日期不能大于等于当前日期` })
  648. return false
  649. }
  650. }
  651. if (searchCount.value == '') {
  652. numberRef.value?.focus()
  653. scanError()
  654. showToast({ duration: 3000, message: '请先输入收货数量' })
  655. return false
  656. }
  657. if (containerNo.value == '') {
  658. scanError()
  659. containerNoRef.value?.focus()
  660. showToast({ duration: 3000, message: '请先扫描库位号' })
  661. scanType.value=5
  662. return false
  663. }
  664. // 唯一码收集
  665. if (uniqueRuleList.value.length > 0 && uniqueCodeList.value.length != searchCount.value) {
  666. scanType.value = 3
  667. uniqueCodeRef.value?.show('', '请扫描唯一码', `收货数量:${searchCount.value}`, uniqueRuleMap.value)
  668. return false
  669. }
  670. return true
  671. }
  672. // 收货
  673. const onConfirm = () => {
  674. if(isCheck()){
  675. const lotMap = toMap(lotData.value, 'field', 'mapping')
  676. const { asnLineNo, asnNo, warehouse } = asnInfo.value
  677. const {taskNo: taskCode } = taskInfo.value
  678. const data = {
  679. asnLineNo,
  680. asnNo,
  681. containerId: containerNo.value,
  682. quantity: searchCount.value,
  683. warehouse,
  684. serialNos: uniqueCodeList.value.length > 0 ? uniqueCodeList.value : undefined,
  685. ...lotMap,
  686. taskNo:taskCode
  687. }
  688. showLoading()
  689. inputBarcodeType.value='task'
  690. setBotReceiving(data).then(res => {
  691. scanSuccess()
  692. showNotify({ type: 'success', duration: 3000, message: `${searchBarcode.value}收货完成,请继续收货!`})
  693. setBarcode(taskNo.value, '2')
  694. reset()
  695. taskInfo.value={}
  696. scanType.value=2
  697. closeLoading()
  698. }).catch(err => {
  699. if(err.message.includes('序列号已存在')){
  700. scanType.value = 3
  701. uniqueCodeRef.value?.show('', '请扫描唯一码', `收货数量:${searchCount.value},${err.message}`, uniqueRuleMap.value)
  702. }
  703. scanError()
  704. closeLoading()
  705. })
  706. }
  707. }
  708. // 数据刷新
  709. const loadData = () => {
  710. if (!taskNo.value) {
  711. inputBarcodeRef.value?.show('', '请扫描开单任务号','')
  712. return
  713. } else {
  714. // currentTime.value=getCurrentTime()
  715. // startTimer()
  716. }
  717. }
  718. onUnmounted(() => {
  719. closeListener()
  720. stopTimer()
  721. })
  722. window.onRefresh = loadData
  723. </script>
  724. <style scoped lang="sass">
  725. .take-delivery
  726. .take-info
  727. padding: 6px 10px
  728. background: #e0eeff
  729. display: flex
  730. flex-direction: column
  731. text-align: left
  732. .take-info-no
  733. flex: 1
  734. .info-no-title
  735. font-size: 18px
  736. display: flex
  737. justify-content: space-between
  738. align-items: center
  739. .info-no-tips
  740. font-size: 14px
  741. color: #666666
  742. display: flex
  743. justify-content: space-between
  744. padding: 6px 0
  745. .take-info-number
  746. flex: 1
  747. border-top: 1.5px solid #ffffff
  748. display: flex
  749. justify-content: space-between
  750. color: #666
  751. font-size: 14px
  752. .info-number-left
  753. flex: 1
  754. display: flex
  755. justify-content: space-between
  756. align-items: center
  757. .number-left-box
  758. flex: 1
  759. display: flex
  760. justify-content: center
  761. align-items: center
  762. .left-box-title
  763. font-size: 14px
  764. font-weight: bold
  765. color: #000
  766. line-height: 34px
  767. .info-number-right
  768. width: 0%
  769. text-align: center
  770. .van-search
  771. padding: 0
  772. .take-barcode
  773. margin-top: 10px
  774. text-align: left
  775. background: #FFFFFF
  776. .barcode-input
  777. :deep(.van-search)
  778. padding: 0
  779. height: 50px
  780. display: flex
  781. align-items: center
  782. :deep(.van-search__field)
  783. border-bottom: 2px solid #ffffff
  784. height: 50px
  785. display: flex
  786. align-items: center
  787. :deep(.van-search__content)
  788. background: #fff
  789. height: 50px
  790. display: flex
  791. align-items: center
  792. :deep(.van-field__control)
  793. font-size: 16px
  794. line-height: 50px
  795. font-weight: bold
  796. :deep(.van-search__label)
  797. font-size: 16px
  798. font-weight: bold
  799. line-height: 50px
  800. display: flex
  801. align-items: center
  802. .search-input-barcode
  803. :deep(.van-search__field)
  804. border-bottom: 2px solid #0077ff
  805. z-index: 2
  806. .take-lot
  807. text-align: left
  808. margin-top: 5px
  809. ::v-deep(.van-cell)
  810. padding: 5px 8px
  811. .take-lot-title
  812. font-size: 15px
  813. font-weight: bold
  814. padding: 0 5px
  815. border-left: 3px solid #1989fa
  816. color: #333
  817. margin-bottom: 3px
  818. .take-button
  819. padding: 20px
  820. </style>