scan.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547
  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. <!-- 选择被辅助工序 -->
  14. <view class="info-row uni-row">
  15. <view class="label">生产工序</view>
  16. <view class="value">
  17. <uni-data-select style="width: 70%;" v-model="lot.technologicalProcessDetailId"
  18. :localdata="processes" @change="handleProcessChange"></uni-data-select>
  19. </view>
  20. </view>
  21. <view class="info-row uni-row">
  22. <view class="label">辅助工序</view>
  23. <view class="value">
  24. <uni-data-select style="width: 70%;" v-model="lot.auxiliaryProcessId"
  25. :localdata="auxiliaryProcesses" @change="handleAuxiliaryProcessChange"></uni-data-select>
  26. </view>
  27. </view>
  28. <!-- 选择辅助工序 -->
  29. <view class="info-row uni-row">
  30. <view class="label">投产数量</view>
  31. <view class="value">{{ lot.pudName }}</view>
  32. </view>
  33. <view class="info-row uni-row">
  34. <view class="label">批次箱号</view>
  35. <view class="value">{{ lot.allCarrierName }}</view>
  36. </view>
  37. <!-- <input type="text" v-model="carrierCode" placeholder="请输入箱号或检查载具号" /> -->
  38. <view class="btn uni-row" style="background-color: #ff5555;" @click.stop="handleScanCode">
  39. <uni-icons type="scan" size="16" style="color: #ffffff; margin-right: 8rpx;" />
  40. <text>扫描箱码或载具二维码</text>
  41. </view>
  42. <!-- <view class="btn uni-row" style="margin-top: 48rpx;" @click.stop="handleConfirm">箱码确定</view>
  43. <view class="btn uni-row" style="background-color: #26d01d;" @click.stop="handleSave">保存
  44. </view> -->
  45. <view class="btn uni-row" style="margin-top: 48rpx;" @click.stop="handleSave">保存</view>
  46. </view>
  47. <!-- <dialog-processInspection ref='selectProcessInspection'
  48. @handleSelectProcessInspection='handleSelectProcessInspection'></dialog-processInspection> -->
  49. <dialog-daywork-choice ref="selectDaywork" @handleSelectDaywork="handleSelectDaywork"></dialog-daywork-choice>
  50. <QrScanner v-if="showQrCodeReader" @decode="onDecodeHandler" @close="qrReaderClose" />
  51. </view>
  52. </template>
  53. <script setup>
  54. import {
  55. ref
  56. } from 'vue'
  57. import {
  58. onLoad,
  59. onReady,
  60. onUnload,
  61. onShow
  62. } from '@dcloudio/uni-app'
  63. import QrScanner from '../vueQrCode/index.vue'
  64. import {
  65. saveOutsourcedInspecion,
  66. getCarrierInfo,
  67. getLotOutsourcedInfo
  68. } from '@/api/business/processInspection.js'
  69. import {
  70. getInfoByCarrierCode,
  71. getAuxiliaryProcesses,
  72. saveAuxiliaryDayowrk
  73. } from '@/api/business/auxiliaryDaywork.js'
  74. import {
  75. store
  76. } from '../../store';
  77. import {
  78. debounce
  79. } from '../../utils/common';
  80. const carrierCode = ref('')
  81. const lot = ref({})
  82. const query = ref({})
  83. const showQrCodeReader = ref(false);
  84. const selectDaywork = ref(null)
  85. const lastRequestTimestamp = ref(0);
  86. const auxiliaryProcesses = ref([])
  87. const processes = ref([])
  88. // 页面生命周期函数
  89. onLoad(() => {})
  90. //H5扫码器回调
  91. function onDecodeHandler(data) {
  92. showQrCodeReader.value = false;
  93. const result = {
  94. carrierCode: data,
  95. processCode: ''
  96. }
  97. if (!result.carrierCode || result.carrierCode == "") {
  98. uni.showToast({
  99. icon: "none",
  100. title: "请扫载具码",
  101. duration: 1000
  102. })
  103. return
  104. }
  105. //判断该箱是否绑定批次
  106. result.processCode = store.outsourcedCode;
  107. // console.log(result.processCode)
  108. /************************ 根据扫码查询到的数据和需要检查的工序查询信息 ************************/
  109. getInfoByCarrierCode(result).then(response => {
  110. if (response.code == 200) {
  111. // 判断是哪种返回值 假设是想信息则给lot附检查箱信息
  112. // 假设是dayworkCarriers 则 判断是几个批次,假设为多批,则弹出选择框。
  113. if (response.data != null) {
  114. if (response.data.length > 1) {
  115. query.value = result;
  116. selectDaywork.value.open(response.data)
  117. } else {
  118. // console.log(response)
  119. uni.showLoading({
  120. title: '加载中'
  121. })
  122. uni.hideLoading()
  123. lot.value = response.data[0]
  124. processes.value = lot.value.processSequence.map(v => ({
  125. text: v.processAlias,
  126. value: v.technologicalProcessDetailId,
  127. ...v
  128. }))
  129. }
  130. }
  131. } else {
  132. uni.showToast({
  133. icon: 'none',
  134. title: response.msg,
  135. duration: 2000
  136. })
  137. }
  138. }).catch(err => {
  139. uni.showToast({
  140. icon: 'none',
  141. title: err.message,
  142. duration: 2000
  143. })
  144. })
  145. }
  146. //H5扫码器关闭
  147. function qrReaderClose() {
  148. showQrCodeReader.value = false;
  149. }
  150. const handleScanCode = () => {
  151. showQrCodeReader.value = true;
  152. // 引入原生插件
  153. // const mpaasScanModule = uni.requireNativePlugin("Mpaas-Scan-Module");
  154. // if (mpaasScanModule) {
  155. // // 调用插件的 mpaasScan 方法
  156. // mpaasScanModule.mpaasScan({
  157. // // 扫码识别类型,参数可多选,qrCode、barCode,
  158. // // 如不设置,默认识别所有扫码类型,可能有些许影响识别效率
  159. // scanType: ["qrCode", "barCode"],
  160. // // 是否隐藏相册,默认false不隐藏
  161. // hideAlbum: false,
  162. // },
  163. // (ret) => {
  164. // console.log(ret)
  165. // const result = {
  166. // carrierCode: ret.resp_result,
  167. // processCode: ''
  168. // }
  169. // if (!result.carrierCode || result.carrierCode == "") {
  170. // uni.showToast({
  171. // icon: "none",
  172. // title: "请扫载具码",
  173. // duration: 1000
  174. // })
  175. // return
  176. // }
  177. // //判断该箱是否绑定批次
  178. // result.processCode = store.outsourcedCode;
  179. // // console.log(result.processCode)
  180. // /************************ 根据扫码查询到的数据和需要检查的工序查询信息 ************************/
  181. // getInfoByCarrierCode(result).then(response => {
  182. // if (response.code == 200) {
  183. // // 判断是哪种返回值 假设是想信息则给lot附检查箱信息
  184. // // 假设是dayworkCarriers 则 判断是几个批次,假设为多批,则弹出选择框。
  185. // if (response.data != null) {
  186. // if (response.data.length > 1) {
  187. // query.value = result;
  188. // selectDaywork.value.open(response.data)
  189. // } else {
  190. // // console.log(response)
  191. // uni.showLoading({
  192. // title: '加载中'
  193. // })
  194. // uni.hideLoading()
  195. // lot.value = response.data[0]
  196. // processes.value = lot.value.processSequence.map(v => ({
  197. // text: v.processAlias,
  198. // value: v.technologicalProcessDetailId,
  199. // ...v
  200. // }))
  201. // }
  202. // }
  203. // } else {
  204. // uni.showToast({
  205. // icon: 'none',
  206. // title: response.msg,
  207. // duration: 2000
  208. // })
  209. // }
  210. // }).catch(err => {
  211. // uni.showToast({
  212. // icon: 'none',
  213. // title: err.message,
  214. // duration: 2000
  215. // })
  216. // })
  217. // }
  218. // )
  219. // } else {
  220. // const result = {
  221. // carrierCode: '001135',
  222. // processCode: store.outsourcedCode
  223. // }
  224. // getInfoByCarrierCode(result).then(response => {
  225. // if (response.code == 200) {
  226. // // 判断是哪种返回值 假设是想信息则给lot附检查箱信息
  227. // // 假设是dayworkCarriers 则 判断是几个批次,假设为多批,则弹出选择框。
  228. // if (response.data != null) {
  229. // if (response.data.length > 1) {
  230. // query.value = result;
  231. // selectDaywork.value.open(response.data)
  232. // } else {
  233. // // console.log(response)
  234. // uni.showLoading({
  235. // title: '加载中'
  236. // })
  237. // uni.hideLoading()
  238. // lot.value = response.data[0]
  239. // processes.value = lot.value.processSequence.map(v => ({
  240. // text: v.processAlias,
  241. // value: v.technologicalProcessDetailId,
  242. // ...v
  243. // }))
  244. // }
  245. // }
  246. // } else {
  247. // uni.showToast({
  248. // icon: 'none',
  249. // title: response.msg,
  250. // duration: 2000
  251. // })
  252. // }
  253. // }).catch(err => {
  254. // uni.showToast({
  255. // icon: 'none',
  256. // title: err.message,
  257. // duration: 2000
  258. // })
  259. // })
  260. // }
  261. }
  262. //选择批号弹窗带回
  263. function handleSelectDaywork(data) {
  264. console.log("带回", data)
  265. lot.value = data
  266. processes.value = lot.value.processSequence.map(v => ({
  267. text: v.processAlias,
  268. value: v.technologicalProcessDetailId,
  269. ...v
  270. }))
  271. uni.hideLoading()
  272. // query.value.lotCode = data
  273. // uni.showLoading({
  274. // title: '加载中'
  275. // });
  276. // getLotOutsourcedInfo(query.value).then(res => {
  277. // if (res.code == 200) {
  278. // lot.value = res.data;
  279. // console.log(res)
  280. // lot.value.carrierCode = query.value.carrierCode
  281. // carrierCode.value = query.value.carrierCode;
  282. // // console.log("res", res);
  283. // uni.hideLoading();
  284. // } else {
  285. // uni.showToast({
  286. // icon: 'none',
  287. // title: res.msg,
  288. // duration: 2000
  289. // })
  290. // }
  291. // });
  292. }
  293. function checkSave() {
  294. // uni.showToast({
  295. // title: 'lotCode:' + lot.value.lotCode + 'inspectionCarrierId: ' + lot.value.inspectionCarrierId,
  296. // icon: 'none'
  297. // })
  298. if (lot.value.lotCode == '' || lot.value.lotCode == null) {
  299. debounce(handleScanCode, 700)
  300. }
  301. if (lot.value.inspectionCarrierId == null || lot.value.inspectionCarrierId == '') {
  302. debounce(handleScanCode, 700)
  303. }
  304. }
  305. // 确定后,将批次id,批次号,传递过去
  306. const handleConfirm = () => {
  307. /** 因为调试时无法扫码所以暂时用确定方法代替扫码 **/
  308. /** 调用查询方法查询箱号信息 **/
  309. /**
  310. * 如果返回的是载具信息表示这是检查载具,将载具的id和code存到lot.inspectionCarrierId和lot.inspectionCarrierCode中
  311. * 如果返回的是1条dayweorCarrier的载具绑定信息则调用查询方法查询批次信息
  312. * 如果返回的是多条dayweorCarrier的载具绑定信息,则表示这是一箱多批需要调用选择批号弹窗在processInspection文件scan229行有对应的方法
  313. *
  314. * */
  315. if (lot.carrierCode || carrierCode.value !== "") {
  316. // lot.value.carrierCode = carrierCode.value
  317. const result = {
  318. // ...lot.value
  319. carrierCode: carrierCode.value
  320. }
  321. result.processCode = store.outsourcedCode;
  322. // console.log(result.processCode)
  323. getInfoByCarrierCode(result).then(response => {
  324. if (response.code == 200) {
  325. // 判断是哪种返回值 假设是想信息则给lot附检查箱信息
  326. // 假设是dayworkCarriers 则 判断是几个批次,假设为多批,则弹出选择框。
  327. if (response.data != null) {
  328. if (response.data.length > 1) {
  329. query.value = result;
  330. selectDaywork.value.open(response.data)
  331. } else {
  332. // console.log(response)
  333. uni.showLoading({
  334. title: '加载中'
  335. })
  336. uni.hideLoading()
  337. lot.value = response.data[0]
  338. processes.value = lot.value.processSequence.map(v => ({
  339. text: v.processAlias,
  340. value: v.technologicalProcessDetailId,
  341. ...v
  342. }))
  343. }
  344. }
  345. } else {
  346. uni.showToast({
  347. icon: 'none',
  348. title: response.msg,
  349. duration: 2000
  350. })
  351. }
  352. }).catch(err => {
  353. uni.showToast({
  354. icon: 'none',
  355. title: err.message,
  356. duration: 2000
  357. })
  358. })
  359. } else {
  360. uni.showToast({
  361. icon: 'none',
  362. title: "请输入箱号",
  363. duration: 2000
  364. })
  365. return;
  366. }
  367. }
  368. const getProcesses = () => {
  369. getAuxiliaryProcesses().then(res => {
  370. if (res.code == 200) {
  371. auxiliaryProcesses.value = res.data.map(v => ({
  372. text: v.name,
  373. value: v.id,
  374. ...v
  375. }))
  376. console.log(auxiliaryProcesses.value)
  377. }
  378. })
  379. }
  380. const handleSave = () => {
  381. // 判断是否已有批次和检查载具
  382. if (lot.value.lotCode == '' || lot.value.lotCode == null) {
  383. uni.showToast({
  384. icon: 'none',
  385. title: "请先扫载具码",
  386. duration: 2000
  387. })
  388. return
  389. }
  390. if (lot.value.technologicalProcessDetailId == null) {
  391. uni.showToast({
  392. icon: 'none',
  393. title: '请先选择生产工序'
  394. })
  395. return
  396. }
  397. if (lot.value.auxiliaryProcessId == null) {
  398. uni.showToast({
  399. icon: 'none',
  400. title: '请先选择辅助工序'
  401. })
  402. return
  403. }
  404. // 保存
  405. const currentTime = Date.now();
  406. // 检查是否已经过去了 2 秒
  407. if (currentTime - lastRequestTimestamp.value < 2000) {
  408. // 如果在 2 秒 内已经点击,那么不执行
  409. uni.showToast({
  410. icon: 'none',
  411. title: `请勿重复点击`,
  412. duration: 2000
  413. })
  414. return;
  415. }
  416. lastRequestTimestamp.value = currentTime;
  417. let pages = getCurrentPages();
  418. saveAuxiliaryDayowrk({
  419. productId: lot.value.productId,
  420. userId: store.userInfo.userId,
  421. nickName: store.userInfo.nickName,
  422. userName: store.userInfo.userName,
  423. deptId: store.curDeptDetails.deptId,
  424. deptName: store.curDeptDetails.deptName,
  425. processId: lot.value.currentProcess.id,
  426. processStepNumber: lot.value.currentProcess.processStepNumber,
  427. technologicalProcessDetailId: lot.value.technologicalProcessDetailId,
  428. auxiliaryProcessId: lot.value.auxiliaryProcessId,
  429. daywork: lot.value
  430. }).then(res => {
  431. if (res.code == 200) {
  432. let index = 0;
  433. for (let i = 0; i < pages.length; i++) {
  434. if (pages[i].$page.fullPath == "/pages/auxiliaryDaywork/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. function handleProcessChange() {
  452. console.log(lot.value.processId)
  453. // 获取投产数量
  454. const process = processes.value.find(v => v.technologicalProcessDetailId == lot.value.technologicalProcessDetailId)
  455. console.log(process)
  456. const item = lot.value.dayworkItemList.find(e => e.processId == process.id && process.processStepNumber == e
  457. .processStepNumber)
  458. console.log(item)
  459. lot.value.pudName = item.prodNum
  460. lot.value.currentProcess = process
  461. }
  462. function handleAuxiliaryProcessChange() {
  463. console.log(lot.value.auxiliaryProcessId)
  464. }
  465. getProcesses()
  466. </script>
  467. <style lang="scss">
  468. .page-container {
  469. height: 100%;
  470. background-color: #ececec;
  471. font-size: 28rpx;
  472. padding: 24rpx;
  473. box-sizing: border-box;
  474. }
  475. .consultation-container {
  476. background-color: #ffffff;
  477. padding: 24rpx;
  478. border-radius: 12rpx;
  479. .title {
  480. justify-content: center;
  481. font-size: 32rpx;
  482. font-weight: 700;
  483. }
  484. .info-row {
  485. margin-top: 24rpx;
  486. .label {
  487. width: 160rpx;
  488. }
  489. .value {
  490. flex: 1;
  491. textarea {
  492. flex: 1;
  493. border: 1px solid #888888;
  494. box-sizing: border-box;
  495. padding: 16rpx;
  496. }
  497. }
  498. }
  499. .btn {
  500. background-color: #1684fc;
  501. color: #ffffff;
  502. border-radius: 8rpx;
  503. margin: 4rpx 24rpx 24rpx 24rpx;
  504. height: 64rpx;
  505. justify-content: center;
  506. align-items: center;
  507. }
  508. input {
  509. margin: 48rpx 24rpx 0 24rpx;
  510. height: 64rpx;
  511. border: 1px solid #888888;
  512. text-align: center;
  513. }
  514. }
  515. </style>