scan.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  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. getPatrolLotInfo,
  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. deptId : store.curDeptDetails.deptId
  112. }
  113. if (!result.carrierCode || result.carrierCode == "") {
  114. uni.showToast({
  115. icon: "none",
  116. title: "请扫载具码",
  117. duration: 1000
  118. })
  119. return
  120. }
  121. //判断该箱是否绑定批次
  122. result.processCode = store.outsourcedCode;
  123. // console.log(result.processCode)
  124. /************************ 根据扫码查询到的数据和需要检查的工序查询信息 ************************/
  125. getCarrierInfo(result).then(response => {
  126. if (response.code == 200) {
  127. // 判断是哪种返回值 假设是想信息则给lot附检查箱信息
  128. // 假设是dayworkCarriers 则 判断是几个批次,假设为多批,则弹出选择框。
  129. if (response.data.dayworkCarriers != null) {
  130. if (response.data.dayworkCarriers.length > 1) {
  131. query.value = result;
  132. selectProcessInspection.value.open(response.data.dayworkCarriers)
  133. } else {
  134. // console.log(response)
  135. uni.showLoading({
  136. title: '加载中'
  137. });
  138. // 此处根据拿到的箱子id, 获取到相对应的【 lot_id】,【 lot_code】, 以及该批次关联的其它箱号
  139. // 需要定义一个请求方法, 从后端获取
  140. result.deptId = store.curDeptDetails.deptId
  141. getPatrolLotInfo(result).then(res => {
  142. if (res.code == 200) {
  143. console.log(res)
  144. if(res.data.dayworkItemList.length == 0) {
  145. uni.showToast({
  146. icon: 'none',
  147. title: "该批次本日没有可进行巡检的报工",
  148. duration: 2000
  149. })
  150. }else{
  151. getUser(res.data.dayworkItemList)
  152. getEquipment(res.data.dayworkItemList)
  153. lot.value = {
  154. ...lot.value,
  155. ...res.data
  156. };
  157. lot.value.carrierCode = result.carrierCode
  158. carrierCode.value = result.carrierCode;
  159. // console.log("res", res);
  160. uni.hideLoading();
  161. // 判断是否批次号和检查箱码都扫完
  162. checkSave()
  163. }
  164. } else {
  165. uni.showToast({
  166. icon: 'none',
  167. title: res.msg,
  168. duration: 2000
  169. })
  170. }
  171. }).catch(err => {
  172. uni.showToast({
  173. icon: 'none',
  174. title: err.message,
  175. duration: 2000
  176. })
  177. })
  178. }
  179. } else if (response.data.inspectionCarrier != null) {
  180. console.log(response)
  181. lot.value.inspectionCarrierCode = response.data.inspectionCarrier.code
  182. lot.value.inspectionCarrierId = response.data.inspectionCarrier.id
  183. // 判断是否批次号和检查箱码都扫完
  184. checkSave()
  185. }
  186. } else {
  187. uni.showToast({
  188. icon: 'none',
  189. title: response.msg,
  190. duration: 2000
  191. })
  192. }
  193. }).catch(err => {
  194. uni.showToast({
  195. icon: 'none',
  196. title: err.message,
  197. duration: 2000
  198. })
  199. })
  200. }
  201. )
  202. } else {
  203. const result = {
  204. carrierCode: '000493',
  205. deptId : store.curDeptDetails.deptId
  206. }
  207. getCarrierInfo(result).then(response => {
  208. if (response.code == 200) {
  209. // 判断是哪种返回值 假设是想信息则给lot附检查箱信息
  210. // 假设是dayworkCarriers 则 判断是几个批次,假设为多批,则弹出选择框。
  211. if (response.data.dayworkCarriers != null) {
  212. if (response.data.dayworkCarriers.length > 1) {
  213. query.value = result;
  214. query.value.deptId = store.curDeptDetails.deptId
  215. selectProcessInspection.value.open(response.data.dayworkCarriers)
  216. } else {
  217. // console.log(response)
  218. uni.showLoading({
  219. title: '加载中'
  220. });
  221. // 此处根据拿到的箱子id, 获取到相对应的【 lot_id】,【 lot_code】, 以及该批次关联的其它箱号
  222. // 需要定义一个请求方法, 从后端获取
  223. getPatrolLotInfo(result).then(res => {
  224. if (res.code == 200) {
  225. console.log(res)
  226. if(res.data.dayworkItemList.length == 0) {
  227. uni.showToast({
  228. icon: 'none',
  229. title: "该批次本日没有可进行巡检的报工",
  230. duration: 2000
  231. })
  232. }else{
  233. console.log("888")
  234. getUser(res.data.dayworkItemList)
  235. getEquipment(res.data.dayworkItemList)
  236. lot.value = {
  237. ...lot.value,
  238. ...res.data
  239. };
  240. lot.value.carrierCode = result.carrierCode
  241. carrierCode.value = result.carrierCode;
  242. lot.value.inspectionCarrierId = '1803605009554784261'
  243. lot.value.inspectionCarrierCode = "300053"
  244. // console.log("res", res);
  245. uni.hideLoading();
  246. // 判断是否批次号和检查箱码都扫完
  247. checkSave()
  248. }
  249. } else {
  250. uni.showToast({
  251. icon: 'none',
  252. title: res.msg,
  253. duration: 2000
  254. })
  255. }
  256. }).catch(err => {
  257. uni.showToast({
  258. icon: 'none',
  259. title: err.message,
  260. duration: 2000
  261. })
  262. })
  263. }
  264. } else if (response.data.inspectionCarrier != null) {
  265. console.log(response)
  266. lot.value.inspectionCarrierCode = response.data.inspectionCarrier.code
  267. lot.value.inspectionCarrierId = response.data.inspectionCarrier.id
  268. // 判断是否批次号和检查箱码都扫完
  269. checkSave()
  270. }
  271. } else {
  272. uni.showToast({
  273. icon: 'none',
  274. title: response.msg,
  275. duration: 2000
  276. })
  277. }
  278. }).catch(err => {
  279. uni.showToast({
  280. icon: 'none',
  281. title: err.message,
  282. duration: 2000
  283. })
  284. })
  285. }
  286. }
  287. function checkSave() {
  288. if (lot.value.lotCode == '' || lot.value.lotCode == null) {
  289. debounce(handleScanCode, 700)
  290. }
  291. if (lot.value.inspectionCarrierId == null || lot.value.inspectionCarrierId == '') {
  292. debounce(handleScanCode, 700)
  293. }
  294. }
  295. function handleGetEquipmentList() {
  296. getEquipment(lot.value.dayworkItemList)
  297. }
  298. function getEquipment(data) {
  299. const uniqueEquipmentMap = new Map();
  300. console.log(userId.value)
  301. let filterList = data.filter(info => info.userId == userId.value)
  302. console.log(filterList)
  303. filterList.forEach(item => {
  304. // 检查 Map 中是否已经有这个 equimentDetailId
  305. if (!uniqueEquipmentMap.has(item.equipmentDetailId)) {
  306. // 如果没有,添加到 Map 中
  307. uniqueEquipmentMap.set(item.equipmentDetailId, {
  308. value: item.equipmentDetailId,
  309. text: item.equipmentDetailCode
  310. });
  311. }
  312. });
  313. // 将 Map 的值转换为数组
  314. equipmentList.value = Array.from(uniqueEquipmentMap.values());
  315. equipment.value = equipmentList.value[0].value
  316. }
  317. function getUser(data) {
  318. const uniqueUserMap = new Map();
  319. console.log(data)
  320. data.forEach(item => {
  321. // 检查 Map 中是否已经有这个 equimentDetailId
  322. if (!uniqueUserMap.has(item.userId)) {
  323. // 如果没有,添加到 Map 中
  324. uniqueUserMap.set(item.userId, {
  325. value: item.userId,
  326. text: item.nickName
  327. });
  328. }
  329. });
  330. console.log(uniqueUserMap)
  331. // 将 Map 的值转换为数组
  332. userList.value = Array.from(uniqueUserMap.values());
  333. console.log(userList.value)
  334. userId.value = userList.value[0].value
  335. }
  336. //选择批号弹窗带回
  337. function handleSelectProcessInspection(data) {
  338. console.log("带回", data)
  339. query.value.lotCode = data
  340. uni.showLoading({
  341. title: '加载中'
  342. });
  343. getLotInfo(query.value).then(res => {
  344. if (res.code == 200) {
  345. console.log(res)
  346. if(res.data.dayworkItemList.length == 0) {
  347. uni.showToast({
  348. icon: 'none',
  349. title: "该批次当天没有报工",
  350. duration: 2000
  351. })
  352. }else{
  353. console.log("888")
  354. getUser(res.data.dayworkItemList)
  355. getEquipment(res.data.dayworkItemList)
  356. lot.value = {
  357. ...lot.value,
  358. ...res.data
  359. };
  360. lot.value.carrierCode = query.value.carrierCode
  361. carrierCode.value = query.value.carrierCode;
  362. // console.log("res", res);
  363. uni.hideLoading();
  364. // 判断是否批次号和检查箱码都扫完
  365. checkSave()
  366. }
  367. } else {
  368. uni.showToast({
  369. icon: 'none',
  370. title: res.msg,
  371. duration: 2000
  372. })
  373. }
  374. }).catch(err => {
  375. uni.showToast({
  376. icon: 'none',
  377. title: err.message,
  378. duration: 2000
  379. })
  380. })
  381. }
  382. //确定后,将批次id,批次号,传递过去
  383. const handleConfirm = () => {
  384. console.log(lot.value)
  385. if(lot.value.allCarrierName !=undefined && lot.value.inspectionCarrierId !=undefined){
  386. lot.value.equipmentDetailId = equipment.value
  387. lot.value.equipmentDetailCode = equipmentList.value[equipmentList.value.findIndex(item =>item.value == 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>