dialog-end-work.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  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. };
  96. workInfo.value.qualifiedNum = 0;
  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;
  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. wasteInfo.value[i].rejectNum = wasteInfo.value[i].rejectNum.replace(/^0+|^-|[^\d]/g, '');
  166. // 合格数随着投产数
  167. //let sumRejectNum = 0;
  168. // for (let i = 0; i < wasteInfo.value.length; i++) {
  169. // wasteInfo.value[i].rejectNum = wasteInfo.value[i].rejectNum.replace(/^0+|^-|[^\d]/g, '');
  170. // // sumRejectNum += Number(wasteInfo.value[i].rejectNum);
  171. // }
  172. // if (temp.value > 0) {
  173. // debounce(function() {
  174. // workInfo.value.qualifiedNum = temp.value;
  175. // workInfo.value.qualifiedNum -= sumRejectNum;
  176. // }, 500)
  177. // }
  178. }
  179. function handleScanCode() {
  180. // 引入原生插件
  181. const mpaasScanModule = uni.requireNativePlugin("Mpaas-Scan-Module");
  182. // 调用插件的 mpaasScan 方法
  183. mpaasScanModule.mpaasScan({
  184. // 扫码识别类型,参数可多选,qrCode、barCode,
  185. // 如不设置,默认识别所有扫码类型,可能有些许影响识别效率
  186. scanType: ["qrCode", "barCode"],
  187. // 是否隐藏相册,默认false不隐藏
  188. hideAlbum: false,
  189. },
  190. (ret) => {
  191. let vehicleObj = JSON.parse(ret.resp_result);
  192. for (let i = 0; i < bindList.value.length; i++) {
  193. if (vehicleObj.carrierCode == bindList.value[i].carrierCode) {
  194. if (!bindList.value[i].flag) {
  195. endFlag.value += 1;
  196. }
  197. bindList.value[i].flag = true;
  198. }
  199. }
  200. }
  201. );
  202. }
  203. function handlePreFinishReporting(){
  204. handleSave();
  205. }
  206. function handleFinishReporting() {
  207. if (showCarrierList.value) {
  208. if (endFlag.value >= bindList.value.length) {
  209. handleSave();
  210. } else {
  211. uni.showToast({
  212. icon: "none",
  213. title: "请先扫码确认载具"
  214. })
  215. return;
  216. }
  217. } else {
  218. handleSave();
  219. }
  220. }
  221. function handleSave() {
  222. console.log(workInfo.value.qualifiedNum)
  223. if (workInfo.value.qualifiedNum === null || workInfo.value.qualifiedNum === '') {
  224. uni.showToast({
  225. icon: "error",
  226. title: "请输入合格数",
  227. })
  228. return;
  229. }
  230. for (let i = 0; i < wasteInfo.value.length; i++) {
  231. if ((!wasteInfo.value[i].rejectNum && wasteInfo.value[i].reason) ||
  232. (wasteInfo.value[i].rejectNum && !wasteInfo.value[i].reason) ||
  233. (!wasteInfo.value[i].rejectNum && !wasteInfo.value[i].reason)) {
  234. uni.showToast({
  235. icon: "error",
  236. title: "请输入废弃数或废弃原因",
  237. duration: 2000
  238. })
  239. return;
  240. }
  241. }
  242. close();
  243. if (workInfo.value.status != '3') {
  244. workInfo.value.status = '2';
  245. }
  246. workInfo.value.endTime = timestampToTime(new Date());
  247. workInfo.value.rejectList = wasteInfo.value;
  248. console.log(workInfo.value)
  249. saveDayWorkItem(workInfo.value).then(res => {
  250. if (res.code === 200) {
  251. uni.showToast({
  252. icon: 'success',
  253. title: '操作成功',
  254. });
  255. uni.$emit('dayworkItemUpdate');
  256. baseDialog.value.close();
  257. workInfo.value.qualifiedNum = null;
  258. } else {
  259. uni.showToast({
  260. icon: 'none',
  261. title: res.msg
  262. });
  263. }
  264. })
  265. }
  266. function handleAddWasteInfo() {
  267. if(wasteInfo.value.some(item => item.rejectNum == '' || item.reason == '')){
  268. uni.showToast({
  269. icon: 'none',
  270. title: '请填写废品量或废品原因再点击添加'
  271. })
  272. }else{
  273. wasteInfo.value.push({
  274. rejectNum: '',
  275. reason: ''
  276. })
  277. }
  278. }
  279. function handleDeleteWasteInfo(index) {
  280. wasteInfo.value.splice(index, 1);
  281. handleInputRejectNum();
  282. }
  283. function handleTenantChange() {
  284. }
  285. defineExpose({
  286. open
  287. })
  288. </script>
  289. <style lang="scss">
  290. .dialog-body {
  291. .list-container {
  292. width: 100%;
  293. display: flex;
  294. align-items: flex-start;
  295. padding: 0 4rpx;
  296. .list-title {
  297. width: 100%;
  298. margin-top: 16rpx;
  299. height: 64rpx;
  300. line-height: 64rpx;
  301. align-items: center;
  302. .label {
  303. flex: 1;
  304. font-size: 32rpx;
  305. }
  306. .input {
  307. width: 40%;
  308. height: 66rpx;
  309. padding-left: 10rpx;
  310. font-size: 22rpx;
  311. border: 1rpx solid #e1e1e1;
  312. border-radius: 8rpx;
  313. }
  314. .icon-gear {
  315. font-size: 56rpx;
  316. }
  317. }
  318. .switch {
  319. margin-top: -8rpx;
  320. align-items: center;
  321. transform: scale(0.7);
  322. }
  323. .confirmCarrier {
  324. .label {
  325. padding-top: 20rpx;
  326. font-size: 32rpx;
  327. }
  328. .vehicleList {
  329. justify-content: baseline;
  330. align-content: flex-start;
  331. flex-wrap: wrap;
  332. width: 100%;
  333. height: 120rpx;
  334. overflow: auto;
  335. .vehicleNo {
  336. padding: 0 10rpx;
  337. margin: 10rpx 20rpx 0 0;
  338. justify-content: space-between;
  339. align-items: center;
  340. width: auto;
  341. height: 60rpx;
  342. border: 2rpx solid rgba(213, 213, 213, 1);
  343. border-radius: 6rpx;
  344. }
  345. .blueBorder {
  346. background-color: #1684fc;
  347. color: #FFFFFF;
  348. }
  349. }
  350. }
  351. }
  352. .add-btn-container {
  353. margin-top: 32rpx;
  354. .btn {
  355. flex: 1;
  356. background-color: rgba(255, 85, 85, 1);
  357. color: #FFFFFF;
  358. margin-left: 5rpx;
  359. padding: 0;
  360. }
  361. .btnScan {
  362. flex: 1;
  363. color: #FFFFFF;
  364. margin-right: 5rpx;
  365. padding: 0;
  366. }
  367. }
  368. }
  369. </style>