dialog-turnoverApplication.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549
  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 v-model="curDayworkItem.deptId" :localdata="insideDepts"
  15. @change="handleChangeInside" :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"
  21. @change="handleChangeOutside" :clear="false"
  22. style="margin: 0 0 0 16rpx;outline: 2rpx solid #999999;border-radius: 10rpx;"></uni-data-select>
  23. </uni-section>
  24. </view>
  25. <view v-if="curDayworkItem.turnoverType != '3'" class="list-title uni-row">
  26. <text class="label" style="margin: 0 0 0 -24rpx;">是否包装签票</text><text style="margin-left: 56rpx;"
  27. class="label">否</text>
  28. <switch class="switch" @change="switchChange" :checked="normalStatus"
  29. style="transform: scale(0.8);align-items: center;font-size:32rpx ;"
  30. color="rgba(103, 195, 55, 1.0)" />
  31. <text class="label">是</text>
  32. </view>
  33. <view class="list-title">
  34. <text class="label" style="margin: 0 0 0 -308rpx;">请选择您摆放位置</text>
  35. </view>
  36. <view class="turnArea uni-row" v-if="curDayworkItem.turnoverType == '1'">
  37. <view v-for="(item,index) in turnAreaList" class="btn">
  38. <view :class="{ 'middle-btn': true, 'active': handleTurnoverDoor(item) }"
  39. @click="selectTurnoverDoor(item)"><text class="label"
  40. style="font-size: 30rpx;">{{item.code}}</text></view>
  41. </view>
  42. </view>
  43. <view class="turnArea uni-row" v-if="curDayworkItem.turnoverType == '2'">
  44. <view v-for="(item,index) in turnoverArea" class="btn">
  45. <view :class="{ 'middle-btn': true, 'active': handleTurnoverDoor(item) }"
  46. @click="selectTurnoverDoorOutside(item)"><text class="label"
  47. style="font-size: 30rpx;">{{item.code}}</text></view>
  48. </view>
  49. </view>
  50. <view class="turnArea uni-row" v-if="curDayworkItem.turnoverType == '3'">
  51. <view v-for="(item,index) in turnoverArea" class="btn">
  52. <view :class="{ 'middle-btn': true, 'active': handleTurnoverDoor(item) }"
  53. @click="selectTurnoverOutsource(item)"><text class="label"
  54. style="font-size: 30rpx;">{{item.code}}</text></view>
  55. </view>
  56. </view>
  57. </view>
  58. <view class="add-btn-container uni-row">
  59. <button type="default" class="btn" @click="handleConfirm">确认</button>
  60. </view>
  61. </dialog-base>
  62. </template>
  63. <script setup>
  64. import {
  65. ref,
  66. getCurrentInstance
  67. } from 'vue'
  68. import {
  69. onLoad
  70. } from '@dcloudio/uni-app'
  71. import {
  72. getDictInfoByType
  73. } from '@/api/dict/dict.js'
  74. import {
  75. getTurnoverByWorkshop,
  76. getOutsourceTurnoverByWorkshop
  77. } from '@/api/business/workshop.js'
  78. import {
  79. getDayWorkItemList,
  80. saveDayWorkItem,
  81. turnover,
  82. turnoverOutsource
  83. } from '@/api/business/dayWorkItem.js'
  84. import {
  85. getDeptListInfo
  86. } from '@/api/dept/dept.js'
  87. import {
  88. getTurnoverListByDeptId,
  89. } from '@/api/business/turnover.js'
  90. import {
  91. store
  92. } from '@/store/index.js'
  93. import {
  94. timestampToTime
  95. } from '@/utils/common.js'
  96. const baseDialog = ref(null)
  97. const turnoverDoorChecked = ref([])
  98. // 创建一个引用来存储最后一次请求的时间戳
  99. const lastRequestTimestamp = ref(0);
  100. const turnoverType = ref([])
  101. const outTurnArea = ref([])
  102. const turnoverArea = ref([])
  103. const normalStatus = ref(false)
  104. const selection = ref([])
  105. const curDayworkItem = ref({
  106. turnoverType: 1
  107. })
  108. const dayworkInfo = ref(null)
  109. const deptList = ref([]) // 工段列表
  110. const insideDepts = ref([]) // 车间内工段
  111. const outsideDepts = ref([]) // 车间外工段
  112. const turnAreaList = ref([]) // 周转区列表
  113. const emit = defineEmits(['reflushDaywork']) // 自定义调用父组件方法
  114. onLoad(() => {
  115. })
  116. function open(data) {
  117. resetPage();
  118. dayworkInfo.value = data;
  119. normalStatus.value = false
  120. init();
  121. baseDialog.value.open();
  122. }
  123. defineExpose({
  124. open
  125. })
  126. function close() {
  127. baseDialog.value.close()
  128. turnAreaList.value = [];
  129. }
  130. function resetPage() {
  131. turnoverDoorChecked.value = []
  132. turnoverType.value = []
  133. turnoverArea.value = []
  134. selection.value = []
  135. curDayworkItem.value = {
  136. turnoverType: 1
  137. }
  138. deptList.value = []
  139. insideDepts.value = []
  140. outsideDepts.value = []
  141. turnAreaList.value = []
  142. }
  143. function switchChange(event) {
  144. console.log(event.detail.value)
  145. //是
  146. if (event.detail.value) {
  147. normalStatus.value = true
  148. curDayworkItem.value.isNextPacking = true
  149. } else {
  150. //否
  151. normalStatus.value = false
  152. curDayworkItem.value.isNextPacking = false
  153. }
  154. console.log(event.detail.value, !store.isPreProcess)
  155. console.log(curDayworkItem.value)
  156. }
  157. function init() {
  158. console.log(dayworkInfo.value)
  159. getDictInfoByType('daywork_turnover_type').then(res => {
  160. turnoverType.value = res.data;
  161. getTurnoverByWorkshop({
  162. deptId: store.curDeptDetails.deptId
  163. }).then(res => {
  164. turnoverArea.value = res.data;
  165. })
  166. })
  167. getOutsourceTurnoverByWorkshop({
  168. deptCode: '170000'
  169. }).then(response => {
  170. outTurnArea.value = response.data
  171. })
  172. getDayWorkItemList({
  173. dayworkId: dayworkInfo.value.id,
  174. userId: store.userInfo.userId,
  175. lotId: dayworkInfo.value.lotId,
  176. isWasteRecycling: dayworkInfo.value.isWasteRecycling,
  177. isAmend: dayworkInfo.value.isAmend,
  178. processStepNumber: dayworkInfo.value.currentProcess.processStepNumber
  179. }).then(res => {
  180. curDayworkItem.value = {
  181. ...res.rows[0],
  182. turnoverType: 1,
  183. deptId: null
  184. };
  185. })
  186. getDeptListInfo({
  187. tenantId: store.tenantId,
  188. productionPlanDetailId: store.planDetails.id,
  189. lotId: dayworkInfo.value.lotId,
  190. isWasteRecycling: dayworkInfo.value.isWasteRecycling,
  191. isAmend: dayworkInfo.value.isAmend
  192. }).then(res => {
  193. for (let i = 0; i < res.data.length; i++) {
  194. deptList.value = res.data;
  195. console.log(deptList.value)
  196. if (store.curDeptDetails.workshopId == res.data[i].workshopId) {
  197. insideDepts.value.push({
  198. text: res.data[i].deptName,
  199. value: res.data[i].deptId,
  200. data: res.data[i]
  201. })
  202. } else {
  203. outsideDepts.value.push({
  204. text: res.data[i].deptName,
  205. value: res.data[i].deptId,
  206. data: res.data[i]
  207. })
  208. }
  209. }
  210. console.log(insideDepts.value)
  211. console.log(outsideDepts.value)
  212. })
  213. }
  214. function selectTurnoverType(item) {
  215. curDayworkItem.value.deptId = null
  216. curDayworkItem.value.turnoverType = item.dictValue;
  217. selection.value = []
  218. normalStatus.value = false
  219. curDayworkItem.value.isNextPacking = false
  220. }
  221. function selectTurnoverDoor(item) {
  222. console.log(item, "chejiannei")
  223. // turnoverDoorChecked.value = item;
  224. // curDayworkItem.value.turnoverArea = item.dictValue;
  225. let index = selection.value.findIndex(selectedItem => selectedItem === item);
  226. if (index > -1) {
  227. selection.value.splice(index, 1);
  228. } else {
  229. selection.value.push(item);
  230. }
  231. }
  232. function selectTurnoverDoorOutside(item) {
  233. console.log(item, "wai")
  234. selection.value[0] = item;
  235. }
  236. function selectTurnoverOutsource(item) {
  237. console.log(item, "waixie")
  238. selection.value[0] = item
  239. }
  240. function handleTurnoverDoor(item) {
  241. return selection.value.includes(item);
  242. }
  243. //校验车间内车间外
  244. function handleValidate(data) {
  245. console.log(data)
  246. if (data.turnoverArea == "" || data.deptId == null || selection.value.length == 0) {
  247. return false;
  248. } else {
  249. return true;
  250. }
  251. }
  252. //校验外协
  253. function handleValidateOutsource(data) {
  254. console.log(data)
  255. if (selection.value.length == 0) {
  256. return false;
  257. } else {
  258. return true;
  259. }
  260. }
  261. function handleConfirmOutsource() {
  262. if (!handleValidateOutsource(curDayworkItem.value)) {
  263. uni.showToast({
  264. icon: "none",
  265. title: '请选择完整信息'
  266. });
  267. } else {
  268. const currentTime = Date.now();
  269. // 检查是否已经过去了 2 秒
  270. if (currentTime - lastRequestTimestamp.value < 2000) {
  271. // 如果在 2 秒 内已经有请求发出,那么不执行
  272. uni.showToast({
  273. icon: 'none',
  274. title: `请勿重复点击`,
  275. duration: 2000
  276. })
  277. return;
  278. }
  279. lastRequestTimestamp.value = currentTime;
  280. curDayworkItem.value.id = null;
  281. curDayworkItem.value.processStepNumber = dayworkInfo.value.currentProcess.processStepNumber
  282. curDayworkItem.value.startTime = timestampToTime(new Date());
  283. curDayworkItem.value.endTime = timestampToTime(new Date());
  284. curDayworkItem.value.technologicalProcessId = dayworkInfo.value.technologicalProcessId;
  285. curDayworkItem.value.dayworkId = dayworkInfo.value.id;
  286. curDayworkItem.value.productionPlanDetailId = dayworkInfo.value.productionPlanDetailId;
  287. curDayworkItem.value.status = '4';
  288. if (!store.tenantId) {
  289. curDayworkItem.value.tenantId = store.userInfo.tenantId;
  290. } else {
  291. curDayworkItem.value.tenantId = store.tenantId;
  292. }
  293. //curDayworkItem.value.turnoverArea = "外协周转";
  294. curDayworkItem.value.turnoverArea = selection.value.map((item) => {
  295. return item.code;
  296. }).join('、')
  297. // 0627 将turnoverId存入dayworkItem,多选将Id进行拼接
  298. curDayworkItem.value.turnoverId = selection.value.map((item) => {
  299. return item.id;
  300. }).join('、')
  301. /**** 此处暂时为硬编码,170000为外协部门编码,根据编码查询信息 ***/
  302. curDayworkItem.value.deptCode = 170000;
  303. close();
  304. turnoverOutsource(curDayworkItem.value).then(res => {
  305. if (res.code === 200) {
  306. uni.showToast({
  307. icon: 'success',
  308. title: '操作成功'
  309. });
  310. emit('reflushDaywork');
  311. } else {
  312. uni.showToast({
  313. icon: 'none',
  314. title: res.msg,
  315. duration: 2000
  316. });
  317. setTimeout(() => {
  318. emit('reflushDaywork')
  319. }, 1000);
  320. }
  321. })
  322. }
  323. }
  324. function handleConfirm() {
  325. if (curDayworkItem.value.turnoverType == '3') {
  326. handleConfirmOutsource();
  327. } else {
  328. const currentTime = Date.now();
  329. // 检查是否已经过去了 2 秒
  330. if (currentTime - lastRequestTimestamp.value < 2000) {
  331. // 如果在 2 秒 内已经有请求发出,那么不执行
  332. uni.showToast({
  333. icon: 'none',
  334. title: `请勿重复点击`,
  335. duration: 2000
  336. })
  337. return;
  338. }
  339. lastRequestTimestamp.value = currentTime;
  340. console.log(dayworkInfo.value)
  341. curDayworkItem.value.id = null;
  342. curDayworkItem.value.status = '4';
  343. curDayworkItem.value.processStepNumber = dayworkInfo.value.currentProcess.processStepNumber
  344. curDayworkItem.value.startTime = timestampToTime(new Date());
  345. curDayworkItem.value.endTime = timestampToTime(new Date());
  346. curDayworkItem.value.technologicalProcessId = dayworkInfo.value.technologicalProcessId;
  347. curDayworkItem.value.dayworkId = dayworkInfo.value.id;
  348. curDayworkItem.value.productionPlanDetailId = dayworkInfo.value.productionPlanDetailId;
  349. if (!store.tenantId) {
  350. curDayworkItem.value.tenantId = store.userInfo.tenantId;
  351. } else {
  352. curDayworkItem.value.tenantId = store.tenantId;
  353. }
  354. // 过滤出周转位置的数组,并转换成字符串
  355. const newArray = selection.value.map((item) => {
  356. if (item.code) {
  357. return item.code;
  358. } else if (item.dictLabel) {
  359. return item.dictLabel;
  360. } else {
  361. return null;
  362. }
  363. })
  364. const newIdArray = selection.value.map((item) => {
  365. if (item.id) {
  366. return item.id;
  367. } else {
  368. return null;
  369. }
  370. })
  371. if (curDayworkItem.value.turnoverType == '1') {
  372. curDayworkItem.value.place = newArray.join('、');
  373. //0628将位置id也拼接的方式存下来
  374. curDayworkItem.value.placeId = newIdArray.join('、');
  375. curDayworkItem.value.turnoverArea = "车间内周转看place字段";
  376. } else {
  377. curDayworkItem.value.turnoverArea = newArray.join('、');
  378. //0628将位置id也拼接的方式存下来
  379. curDayworkItem.value.turnoverId = newIdArray.join('、');
  380. }
  381. // curDayworkItem.value.dayworkId = store.dayworkInfo.id;
  382. // 设置周转下一个车间名
  383. for (let i = 0; i < deptList.value.length; i++) {
  384. if (deptList.value[i].deptId == curDayworkItem.value.deptId) {
  385. curDayworkItem.value.deptName = deptList.value[i].deptName;
  386. }
  387. }
  388. console.log(curDayworkItem.value);
  389. // console.log(dayworkInfo.value)
  390. if (!handleValidate(curDayworkItem.value)) {
  391. uni.showToast({
  392. icon: "none",
  393. title: '请选择完整信息'
  394. });
  395. } else {
  396. curDayworkItem.value.isNextPacking = false
  397. if (normalStatus.value) {
  398. curDayworkItem.value.isNextPacking = true
  399. }
  400. close();
  401. turnover(curDayworkItem.value).then(res => {
  402. if (res.code === 200) {
  403. uni.showToast({
  404. icon: 'success',
  405. title: '操作成功'
  406. });
  407. emit('reflushDaywork');
  408. } else {
  409. console.log("999")
  410. console.log(res.msg)
  411. uni.showToast({
  412. icon: 'none',
  413. title: res.msg,
  414. duration: 2000
  415. });
  416. setTimeout(() => {
  417. emit('reflushDaywork')
  418. }, 1000);
  419. }
  420. })
  421. }
  422. // emit('confirm');
  423. }
  424. }
  425. function handleChangeInside() {
  426. let deptInfo = deptList.value.find(item => item.deptId == curDayworkItem.value.deptId)
  427. console.log(deptInfo)
  428. if (deptInfo.isSortPackaging == 1) {
  429. normalStatus.value = true
  430. } else {
  431. normalStatus.value = false
  432. }
  433. turnAreaList.value = [];
  434. selection.value = []
  435. getTurnoverListByDeptId({
  436. deptId: curDayworkItem.value.deptId,
  437. }).then(res => {
  438. for (var i = 0; i < res.data.length; i++) {
  439. if (res.data[i].status != 1) {
  440. turnAreaList.value[i] = res.data[i];
  441. }
  442. }
  443. })
  444. }
  445. function handleChangeOutside() {
  446. let deptInfo = deptList.value.find(item => item.deptId == curDayworkItem.value.deptId)
  447. console.log(deptInfo)
  448. if (deptInfo.isSortPackaging == 1) {
  449. normalStatus.value = true
  450. } else {
  451. normalStatus.value = false
  452. }
  453. }
  454. </script>
  455. <style lang="scss">
  456. .dialog-body {
  457. .list-container {
  458. width: 100%;
  459. .list-title {
  460. margin-top: 24rpx;
  461. .label {
  462. font-size: 32rpx;
  463. }
  464. }
  465. .turnArea {
  466. flex-wrap: wrap;
  467. height: auto;
  468. max-height: 200rpx;
  469. overflow: auto;
  470. }
  471. .btn {
  472. margin-top: 24rpx;
  473. .middle-btn {
  474. margin-right: 32rpx;
  475. align-items: center;
  476. justify-content: center;
  477. padding-left: 0;
  478. height: 80rpx;
  479. width: 220rpx;
  480. border-radius: 8rpx;
  481. background-color: #FFFFFF;
  482. border: 1px solid #999999;
  483. background-color: #FFFFFF;
  484. }
  485. .label {
  486. font-size: 24rpx;
  487. color: #000000;
  488. }
  489. .active {
  490. border-color: #1684fc;
  491. background-color: rgb(236, 245, 255);
  492. .label {
  493. color: #1684fc;
  494. }
  495. }
  496. }
  497. }
  498. .add-btn-container {
  499. margin-top: 32rpx;
  500. .btn {
  501. flex: 1;
  502. background-color: rgb(255, 121, 1);
  503. color: #FFFFFF;
  504. }
  505. }
  506. }
  507. </style>