dialog-end-work.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  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" 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="handleTenantChange"></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" 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 class="add-btn-container uni-row">
  38. <button v-if="showCarrierList" type="primary" class="btnScan" @click="handleScanCode">扫码确认载具</button>
  39. <button type="default" class="btn" @click="handleFinishReporting">结束报工</button>
  40. </view>
  41. </dialog-base>
  42. </template>
  43. <script setup>
  44. import {
  45. ref,
  46. getCurrentInstance
  47. } from 'vue'
  48. import {
  49. onLoad
  50. } from '@dcloudio/uni-app'
  51. import {
  52. updateDayWorkItem,
  53. saveDayWorkItem
  54. } from "@/api/business/dayWorkItem.js"
  55. import {
  56. getDayworkCarrierList
  57. } from '@/api/business/dayworkCarrier.js'
  58. import {
  59. store
  60. } from '@/store/index.js'
  61. import {
  62. timestampToTime,
  63. toHHmmss
  64. } from '@/utils/common.js'
  65. import {
  66. getDictInfoByType
  67. } from '@/api/dict/dict.js'
  68. import {
  69. getSpecialDeptProcessList
  70. } from '@/api/business/deptProcess.js'
  71. import {
  72. debounce
  73. } from '@/utils/common.js'
  74. const baseDialog = ref(null)
  75. const workInfo = ref({})
  76. const wasteInfo = ref([])
  77. const reasonList = ref([])
  78. const emit = defineEmits(['reset'])
  79. const showCarrierList = ref(false) // 工序是否完成显示载具列表
  80. const bindList = ref([])
  81. const confirmCarrierList = ref([])
  82. const endFlag = ref(0)
  83. const specialDeptProcessList = ref([])
  84. const temp = ref(0) // 保存workInfo.value.qualifiedNum的值(还原用)
  85. onLoad(() => {
  86. })
  87. function open(data, itemListData) {
  88. resetPage();
  89. workInfo.value = {
  90. ...data
  91. };
  92. getSpecialDeptProcessList().then(res => {
  93. if (res.code == 200) {
  94. for (let i = 0; i < res.data.length; i++) {
  95. specialDeptProcessList.value[i] = res.data[i].processId;
  96. }
  97. }
  98. if (specialDeptProcessList.value.includes(workInfo.value.processId)) {
  99. let sumReject = 0;
  100. for (let i = 0; i < itemListData.length; i++) {
  101. sumReject += itemListData[i].rejectNum;
  102. }
  103. workInfo.value.qualifiedNum = store.dayworkInfo.processQualifiedNum > 0 ? store.dayworkInfo.processQualifiedNum - sumReject : store.dayworkInfo.oneLotQuantity - sumReject;
  104. temp.value = workInfo.value.qualifiedNum;sumReject
  105. console.log(store.dayworkInfo)
  106. } else {
  107. workInfo.value.qualifiedNum = 0;
  108. }
  109. })
  110. wasteInfo.value = []
  111. init();
  112. baseDialog.value.open()
  113. }
  114. function close() {
  115. baseDialog.value.close()
  116. }
  117. function resetPage() {
  118. workInfo.value = {};
  119. wasteInfo.value = [];
  120. reasonList.value = [];
  121. showCarrierList.value = false;
  122. bindList.value = [];
  123. confirmCarrierList.value = [];
  124. endFlag.value = 0;
  125. }
  126. function init() {
  127. getDictInfoByType("waste_causes").then(res => {
  128. for (let i = 0; i < res.data.length; i++) {
  129. reasonList.value[i] = {
  130. value: res.data[i].dictValue,
  131. text: res.data[i].dictLabel
  132. }
  133. }
  134. })
  135. getDayworkCarrierList({
  136. dayworkId: store.dayworkInfo.id,
  137. isChanged: 0
  138. }).then(res => {
  139. console.log(res)
  140. if (res.code == 200) {
  141. bindList.value = res.rows;
  142. for (let i = 0; i < bindList.value.length; i++) {
  143. bindList.value[i].flag = false;
  144. }
  145. }
  146. })
  147. }
  148. function switchChange(event) {
  149. if (event.detail.value) {
  150. workInfo.value.status = "3"
  151. } else {
  152. workInfo.value.status = "2"
  153. }
  154. showCarrierList.value = event.detail.value;
  155. }
  156. function handleInputQualifiedNum() {
  157. workInfo.value.qualifiedNum = workInfo.value.qualifiedNum.replace(/^-+|[^\d]/g, '');
  158. }
  159. function handleInputRejectNum() {
  160. let sumRejectNum = 0;
  161. for (let i = 0; i < wasteInfo.value.length; i++) {
  162. wasteInfo.value[i].rejectNum = wasteInfo.value[i].rejectNum.replace(/^0+|^-|[^\d]/g, '');
  163. sumRejectNum += Number(wasteInfo.value[i].rejectNum);
  164. }
  165. if (temp.value > 0) {
  166. debounce(function() {
  167. workInfo.value.qualifiedNum = temp.value;
  168. workInfo.value.qualifiedNum -= sumRejectNum;
  169. }, 500)
  170. }
  171. }
  172. function handleScanCode() {
  173. uni.scanCode({
  174. scanType: ['qrCode'], // 条形码扫描
  175. onlyFromCamera: true, // 只允许相机扫码
  176. autoZoom: false,
  177. success: function(res) {
  178. let vehicleObj = JSON.parse(res.result);
  179. for (let i = 0; i < bindList.value.length; i++) {
  180. if (vehicleObj.carrierCode == bindList.value[i].carrierCode) {
  181. if (!bindList.value[i].flag) {
  182. endFlag.value += 1;
  183. }
  184. bindList.value[i].flag = true;
  185. }
  186. }
  187. }
  188. });
  189. }
  190. function handleFinishReporting() {
  191. if (showCarrierList.value) {
  192. if (endFlag.value >= bindList.value.length) {
  193. handleSave();
  194. } else {
  195. uni.showToast({
  196. icon: "none",
  197. title: "请先扫码确认载具"
  198. })
  199. return;
  200. }
  201. } else {
  202. handleSave();
  203. }
  204. }
  205. function handleSave() {
  206. if (!workInfo.value.qualifiedNum) {
  207. uni.showToast({
  208. icon: "error",
  209. title: "请输入合格数",
  210. })
  211. return;
  212. }
  213. for (let i = 0; i < wasteInfo.value.length; i++) {
  214. if ((!wasteInfo.value[i].rejectNum && wasteInfo.value[i].reason) ||
  215. (wasteInfo.value[i].rejectNum && !wasteInfo.value[i].reason) ||
  216. (!wasteInfo.value[i].rejectNum && !wasteInfo.value[i].reason)) {
  217. uni.showToast({
  218. icon: "error",
  219. title: "请输入废弃数或废弃原因",
  220. duration: 2000
  221. })
  222. return;
  223. }
  224. }
  225. close();
  226. if (workInfo.value.status != '3') {
  227. workInfo.value.status = '2';
  228. }
  229. workInfo.value.endTime = timestampToTime(new Date());
  230. workInfo.value.rejectList = wasteInfo.value;
  231. console.log(workInfo.value)
  232. saveDayWorkItem(workInfo.value).then(res => {
  233. if (res.code === 200) {
  234. uni.showToast({
  235. icon: 'success',
  236. title: '操作成功',
  237. });
  238. uni.$emit('dayworkItemUpdate');
  239. baseDialog.value.close();
  240. workInfo.value.qualifiedNum = null;
  241. } else {
  242. uni.showToast({
  243. icon: 'none',
  244. title: res.msg
  245. });
  246. }
  247. })
  248. }
  249. function handleAddWasteInfo() {
  250. wasteInfo.value.push({
  251. rejectNum: '',
  252. reason: ''
  253. })
  254. }
  255. function handleDeleteWasteInfo(index) {
  256. wasteInfo.value.splice(index, 1);
  257. handleInputRejectNum();
  258. }
  259. function handleTenantChange() {
  260. }
  261. defineExpose({
  262. open
  263. })
  264. </script>
  265. <style lang="scss">
  266. .dialog-body {
  267. .list-container {
  268. width: 100%;
  269. display: flex;
  270. align-items: flex-start;
  271. padding: 0 4rpx;
  272. .list-title {
  273. width: 100%;
  274. margin-top: 16rpx;
  275. height: 64rpx;
  276. line-height: 64rpx;
  277. align-items: center;
  278. .label {
  279. flex: 1;
  280. font-size: 32rpx;
  281. }
  282. .input {
  283. width: 40%;
  284. height: 66rpx;
  285. padding-left: 10rpx;
  286. font-size: 22rpx;
  287. border: 1rpx solid #e1e1e1;
  288. border-radius: 8rpx;
  289. }
  290. .icon-gear {
  291. font-size: 56rpx;
  292. }
  293. }
  294. .switch {
  295. margin-top: -8rpx;
  296. align-items: center;
  297. transform: scale(0.7);
  298. }
  299. .confirmCarrier {
  300. .label {
  301. padding-top: 20rpx;
  302. font-size: 32rpx;
  303. }
  304. .vehicleList {
  305. justify-content: baseline;
  306. align-content: flex-start;
  307. flex-wrap: wrap;
  308. width: 100%;
  309. height: 120rpx;
  310. overflow: auto;
  311. .vehicleNo {
  312. padding: 0 10rpx;
  313. margin: 10rpx 20rpx 0 0;
  314. justify-content: space-between;
  315. align-items: center;
  316. width: auto;
  317. height: 60rpx;
  318. border: 2rpx solid rgba(213, 213, 213, 1);
  319. border-radius: 6rpx;
  320. }
  321. .blueBorder {
  322. background-color: #1684fc;
  323. color: #FFFFFF;
  324. }
  325. }
  326. }
  327. }
  328. .add-btn-container {
  329. margin-top: 32rpx;
  330. .btn {
  331. flex: 1;
  332. background-color: rgba(255, 85, 85, 1);
  333. color: #FFFFFF;
  334. margin-left: 5rpx;
  335. padding: 0;
  336. }
  337. .btnScan {
  338. flex: 1;
  339. color: #FFFFFF;
  340. margin-right: 5rpx;
  341. padding: 0;
  342. }
  343. }
  344. }
  345. </style>