scan.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616
  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. console.log(res)
  343. lot.value.carrierCode = query.value.carrierCode
  344. carrierCode.value = query.value.carrierCode;
  345. // console.log("res", res);
  346. uni.hideLoading();
  347. } else {
  348. uni.showToast({
  349. icon: 'none',
  350. title: res.msg,
  351. duration: 2000
  352. })
  353. }
  354. });
  355. }
  356. function checkSave() {
  357. // uni.showToast({
  358. // title: 'lotCode:' + lot.value.lotCode + 'inspectionCarrierId: ' + lot.value.inspectionCarrierId,
  359. // icon: 'none'
  360. // })
  361. if (lot.value.lotCode == '' || lot.value.lotCode == null) {
  362. debounce(handleScanCode, 700)
  363. }
  364. if (lot.value.inspectionCarrierId == null || lot.value.inspectionCarrierId == '') {
  365. debounce(handleScanCode, 700)
  366. }
  367. }
  368. // 确定后,将批次id,批次号,传递过去
  369. const handleConfirm = () => {
  370. /** 因为调试时无法扫码所以暂时用确定方法代替扫码 **/
  371. /** 调用查询方法查询箱号信息 **/
  372. /**
  373. * 如果返回的是载具信息表示这是检查载具,将载具的id和code存到lot.inspectionCarrierId和lot.inspectionCarrierCode中
  374. * 如果返回的是1条dayweorCarrier的载具绑定信息则调用查询方法查询批次信息
  375. * 如果返回的是多条dayweorCarrier的载具绑定信息,则表示这是一箱多批需要调用选择批号弹窗在processInspection文件scan229行有对应的方法
  376. *
  377. * */
  378. if (lot.carrierCode || carrierCode.value !== "") {
  379. // lot.value.carrierCode = carrierCode.value
  380. const result = {
  381. // ...lot.value
  382. carrierCode: carrierCode.value
  383. }
  384. result.processCode = store.outsourcedCode;
  385. // console.log(result.processCode)
  386. getCarrierInfo(result).then(response => {
  387. if (response.code == 200) {
  388. // 判断是哪种返回值 假设是想信息则给lot附检查箱信息
  389. // 假设是dayworkCarriers 则 判断是几个批次,假设为多批,则弹出选择框。
  390. if (response.data.dayworkCarriers != null) {
  391. if (response.data.dayworkCarriers.length > 1) {
  392. query.value = result;
  393. selectProcessInspection.value.open(response.data.dayworkCarriers)
  394. } else {
  395. // console.log(response)
  396. uni.showLoading({
  397. title: '加载中'
  398. });
  399. // 此处根据拿到的箱子id, 获取到相对应的【 lot_id】,【 lot_code】, 以及该批次关联的其它箱号
  400. // 需要定义一个请求方法, 从后端获取
  401. getLotOutsourcedInfo(result).then(res => {
  402. if (res.code == 200) {
  403. console.log(res)
  404. lot.value = {
  405. ...lot.value,
  406. ...res.data,
  407. processNames: res.data.processList
  408. };
  409. lot.value.carrierCode = result.carrierCode
  410. carrierCode.value = result.carrierCode;
  411. // console.log("res", res);
  412. uni.hideLoading();
  413. } else {
  414. uni.showToast({
  415. icon: 'none',
  416. title: res.msg,
  417. duration: 2000
  418. })
  419. }
  420. }).catch(err => {
  421. uni.showToast({
  422. icon: 'none',
  423. title: err.message,
  424. duration: 2000
  425. })
  426. })
  427. }
  428. } else if (response.data.inspectionCarrier != null) {
  429. console.log(response)
  430. lot.value.inspectionCarrierCode = response.data.inspectionCarrier.code
  431. lot.value.inspectionCarrierId = response.data.inspectionCarrier.id
  432. }
  433. } else {
  434. uni.showToast({
  435. icon: 'none',
  436. title: response.msg,
  437. duration: 2000
  438. })
  439. }
  440. }).catch(err => {
  441. uni.showToast({
  442. icon: 'none',
  443. title: err.message,
  444. duration: 2000
  445. })
  446. })
  447. } else {
  448. uni.showToast({
  449. icon: 'none',
  450. title: "请输入箱号",
  451. duration: 2000
  452. })
  453. return;
  454. }
  455. }
  456. const handleSave = () => {
  457. console.log('保存')
  458. if (!saveLoading.value) {
  459. console.log('实效')
  460. // 判断是否已有批次和检查载具
  461. if (lot.value.lotCode == '' || lot.value.lotCode == null) {
  462. uni.showToast({
  463. icon: 'none',
  464. title: "请先扫外协箱码",
  465. duration: 2000
  466. })
  467. return
  468. }
  469. if (lot.value.inspectionCarrierId == null) {
  470. uni.showToast({
  471. icon: 'none',
  472. title: "请先扫检查载具",
  473. duration: 2000
  474. })
  475. return
  476. }
  477. // 保存
  478. if (lot.value.hasInspection == 1) {
  479. uni.showModal({
  480. title: '提示',
  481. content: `该批次已做过检查是否继续?`,
  482. success: function(res) {
  483. if (res.confirm) {
  484. saveLoading.value = true
  485. confirmThen()
  486. } else if (res.cancel) {}
  487. }
  488. })
  489. } else {
  490. saveLoading.value = true
  491. confirmThen()
  492. }
  493. }
  494. }
  495. function confirmThen() {
  496. const currentTime = Date.now();
  497. // 检查是否已经过去了 2 秒
  498. if (currentTime - lastRequestTimestamp.value < 2000) {
  499. // 如果在 2 秒 内已经点击,那么不执行
  500. uni.showToast({
  501. icon: 'none',
  502. title: `请勿重复点击`,
  503. duration: 2000
  504. })
  505. return;
  506. }
  507. lastRequestTimestamp.value = currentTime;
  508. let pages = getCurrentPages();
  509. saveOutsourcedInspecion({
  510. lot: lot.value,
  511. user: store.userInfo,
  512. status: 0,
  513. inspectionCarrierCode: lot.value.inspectionCarrierCode,
  514. inspectionCarrierId: lot.value.inspectionCarrierId,
  515. outsourceOrderDetailId: lot.value.outsourceOrderDetailId,
  516. processNames: lot.value.processNames
  517. }).then(res => {
  518. saveLoading.value = false
  519. if (res.code == 200) {
  520. let index = 0;
  521. for (let i = 0; i < pages.length; i++) {
  522. if (pages[i].$page.fullPath ==
  523. "/pages/outsourcedInspection/index") {
  524. index = pages.length - i - 1;
  525. }
  526. }
  527. console.log("index", index);
  528. uni.navigateBack({
  529. delta: index
  530. });
  531. } else {
  532. uni.showToast({
  533. icon: 'none',
  534. title: res.msg,
  535. duration: 2000
  536. })
  537. }
  538. });
  539. }
  540. </script>
  541. <style lang="scss">
  542. .page-container {
  543. height: 100%;
  544. background-color: #ececec;
  545. font-size: 28rpx;
  546. padding: 24rpx;
  547. box-sizing: border-box;
  548. }
  549. .consultation-container {
  550. background-color: #ffffff;
  551. padding: 24rpx;
  552. border-radius: 12rpx;
  553. .title {
  554. justify-content: center;
  555. font-size: 32rpx;
  556. font-weight: 700;
  557. }
  558. .info-row {
  559. margin-top: 24rpx;
  560. .label {
  561. width: 160rpx;
  562. }
  563. .value {
  564. flex: 1;
  565. textarea {
  566. flex: 1;
  567. border: 1px solid #888888;
  568. box-sizing: border-box;
  569. padding: 16rpx;
  570. }
  571. }
  572. }
  573. .btn {
  574. background-color: #1684fc;
  575. color: #ffffff;
  576. border-radius: 8rpx;
  577. margin: 4rpx 24rpx 24rpx 24rpx;
  578. height: 64rpx;
  579. justify-content: center;
  580. align-items: center;
  581. }
  582. input {
  583. margin: 48rpx 24rpx 0 24rpx;
  584. height: 64rpx;
  585. border: 1px solid #888888;
  586. text-align: center;
  587. }
  588. }
  589. </style>