index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
  1. <template>
  2. <view class="uni-column" style="height: 96%;padding: 24rpx;">
  3. <view v-if="allData.length>0" style="margin-bottom: 10rpx;">
  4. <view>
  5. <view class="item-info uni-row" style="height: 80rpx;">
  6. <view style="flex: 2;">
  7. <button :class="[ checkAll ? 'active' : 'select' ]" @click="handleAll"
  8. style="margin-left: 0px;display: flex; align-items: center; justify-content: center;">全选</button>
  9. </view>
  10. <button @click="handleSearch" style="margin-right: 20rpx ;">搜索</button>
  11. <uni-data-select v-model="workshopId" :localdata="workshopList" @change="handleChangeWorkshop"
  12. :clear="false" class="label right"
  13. style=" margin-right: 20rpx; outline: 2rpx solid #999999;border-radius: 10rpx;flex: 1;"></uni-data-select>
  14. </view>
  15. </view>
  16. </view>
  17. <view v-if="allData.length>0" style="overflow: auto; margin-bottom: 100rpx;">
  18. <view v-for="(item, index) in listData" :key="index" :class="{'list-item':true,'selected':isSelected(item)}"
  19. @click="handleSelection(item)">
  20. <view class="title-container uni-row">
  21. <view class="title uni-row"><text class="label">{{item.lotCode}}</text></view>
  22. <view><button class="start-batch-btn uni-row"
  23. style="height: 70rpx; display: flex; align-items: center; justify-content: center;"
  24. type=primary @click.stop='handleChangeCarrier(item)'>换箱</button>
  25. </view>
  26. </view>
  27. <view class="item-info uni-row">
  28. <text class="label">产品描述</text>
  29. <text class="label right">{{item['productDescription']}}</text>
  30. </view>
  31. <view class="item-info uni-row">
  32. <text class="label">关联箱号</text>
  33. <text class="label right">{{item['carrierName']}}</text>
  34. </view>
  35. <view class="item-info uni-row">
  36. <view class="label">设备</view>
  37. <text class="label right">{{item['equipmentDetailCode']}}</text>
  38. </view>
  39. <view class="item-info uni-row">
  40. <text class="label">当前序</text>
  41. <text class="label right">{{item['process'].processAlias}}</text>
  42. </view>
  43. <view class="item-info uni-row">
  44. <text class="label">下序</text>
  45. <text class="label right">{{item['nextProcess'].processAlias}}</text>
  46. </view>
  47. <view class="item-info uni-row">
  48. <text class="label">下序工段</text>
  49. <text class="label right">{{item.quickInfo.deptName}}</text>
  50. </view>
  51. </view>
  52. </view>
  53. <view v-if="allData.length==0" style="color: #999;">
  54. <image style="width: 420rpx; height: 420rpx; padding-top: 30% ; margin: auto;"
  55. src="../../static/images/fastProductionPlan.png" />
  56. </view>
  57. <view v-if="allData.length==0" class='bottom-btn-container'>
  58. <text style="margin: auto; padding-bottom: 10%;">扫箱码开始快速报工</text>
  59. <button class="start-batch-btn uni-row" type=primary @click='handleAdd'>扫码开始报工</button>
  60. </view>
  61. <view v-if="allData.length>0" class='btn uni-row'>
  62. <button class='bottom-btn left-btn' type="warn" @click="handleEnd">结束报工</button>
  63. <button class='bottom-btn right-btn' type="primary" @click="handleContinue">继续扫码</button>
  64. </view>
  65. <dialog-lotReporting ref="lotReporting" :getList="init" @scan="handleAdd"></dialog-lotReporting>
  66. <dialog-Search ref="searchRef" @search="refreshSearch"></dialog-Search>
  67. </view>
  68. <view
  69. style="background-color: #99999999; z-index: 5; position: absolute; left: 0px; right: 0px; top: 0px; bottom: 0px;"
  70. v-if="loading">
  71. </view>
  72. </template>
  73. <script setup>
  74. import {
  75. getPlanDetailsList
  76. } from '@/api/business/planDetails.js'
  77. import {
  78. store
  79. } from '@/store/index.js'
  80. import {
  81. onShow
  82. } from '@dcloudio/uni-app'
  83. import {
  84. getDayWorkList,
  85. showDaywork,
  86. showDayworkSave,
  87. turnoverDelete
  88. } from '@/api/business/dayWork.js'
  89. import {
  90. getQuickDayworkList,
  91. finishQuick,
  92. getDayworkByCarrierId,
  93. getDayworkByCarrierCode,
  94. reportDaywork
  95. } from '@/api/business/quickDaywork'
  96. import {
  97. isTakeStock
  98. } from '@/api/business/taksStackLot.js'
  99. import {
  100. ref
  101. } from 'vue'
  102. import path from '@/api/base/path.js'
  103. const lotReporting = ref(null)
  104. const workshopId = ref(null);
  105. const searchRef = ref(null);
  106. const keyword = ref('')
  107. const loading = ref(false)
  108. const form = ref([]); //表单数据true
  109. const checkAll = ref(false); //是否全选
  110. // 创建一个引用来存储最后一次请求的时间戳
  111. const lastRequestTimestamp = ref(0);
  112. const listData = ref([]);
  113. const allData = ref([])
  114. const selection = ref([]); //选中数据
  115. const workshopList = ref([]); //车间数据
  116. onShow(() => {
  117. init()
  118. })
  119. //初始化
  120. function init() {
  121. // console.log(store.curDeptDetails)
  122. uni.showLoading({
  123. title: '加载中'
  124. });
  125. checkAll.value = false
  126. getQuickDayworkList({
  127. deptId: store.curDeptDetails.deptId,
  128. }).then(res => {
  129. // console.log(res)
  130. if (res.code == 200) {
  131. allData.value = res.rows
  132. if (allData.value.length == 0) {
  133. listData.value = []
  134. }
  135. uni.hideLoading();
  136. }
  137. if (res.other.workShops != null) {
  138. workshopList.value = res.other.workShops.map(v => ({
  139. value: v.id,
  140. text: v.name,
  141. depts: v.depts
  142. }))
  143. if ((workshopId.value == null || !workshopList.value.some(e => e.value === workshopId.value)) &&
  144. workshopList.value.length > 0) {
  145. workshopId.value = workshopList.value[0].value
  146. handleChangeWorkshop(workshopId.value)
  147. } else {
  148. handleChangeWorkshop(workshopId.value)
  149. }
  150. } else {
  151. workshopList.value = []
  152. }
  153. uni.hideLoading();
  154. loading.value = false
  155. })
  156. }
  157. // 搜索按钮操作
  158. function handleSearch() {
  159. searchRef.value.open();
  160. }
  161. function refreshSearch(input) {
  162. // console.log(input)
  163. keyword.value = input
  164. handleChangeWorkshop(workshopId.value)
  165. }
  166. /* 【原有代码】
  167. function handleAdd() {
  168. const mpaasScanModule = uni.requireNativePlugin("Mpaas-Scan-Module");
  169. if (mpaasScanModule) {
  170. // 调用插件的 mpaasScan 方法
  171. mpaasScanModule.mpaasScan({
  172. // 扫码识别类型,参数可多选,qrCode、barCode,
  173. // 如不设置,默认识别所有扫码类型,可能有些许影响识别效率
  174. scanType: ["qrCode", "barCode"],
  175. // 是否隐藏相册,默认false不隐藏
  176. hideAlbum: false,
  177. },
  178. (ret) => {
  179. let vehicleObj = JSON.parse(ret.resp_result);
  180. if (!vehicleObj.carrierId || vehicleObj.carrierId == "") {
  181. uni.showToast({
  182. icon: "none",
  183. title: "请扫载具码",
  184. duration: 1000
  185. })
  186. return;
  187. }
  188. getDayworkByCarrierId({
  189. carrierId: vehicleObj.carrierId,
  190. deptId: store.curDeptDetails.deptId,
  191. status: 7
  192. }).then(response => {
  193. if (response.code == 200) {
  194. // console.log(response.data.items.length)
  195. // console.log(response.data)
  196. // if (response.data.items[0].deptId !== store.curDeptDetails.deptId) {
  197. // uni.showToast({
  198. // icon: 'none',
  199. // title: '该批次不在当前工段',
  200. // duration: 2000
  201. // })
  202. // return
  203. // }
  204. if (response.data.items.length > 0) {
  205. lotReporting.value.open(response.data);
  206. } else {
  207. uni.showToast({
  208. icon: 'none',
  209. title: '该批次不在此计划单内, 或不在当前工段',
  210. duration: 2000
  211. })
  212. }
  213. } else {
  214. uni.showToast({
  215. icon: 'none',
  216. title: response.msg,
  217. duration: 2000
  218. })
  219. }
  220. })
  221. }
  222. );
  223. } else {
  224. // 测试时用
  225. getDayworkByCarrierId({
  226. carrierId: '1747500987688890381',
  227. status: 7,
  228. deptId: store.curDeptDetails.deptId,
  229. }).then(response => {
  230. console.log(response)
  231. if (response.code == 200) {
  232. //
  233. // if (response.data.items[0].deptId !== store.curDeptDetails.deptId) {
  234. // uni.showToast({
  235. // icon: 'none',
  236. // title: '该批次不在当前工段',
  237. // duration: 2000
  238. // })
  239. // return
  240. // }
  241. if (response.data.items.length > 0) {
  242. // console.log(response.data)
  243. lotReporting.value.open(response.data);
  244. } else {
  245. uni.showToast({
  246. icon: 'none',
  247. title: '该批次不在此计划单内, 或不在当前工段',
  248. duration: 2000
  249. })
  250. }
  251. } else {
  252. uni.showToast({
  253. icon: 'none',
  254. title: response.msg,
  255. duration: 2000
  256. })
  257. }
  258. })
  259. }
  260. // lotReporting.value.open(data);
  261. }
  262. */
  263. function handleAdd() {
  264. const mpaasScanModule = uni.requireNativePlugin("Mpaas-Scan-Module");
  265. if (mpaasScanModule) {
  266. // 调用插件的 mpaasScan 方法
  267. mpaasScanModule.mpaasScan({
  268. // 扫码识别类型,参数可多选,qrCode、barCode,
  269. // 如不设置,默认识别所有扫码类型,可能有些许影响识别效率
  270. scanType: ["qrCode", "barCode"],
  271. // 是否隐藏相册,默认false不隐藏
  272. hideAlbum: false,
  273. },
  274. (ret) => {
  275. let vehicleObj = {
  276. carrierCode: ret.resp_result
  277. };
  278. if (!vehicleObj.carrierCode || vehicleObj.carrierCode == "") {
  279. uni.showToast({
  280. icon: "none",
  281. title: "请扫载具码",
  282. duration: 1000
  283. })
  284. return;
  285. }
  286. getDayworkByCarrierCode({
  287. carrierCode: vehicleObj.carrierCode,
  288. deptId: store.curDeptDetails.deptId,
  289. status: 7
  290. }).then(response => {
  291. if (response.code == 200) {
  292. if (response.data.items.length > 0) {
  293. lotReporting.value.open(response.data);
  294. } else {
  295. uni.showToast({
  296. icon: 'none',
  297. title: '该批次不在此计划单内, 或不在当前工段',
  298. duration: 2000
  299. })
  300. }
  301. } else {
  302. uni.showToast({
  303. icon: 'none',
  304. title: response.msg,
  305. duration: 2000
  306. })
  307. }
  308. })
  309. }
  310. );
  311. } else {
  312. // 测试时用
  313. getDayworkByCarrierCode({
  314. carrierCode: '000653',
  315. status: 7,
  316. deptId: store.curDeptDetails.deptId
  317. }).then(response => {
  318. console.log(response)
  319. if (response.code == 200) {
  320. //
  321. // if (response.data.items[0].deptId !== store.curDeptDetails.deptId) {
  322. // uni.showToast({
  323. // icon: 'none',
  324. // title: '该批次不在当前工段',
  325. // duration: 2000
  326. // })
  327. // return
  328. // }
  329. if (response.data.items.length > 0) {
  330. // console.log(response.data)
  331. lotReporting.value.open(response.data);
  332. } else {
  333. uni.showToast({
  334. icon: 'none',
  335. title: '该批次不在此计划单内, 或不在当前工段',
  336. duration: 2000
  337. })
  338. }
  339. } else {
  340. uni.showToast({
  341. icon: 'none',
  342. title: response.msg,
  343. duration: 2000
  344. })
  345. }
  346. })
  347. }
  348. // lotReporting.value.open(data);
  349. }
  350. function handleContinue() {
  351. // lotReporting.value.open('test')
  352. handleAdd()
  353. }
  354. // 全选按钮操作
  355. function handleAll() {
  356. //清空选中数据
  357. selection.value.length = 0;
  358. if (checkAll.value) {
  359. //变更选中状态
  360. checkAll.value = false;
  361. } else {
  362. checkAll.value = true;
  363. listData.value.findIndex(item => handleSelection(item))
  364. }
  365. }
  366. function handleChangeWorkshop(arg) {
  367. const workshop = workshopList.value.find(v => v.value === arg)
  368. // console.log(allData.value)
  369. // console.log(workshop)
  370. // console.log()
  371. listData.value = allData.value.filter(v => workshop.depts.some(e => e.deptId === v.quickInfo.deptId) && (v.lotCode
  372. .includes(keyword.value) || v.productDescription.includes(keyword.value) || v.carrierName.includes(
  373. keyword.value)))
  374. selection.value = []
  375. }
  376. function isSelected(item) {
  377. return selection.value.includes(item);
  378. }
  379. //
  380. function handleSelection(item) {
  381. const buttonIndex = selection.value.findIndex(selectedItem => selectedItem === item);
  382. if (buttonIndex > -1) {
  383. selection.value.splice(buttonIndex, 1); // 取消选中
  384. } else {
  385. selection.value.push(item); // 选中
  386. }
  387. if (selection.value.length == listData.value.length) {
  388. checkAll.value = true;
  389. } else {
  390. checkAll.value = false;
  391. }
  392. }
  393. function handleChangeCarrier(item) {
  394. uni.$once('refreshQuickReport', () => {
  395. init()
  396. })
  397. store.dayworkInfo = null
  398. uni.navigateTo({
  399. url: "/pages/changeBox/index",
  400. success: function(res) {
  401. // 通过eventChannel向被打开页面传送数据
  402. res.eventChannel.emit('acceptDataFromOpenerPage', {
  403. data: item
  404. })
  405. }
  406. })
  407. }
  408. function handleEnd() {
  409. if (selection.value.length === 0) {
  410. uni.showToast({
  411. icon: 'none',
  412. title: '请选择完成报工批次'
  413. })
  414. return
  415. }
  416. const currentTime = Date.now();
  417. // 检查是否已经过去了 2 秒
  418. if (currentTime - lastRequestTimestamp.value < 2000) {
  419. // 如果在 2 秒 内已经有请求发出,那么不执行
  420. uni.showToast({
  421. icon: 'none',
  422. title: `请勿重复点击`,
  423. duration: 2000
  424. })
  425. return;
  426. }
  427. lastRequestTimestamp.value = currentTime;
  428. // 更新请求时间戳
  429. isTakeStock().then(response => {
  430. if (response.data) {
  431. uni.showToast({
  432. icon: 'none',
  433. title: '正在盘点,不能结束报工',
  434. duration: 2000
  435. })
  436. } else {
  437. loading.value = true
  438. uni.showLoading({
  439. title: '加载中'
  440. });
  441. lastRequestTimestamp.value = currentTime;
  442. selection.value.forEach(item => {
  443. item.tenantId = !store.tenantId ? store.userInfo.tenantId : store.tenantId
  444. })
  445. finishQuick(selection.value).then(res => {
  446. // console.log(res)
  447. if (res.code === 200) {
  448. init()
  449. } else {
  450. // loading.value = false
  451. // uni.hideLoading()
  452. uni.showToast({
  453. icon: 'none',
  454. title: res.msg,
  455. duration: 2000
  456. });
  457. setTimeout(() => {
  458. init()
  459. }, 1500);
  460. }
  461. })
  462. }
  463. })
  464. }
  465. // init();
  466. </script>
  467. <style lang="scss">
  468. $nav-height: 60rpx;
  469. .bottom-btn-container {
  470. position: fixed;
  471. top: 80%;
  472. right: 20rpx;
  473. left: 20rpx;
  474. .start-batch-btn {
  475. margin-bottom: 24rpx;
  476. border-radius: 8rpx;
  477. background-color: #00e2a6;
  478. width: 80%;
  479. }
  480. }
  481. .active {
  482. flex: 1;
  483. height: 40rpx;
  484. background-color: #5e6eff;
  485. border: 1px solid #5e6eff;
  486. color: #000000;
  487. }
  488. .select {
  489. flex: 1;
  490. height: 40rpx;
  491. // font-size: 20rpx;
  492. background-color: #5e6eff;
  493. border: 1px solid #5e6eff;
  494. color: #ffffff;
  495. }
  496. .btn {
  497. position: fixed;
  498. right: 0;
  499. bottom: 0;
  500. left: 0;
  501. height: 100rpx;
  502. padding: 16rpx 24rpx;
  503. align-items: center;
  504. background-color: #FFFFFF;
  505. justify-content: space-between;
  506. .bottom-btn {
  507. flex: 1;
  508. font-size: 28rpx;
  509. color: #FFFFFF;
  510. &.left-btn {
  511. // background-color: #a4adb3;
  512. }
  513. &.right-btn {
  514. background-color: #1684fc;
  515. margin-left: 24rpx;
  516. }
  517. }
  518. }
  519. .box-bg {
  520. width: 100%;
  521. background-color: #F5F5F5;
  522. padding: 5rpx 0;
  523. justify-content: space-around;
  524. align-items: center;
  525. .input-view {
  526. width: 100%;
  527. flex: 4;
  528. background-color: #f8f8f8;
  529. height: $nav-height;
  530. border: 1rpx solid #999;
  531. border-radius: 15rpx;
  532. padding: 0 15rpx;
  533. flex-wrap: nowrap;
  534. margin: 0 10rpx 20rpx;
  535. line-height: $nav-height;
  536. .input-uni-icon {
  537. line-height: $nav-height;
  538. }
  539. .nav-bar-input {
  540. width: 80%;
  541. height: $nav-height;
  542. line-height: $nav-height;
  543. padding: 0 5rpx;
  544. background-color: #f8f8f8;
  545. }
  546. }
  547. .search {
  548. width: 20%;
  549. text-align: center;
  550. color: #808080;
  551. margin-top: -20rpx;
  552. }
  553. }
  554. .list-item {
  555. background-color: #fff;
  556. position: relative;
  557. padding: 16rpx;
  558. padding-bottom: 24rpx;
  559. border-radius: 24rpx;
  560. margin-bottom: 24rpx;
  561. .title-container {
  562. justify-content: space-between;
  563. margin-top: 8rpx;
  564. margin-bottom: 16rpx;
  565. .title {
  566. height: 48rpx;
  567. align-items: center;
  568. .label {
  569. font-size: 32rpx;
  570. font-weight: bold;
  571. &.code {
  572. margin-left: 8rpx;
  573. }
  574. }
  575. }
  576. .tag {
  577. border: 1px solid #1ce5b0;
  578. background-color: #f6fffd;
  579. padding: 8rpx;
  580. border-radius: 8rpx;
  581. .label {
  582. color: #1ce5b0;
  583. font-size: 24rpx;
  584. }
  585. &.not-start {
  586. border: 1px solid #bbbbbb;
  587. background-color: #f5f5f5;
  588. .label {
  589. color: #bbbbbb;
  590. }
  591. }
  592. }
  593. }
  594. .item-info {
  595. margin-bottom: 8rpx;
  596. .label {
  597. font-size: 28rpx;
  598. width: 150rpx;
  599. color: #808080;
  600. &.right {
  601. flex: 1;
  602. color: #000000;
  603. }
  604. }
  605. }
  606. }
  607. .selected {
  608. border: 1rpx solid #c0c4fc;
  609. background-color: #c0c4fc;
  610. /* 选中之后样式 */
  611. }
  612. </style>