scan.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  1. <template>
  2. <view class="page-container uni-column">
  3. <view class="consultation-container uni-column">
  4. <view class="title uni-row">箱号:{{ lot.carrierCode }}</view>
  5. <view class="info-row uni-row">
  6. <view class="label">批次号</view>
  7. <view class="value">{{ lot.lotCode }}</view>
  8. </view>
  9. <view class="info-row uni-row">
  10. <view class="label">产品描述</view>
  11. <view class="value">{{ lot.productDescription }}</view>
  12. </view>
  13. <view class="info-row uni-row">
  14. <view class="label">外协工序</view>
  15. <view class="value">{{ lot.processNames }}</view>
  16. </view>
  17. <view class="info-row uni-row">
  18. <view class="label">投产数量</view>
  19. <view class="value">{{ lot.pudName }}</view>
  20. </view>
  21. <view class="info-row uni-row">
  22. <view class="label">批次箱号</view>
  23. <view class="value">{{ lot.allCarrierName }}</view>
  24. </view>
  25. <view class="info-row uni-row">
  26. <view class="label">检查箱号</view>
  27. <view class="value">{{ lot.inspectionCarrierCode }}</view>
  28. </view>
  29. <!-- <input type="text" v-model="carrierCode" placeholder="请输入箱号或检查载具号" /> -->
  30. <view class="btn uni-row" style="background-color: #ff5555;" @click="handleScanCode">
  31. <uni-icons type="scan" size="16" style="color: #ffffff; margin-right: 8rpx;" />
  32. <text>扫描箱码或载具二维码</text>
  33. </view>
  34. <!-- <view class="btn uni-row" style="margin-top: 48rpx;" @click.stop="handleConfirm">箱码确定</view>
  35. <view class="btn uni-row" style="background-color: #26d01d;" @click.stop="handleSave">保存
  36. </view> -->
  37. <view class="btn uni-row" style="margin-top: 48rpx;" @click.stop="handleSave">保存</view>
  38. </view>
  39. <dialog-processInspection ref='selectProcessInspection'
  40. @handleSelectProcessInspection='handleSelectProcessInspection'></dialog-processInspection>
  41. <QrScanner v-if="showQrCodeReader" @decode="onDecodeHandler" @close="qrReaderClose" />
  42. </view>
  43. </template>
  44. <script setup>
  45. import {
  46. ref
  47. } from 'vue'
  48. import {
  49. onLoad,
  50. onReady,
  51. onUnload,
  52. onShow
  53. } from '@dcloudio/uni-app'
  54. import {
  55. saveOutsourcedInspecion,
  56. getLotInfo,
  57. getCarrierInfo,
  58. getLotOutsourcedInfo
  59. } from '@/api/business/processInspection.js'
  60. import QrScanner from '../vueQrCode/index.vue'
  61. import {
  62. store
  63. } from '../../store';
  64. import {
  65. debounce
  66. } from '../../utils/common';
  67. const carrierCode = ref('')
  68. const lot = ref({})
  69. const query = ref({})
  70. const selectProcessInspection = ref(null)
  71. const lastRequestTimestamp = ref(0);
  72. const saveLoading = ref(false)
  73. const showQrCodeReader = ref(false);
  74. // 页面生命周期函数
  75. onLoad(() => {})
  76. //H5扫码器回调
  77. function onDecodeHandler(data) {
  78. showQrCodeReader.value = false;
  79. const result = {
  80. carrierCode: data,
  81. processCode: ''
  82. }
  83. if (!result.carrierCode || result.carrierCode == "") {
  84. uni.showToast({
  85. icon: "none",
  86. title: "请扫载具码",
  87. duration: 1000
  88. })
  89. return
  90. }
  91. //判断该箱是否绑定批次
  92. result.processCode = store.outsourcedCode;
  93. // console.log(result.processCode)
  94. /************************ 根据扫码查询到的数据和需要检查的工序查询信息 ************************/
  95. getCarrierInfo(result).then(response => {
  96. if (response.code == 200) {
  97. // 判断是哪种返回值 假设是想信息则给lot附检查箱信息
  98. // 假设是dayworkCarriers 则 判断是几个批次,假设为多批,则弹出选择框。
  99. if (response.data.dayworkCarriers != null) {
  100. if (response.data.dayworkCarriers.length > 1) {
  101. query.value = result;
  102. selectProcessInspection.value.open(response.data.dayworkCarriers)
  103. } else {
  104. // console.log(response)
  105. uni.showLoading({
  106. title: '加载中'
  107. });
  108. // 此处根据拿到的箱子id, 获取到相对应的【 lot_id】,【 lot_code】, 以及该批次关联的其它箱号
  109. // 需要定义一个请求方法, 从后端获取
  110. getLotOutsourcedInfo(result).then(res => {
  111. if (res.code == 200) {
  112. lot.value = {
  113. ...lot.value,
  114. ...res.data,
  115. processNames: res.data.processList
  116. };
  117. lot.value.carrierCode = result.carrierCode
  118. carrierCode.value = result.carrierCode;
  119. // console.log("res", res);
  120. uni.hideLoading();
  121. checkSave()
  122. } else {
  123. uni.showToast({
  124. icon: 'none',
  125. title: res.msg,
  126. duration: 2000
  127. })
  128. }
  129. }).catch(err => {
  130. uni.showToast({
  131. icon: 'none',
  132. title: err.message,
  133. duration: 2000
  134. })
  135. })
  136. }
  137. } else if (response.data.inspectionCarrier != null) {
  138. console.log(response)
  139. lot.value.inspectionCarrierCode = response.data.inspectionCarrier.code
  140. lot.value.inspectionCarrierId = response.data.inspectionCarrier.id
  141. checkSave()
  142. }
  143. } else {
  144. uni.showToast({
  145. icon: 'none',
  146. title: response.msg,
  147. duration: 2000
  148. })
  149. }
  150. }).catch(err => {
  151. uni.showToast({
  152. icon: 'none',
  153. title: err.message,
  154. duration: 2000
  155. })
  156. })
  157. }
  158. //H5扫码器关闭
  159. function qrReaderClose() {
  160. showQrCodeReader.value = false;
  161. }
  162. const handleScanCode = () => {
  163. showQrCodeReader.value = true;
  164. // 引入原生插件
  165. // const mpaasScanModule = uni.requireNativePlugin("Mpaas-Scan-Module");
  166. // if (mpaasScanModule) {
  167. // // 调用插件的 mpaasScan 方法
  168. // mpaasScanModule.mpaasScan({
  169. // // 扫码识别类型,参数可多选,qrCode、barCode,
  170. // // 如不设置,默认识别所有扫码类型,可能有些许影响识别效率
  171. // scanType: ["qrCode", "barCode"],
  172. // // 是否隐藏相册,默认false不隐藏
  173. // hideAlbum: false,
  174. // },
  175. // (ret) => {
  176. // console.log(ret)
  177. // const result = {
  178. // carrierCode: ret.resp_result,
  179. // processCode: ''
  180. // }
  181. // if (!result.carrierCode || result.carrierCode == "") {
  182. // uni.showToast({
  183. // icon: "none",
  184. // title: "请扫载具码",
  185. // duration: 1000
  186. // })
  187. // return
  188. // }
  189. // //判断该箱是否绑定批次
  190. // result.processCode = store.outsourcedCode;
  191. // // console.log(result.processCode)
  192. // /************************ 根据扫码查询到的数据和需要检查的工序查询信息 ************************/
  193. // getCarrierInfo(result).then(response => {
  194. // if (response.code == 200) {
  195. // // 判断是哪种返回值 假设是想信息则给lot附检查箱信息
  196. // // 假设是dayworkCarriers 则 判断是几个批次,假设为多批,则弹出选择框。
  197. // if (response.data.dayworkCarriers != null) {
  198. // if (response.data.dayworkCarriers.length > 1) {
  199. // query.value = result;
  200. // selectProcessInspection.value.open(response.data.dayworkCarriers)
  201. // } else {
  202. // // console.log(response)
  203. // uni.showLoading({
  204. // title: '加载中'
  205. // });
  206. // // 此处根据拿到的箱子id, 获取到相对应的【 lot_id】,【 lot_code】, 以及该批次关联的其它箱号
  207. // // 需要定义一个请求方法, 从后端获取
  208. // getLotOutsourcedInfo(result).then(res => {
  209. // if (res.code == 200) {
  210. // lot.value = {
  211. // ...lot.value,
  212. // ...res.data,
  213. // processNames: res.data.processList
  214. // };
  215. // lot.value.carrierCode = result.carrierCode
  216. // carrierCode.value = result.carrierCode;
  217. // // console.log("res", res);
  218. // uni.hideLoading();
  219. // checkSave()
  220. // } else {
  221. // uni.showToast({
  222. // icon: 'none',
  223. // title: res.msg,
  224. // duration: 2000
  225. // })
  226. // }
  227. // }).catch(err => {
  228. // uni.showToast({
  229. // icon: 'none',
  230. // title: err.message,
  231. // duration: 2000
  232. // })
  233. // })
  234. // }
  235. // } else if (response.data.inspectionCarrier != null) {
  236. // console.log(response)
  237. // lot.value.inspectionCarrierCode = response.data.inspectionCarrier.code
  238. // lot.value.inspectionCarrierId = response.data.inspectionCarrier.id
  239. // checkSave()
  240. // }
  241. // } else {
  242. // uni.showToast({
  243. // icon: 'none',
  244. // title: response.msg,
  245. // duration: 2000
  246. // })
  247. // }
  248. // }).catch(err => {
  249. // uni.showToast({
  250. // icon: 'none',
  251. // title: err.message,
  252. // duration: 2000
  253. // })
  254. // })
  255. // }
  256. // )
  257. // } else {
  258. // const result = {
  259. // carrierCode: '000381',
  260. // processCode: store.outsourcedCode
  261. // }
  262. // getCarrierInfo(result).then(response => {
  263. // if (response.code == 200) {
  264. // // 判断是哪种返回值 假设是想信息则给lot附检查箱信息
  265. // // 假设是dayworkCarriers 则 判断是几个批次,假设为多批,则弹出选择框。
  266. // if (response.data.dayworkCarriers != null) {
  267. // if (response.data.dayworkCarriers.length > 1) {
  268. // query.value = result;
  269. // selectProcessInspection.value.open(response.data.dayworkCarriers)
  270. // } else {
  271. // // console.log(response)
  272. // uni.showLoading({
  273. // title: '加载中'
  274. // });
  275. // // 此处根据拿到的箱子id, 获取到相对应的【 lot_id】,【 lot_code】, 以及该批次关联的其它箱号
  276. // // 需要定义一个请求方法, 从后端获取
  277. // getLotOutsourcedInfo(result).then(res => {
  278. // if (res.code == 200) {
  279. // console.log(res)
  280. // lot.value = {
  281. // ...lot.value,
  282. // ...res.data,
  283. // processNames: res.data.processList
  284. // };
  285. // console.log(lot.value.hasInspection)
  286. // lot.value.carrierCode = result.carrierCode
  287. // carrierCode.value = result.carrierCode;
  288. // lot.value.inspectionCarrierId = '1846793994481221640'
  289. // lot.value.inspectionCarrierCode = "300250"
  290. // // console.log("res", res);
  291. // uni.hideLoading();
  292. // // 判断是否批次号和检查箱码都扫完
  293. // checkSave()
  294. // } else {
  295. // uni.showToast({
  296. // icon: 'none',
  297. // title: res.msg,
  298. // duration: 2000
  299. // })
  300. // }
  301. // }).catch(err => {
  302. // uni.showToast({
  303. // icon: 'none',
  304. // title: err.message,
  305. // duration: 2000
  306. // })
  307. // })
  308. // }
  309. // } else if (response.data.inspectionCarrier != null) {
  310. // console.log(response)
  311. // lot.value.inspectionCarrierCode = response.data.inspectionCarrier.code
  312. // lot.value.inspectionCarrierId = response.data.inspectionCarrier.id
  313. // // 判断是否批次号和检查箱码都扫完
  314. // checkSave()
  315. // }
  316. // } else {
  317. // uni.showToast({
  318. // icon: 'none',
  319. // title: response.msg,
  320. // duration: 2000
  321. // })
  322. // }
  323. // }).catch(err => {
  324. // uni.showToast({
  325. // icon: 'none',
  326. // title: err.message,
  327. // duration: 2000
  328. // })
  329. // })
  330. // }
  331. }
  332. //选择批号弹窗带回
  333. function handleSelectProcessInspection(data) {
  334. // console.log("带回", data)
  335. query.value.lotCode = data
  336. uni.showLoading({
  337. title: '加载中'
  338. });
  339. getLotOutsourcedInfo(query.value).then(res => {
  340. if (res.code == 200) {
  341. lot.value = res.data;
  342. lot.value.processNames = res.data.processList
  343. console.log(res)
  344. lot.value.carrierCode = query.value.carrierCode
  345. carrierCode.value = query.value.carrierCode;
  346. // console.log("res", res);
  347. uni.hideLoading();
  348. } else {
  349. uni.showToast({
  350. icon: 'none',
  351. title: res.msg,
  352. duration: 2000
  353. })
  354. }
  355. });
  356. }
  357. function checkSave() {
  358. // uni.showToast({
  359. // title: 'lotCode:' + lot.value.lotCode + 'inspectionCarrierId: ' + lot.value.inspectionCarrierId,
  360. // icon: 'none'
  361. // })
  362. if (lot.value.lotCode == '' || lot.value.lotCode == null) {
  363. debounce(handleScanCode, 700)
  364. }
  365. if (lot.value.inspectionCarrierId == null || lot.value.inspectionCarrierId == '') {
  366. debounce(handleScanCode, 700)
  367. }
  368. }
  369. // 确定后,将批次id,批次号,传递过去
  370. const handleConfirm = () => {
  371. /** 因为调试时无法扫码所以暂时用确定方法代替扫码 **/
  372. /** 调用查询方法查询箱号信息 **/
  373. /**
  374. * 如果返回的是载具信息表示这是检查载具,将载具的id和code存到lot.inspectionCarrierId和lot.inspectionCarrierCode中
  375. * 如果返回的是1条dayweorCarrier的载具绑定信息则调用查询方法查询批次信息
  376. * 如果返回的是多条dayweorCarrier的载具绑定信息,则表示这是一箱多批需要调用选择批号弹窗在processInspection文件scan229行有对应的方法
  377. *
  378. * */
  379. if (lot.carrierCode || carrierCode.value !== "") {
  380. // lot.value.carrierCode = carrierCode.value
  381. const result = {
  382. // ...lot.value
  383. carrierCode: carrierCode.value
  384. }
  385. result.processCode = store.outsourcedCode;
  386. // console.log(result.processCode)
  387. getCarrierInfo(result).then(response => {
  388. if (response.code == 200) {
  389. // 判断是哪种返回值 假设是想信息则给lot附检查箱信息
  390. // 假设是dayworkCarriers 则 判断是几个批次,假设为多批,则弹出选择框。
  391. if (response.data.dayworkCarriers != null) {
  392. if (response.data.dayworkCarriers.length > 1) {
  393. query.value = result;
  394. selectProcessInspection.value.open(response.data.dayworkCarriers)
  395. } else {
  396. // console.log(response)
  397. uni.showLoading({
  398. title: '加载中'
  399. });
  400. // 此处根据拿到的箱子id, 获取到相对应的【 lot_id】,【 lot_code】, 以及该批次关联的其它箱号
  401. // 需要定义一个请求方法, 从后端获取
  402. getLotOutsourcedInfo(result).then(res => {
  403. if (res.code == 200) {
  404. console.log(res)
  405. lot.value = {
  406. ...lot.value,
  407. ...res.data,
  408. processNames: res.data.processList
  409. };
  410. lot.value.carrierCode = result.carrierCode
  411. carrierCode.value = result.carrierCode;
  412. // console.log("res", res);
  413. uni.hideLoading();
  414. } else {
  415. uni.showToast({
  416. icon: 'none',
  417. title: res.msg,
  418. duration: 2000
  419. })
  420. }
  421. }).catch(err => {
  422. uni.showToast({
  423. icon: 'none',
  424. title: err.message,
  425. duration: 2000
  426. })
  427. })
  428. }
  429. } else if (response.data.inspectionCarrier != null) {
  430. console.log(response)
  431. lot.value.inspectionCarrierCode = response.data.inspectionCarrier.code
  432. lot.value.inspectionCarrierId = response.data.inspectionCarrier.id
  433. }
  434. } else {
  435. uni.showToast({
  436. icon: 'none',
  437. title: response.msg,
  438. duration: 2000
  439. })
  440. }
  441. }).catch(err => {
  442. uni.showToast({
  443. icon: 'none',
  444. title: err.message,
  445. duration: 2000
  446. })
  447. })
  448. } else {
  449. uni.showToast({
  450. icon: 'none',
  451. title: "请输入箱号",
  452. duration: 2000
  453. })
  454. return;
  455. }
  456. }
  457. const handleSave = () => {
  458. console.log('保存')
  459. if (!saveLoading.value) {
  460. console.log('实效')
  461. // 判断是否已有批次和检查载具
  462. if (lot.value.lotCode == '' || lot.value.lotCode == null) {
  463. uni.showToast({
  464. icon: 'none',
  465. title: "请先扫外协箱码",
  466. duration: 2000
  467. })
  468. return
  469. }
  470. if (lot.value.inspectionCarrierId == null) {
  471. uni.showToast({
  472. icon: 'none',
  473. title: "请先扫检查载具",
  474. duration: 2000
  475. })
  476. return
  477. }
  478. // 保存
  479. if (lot.value.hasInspection == 1) {
  480. uni.showModal({
  481. title: '提示',
  482. content: `该批次已做过检查是否继续?`,
  483. success: function(res) {
  484. if (res.confirm) {
  485. saveLoading.value = true
  486. confirmThen()
  487. } else if (res.cancel) {}
  488. }
  489. })
  490. } else {
  491. saveLoading.value = true
  492. confirmThen()
  493. }
  494. }
  495. }
  496. function confirmThen() {
  497. const currentTime = Date.now();
  498. // 检查是否已经过去了 2 秒
  499. if (currentTime - lastRequestTimestamp.value < 2000) {
  500. // 如果在 2 秒 内已经点击,那么不执行
  501. uni.showToast({
  502. icon: 'none',
  503. title: `请勿重复点击`,
  504. duration: 2000
  505. })
  506. return;
  507. }
  508. lastRequestTimestamp.value = currentTime;
  509. let pages = getCurrentPages();
  510. saveOutsourcedInspecion({
  511. lot: lot.value,
  512. user: store.userInfo,
  513. status: 0,
  514. inspectionCarrierCode: lot.value.inspectionCarrierCode,
  515. inspectionCarrierId: lot.value.inspectionCarrierId,
  516. outsourceOrderDetailId: lot.value.outsourceOrderDetailId,
  517. processNames: lot.value.processNames
  518. }).then(res => {
  519. saveLoading.value = false
  520. if (res.code == 200) {
  521. let index = 0;
  522. for (let i = 0; i < pages.length; i++) {
  523. if (pages[i].$page.fullPath ==
  524. "/pages/outsourcedInspection/index") {
  525. index = pages.length - i - 1;
  526. }
  527. }
  528. console.log("index", index);
  529. uni.navigateBack({
  530. delta: index
  531. });
  532. } else {
  533. uni.showToast({
  534. icon: 'none',
  535. title: res.msg,
  536. duration: 2000
  537. })
  538. }
  539. });
  540. }
  541. </script>
  542. <style lang="scss">
  543. .page-container {
  544. height: 100%;
  545. background-color: #ececec;
  546. font-size: 28rpx;
  547. padding: 24rpx;
  548. box-sizing: border-box;
  549. }
  550. .consultation-container {
  551. background-color: #ffffff;
  552. padding: 24rpx;
  553. border-radius: 12rpx;
  554. .title {
  555. justify-content: center;
  556. font-size: 32rpx;
  557. font-weight: 700;
  558. }
  559. .info-row {
  560. margin-top: 24rpx;
  561. .label {
  562. width: 160rpx;
  563. }
  564. .value {
  565. flex: 1;
  566. textarea {
  567. flex: 1;
  568. border: 1px solid #888888;
  569. box-sizing: border-box;
  570. padding: 16rpx;
  571. }
  572. }
  573. }
  574. .btn {
  575. background-color: #1684fc;
  576. color: #ffffff;
  577. border-radius: 8rpx;
  578. margin: 4rpx 24rpx 24rpx 24rpx;
  579. height: 64rpx;
  580. justify-content: center;
  581. align-items: center;
  582. }
  583. input {
  584. margin: 48rpx 24rpx 0 24rpx;
  585. height: 64rpx;
  586. border: 1px solid #888888;
  587. text-align: center;
  588. }
  589. }
  590. </style>