scan.vue 14 KB

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