scan.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603
  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"
  32. :clear="false" @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"
  40. :clear="false"
  41. style="margin: 0 0 0 16rpx;outline: 2rpx solid #999999;border-radius: 10rpx;"></uni-data-select>
  42. </view>
  43. </view>
  44. <view class="info-row uni-row">
  45. <view class="label">所有箱号</view>
  46. <view class="value">{{ lot.allCarrierName }}</view>
  47. </view>
  48. <view class="info-row uni-row">
  49. <view class="label">巡检箱号</view>
  50. <view class="value">{{ lot.inspectionCarrierCode }}</view>
  51. </view>
  52. <!-- <input type="text" v-model="carrierCode" placeholder="请输入箱号" /> -->
  53. <view class="btn uni-row" style="background-color: #ff5555;" @click.stop="handleScanCode">
  54. <uni-icons type="scan" size="16" style="color: #ffffff; margin-right: 8rpx;" />
  55. <text>扫描箱码及检测箱码</text>
  56. </view>
  57. <view class="btn uni-row" style="margin-top: 48rpx;" @click.stop="handleConfirm">确定</view>
  58. </view>
  59. <dialog-processInspection ref='selectProcessInspection'
  60. @handleSelectProcessInspection='handleSelectProcessInspection'></dialog-processInspection>
  61. <QrScanner v-if="showQrCodeReader" @decode="onDecodeHandler" @close="qrReaderClose" />
  62. </view>
  63. </template>
  64. <script setup>
  65. import {
  66. ref
  67. } from 'vue'
  68. import {
  69. onLoad,
  70. onReady,
  71. onUnload,
  72. onShow
  73. } from '@dcloudio/uni-app'
  74. import {
  75. getPatrolLotInfo,
  76. getCarrierInfoProcess,
  77. getCarrierInfo,
  78. } from '@/api/business/processInspection.js'
  79. import QrScanner from '../vueQrCode/index.vue'
  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 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. const showQrCodeReader = ref(false);
  95. // 页面生命周期函数
  96. onLoad(() => {})
  97. //H5扫码器回调
  98. function onDecodeHandler(data) {
  99. showQrCodeReader.value = false;
  100. const result = {
  101. carrierCode: data,
  102. processCode: '',
  103. deptId : store.curDeptDetails.deptId
  104. }
  105. if (!result.carrierCode || result.carrierCode == "") {
  106. uni.showToast({
  107. icon: "none",
  108. title: "请扫载具码",
  109. duration: 1000
  110. })
  111. return
  112. }
  113. //判断该箱是否绑定批次
  114. result.processCode = store.outsourcedCode;
  115. // console.log(result.processCode)
  116. /************************ 根据扫码查询到的数据和需要检查的工序查询信息 ************************/
  117. getCarrierInfo(result).then(response => {
  118. if (response.code == 200) {
  119. // 判断是哪种返回值 假设是想信息则给lot附检查箱信息
  120. // 假设是dayworkCarriers 则 判断是几个批次,假设为多批,则弹出选择框。
  121. if (response.data.dayworkCarriers != null) {
  122. if (response.data.dayworkCarriers.length > 1) {
  123. query.value = result;
  124. selectProcessInspection.value.open(response.data.dayworkCarriers)
  125. } else {
  126. // console.log(response)
  127. uni.showLoading({
  128. title: '加载中'
  129. });
  130. // 此处根据拿到的箱子id, 获取到相对应的【 lot_id】,【 lot_code】, 以及该批次关联的其它箱号
  131. // 需要定义一个请求方法, 从后端获取
  132. result.deptId = store.curDeptDetails.deptId
  133. getPatrolLotInfo(result).then(res => {
  134. if (res.code == 200) {
  135. console.log(res)
  136. if(res.data.dayworkItemList.length == 0) {
  137. uni.showToast({
  138. icon: 'none',
  139. title: "该批次本日没有可进行巡检的报工",
  140. duration: 2000
  141. })
  142. }else{
  143. getUser(res.data.dayworkItemList)
  144. getEquipment(res.data.dayworkItemList)
  145. lot.value = {
  146. ...lot.value,
  147. ...res.data
  148. };
  149. lot.value.carrierCode = result.carrierCode
  150. carrierCode.value = result.carrierCode;
  151. // console.log("res", res);
  152. uni.hideLoading();
  153. // 判断是否批次号和检查箱码都扫完
  154. checkSave()
  155. }
  156. } else {
  157. uni.showToast({
  158. icon: 'none',
  159. title: res.msg,
  160. duration: 2000
  161. })
  162. }
  163. }).catch(err => {
  164. uni.showToast({
  165. icon: 'none',
  166. title: err.message,
  167. duration: 2000
  168. })
  169. })
  170. }
  171. } else if (response.data.inspectionCarrier != null) {
  172. console.log(response)
  173. lot.value.inspectionCarrierCode = response.data.inspectionCarrier.code
  174. lot.value.inspectionCarrierId = response.data.inspectionCarrier.id
  175. // 判断是否批次号和检查箱码都扫完
  176. checkSave()
  177. }
  178. } else {
  179. uni.showToast({
  180. icon: 'none',
  181. title: response.msg,
  182. duration: 2000
  183. })
  184. }
  185. }).catch(err => {
  186. uni.showToast({
  187. icon: 'none',
  188. title: err.message,
  189. duration: 2000
  190. })
  191. })
  192. }
  193. //H5扫码器关闭
  194. function qrReaderClose() {
  195. showQrCodeReader.value = false;
  196. }
  197. const handleScanCode = () => {
  198. showQrCodeReader.value = true;
  199. // 引入原生插件
  200. // const mpaasScanModule = uni.requireNativePlugin("Mpaas-Scan-Module");
  201. // if (mpaasScanModule) {
  202. // // 调用插件的 mpaasScan 方法
  203. // mpaasScanModule.mpaasScan({
  204. // // 扫码识别类型,参数可多选,qrCode、barCode,
  205. // // 如不设置,默认识别所有扫码类型,可能有些许影响识别效率
  206. // scanType: ["qrCode", "barCode"],
  207. // // 是否隐藏相册,默认false不隐藏
  208. // hideAlbum: false,
  209. // },
  210. // (ret) => {
  211. // console.log(ret)
  212. // const result = {
  213. // carrierCode: ret.resp_result,
  214. // processCode: '',
  215. // deptId : store.curDeptDetails.deptId
  216. // }
  217. // if (!result.carrierCode || result.carrierCode == "") {
  218. // uni.showToast({
  219. // icon: "none",
  220. // title: "请扫载具码",
  221. // duration: 1000
  222. // })
  223. // return
  224. // }
  225. // //判断该箱是否绑定批次
  226. // result.processCode = store.outsourcedCode;
  227. // // console.log(result.processCode)
  228. // /************************ 根据扫码查询到的数据和需要检查的工序查询信息 ************************/
  229. // getCarrierInfo(result).then(response => {
  230. // if (response.code == 200) {
  231. // // 判断是哪种返回值 假设是想信息则给lot附检查箱信息
  232. // // 假设是dayworkCarriers 则 判断是几个批次,假设为多批,则弹出选择框。
  233. // if (response.data.dayworkCarriers != null) {
  234. // if (response.data.dayworkCarriers.length > 1) {
  235. // query.value = result;
  236. // selectProcessInspection.value.open(response.data.dayworkCarriers)
  237. // } else {
  238. // // console.log(response)
  239. // uni.showLoading({
  240. // title: '加载中'
  241. // });
  242. // // 此处根据拿到的箱子id, 获取到相对应的【 lot_id】,【 lot_code】, 以及该批次关联的其它箱号
  243. // // 需要定义一个请求方法, 从后端获取
  244. // result.deptId = store.curDeptDetails.deptId
  245. // getPatrolLotInfo(result).then(res => {
  246. // if (res.code == 200) {
  247. // console.log(res)
  248. // if(res.data.dayworkItemList.length == 0) {
  249. // uni.showToast({
  250. // icon: 'none',
  251. // title: "该批次本日没有可进行巡检的报工",
  252. // duration: 2000
  253. // })
  254. // }else{
  255. // getUser(res.data.dayworkItemList)
  256. // getEquipment(res.data.dayworkItemList)
  257. // lot.value = {
  258. // ...lot.value,
  259. // ...res.data
  260. // };
  261. // lot.value.carrierCode = result.carrierCode
  262. // carrierCode.value = result.carrierCode;
  263. // // console.log("res", res);
  264. // uni.hideLoading();
  265. // // 判断是否批次号和检查箱码都扫完
  266. // checkSave()
  267. // }
  268. // } else {
  269. // uni.showToast({
  270. // icon: 'none',
  271. // title: res.msg,
  272. // duration: 2000
  273. // })
  274. // }
  275. // }).catch(err => {
  276. // uni.showToast({
  277. // icon: 'none',
  278. // title: err.message,
  279. // duration: 2000
  280. // })
  281. // })
  282. // }
  283. // } else if (response.data.inspectionCarrier != null) {
  284. // console.log(response)
  285. // lot.value.inspectionCarrierCode = response.data.inspectionCarrier.code
  286. // lot.value.inspectionCarrierId = response.data.inspectionCarrier.id
  287. // // 判断是否批次号和检查箱码都扫完
  288. // checkSave()
  289. // }
  290. // } else {
  291. // uni.showToast({
  292. // icon: 'none',
  293. // title: response.msg,
  294. // duration: 2000
  295. // })
  296. // }
  297. // }).catch(err => {
  298. // uni.showToast({
  299. // icon: 'none',
  300. // title: err.message,
  301. // duration: 2000
  302. // })
  303. // })
  304. // }
  305. // )
  306. // } else {
  307. // const result = {
  308. // carrierCode: '000493',
  309. // deptId : store.curDeptDetails.deptId
  310. // }
  311. // getCarrierInfo(result).then(response => {
  312. // if (response.code == 200) {
  313. // // 判断是哪种返回值 假设是想信息则给lot附检查箱信息
  314. // // 假设是dayworkCarriers 则 判断是几个批次,假设为多批,则弹出选择框。
  315. // if (response.data.dayworkCarriers != null) {
  316. // if (response.data.dayworkCarriers.length > 1) {
  317. // query.value = result;
  318. // query.value.deptId = store.curDeptDetails.deptId
  319. // selectProcessInspection.value.open(response.data.dayworkCarriers)
  320. // } else {
  321. // // console.log(response)
  322. // uni.showLoading({
  323. // title: '加载中'
  324. // });
  325. // // 此处根据拿到的箱子id, 获取到相对应的【 lot_id】,【 lot_code】, 以及该批次关联的其它箱号
  326. // // 需要定义一个请求方法, 从后端获取
  327. // getPatrolLotInfo(result).then(res => {
  328. // if (res.code == 200) {
  329. // console.log(res)
  330. // if(res.data.dayworkItemList.length == 0) {
  331. // uni.showToast({
  332. // icon: 'none',
  333. // title: "该批次本日没有可进行巡检的报工",
  334. // duration: 2000
  335. // })
  336. // }else{
  337. // console.log("888")
  338. // getUser(res.data.dayworkItemList)
  339. // getEquipment(res.data.dayworkItemList)
  340. // lot.value = {
  341. // ...lot.value,
  342. // ...res.data
  343. // };
  344. // lot.value.carrierCode = result.carrierCode
  345. // carrierCode.value = result.carrierCode;
  346. // lot.value.inspectionCarrierId = '1803605009554784261'
  347. // lot.value.inspectionCarrierCode = "300053"
  348. // // console.log("res", res);
  349. // uni.hideLoading();
  350. // // 判断是否批次号和检查箱码都扫完
  351. // checkSave()
  352. // }
  353. // } else {
  354. // uni.showToast({
  355. // icon: 'none',
  356. // title: res.msg,
  357. // duration: 2000
  358. // })
  359. // }
  360. // }).catch(err => {
  361. // uni.showToast({
  362. // icon: 'none',
  363. // title: err.message,
  364. // duration: 2000
  365. // })
  366. // })
  367. // }
  368. // } else if (response.data.inspectionCarrier != null) {
  369. // console.log(response)
  370. // lot.value.inspectionCarrierCode = response.data.inspectionCarrier.code
  371. // lot.value.inspectionCarrierId = response.data.inspectionCarrier.id
  372. // // 判断是否批次号和检查箱码都扫完
  373. // checkSave()
  374. // }
  375. // } else {
  376. // uni.showToast({
  377. // icon: 'none',
  378. // title: response.msg,
  379. // duration: 2000
  380. // })
  381. // }
  382. // }).catch(err => {
  383. // uni.showToast({
  384. // icon: 'none',
  385. // title: err.message,
  386. // duration: 2000
  387. // })
  388. // })
  389. // }
  390. }
  391. function checkSave() {
  392. if (lot.value.lotCode == '' || lot.value.lotCode == null) {
  393. debounce(handleScanCode, 700)
  394. }
  395. if (lot.value.inspectionCarrierId == null || lot.value.inspectionCarrierId == '') {
  396. debounce(handleScanCode, 700)
  397. }
  398. }
  399. function handleGetEquipmentList() {
  400. getEquipment(lot.value.dayworkItemList)
  401. }
  402. function getEquipment(data) {
  403. const uniqueEquipmentMap = new Map();
  404. console.log(userId.value)
  405. let filterList = data.filter(info => info.userId == userId.value)
  406. console.log(filterList)
  407. filterList.forEach(item => {
  408. // 检查 Map 中是否已经有这个 equimentDetailId
  409. if (!uniqueEquipmentMap.has(item.equipmentDetailId)) {
  410. // 如果没有,添加到 Map 中
  411. uniqueEquipmentMap.set(item.equipmentDetailId, {
  412. value: item.equipmentDetailId,
  413. text: item.equipmentDetailCode
  414. });
  415. }
  416. });
  417. // 将 Map 的值转换为数组
  418. equipmentList.value = Array.from(uniqueEquipmentMap.values());
  419. equipment.value = equipmentList.value[0].value
  420. }
  421. function getUser(data) {
  422. const uniqueUserMap = new Map();
  423. console.log(data)
  424. data.forEach(item => {
  425. // 检查 Map 中是否已经有这个 equimentDetailId
  426. if (!uniqueUserMap.has(item.userId)) {
  427. // 如果没有,添加到 Map 中
  428. uniqueUserMap.set(item.userId, {
  429. value: item.userId,
  430. text: item.nickName
  431. });
  432. }
  433. });
  434. console.log(uniqueUserMap)
  435. // 将 Map 的值转换为数组
  436. userList.value = Array.from(uniqueUserMap.values());
  437. console.log(userList.value)
  438. userId.value = userList.value[0].value
  439. }
  440. //选择批号弹窗带回
  441. function handleSelectProcessInspection(data) {
  442. console.log("带回", data)
  443. query.value.lotCode = data
  444. uni.showLoading({
  445. title: '加载中'
  446. });
  447. getLotInfo(query.value).then(res => {
  448. if (res.code == 200) {
  449. console.log(res)
  450. if(res.data.dayworkItemList.length == 0) {
  451. uni.showToast({
  452. icon: 'none',
  453. title: "该批次当天没有报工",
  454. duration: 2000
  455. })
  456. }else{
  457. console.log("888")
  458. getUser(res.data.dayworkItemList)
  459. getEquipment(res.data.dayworkItemList)
  460. lot.value = {
  461. ...lot.value,
  462. ...res.data
  463. };
  464. lot.value.carrierCode = query.value.carrierCode
  465. carrierCode.value = query.value.carrierCode;
  466. // console.log("res", res);
  467. uni.hideLoading();
  468. // 判断是否批次号和检查箱码都扫完
  469. checkSave()
  470. }
  471. } else {
  472. uni.showToast({
  473. icon: 'none',
  474. title: res.msg,
  475. duration: 2000
  476. })
  477. }
  478. }).catch(err => {
  479. uni.showToast({
  480. icon: 'none',
  481. title: err.message,
  482. duration: 2000
  483. })
  484. })
  485. }
  486. //确定后,将批次id,批次号,传递过去
  487. const handleConfirm = () => {
  488. console.log(lot.value)
  489. if(lot.value.allCarrierName !=undefined && lot.value.inspectionCarrierId !=undefined){
  490. lot.value.equipmentDetailId = equipment.value
  491. lot.value.equipmentDetailCode = equipmentList.value[equipmentList.value.findIndex(item =>item.value == 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>