scan.vue 16 KB

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