scan.vue 18 KB

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