dialog-turnoverApplicationAssist.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  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. getAssistDayWorkItemList,
  80. saveDayWorkItem,
  81. turnoverAssist,
  82. turnoverOutsourceAssist
  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. getAssistDayWorkItemList({
  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. console.log()
  186. })
  187. getDeptListInfo({
  188. tenantId: store.tenantId,
  189. productionPlanDetailId: store.planDetails.id,
  190. lotId: dayworkInfo.value.lotId,
  191. isWasteRecycling: dayworkInfo.value.isWasteRecycling,
  192. isAmend: dayworkInfo.value.isAmend
  193. }).then(res => {
  194. for (let i = 0; i < res.data.length; i++) {
  195. deptList.value = res.data;
  196. console.log(deptList.value)
  197. if (store.curDeptDetails.workshopId == res.data[i].workshopId) {
  198. insideDepts.value.push({
  199. text: res.data[i].deptName,
  200. value: res.data[i].deptId,
  201. data: res.data[i]
  202. })
  203. } else {
  204. outsideDepts.value.push({
  205. text: res.data[i].deptName,
  206. value: res.data[i].deptId,
  207. data: res.data[i]
  208. })
  209. }
  210. }
  211. console.log(insideDepts.value)
  212. console.log(outsideDepts.value)
  213. })
  214. }
  215. function selectTurnoverType(item) {
  216. curDayworkItem.value.deptId = null
  217. curDayworkItem.value.turnoverType = item.dictValue;
  218. selection.value = []
  219. normalStatus.value = false
  220. curDayworkItem.value.isNextPacking = false
  221. }
  222. function selectTurnoverDoor(item) {
  223. console.log(item, "chejiannei")
  224. // turnoverDoorChecked.value = item;
  225. // curDayworkItem.value.turnoverArea = item.dictValue;
  226. let index = selection.value.findIndex(selectedItem => selectedItem === item);
  227. if (index > -1) {
  228. selection.value.splice(index, 1);
  229. } else {
  230. selection.value.push(item);
  231. }
  232. }
  233. function selectTurnoverDoorOutside(item) {
  234. console.log(item, "wai")
  235. selection.value[0] = item;
  236. }
  237. function selectTurnoverOutsource(item) {
  238. console.log(item, "waixie")
  239. selection.value[0] = item
  240. }
  241. function handleTurnoverDoor(item) {
  242. return selection.value.includes(item);
  243. }
  244. //校验车间内车间外
  245. function handleValidate(data) {
  246. console.log(data)
  247. if (data.turnoverArea == "" || data.deptId == null || selection.value.length == 0) {
  248. return false;
  249. } else {
  250. return true;
  251. }
  252. }
  253. //校验外协
  254. function handleValidateOutsource(data) {
  255. console.log(data)
  256. if (selection.value.length == 0) {
  257. return false;
  258. } else {
  259. return true;
  260. }
  261. }
  262. function handleConfirmOutsource() {
  263. if (!handleValidateOutsource(curDayworkItem.value)) {
  264. uni.showToast({
  265. icon: "none",
  266. title: '请选择完整信息'
  267. });
  268. } else {
  269. const currentTime = Date.now();
  270. // 检查是否已经过去了 2 秒
  271. if (currentTime - lastRequestTimestamp.value < 2000) {
  272. // 如果在 2 秒 内已经有请求发出,那么不执行
  273. uni.showToast({
  274. icon: 'none',
  275. title: `请勿重复点击`,
  276. duration: 2000
  277. })
  278. return;
  279. }
  280. lastRequestTimestamp.value = currentTime;
  281. curDayworkItem.value.id = null;
  282. curDayworkItem.value.processStepNumber = dayworkInfo.value.currentProcess.processStepNumber
  283. curDayworkItem.value.startTime = timestampToTime(new Date());
  284. curDayworkItem.value.endTime = timestampToTime(new Date());
  285. curDayworkItem.value.technologicalProcessId = dayworkInfo.value.technologicalProcessId;
  286. curDayworkItem.value.dayworkId = dayworkInfo.value.id;
  287. curDayworkItem.value.productionPlanDetailId = dayworkInfo.value.productionPlanDetailId;
  288. curDayworkItem.value.status = '4';
  289. if (!store.tenantId) {
  290. curDayworkItem.value.tenantId = store.userInfo.tenantId;
  291. } else {
  292. curDayworkItem.value.tenantId = store.tenantId;
  293. }
  294. //curDayworkItem.value.turnoverArea = "外协周转";
  295. curDayworkItem.value.turnoverArea = selection.value.map((item) => {
  296. return item.code;
  297. }).join('、')
  298. // 0627 将turnoverId存入dayworkItem,多选将Id进行拼接
  299. curDayworkItem.value.turnoverId = selection.value.map((item) => {
  300. return item.id;
  301. }).join('、')
  302. /**** 此处暂时为硬编码,170000为外协部门编码,根据编码查询信息 ***/
  303. curDayworkItem.value.deptCode = 170000;
  304. close();
  305. turnoverOutsourceAssist(curDayworkItem.value).then(res => {
  306. if (res.code === 200) {
  307. uni.showToast({
  308. icon: 'success',
  309. title: '操作成功'
  310. });
  311. emit('reflushDaywork');
  312. } else {
  313. uni.showToast({
  314. icon: 'none',
  315. title: res.msg,
  316. duration: 2000
  317. });
  318. setTimeout(() => {
  319. emit('reflushDaywork')
  320. }, 1000);
  321. }
  322. })
  323. }
  324. }
  325. function handleConfirm() {
  326. if (curDayworkItem.value.turnoverType == '3') {
  327. handleConfirmOutsource();
  328. } else {
  329. const currentTime = Date.now();
  330. // 检查是否已经过去了 2 秒
  331. if (currentTime - lastRequestTimestamp.value < 2000) {
  332. // 如果在 2 秒 内已经有请求发出,那么不执行
  333. uni.showToast({
  334. icon: 'none',
  335. title: `请勿重复点击`,
  336. duration: 2000
  337. })
  338. return;
  339. }
  340. lastRequestTimestamp.value = currentTime;
  341. console.log(dayworkInfo.value)
  342. curDayworkItem.value.id = null;
  343. curDayworkItem.value.status = '4';
  344. curDayworkItem.value.processStepNumber = dayworkInfo.value.currentProcess.processStepNumber
  345. curDayworkItem.value.startTime = timestampToTime(new Date());
  346. curDayworkItem.value.endTime = timestampToTime(new Date());
  347. curDayworkItem.value.technologicalProcessId = dayworkInfo.value.technologicalProcessId;
  348. curDayworkItem.value.dayworkId = dayworkInfo.value.id;
  349. curDayworkItem.value.productionPlanDetailId = dayworkInfo.value.productionPlanDetailId;
  350. if (!store.tenantId) {
  351. curDayworkItem.value.tenantId = store.userInfo.tenantId;
  352. } else {
  353. curDayworkItem.value.tenantId = store.tenantId;
  354. }
  355. // 过滤出周转位置的数组,并转换成字符串
  356. const newArray = selection.value.map((item) => {
  357. if (item.code) {
  358. return item.code;
  359. } else if (item.dictLabel) {
  360. return item.dictLabel;
  361. } else {
  362. return null;
  363. }
  364. })
  365. const newIdArray = selection.value.map((item) => {
  366. if (item.id) {
  367. return item.id;
  368. } else {
  369. return null;
  370. }
  371. })
  372. if (curDayworkItem.value.turnoverType == '1') {
  373. curDayworkItem.value.place = newArray.join('、');
  374. //0628将位置id也拼接的方式存下来
  375. curDayworkItem.value.placeId = newIdArray.join('、');
  376. curDayworkItem.value.turnoverArea = "车间内周转看place字段";
  377. } else {
  378. curDayworkItem.value.turnoverArea = newArray.join('、');
  379. //0628将位置id也拼接的方式存下来
  380. curDayworkItem.value.turnoverId = newIdArray.join('、');
  381. }
  382. // curDayworkItem.value.dayworkId = store.dayworkInfo.id;
  383. // 设置周转下一个车间名
  384. for (let i = 0; i < deptList.value.length; i++) {
  385. if (deptList.value[i].deptId == curDayworkItem.value.deptId) {
  386. curDayworkItem.value.deptName = deptList.value[i].deptName;
  387. }
  388. }
  389. console.log(curDayworkItem.value);
  390. // console.log(dayworkInfo.value)
  391. if (!handleValidate(curDayworkItem.value)) {
  392. uni.showToast({
  393. icon: "none",
  394. title: '请选择完整信息'
  395. });
  396. } else {
  397. curDayworkItem.value.isNextPacking = false
  398. if (normalStatus.value) {
  399. curDayworkItem.value.isNextPacking = true
  400. }
  401. close();
  402. turnoverAssist(curDayworkItem.value).then(res => {
  403. if (res.code === 200) {
  404. uni.showToast({
  405. icon: 'success',
  406. title: '操作成功'
  407. });
  408. emit('reflushDaywork');
  409. } else {
  410. console.log("999")
  411. console.log(res.msg)
  412. uni.showToast({
  413. icon: 'none',
  414. title: res.msg,
  415. duration: 2000
  416. });
  417. setTimeout(() => {
  418. emit('reflushDaywork')
  419. }, 1000);
  420. }
  421. })
  422. }
  423. // emit('confirm');
  424. }
  425. }
  426. function handleChangeInside() {
  427. let deptInfo = deptList.value.find(item => item.deptId == curDayworkItem.value.deptId)
  428. console.log(deptInfo)
  429. if (deptInfo.isSortPackaging == 1) {
  430. normalStatus.value = true
  431. } else {
  432. normalStatus.value = false
  433. }
  434. turnAreaList.value = [];
  435. selection.value = []
  436. getTurnoverListByDeptId({
  437. deptId: curDayworkItem.value.deptId,
  438. }).then(res => {
  439. for (var i = 0; i < res.data.length; i++) {
  440. if (res.data[i].status != 1) {
  441. turnAreaList.value[i] = res.data[i];
  442. }
  443. }
  444. })
  445. }
  446. function handleChangeOutside() {
  447. let deptInfo = deptList.value.find(item => item.deptId == curDayworkItem.value.deptId)
  448. console.log(deptInfo)
  449. if (deptInfo.isSortPackaging == 1) {
  450. normalStatus.value = true
  451. } else {
  452. normalStatus.value = false
  453. }
  454. }
  455. </script>
  456. <style lang="scss">
  457. .dialog-body {
  458. .list-container {
  459. width: 100%;
  460. .list-title {
  461. margin-top: 24rpx;
  462. .label {
  463. font-size: 32rpx;
  464. }
  465. }
  466. .turnArea {
  467. flex-wrap: wrap;
  468. height: auto;
  469. max-height: 200rpx;
  470. overflow: auto;
  471. }
  472. .btn {
  473. margin-top: 24rpx;
  474. .middle-btn {
  475. margin-right: 32rpx;
  476. align-items: center;
  477. justify-content: center;
  478. padding-left: 0;
  479. height: 80rpx;
  480. width: 220rpx;
  481. border-radius: 8rpx;
  482. background-color: #FFFFFF;
  483. border: 1px solid #999999;
  484. background-color: #FFFFFF;
  485. }
  486. .label {
  487. font-size: 24rpx;
  488. color: #000000;
  489. }
  490. .active {
  491. border-color: #1684fc;
  492. background-color: rgb(236, 245, 255);
  493. .label {
  494. color: #1684fc;
  495. }
  496. }
  497. }
  498. }
  499. .add-btn-container {
  500. margin-top: 32rpx;
  501. .btn {
  502. flex: 1;
  503. background-color: rgb(255, 121, 1);
  504. color: #FFFFFF;
  505. }
  506. }
  507. }
  508. </style>