scan.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  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"
  32. :clear="false" @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"
  40. :clear="false"
  41. style="margin: 0 0 0 16rpx;outline: 2rpx solid #999999;border-radius: 10rpx;"></uni-data-select>
  42. </view>
  43. </view>
  44. <view class="info-row uni-row">
  45. <view class="label">所有箱号</view>
  46. <view class="value">{{ lot.allCarrierName }}</view>
  47. </view>
  48. <view class="info-row uni-row">
  49. <view class="label">巡检箱号</view>
  50. <view class="value">{{ lot.inspectionCarrierCode }}</view>
  51. </view>
  52. <!-- <input type="text" v-model="carrierCode" placeholder="请输入箱号" /> -->
  53. <view class="btn uni-row" style="background-color: #ff5555;" @click.stop="handleScanCode">
  54. <uni-icons type="scan" size="16" style="color: #ffffff; margin-right: 8rpx;" />
  55. <text>扫描箱码及检测箱码</text>
  56. </view>
  57. <view class="btn uni-row" style="margin-top: 48rpx;" @click.stop="handleConfirm">确定</view>
  58. </view>
  59. <dialog-processInspection ref='selectProcessInspection'
  60. @handleSelectProcessInspection='handleSelectProcessInspection'></dialog-processInspection>
  61. </view>
  62. </template>
  63. <script setup>
  64. import {
  65. ref
  66. } from 'vue'
  67. import {
  68. onLoad,
  69. onReady,
  70. onUnload,
  71. onShow
  72. } from '@dcloudio/uni-app'
  73. import {
  74. getDeliveryLotInfo,
  75. getCarrierInfoProcess,
  76. getCarrierInfo,
  77. } from '@/api/business/processInspection.js'
  78. import {
  79. debounce
  80. } from '../../utils/common';
  81. import {
  82. store
  83. } from '../../store';
  84. const carrierCode = ref('')
  85. const equipmentList = ref([])
  86. const userList = ref([])
  87. const userId = ref(null)
  88. const equipment = ref(null)
  89. const lot = ref({})
  90. const query = ref({})
  91. const selectProcessInspection = ref(null)
  92. // 页面生命周期函数
  93. onLoad(() => {})
  94. const handleScanCode = () => {
  95. // 引入原生插件
  96. const mpaasScanModule = uni.requireNativePlugin("Mpaas-Scan-Module");
  97. if (mpaasScanModule) {
  98. // 调用插件的 mpaasScan 方法
  99. mpaasScanModule.mpaasScan({
  100. // 扫码识别类型,参数可多选,qrCode、barCode,
  101. // 如不设置,默认识别所有扫码类型,可能有些许影响识别效率
  102. scanType: ["qrCode", "barCode"],
  103. // 是否隐藏相册,默认false不隐藏
  104. hideAlbum: false,
  105. },
  106. (ret) => {
  107. console.log(ret)
  108. const result = {
  109. carrierCode: ret.resp_result,
  110. processCode: ''
  111. }
  112. if (!result.carrierCode || result.carrierCode == "") {
  113. uni.showToast({
  114. icon: "none",
  115. title: "请扫载具码",
  116. duration: 1000
  117. })
  118. return
  119. }
  120. //判断该箱是否绑定批次
  121. result.processCode = store.outsourcedCode;
  122. // console.log(result.processCode)
  123. /************************ 根据扫码查询到的数据和需要检查的工序查询信息 ************************/
  124. getCarrierInfo(result).then(response => {
  125. if (response.code == 200) {
  126. // 判断是哪种返回值 假设是想信息则给lot附检查箱信息
  127. // 假设是dayworkCarriers 则 判断是几个批次,假设为多批,则弹出选择框。
  128. if (response.data.dayworkCarriers != null) {
  129. if (response.data.dayworkCarriers.length > 1) {
  130. query.value = result;
  131. selectProcessInspection.value.open(response.data.dayworkCarriers)
  132. } else {
  133. // console.log(response)
  134. uni.showLoading({
  135. title: '加载中'
  136. });
  137. // 此处根据拿到的箱子id, 获取到相对应的【 lot_id】,【 lot_code】, 以及该批次关联的其它箱号
  138. // 需要定义一个请求方法, 从后端获取
  139. getDeliveryLotInfo(result).then(res => {
  140. if (res.code == 200) {
  141. console.log(res)
  142. if(res.data.dayworkItemList.length == 0) {
  143. uni.showToast({
  144. icon: 'none',
  145. title: "该批次当天没有报工",
  146. duration: 2000
  147. })
  148. }else{
  149. getUser(res.data.dayworkItemList)
  150. getEquipment(res.data.dayworkItemList)
  151. lot.value = {
  152. ...lot.value,
  153. ...res.data
  154. };
  155. lot.value.carrierCode = result.carrierCode
  156. carrierCode.value = result.carrierCode;
  157. // console.log("res", res);
  158. uni.hideLoading();
  159. // 判断是否批次号和检查箱码都扫完
  160. checkSave()
  161. }
  162. } else {
  163. uni.showToast({
  164. icon: 'none',
  165. title: res.msg,
  166. duration: 2000
  167. })
  168. }
  169. }).catch(err => {
  170. uni.showToast({
  171. icon: 'none',
  172. title: err.message,
  173. duration: 2000
  174. })
  175. })
  176. }
  177. } else if (response.data.inspectionCarrier != null) {
  178. console.log(response)
  179. lot.value.inspectionCarrierCode = response.data.inspectionCarrier.code
  180. lot.value.inspectionCarrierId = response.data.inspectionCarrier.id
  181. // 判断是否批次号和检查箱码都扫完
  182. checkSave()
  183. }
  184. } else {
  185. uni.showToast({
  186. icon: 'none',
  187. title: response.msg,
  188. duration: 2000
  189. })
  190. }
  191. }).catch(err => {
  192. uni.showToast({
  193. icon: 'none',
  194. title: err.message,
  195. duration: 2000
  196. })
  197. })
  198. }
  199. )
  200. } else {
  201. const result = {
  202. carrierCode: '000948'
  203. }
  204. getCarrierInfo(result).then(response => {
  205. if (response.code == 200) {
  206. // 判断是哪种返回值 假设是想信息则给lot附检查箱信息
  207. // 假设是dayworkCarriers 则 判断是几个批次,假设为多批,则弹出选择框。
  208. if (response.data.dayworkCarriers != null) {
  209. if (response.data.dayworkCarriers.length > 1) {
  210. query.value = result;
  211. selectProcessInspection.value.open(response.data.dayworkCarriers)
  212. } else {
  213. // console.log(response)
  214. uni.showLoading({
  215. title: '加载中'
  216. });
  217. // 此处根据拿到的箱子id, 获取到相对应的【 lot_id】,【 lot_code】, 以及该批次关联的其它箱号
  218. // 需要定义一个请求方法, 从后端获取
  219. getDeliveryLotInfo(result).then(res => {
  220. if (res.code == 200) {
  221. console.log(res)
  222. if(res.data.dayworkItemList.length == 0) {
  223. uni.showToast({
  224. icon: 'none',
  225. title: "该批次当天没有报工",
  226. duration: 2000
  227. })
  228. }else{
  229. getUser(res.data.dayworkItemList)
  230. getEquipment(res.data.dayworkItemList)
  231. lot.value = {
  232. ...lot.value,
  233. ...res.data
  234. };
  235. lot.value.carrierCode = result.carrierCode
  236. carrierCode.value = result.carrierCode;
  237. lot.value.inspectionCarrierId = '1803605009558978562'
  238. lot.value.inspectionCarrierCode = "300057"
  239. // console.log("res", res);
  240. uni.hideLoading();
  241. // 判断是否批次号和检查箱码都扫完
  242. checkSave()
  243. }
  244. } else {
  245. uni.showToast({
  246. icon: 'none',
  247. title: res.msg,
  248. duration: 2000
  249. })
  250. }
  251. }).catch(err => {
  252. uni.showToast({
  253. icon: 'none',
  254. title: err.message,
  255. duration: 2000
  256. })
  257. })
  258. }
  259. } else if (response.data.inspectionCarrier != null) {
  260. console.log(response)
  261. lot.value.inspectionCarrierCode = response.data.inspectionCarrier.code
  262. lot.value.inspectionCarrierId = response.data.inspectionCarrier.id
  263. // 判断是否批次号和检查箱码都扫完
  264. checkSave()
  265. }
  266. } else {
  267. uni.showToast({
  268. icon: 'none',
  269. title: response.msg,
  270. duration: 2000
  271. })
  272. }
  273. }).catch(err => {
  274. uni.showToast({
  275. icon: 'none',
  276. title: err.message,
  277. duration: 2000
  278. })
  279. })
  280. }
  281. }
  282. function checkSave() {
  283. if (lot.value.lotCode == '' || lot.value.lotCode == null) {
  284. debounce(handleScanCode, 700)
  285. }
  286. if (lot.value.inspectionCarrierId == null || lot.value.inspectionCarrierId == '') {
  287. debounce(handleScanCode, 700)
  288. }
  289. }
  290. function handleGetEquipmentList() {
  291. getEquipment(lot.value.dayworkItemList)
  292. }
  293. function getEquipment(data) {
  294. const uniqueEquipmentMap = new Map();
  295. console.log(userId.value)
  296. let filterList = data.filter(info => info.userId == userId.value)
  297. console.log(filterList)
  298. filterList.forEach(item => {
  299. // 检查 Map 中是否已经有这个 equimentDetailId
  300. if (!uniqueEquipmentMap.has(item.equipmentDetailId)) {
  301. // 如果没有,添加到 Map 中
  302. uniqueEquipmentMap.set(item.equipmentDetailId, {
  303. value: item.equipmentDetailId,
  304. text: item.equipmentDetailCode
  305. });
  306. }
  307. });
  308. // 将 Map 的值转换为数组
  309. equipmentList.value = Array.from(uniqueEquipmentMap.values());
  310. equipment.value = equipmentList.value[0].value
  311. console.log(equipmentList.value)
  312. console.log(equipmentList.value)
  313. }
  314. function getUser(data) {
  315. const uniqueUserMap = new Map();
  316. console.log(data)
  317. data.forEach(item => {
  318. // 检查 Map 中是否已经有这个 equimentDetailId
  319. if (!uniqueUserMap.has(item.userId)) {
  320. // 如果没有,添加到 Map 中
  321. uniqueUserMap.set(item.userId, {
  322. value: item.userId,
  323. text: item.nickName
  324. });
  325. }
  326. });
  327. console.log(uniqueUserMap)
  328. // 将 Map 的值转换为数组
  329. userList.value = Array.from(uniqueUserMap.values());
  330. console.log(userList.value)
  331. userId.value = userList.value[0].value
  332. }
  333. //选择批号弹窗带回
  334. function handleSelectProcessInspection(data) {
  335. console.log("带回", data)
  336. query.value.lotCode = data
  337. uni.showLoading({
  338. title: '加载中'
  339. });
  340. getLotInfo(query.value).then(res => {
  341. if (res.code == 200) {
  342. console.log(res)
  343. if(res.data.dayworkItemList.length == 0) {
  344. uni.showToast({
  345. icon: 'none',
  346. title: "该批次当天没有报工",
  347. duration: 2000
  348. })
  349. }else{
  350. console.log("888")
  351. getUser(res.data.dayworkItemList)
  352. getEquipment(res.data.dayworkItemList)
  353. lot.value = {
  354. ...lot.value,
  355. ...res.data
  356. };
  357. lot.value.carrierCode = query.value.carrierCode
  358. carrierCode.value = query.value.carrierCode;
  359. // console.log("res", res);
  360. uni.hideLoading();
  361. // 判断是否批次号和检查箱码都扫完
  362. checkSave()
  363. }
  364. } else {
  365. uni.showToast({
  366. icon: 'none',
  367. title: res.msg,
  368. duration: 2000
  369. })
  370. }
  371. }).catch(err => {
  372. uni.showToast({
  373. icon: 'none',
  374. title: err.message,
  375. duration: 2000
  376. })
  377. })
  378. }
  379. //确定后,将批次id,批次号,传递过去
  380. const handleConfirm = () => {
  381. console.log(lot.value)
  382. if(lot.value.allCarrierName !=undefined && lot.value.inspectionCarrierId !=undefined){
  383. lot.value.equipmentDetailId = equipment.value
  384. lot.value.equipmentDetailCode = equipmentList.value[equipmentList.value.findIndex(item =>item.value == 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>