dialog-end-work.vue 17 KB

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