dialog-end-work.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  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="handleScanCode">扫码确认载具</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 handleScanCode() {
  127. uni.scanCode({
  128. scanType: ['qrCode'], // 条形码扫描
  129. onlyFromCamera: true, // 只允许相机扫码
  130. autoZoom: false,
  131. success: function(res) {
  132. let vehicleObj = JSON.parse(res.result);
  133. }
  134. });
  135. }
  136. function handleFinishReporting() {
  137. if (!workInfo.value.qualifiedNum) {
  138. uni.showToast({
  139. icon: "error",
  140. title: "请输入合格数",
  141. })
  142. return;
  143. }
  144. for (let i = 0; i < wasteInfo.value.length; i++) {
  145. if ((!wasteInfo.value[i].rejectNum && wasteInfo.value[i].reason) ||
  146. (wasteInfo.value[i].rejectNum && !wasteInfo.value[i].reason) ||
  147. (!wasteInfo.value[i].rejectNum && !wasteInfo.value[i].reason)) {
  148. uni.showToast({
  149. icon: "error",
  150. title: "请输入废弃数或废弃原因",
  151. duration: 2000
  152. })
  153. return;
  154. }
  155. }
  156. close();
  157. if (workInfo.value.status != '3') {
  158. workInfo.value.status = '2';
  159. }
  160. workInfo.value.endTime = timestampToTime(new Date());
  161. workInfo.value.rejectList = wasteInfo.value;
  162. console.log(workInfo.value)
  163. saveDayWorkItem(workInfo.value).then(res => {
  164. if (res.code === 200) {
  165. uni.showToast({
  166. icon: 'success',
  167. title: '操作成功',
  168. });
  169. uni.$emit('dayworkItemUpdate');
  170. baseDialog.value.close();
  171. workInfo.value.qualifiedNum = null;
  172. } else {
  173. uni.showToast({
  174. icon: 'none',
  175. title: res.msg
  176. });
  177. }
  178. })
  179. }
  180. function handleAddWasteInfo() {
  181. wasteInfo.value.push({
  182. rejectNum: '',
  183. reason: ''
  184. })
  185. }
  186. function handleDeleteWasteInfo(index) {
  187. wasteInfo.value.splice(index, 1)
  188. }
  189. function handleTenantChange() {
  190. }
  191. defineExpose({
  192. open
  193. })
  194. </script>
  195. <style lang="scss">
  196. .dialog-body {
  197. .list-container {
  198. width: 100%;
  199. display: flex;
  200. align-items: flex-start;
  201. padding: 0 4rpx;
  202. .list-title {
  203. width: 100%;
  204. margin-top: 16rpx;
  205. height: 64rpx;
  206. line-height: 64rpx;
  207. align-items: center;
  208. .label {
  209. flex: 1;
  210. font-size: 32rpx;
  211. }
  212. .input {
  213. width: 40%;
  214. height: 66rpx;
  215. padding-left: 10rpx;
  216. font-size: 22rpx;
  217. border: 1rpx solid #e1e1e1;
  218. border-radius: 8rpx;
  219. }
  220. .icon-gear {
  221. font-size: 56rpx;
  222. }
  223. }
  224. .switch {
  225. margin-top: -8rpx;
  226. align-items: center;
  227. transform: scale(0.7);
  228. }
  229. .confirmCarrier {
  230. .label {
  231. padding-top: 20rpx;
  232. font-size: 32rpx;
  233. }
  234. .vehicleList {
  235. justify-content: baseline;
  236. align-content: flex-start;
  237. flex-wrap: wrap;
  238. width: 100%;
  239. height: 120rpx;
  240. overflow: auto;
  241. .vehicleNo {
  242. padding: 0 10rpx;
  243. margin: 10rpx 20rpx 0 0;
  244. justify-content: space-between;
  245. align-items: center;
  246. width: auto;
  247. height: 60rpx;
  248. border: 1px solid rgba(213, 213, 213, 1);
  249. border-radius: 6rpx;
  250. }
  251. }
  252. }
  253. }
  254. .add-btn-container {
  255. margin-top: 32rpx;
  256. .btn {
  257. flex: 1;
  258. background-color: rgba(255, 85, 85, 1);
  259. color: #FFFFFF;
  260. margin-left: 5rpx;
  261. padding: 0;
  262. }
  263. .btnScan {
  264. flex: 1;
  265. color: #FFFFFF;
  266. margin-right: 5rpx;
  267. padding: 0;
  268. }
  269. }
  270. }
  271. </style>