dialog-end-work.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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 = {
  73. ...data
  74. };
  75. workInfo.value.qualifiedNum = null;
  76. console.log(data)
  77. wasteInfo.value = []
  78. baseDialog.value.open()
  79. }
  80. function close() {
  81. baseDialog.value.close()
  82. }
  83. function switchChange(event) {
  84. if (event.detail.value) {
  85. workInfo.value.status = "3"
  86. }else{
  87. workInfo.value.status = "2"
  88. }
  89. }
  90. function handleInputQualifiedNum() {
  91. workInfo.value.qualifiedNum = workInfo.value.qualifiedNum.replace(/^0+|^-+|[^\d]/g, '');
  92. }
  93. function handleInputRejectNum() {
  94. for (let i = 0; i < wasteInfo.value.length; i++) {
  95. wasteInfo.value[i].rejectNum = wasteInfo.value[i].rejectNum.replace(/^0+|^-|[^\d]/g, '');
  96. }
  97. }
  98. function handleFinishReporting() {
  99. if(!workInfo.value.qualifiedNum){
  100. uni.showToast({
  101. icon: "error",
  102. title: "请输入合格数",
  103. })
  104. return;
  105. }
  106. for (let i = 0; i < wasteInfo.value.length; i++) {
  107. if ((!wasteInfo.value[i].rejectNum && wasteInfo.value[i].reason) ||
  108. (wasteInfo.value[i].rejectNum && !wasteInfo.value[i].reason) ||
  109. (!wasteInfo.value[i].rejectNum && !wasteInfo.value[i].reason)) {
  110. uni.showToast({
  111. icon: "error",
  112. title: "请输入废弃数或废弃原因",
  113. duration: 2000
  114. })
  115. return;
  116. }
  117. }
  118. close();
  119. if (workInfo.value.status != '3') {
  120. workInfo.value.status = '2';
  121. }
  122. workInfo.value.endTime = timestampToTime(new Date());
  123. workInfo.value.rejectList = wasteInfo.value;
  124. console.log(workInfo.value)
  125. saveDayWorkItem(workInfo.value).then(res => {
  126. if (res.code === 200) {
  127. uni.showToast({
  128. icon: 'success',
  129. title: '操作成功',
  130. });
  131. uni.$emit('dayworkItemUpdate');
  132. baseDialog.value.close();
  133. workInfo.value.qualifiedNum = null;
  134. } else {
  135. uni.showToast({
  136. icon: 'none',
  137. title: res.msg
  138. });
  139. }
  140. })
  141. }
  142. function handleAddWasteInfo() {
  143. wasteInfo.value.push({
  144. rejectNum: '',
  145. reason: ''
  146. })
  147. }
  148. function handleDeleteWasteInfo(index) {
  149. wasteInfo.value.splice(index, 1)
  150. }
  151. function handleTenantChange() {
  152. }
  153. defineExpose({
  154. open
  155. })
  156. </script>
  157. <style lang="scss">
  158. .dialog-body {
  159. .list-container {
  160. width: 100%;
  161. display: flex;
  162. align-items: flex-start;
  163. padding: 0 4rpx;
  164. .list-title {
  165. width: 100%;
  166. margin-top: 16rpx;
  167. height: 64rpx;
  168. line-height: 64rpx;
  169. .label {
  170. flex: 1;
  171. font-size: 32rpx;
  172. }
  173. .input {
  174. width: 40%;
  175. height: 66rpx;
  176. padding-left: 10rpx;
  177. font-size: 22rpx;
  178. border: 1rpx solid #e1e1e1;
  179. border-radius: 8rpx;
  180. }
  181. .icon-gear {
  182. font-size: 56rpx;
  183. }
  184. }
  185. .switch {
  186. margin-top: -8rpx;
  187. align-items: center;
  188. transform: scale(0.7);
  189. }
  190. .equipment-container {
  191. width: 100%;
  192. height: 120rpx;
  193. flex-wrap: wrap;
  194. justify-content: flex-start;
  195. overflow: auto;
  196. .checkbox {
  197. padding: 12rpx 0;
  198. justify-content: center;
  199. align-items: center;
  200. }
  201. }
  202. .table-item {
  203. margin-top: 24rpx;
  204. }
  205. }
  206. .add-btn-container {
  207. margin-top: 32rpx;
  208. .btn {
  209. flex: 1;
  210. background-color: rgba(255, 85, 85, 1);
  211. color: #FFFFFF;
  212. }
  213. }
  214. }
  215. </style>