dialog-end-work.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  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.processQualifiedNum > 0 ?
  127. Math.max(0, store.dayworkInfo.processQualifiedNum - lotPreSumQualifiedNum.value -
  128. lotPreSumReject.value) :
  129. Math.max(0, store.dayworkInfo.productionQuantity - lotPreSumQualifiedNum.value - lotPreSumReject
  130. .value);
  131. // temp.value = workInfo.value.qualifiedNum;
  132. } else {
  133. workInfo.value.qualifiedNum = 0;
  134. }
  135. }).catch(err => {
  136. console.log('146 err')
  137. });
  138. init();
  139. baseDialog.value.open()
  140. }
  141. function close() {
  142. baseDialog.value.close()
  143. }
  144. function getIsFirst(dayworkId) {
  145. getIsFirstOrder(dayworkId).then(res => {
  146. if (res.code == 200) {
  147. isFirstOrder.value = res.data.isFirstOrder;
  148. }
  149. }).catch(err => {
  150. console.log(err)
  151. })
  152. }
  153. function resetPage() {
  154. workInfo.value.qualifiedNum = null;
  155. workInfo.value = {};
  156. wasteInfo.value = [];
  157. reasonList.value = [];
  158. showCarrierList.value = false;
  159. bindList.value = [];
  160. confirmCarrierList.value = [];
  161. endFlag.value = 0;
  162. lotPreSumReject.value = 0;
  163. lotPreSumQualifiedNum.value = 0;
  164. remainingQualifiedNum.value = 0;
  165. }
  166. function init() {
  167. getDictInfoByType("waste_causes").then(res => {
  168. for (let i = 0; i < res.data.length; i++) {
  169. reasonList.value[i] = {
  170. value: res.data[i].dictValue,
  171. text: res.data[i].dictLabel
  172. }
  173. }
  174. }).catch(err => {
  175. console.log('189 err')
  176. })
  177. getDayworkCarrierList({
  178. dayworkId: store.dayworkInfo.id,
  179. isChanged: 0
  180. }).then(res => {
  181. console.log(res)
  182. if (res.code == 200) {
  183. bindList.value = res.rows;
  184. for (let i = 0; i < bindList.value.length; i++) {
  185. bindList.value[i].flag = false;
  186. }
  187. }
  188. }).catch(err => {
  189. console.log('203 err')
  190. })
  191. }
  192. function switchChange(event) {
  193. if (event.detail.value) {
  194. workInfo.value.status = "3"
  195. } else {
  196. workInfo.value.status = "2"
  197. }
  198. showCarrierList.value = event.detail.value;
  199. }
  200. function handleInputQualifiedNum() {
  201. workInfo.value.qualifiedNum = workInfo.value.qualifiedNum.replace(/^-+|[^\d]/g, '');
  202. }
  203. function handleInputRejectNum(item) {
  204. item.rejectNum = item.rejectNum.replace(/^0+|^-|[^\d]/g, '');
  205. // 合格数随着投产数
  206. //let sumRejectNum = 0;
  207. // for (let i = 0; i < wasteInfo.value.length; i++) {
  208. // wasteInfo.value[i].rejectNum = wasteInfo.value[i].rejectNum.replace(/^0+|^-|[^\d]/g, '');
  209. // // sumRejectNum += Number(wasteInfo.value[i].rejectNum);
  210. // }
  211. // if (temp.value > 0) {
  212. // debounce(function() {
  213. // workInfo.value.qualifiedNum = temp.value;
  214. // workInfo.value.qualifiedNum -= sumRejectNum;
  215. // }, 500)
  216. // }
  217. }
  218. function handleScanCode() {
  219. // 引入原生插件
  220. const mpaasScanModule = uni.requireNativePlugin("Mpaas-Scan-Module");
  221. //调用插件的 mpaasScan 方法
  222. mpaasScanModule.mpaasScan({
  223. // 扫码识别类型,参数可多选,qrCode、barCode,
  224. // 如不设置,默认识别所有扫码类型,可能有些许影响识别效率
  225. scanType: ["qrCode", "barCode"],
  226. // 是否隐藏相册,默认false不隐藏
  227. hideAlbum: false,
  228. },
  229. (ret) => {
  230. let vehicleObj = JSON.parse(ret.resp_result);
  231. for (let i = 0; i < bindList.value.length; i++) {
  232. if (vehicleObj.carrierCode == bindList.value[i].carrierCode) {
  233. if (!bindList.value[i].flag) {
  234. endFlag.value += 1;
  235. }
  236. bindList.value[i].flag = true;
  237. }
  238. }
  239. }
  240. );
  241. }
  242. function handlePreFinishReporting() {
  243. console.log("44")
  244. //投产数
  245. let number = store.dayworkInfo.processQualifiedNum == 0 ? store.dayworkInfo.productionQuantity : store.dayworkInfo
  246. .processQualifiedNum;
  247. workInfo.value.prodNum = number
  248. console.log("合格量", (parseInt(workInfo.value.qualifiedNum) + lotPreSumQualifiedNum.value))
  249. let percent = (((parseInt(workInfo.value.qualifiedNum) + lotPreSumQualifiedNum.value) / number) * 100).toFixed(2);
  250. console.log("percent", lotPreSumQualifiedNum.value);
  251. let num = 103;
  252. // 填入数大于剩余量情况
  253. if (parseInt(workInfo.value.qualifiedNum) + lotPreSumQualifiedNum.value - number > 0) {
  254. // 判断当前是否为首序
  255. if (isFirstOrder.value) {
  256. percent = ((parseInt(workInfo.value.qualifiedNum) + lotPreSumQualifiedNum.value - number) / number) * 100;
  257. percent = Math.ceil(percent * 100) / 100;
  258. uni.showModal({
  259. title: '提示',
  260. content: `合格数总量超出投入量${percent}%,是否继续保存?`,
  261. success: function(res) {
  262. if (res.confirm) {
  263. handleSave();
  264. } else if (res.cancel) {}
  265. }
  266. })
  267. } else {
  268. if (percent > num) {
  269. uni.showToast({
  270. icon: 'none',
  271. title: '合格数总量为投产量的' + percent + "%,请重新输入!"
  272. })
  273. return;
  274. } else {
  275. handleSave();
  276. }
  277. }
  278. } else {
  279. handleSave();
  280. }
  281. }
  282. function handleFinishReporting() {
  283. console.log(store.isPreProcess)
  284. //投产数
  285. let number = workInfo.value.prodNum;
  286. let percent = (((parseInt(workInfo.value.qualifiedNum) + lotPreSumQualifiedNum.value) / number) * 100).toFixed(2);
  287. let num = 103;
  288. if (parseInt(workInfo.value.qualifiedNum) + lotPreSumQualifiedNum.value - number > 0) {
  289. if (isFirstOrder.value) {
  290. percent = ((parseInt(workInfo.value.qualifiedNum) + lotPreSumQualifiedNum.value - number) / number) * 100;
  291. percent = Math.ceil(percent * 100) / 100;
  292. uni.showModal({
  293. title: '提示',
  294. content: `合格数总量超出投入量${percent}%,是否继续保存?`,
  295. success: function(res) {
  296. if (res.confirm) {
  297. if (showCarrierList.value) {
  298. if (endFlag.value >= bindList.value.length) {
  299. handleSave();
  300. } else {
  301. uni.showToast({
  302. icon: "none",
  303. title: "请先扫码确认载具",
  304. duration: 2000
  305. })
  306. return;
  307. }
  308. } else {
  309. handleSave();
  310. }
  311. } else if (res.cancel) {}
  312. }
  313. })
  314. } else {
  315. if (percent > num) {
  316. uni.showToast({
  317. icon: 'none',
  318. title: '合格数总量为投产量的' + percent + "%,请重新输入!"
  319. })
  320. return;
  321. } else {
  322. handleSave();
  323. }
  324. }
  325. } else {
  326. if (showCarrierList.value) {
  327. if (endFlag.value >= bindList.value.length) {
  328. handleSave();
  329. } else {
  330. uni.showToast({
  331. icon: "none",
  332. title: "请先扫码确认载具",
  333. duration: 2000
  334. })
  335. return;
  336. }
  337. } else {
  338. handleSave();
  339. }
  340. }
  341. }
  342. function handleSave() {
  343. console.log(workInfo.value.qualifiedNum)
  344. if (workInfo.value.qualifiedNum === null || workInfo.value.qualifiedNum === '') {
  345. uni.showToast({
  346. icon: "none",
  347. title: "请输入合格数",
  348. duration: 2000
  349. })
  350. return;
  351. }
  352. let rejectSum = 0
  353. console.log(rejectSum);
  354. for (let i = 0; i < wasteInfo.value.length; i++) {
  355. if ((!wasteInfo.value[i].rejectNum && wasteInfo.value[i].reason) ||
  356. (wasteInfo.value[i].rejectNum && !wasteInfo.value[i].reason) ||
  357. (!wasteInfo.value[i].rejectNum && !wasteInfo.value[i].reason)) {
  358. uni.showToast({
  359. icon: 'none',
  360. title: "请输入废弃数或废弃原因",
  361. duration: 2000
  362. })
  363. return;
  364. }
  365. rejectSum += Number(wasteInfo.value[i].rejectNum);
  366. }
  367. if (rejectSum > workInfo.value.prodNum) {
  368. uni.showToast({
  369. icon: 'none',
  370. title: '废品数不能大于投产数',
  371. duration: 2000
  372. })
  373. return;
  374. }
  375. if (workInfo.value.status != '3') {
  376. workInfo.value.status = '2';
  377. }
  378. workInfo.value.endTime = timestampToTime(new Date());
  379. workInfo.value.rejectList = wasteInfo.value;
  380. workInfo.value.isPreProcess = store.isPreProcess;
  381. workInfo.value.processStepNumber = store.dayworkInfo.currentProcess.processStepNumber
  382. saveDayWorkItem(workInfo.value).then(res => {
  383. if (res.code === 200) {
  384. uni.showToast({
  385. icon: 'success',
  386. title: '操作成功',
  387. });
  388. emit('resflushItem');
  389. close();
  390. } else {
  391. uni.showToast({
  392. icon: 'none',
  393. title: res.msg
  394. });
  395. }
  396. })
  397. }
  398. function handleAddWasteInfo() {
  399. if (wasteInfo.value.length > 0) {
  400. if (wasteInfo.value.some(item => item.rejectNum == '' || item.reason == '')) {
  401. uni.showToast({
  402. icon: 'none',
  403. title: '请填写废品量或废品原因再点击添加'
  404. })
  405. } else {
  406. wasteInfo.value.push({
  407. rejectNum: '',
  408. reason: ''
  409. })
  410. }
  411. } else {
  412. wasteInfo.value.push({
  413. rejectNum: store.dayworkInfo.processQualifiedNum > 0 ? store.dayworkInfo
  414. .processQualifiedNum - lotPreSumQualifiedNum.value - lotPreSumReject.value - workInfo.value
  415. .qualifiedNum > 0 ? store.dayworkInfo
  416. .processQualifiedNum - lotPreSumQualifiedNum.value - lotPreSumReject.value - workInfo.value
  417. .qualifiedNum : 1 : store.dayworkInfo.isLast == 1 ?
  418. store.dayworkInfo.lastLotQuantity - lotPreSumQualifiedNum.value - lotPreSumReject.value -
  419. workInfo.value.qualifiedNum > 0 ?
  420. store.dayworkInfo.lastLotQuantity - lotPreSumQualifiedNum.value - lotPreSumReject.value -
  421. workInfo.value.qualifiedNum : 1 : store.dayworkInfo.oneLotQuantity - lotPreSumQualifiedNum
  422. .value - lotPreSumReject.value -
  423. workInfo.value.qualifiedNum > 0 ?
  424. store.dayworkInfo.oneLotQuantity - lotPreSumQualifiedNum.value - lotPreSumReject.value -
  425. workInfo.value.qualifiedNum : 1,
  426. reason: ''
  427. })
  428. }
  429. }
  430. function handleDeleteWasteInfo(index) {
  431. wasteInfo.value.splice(index, 1);
  432. }
  433. function handleReasonChange(item) {
  434. if (wasteInfo.value.filter(waste => waste.reason == item.reason).length > 1) {
  435. wasteInfo.value.splice(wasteInfo.value.indexOf(item), 1);
  436. uni.showToast({
  437. icon: 'none',
  438. title: '请勿重复选择废品原因',
  439. duration: 2000
  440. })
  441. }
  442. }
  443. defineExpose({
  444. open
  445. })
  446. </script>
  447. <style lang="scss">
  448. .dialog-body {
  449. .list-container {
  450. width: 100%;
  451. display: flex;
  452. align-items: flex-start;
  453. padding: 0 4rpx;
  454. .list-title {
  455. width: 100%;
  456. margin-top: 16rpx;
  457. height: 64rpx;
  458. line-height: 64rpx;
  459. align-items: center;
  460. .label {
  461. flex: 1;
  462. font-size: 32rpx;
  463. }
  464. .input {
  465. width: 40%;
  466. height: 66rpx;
  467. padding-left: 10rpx;
  468. font-size: 22rpx;
  469. border: 1rpx solid #e1e1e1;
  470. border-radius: 8rpx;
  471. }
  472. .icon-gear {
  473. font-size: 56rpx;
  474. }
  475. }
  476. .switch {
  477. margin-top: -8rpx;
  478. align-items: center;
  479. transform: scale(0.7);
  480. }
  481. .confirmCarrier {
  482. .label {
  483. padding-top: 20rpx;
  484. font-size: 32rpx;
  485. }
  486. .vehicleList {
  487. justify-content: baseline;
  488. align-content: flex-start;
  489. flex-wrap: wrap;
  490. width: 100%;
  491. height: 120rpx;
  492. overflow: auto;
  493. .vehicleNo {
  494. padding: 0 10rpx;
  495. margin: 10rpx 20rpx 0 0;
  496. justify-content: space-between;
  497. align-items: center;
  498. width: auto;
  499. height: 60rpx;
  500. border: 2rpx solid rgba(213, 213, 213, 1);
  501. border-radius: 6rpx;
  502. }
  503. .blueBorder {
  504. background-color: #1684fc;
  505. color: #FFFFFF;
  506. }
  507. }
  508. }
  509. }
  510. .add-btn-container {
  511. margin-top: 32rpx;
  512. .btn {
  513. flex: 1;
  514. background-color: rgba(255, 85, 85, 1);
  515. color: #FFFFFF;
  516. margin-left: 5rpx;
  517. padding: 0;
  518. }
  519. .btnScan {
  520. flex: 1;
  521. color: #FFFFFF;
  522. margin-right: 5rpx;
  523. padding: 0;
  524. }
  525. }
  526. }
  527. </style>