dialog-end-work.vue 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  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. // uni.scanCode({
  201. // scanType: ['qrCode'], // 条形码扫描
  202. // onlyFromCamera: true, // 只允许相机扫码
  203. // autoZoom: false,
  204. // success: function(res) {
  205. // let vehicleObj = JSON.parse(res.result);
  206. // for (let i = 0; i < bindList.value.length; i++) {
  207. // if (vehicleObj.carrierCode == bindList.value[i].carrierCode) {
  208. // if (!bindList.value[i].flag) {
  209. // endFlag.value += 1;
  210. // }
  211. // bindList.value[i].flag = true;
  212. // }
  213. // }
  214. // }
  215. // });
  216. }
  217. function handlePreFinishReporting(){
  218. handleSave();
  219. }
  220. function handleFinishReporting() {
  221. if (showCarrierList.value) {
  222. if (endFlag.value >= bindList.value.length) {
  223. handleSave();
  224. } else {
  225. uni.showToast({
  226. icon: "none",
  227. title: "请先扫码确认载具"
  228. })
  229. return;
  230. }
  231. } else {
  232. handleSave();
  233. }
  234. }
  235. function handleSave() {
  236. if (!workInfo.value.qualifiedNum) {
  237. uni.showToast({
  238. icon: "error",
  239. title: "请输入合格数",
  240. })
  241. return;
  242. }
  243. for (let i = 0; i < wasteInfo.value.length; i++) {
  244. if ((!wasteInfo.value[i].rejectNum && wasteInfo.value[i].reason) ||
  245. (wasteInfo.value[i].rejectNum && !wasteInfo.value[i].reason) ||
  246. (!wasteInfo.value[i].rejectNum && !wasteInfo.value[i].reason)) {
  247. uni.showToast({
  248. icon: "error",
  249. title: "请输入废弃数或废弃原因",
  250. duration: 2000
  251. })
  252. return;
  253. }
  254. }
  255. close();
  256. if (workInfo.value.status != '3') {
  257. workInfo.value.status = '2';
  258. }
  259. workInfo.value.endTime = timestampToTime(new Date());
  260. workInfo.value.rejectList = wasteInfo.value;
  261. console.log(workInfo.value)
  262. saveDayWorkItem(workInfo.value).then(res => {
  263. if (res.code === 200) {
  264. uni.showToast({
  265. icon: 'success',
  266. title: '操作成功',
  267. });
  268. uni.$emit('dayworkItemUpdate');
  269. baseDialog.value.close();
  270. workInfo.value.qualifiedNum = null;
  271. } else {
  272. uni.showToast({
  273. icon: 'none',
  274. title: res.msg
  275. });
  276. }
  277. })
  278. }
  279. function handleAddWasteInfo() {
  280. wasteInfo.value.push({
  281. rejectNum: '',
  282. reason: ''
  283. })
  284. }
  285. function handleDeleteWasteInfo(index) {
  286. wasteInfo.value.splice(index, 1);
  287. handleInputRejectNum();
  288. }
  289. function handleTenantChange() {
  290. }
  291. defineExpose({
  292. open
  293. })
  294. </script>
  295. <style lang="scss">
  296. .dialog-body {
  297. .list-container {
  298. width: 100%;
  299. display: flex;
  300. align-items: flex-start;
  301. padding: 0 4rpx;
  302. .list-title {
  303. width: 100%;
  304. margin-top: 16rpx;
  305. height: 64rpx;
  306. line-height: 64rpx;
  307. align-items: center;
  308. .label {
  309. flex: 1;
  310. font-size: 32rpx;
  311. }
  312. .input {
  313. width: 40%;
  314. height: 66rpx;
  315. padding-left: 10rpx;
  316. font-size: 22rpx;
  317. border: 1rpx solid #e1e1e1;
  318. border-radius: 8rpx;
  319. }
  320. .icon-gear {
  321. font-size: 56rpx;
  322. }
  323. }
  324. .switch {
  325. margin-top: -8rpx;
  326. align-items: center;
  327. transform: scale(0.7);
  328. }
  329. .confirmCarrier {
  330. .label {
  331. padding-top: 20rpx;
  332. font-size: 32rpx;
  333. }
  334. .vehicleList {
  335. justify-content: baseline;
  336. align-content: flex-start;
  337. flex-wrap: wrap;
  338. width: 100%;
  339. height: 120rpx;
  340. overflow: auto;
  341. .vehicleNo {
  342. padding: 0 10rpx;
  343. margin: 10rpx 20rpx 0 0;
  344. justify-content: space-between;
  345. align-items: center;
  346. width: auto;
  347. height: 60rpx;
  348. border: 2rpx solid rgba(213, 213, 213, 1);
  349. border-radius: 6rpx;
  350. }
  351. .blueBorder {
  352. background-color: #1684fc;
  353. color: #FFFFFF;
  354. }
  355. }
  356. }
  357. }
  358. .add-btn-container {
  359. margin-top: 32rpx;
  360. .btn {
  361. flex: 1;
  362. background-color: rgba(255, 85, 85, 1);
  363. color: #FFFFFF;
  364. margin-left: 5rpx;
  365. padding: 0;
  366. }
  367. .btnScan {
  368. flex: 1;
  369. color: #FFFFFF;
  370. margin-right: 5rpx;
  371. padding: 0;
  372. }
  373. }
  374. }
  375. </style>