dialog-end-work.vue 5.4 KB

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