scan.vue 14 KB

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