dialog-turnoverApplication.vue 15 KB

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