scan.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524
  1. <template>
  2. <view class="page-container uni-column">
  3. <view class="consultation-container uni-column">
  4. <view class="title uni-row">箱号:{{ lot.carrierCode }}</view>
  5. <view class="info-row uni-row">
  6. <view class="label">批次号</view>
  7. <view class="value">{{ lot.lotCode }}</view>
  8. </view>
  9. <view class="info-row uni-row">
  10. <view class="label">产品描述</view>
  11. <view class="value">{{ lot.productDescription }}</view>
  12. </view>
  13. <view class="info-row uni-row">
  14. <view class="label">外协工序</view>
  15. <view class="value">{{ lot.processNames }}</view>
  16. </view>
  17. <view class="info-row uni-row">
  18. <view class="label">投产数量</view>
  19. <view class="value">{{ lot.pudName }}</view>
  20. </view>
  21. <view class="info-row uni-row">
  22. <view class="label">批次箱号</view>
  23. <view class="value">{{ lot.allCarrierName }}</view>
  24. </view>
  25. <view class="info-row uni-row">
  26. <view class="label">检查箱号</view>
  27. <view class="value">{{ lot.inspectionCarrierCode }}</view>
  28. </view>
  29. <!-- <input type="text" v-model="carrierCode" placeholder="请输入箱号或检查载具号" /> -->
  30. <view class="btn uni-row" style="background-color: #ff5555;" @click.stop="handleScanCode">
  31. <uni-icons type="scan" size="16" style="color: #ffffff; margin-right: 8rpx;" />
  32. <text>扫描箱码或载具二维码</text>
  33. </view>
  34. <!-- <view class="btn uni-row" style="margin-top: 48rpx;" @click.stop="handleConfirm">箱码确定</view>
  35. <view class="btn uni-row" style="background-color: #26d01d;" @click.stop="handleSave">保存
  36. </view> -->
  37. <view class="btn uni-row" style="margin-top: 48rpx;" @click.stop="handleSave">保存</view>
  38. </view>
  39. <dialog-processInspection ref='selectProcessInspection'
  40. @handleSelectProcessInspection='handleSelectProcessInspection'></dialog-processInspection>
  41. </view>
  42. </template>
  43. <script setup>
  44. import {
  45. ref
  46. } from 'vue'
  47. import {
  48. onLoad,
  49. onReady,
  50. onUnload,
  51. onShow
  52. } from '@dcloudio/uni-app'
  53. import {
  54. saveOutsourcedInspecion,
  55. getLotInfo,
  56. getCarrierInfo,
  57. getLotOutsourcedInfo
  58. } from '@/api/business/processInspection.js'
  59. import {
  60. store
  61. } from '../../store';
  62. import {
  63. debounce
  64. } from '../../utils/common';
  65. const carrierCode = ref('')
  66. const lot = ref({})
  67. const query = ref({})
  68. const selectProcessInspection = ref(null)
  69. const lastRequestTimestamp = ref(0);
  70. const saveLoading = ref(false)
  71. // 页面生命周期函数
  72. onLoad(() => {})
  73. const handleScanCode = () => {
  74. // 引入原生插件
  75. const mpaasScanModule = uni.requireNativePlugin("Mpaas-Scan-Module");
  76. if (mpaasScanModule) {
  77. // 调用插件的 mpaasScan 方法
  78. mpaasScanModule.mpaasScan({
  79. // 扫码识别类型,参数可多选,qrCode、barCode,
  80. // 如不设置,默认识别所有扫码类型,可能有些许影响识别效率
  81. scanType: ["qrCode", "barCode"],
  82. // 是否隐藏相册,默认false不隐藏
  83. hideAlbum: false,
  84. },
  85. (ret) => {
  86. console.log(ret)
  87. const result = {
  88. carrierCode: ret.resp_result,
  89. processCode: ''
  90. }
  91. if (!result.carrierCode || result.carrierCode == "") {
  92. uni.showToast({
  93. icon: "none",
  94. title: "请扫载具码",
  95. duration: 1000
  96. })
  97. return
  98. }
  99. //判断该箱是否绑定批次
  100. result.processCode = store.outsourcedCode;
  101. // console.log(result.processCode)
  102. /************************ 根据扫码查询到的数据和需要检查的工序查询信息 ************************/
  103. getCarrierInfo(result).then(response => {
  104. if (response.code == 200) {
  105. // 判断是哪种返回值 假设是想信息则给lot附检查箱信息
  106. // 假设是dayworkCarriers 则 判断是几个批次,假设为多批,则弹出选择框。
  107. if (response.data.dayworkCarriers != null) {
  108. if (response.data.dayworkCarriers.length > 1) {
  109. query.value = result;
  110. selectProcessInspection.value.open(response.data.dayworkCarriers)
  111. } else {
  112. // console.log(response)
  113. uni.showLoading({
  114. title: '加载中'
  115. });
  116. // 此处根据拿到的箱子id, 获取到相对应的【 lot_id】,【 lot_code】, 以及该批次关联的其它箱号
  117. // 需要定义一个请求方法, 从后端获取
  118. getLotOutsourcedInfo(result).then(res => {
  119. if (res.code == 200) {
  120. lot.value = {
  121. ...lot.value,
  122. ...res.data,
  123. processNames: res.data.processList
  124. };
  125. lot.value.carrierCode = result.carrierCode
  126. carrierCode.value = result.carrierCode;
  127. // console.log("res", res);
  128. uni.hideLoading();
  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. 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. )
  167. } else {
  168. const result = {
  169. carrierCode: '000381',
  170. processCode: store.outsourcedCode
  171. }
  172. getCarrierInfo(result).then(response => {
  173. if (response.code == 200) {
  174. // 判断是哪种返回值 假设是想信息则给lot附检查箱信息
  175. // 假设是dayworkCarriers 则 判断是几个批次,假设为多批,则弹出选择框。
  176. if (response.data.dayworkCarriers != null) {
  177. if (response.data.dayworkCarriers.length > 1) {
  178. query.value = result;
  179. selectProcessInspection.value.open(response.data.dayworkCarriers)
  180. } else {
  181. // console.log(response)
  182. uni.showLoading({
  183. title: '加载中'
  184. });
  185. // 此处根据拿到的箱子id, 获取到相对应的【 lot_id】,【 lot_code】, 以及该批次关联的其它箱号
  186. // 需要定义一个请求方法, 从后端获取
  187. getLotOutsourcedInfo(result).then(res => {
  188. if (res.code == 200) {
  189. console.log(res)
  190. lot.value = {
  191. ...lot.value,
  192. ...res.data,
  193. processNames: res.data.processList
  194. };
  195. console.log(lot.value.hasInspection)
  196. lot.value.carrierCode = result.carrierCode
  197. carrierCode.value = result.carrierCode;
  198. lot.value.inspectionCarrierId = '1846793994481221640'
  199. lot.value.inspectionCarrierCode = "300250"
  200. // console.log("res", res);
  201. uni.hideLoading();
  202. // 判断是否批次号和检查箱码都扫完
  203. checkSave()
  204. } else {
  205. uni.showToast({
  206. icon: 'none',
  207. title: res.msg,
  208. duration: 2000
  209. })
  210. }
  211. }).catch(err => {
  212. uni.showToast({
  213. icon: 'none',
  214. title: err.message,
  215. duration: 2000
  216. })
  217. })
  218. }
  219. } else if (response.data.inspectionCarrier != null) {
  220. console.log(response)
  221. lot.value.inspectionCarrierCode = response.data.inspectionCarrier.code
  222. lot.value.inspectionCarrierId = response.data.inspectionCarrier.id
  223. // 判断是否批次号和检查箱码都扫完
  224. checkSave()
  225. }
  226. } else {
  227. uni.showToast({
  228. icon: 'none',
  229. title: response.msg,
  230. duration: 2000
  231. })
  232. }
  233. }).catch(err => {
  234. uni.showToast({
  235. icon: 'none',
  236. title: err.message,
  237. duration: 2000
  238. })
  239. })
  240. }
  241. }
  242. //选择批号弹窗带回
  243. function handleSelectProcessInspection(data) {
  244. // console.log("带回", data)
  245. query.value.lotCode = data
  246. uni.showLoading({
  247. title: '加载中'
  248. });
  249. getLotOutsourcedInfo(query.value).then(res => {
  250. if (res.code == 200) {
  251. lot.value = res.data;
  252. console.log(res)
  253. lot.value.carrierCode = query.value.carrierCode
  254. carrierCode.value = query.value.carrierCode;
  255. // console.log("res", res);
  256. uni.hideLoading();
  257. } else {
  258. uni.showToast({
  259. icon: 'none',
  260. title: res.msg,
  261. duration: 2000
  262. })
  263. }
  264. });
  265. }
  266. function checkSave() {
  267. // uni.showToast({
  268. // title: 'lotCode:' + lot.value.lotCode + 'inspectionCarrierId: ' + lot.value.inspectionCarrierId,
  269. // icon: 'none'
  270. // })
  271. if (lot.value.lotCode == '' || lot.value.lotCode == null) {
  272. debounce(handleScanCode, 700)
  273. }
  274. if (lot.value.inspectionCarrierId == null || lot.value.inspectionCarrierId == '') {
  275. debounce(handleScanCode, 700)
  276. }
  277. }
  278. // 确定后,将批次id,批次号,传递过去
  279. const handleConfirm = () => {
  280. /** 因为调试时无法扫码所以暂时用确定方法代替扫码 **/
  281. /** 调用查询方法查询箱号信息 **/
  282. /**
  283. * 如果返回的是载具信息表示这是检查载具,将载具的id和code存到lot.inspectionCarrierId和lot.inspectionCarrierCode中
  284. * 如果返回的是1条dayweorCarrier的载具绑定信息则调用查询方法查询批次信息
  285. * 如果返回的是多条dayweorCarrier的载具绑定信息,则表示这是一箱多批需要调用选择批号弹窗在processInspection文件scan229行有对应的方法
  286. *
  287. * */
  288. if (lot.carrierCode || carrierCode.value !== "") {
  289. // lot.value.carrierCode = carrierCode.value
  290. const result = {
  291. // ...lot.value
  292. carrierCode: carrierCode.value
  293. }
  294. result.processCode = store.outsourcedCode;
  295. // console.log(result.processCode)
  296. getCarrierInfo(result).then(response => {
  297. if (response.code == 200) {
  298. // 判断是哪种返回值 假设是想信息则给lot附检查箱信息
  299. // 假设是dayworkCarriers 则 判断是几个批次,假设为多批,则弹出选择框。
  300. if (response.data.dayworkCarriers != null) {
  301. if (response.data.dayworkCarriers.length > 1) {
  302. query.value = result;
  303. selectProcessInspection.value.open(response.data.dayworkCarriers)
  304. } else {
  305. // console.log(response)
  306. uni.showLoading({
  307. title: '加载中'
  308. });
  309. // 此处根据拿到的箱子id, 获取到相对应的【 lot_id】,【 lot_code】, 以及该批次关联的其它箱号
  310. // 需要定义一个请求方法, 从后端获取
  311. getLotOutsourcedInfo(result).then(res => {
  312. if (res.code == 200) {
  313. console.log(res)
  314. lot.value = {
  315. ...lot.value,
  316. ...res.data,
  317. processNames: res.data.processList
  318. };
  319. lot.value.carrierCode = result.carrierCode
  320. carrierCode.value = result.carrierCode;
  321. // console.log("res", res);
  322. uni.hideLoading();
  323. } else {
  324. uni.showToast({
  325. icon: 'none',
  326. title: res.msg,
  327. duration: 2000
  328. })
  329. }
  330. }).catch(err => {
  331. uni.showToast({
  332. icon: 'none',
  333. title: err.message,
  334. duration: 2000
  335. })
  336. })
  337. }
  338. } else if (response.data.inspectionCarrier != null) {
  339. console.log(response)
  340. lot.value.inspectionCarrierCode = response.data.inspectionCarrier.code
  341. lot.value.inspectionCarrierId = response.data.inspectionCarrier.id
  342. }
  343. } else {
  344. uni.showToast({
  345. icon: 'none',
  346. title: response.msg,
  347. duration: 2000
  348. })
  349. }
  350. }).catch(err => {
  351. uni.showToast({
  352. icon: 'none',
  353. title: err.message,
  354. duration: 2000
  355. })
  356. })
  357. } else {
  358. uni.showToast({
  359. icon: 'none',
  360. title: "请输入箱号",
  361. duration: 2000
  362. })
  363. return;
  364. }
  365. }
  366. const handleSave = () => {
  367. console.log('保存')
  368. if (!saveLoading.value) {
  369. console.log('实效')
  370. // 判断是否已有批次和检查载具
  371. if (lot.value.lotCode == '' || lot.value.lotCode == null) {
  372. uni.showToast({
  373. icon: 'none',
  374. title: "请先扫外协箱码",
  375. duration: 2000
  376. })
  377. return
  378. }
  379. if (lot.value.inspectionCarrierId == null) {
  380. uni.showToast({
  381. icon: 'none',
  382. title: "请先扫检查载具",
  383. duration: 2000
  384. })
  385. return
  386. }
  387. // 保存
  388. if (lot.value.hasInspection == 1) {
  389. uni.showModal({
  390. title: '提示',
  391. content: `该批次已做过检查是否继续?`,
  392. success: function(res) {
  393. if (res.confirm) {
  394. saveLoading.value = true
  395. confirmThen()
  396. } else if (res.cancel) {}
  397. }
  398. })
  399. } else {
  400. saveLoading.value = true
  401. confirmThen()
  402. }
  403. }
  404. }
  405. function confirmThen() {
  406. const currentTime = Date.now();
  407. // 检查是否已经过去了 2 秒
  408. if (currentTime - lastRequestTimestamp.value < 2000) {
  409. // 如果在 2 秒 内已经点击,那么不执行
  410. uni.showToast({
  411. icon: 'none',
  412. title: `请勿重复点击`,
  413. duration: 2000
  414. })
  415. return;
  416. }
  417. lastRequestTimestamp.value = currentTime;
  418. let pages = getCurrentPages();
  419. saveOutsourcedInspecion({
  420. lot: lot.value,
  421. user: store.userInfo,
  422. status: 0,
  423. inspectionCarrierCode: lot.value.inspectionCarrierCode,
  424. inspectionCarrierId: lot.value.inspectionCarrierId,
  425. outsourceOrderDetailId: lot.value.outsourceOrderDetailId,
  426. processNames: lot.value.processNames
  427. }).then(res => {
  428. saveLoading.value = false
  429. if (res.code == 200) {
  430. let index = 0;
  431. for (let i = 0; i < pages.length; i++) {
  432. if (pages[i].$page.fullPath ==
  433. "/pages/outsourcedInspection/index") {
  434. index = pages.length - i - 1;
  435. }
  436. }
  437. console.log("index", index);
  438. uni.navigateBack({
  439. delta: index
  440. });
  441. } else {
  442. uni.showToast({
  443. icon: 'none',
  444. title: res.msg,
  445. duration: 2000
  446. })
  447. }
  448. });
  449. }
  450. </script>
  451. <style lang="scss">
  452. .page-container {
  453. height: 100%;
  454. background-color: #ececec;
  455. font-size: 28rpx;
  456. padding: 24rpx;
  457. box-sizing: border-box;
  458. }
  459. .consultation-container {
  460. background-color: #ffffff;
  461. padding: 24rpx;
  462. border-radius: 12rpx;
  463. .title {
  464. justify-content: center;
  465. font-size: 32rpx;
  466. font-weight: 700;
  467. }
  468. .info-row {
  469. margin-top: 24rpx;
  470. .label {
  471. width: 160rpx;
  472. }
  473. .value {
  474. flex: 1;
  475. textarea {
  476. flex: 1;
  477. border: 1px solid #888888;
  478. box-sizing: border-box;
  479. padding: 16rpx;
  480. }
  481. }
  482. }
  483. .btn {
  484. background-color: #1684fc;
  485. color: #ffffff;
  486. border-radius: 8rpx;
  487. margin: 4rpx 24rpx 24rpx 24rpx;
  488. height: 64rpx;
  489. justify-content: center;
  490. align-items: center;
  491. }
  492. input {
  493. margin: 48rpx 24rpx 0 24rpx;
  494. height: 64rpx;
  495. border: 1px solid #888888;
  496. text-align: center;
  497. }
  498. }
  499. </style>