dialog-end-work.vue 14 KB

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