dialog-end-work.vue 13 KB

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