index.vue 29 KB

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