index.vue 15 KB

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