dialog-end-work.vue 5.2 KB

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