dialog-turnoverApplication.vue 9.2 KB

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