scan.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  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. getPatrolLotInfo,
  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. deptId: store.curDeptDetails.deptId
  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. result.deptId = store.curDeptDetails.deptId
  140. getPatrolLotInfo(result).then(res => {
  141. if (res.code == 200) {
  142. console.log(res)
  143. if (res.data.dayworkItemList.length == 0) {
  144. uni.showToast({
  145. icon: 'none',
  146. title: "该批次本日没有可进行巡检的报工",
  147. duration: 2000
  148. })
  149. } else {
  150. getUser(res.data.dayworkItemList)
  151. getEquipment(res.data.dayworkItemList)
  152. lot.value = {
  153. ...lot.value,
  154. ...res.data
  155. };
  156. lot.value.carrierCode = result.carrierCode
  157. carrierCode.value = result.carrierCode;
  158. // console.log("res", res);
  159. uni.hideLoading();
  160. // 判断是否批次号和检查箱码都扫完
  161. checkSave()
  162. }
  163. } else {
  164. uni.showToast({
  165. icon: 'none',
  166. title: res.msg,
  167. duration: 2000
  168. })
  169. }
  170. }).catch(err => {
  171. uni.showToast({
  172. icon: 'none',
  173. title: err.message,
  174. duration: 2000
  175. })
  176. })
  177. }
  178. } else if (response.data.inspectionCarrier != null) {
  179. console.log(response)
  180. lot.value.inspectionCarrierCode = response.data.inspectionCarrier.code
  181. lot.value.inspectionCarrierId = response.data.inspectionCarrier.id
  182. // 判断是否批次号和检查箱码都扫完
  183. checkSave()
  184. }
  185. } else {
  186. uni.showToast({
  187. icon: 'none',
  188. title: response.msg,
  189. duration: 2000
  190. })
  191. }
  192. }).catch(err => {
  193. uni.showToast({
  194. icon: 'none',
  195. title: err.message,
  196. duration: 2000
  197. })
  198. })
  199. }
  200. )
  201. } else {
  202. const result = {
  203. carrierCode: '000893',
  204. deptId: store.curDeptDetails.deptId
  205. }
  206. getCarrierInfo(result).then(response => {
  207. if (response.code == 200) {
  208. // 判断是哪种返回值 假设是想信息则给lot附检查箱信息
  209. // 假设是dayworkCarriers 则 判断是几个批次,假设为多批,则弹出选择框。
  210. if (response.data.dayworkCarriers != null) {
  211. if (response.data.dayworkCarriers.length > 1) {
  212. query.value = result;
  213. query.value.deptId = store.curDeptDetails.deptId
  214. selectProcessInspection.value.open(response.data.dayworkCarriers)
  215. } else {
  216. // console.log(response)
  217. uni.showLoading({
  218. title: '加载中'
  219. });
  220. // 此处根据拿到的箱子id, 获取到相对应的【 lot_id】,【 lot_code】, 以及该批次关联的其它箱号
  221. // 需要定义一个请求方法, 从后端获取
  222. getPatrolLotInfo(result).then(res => {
  223. if (res.code == 200) {
  224. console.log(res)
  225. if (res.data.dayworkItemList.length == 0) {
  226. uni.showToast({
  227. icon: 'none',
  228. title: "该批次本日没有可进行巡检的报工",
  229. duration: 2000
  230. })
  231. } else {
  232. console.log("888")
  233. getUser(res.data.dayworkItemList)
  234. getEquipment(res.data.dayworkItemList)
  235. lot.value = {
  236. ...lot.value,
  237. ...res.data
  238. };
  239. lot.value.carrierCode = result.carrierCode
  240. carrierCode.value = result.carrierCode;
  241. lot.value.inspectionCarrierId = '1846793994468638729'
  242. lot.value.inspectionCarrierCode = "300221"
  243. // console.log("res", res);
  244. uni.hideLoading();
  245. // 判断是否批次号和检查箱码都扫完
  246. checkSave()
  247. }
  248. } else {
  249. uni.showToast({
  250. icon: 'none',
  251. title: res.msg,
  252. duration: 2000
  253. })
  254. }
  255. }).catch(err => {
  256. uni.showToast({
  257. icon: 'none',
  258. title: err.message,
  259. duration: 2000
  260. })
  261. })
  262. }
  263. } else if (response.data.inspectionCarrier != null) {
  264. console.log(response)
  265. lot.value.inspectionCarrierCode = response.data.inspectionCarrier.code
  266. lot.value.inspectionCarrierId = response.data.inspectionCarrier.id
  267. // 判断是否批次号和检查箱码都扫完
  268. checkSave()
  269. }
  270. } else {
  271. uni.showToast({
  272. icon: 'none',
  273. title: response.msg,
  274. duration: 2000
  275. })
  276. }
  277. }).catch(err => {
  278. uni.showToast({
  279. icon: 'none',
  280. title: err.message,
  281. duration: 2000
  282. })
  283. })
  284. }
  285. }
  286. function checkSave() {
  287. if (lot.value.lotCode == '' || lot.value.lotCode == null) {
  288. debounce(handleScanCode, 700)
  289. }
  290. if (lot.value.inspectionCarrierId == null || lot.value.inspectionCarrierId == '') {
  291. debounce(handleScanCode, 700)
  292. }
  293. }
  294. function handleGetEquipmentList() {
  295. getEquipment(lot.value.dayworkItemList)
  296. }
  297. function getEquipment(data) {
  298. const uniqueEquipmentMap = new Map();
  299. console.log(userId.value)
  300. let filterList = data.filter(info => info.userId == userId.value)
  301. console.log(filterList)
  302. filterList.forEach(item => {
  303. // 检查 Map 中是否已经有这个 equimentDetailId
  304. if (!uniqueEquipmentMap.has(item.equipmentDetailId)) {
  305. // 如果没有,添加到 Map 中
  306. uniqueEquipmentMap.set(item.equipmentDetailId, {
  307. value: item.equipmentDetailId,
  308. text: item.equipmentDetailCode
  309. });
  310. }
  311. });
  312. // 将 Map 的值转换为数组
  313. equipmentList.value = Array.from(uniqueEquipmentMap.values());
  314. equipment.value = equipmentList.value[0].value
  315. }
  316. function getUser(data) {
  317. const uniqueUserMap = new Map();
  318. console.log(data)
  319. data.forEach(item => {
  320. // 检查 Map 中是否已经有这个 equimentDetailId
  321. if (!uniqueUserMap.has(item.userId)) {
  322. // 如果没有,添加到 Map 中
  323. uniqueUserMap.set(item.userId, {
  324. value: item.userId,
  325. text: item.nickName
  326. });
  327. }
  328. });
  329. console.log(uniqueUserMap)
  330. // 将 Map 的值转换为数组
  331. userList.value = Array.from(uniqueUserMap.values());
  332. console.log(userList.value)
  333. userId.value = userList.value[0].value
  334. }
  335. //选择批号弹窗带回
  336. function handleSelectProcessInspection(data) {
  337. console.log("带回", data)
  338. query.value.lotCode = data
  339. uni.showLoading({
  340. title: '加载中'
  341. });
  342. getPatrolLotInfo(query.value).then(res => {
  343. if (res.code == 200) {
  344. console.log(res)
  345. if (res.data.dayworkItemList.length == 0) {
  346. uni.showToast({
  347. icon: 'none',
  348. title: "该批次当天没有报工",
  349. duration: 2000
  350. })
  351. } else {
  352. console.log("888")
  353. getUser(res.data.dayworkItemList)
  354. getEquipment(res.data.dayworkItemList)
  355. lot.value = {
  356. ...lot.value,
  357. ...res.data
  358. };
  359. lot.value.carrierCode = query.value.carrierCode
  360. carrierCode.value = query.value.carrierCode;
  361. // console.log("res", res);
  362. uni.hideLoading();
  363. // 判断是否批次号和检查箱码都扫完
  364. checkSave()
  365. }
  366. } else {
  367. uni.showToast({
  368. icon: 'none',
  369. title: res.msg,
  370. duration: 2000
  371. })
  372. }
  373. }).catch(err => {
  374. uni.showToast({
  375. icon: 'none',
  376. title: err.message,
  377. duration: 2000
  378. })
  379. })
  380. }
  381. //确定后,将批次id,批次号,传递过去
  382. const handleConfirm = () => {
  383. console.log(lot.value)
  384. if (lot.value.allCarrierName != undefined && lot.value.inspectionCarrierId != undefined) {
  385. lot.value.equipmentDetailId = equipment.value
  386. lot.value.equipmentDetailCode = equipmentList.value[equipmentList.value.findIndex(item => item.value ==
  387. equipment.value)].text
  388. lot.value.userId = userId.value
  389. lot.value.nickName = userList.value[userList.value.findIndex(item => item.value == userId.value)].text
  390. store.processInspection = null
  391. uni.navigateTo({
  392. url: "/pages/onSiteInspection/form",
  393. success: (res) => {
  394. // 通过eventChannel向被打开页面传送数据
  395. res.eventChannel.emit("onSiteInspectionFrom", {
  396. data: lot.value
  397. })
  398. }
  399. })
  400. } else {
  401. if (lot.value.allCarrierName == undefined) {
  402. uni.showToast({
  403. icon: 'none',
  404. title: "请扫描箱码",
  405. duration: 2000
  406. })
  407. } else if (lot.value.allCarrierName != undefined && lot.value.inspectionCarrierId == undefined) {
  408. uni.showToast({
  409. icon: 'none',
  410. title: "请扫描检测载具",
  411. duration: 2000
  412. })
  413. }
  414. return;
  415. }
  416. }
  417. </script>
  418. <style lang="scss">
  419. .page-container {
  420. height: 100%;
  421. background-color: #ececec;
  422. font-size: 28rpx;
  423. padding: 24rpx;
  424. box-sizing: border-box;
  425. }
  426. .consultation-container {
  427. background-color: #ffffff;
  428. padding: 24rpx;
  429. border-radius: 12rpx;
  430. .title {
  431. justify-content: center;
  432. font-size: 32rpx;
  433. font-weight: 700;
  434. }
  435. .info-row {
  436. margin-top: 24rpx;
  437. .label {
  438. width: 160rpx;
  439. }
  440. .value {
  441. flex: 1;
  442. textarea {
  443. flex: 1;
  444. border: 1px solid #888888;
  445. box-sizing: border-box;
  446. padding: 16rpx;
  447. }
  448. }
  449. }
  450. .btn {
  451. background-color: #1684fc;
  452. color: #ffffff;
  453. border-radius: 8rpx;
  454. margin: 4rpx 24rpx 24rpx 24rpx;
  455. height: 64rpx;
  456. justify-content: center;
  457. align-items: center;
  458. }
  459. input {
  460. margin: 48rpx 24rpx 0 24rpx;
  461. height: 64rpx;
  462. border: 1px solid #888888;
  463. text-align: center;
  464. }
  465. }
  466. </style>