dialog-end-inner-work.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  1. <template>
  2. <view class="mask" v-if="isLoading"></view>
  3. <dialog-base ref="baseDialog" title="结束报工">
  4. <view class="list-container">
  5. <view class="list-title uni-row">
  6. <text class="label">合格量</text>
  7. <input class="input" @input="handleInputQualifiedNum" style="width: 70%;"
  8. v-model="workInfo.qualifiedNum" placeholder="请输入合格量" />
  9. </view>
  10. <view class="list-title uni-row">
  11. <text class="label">废品信息</text>
  12. <view class="uni-row" style="justify-content: flex-end;"><text class="label" style="color: blue;"
  13. @click="handleAddWasteInfo">+添加</text></view>
  14. </view>
  15. <view class="list-title uni-row" v-for="(item, index) in wasteInfo">
  16. <input class="input" @input="handleInputRejectNum(item)" style="width: 20%;" v-model="item.rejectNum"
  17. placeholder="废品量" />
  18. <uni-data-select style="margin-left: 40rpx;width: 70%;" v-model="item.reason" :localdata="reasonList"
  19. @change="handleReasonChange(item)"></uni-data-select>
  20. <uni-icons class="icon-gear" type="close" size="40" color="red"
  21. @click="handleDeleteWasteInfo(index)"></uni-icons>
  22. </view>
  23. <view class="list-title uni-row">
  24. <text class="label">当前序是否完成</text><text>否</text>
  25. <switch class="switch" @change="switchChange" color="rgba(103, 195, 55, 1.0)" />
  26. <text>是</text>
  27. </view>
  28. <view v-if="showCarrierList && !store.isPreProcess" class="confirmCarrier">
  29. <text class="label">确认载具</text>
  30. <view class="vehicleList uni-row">
  31. <view v-for="(item,index) in bindList" :key="index"
  32. :class="{ 'vehicleNo': true, 'uni-row': true, 'blueBorder': item.flag }">
  33. <text>{{item.carrierCode}}</text>
  34. </view>
  35. </view>
  36. </view>
  37. </view>
  38. <view v-if="store.isPreProcess" class="add-btn-container uni-row">
  39. <button type="default" class="btn" @click="handlePreFinishReporting">结束报工</button>
  40. </view>
  41. <view v-if="!store.isPreProcess" class="add-btn-container uni-row">
  42. <button v-if="showCarrierList" type="primary" class="btnScan" @click="handleScanCode">扫码确认载具</button>
  43. <button type="default" class="btn" @click="handleFinishReporting">结束报工</button>
  44. </view>
  45. </dialog-base>
  46. </template>
  47. <script setup>
  48. import {
  49. ref,
  50. getCurrentInstance
  51. } from 'vue'
  52. import {
  53. onLoad
  54. } from '@dcloudio/uni-app'
  55. import {
  56. updateDayWorkItem,
  57. saveInnerDayworkItem
  58. } from "@/api/business/dayWorkItem.js"
  59. import {
  60. getDayworkCarrierList
  61. } from '@/api/business/dayworkCarrier.js'
  62. import {
  63. store
  64. } from '@/store/index.js'
  65. import {
  66. timestampToTime,
  67. toHHmmss
  68. } from '@/utils/common.js'
  69. import {
  70. getDictInfoByType
  71. } from '@/api/dict/dict.js'
  72. import {
  73. getSpecialDeptProcessList
  74. } from '@/api/business/deptProcess.js'
  75. import {
  76. debounce
  77. } from '@/utils/common.js'
  78. import {
  79. getDayWorkItemList,
  80. listItem,
  81. getIsFirstOrder,
  82. } from '@/api/business/dayWorkItem.js'
  83. const baseDialog = ref(null)
  84. const workInfo = ref({})
  85. const wasteInfo = ref([])
  86. const reasonList = ref([])
  87. const emit = defineEmits(['resflushItem'])
  88. const showCarrierList = ref(false) // 工序是否完成显示载具列表
  89. const bindList = ref([])
  90. const confirmCarrierList = ref([])
  91. const isFirstOrder = ref(true); //是否为首序
  92. const isLoading = ref(false);
  93. const endFlag = ref(0)
  94. const specialDeptProcessList = ref([])
  95. const temp = ref(0) // 保存workInfo.value.qualifiedNum的值(还原用)
  96. const lotPreSumReject = ref(0)
  97. const lotPreSumQualifiedNum = ref(0)
  98. const remainingQualifiedNum = ref(0) // 当前的合格量还能最大添加多少(剩余数量)
  99. onLoad(() => {})
  100. function open(data, itemListData) {
  101. console.log(store.isPreProcess)
  102. console.log("777")
  103. resetPage();
  104. workInfo.value = {
  105. ...data,
  106. };
  107. console.log("数据data", workInfo);
  108. //查看是否为首序
  109. getIsFirst(store.dayworkInfo.id);
  110. workInfo.value.qualifiedNum = 0;
  111. Promise.all([getSpecialDeptProcessList(), listItem({
  112. dayworkId: store.dayworkInfo.id,
  113. status: 2
  114. }), ], )
  115. .then(([res, response]) => {
  116. if (res.code == 200 && response.code == 200) {
  117. for (let i = 0; i < res.data.length; i++) {
  118. specialDeptProcessList.value[i] = res.data[i].processId;
  119. }
  120. for (let i = 0; i < response.rows.length; i++) {
  121. if (response.rows[i].processStepNumber == workInfo.value.processStepNumber) {
  122. lotPreSumReject.value += response.rows[i].rejectSum;
  123. lotPreSumQualifiedNum.value += response.rows[i].qualifiedNum;
  124. }
  125. }
  126. }
  127. if (specialDeptProcessList.value.includes(workInfo.value.processId)) {
  128. workInfo.value.qualifiedNum = store.dayworkInfo.prevProcess != null ?
  129. Math.max(0, store.dayworkInfo.processQualifiedNum - lotPreSumQualifiedNum.value -
  130. lotPreSumReject.value) :
  131. Math.max(0, store.dayworkInfo.productionQuantity - lotPreSumQualifiedNum.value -
  132. lotPreSumReject
  133. .value);
  134. // temp.value = workInfo.value.qualifiedNum;
  135. } else {
  136. workInfo.value.qualifiedNum = 0;
  137. }
  138. }).catch(err => {
  139. console.log('146 err')
  140. });
  141. init();
  142. baseDialog.value.open()
  143. }
  144. function close() {
  145. baseDialog.value.close()
  146. }
  147. function getIsFirst(dayworkId) {
  148. getIsFirstOrder(dayworkId).then(res => {
  149. if (res.code == 200) {
  150. isFirstOrder.value = res.data.isFirstOrder;
  151. }
  152. }).catch(err => {
  153. console.log(err)
  154. })
  155. }
  156. function resetPage() {
  157. workInfo.value.qualifiedNum = null;
  158. workInfo.value = {};
  159. wasteInfo.value = [];
  160. reasonList.value = [];
  161. showCarrierList.value = false;
  162. bindList.value = [];
  163. confirmCarrierList.value = [];
  164. endFlag.value = 0;
  165. lotPreSumReject.value = 0;
  166. lotPreSumQualifiedNum.value = 0;
  167. remainingQualifiedNum.value = 0;
  168. }
  169. function init() {
  170. getDictInfoByType("waste_causes").then(res => {
  171. for (let i = 0; i < res.data.length; i++) {
  172. reasonList.value[i] = {
  173. value: res.data[i].dictValue,
  174. text: res.data[i].dictLabel
  175. }
  176. }
  177. }).catch(err => {
  178. console.log('189 err')
  179. })
  180. getDayworkCarrierList({
  181. dayworkId: store.dayworkInfo.id,
  182. isChanged: 0,
  183. processInspectionId: 0
  184. }).then(res => {
  185. console.log(res)
  186. if (res.code == 200) {
  187. bindList.value = res.rows;
  188. for (let i = 0; i < bindList.value.length; i++) {
  189. bindList.value[i].flag = false;
  190. }
  191. }
  192. }).catch(err => {
  193. console.log('203 err')
  194. })
  195. }
  196. function switchChange(event) {
  197. if (event.detail.value) {
  198. workInfo.value.status = "3"
  199. } else {
  200. workInfo.value.status = "2"
  201. }
  202. console.log(event.detail.value, !store.isPreProcess)
  203. showCarrierList.value = event.detail.value;
  204. }
  205. function handleInputQualifiedNum() {
  206. workInfo.value.qualifiedNum = workInfo.value.qualifiedNum.replace(/^-+|[^\d]/g, '');
  207. }
  208. function handleInputRejectNum(item) {
  209. item.rejectNum = item.rejectNum.replace(/^0+|^-|[^\d]/g, '');
  210. // 合格数随着投产数
  211. //let sumRejectNum = 0;
  212. // for (let i = 0; i < wasteInfo.value.length; i++) {
  213. // wasteInfo.value[i].rejectNum = wasteInfo.value[i].rejectNum.replace(/^0+|^-|[^\d]/g, '');
  214. // // sumRejectNum += Number(wasteInfo.value[i].rejectNum);
  215. // }
  216. // if (temp.value > 0) {
  217. // debounce(function() {
  218. // workInfo.value.qualifiedNum = temp.value;
  219. // workInfo.value.qualifiedNum -= sumRejectNum;
  220. // }, 500)
  221. // }
  222. }
  223. /*
  224. function handleScanCode() {
  225. // 引入原生插件
  226. const mpaasScanModule = uni.requireNativePlugin("Mpaas-Scan-Module");
  227. if (mpaasScanModule) {
  228. //调用插件的 mpaasScan 方法
  229. mpaasScanModule.mpaasScan({
  230. // 扫码识别类型,参数可多选,qrCode、barCode,
  231. // 如不设置,默认识别所有扫码类型,可能有些许影响识别效率
  232. scanType: ["qrCode", "barCode"],
  233. // 是否隐藏相册,默认false不隐藏
  234. hideAlbum: false,
  235. },
  236. (ret) => {
  237. let vehicleObj = JSON.parse(ret.resp_result);
  238. let hasInFlag = false
  239. for (let i = 0; i < bindList.value.length; i++) {
  240. if (vehicleObj.carrierCode == bindList.value[i].carrierCode) {
  241. hasInFlag = true
  242. if (!bindList.value[i].flag) {
  243. endFlag.value += 1;
  244. }
  245. bindList.value[i].flag = true;
  246. }
  247. }
  248. if(!hasInFlag) {
  249. uni.showToast({
  250. icon: 'none',
  251. title: '该批次没有绑定此箱',
  252. duration: 2000
  253. })
  254. }
  255. if (endFlag.value < bindList.value.length && hasInFlag) {
  256. setTimeout(() => {
  257. handleScanCode();
  258. }, 700);
  259. }
  260. }
  261. );
  262. }
  263. }
  264. */
  265. function handleScanCode() {
  266. // 引入原生插件
  267. const mpaasScanModule = uni.requireNativePlugin("Mpaas-Scan-Module");
  268. if (mpaasScanModule) {
  269. //调用插件的 mpaasScan 方法
  270. mpaasScanModule.mpaasScan({
  271. // 扫码识别类型,参数可多选,qrCode、barCode,
  272. // 如不设置,默认识别所有扫码类型,可能有些许影响识别效率
  273. scanType: ["qrCode", "barCode"],
  274. // 是否隐藏相册,默认false不隐藏
  275. hideAlbum: false,
  276. },
  277. (ret) => {
  278. let vehicleObj = {
  279. carrierCode: ret.resp_result
  280. };
  281. let hasInFlag = false
  282. for (let i = 0; i < bindList.value.length; i++) {
  283. if (vehicleObj.carrierCode == bindList.value[i].carrierCode) {
  284. hasInFlag = true
  285. if (!bindList.value[i].flag) {
  286. endFlag.value += 1;
  287. }
  288. bindList.value[i].flag = true;
  289. }
  290. }
  291. if (!hasInFlag) {
  292. uni.showToast({
  293. icon: 'none',
  294. title: '该批次没有绑定此箱',
  295. duration: 2000
  296. })
  297. }
  298. if (endFlag.value < bindList.value.length && hasInFlag) {
  299. setTimeout(() => {
  300. handleScanCode();
  301. }, 700);
  302. }
  303. }
  304. );
  305. } else {
  306. let vehicleObj = {
  307. carrierCode: bindList.value[0].carrierCode
  308. };
  309. let hasInFlag = false
  310. for (let i = 0; i < bindList.value.length; i++) {
  311. if (vehicleObj.carrierCode == bindList.value[i].carrierCode) {
  312. hasInFlag = true
  313. if (!bindList.value[i].flag) {
  314. endFlag.value += 1;
  315. }
  316. bindList.value[i].flag = true;
  317. }
  318. }
  319. if (!hasInFlag) {
  320. uni.showToast({
  321. icon: 'none',
  322. title: '该批次没有绑定此箱',
  323. duration: 2000
  324. })
  325. }
  326. if (endFlag.value < bindList.value.length && hasInFlag) {
  327. setTimeout(() => {
  328. handleScanCode();
  329. }, 700);
  330. }
  331. }
  332. }
  333. function handlePreFinishReporting() {
  334. console.log("999")
  335. //投产数
  336. let number = store.dayworkInfo.prevProcess == null ? store.dayworkInfo.productionQuantity : store.dayworkInfo
  337. .processQualifiedNum;
  338. workInfo.value.prodNum = number
  339. console.log(parseInt(workInfo.value.qualifiedNum))
  340. console.log(lotPreSumQualifiedNum.value)
  341. console.log(number)
  342. // 填入数大于剩余量情况
  343. if (parseInt(workInfo.value.qualifiedNum) + lotPreSumQualifiedNum.value - number > 0) {
  344. console.log("555")
  345. uni.showToast({
  346. icon: 'none',
  347. title: '当前序合格总数不能超过投产数'
  348. })
  349. } else {
  350. //判断当前序合格总数为0 ,不允许保存
  351. if (workInfo.value.status == "3" && parseInt(workInfo.value.qualifiedNum) + lotPreSumQualifiedNum.value == 0) {
  352. uni.showToast({
  353. icon: 'none',
  354. title: '当前序合格总数不能为0',
  355. duration: 2000
  356. })
  357. } else {
  358. handleSave();
  359. }
  360. }
  361. }
  362. function handleFinishReporting() {
  363. console.log(store.isPreProcess)
  364. //投产数
  365. let number = workInfo.value.prodNum;
  366. //判断当前序合格总数为0 ,不允许保存
  367. if (workInfo.value.status == "3" && parseInt(workInfo.value.qualifiedNum) + lotPreSumQualifiedNum.value == 0) {
  368. uni.showToast({
  369. icon: 'none',
  370. title: '当前序合格总数不能为0'
  371. })
  372. return;
  373. }
  374. console.log(parseInt(workInfo.value.qualifiedNum))
  375. console.log(lotPreSumQualifiedNum.value)
  376. console.log(number)
  377. if (parseInt(workInfo.value.qualifiedNum) + lotPreSumQualifiedNum.value > number) {
  378. uni.showToast({
  379. icon: 'none',
  380. title: '当前序合格总数不能超过投产数'
  381. })
  382. return;
  383. }
  384. if (showCarrierList.value) {
  385. if (endFlag.value >= bindList.value.length) {
  386. handleSave();
  387. } else {
  388. uni.showToast({
  389. icon: "none",
  390. title: "请先扫码确认载具",
  391. duration: 2000
  392. })
  393. return;
  394. }
  395. } else {
  396. handleSave();
  397. }
  398. }
  399. function handleSave() {
  400. console.log(workInfo.value.qualifiedNum)
  401. if (workInfo.value.qualifiedNum === null || workInfo.value.qualifiedNum === '') {
  402. uni.showToast({
  403. icon: "none",
  404. title: "请输入合格数",
  405. duration: 2000
  406. })
  407. return;
  408. }
  409. let rejectSum = 0
  410. console.log(rejectSum);
  411. for (let i = 0; i < wasteInfo.value.length; i++) {
  412. if ((!wasteInfo.value[i].rejectNum && wasteInfo.value[i].reason) ||
  413. (wasteInfo.value[i].rejectNum && !wasteInfo.value[i].reason) ||
  414. (!wasteInfo.value[i].rejectNum && !wasteInfo.value[i].reason)) {
  415. uni.showToast({
  416. icon: 'none',
  417. title: "请输入废弃数或废弃原因",
  418. duration: 2000
  419. })
  420. return;
  421. }
  422. rejectSum += Number(wasteInfo.value[i].rejectNum);
  423. }
  424. if (rejectSum > workInfo.value.prodNum) {
  425. uni.showToast({
  426. icon: 'none',
  427. title: '废品数不能大于投产数',
  428. duration: 2000
  429. })
  430. return;
  431. }
  432. if (workInfo.value.status != '3') {
  433. workInfo.value.status = '2';
  434. }
  435. isLoading.value = true; // 显示遮罩层
  436. workInfo.value.endTime = timestampToTime(new Date());
  437. uni.showLoading({
  438. title: '加载中'
  439. });
  440. workInfo.value.rejectList = wasteInfo.value;
  441. workInfo.value.isPreProcess = store.isPreProcess;
  442. workInfo.value.processStepNumber = store.dayworkInfo.currentProcess.processStepNumber
  443. console.log(workInfo.value)
  444. saveInnerDayworkItem(workInfo.value).then(res => {
  445. isLoading.value = false; // 隐藏遮罩层
  446. uni.hideLoading();
  447. if (res.code === 200) {
  448. uni.showToast({
  449. icon: 'success',
  450. title: '操作成功',
  451. });
  452. emit('resflushItem');
  453. close();
  454. } else {
  455. uni.showToast({
  456. icon: 'none',
  457. title: res.msg
  458. });
  459. }
  460. })
  461. }
  462. function handleAddWasteInfo() {
  463. if (wasteInfo.value.length > 0) {
  464. if (wasteInfo.value.some(item => item.rejectNum == '' || item.reason == '')) {
  465. uni.showToast({
  466. icon: 'none',
  467. title: '请填写废品量或废品原因再点击添加'
  468. })
  469. } else {
  470. wasteInfo.value.push({
  471. rejectNum: '',
  472. reason: ''
  473. })
  474. }
  475. } else {
  476. wasteInfo.value.push({
  477. rejectNum: store.dayworkInfo.processQualifiedNum > 0 ? store.dayworkInfo
  478. .processQualifiedNum - lotPreSumQualifiedNum.value - lotPreSumReject.value - workInfo.value
  479. .qualifiedNum > 0 ? store.dayworkInfo
  480. .processQualifiedNum - lotPreSumQualifiedNum.value - lotPreSumReject.value - workInfo.value
  481. .qualifiedNum : 1 : store.dayworkInfo.isLast == 1 ?
  482. store.dayworkInfo.lastLotQuantity - lotPreSumQualifiedNum.value - lotPreSumReject.value -
  483. workInfo.value.qualifiedNum > 0 ?
  484. store.dayworkInfo.lastLotQuantity - lotPreSumQualifiedNum.value - lotPreSumReject.value -
  485. workInfo.value.qualifiedNum : 1 : store.dayworkInfo.oneLotQuantity - lotPreSumQualifiedNum
  486. .value - lotPreSumReject.value -
  487. workInfo.value.qualifiedNum > 0 ?
  488. store.dayworkInfo.oneLotQuantity - lotPreSumQualifiedNum.value - lotPreSumReject.value -
  489. workInfo.value.qualifiedNum : 1,
  490. reason: ''
  491. })
  492. }
  493. }
  494. function handleDeleteWasteInfo(index) {
  495. wasteInfo.value.splice(index, 1);
  496. }
  497. function handleReasonChange(item) {
  498. if (wasteInfo.value.filter(waste => waste.reason == item.reason).length > 1) {
  499. wasteInfo.value.splice(wasteInfo.value.indexOf(item), 1);
  500. uni.showToast({
  501. icon: 'none',
  502. title: '请勿重复选择废品原因',
  503. duration: 2000
  504. })
  505. }
  506. }
  507. defineExpose({
  508. open
  509. })
  510. </script>
  511. <style lang="scss">
  512. .dialog-body {
  513. .list-container {
  514. width: 100%;
  515. display: flex;
  516. align-items: flex-start;
  517. padding: 0 4rpx;
  518. .list-title {
  519. width: 100%;
  520. margin-top: 16rpx;
  521. height: 64rpx;
  522. line-height: 64rpx;
  523. align-items: center;
  524. .label {
  525. flex: 1;
  526. font-size: 32rpx;
  527. }
  528. .input {
  529. width: 40%;
  530. height: 66rpx;
  531. padding-left: 10rpx;
  532. font-size: 22rpx;
  533. border: 1rpx solid #e1e1e1;
  534. border-radius: 8rpx;
  535. }
  536. .icon-gear {
  537. font-size: 56rpx;
  538. }
  539. }
  540. .switch {
  541. margin-top: -8rpx;
  542. align-items: center;
  543. transform: scale(0.7);
  544. }
  545. .confirmCarrier {
  546. .label {
  547. padding-top: 20rpx;
  548. font-size: 32rpx;
  549. }
  550. .vehicleList {
  551. justify-content: baseline;
  552. align-content: flex-start;
  553. flex-wrap: wrap;
  554. width: 100%;
  555. height: 120rpx;
  556. overflow: auto;
  557. .vehicleNo {
  558. padding: 0 10rpx;
  559. margin: 10rpx 20rpx 0 0;
  560. justify-content: space-between;
  561. align-items: center;
  562. width: auto;
  563. height: 60rpx;
  564. border: 2rpx solid rgba(213, 213, 213, 1);
  565. border-radius: 6rpx;
  566. }
  567. .blueBorder {
  568. background-color: #1684fc;
  569. color: #FFFFFF;
  570. }
  571. }
  572. }
  573. }
  574. .add-btn-container {
  575. margin-top: 32rpx;
  576. .btn {
  577. flex: 1;
  578. background-color: rgba(255, 85, 85, 1);
  579. color: #FFFFFF;
  580. margin-left: 5rpx;
  581. padding: 0;
  582. }
  583. .btnScan {
  584. flex: 1;
  585. color: #FFFFFF;
  586. margin-right: 5rpx;
  587. padding: 0;
  588. }
  589. }
  590. }
  591. .mask {
  592. position: fixed;
  593. top: 0;
  594. left: 0;
  595. right: 0;
  596. bottom: 0;
  597. background-color: rgba(0, 0, 0, 0.5);
  598. z-index: 2000;
  599. display: flex;
  600. justify-content: center;
  601. align-items: center;
  602. }
  603. .mask .loading-text {
  604. color: #fff;
  605. font-size: 36rpx;
  606. }
  607. </style>