scan.vue 17 KB

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