scan.vue 14 KB

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