dialog-turnoverApplication.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  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">下序是否包装</text><text style="margin-left: 56rpx;" class="label">否</text>
  27. <switch class="switch" @change="switchChange" :checked="normalStatus"
  28. style="transform: scale(0.8);align-items: center;font-size:32rpx ;"
  29. color="rgba(103, 195, 55, 1.0)" />
  30. <text class="label">是</text>
  31. </view>
  32. <view class="list-title">
  33. <text class="label">请选择您摆放位置</text>
  34. </view>
  35. <view class="turnArea uni-row" v-if="curDayworkItem.turnoverType == '1'">
  36. <view v-for="(item,index) in turnAreaList" class="btn">
  37. <view :class="{ 'middle-btn': true, 'active': handleTurnoverDoor(item) }"
  38. @click="selectTurnoverDoor(item)"><text class="label"
  39. style="font-size: 30rpx;">{{item.code}}</text></view>
  40. </view>
  41. </view>
  42. <view class="turnArea uni-row" v-if="curDayworkItem.turnoverType == '2'">
  43. <view v-for="(item,index) in turnoverArea" class="btn">
  44. <view :class="{ 'middle-btn': true, 'active': handleTurnoverDoor(item) }"
  45. @click="selectTurnoverDoorOutside(item)"><text class="label"
  46. style="font-size: 30rpx;">{{item.code}}</text></view>
  47. </view>
  48. </view>
  49. <view class="turnArea uni-row" v-if="curDayworkItem.turnoverType == '3'">
  50. <view v-for="(item,index) in turnoverArea" class="btn">
  51. <view :class="{ 'middle-btn': true, 'active': handleTurnoverDoor(item) }"
  52. @click="selectTurnoverOutsource(item)"><text class="label"
  53. style="font-size: 30rpx;">{{item.code}}</text></view>
  54. </view>
  55. </view>
  56. <view class="add-btn-container uni-row">
  57. <button type="default" class="btn" @click="handleConfirm">确认</button>
  58. </view>
  59. </view>
  60. </dialog-base>
  61. </template>
  62. <script setup>
  63. import {
  64. ref,
  65. getCurrentInstance
  66. } from 'vue'
  67. import {
  68. onLoad
  69. } from '@dcloudio/uni-app'
  70. import {
  71. getDictInfoByType
  72. } from '@/api/dict/dict.js'
  73. import {
  74. getTurnoverByWorkshop,
  75. getOutsourceTurnoverByWorkshop
  76. } from '@/api/business/workshop.js'
  77. import {
  78. getDayWorkItemList,
  79. saveDayWorkItem,
  80. turnover,
  81. turnoverOutsource
  82. } from '@/api/business/dayWorkItem.js'
  83. import {
  84. getDeptListInfo
  85. } from '@/api/dept/dept.js'
  86. import {
  87. getTurnoverListByDeptId,
  88. } from '@/api/business/turnover.js'
  89. import {
  90. store
  91. } from '@/store/index.js'
  92. import {
  93. timestampToTime
  94. } from '@/utils/common.js'
  95. const baseDialog = ref(null)
  96. const turnoverDoorChecked = ref([])
  97. // 创建一个引用来存储最后一次请求的时间戳
  98. const lastRequestTimestamp = ref(0);
  99. const turnoverType = ref([])
  100. const outTurnArea = ref([])
  101. const turnoverArea = ref([])
  102. const normalStatus = ref(false)
  103. const selection = ref([])
  104. const curDayworkItem = ref({
  105. turnoverType: 1
  106. })
  107. const dayworkInfo = ref(null)
  108. const deptList = ref([]) // 工段列表
  109. const insideDepts = ref([]) // 车间内工段
  110. const outsideDepts = ref([]) // 车间外工段
  111. const turnAreaList = ref([]) // 周转区列表
  112. const emit = defineEmits(['reflushDaywork']) // 自定义调用父组件方法
  113. onLoad(() => {
  114. })
  115. function open(data) {
  116. resetPage();
  117. dayworkInfo.value = data;
  118. normalStatus.value = false
  119. init();
  120. baseDialog.value.open();
  121. }
  122. defineExpose({
  123. open
  124. })
  125. function close() {
  126. baseDialog.value.close()
  127. turnAreaList.value = [];
  128. }
  129. function resetPage() {
  130. turnoverDoorChecked.value = []
  131. turnoverType.value = []
  132. turnoverArea.value = []
  133. selection.value = []
  134. curDayworkItem.value = {
  135. turnoverType: 1
  136. }
  137. deptList.value = []
  138. insideDepts.value = []
  139. outsideDepts.value = []
  140. turnAreaList.value = []
  141. }
  142. function switchChange(event) {
  143. console.log(event.detail.value)
  144. //是
  145. if (event.detail.value) {
  146. normalStatus.value = true
  147. curDayworkItem.value.isNextPacking = true
  148. } else {
  149. //否
  150. normalStatus.value = false
  151. curDayworkItem.value.isNextPacking = false
  152. }
  153. console.log(event.detail.value, !store.isPreProcess)
  154. console.log(curDayworkItem.value)
  155. }
  156. function init() {
  157. console.log(dayworkInfo.value)
  158. getDictInfoByType('daywork_turnover_type').then(res => {
  159. turnoverType.value = res.data;
  160. getTurnoverByWorkshop({
  161. deptId: store.curDeptDetails.deptId
  162. }).then(res => {
  163. turnoverArea.value = res.data;
  164. })
  165. })
  166. getOutsourceTurnoverByWorkshop({
  167. deptCode: '170000'
  168. }).then(response => {
  169. outTurnArea.value = response.data
  170. })
  171. getDayWorkItemList({
  172. dayworkId: dayworkInfo.value.id,
  173. userId: store.userInfo.userId,
  174. lotId: dayworkInfo.value.lotId,
  175. isWasteRecycling: dayworkInfo.value.isWasteRecycling,
  176. isAmend: dayworkInfo.value.isAmend,
  177. processStepNumber: dayworkInfo.value.currentProcess.processStepNumber
  178. }).then(res => {
  179. curDayworkItem.value = {
  180. ...res.rows[0],
  181. turnoverType: 1,
  182. deptId: null
  183. };
  184. })
  185. getDeptListInfo({
  186. tenantId: store.tenantId,
  187. productionPlanDetailId: store.planDetails.id,
  188. lotId: dayworkInfo.value.lotId,
  189. isWasteRecycling: dayworkInfo.value.isWasteRecycling,
  190. isAmend: dayworkInfo.value.isAmend
  191. }).then(res => {
  192. for (let i = 0; i < res.data.length; i++) {
  193. deptList.value = res.data;
  194. console.log(deptList.value)
  195. if (store.curDeptDetails.workshopId == res.data[i].workshopId) {
  196. insideDepts.value.push({
  197. text: res.data[i].deptName,
  198. value: res.data[i].deptId,
  199. data: res.data[i]
  200. })
  201. } else {
  202. outsideDepts.value.push({
  203. text: res.data[i].deptName,
  204. value: res.data[i].deptId,
  205. data: res.data[i]
  206. })
  207. }
  208. }
  209. console.log(insideDepts.value)
  210. console.log(outsideDepts.value)
  211. })
  212. }
  213. function selectTurnoverType(item) {
  214. curDayworkItem.value.deptId = null
  215. curDayworkItem.value.turnoverType = item.dictValue;
  216. selection.value = []
  217. normalStatus.value = false
  218. curDayworkItem.value.isNextPacking = false
  219. }
  220. function selectTurnoverDoor(item) {
  221. console.log(item, "chejiannei")
  222. // turnoverDoorChecked.value = item;
  223. // curDayworkItem.value.turnoverArea = item.dictValue;
  224. let index = selection.value.findIndex(selectedItem => selectedItem === item);
  225. if (index > -1) {
  226. selection.value.splice(index, 1);
  227. } else {
  228. selection.value.push(item);
  229. }
  230. }
  231. function selectTurnoverDoorOutside(item) {
  232. console.log(item, "wai")
  233. selection.value[0] = item;
  234. }
  235. function selectTurnoverOutsource(item) {
  236. console.log(item, "waixie")
  237. selection.value[0] = item
  238. }
  239. function handleTurnoverDoor(item) {
  240. return selection.value.includes(item);
  241. }
  242. //校验车间内车间外
  243. function handleValidate(data) {
  244. console.log(data)
  245. if (data.turnoverArea == "" || data.deptId == null || selection.value.length == 0) {
  246. return false;
  247. } else {
  248. return true;
  249. }
  250. }
  251. //校验外协
  252. function handleValidateOutsource(data) {
  253. console.log(data)
  254. if (selection.value.length == 0) {
  255. return false;
  256. } else {
  257. return true;
  258. }
  259. }
  260. function handleConfirmOutsource() {
  261. if (!handleValidateOutsource(curDayworkItem.value)) {
  262. uni.showToast({
  263. icon: "none",
  264. title: '请选择完整信息'
  265. });
  266. } else {
  267. const currentTime = Date.now();
  268. // 检查是否已经过去了 2 秒
  269. if (currentTime - lastRequestTimestamp.value < 2000) {
  270. // 如果在 2 秒 内已经有请求发出,那么不执行
  271. uni.showToast({
  272. icon: 'none',
  273. title: `请勿重复点击`,
  274. duration: 2000
  275. })
  276. return;
  277. }
  278. lastRequestTimestamp.value = currentTime;
  279. curDayworkItem.value.id = null;
  280. curDayworkItem.value.processStepNumber = dayworkInfo.value.currentProcess.processStepNumber
  281. curDayworkItem.value.startTime = timestampToTime(new Date());
  282. curDayworkItem.value.endTime = timestampToTime(new Date());
  283. curDayworkItem.value.technologicalProcessId = dayworkInfo.value.technologicalProcessId;
  284. curDayworkItem.value.dayworkId = dayworkInfo.value.id;
  285. curDayworkItem.value.productionPlanDetailId = dayworkInfo.value.productionPlanDetailId;
  286. curDayworkItem.value.status = '4';
  287. if (!store.tenantId) {
  288. curDayworkItem.value.tenantId = store.userInfo.tenantId;
  289. } else {
  290. curDayworkItem.value.tenantId = store.tenantId;
  291. }
  292. //curDayworkItem.value.turnoverArea = "外协周转";
  293. curDayworkItem.value.turnoverArea = selection.value.map((item) => {
  294. return item.code;
  295. }).join('、')
  296. // 0627 将turnoverId存入dayworkItem,多选将Id进行拼接
  297. curDayworkItem.value.turnoverId = selection.value.map((item) => {
  298. return item.id;
  299. }).join('、')
  300. /**** 此处暂时为硬编码,170000为外协部门编码,根据编码查询信息 ***/
  301. curDayworkItem.value.deptCode = 170000;
  302. console.log(curDayworkItem.value)
  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. overflow: auto;
  458. .list-container {
  459. width: 100%;
  460. overflow: auto;
  461. .list-title {
  462. margin-top: 24rpx;
  463. .label {
  464. font-size: 32rpx;
  465. }
  466. }
  467. .turnArea {
  468. flex-wrap: wrap;
  469. height: auto;
  470. max-height: 200rpx;
  471. overflow: auto;
  472. }
  473. .btn {
  474. margin-top: 24rpx;
  475. .middle-btn {
  476. margin-right: 32rpx;
  477. align-items: center;
  478. justify-content: center;
  479. padding-left: 0;
  480. height: 80rpx;
  481. width: 220rpx;
  482. border-radius: 8rpx;
  483. background-color: #FFFFFF;
  484. border: 1px solid #999999;
  485. background-color: #FFFFFF;
  486. }
  487. .label {
  488. font-size: 24rpx;
  489. color: #000000;
  490. }
  491. .active {
  492. border-color: #1684fc;
  493. background-color: rgb(236, 245, 255);
  494. .label {
  495. color: #1684fc;
  496. }
  497. }
  498. }
  499. }
  500. .add-btn-container {
  501. margin-top: 32rpx;
  502. .btn {
  503. flex: 1;
  504. background-color: rgb(255, 121, 1);
  505. color: #FFFFFF;
  506. }
  507. }
  508. }
  509. </style>