scan.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  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: '100274',
  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. lot.value.processNames = res.data.processList
  253. console.log(res)
  254. lot.value.carrierCode = query.value.carrierCode
  255. carrierCode.value = query.value.carrierCode;
  256. // console.log("res", res);
  257. uni.hideLoading();
  258. } else {
  259. uni.showToast({
  260. icon: 'none',
  261. title: res.msg,
  262. duration: 2000
  263. })
  264. }
  265. });
  266. }
  267. function checkSave() {
  268. // uni.showToast({
  269. // title: 'lotCode:' + lot.value.lotCode + 'inspectionCarrierId: ' + lot.value.inspectionCarrierId,
  270. // icon: 'none'
  271. // })
  272. if (lot.value.lotCode == '' || lot.value.lotCode == null) {
  273. debounce(handleScanCode, 700)
  274. }
  275. if (lot.value.inspectionCarrierId == null || lot.value.inspectionCarrierId == '') {
  276. debounce(handleScanCode, 700)
  277. }
  278. }
  279. // 确定后,将批次id,批次号,传递过去
  280. const handleConfirm = () => {
  281. /** 因为调试时无法扫码所以暂时用确定方法代替扫码 **/
  282. /** 调用查询方法查询箱号信息 **/
  283. /**
  284. * 如果返回的是载具信息表示这是检查载具,将载具的id和code存到lot.inspectionCarrierId和lot.inspectionCarrierCode中
  285. * 如果返回的是1条dayweorCarrier的载具绑定信息则调用查询方法查询批次信息
  286. * 如果返回的是多条dayweorCarrier的载具绑定信息,则表示这是一箱多批需要调用选择批号弹窗在processInspection文件scan229行有对应的方法
  287. *
  288. * */
  289. if (lot.carrierCode || carrierCode.value !== "") {
  290. // lot.value.carrierCode = carrierCode.value
  291. const result = {
  292. // ...lot.value
  293. carrierCode: carrierCode.value
  294. }
  295. result.processCode = store.outsourcedCode;
  296. // console.log(result.processCode)
  297. getCarrierInfo(result).then(response => {
  298. if (response.code == 200) {
  299. // 判断是哪种返回值 假设是想信息则给lot附检查箱信息
  300. // 假设是dayworkCarriers 则 判断是几个批次,假设为多批,则弹出选择框。
  301. if (response.data.dayworkCarriers != null) {
  302. if (response.data.dayworkCarriers.length > 1) {
  303. query.value = result;
  304. selectProcessInspection.value.open(response.data.dayworkCarriers)
  305. } else {
  306. // console.log(response)
  307. uni.showLoading({
  308. title: '加载中'
  309. });
  310. // 此处根据拿到的箱子id, 获取到相对应的【 lot_id】,【 lot_code】, 以及该批次关联的其它箱号
  311. // 需要定义一个请求方法, 从后端获取
  312. getLotOutsourcedInfo(result).then(res => {
  313. if (res.code == 200) {
  314. console.log(res)
  315. lot.value = {
  316. ...lot.value,
  317. ...res.data,
  318. processNames: res.data.processList
  319. };
  320. lot.value.carrierCode = result.carrierCode
  321. carrierCode.value = result.carrierCode;
  322. // console.log("res", res);
  323. uni.hideLoading();
  324. } else {
  325. uni.showToast({
  326. icon: 'none',
  327. title: res.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. } else if (response.data.inspectionCarrier != null) {
  340. console.log(response)
  341. lot.value.inspectionCarrierCode = response.data.inspectionCarrier.code
  342. lot.value.inspectionCarrierId = response.data.inspectionCarrier.id
  343. }
  344. } else {
  345. uni.showToast({
  346. icon: 'none',
  347. title: response.msg,
  348. duration: 2000
  349. })
  350. }
  351. }).catch(err => {
  352. uni.showToast({
  353. icon: 'none',
  354. title: err.message,
  355. duration: 2000
  356. })
  357. })
  358. } else {
  359. uni.showToast({
  360. icon: 'none',
  361. title: "请输入箱号",
  362. duration: 2000
  363. })
  364. return;
  365. }
  366. }
  367. const handleSave = () => {
  368. console.log('保存')
  369. if (!saveLoading.value) {
  370. console.log('实效')
  371. // 判断是否已有批次和检查载具
  372. if (lot.value.lotCode == '' || lot.value.lotCode == null) {
  373. uni.showToast({
  374. icon: 'none',
  375. title: "请先扫外协箱码",
  376. duration: 2000
  377. })
  378. return
  379. }
  380. if (lot.value.inspectionCarrierId == null) {
  381. uni.showToast({
  382. icon: 'none',
  383. title: "请先扫检查载具",
  384. duration: 2000
  385. })
  386. return
  387. }
  388. // 保存
  389. if (lot.value.hasInspection == 1) {
  390. uni.showModal({
  391. title: '提示',
  392. content: `该批次已做过检查是否继续?`,
  393. success: function(res) {
  394. if (res.confirm) {
  395. saveLoading.value = true
  396. confirmThen()
  397. } else if (res.cancel) {}
  398. }
  399. })
  400. } else {
  401. saveLoading.value = true
  402. confirmThen()
  403. }
  404. }
  405. }
  406. function confirmThen() {
  407. const currentTime = Date.now();
  408. // 检查是否已经过去了 2 秒
  409. if (currentTime - lastRequestTimestamp.value < 2000) {
  410. // 如果在 2 秒 内已经点击,那么不执行
  411. uni.showToast({
  412. icon: 'none',
  413. title: `请勿重复点击`,
  414. duration: 2000
  415. })
  416. return;
  417. }
  418. lastRequestTimestamp.value = currentTime;
  419. let pages = getCurrentPages();
  420. saveOutsourcedInspecion({
  421. lot: lot.value,
  422. user: store.userInfo,
  423. status: 0,
  424. inspectionCarrierCode: lot.value.inspectionCarrierCode,
  425. inspectionCarrierId: lot.value.inspectionCarrierId,
  426. outsourceOrderDetailId: lot.value.outsourceOrderDetailId,
  427. processNames: lot.value.processNames
  428. }).then(res => {
  429. saveLoading.value = false
  430. if (res.code == 200) {
  431. let index = 0;
  432. for (let i = 0; i < pages.length; i++) {
  433. if (pages[i].$page.fullPath ==
  434. "/pages/outsourcedInspection/index") {
  435. index = pages.length - i - 1;
  436. }
  437. }
  438. console.log("index", index);
  439. uni.navigateBack({
  440. delta: index
  441. });
  442. } else {
  443. uni.showToast({
  444. icon: 'none',
  445. title: res.msg,
  446. duration: 2000
  447. })
  448. }
  449. });
  450. }
  451. </script>
  452. <style lang="scss">
  453. .page-container {
  454. height: 100%;
  455. background-color: #ececec;
  456. font-size: 28rpx;
  457. padding: 24rpx;
  458. box-sizing: border-box;
  459. }
  460. .consultation-container {
  461. background-color: #ffffff;
  462. padding: 24rpx;
  463. border-radius: 12rpx;
  464. .title {
  465. justify-content: center;
  466. font-size: 32rpx;
  467. font-weight: 700;
  468. }
  469. .info-row {
  470. margin-top: 24rpx;
  471. .label {
  472. width: 160rpx;
  473. }
  474. .value {
  475. flex: 1;
  476. textarea {
  477. flex: 1;
  478. border: 1px solid #888888;
  479. box-sizing: border-box;
  480. padding: 16rpx;
  481. }
  482. }
  483. }
  484. .btn {
  485. background-color: #1684fc;
  486. color: #ffffff;
  487. border-radius: 8rpx;
  488. margin: 4rpx 24rpx 24rpx 24rpx;
  489. height: 64rpx;
  490. justify-content: center;
  491. align-items: center;
  492. }
  493. input {
  494. margin: 48rpx 24rpx 0 24rpx;
  495. height: 64rpx;
  496. border: 1px solid #888888;
  497. text-align: center;
  498. }
  499. }
  500. </style>