dialog-end-work.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671
  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. processInspectionId: 0
  182. }).then(res => {
  183. console.log(res)
  184. if (res.code == 200) {
  185. bindList.value = res.rows;
  186. for (let i = 0; i < bindList.value.length; i++) {
  187. bindList.value[i].flag = false;
  188. }
  189. }
  190. }).catch(err => {
  191. console.log('203 err')
  192. })
  193. }
  194. function switchChange(event) {
  195. if (event.detail.value) {
  196. workInfo.value.status = "3"
  197. } else {
  198. workInfo.value.status = "2"
  199. }
  200. console.log(event.detail.value, !store.isPreProcess)
  201. showCarrierList.value = event.detail.value;
  202. }
  203. function handleInputQualifiedNum() {
  204. workInfo.value.qualifiedNum = workInfo.value.qualifiedNum.replace(/^-+|[^\d]/g, '');
  205. }
  206. function handleInputRejectNum(item) {
  207. item.rejectNum = item.rejectNum.replace(/^0+|^-|[^\d]/g, '');
  208. // 合格数随着投产数
  209. //let sumRejectNum = 0;
  210. // for (let i = 0; i < wasteInfo.value.length; i++) {
  211. // wasteInfo.value[i].rejectNum = wasteInfo.value[i].rejectNum.replace(/^0+|^-|[^\d]/g, '');
  212. // // sumRejectNum += Number(wasteInfo.value[i].rejectNum);
  213. // }
  214. // if (temp.value > 0) {
  215. // debounce(function() {
  216. // workInfo.value.qualifiedNum = temp.value;
  217. // workInfo.value.qualifiedNum -= sumRejectNum;
  218. // }, 500)
  219. // }
  220. }
  221. /*
  222. function handleScanCode() {
  223. // 引入原生插件
  224. const mpaasScanModule = uni.requireNativePlugin("Mpaas-Scan-Module");
  225. if (mpaasScanModule) {
  226. //调用插件的 mpaasScan 方法
  227. mpaasScanModule.mpaasScan({
  228. // 扫码识别类型,参数可多选,qrCode、barCode,
  229. // 如不设置,默认识别所有扫码类型,可能有些许影响识别效率
  230. scanType: ["qrCode", "barCode"],
  231. // 是否隐藏相册,默认false不隐藏
  232. hideAlbum: false,
  233. },
  234. (ret) => {
  235. let vehicleObj = JSON.parse(ret.resp_result);
  236. let hasInFlag = false
  237. for (let i = 0; i < bindList.value.length; i++) {
  238. if (vehicleObj.carrierCode == bindList.value[i].carrierCode) {
  239. hasInFlag = true
  240. if (!bindList.value[i].flag) {
  241. endFlag.value += 1;
  242. }
  243. bindList.value[i].flag = true;
  244. }
  245. }
  246. if(!hasInFlag) {
  247. uni.showToast({
  248. icon: 'none',
  249. title: '该批次没有绑定此箱',
  250. duration: 2000
  251. })
  252. }
  253. if (endFlag.value < bindList.value.length && hasInFlag) {
  254. setTimeout(() => {
  255. handleScanCode();
  256. }, 700);
  257. }
  258. }
  259. );
  260. }
  261. }
  262. */
  263. function handleScanCode() {
  264. // 引入原生插件
  265. const mpaasScanModule = uni.requireNativePlugin("Mpaas-Scan-Module");
  266. if (mpaasScanModule) {
  267. //调用插件的 mpaasScan 方法
  268. mpaasScanModule.mpaasScan({
  269. // 扫码识别类型,参数可多选,qrCode、barCode,
  270. // 如不设置,默认识别所有扫码类型,可能有些许影响识别效率
  271. scanType: ["qrCode", "barCode"],
  272. // 是否隐藏相册,默认false不隐藏
  273. hideAlbum: false,
  274. },
  275. (ret) => {
  276. let vehicleObj = {
  277. carrierCode: ret.resp_result
  278. };
  279. let hasInFlag = false
  280. for (let i = 0; i < bindList.value.length; i++) {
  281. if (vehicleObj.carrierCode == bindList.value[i].carrierCode) {
  282. hasInFlag = true
  283. if (!bindList.value[i].flag) {
  284. endFlag.value += 1;
  285. }
  286. bindList.value[i].flag = true;
  287. }
  288. }
  289. if (!hasInFlag) {
  290. uni.showToast({
  291. icon: 'none',
  292. title: '该批次没有绑定此箱',
  293. duration: 2000
  294. })
  295. }
  296. if (endFlag.value < bindList.value.length && hasInFlag) {
  297. setTimeout(() => {
  298. handleScanCode();
  299. }, 700);
  300. }
  301. }
  302. );
  303. } else {
  304. let vehicleObj = {
  305. carrierCode: bindList.value[0].carrierCode
  306. };
  307. let hasInFlag = false
  308. for (let i = 0; i < bindList.value.length; i++) {
  309. if (vehicleObj.carrierCode == bindList.value[i].carrierCode) {
  310. hasInFlag = true
  311. if (!bindList.value[i].flag) {
  312. endFlag.value += 1;
  313. }
  314. bindList.value[i].flag = true;
  315. }
  316. }
  317. if (!hasInFlag) {
  318. uni.showToast({
  319. icon: 'none',
  320. title: '该批次没有绑定此箱',
  321. duration: 2000
  322. })
  323. }
  324. if (endFlag.value < bindList.value.length && hasInFlag) {
  325. setTimeout(() => {
  326. handleScanCode();
  327. }, 700);
  328. }
  329. }
  330. }
  331. function handlePreFinishReporting() {
  332. //投产数
  333. let number = store.dayworkInfo.prevProcess == null ? store.dayworkInfo.productionQuantity : store.dayworkInfo
  334. .processQualifiedNum;
  335. workInfo.value.prodNum = number
  336. let max = parseInt(number * 1.03);
  337. // max = parseInt(String(max).split("."));
  338. console.log("maxawdjkkaljdalkw", max);
  339. let sunm = parseInt(workInfo.value.qualifiedNum) + lotPreSumQualifiedNum.value; //计算总合格数
  340. let percent = (sunm / number) * 100; //合格率
  341. percent = Math.ceil(percent * 100) / 100; //只入不舍
  342. console.log("合格量", percent)
  343. // let percent = (((parseInt(workInfo.value.qualifiedNum) + lotPreSumQualifiedNum.value) / number) * 100).toFixed(2);
  344. let num = 103;
  345. // 填入数大于剩余量情况
  346. if (parseInt(workInfo.value.qualifiedNum) + lotPreSumQualifiedNum.value - number > 0) {
  347. // 判断当前是否为首序
  348. if (isFirstOrder.value) {
  349. uni.showModal({
  350. title: '提示',
  351. content: `合格数总量超出投入量${percent}%,是否继续保存?`,
  352. success: function(res) {
  353. if (res.confirm) {
  354. handleSave();
  355. } else if (res.cancel) {}
  356. }
  357. })
  358. } else {
  359. if (percent > num) {
  360. uni.showToast({
  361. icon: 'none',
  362. title: '合格数总量为投产量的' + percent + "%,请重新输入!"
  363. })
  364. return;
  365. } else {
  366. handleSave();
  367. }
  368. }
  369. } else {
  370. handleSave();
  371. }
  372. }
  373. function handleFinishReporting() {
  374. console.log(store.isPreProcess)
  375. //投产数
  376. let number = workInfo.value.prodNum;
  377. let percent = (((parseInt(workInfo.value.qualifiedNum) + lotPreSumQualifiedNum.value) / number) * 100).toFixed(
  378. 2);
  379. let num = 103;
  380. if (parseInt(workInfo.value.qualifiedNum) + lotPreSumQualifiedNum.value - number > 0) {
  381. if (isFirstOrder.value) {
  382. if (percent == 103) {
  383. percent = 103.1
  384. }
  385. uni.showModal({
  386. title: '提示',
  387. content: `合格数总量超出投入量${percent}%,是否继续保存?`,
  388. success: function(res) {
  389. if (res.confirm) {
  390. if (showCarrierList.value) {
  391. if (endFlag.value >= bindList.value.length) {
  392. handleSave();
  393. } else {
  394. uni.showToast({
  395. icon: "none",
  396. title: "请先扫码确认载具",
  397. duration: 2000
  398. })
  399. return;
  400. }
  401. } else {
  402. handleSave();
  403. }
  404. } else if (res.cancel) {}
  405. }
  406. })
  407. } else {
  408. if (percent == num) {
  409. percent = 103.01
  410. }
  411. if (percent > num) {
  412. uni.showToast({
  413. icon: 'none',
  414. title: '合格数总量为投产量的' + percent + "%,请重新输入!"
  415. })
  416. return;
  417. } else {
  418. handleSave();
  419. }
  420. }
  421. } else {
  422. if (showCarrierList.value) {
  423. if (endFlag.value >= bindList.value.length) {
  424. handleSave();
  425. } else {
  426. uni.showToast({
  427. icon: "none",
  428. title: "请先扫码确认载具",
  429. duration: 2000
  430. })
  431. return;
  432. }
  433. } else {
  434. handleSave();
  435. }
  436. }
  437. }
  438. function handleSave() {
  439. console.log(workInfo.value.qualifiedNum)
  440. if (workInfo.value.qualifiedNum === null || workInfo.value.qualifiedNum === '') {
  441. uni.showToast({
  442. icon: "none",
  443. title: "请输入合格数",
  444. duration: 2000
  445. })
  446. return;
  447. }
  448. let rejectSum = 0
  449. console.log(rejectSum);
  450. for (let i = 0; i < wasteInfo.value.length; i++) {
  451. if ((!wasteInfo.value[i].rejectNum && wasteInfo.value[i].reason) ||
  452. (wasteInfo.value[i].rejectNum && !wasteInfo.value[i].reason) ||
  453. (!wasteInfo.value[i].rejectNum && !wasteInfo.value[i].reason)) {
  454. uni.showToast({
  455. icon: 'none',
  456. title: "请输入废弃数或废弃原因",
  457. duration: 2000
  458. })
  459. return;
  460. }
  461. rejectSum += Number(wasteInfo.value[i].rejectNum);
  462. }
  463. if (rejectSum > workInfo.value.prodNum) {
  464. uni.showToast({
  465. icon: 'none',
  466. title: '废品数不能大于投产数',
  467. duration: 2000
  468. })
  469. return;
  470. }
  471. if (workInfo.value.status != '3') {
  472. workInfo.value.status = '2';
  473. }
  474. workInfo.value.endTime = timestampToTime(new Date());
  475. workInfo.value.rejectList = wasteInfo.value;
  476. workInfo.value.isPreProcess = store.isPreProcess;
  477. workInfo.value.processStepNumber = store.dayworkInfo.currentProcess.processStepNumber
  478. saveDayWorkItem(workInfo.value).then(res => {
  479. if (res.code === 200) {
  480. uni.showToast({
  481. icon: 'success',
  482. title: '操作成功',
  483. });
  484. emit('resflushItem');
  485. close();
  486. } else {
  487. uni.showToast({
  488. icon: 'none',
  489. title: res.msg
  490. });
  491. }
  492. })
  493. }
  494. function handleAddWasteInfo() {
  495. if (wasteInfo.value.length > 0) {
  496. if (wasteInfo.value.some(item => item.rejectNum == '' || item.reason == '')) {
  497. uni.showToast({
  498. icon: 'none',
  499. title: '请填写废品量或废品原因再点击添加'
  500. })
  501. } else {
  502. wasteInfo.value.push({
  503. rejectNum: '',
  504. reason: ''
  505. })
  506. }
  507. } else {
  508. wasteInfo.value.push({
  509. rejectNum: store.dayworkInfo.processQualifiedNum > 0 ? store.dayworkInfo
  510. .processQualifiedNum - lotPreSumQualifiedNum.value - lotPreSumReject.value - workInfo.value
  511. .qualifiedNum > 0 ? store.dayworkInfo
  512. .processQualifiedNum - lotPreSumQualifiedNum.value - lotPreSumReject.value - workInfo.value
  513. .qualifiedNum : 1 : store.dayworkInfo.isLast == 1 ?
  514. store.dayworkInfo.lastLotQuantity - lotPreSumQualifiedNum.value - lotPreSumReject.value -
  515. workInfo.value.qualifiedNum > 0 ?
  516. store.dayworkInfo.lastLotQuantity - lotPreSumQualifiedNum.value - lotPreSumReject.value -
  517. workInfo.value.qualifiedNum : 1 : store.dayworkInfo.oneLotQuantity - lotPreSumQualifiedNum
  518. .value - lotPreSumReject.value -
  519. workInfo.value.qualifiedNum > 0 ?
  520. store.dayworkInfo.oneLotQuantity - lotPreSumQualifiedNum.value - lotPreSumReject.value -
  521. workInfo.value.qualifiedNum : 1,
  522. reason: ''
  523. })
  524. }
  525. }
  526. function handleDeleteWasteInfo(index) {
  527. wasteInfo.value.splice(index, 1);
  528. }
  529. function handleReasonChange(item) {
  530. if (wasteInfo.value.filter(waste => waste.reason == item.reason).length > 1) {
  531. wasteInfo.value.splice(wasteInfo.value.indexOf(item), 1);
  532. uni.showToast({
  533. icon: 'none',
  534. title: '请勿重复选择废品原因',
  535. duration: 2000
  536. })
  537. }
  538. }
  539. defineExpose({
  540. open
  541. })
  542. </script>
  543. <style lang="scss">
  544. .dialog-body {
  545. .list-container {
  546. width: 100%;
  547. display: flex;
  548. align-items: flex-start;
  549. padding: 0 4rpx;
  550. .list-title {
  551. width: 100%;
  552. margin-top: 16rpx;
  553. height: 64rpx;
  554. line-height: 64rpx;
  555. align-items: center;
  556. .label {
  557. flex: 1;
  558. font-size: 32rpx;
  559. }
  560. .input {
  561. width: 40%;
  562. height: 66rpx;
  563. padding-left: 10rpx;
  564. font-size: 22rpx;
  565. border: 1rpx solid #e1e1e1;
  566. border-radius: 8rpx;
  567. }
  568. .icon-gear {
  569. font-size: 56rpx;
  570. }
  571. }
  572. .switch {
  573. margin-top: -8rpx;
  574. align-items: center;
  575. transform: scale(0.7);
  576. }
  577. .confirmCarrier {
  578. .label {
  579. padding-top: 20rpx;
  580. font-size: 32rpx;
  581. }
  582. .vehicleList {
  583. justify-content: baseline;
  584. align-content: flex-start;
  585. flex-wrap: wrap;
  586. width: 100%;
  587. height: 120rpx;
  588. overflow: auto;
  589. .vehicleNo {
  590. padding: 0 10rpx;
  591. margin: 10rpx 20rpx 0 0;
  592. justify-content: space-between;
  593. align-items: center;
  594. width: auto;
  595. height: 60rpx;
  596. border: 2rpx solid rgba(213, 213, 213, 1);
  597. border-radius: 6rpx;
  598. }
  599. .blueBorder {
  600. background-color: #1684fc;
  601. color: #FFFFFF;
  602. }
  603. }
  604. }
  605. }
  606. .add-btn-container {
  607. margin-top: 32rpx;
  608. .btn {
  609. flex: 1;
  610. background-color: rgba(255, 85, 85, 1);
  611. color: #FFFFFF;
  612. margin-left: 5rpx;
  613. padding: 0;
  614. }
  615. .btnScan {
  616. flex: 1;
  617. color: #FFFFFF;
  618. margin-right: 5rpx;
  619. padding: 0;
  620. }
  621. }
  622. }
  623. </style>