dialog-turnoverApplication.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  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 >
  26. <text style=" margin: 0 0 0 5rpx;">请选择您摆放位置</text>
  27. </view>
  28. <view class="turnArea uni-row" v-if="curDayworkItem.turnoverType == '1'">
  29. <view v-for="(item,index) in turnAreaList" class="btn">
  30. <view :class="{ 'middle-btn': true, 'active': handleTurnoverDoor(item) }"
  31. @click="selectTurnoverDoor(item)"><text class="label"
  32. style="font-size: 30rpx;">{{item.code}}</text></view>
  33. </view>
  34. </view>
  35. <view class="turnArea uni-row" v-if="curDayworkItem.turnoverType == '2'">
  36. <view v-for="(item,index) in turnoverArea" class="btn">
  37. <view :class="{ 'middle-btn': true, 'active': handleTurnoverDoor(item) }"
  38. @click="selectTurnoverDoorOutside(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 == '3'">
  43. <view v-for="(item,index) in turnoverArea" class="btn">
  44. <view :class="{ 'middle-btn': true, 'active': handleTurnoverDoor(item) }"
  45. @click="selectTurnoverOutsource(item)"><text class="label"
  46. style="font-size: 30rpx;">{{item.code}}</text></view>
  47. </view>
  48. </view>
  49. </view>
  50. <view class="add-btn-container uni-row">
  51. <button type="default" class="btn" @click="handleConfirm">确认</button>
  52. </view>
  53. </dialog-base>
  54. </template>
  55. <script setup>
  56. import {
  57. ref,
  58. getCurrentInstance
  59. } from 'vue'
  60. import {
  61. onLoad
  62. } from '@dcloudio/uni-app'
  63. import {
  64. getDictInfoByType
  65. } from '@/api/dict/dict.js'
  66. import {
  67. getTurnoverByWorkshop,
  68. getOutsourceTurnoverByWorkshop
  69. } from '@/api/business/workshop.js'
  70. import {
  71. getDayWorkItemList,
  72. saveDayWorkItem,
  73. turnover,
  74. turnoverOutsource
  75. } from '@/api/business/dayWorkItem.js'
  76. import {
  77. getDeptList
  78. } from '@/api/dept/dept.js'
  79. import {
  80. getTurnoverListByDeptId,
  81. } from '@/api/business/turnover.js'
  82. import {
  83. store
  84. } from '@/store/index.js'
  85. import {
  86. timestampToTime
  87. } from '@/utils/common.js'
  88. const baseDialog = ref(null)
  89. const turnoverDoorChecked = ref([])
  90. const turnoverType = ref([])
  91. const outTurnArea = ref([])
  92. const turnoverArea = ref([])
  93. const selection = ref([])
  94. const curDayworkItem = ref({
  95. turnoverType: 1
  96. })
  97. const dayworkInfo = ref(null)
  98. const deptList = ref([]) // 工段列表
  99. const insideDepts = ref([]) // 车间内工段
  100. const outsideDepts = ref([]) // 车间外工段
  101. const turnAreaList = ref([]) // 周转区列表
  102. const emit = defineEmits(['reflushDaywork']) // 自定义调用父组件方法
  103. onLoad(() => {
  104. })
  105. function open(data) {
  106. resetPage();
  107. dayworkInfo.value = data;
  108. init();
  109. baseDialog.value.open();
  110. }
  111. defineExpose({
  112. open
  113. })
  114. function close() {
  115. baseDialog.value.close()
  116. turnAreaList.value = [];
  117. }
  118. function resetPage() {
  119. turnoverDoorChecked.value = []
  120. turnoverType.value = []
  121. turnoverArea.value = []
  122. selection.value = []
  123. curDayworkItem.value = {
  124. turnoverType: 1
  125. }
  126. deptList.value = []
  127. insideDepts.value = []
  128. outsideDepts.value = []
  129. turnAreaList.value = []
  130. }
  131. function init() {
  132. getDictInfoByType('daywork_turnover_type').then(res => {
  133. turnoverType.value = res.data;
  134. getTurnoverByWorkshop({
  135. deptId: store.curDeptDetails.deptId
  136. }).then(res => {
  137. turnoverArea.value = res.data;
  138. })
  139. })
  140. getOutsourceTurnoverByWorkshop({
  141. deptCode:'170000'
  142. }).then(response =>{
  143. outTurnArea.value = response.data
  144. })
  145. getDayWorkItemList({
  146. dayworkId: dayworkInfo.value.id,
  147. userId: store.userInfo.userId,
  148. lotId: dayworkInfo.value.lotId,
  149. isWasteRecycling: dayworkInfo.value.isWasteRecycling,
  150. isAmend:dayworkInfo.value.isAmend,
  151. processStepNumber: dayworkInfo.value.currentProcess.processStepNumber
  152. }).then(res => {
  153. curDayworkItem.value = {
  154. ...res.rows[0],
  155. turnoverType: 1,
  156. deptId: null
  157. };
  158. })
  159. getDeptList({
  160. tenantId: store.tenantId,
  161. productionPlanDetailId: store.planDetails.id,
  162. lotId: dayworkInfo.value.lotId,
  163. isWasteRecycling: dayworkInfo.value.isWasteRecycling,
  164. isAmend: dayworkInfo.value.isAmend
  165. }).then(res => {
  166. for (let i = 0; i < res.data.length; i++) {
  167. deptList.value = res.data;
  168. console.log(deptList.value)
  169. if (store.curDeptDetails.workshopId == res.data[i].workshopId) {
  170. insideDepts.value.push({
  171. text: res.data[i].deptName,
  172. value: res.data[i].deptId,
  173. data: res.data[i]
  174. })
  175. } else {
  176. outsideDepts.value.push({
  177. text: res.data[i].deptName,
  178. value: res.data[i].deptId,
  179. data: res.data[i]
  180. })
  181. }
  182. }
  183. console.log(insideDepts.value)
  184. console.log(outsideDepts.value)
  185. })
  186. }
  187. function selectTurnoverType(item) {
  188. curDayworkItem.value.turnoverType = item.dictValue;
  189. selection.value = []
  190. }
  191. function selectTurnoverDoor(item) {
  192. // turnoverDoorChecked.value = item;
  193. // curDayworkItem.value.turnoverArea = item.dictValue;
  194. let index = selection.value.findIndex(selectedItem => selectedItem === item);
  195. if (index > -1) {
  196. selection.value.splice(index, 1);
  197. } else {
  198. selection.value.push(item);
  199. }
  200. }
  201. function selectTurnoverDoorOutside(item) {
  202. selection.value[0] = item;
  203. }
  204. function selectTurnoverOutsource(item) {
  205. selection.value[0] = item
  206. }
  207. function handleTurnoverDoor(item) {
  208. return selection.value.includes(item);
  209. }
  210. //校验车间内车间外
  211. function handleValidate(data) {
  212. console.log(data)
  213. if (data.turnoverArea == "" || data.deptId == null || selection.value.length == 0) {
  214. return false;
  215. } else {
  216. return true;
  217. }
  218. }
  219. //校验外协
  220. function handleValidateOutsource(data) {
  221. console.log(data)
  222. if (selection.value.length == 0) {
  223. return false;
  224. } else {
  225. return true;
  226. }
  227. }
  228. function handleConfirmOutsource() {
  229. if (!handleValidateOutsource(curDayworkItem.value)) {
  230. uni.showToast({
  231. icon: "none",
  232. title: '请选择完整信息'
  233. });
  234. } else {
  235. curDayworkItem.value.id = null;
  236. curDayworkItem.value.startTime = timestampToTime(new Date());
  237. curDayworkItem.value.endTime = timestampToTime(new Date());
  238. curDayworkItem.value.technologicalProcessId = dayworkInfo.value.technologicalProcessId;
  239. curDayworkItem.value.dayworkId = dayworkInfo.value.id;
  240. curDayworkItem.value.productionPlanDetailId = dayworkInfo.value.productionPlanDetailId;
  241. curDayworkItem.value.status = '4';
  242. if (!store.tenantId) {
  243. curDayworkItem.value.tenantId = store.userInfo.tenantId;
  244. } else {
  245. curDayworkItem.value.tenantId = store.tenantId;
  246. }
  247. //curDayworkItem.value.turnoverArea = "外协周转";
  248. curDayworkItem.value.turnoverArea = selection.value.map((item) => {return item.code;}).join('、')
  249. /**** 此处暂时为硬编码,170000为外协部门编码,根据编码查询信息 ***/
  250. curDayworkItem.value.deptCode = 170000;
  251. close();
  252. turnoverOutsource(curDayworkItem.value).then(res => {
  253. if (res.code === 200) {
  254. uni.showToast({
  255. icon: 'success',
  256. title: '操作成功'
  257. });
  258. emit('reflushDaywork');
  259. } else {
  260. uni.showToast({
  261. icon: 'none',
  262. title: '操作失败'
  263. });
  264. }
  265. })
  266. }
  267. }
  268. function handleConfirm() {
  269. if (curDayworkItem.value.turnoverType == '3') {
  270. handleConfirmOutsource();
  271. } else {
  272. //console.log(dayworkInfo.value)
  273. curDayworkItem.value.id = null;
  274. curDayworkItem.value.status = curDayworkItem.value.turnoverType == '1' ? '7' : '4';
  275. curDayworkItem.value.startTime = timestampToTime(new Date());
  276. curDayworkItem.value.endTime = timestampToTime(new Date());
  277. curDayworkItem.value.technologicalProcessId = dayworkInfo.value.technologicalProcessId;
  278. curDayworkItem.value.dayworkId = dayworkInfo.value.id;
  279. curDayworkItem.value.productionPlanDetailId = dayworkInfo.value.productionPlanDetailId;
  280. if (!store.tenantId) {
  281. curDayworkItem.value.tenantId = store.userInfo.tenantId;
  282. } else {
  283. curDayworkItem.value.tenantId = store.tenantId;
  284. }
  285. // 过滤出周转位置的数组,并转换成字符串
  286. const newArray = selection.value.map((item) => {
  287. if (item.code) {
  288. return item.code;
  289. } else if (item.dictLabel) {
  290. return item.dictLabel;
  291. } else {
  292. return null;
  293. }
  294. })
  295. if (curDayworkItem.value.turnoverType == '1') {
  296. curDayworkItem.value.place = newArray.join('、');
  297. curDayworkItem.value.turnoverArea = "车间内周转看place字段";
  298. } else {
  299. curDayworkItem.value.turnoverArea = newArray.join('、');
  300. }
  301. // curDayworkItem.value.dayworkId = store.dayworkInfo.id;
  302. // 设置周转下一个车间名
  303. for (let i = 0; i < deptList.value.length; i++) {
  304. if (deptList.value[i].deptId == curDayworkItem.value.deptId) {
  305. curDayworkItem.value.deptName = deptList.value[i].deptName;
  306. }
  307. }
  308. // console.log(curDayworkItem.value);
  309. // console.log(dayworkInfo.value)
  310. if (!handleValidate(curDayworkItem.value)) {
  311. uni.showToast({
  312. icon: "none",
  313. title: '请选择完整信息'
  314. });
  315. } else {
  316. close();
  317. turnover(curDayworkItem.value).then(res => {
  318. if (res.code === 200) {
  319. uni.showToast({
  320. icon: 'success',
  321. title: '操作成功'
  322. });
  323. emit('reflushDaywork');
  324. } else {
  325. uni.showToast({
  326. icon: 'none',
  327. title: '操作失败'
  328. });
  329. }
  330. })
  331. }
  332. // emit('confirm');
  333. }
  334. }
  335. function handleChangeInside() {
  336. turnAreaList.value = [];
  337. selection.value = []
  338. getTurnoverListByDeptId({
  339. deptId: curDayworkItem.value.deptId,
  340. }).then(res => {
  341. for (var i = 0; i < res.data.length; i++) {
  342. if (res.data[i].status != 1) {
  343. turnAreaList.value[i] = res.data[i];
  344. }
  345. }
  346. })
  347. }
  348. function handleChangeOutside() {
  349. //console.log(curDayworkItem.value.deptId)
  350. }
  351. </script>
  352. <style lang="scss">
  353. .dialog-body {
  354. .list-container {
  355. width: 100%;
  356. .list-title {
  357. margin-top: 24rpx;
  358. .label {
  359. font-size: 32rpx;
  360. }
  361. }
  362. .turnArea {
  363. flex-wrap: wrap;
  364. height: auto;
  365. max-height: 200rpx;
  366. overflow: auto;
  367. }
  368. .btn {
  369. margin-top: 24rpx;
  370. .middle-btn {
  371. margin-right: 32rpx;
  372. align-items: center;
  373. justify-content: center;
  374. padding-left: 0;
  375. height: 80rpx;
  376. width: 220rpx;
  377. border-radius: 8rpx;
  378. background-color: #FFFFFF;
  379. border: 1px solid #999999;
  380. background-color: #FFFFFF;
  381. }
  382. .label {
  383. font-size: 24rpx;
  384. color: #000000;
  385. }
  386. .active {
  387. border-color: #1684fc;
  388. background-color: rgb(236, 245, 255);
  389. .label {
  390. color: #1684fc;
  391. }
  392. }
  393. }
  394. }
  395. .add-btn-container {
  396. margin-top: 32rpx;
  397. .btn {
  398. flex: 1;
  399. background-color: rgb(255, 121, 1);
  400. color: #FFFFFF;
  401. }
  402. }
  403. }
  404. </style>