scan.vue 14 KB

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