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