dialog-end-work.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  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 && !store.isProPreProcess" 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.isProPreProcess" class="add-btn-container uni-row">
  38. <button type="default" class="btn" @click="handlePreFinishReporting">结束报工</button>
  39. </view>
  40. <view v-if="!store.isProPreProcess" 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. const baseDialog = ref(null)
  78. const workInfo = ref({})
  79. const wasteInfo = ref([])
  80. const reasonList = ref([])
  81. const emit = defineEmits(['reset'])
  82. const showCarrierList = ref(false) // 工序是否完成显示载具列表
  83. const bindList = ref([])
  84. const confirmCarrierList = ref([])
  85. const endFlag = ref(0)
  86. const specialDeptProcessList = ref([])
  87. const temp = ref(0) // 保存workInfo.value.qualifiedNum的值(还原用)
  88. onLoad(() => {
  89. })
  90. function open(data, itemListData) {
  91. console.log(store.isProPreProcess)
  92. resetPage();
  93. workInfo.value = {
  94. ...data,
  95. qualifiedNum: 0
  96. };
  97. getSpecialDeptProcessList().then(res => {
  98. if (res.code == 200) {
  99. for (let i = 0; i < res.data.length; i++) {
  100. specialDeptProcessList.value[i] = res.data[i].processId;
  101. }
  102. }
  103. if (specialDeptProcessList.value.includes(workInfo.value.processId)) {
  104. let sumReject = 0;
  105. for (let i = 0; i < itemListData.length; i++) {
  106. sumReject += itemListData[i].rejectNum;
  107. }
  108. workInfo.value.qualifiedNum = store.dayworkInfo.processQualifiedNum > 0 ? store.dayworkInfo.processQualifiedNum - sumReject : store.dayworkInfo.oneLotQuantity - sumReject;
  109. temp.value = workInfo.value.qualifiedNum;sumReject
  110. console.log(store.dayworkInfo)
  111. } else {
  112. workInfo.value.qualifiedNum = 0;
  113. }
  114. })
  115. wasteInfo.value = []
  116. init();
  117. baseDialog.value.open()
  118. }
  119. function close() {
  120. baseDialog.value.close()
  121. }
  122. function resetPage() {
  123. workInfo.value = {};
  124. wasteInfo.value = [];
  125. reasonList.value = [];
  126. showCarrierList.value = false;
  127. bindList.value = [];
  128. confirmCarrierList.value = [];
  129. endFlag.value = 0;
  130. }
  131. function init() {
  132. getDictInfoByType("waste_causes").then(res => {
  133. for (let i = 0; i < res.data.length; i++) {
  134. reasonList.value[i] = {
  135. value: res.data[i].dictValue,
  136. text: res.data[i].dictLabel
  137. }
  138. }
  139. })
  140. getDayworkCarrierList({
  141. dayworkId: store.dayworkInfo.id,
  142. isChanged: 0
  143. }).then(res => {
  144. console.log(res)
  145. if (res.code == 200) {
  146. bindList.value = res.rows;
  147. for (let i = 0; i < bindList.value.length; i++) {
  148. bindList.value[i].flag = false;
  149. }
  150. }
  151. })
  152. }
  153. function switchChange(event) {
  154. if (event.detail.value) {
  155. workInfo.value.status = "3"
  156. } else {
  157. workInfo.value.status = "2"
  158. }
  159. showCarrierList.value = event.detail.value;
  160. }
  161. function handleInputQualifiedNum() {
  162. workInfo.value.qualifiedNum = workInfo.value.qualifiedNum.replace(/^-+|[^\d]/g, '');
  163. }
  164. function handleInputRejectNum() {
  165. let sumRejectNum = 0;
  166. for (let i = 0; i < wasteInfo.value.length; i++) {
  167. wasteInfo.value[i].rejectNum = wasteInfo.value[i].rejectNum.replace(/^0+|^-|[^\d]/g, '');
  168. sumRejectNum += Number(wasteInfo.value[i].rejectNum);
  169. }
  170. if (temp.value > 0) {
  171. debounce(function() {
  172. workInfo.value.qualifiedNum = temp.value;
  173. workInfo.value.qualifiedNum -= sumRejectNum;
  174. }, 500)
  175. }
  176. }
  177. function handleScanCode() {
  178. // 引入原生插件
  179. const mpaasScanModule = uni.requireNativePlugin("Mpaas-Scan-Module");
  180. // 调用插件的 mpaasScan 方法
  181. mpaasScanModule.mpaasScan({
  182. // 扫码识别类型,参数可多选,qrCode、barCode,
  183. // 如不设置,默认识别所有扫码类型,可能有些许影响识别效率
  184. scanType: ["qrCode", "barCode"],
  185. // 是否隐藏相册,默认false不隐藏
  186. hideAlbum: false,
  187. },
  188. (ret) => {
  189. let vehicleObj = JSON.parse(ret.resp_result);
  190. for (let i = 0; i < bindList.value.length; i++) {
  191. if (vehicleObj.carrierCode == bindList.value[i].carrierCode) {
  192. if (!bindList.value[i].flag) {
  193. endFlag.value += 1;
  194. }
  195. bindList.value[i].flag = true;
  196. }
  197. }
  198. }
  199. );
  200. }
  201. function handlePreFinishReporting(){
  202. handleSave();
  203. }
  204. function handleFinishReporting() {
  205. if (showCarrierList.value) {
  206. if (endFlag.value >= bindList.value.length) {
  207. handleSave();
  208. } else {
  209. uni.showToast({
  210. icon: "none",
  211. title: "请先扫码确认载具"
  212. })
  213. return;
  214. }
  215. } else {
  216. handleSave();
  217. }
  218. }
  219. function handleSave() {
  220. if (!workInfo.value.qualifiedNum) {
  221. uni.showToast({
  222. icon: "error",
  223. title: "请输入合格数",
  224. })
  225. return;
  226. }
  227. for (let i = 0; i < wasteInfo.value.length; i++) {
  228. if ((!wasteInfo.value[i].rejectNum && wasteInfo.value[i].reason) ||
  229. (wasteInfo.value[i].rejectNum && !wasteInfo.value[i].reason) ||
  230. (!wasteInfo.value[i].rejectNum && !wasteInfo.value[i].reason)) {
  231. uni.showToast({
  232. icon: "error",
  233. title: "请输入废弃数或废弃原因",
  234. duration: 2000
  235. })
  236. return;
  237. }
  238. }
  239. close();
  240. if (workInfo.value.status != '3') {
  241. workInfo.value.status = '2';
  242. }
  243. workInfo.value.endTime = timestampToTime(new Date());
  244. workInfo.value.rejectList = wasteInfo.value;
  245. console.log(workInfo.value)
  246. saveDayWorkItem(workInfo.value).then(res => {
  247. if (res.code === 200) {
  248. uni.showToast({
  249. icon: 'success',
  250. title: '操作成功',
  251. });
  252. uni.$emit('dayworkItemUpdate');
  253. baseDialog.value.close();
  254. workInfo.value.qualifiedNum = null;
  255. } else {
  256. uni.showToast({
  257. icon: 'none',
  258. title: res.msg
  259. });
  260. }
  261. })
  262. }
  263. function handleAddWasteInfo() {
  264. if(wasteInfo.value.some(item => item.rejectNum == '' || item.reason == '')){
  265. uni.showToast({
  266. icon: 'none',
  267. title: '请填写废品量或废品原因再点击添加'
  268. })
  269. }else{
  270. wasteInfo.value.push({
  271. rejectNum: '',
  272. reason: ''
  273. })
  274. }
  275. }
  276. function handleDeleteWasteInfo(index) {
  277. wasteInfo.value.splice(index, 1);
  278. handleInputRejectNum();
  279. }
  280. function handleTenantChange() {
  281. }
  282. defineExpose({
  283. open
  284. })
  285. </script>
  286. <style lang="scss">
  287. .dialog-body {
  288. .list-container {
  289. width: 100%;
  290. display: flex;
  291. align-items: flex-start;
  292. padding: 0 4rpx;
  293. .list-title {
  294. width: 100%;
  295. margin-top: 16rpx;
  296. height: 64rpx;
  297. line-height: 64rpx;
  298. align-items: center;
  299. .label {
  300. flex: 1;
  301. font-size: 32rpx;
  302. }
  303. .input {
  304. width: 40%;
  305. height: 66rpx;
  306. padding-left: 10rpx;
  307. font-size: 22rpx;
  308. border: 1rpx solid #e1e1e1;
  309. border-radius: 8rpx;
  310. }
  311. .icon-gear {
  312. font-size: 56rpx;
  313. }
  314. }
  315. .switch {
  316. margin-top: -8rpx;
  317. align-items: center;
  318. transform: scale(0.7);
  319. }
  320. .confirmCarrier {
  321. .label {
  322. padding-top: 20rpx;
  323. font-size: 32rpx;
  324. }
  325. .vehicleList {
  326. justify-content: baseline;
  327. align-content: flex-start;
  328. flex-wrap: wrap;
  329. width: 100%;
  330. height: 120rpx;
  331. overflow: auto;
  332. .vehicleNo {
  333. padding: 0 10rpx;
  334. margin: 10rpx 20rpx 0 0;
  335. justify-content: space-between;
  336. align-items: center;
  337. width: auto;
  338. height: 60rpx;
  339. border: 2rpx solid rgba(213, 213, 213, 1);
  340. border-radius: 6rpx;
  341. }
  342. .blueBorder {
  343. background-color: #1684fc;
  344. color: #FFFFFF;
  345. }
  346. }
  347. }
  348. }
  349. .add-btn-container {
  350. margin-top: 32rpx;
  351. .btn {
  352. flex: 1;
  353. background-color: rgba(255, 85, 85, 1);
  354. color: #FFFFFF;
  355. margin-left: 5rpx;
  356. padding: 0;
  357. }
  358. .btnScan {
  359. flex: 1;
  360. color: #FFFFFF;
  361. margin-right: 5rpx;
  362. padding: 0;
  363. }
  364. }
  365. }
  366. </style>