dialog-end-work.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  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" class="confirmCarrier">
  28. <text class="label">确认载具</text>
  29. <view class="vehicleList uni-row">
  30. <view class="vehicleNo uni-row" v-for="(item,index) in bindList">
  31. <text>{{item.carrierCode}}</text>
  32. </view>
  33. </view>
  34. </view>
  35. </view>
  36. <view class="add-btn-container uni-row">
  37. <button v-if="showCarrierList" type="primary" class="btnScan" @click="handleFinishReporting">扫码确认载具</button>
  38. <button type="default" class="btn" @click="handleFinishReporting">结束报工</button>
  39. </view>
  40. </dialog-base>
  41. </template>
  42. <script setup>
  43. import {
  44. ref,
  45. getCurrentInstance
  46. } from 'vue'
  47. import {
  48. onLoad
  49. } from '@dcloudio/uni-app'
  50. import {
  51. updateDayWorkItem,
  52. saveDayWorkItem
  53. } from "@/api/business/dayWorkItem.js"
  54. import {
  55. getDayworkCarrierList
  56. } from '@/api/business/dayworkCarrier.js'
  57. import {
  58. store
  59. } from '@/store/index.js'
  60. import {
  61. timestampToTime,
  62. toHHmmss
  63. } from '@/utils/common.js'
  64. import {
  65. getDictInfoByType
  66. } from '@/api/dict/dict.js'
  67. const baseDialog = ref(null)
  68. const workInfo = ref({})
  69. const wasteInfo = ref([])
  70. const reasonList = ref([])
  71. const emit = defineEmits(['reset'])
  72. const showCarrierList = ref(false) // 工序是否完成显示载具列表
  73. const bindList = ref([])
  74. onLoad(() => {
  75. init();
  76. })
  77. function init() {
  78. getDictInfoByType("waste_causes").then(res => {
  79. for (let i = 0; i < res.data.length; i++) {
  80. reasonList.value[i] = {
  81. value: res.data[i].dictValue,
  82. text: res.data[i].dictLabel
  83. }
  84. }
  85. console.log(res);
  86. console.log(reasonList.value);
  87. })
  88. getDayworkCarrierList({
  89. dayworkId: store.dayworkInfo.id,
  90. isChanged: 0
  91. }).then(res => {
  92. console.log(res)
  93. if (res.code == 200) {
  94. bindList.value = res.rows;
  95. }
  96. })
  97. }
  98. function open(data) {
  99. workInfo.value = {
  100. ...data
  101. };
  102. workInfo.value.qualifiedNum = null;
  103. console.log(data)
  104. wasteInfo.value = []
  105. baseDialog.value.open()
  106. }
  107. function close() {
  108. baseDialog.value.close()
  109. }
  110. function switchChange(event) {
  111. if (event.detail.value) {
  112. workInfo.value.status = "3"
  113. } else {
  114. workInfo.value.status = "2"
  115. }
  116. showCarrierList.value = event.detail.value;
  117. }
  118. function handleInputQualifiedNum() {
  119. workInfo.value.qualifiedNum = workInfo.value.qualifiedNum.replace(/^0+|^-+|[^\d]/g, '');
  120. }
  121. function handleInputRejectNum() {
  122. for (let i = 0; i < wasteInfo.value.length; i++) {
  123. wasteInfo.value[i].rejectNum = wasteInfo.value[i].rejectNum.replace(/^0+|^-|[^\d]/g, '');
  124. }
  125. }
  126. function handleFinishReporting() {
  127. if (!workInfo.value.qualifiedNum) {
  128. uni.showToast({
  129. icon: "error",
  130. title: "请输入合格数",
  131. })
  132. return;
  133. }
  134. for (let i = 0; i < wasteInfo.value.length; i++) {
  135. if ((!wasteInfo.value[i].rejectNum && wasteInfo.value[i].reason) ||
  136. (wasteInfo.value[i].rejectNum && !wasteInfo.value[i].reason) ||
  137. (!wasteInfo.value[i].rejectNum && !wasteInfo.value[i].reason)) {
  138. uni.showToast({
  139. icon: "error",
  140. title: "请输入废弃数或废弃原因",
  141. duration: 2000
  142. })
  143. return;
  144. }
  145. }
  146. close();
  147. if (workInfo.value.status != '3') {
  148. workInfo.value.status = '2';
  149. }
  150. workInfo.value.endTime = timestampToTime(new Date());
  151. workInfo.value.rejectList = wasteInfo.value;
  152. console.log(workInfo.value)
  153. saveDayWorkItem(workInfo.value).then(res => {
  154. if (res.code === 200) {
  155. uni.showToast({
  156. icon: 'success',
  157. title: '操作成功',
  158. });
  159. uni.$emit('dayworkItemUpdate');
  160. baseDialog.value.close();
  161. workInfo.value.qualifiedNum = null;
  162. } else {
  163. uni.showToast({
  164. icon: 'none',
  165. title: res.msg
  166. });
  167. }
  168. })
  169. }
  170. function handleAddWasteInfo() {
  171. wasteInfo.value.push({
  172. rejectNum: '',
  173. reason: ''
  174. })
  175. }
  176. function handleDeleteWasteInfo(index) {
  177. wasteInfo.value.splice(index, 1)
  178. }
  179. function handleTenantChange() {
  180. }
  181. defineExpose({
  182. open
  183. })
  184. </script>
  185. <style lang="scss">
  186. .dialog-body {
  187. .list-container {
  188. width: 100%;
  189. display: flex;
  190. align-items: flex-start;
  191. padding: 0 4rpx;
  192. .list-title {
  193. width: 100%;
  194. margin-top: 16rpx;
  195. height: 64rpx;
  196. line-height: 64rpx;
  197. .label {
  198. flex: 1;
  199. font-size: 32rpx;
  200. }
  201. .input {
  202. width: 40%;
  203. height: 66rpx;
  204. padding-left: 10rpx;
  205. font-size: 22rpx;
  206. border: 1rpx solid #e1e1e1;
  207. border-radius: 8rpx;
  208. }
  209. .icon-gear {
  210. font-size: 56rpx;
  211. }
  212. }
  213. .switch {
  214. margin-top: -8rpx;
  215. align-items: center;
  216. transform: scale(0.7);
  217. }
  218. .confirmCarrier {
  219. .vehicleList {
  220. justify-content: baseline;
  221. align-content: flex-start;
  222. flex-wrap: wrap;
  223. width: 100%;
  224. height: 120rpx;
  225. overflow: auto;
  226. .vehicleNo {
  227. padding: 0 10rpx;
  228. margin: 10rpx 20rpx 0 0;
  229. justify-content: space-between;
  230. align-items: center;
  231. width: auto;
  232. height: 60rpx;
  233. border: 1px solid rgba(213, 213, 213, 1);
  234. border-radius: 6rpx;
  235. }
  236. }
  237. }
  238. }
  239. .add-btn-container {
  240. margin-top: 32rpx;
  241. .btn {
  242. flex: 1;
  243. background-color: rgba(255, 85, 85, 1);
  244. color: #FFFFFF;
  245. margin-left: 5rpx;
  246. padding: 0;
  247. }
  248. .btnScan {
  249. flex: 1;
  250. color: #FFFFFF;
  251. margin-right: 5rpx;
  252. padding: 0;
  253. }
  254. }
  255. }
  256. </style>