dialog-end-work.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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" placeholder="废品量" />
  16. <uni-data-select style="margin-left: 40rpx;width: 70%;" v-model="item.reason" :localdata="reasonList"
  17. @change="handleTenantChange"></uni-data-select>
  18. <uni-icons class="icon-gear" type="close" size="60" color="red"
  19. @click="handleDeleteWasteInfo(index)"></uni-icons>
  20. </view>
  21. <view class="list-title uni-row" style="margin-top: 48rpx;">
  22. <text class="label">当前序是否完成</text><text>否</text>
  23. <switch class="switch" @change="switchChange" color="rgba(255,85,85,1)" />
  24. <text>是</text>
  25. </view>
  26. </view>
  27. <view class="add-btn-container uni-row">
  28. <button type="default" class="btn" @click="handleFinishReporting">结束报工</button>
  29. </view>
  30. </dialog-base>
  31. </template>
  32. <script setup>
  33. import {
  34. ref,
  35. getCurrentInstance
  36. } from 'vue'
  37. import {
  38. onLoad
  39. } from '@dcloudio/uni-app'
  40. import {
  41. updateDayWorkItem,
  42. saveDayWorkItem
  43. } from "@/api/business/dayWorkItem.js"
  44. import {
  45. timestampToTime,
  46. toHHmmss
  47. } from '@/utils/common.js'
  48. import {
  49. getDictInfoByType
  50. } from '@/api/dict/dict.js'
  51. const baseDialog = ref(null)
  52. const workInfo = ref({})
  53. const wasteInfo = ref([])
  54. const reasonList = ref([])
  55. const emit = defineEmits(['reset'])
  56. onLoad(() => {
  57. init();
  58. })
  59. function init() {
  60. getDictInfoByType("waste_causes").then(res => {
  61. for (let i = 0; i < res.data.length; i++) {
  62. reasonList.value[i] = {
  63. value: res.data[i].dictValue,
  64. text: res.data[i].dictLabel
  65. }
  66. }
  67. console.log(res);
  68. console.log(reasonList.value);
  69. })
  70. }
  71. function open(data) {
  72. workInfo.value = data;
  73. workInfo.value.qualifiedNum = null;
  74. console.log(data)
  75. wasteInfo.value = []
  76. baseDialog.value.open()
  77. }
  78. function close() {
  79. baseDialog.value.close()
  80. }
  81. function switchChange(event) {
  82. if (event.detail.value) {
  83. workInfo.value.status = "3"
  84. }else{
  85. workInfo.value.status = "2"
  86. }
  87. }
  88. function handleInputQualifiedNum() {
  89. workInfo.value.qualifiedNum = workInfo.value.qualifiedNum.replace(/^0+|^-+|[^\d]/g, '');
  90. }
  91. function handleInputRejectNum() {
  92. for (let i = 0; i < wasteInfo.value.length; i++) {
  93. wasteInfo.value[i].rejectNum = wasteInfo.value[i].rejectNum.replace(/^0+|^-|[^\d]/g, '');
  94. }
  95. }
  96. function handleFinishReporting() {
  97. if(!workInfo.value.qualifiedNum){
  98. uni.showToast({
  99. icon: "error",
  100. title: "请输入合格数",
  101. duration: 2000
  102. })
  103. return;
  104. }
  105. for (let i = 0; i < wasteInfo.value.length; i++) {
  106. if ((!wasteInfo.value[i].rejectNum && wasteInfo.value[i].reason) ||
  107. (wasteInfo.value[i].rejectNum && !wasteInfo.value[i].reason) ||
  108. (!wasteInfo.value[i].rejectNum && !wasteInfo.value[i].reason)) {
  109. uni.showToast({
  110. icon: "error",
  111. title: "请输入废弃数或废弃原因",
  112. duration: 2000
  113. })
  114. return;
  115. }
  116. }
  117. close();
  118. if (workInfo.value.status != '3') {
  119. workInfo.value.status = '2';
  120. }
  121. workInfo.value.endTime = timestampToTime(new Date());
  122. workInfo.value.rejectList = wasteInfo.value;
  123. console.log(workInfo.value)
  124. saveDayWorkItem(workInfo.value).then(res => {
  125. if (res.code === 200) {
  126. uni.showToast({
  127. icon: 'success',
  128. title: '操作成功',
  129. duration: 1000
  130. });
  131. uni.$emit('dayworkItemUpdate');
  132. baseDialog.value.close();
  133. workInfo.value.qualifiedNum = null;
  134. } else {
  135. uni.showToast({
  136. icon: 'error',
  137. title: '操作失败',
  138. duration: 1000
  139. });
  140. }
  141. })
  142. }
  143. function handleAddWasteInfo() {
  144. wasteInfo.value.push({
  145. rejectNum: '',
  146. reason: ''
  147. })
  148. }
  149. function handleDeleteWasteInfo(index) {
  150. wasteInfo.value.splice(index, 1)
  151. }
  152. function handleTenantChange() {
  153. }
  154. defineExpose({
  155. open
  156. })
  157. </script>
  158. <style lang="scss">
  159. .dialog-body {
  160. .list-container {
  161. width: 100%;
  162. display: flex;
  163. align-items: flex-start;
  164. padding: 0 4rpx;
  165. .list-title {
  166. width: 100%;
  167. margin-top: 16rpx;
  168. height: 64rpx;
  169. line-height: 64rpx;
  170. .label {
  171. flex: 1;
  172. font-size: 32rpx;
  173. }
  174. .input {
  175. width: 40%;
  176. height: 66rpx;
  177. padding-left: 10rpx;
  178. font-size: 22rpx;
  179. border: 1rpx solid #e1e1e1;
  180. border-radius: 8rpx;
  181. }
  182. .icon-gear {
  183. font-size: 56rpx;
  184. }
  185. }
  186. .switch {
  187. margin-top: -8rpx;
  188. align-items: center;
  189. transform: scale(0.7);
  190. }
  191. .equipment-container {
  192. width: 100%;
  193. height: 120rpx;
  194. flex-wrap: wrap;
  195. justify-content: flex-start;
  196. overflow: auto;
  197. .checkbox {
  198. padding: 12rpx 0;
  199. justify-content: center;
  200. align-items: center;
  201. }
  202. }
  203. .table-item {
  204. margin-top: 24rpx;
  205. }
  206. }
  207. .add-btn-container {
  208. margin-top: 32rpx;
  209. .btn {
  210. flex: 1;
  211. background-color: rgba(255, 85, 85, 1);
  212. color: #FFFFFF;
  213. }
  214. }
  215. }
  216. </style>