dialog-turnoverApplication.vue 11 KB

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