dialog-turnoverApplication.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484
  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(255,85,85,1)" />
  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. getDeptList
  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. const turnoverType = ref([])
  96. const outTurnArea = ref([])
  97. const turnoverArea = ref([])
  98. const normalStatus = ref(false)
  99. const selection = ref([])
  100. const curDayworkItem = ref({
  101. turnoverType: 1
  102. })
  103. const dayworkInfo = ref(null)
  104. const deptList = ref([]) // 工段列表
  105. const insideDepts = ref([]) // 车间内工段
  106. const outsideDepts = ref([]) // 车间外工段
  107. const turnAreaList = ref([]) // 周转区列表
  108. const emit = defineEmits(['reflushDaywork']) // 自定义调用父组件方法
  109. onLoad(() => {
  110. })
  111. function open(data) {
  112. resetPage();
  113. dayworkInfo.value = data;
  114. normalStatus.value = false
  115. init();
  116. baseDialog.value.open();
  117. }
  118. defineExpose({
  119. open
  120. })
  121. function close() {
  122. baseDialog.value.close()
  123. turnAreaList.value = [];
  124. }
  125. function resetPage() {
  126. turnoverDoorChecked.value = []
  127. turnoverType.value = []
  128. turnoverArea.value = []
  129. selection.value = []
  130. curDayworkItem.value = {
  131. turnoverType: 1
  132. }
  133. deptList.value = []
  134. insideDepts.value = []
  135. outsideDepts.value = []
  136. turnAreaList.value = []
  137. }
  138. function switchChange(event) {
  139. console.log(event.detail.value)
  140. //是
  141. if (event.detail.value) {
  142. normalStatus.value = true
  143. curDayworkItem.value.isNextPacking = true
  144. } else {
  145. //否
  146. normalStatus.value = false
  147. curDayworkItem.value.isNextPacking = false
  148. }
  149. console.log(event.detail.value, !store.isPreProcess)
  150. console.log(curDayworkItem.value)
  151. }
  152. function init() {
  153. getDictInfoByType('daywork_turnover_type').then(res => {
  154. turnoverType.value = res.data;
  155. getTurnoverByWorkshop({
  156. deptId: store.curDeptDetails.deptId
  157. }).then(res => {
  158. turnoverArea.value = res.data;
  159. })
  160. })
  161. getOutsourceTurnoverByWorkshop({
  162. deptCode:'170000'
  163. }).then(response =>{
  164. outTurnArea.value = response.data
  165. })
  166. getDayWorkItemList({
  167. dayworkId: dayworkInfo.value.id,
  168. userId: store.userInfo.userId,
  169. lotId: dayworkInfo.value.lotId,
  170. isWasteRecycling: dayworkInfo.value.isWasteRecycling,
  171. isAmend:dayworkInfo.value.isAmend,
  172. processStepNumber: dayworkInfo.value.currentProcess.processStepNumber
  173. }).then(res => {
  174. curDayworkItem.value = {
  175. ...res.rows[0],
  176. turnoverType: 1,
  177. deptId: null
  178. };
  179. })
  180. getDeptList({
  181. tenantId: store.tenantId,
  182. productionPlanDetailId: store.planDetails.id,
  183. lotId: dayworkInfo.value.lotId,
  184. isWasteRecycling: dayworkInfo.value.isWasteRecycling,
  185. isAmend: dayworkInfo.value.isAmend
  186. }).then(res => {
  187. for (let i = 0; i < res.data.length; i++) {
  188. deptList.value = res.data;
  189. console.log(deptList.value)
  190. if (store.curDeptDetails.workshopId == res.data[i].workshopId) {
  191. insideDepts.value.push({
  192. text: res.data[i].deptName,
  193. value: res.data[i].deptId,
  194. data: res.data[i]
  195. })
  196. } else {
  197. outsideDepts.value.push({
  198. text: res.data[i].deptName,
  199. value: res.data[i].deptId,
  200. data: res.data[i]
  201. })
  202. }
  203. }
  204. console.log(insideDepts.value)
  205. console.log(outsideDepts.value)
  206. })
  207. }
  208. function selectTurnoverType(item) {
  209. curDayworkItem.value.turnoverType = item.dictValue;
  210. selection.value = []
  211. normalStatus.value = false
  212. curDayworkItem.value.isNextPacking = false
  213. }
  214. function selectTurnoverDoor(item) {
  215. console.log(item,"chejiannei")
  216. // turnoverDoorChecked.value = item;
  217. // curDayworkItem.value.turnoverArea = item.dictValue;
  218. let index = selection.value.findIndex(selectedItem => selectedItem === item);
  219. if (index > -1) {
  220. selection.value.splice(index, 1);
  221. } else {
  222. selection.value.push(item);
  223. }
  224. }
  225. function selectTurnoverDoorOutside(item) {
  226. console.log(item,"wai")
  227. selection.value[0] = item;
  228. }
  229. function selectTurnoverOutsource(item) {
  230. console.log(item,"waixie")
  231. selection.value[0] = item
  232. }
  233. function handleTurnoverDoor(item) {
  234. return selection.value.includes(item);
  235. }
  236. //校验车间内车间外
  237. function handleValidate(data) {
  238. console.log(data)
  239. if (data.turnoverArea == "" || data.deptId == null || selection.value.length == 0) {
  240. return false;
  241. } else {
  242. return true;
  243. }
  244. }
  245. //校验外协
  246. function handleValidateOutsource(data) {
  247. console.log(data)
  248. if (selection.value.length == 0) {
  249. return false;
  250. } else {
  251. return true;
  252. }
  253. }
  254. function handleConfirmOutsource() {
  255. if (!handleValidateOutsource(curDayworkItem.value)) {
  256. uni.showToast({
  257. icon: "none",
  258. title: '请选择完整信息'
  259. });
  260. } else {
  261. curDayworkItem.value.id = null;
  262. curDayworkItem.value.startTime = timestampToTime(new Date());
  263. curDayworkItem.value.endTime = timestampToTime(new Date());
  264. curDayworkItem.value.technologicalProcessId = dayworkInfo.value.technologicalProcessId;
  265. curDayworkItem.value.dayworkId = dayworkInfo.value.id;
  266. curDayworkItem.value.productionPlanDetailId = dayworkInfo.value.productionPlanDetailId;
  267. curDayworkItem.value.status = '4';
  268. if (!store.tenantId) {
  269. curDayworkItem.value.tenantId = store.userInfo.tenantId;
  270. } else {
  271. curDayworkItem.value.tenantId = store.tenantId;
  272. }
  273. //curDayworkItem.value.turnoverArea = "外协周转";
  274. curDayworkItem.value.turnoverArea = selection.value.map((item) => {return item.code;}).join('、')
  275. // 0627 将turnoverId存入dayworkItem,多选将Id进行拼接
  276. curDayworkItem.value.turnoverId = selection.value.map((item) => {return item.id;}).join('、')
  277. /**** 此处暂时为硬编码,170000为外协部门编码,根据编码查询信息 ***/
  278. curDayworkItem.value.deptCode = 170000;
  279. close();
  280. turnoverOutsource(curDayworkItem.value).then(res => {
  281. if (res.code === 200) {
  282. uni.showToast({
  283. icon: 'success',
  284. title: '操作成功'
  285. });
  286. emit('reflushDaywork');
  287. } else {
  288. uni.showToast({
  289. icon: 'none',
  290. title: '操作失败'
  291. });
  292. }
  293. })
  294. }
  295. }
  296. function handleConfirm() {
  297. if (curDayworkItem.value.turnoverType == '3') {
  298. handleConfirmOutsource();
  299. } else {
  300. //console.log(dayworkInfo.value)
  301. curDayworkItem.value.id = null;
  302. curDayworkItem.value.status = '4';
  303. curDayworkItem.value.startTime = timestampToTime(new Date());
  304. curDayworkItem.value.endTime = timestampToTime(new Date());
  305. curDayworkItem.value.technologicalProcessId = dayworkInfo.value.technologicalProcessId;
  306. curDayworkItem.value.dayworkId = dayworkInfo.value.id;
  307. curDayworkItem.value.productionPlanDetailId = dayworkInfo.value.productionPlanDetailId;
  308. if (!store.tenantId) {
  309. curDayworkItem.value.tenantId = store.userInfo.tenantId;
  310. } else {
  311. curDayworkItem.value.tenantId = store.tenantId;
  312. }
  313. // 过滤出周转位置的数组,并转换成字符串
  314. const newArray = selection.value.map((item) => {
  315. if (item.code) {
  316. return item.code;
  317. } else if (item.dictLabel) {
  318. return item.dictLabel;
  319. } else {
  320. return null;
  321. }
  322. })
  323. const newIdArray = selection.value.map((item) => {
  324. if (item.id) {
  325. return item.id;
  326. } else {
  327. return null;
  328. }
  329. })
  330. if (curDayworkItem.value.turnoverType == '1') {
  331. curDayworkItem.value.place = newArray.join('、');
  332. //0628将位置id也拼接的方式存下来
  333. curDayworkItem.value.placeId = newIdArray.join('、');
  334. curDayworkItem.value.turnoverArea = "车间内周转看place字段";
  335. } else {
  336. curDayworkItem.value.turnoverArea = newArray.join('、');
  337. //0628将位置id也拼接的方式存下来
  338. curDayworkItem.value.turnoverId = newIdArray.join('、');
  339. }
  340. // curDayworkItem.value.dayworkId = store.dayworkInfo.id;
  341. // 设置周转下一个车间名
  342. for (let i = 0; i < deptList.value.length; i++) {
  343. if (deptList.value[i].deptId == curDayworkItem.value.deptId) {
  344. curDayworkItem.value.deptName = deptList.value[i].deptName;
  345. }
  346. }
  347. console.log(curDayworkItem.value);
  348. // console.log(dayworkInfo.value)
  349. if (!handleValidate(curDayworkItem.value)) {
  350. uni.showToast({
  351. icon: "none",
  352. title: '请选择完整信息'
  353. });
  354. } else {
  355. curDayworkItem.value.isNextPacking = false
  356. if(normalStatus.value) {
  357. curDayworkItem.value.isNextPacking = true
  358. }
  359. close();
  360. turnover(curDayworkItem.value).then(res => {
  361. if (res.code === 200) {
  362. uni.showToast({
  363. icon: 'success',
  364. title: '操作成功'
  365. });
  366. emit('reflushDaywork');
  367. } else {
  368. uni.showToast({
  369. icon: 'none',
  370. title: '操作失败'
  371. });
  372. }
  373. })
  374. }
  375. // emit('confirm');
  376. }
  377. }
  378. function handleChangeInside() {
  379. turnAreaList.value = [];
  380. selection.value = []
  381. getTurnoverListByDeptId({
  382. deptId: curDayworkItem.value.deptId,
  383. }).then(res => {
  384. for (var i = 0; i < res.data.length; i++) {
  385. if (res.data[i].status != 1) {
  386. turnAreaList.value[i] = res.data[i];
  387. }
  388. }
  389. })
  390. }
  391. function handleChangeOutside() {
  392. //console.log(curDayworkItem.value.deptId)
  393. }
  394. </script>
  395. <style lang="scss">
  396. .dialog-body {
  397. .list-container {
  398. width: 100%;
  399. .list-title {
  400. margin-top: 24rpx;
  401. .label {
  402. font-size: 32rpx;
  403. }
  404. }
  405. .turnArea {
  406. flex-wrap: wrap;
  407. height: auto;
  408. max-height: 200rpx;
  409. overflow: auto;
  410. }
  411. .btn {
  412. margin-top: 24rpx;
  413. .middle-btn {
  414. margin-right: 32rpx;
  415. align-items: center;
  416. justify-content: center;
  417. padding-left: 0;
  418. height: 80rpx;
  419. width: 220rpx;
  420. border-radius: 8rpx;
  421. background-color: #FFFFFF;
  422. border: 1px solid #999999;
  423. background-color: #FFFFFF;
  424. }
  425. .label {
  426. font-size: 24rpx;
  427. color: #000000;
  428. }
  429. .active {
  430. border-color: #1684fc;
  431. background-color: rgb(236, 245, 255);
  432. .label {
  433. color: #1684fc;
  434. }
  435. }
  436. }
  437. }
  438. .add-btn-container {
  439. margin-top: 32rpx;
  440. .btn {
  441. flex: 1;
  442. background-color: rgb(255, 121, 1);
  443. color: #FFFFFF;
  444. }
  445. }
  446. }
  447. </style>