dialog-turnoverInnerApplication.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. <template>
  2. <dialog-base ref="baseDialog" title="周转申请">
  3. <view class="list-container">
  4. <view><text style="margin: 0 0 0 5rpx;">请选择周转类型</text></view>
  5. <view class="btn uni-row">
  6. <view v-for="(item,index) in turnoverType"
  7. :class="{ 'middle-btn': true, 'active': item.dictValue == curDayworkItem.turnoverType }"
  8. @click="selectTurnoverType(item)"><text class="label"
  9. style="font-size: 30rpx;">{{item.dictLabel}}</text></view>
  10. </view>
  11. <view class="" style="margin: 0 20rpx 20rpx 0;width: 88%;">
  12. <uni-section title="请选择下序工段" title-font-size="32rpx" style="margin: 0 0 0 -16rpx;"
  13. v-if="curDayworkItem.turnoverType == '1'">
  14. <uni-data-select disabled="true" v-model="curDayworkItem.deptId" :localdata="insideDepts"
  15. :clear="false"
  16. style="margin: 0 0 0 16rpx;outline: 2rpx solid #999999;border-radius: 10rpx;"></uni-data-select>
  17. </uni-section>
  18. <uni-section title="请选择下序工段" title-font-size="32rpx" style="margin: 0 0 0 -16rpx;"
  19. v-if="curDayworkItem.turnoverType == '2'">
  20. <uni-data-select v-model="curDayworkItem.deptId" :localdata="outsideDepts" :clear="false"
  21. style="margin: 0 0 0 16rpx;outline: 2rpx solid #999999;border-radius: 10rpx;"></uni-data-select>
  22. </uni-section>
  23. </view>
  24. <view class="list-title">
  25. <text class="label" style="margin: 0 0 0 -308rpx;">请选择您摆放位置</text>
  26. </view>
  27. <view class="turnArea uni-row" v-if="curDayworkItem.turnoverType == '1'">
  28. <view v-for="(item,index) in turnAreaList" class="btn">
  29. <view :class="{ 'middle-btn': true, 'active': handleTurnoverDoor(item) }"
  30. @click="selectTurnoverDoor(item)"><text class="label"
  31. style="font-size: 30rpx;">{{item.code}}</text></view>
  32. </view>
  33. </view>
  34. </view>
  35. <view class="add-btn-container uni-row">
  36. <button type="default" class="btn" @click="handleConfirm">确认</button>
  37. </view>
  38. </dialog-base>
  39. </template>
  40. <script setup>
  41. import {
  42. ref,
  43. getCurrentInstance
  44. } from 'vue'
  45. import {
  46. onLoad
  47. } from '@dcloudio/uni-app'
  48. import {
  49. getDictInfoByType
  50. } from '@/api/dict/dict.js'
  51. import {
  52. getTurnoverByWorkshop,
  53. getOutsourceTurnoverByWorkshop
  54. } from '@/api/business/workshop.js'
  55. import {
  56. getDayWorkItemList,
  57. turnoverInner,
  58. } from '@/api/business/dayWorkItem.js'
  59. import {
  60. getDeptListInfo
  61. } from '@/api/dept/dept.js'
  62. import {
  63. getTurnoverListByDeptId,
  64. } from '@/api/business/turnover.js'
  65. import {
  66. store
  67. } from '@/store/index.js'
  68. import {
  69. timestampToTime
  70. } from '@/utils/common.js'
  71. const baseDialog = ref(null)
  72. const turnoverDoorChecked = ref([])
  73. // 创建一个引用来存储最后一次请求的时间戳
  74. const lastRequestTimestamp = ref(0);
  75. const turnoverType = ref([])
  76. const outTurnArea = ref([])
  77. const turnoverArea = ref([])
  78. const normalStatus = ref(false)
  79. const selection = ref([])
  80. const curDayworkItem = ref({
  81. turnoverType: 1
  82. })
  83. const dayworkInfo = ref(null)
  84. const deptList = ref([]) // 工段列表
  85. const insideDepts = ref([]) // 车间内工段
  86. const outsideDepts = ref([]) // 车间外工段
  87. const turnAreaList = ref([]) // 周转区列表
  88. const emit = defineEmits(['reflushDaywork']) // 自定义调用父组件方法
  89. onLoad(() => {
  90. })
  91. function open(data) {
  92. resetPage();
  93. dayworkInfo.value = data;
  94. normalStatus.value = false
  95. init();
  96. baseDialog.value.open();
  97. }
  98. defineExpose({
  99. open
  100. })
  101. function close() {
  102. baseDialog.value.close()
  103. turnAreaList.value = [];
  104. }
  105. function resetPage() {
  106. turnoverDoorChecked.value = []
  107. turnoverType.value = []
  108. turnoverArea.value = []
  109. selection.value = []
  110. curDayworkItem.value = {
  111. turnoverType: 1,
  112. deptId: store.curDeptDetails.deptId,
  113. deptName: store.curDeptDetails.deptName
  114. }
  115. deptList.value = []
  116. insideDepts.value = []
  117. outsideDepts.value = []
  118. turnAreaList.value = []
  119. }
  120. function init() {
  121. console.log(dayworkInfo.value)
  122. turnoverType.value = [{
  123. dictValue: "1",
  124. dictLabel: "车间内"
  125. }];
  126. getDayWorkItemList({
  127. dayworkId: dayworkInfo.value.id,
  128. userId: store.userInfo.userId,
  129. lotId: dayworkInfo.value.lotId,
  130. isWasteRecycling: dayworkInfo.value.isWasteRecycling,
  131. isAmend: dayworkInfo.value.isAmend,
  132. processStepNumber: dayworkInfo.value.currentProcess.processStepNumber
  133. }).then(res => {
  134. curDayworkItem.value = {
  135. ...res.rows[0],
  136. turnoverType: 1,
  137. deptId: store.curDeptDetails.deptId,
  138. deptName: store.curDeptDetails.deptName
  139. };
  140. })
  141. deptList.value = store.curDeptDetails;
  142. console.log(deptList.value)
  143. insideDepts.value.push({
  144. text: deptList.value.deptName,
  145. value: deptList.value.deptId,
  146. })
  147. if (store.curDeptDetails.isSortPackaging == 1) {
  148. normalStatus.value = true
  149. } else {
  150. normalStatus.value = false
  151. }
  152. getTurnoverListByDeptId({
  153. deptId: curDayworkItem.value.deptId,
  154. }).then(res => {
  155. console.log("999")
  156. for (var i = 0; i < res.data.length; i++) {
  157. if (res.data[i].status != 1) {
  158. turnAreaList.value[i] = res.data[i];
  159. }
  160. }
  161. })
  162. curDayworkItem.value = {
  163. turnoverType: 1,
  164. deptId: store.curDeptDetails.deptId,
  165. deptName: store.curDeptDetails.deptName
  166. }
  167. }
  168. function selectTurnoverType(item) {
  169. curDayworkItem.value.deptId = null
  170. curDayworkItem.value.turnoverType = item.dictValue;
  171. selection.value = []
  172. normalStatus.value = false
  173. curDayworkItem.value.isNextPacking = false
  174. }
  175. function selectTurnoverDoor(item) {
  176. console.log(item, "chejiannei")
  177. // turnoverDoorChecked.value = item;
  178. // curDayworkItem.value.turnoverArea = item.dictValue;
  179. let index = selection.value.findIndex(selectedItem => selectedItem === item);
  180. if (index > -1) {
  181. selection.value.splice(index, 1);
  182. } else {
  183. selection.value.push(item);
  184. }
  185. }
  186. function handleTurnoverDoor(item) {
  187. return selection.value.includes(item);
  188. }
  189. //校验车间内车间外
  190. function handleValidate(data) {
  191. console.log(data)
  192. if (data.turnoverArea == "" || data.deptId == null || (turnAreaList.value.length != 0 && selection.value.length ==
  193. 0)) {
  194. console.log("999")
  195. return false;
  196. } else {
  197. console.log("888")
  198. return true;
  199. }
  200. }
  201. function handleConfirm() {
  202. const currentTime = Date.now();
  203. // 检查是否已经过去了 2 秒
  204. if (currentTime - lastRequestTimestamp.value < 2000) {
  205. // 如果在 2 秒 内已经有请求发出,那么不执行
  206. uni.showToast({
  207. icon: 'none',
  208. title: `请勿重复点击`,
  209. duration: 2000
  210. })
  211. return;
  212. }
  213. lastRequestTimestamp.value = currentTime;
  214. console.log(dayworkInfo.value)
  215. curDayworkItem.value.id = null;
  216. curDayworkItem.value.status = '4';
  217. curDayworkItem.value.processStepNumber = dayworkInfo.value.currentProcess.processStepNumber
  218. curDayworkItem.value.startTime = timestampToTime(new Date());
  219. curDayworkItem.value.endTime = timestampToTime(new Date());
  220. curDayworkItem.value.technologicalProcessId = dayworkInfo.value.technologicalProcessId;
  221. curDayworkItem.value.dayworkId = dayworkInfo.value.id;
  222. curDayworkItem.value.productionPlanDetailId = dayworkInfo.value.productionPlanDetailId;
  223. if (!store.tenantId) {
  224. curDayworkItem.value.tenantId = store.userInfo.tenantId;
  225. } else {
  226. curDayworkItem.value.tenantId = store.tenantId;
  227. }
  228. // 过滤出周转位置的数组,并转换成字符串
  229. if (selection.value.length > 0) {
  230. const newArray = selection.value.map((item) => {
  231. if (item.code) {
  232. return item.code;
  233. } else if (item.dictLabel) {
  234. return item.dictLabel;
  235. } else {
  236. return null;
  237. }
  238. })
  239. const newIdArray = selection.value.map((item) => {
  240. if (item.id) {
  241. return item.id;
  242. } else {
  243. return null;
  244. }
  245. })
  246. curDayworkItem.value.place = newArray.join('、');
  247. //0628将位置id也拼接的方式存下来
  248. curDayworkItem.value.placeId = newIdArray.join('、');
  249. }
  250. curDayworkItem.value.turnoverArea = "车间内周转看place字段";
  251. // console.log(dayworkInfo.value)
  252. if (!handleValidate(curDayworkItem.value)) {
  253. uni.showToast({
  254. icon: "none",
  255. title: '请选择完整信息'
  256. });
  257. } else {
  258. curDayworkItem.value.isNextPacking = false
  259. if (normalStatus.value) {
  260. curDayworkItem.value.isNextPacking = true
  261. }
  262. close();
  263. turnoverInner(curDayworkItem.value).then(res => {
  264. if (res.code === 200) {
  265. uni.showToast({
  266. icon: 'success',
  267. title: '操作成功'
  268. });
  269. emit('reflushDaywork');
  270. } else {
  271. console.log("999")
  272. console.log(res.msg)
  273. uni.showToast({
  274. icon: 'none',
  275. title: res.msg,
  276. duration: 2000
  277. });
  278. setTimeout(() => {
  279. emit('reflushDaywork')
  280. }, 1000);
  281. }
  282. })
  283. }
  284. }
  285. </script>
  286. <style lang="scss">
  287. .dialog-body {
  288. .list-container {
  289. width: 100%;
  290. .list-title {
  291. margin-top: 24rpx;
  292. .label {
  293. font-size: 32rpx;
  294. }
  295. }
  296. .turnArea {
  297. flex-wrap: wrap;
  298. height: auto;
  299. max-height: 200rpx;
  300. overflow: auto;
  301. }
  302. .btn {
  303. margin-top: 24rpx;
  304. .middle-btn {
  305. margin-right: 32rpx;
  306. align-items: center;
  307. justify-content: center;
  308. padding-left: 0;
  309. height: 80rpx;
  310. width: 220rpx;
  311. border-radius: 8rpx;
  312. background-color: #FFFFFF;
  313. border: 1px solid #999999;
  314. background-color: #FFFFFF;
  315. }
  316. .label {
  317. font-size: 24rpx;
  318. color: #000000;
  319. }
  320. .active {
  321. border-color: #1684fc;
  322. background-color: rgb(236, 245, 255);
  323. .label {
  324. color: #1684fc;
  325. }
  326. }
  327. }
  328. }
  329. .add-btn-container {
  330. margin-top: 32rpx;
  331. .btn {
  332. flex: 1;
  333. background-color: rgb(255, 121, 1);
  334. color: #FFFFFF;
  335. }
  336. }
  337. }
  338. </style>