dialog-end-work.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  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" :key="index"
  31. :class="{ 'vehicleNo': true, 'uni-row': true, 'blueBorder': item.flag }">
  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. const endFlag = ref(0)
  77. onLoad(() => {
  78. })
  79. function resetPage(){
  80. workInfo.value = {};
  81. wasteInfo.value = [];
  82. reasonList.value = [];
  83. showCarrierList.value = false;
  84. bindList.value = [];
  85. confirmCarrierList.value = [];
  86. endFlag.value = 0;
  87. }
  88. function init() {
  89. getDictInfoByType("waste_causes").then(res => {
  90. for (let i = 0; i < res.data.length; i++) {
  91. reasonList.value[i] = {
  92. value: res.data[i].dictValue,
  93. text: res.data[i].dictLabel
  94. }
  95. }
  96. console.log(res);
  97. console.log(reasonList.value);
  98. })
  99. getDayworkCarrierList({
  100. dayworkId: store.dayworkInfo.id,
  101. isChanged: 0
  102. }).then(res => {
  103. console.log(res)
  104. if (res.code == 200) {
  105. bindList.value = res.rows;
  106. for (let i = 0; i < bindList.value.length; i++) {
  107. bindList.value[i].flag = false;
  108. }
  109. console.log(bindList.value)
  110. }
  111. })
  112. }
  113. function open(data) {
  114. resetPage();
  115. workInfo.value = {
  116. ...data
  117. };
  118. workInfo.value.qualifiedNum = null;
  119. console.log(data)
  120. wasteInfo.value = []
  121. init();
  122. baseDialog.value.open()
  123. }
  124. function close() {
  125. baseDialog.value.close()
  126. }
  127. function switchChange(event) {
  128. if (event.detail.value) {
  129. workInfo.value.status = "3"
  130. } else {
  131. workInfo.value.status = "2"
  132. }
  133. showCarrierList.value = event.detail.value;
  134. }
  135. function handleInputQualifiedNum() {
  136. workInfo.value.qualifiedNum = workInfo.value.qualifiedNum.replace(/^-+|[^\d]/g, '');
  137. }
  138. function handleInputRejectNum() {
  139. for (let i = 0; i < wasteInfo.value.length; i++) {
  140. wasteInfo.value[i].rejectNum = wasteInfo.value[i].rejectNum.replace(/^0+|^-|[^\d]/g, '');
  141. }
  142. }
  143. function handleScanCode() {
  144. uni.scanCode({
  145. scanType: ['qrCode'], // 条形码扫描
  146. onlyFromCamera: true, // 只允许相机扫码
  147. autoZoom: false,
  148. success: function(res) {
  149. let vehicleObj = JSON.parse(res.result);
  150. for (let i = 0; i < bindList.value.length; i++) {
  151. if(vehicleObj.carrierCode == bindList.value[i].carrierCode){
  152. if(!bindList.value[i].flag){
  153. endFlag.value += 1;
  154. }
  155. bindList.value[i].flag = true;
  156. }
  157. }
  158. }
  159. });
  160. }
  161. function handleFinishReporting() {
  162. if(showCarrierList.value){
  163. if(endFlag.value >= bindList.value.length){
  164. handleSave();
  165. }else{
  166. uni.showToast({
  167. icon: "none",
  168. title: "请先扫码确认载具"
  169. })
  170. return;
  171. }
  172. }else{
  173. handleSave();
  174. }
  175. }
  176. function handleSave(){
  177. if (!workInfo.value.qualifiedNum) {
  178. uni.showToast({
  179. icon: "error",
  180. title: "请输入合格数",
  181. })
  182. return;
  183. }
  184. for (let i = 0; i < wasteInfo.value.length; i++) {
  185. if ((!wasteInfo.value[i].rejectNum && wasteInfo.value[i].reason) ||
  186. (wasteInfo.value[i].rejectNum && !wasteInfo.value[i].reason) ||
  187. (!wasteInfo.value[i].rejectNum && !wasteInfo.value[i].reason)) {
  188. uni.showToast({
  189. icon: "error",
  190. title: "请输入废弃数或废弃原因",
  191. duration: 2000
  192. })
  193. return;
  194. }
  195. }
  196. close();
  197. if (workInfo.value.status != '3') {
  198. workInfo.value.status = '2';
  199. }
  200. workInfo.value.endTime = timestampToTime(new Date());
  201. workInfo.value.rejectList = wasteInfo.value;
  202. console.log(workInfo.value)
  203. saveDayWorkItem(workInfo.value).then(res => {
  204. if (res.code === 200) {
  205. uni.showToast({
  206. icon: 'success',
  207. title: '操作成功',
  208. });
  209. uni.$emit('dayworkItemUpdate');
  210. baseDialog.value.close();
  211. workInfo.value.qualifiedNum = null;
  212. } else {
  213. uni.showToast({
  214. icon: 'none',
  215. title: res.msg
  216. });
  217. }
  218. })
  219. }
  220. function handleAddWasteInfo() {
  221. wasteInfo.value.push({
  222. rejectNum: '',
  223. reason: ''
  224. })
  225. }
  226. function handleDeleteWasteInfo(index) {
  227. wasteInfo.value.splice(index, 1)
  228. }
  229. function handleTenantChange() {
  230. }
  231. defineExpose({
  232. open
  233. })
  234. </script>
  235. <style lang="scss">
  236. .dialog-body {
  237. .list-container {
  238. width: 100%;
  239. display: flex;
  240. align-items: flex-start;
  241. padding: 0 4rpx;
  242. .list-title {
  243. width: 100%;
  244. margin-top: 16rpx;
  245. height: 64rpx;
  246. line-height: 64rpx;
  247. align-items: center;
  248. .label {
  249. flex: 1;
  250. font-size: 32rpx;
  251. }
  252. .input {
  253. width: 40%;
  254. height: 66rpx;
  255. padding-left: 10rpx;
  256. font-size: 22rpx;
  257. border: 1rpx solid #e1e1e1;
  258. border-radius: 8rpx;
  259. }
  260. .icon-gear {
  261. font-size: 56rpx;
  262. }
  263. }
  264. .switch {
  265. margin-top: -8rpx;
  266. align-items: center;
  267. transform: scale(0.7);
  268. }
  269. .confirmCarrier {
  270. .label {
  271. padding-top: 20rpx;
  272. font-size: 32rpx;
  273. }
  274. .vehicleList {
  275. justify-content: baseline;
  276. align-content: flex-start;
  277. flex-wrap: wrap;
  278. width: 100%;
  279. height: 120rpx;
  280. overflow: auto;
  281. .vehicleNo {
  282. padding: 0 10rpx;
  283. margin: 10rpx 20rpx 0 0;
  284. justify-content: space-between;
  285. align-items: center;
  286. width: auto;
  287. height: 60rpx;
  288. border: 2rpx solid rgba(213, 213, 213, 1);
  289. border-radius: 6rpx;
  290. }
  291. .blueBorder {
  292. background-color: #1684fc;
  293. color: #FFFFFF;
  294. }
  295. }
  296. }
  297. }
  298. .add-btn-container {
  299. margin-top: 32rpx;
  300. .btn {
  301. flex: 1;
  302. background-color: rgba(255, 85, 85, 1);
  303. color: #FFFFFF;
  304. margin-left: 5rpx;
  305. padding: 0;
  306. }
  307. .btnScan {
  308. flex: 1;
  309. color: #FFFFFF;
  310. margin-right: 5rpx;
  311. padding: 0;
  312. }
  313. }
  314. }
  315. </style>