scan.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  1. <template>
  2. <view class="page-container uni-column">
  3. <view class="consultation-container uni-column">
  4. <view class="info-row uni-row">
  5. <view class="label">批次号</view>
  6. <view class="value">{{ lot.lotCode }}</view>
  7. </view>
  8. <view class="info-row uni-row">
  9. <view class="label">图号</view>
  10. <view class="value">{{ lot.drawingNumber }}</view>
  11. </view>
  12. <view class="info-row uni-row">
  13. <view class="label">工艺版本</view>
  14. <view class="value">{{ lot.technologyVersion }}</view>
  15. </view>
  16. <view class="info-row uni-row">
  17. <view class="label">产品描述</view>
  18. <view class="value">{{ lot.productDescription }}</view>
  19. </view>
  20. <view class="info-row uni-row">
  21. <view class="label">当前工序</view>
  22. <view class="value">{{ lot.processAlias }}</view>
  23. </view>
  24. <view class="info-row uni-row">
  25. <view class="label">当前工段</view>
  26. <view class="value">{{ lot.deptName }}</view>
  27. </view>
  28. <view class="info-row uni-row" style="margin-top: 40rpx;">
  29. <view class="label">操作者</view>
  30. <view class="value">
  31. <uni-data-select v-model="userId" :localdata="userList" :clear="false"
  32. @change="handleGetEquipmentList"
  33. style="margin: 0 0 0 16rpx;outline: 2rpx solid #999999;border-radius: 10rpx;"></uni-data-select>
  34. </view>
  35. </view>
  36. <view class="info-row uni-row" style="margin-top: 40rpx;">
  37. <view class="label">加工设备</view>
  38. <view class="value">
  39. <uni-data-select v-model="equipment" :localdata="equipmentList" :clear="false"
  40. style="margin: 0 0 0 16rpx;outline: 2rpx solid #999999;border-radius: 10rpx;"></uni-data-select>
  41. </view>
  42. </view>
  43. <view class="info-row uni-row">
  44. <view class="label">所有箱号</view>
  45. <view class="value">{{ lot.allCarrierName }}</view>
  46. </view>
  47. <view class="info-row uni-row">
  48. <view class="label">巡检箱号</view>
  49. <view class="value">{{ lot.inspectionCarrierCode }}</view>
  50. </view>
  51. <!-- <input type="text" v-model="carrierCode" placeholder="请输入箱号" /> -->
  52. <view class="btn uni-row" style="background-color: #ff5555;" @click.stop="handleScanCode">
  53. <uni-icons type="scan" size="16" style="color: #ffffff; margin-right: 8rpx;" />
  54. <text>扫描箱码及检测箱码</text>
  55. </view>
  56. <view class="btn uni-row" style="margin-top: 48rpx;" @click.stop="handleConfirm">确定</view>
  57. </view>
  58. <dialog-processInspection ref='selectProcessInspection'
  59. @handleSelectProcessInspection='handleSelectProcessInspection'></dialog-processInspection>
  60. </view>
  61. </template>
  62. <script setup>
  63. import {
  64. ref
  65. } from 'vue'
  66. import {
  67. onLoad,
  68. onReady,
  69. onUnload,
  70. onShow
  71. } from '@dcloudio/uni-app'
  72. import {
  73. getDeliveryLotInfo,
  74. getCarrierInfoProcess,
  75. getCarrierInfo,
  76. } from '@/api/business/processInspection.js'
  77. import {
  78. debounce
  79. } from '../../utils/common';
  80. import {
  81. store
  82. } from '../../store';
  83. const carrierCode = ref('')
  84. const equipmentList = ref([])
  85. const userList = ref([])
  86. const userId = ref(null)
  87. const equipment = ref(null)
  88. const lot = ref({})
  89. const query = ref({})
  90. const selectProcessInspection = ref(null)
  91. // 页面生命周期函数
  92. onLoad(() => {})
  93. const handleScanCode = () => {
  94. // 引入原生插件
  95. const mpaasScanModule = uni.requireNativePlugin("Mpaas-Scan-Module");
  96. if (mpaasScanModule) {
  97. // 调用插件的 mpaasScan 方法
  98. mpaasScanModule.mpaasScan({
  99. // 扫码识别类型,参数可多选,qrCode、barCode,
  100. // 如不设置,默认识别所有扫码类型,可能有些许影响识别效率
  101. scanType: ["qrCode", "barCode"],
  102. // 是否隐藏相册,默认false不隐藏
  103. hideAlbum: false,
  104. },
  105. (ret) => {
  106. console.log(ret)
  107. const result = {
  108. carrierCode: ret.resp_result,
  109. processCode: ''
  110. }
  111. if (!result.carrierCode || result.carrierCode == "") {
  112. uni.showToast({
  113. icon: "none",
  114. title: "请扫载具码",
  115. duration: 1000
  116. })
  117. return
  118. }
  119. //判断该箱是否绑定批次
  120. result.processCode = store.outsourcedCode;
  121. // console.log(result.processCode)
  122. /************************ 根据扫码查询到的数据和需要检查的工序查询信息 ************************/
  123. getCarrierInfo(result).then(response => {
  124. if (response.code == 200) {
  125. // 判断是哪种返回值 假设是想信息则给lot附检查箱信息
  126. // 假设是dayworkCarriers 则 判断是几个批次,假设为多批,则弹出选择框。
  127. if (response.data.dayworkCarriers != null) {
  128. if (response.data.dayworkCarriers.length > 1) {
  129. query.value = result;
  130. selectProcessInspection.value.open(response.data.dayworkCarriers)
  131. } else {
  132. // console.log(response)
  133. uni.showLoading({
  134. title: '加载中'
  135. });
  136. // 此处根据拿到的箱子id, 获取到相对应的【 lot_id】,【 lot_code】, 以及该批次关联的其它箱号
  137. // 需要定义一个请求方法, 从后端获取
  138. getDeliveryLotInfo(result).then(res => {
  139. if (res.code == 200) {
  140. console.log(res)
  141. if (res.data.dayworkItemList.length == 0) {
  142. uni.showToast({
  143. icon: 'none',
  144. title: "该批次当天没有报工",
  145. duration: 2000
  146. })
  147. } else {
  148. getUser(res.data.dayworkItemList)
  149. getEquipment(res.data.dayworkItemList)
  150. lot.value = {
  151. ...lot.value,
  152. ...res.data
  153. };
  154. lot.value.carrierCode = result.carrierCode
  155. carrierCode.value = result.carrierCode;
  156. // console.log("res", res);
  157. uni.hideLoading();
  158. // 判断是否批次号和检查箱码都扫完
  159. checkSave()
  160. }
  161. } else {
  162. uni.showToast({
  163. icon: 'none',
  164. title: res.msg,
  165. duration: 2000
  166. })
  167. }
  168. }).catch(err => {
  169. uni.showToast({
  170. icon: 'none',
  171. title: err.message,
  172. duration: 2000
  173. })
  174. })
  175. }
  176. } else if (response.data.inspectionCarrier != null) {
  177. console.log(response)
  178. lot.value.inspectionCarrierCode = response.data.inspectionCarrier.code
  179. lot.value.inspectionCarrierId = response.data.inspectionCarrier.id
  180. // 判断是否批次号和检查箱码都扫完
  181. checkSave()
  182. }
  183. } else {
  184. uni.showToast({
  185. icon: 'none',
  186. title: response.msg,
  187. duration: 2000
  188. })
  189. }
  190. }).catch(err => {
  191. uni.showToast({
  192. icon: 'none',
  193. title: err.message,
  194. duration: 2000
  195. })
  196. })
  197. }
  198. )
  199. } else {
  200. const result = {
  201. carrierCode: '000052'
  202. }
  203. getCarrierInfo(result).then(response => {
  204. if (response.code == 200) {
  205. // 判断是哪种返回值 假设是想信息则给lot附检查箱信息
  206. // 假设是dayworkCarriers 则 判断是几个批次,假设为多批,则弹出选择框。
  207. if (response.data.dayworkCarriers != null) {
  208. if (response.data.dayworkCarriers.length > 1) {
  209. query.value = result;
  210. selectProcessInspection.value.open(response.data.dayworkCarriers)
  211. } else {
  212. // console.log(response)
  213. uni.showLoading({
  214. title: '加载中'
  215. });
  216. // 此处根据拿到的箱子id, 获取到相对应的【 lot_id】,【 lot_code】, 以及该批次关联的其它箱号
  217. // 需要定义一个请求方法, 从后端获取
  218. getDeliveryLotInfo(result).then(res => {
  219. if (res.code == 200) {
  220. console.log(res)
  221. if (res.data.dayworkItemList.length == 0) {
  222. uni.showToast({
  223. icon: 'none',
  224. title: "该批次当天没有报工",
  225. duration: 2000
  226. })
  227. } else {
  228. getUser(res.data.dayworkItemList)
  229. getEquipment(res.data.dayworkItemList)
  230. lot.value = {
  231. ...lot.value,
  232. ...res.data
  233. };
  234. lot.value.carrierCode = result.carrierCode
  235. carrierCode.value = result.carrierCode;
  236. lot.value.inspectionCarrierId = '1803605009558978562'
  237. lot.value.inspectionCarrierCode = "300057"
  238. // console.log("res", res);
  239. uni.hideLoading();
  240. // 判断是否批次号和检查箱码都扫完
  241. checkSave()
  242. }
  243. } else {
  244. uni.showToast({
  245. icon: 'none',
  246. title: res.msg,
  247. duration: 2000
  248. })
  249. }
  250. }).catch(err => {
  251. uni.showToast({
  252. icon: 'none',
  253. title: err.message,
  254. duration: 2000
  255. })
  256. })
  257. }
  258. } else if (response.data.inspectionCarrier != null) {
  259. console.log(response)
  260. lot.value.inspectionCarrierCode = response.data.inspectionCarrier.code
  261. lot.value.inspectionCarrierId = response.data.inspectionCarrier.id
  262. // 判断是否批次号和检查箱码都扫完
  263. checkSave()
  264. }
  265. } else {
  266. uni.showToast({
  267. icon: 'none',
  268. title: response.msg,
  269. duration: 2000
  270. })
  271. }
  272. }).catch(err => {
  273. uni.showToast({
  274. icon: 'none',
  275. title: err.message,
  276. duration: 2000
  277. })
  278. })
  279. }
  280. }
  281. function checkSave() {
  282. if (lot.value.lotCode == '' || lot.value.lotCode == null) {
  283. debounce(handleScanCode, 700)
  284. }
  285. if (lot.value.inspectionCarrierId == null || lot.value.inspectionCarrierId == '') {
  286. debounce(handleScanCode, 700)
  287. }
  288. }
  289. function handleGetEquipmentList() {
  290. getEquipment(lot.value.dayworkItemList)
  291. }
  292. function getEquipment(data) {
  293. const uniqueEquipmentMap = new Map();
  294. console.log(userId.value)
  295. let filterList = data.filter(info => info.userId == userId.value)
  296. console.log(filterList)
  297. filterList.forEach(item => {
  298. // 检查 Map 中是否已经有这个 equimentDetailId
  299. if (!uniqueEquipmentMap.has(item.equipmentDetailId)) {
  300. // 如果没有,添加到 Map 中
  301. uniqueEquipmentMap.set(item.equipmentDetailId, {
  302. value: item.equipmentDetailId,
  303. text: item.equipmentDetailCode
  304. });
  305. }
  306. });
  307. // 将 Map 的值转换为数组
  308. equipmentList.value = Array.from(uniqueEquipmentMap.values());
  309. equipment.value = equipmentList.value[0].value
  310. console.log(equipmentList.value)
  311. console.log(equipmentList.value)
  312. }
  313. function getUser(data) {
  314. const uniqueUserMap = new Map();
  315. console.log(data)
  316. data.forEach(item => {
  317. // 检查 Map 中是否已经有这个 equimentDetailId
  318. if (!uniqueUserMap.has(item.userId)) {
  319. // 如果没有,添加到 Map 中
  320. uniqueUserMap.set(item.userId, {
  321. value: item.userId,
  322. text: item.nickName
  323. });
  324. }
  325. });
  326. console.log(uniqueUserMap)
  327. // 将 Map 的值转换为数组
  328. userList.value = Array.from(uniqueUserMap.values());
  329. console.log(userList.value)
  330. userId.value = userList.value[0].value
  331. }
  332. //选择批号弹窗带回
  333. function handleSelectProcessInspection(data) {
  334. console.log("带回", data)
  335. query.value.lotCode = data
  336. uni.showLoading({
  337. title: '加载中'
  338. });
  339. getLotInfo(query.value).then(res => {
  340. if (res.code == 200) {
  341. console.log(res)
  342. if (res.data.dayworkItemList.length == 0) {
  343. uni.showToast({
  344. icon: 'none',
  345. title: "该批次当天没有报工",
  346. duration: 2000
  347. })
  348. } else {
  349. console.log("888")
  350. getUser(res.data.dayworkItemList)
  351. getEquipment(res.data.dayworkItemList)
  352. lot.value = {
  353. ...lot.value,
  354. ...res.data
  355. };
  356. lot.value.carrierCode = query.value.carrierCode
  357. carrierCode.value = query.value.carrierCode;
  358. // console.log("res", res);
  359. uni.hideLoading();
  360. // 判断是否批次号和检查箱码都扫完
  361. checkSave()
  362. }
  363. } else {
  364. uni.showToast({
  365. icon: 'none',
  366. title: res.msg,
  367. duration: 2000
  368. })
  369. }
  370. }).catch(err => {
  371. uni.showToast({
  372. icon: 'none',
  373. title: err.message,
  374. duration: 2000
  375. })
  376. })
  377. }
  378. //确定后,将批次id,批次号,传递过去
  379. const handleConfirm = () => {
  380. console.log(lot.value)
  381. if (lot.value.allCarrierName != undefined && lot.value.inspectionCarrierId != undefined) {
  382. lot.value.equipmentDetailId = equipment.value
  383. lot.value.equipmentDetailCode = equipmentList.value[equipmentList.value.findIndex(item => item.value ==
  384. equipment.value)].text
  385. lot.value.userId = userId.value
  386. lot.value.nickName = userList.value[userList.value.findIndex(item => item.value == userId.value)].text
  387. store.processInspection = null
  388. uni.navigateTo({
  389. url: "/pages/deliveryInspection/form",
  390. success: (res) => {
  391. // 通过eventChannel向被打开页面传送数据
  392. res.eventChannel.emit("deliveryInspectionFrom", {
  393. data: lot.value
  394. })
  395. }
  396. })
  397. } else {
  398. if (lot.value.allCarrierName == undefined) {
  399. uni.showToast({
  400. icon: 'none',
  401. title: "请扫描箱码",
  402. duration: 2000
  403. })
  404. } else if (lot.value.allCarrierName != undefined && lot.value.inspectionCarrierId == undefined) {
  405. uni.showToast({
  406. icon: 'none',
  407. title: "请扫描检测载具",
  408. duration: 2000
  409. })
  410. }
  411. return;
  412. }
  413. }
  414. </script>
  415. <style lang="scss">
  416. .page-container {
  417. height: 100%;
  418. background-color: #ececec;
  419. font-size: 28rpx;
  420. padding: 24rpx;
  421. box-sizing: border-box;
  422. }
  423. .consultation-container {
  424. background-color: #ffffff;
  425. padding: 24rpx;
  426. border-radius: 12rpx;
  427. .title {
  428. justify-content: center;
  429. font-size: 32rpx;
  430. font-weight: 700;
  431. }
  432. .info-row {
  433. margin-top: 24rpx;
  434. .label {
  435. width: 160rpx;
  436. }
  437. .value {
  438. flex: 1;
  439. textarea {
  440. flex: 1;
  441. border: 1px solid #888888;
  442. box-sizing: border-box;
  443. padding: 16rpx;
  444. }
  445. }
  446. }
  447. .btn {
  448. background-color: #1684fc;
  449. color: #ffffff;
  450. border-radius: 8rpx;
  451. margin: 4rpx 24rpx 24rpx 24rpx;
  452. height: 64rpx;
  453. justify-content: center;
  454. align-items: center;
  455. }
  456. input {
  457. margin: 48rpx 24rpx 0 24rpx;
  458. height: 64rpx;
  459. border: 1px solid #888888;
  460. text-align: center;
  461. }
  462. }
  463. </style>