scan.vue 15 KB

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