dialog-end-work.vue 7.2 KB

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