scan.vue 18 KB

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