scan.vue 13 KB

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