dialog-turnoverApplication.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  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. isAmend:dayworkInfo.value.isAmend,
  137. processStepNumber: dayworkInfo.value.currentProcess.processStepNumber
  138. }).then(res => {
  139. curDayworkItem.value = {
  140. ...res.rows[0],
  141. turnoverType: 1,
  142. deptId: null
  143. };
  144. })
  145. getDeptList({
  146. tenantId: store.tenantId,
  147. productionPlanDetailId: store.planDetails.id,
  148. lotId: dayworkInfo.value.lotId,
  149. isWasteRecycling: dayworkInfo.value.isWasteRecycling,
  150. isAmend: dayworkInfo.value.isAmend
  151. }).then(res => {
  152. for (let i = 0; i < res.data.length; i++) {
  153. deptList.value = res.data;
  154. console.log(deptList.value)
  155. if (store.curDeptDetails.workshopId == res.data[i].workshopId) {
  156. insideDepts.value.push({
  157. text: res.data[i].deptName,
  158. value: res.data[i].deptId,
  159. data: res.data[i]
  160. })
  161. } else {
  162. outsideDepts.value.push({
  163. text: res.data[i].deptName,
  164. value: res.data[i].deptId,
  165. data: res.data[i]
  166. })
  167. }
  168. }
  169. console.log(insideDepts.value)
  170. console.log(outsideDepts.value)
  171. })
  172. }
  173. function selectTurnoverType(item) {
  174. curDayworkItem.value.turnoverType = item.dictValue;
  175. selection.value = []
  176. }
  177. function selectTurnoverDoor(item) {
  178. // turnoverDoorChecked.value = item;
  179. // curDayworkItem.value.turnoverArea = item.dictValue;
  180. let index = selection.value.findIndex(selectedItem => selectedItem === item);
  181. if (index > -1) {
  182. selection.value.splice(index, 1);
  183. } else {
  184. selection.value.push(item);
  185. }
  186. }
  187. function selectTurnoverDoorOutside(item) {
  188. selection.value[0] = item;
  189. }
  190. function handleTurnoverDoor(item) {
  191. return selection.value.includes(item);
  192. }
  193. function handleValidate(data) {
  194. console.log(data)
  195. if (data.turnoverArea == "" || data.deptId == null || selection.value.length == 0) {
  196. return false;
  197. } else {
  198. return true;
  199. }
  200. }
  201. function handleConfirmOutsource() {
  202. curDayworkItem.value.id = null;
  203. curDayworkItem.value.startTime = timestampToTime(new Date());
  204. curDayworkItem.value.endTime = timestampToTime(new Date());
  205. curDayworkItem.value.technologicalProcessId = dayworkInfo.value.technologicalProcessId;
  206. curDayworkItem.value.dayworkId = dayworkInfo.value.id;
  207. curDayworkItem.value.productionPlanDetailId = dayworkInfo.value.productionPlanDetailId;
  208. curDayworkItem.value.status = '4';
  209. if (!store.tenantId) {
  210. curDayworkItem.value.tenantId = store.userInfo.tenantId;
  211. } else {
  212. curDayworkItem.value.tenantId = store.tenantId;
  213. }
  214. curDayworkItem.value.turnoverArea = "外协周转";
  215. /**** 此处暂时为硬编码,170000为外协部门编码,根据编码查询信息 ***/
  216. curDayworkItem.value.deptCode = 170000;
  217. close();
  218. turnoverOutsource(curDayworkItem.value).then(res => {
  219. if (res.code === 200) {
  220. uni.showToast({
  221. icon: 'success',
  222. title: '操作成功'
  223. });
  224. emit('reflushDaywork');
  225. } else {
  226. uni.showToast({
  227. icon: 'none',
  228. title: '操作失败'
  229. });
  230. }
  231. })
  232. }
  233. function handleConfirm() {
  234. if (curDayworkItem.value.turnoverType == '3') {
  235. handleConfirmOutsource();
  236. } else {
  237. //console.log(dayworkInfo.value)
  238. curDayworkItem.value.id = null;
  239. curDayworkItem.value.status = curDayworkItem.value.turnoverType == '1' ? '7' : '4';
  240. curDayworkItem.value.startTime = timestampToTime(new Date());
  241. curDayworkItem.value.endTime = timestampToTime(new Date());
  242. curDayworkItem.value.technologicalProcessId = dayworkInfo.value.technologicalProcessId;
  243. curDayworkItem.value.dayworkId = dayworkInfo.value.id;
  244. curDayworkItem.value.productionPlanDetailId = dayworkInfo.value.productionPlanDetailId;
  245. if (!store.tenantId) {
  246. curDayworkItem.value.tenantId = store.userInfo.tenantId;
  247. } else {
  248. curDayworkItem.value.tenantId = store.tenantId;
  249. }
  250. // 过滤出周转位置的数组,并转换成字符串
  251. const newArray = selection.value.map((item) => {
  252. if (item.code) {
  253. return item.code;
  254. } else if (item.dictLabel) {
  255. return item.dictLabel;
  256. } else {
  257. return null;
  258. }
  259. })
  260. if (curDayworkItem.value.turnoverType == '1') {
  261. curDayworkItem.value.place = newArray.join('、');
  262. curDayworkItem.value.turnoverArea = "车间内周转看place字段";
  263. } else {
  264. curDayworkItem.value.turnoverArea = newArray.join('、');
  265. }
  266. // curDayworkItem.value.dayworkId = store.dayworkInfo.id;
  267. // 设置周转下一个车间名
  268. for (let i = 0; i < deptList.value.length; i++) {
  269. if (deptList.value[i].deptId == curDayworkItem.value.deptId) {
  270. curDayworkItem.value.deptName = deptList.value[i].deptName;
  271. }
  272. }
  273. // console.log(curDayworkItem.value);
  274. // console.log(dayworkInfo.value)
  275. if (!handleValidate(curDayworkItem.value)) {
  276. uni.showToast({
  277. icon: "none",
  278. title: '请选择完整信息'
  279. });
  280. } else {
  281. close();
  282. turnover(curDayworkItem.value).then(res => {
  283. if (res.code === 200) {
  284. uni.showToast({
  285. icon: 'success',
  286. title: '操作成功'
  287. });
  288. emit('reflushDaywork');
  289. } else {
  290. uni.showToast({
  291. icon: 'none',
  292. title: '操作失败'
  293. });
  294. }
  295. })
  296. }
  297. // emit('confirm');
  298. }
  299. }
  300. function handleChangeInside() {
  301. turnAreaList.value = [];
  302. selection.value = []
  303. getTurnoverListByDeptId({
  304. deptId: curDayworkItem.value.deptId,
  305. }).then(res => {
  306. for (var i = 0; i < res.data.length; i++) {
  307. if (res.data[i].status != 1) {
  308. turnAreaList.value[i] = res.data[i];
  309. }
  310. }
  311. })
  312. }
  313. function handleChangeOutside() {
  314. //console.log(curDayworkItem.value.deptId)
  315. }
  316. </script>
  317. <style lang="scss">
  318. .dialog-body {
  319. .list-container {
  320. width: 100%;
  321. .list-title {
  322. margin-top: 24rpx;
  323. .label {
  324. font-size: 32rpx;
  325. }
  326. }
  327. .turnArea {
  328. flex-wrap: wrap;
  329. height: auto;
  330. max-height: 200rpx;
  331. overflow: auto;
  332. }
  333. .btn {
  334. margin-top: 24rpx;
  335. .middle-btn {
  336. margin-right: 32rpx;
  337. align-items: center;
  338. justify-content: center;
  339. padding-left: 0;
  340. height: 80rpx;
  341. width: 220rpx;
  342. border-radius: 8rpx;
  343. background-color: #FFFFFF;
  344. border: 1px solid #999999;
  345. background-color: #FFFFFF;
  346. }
  347. .label {
  348. font-size: 24rpx;
  349. color: #000000;
  350. }
  351. .active {
  352. border-color: #1684fc;
  353. background-color: rgb(236, 245, 255);
  354. .label {
  355. color: #1684fc;
  356. }
  357. }
  358. }
  359. }
  360. .add-btn-container {
  361. margin-top: 32rpx;
  362. .btn {
  363. flex: 1;
  364. background-color: rgb(255, 121, 1);
  365. color: #FFFFFF;
  366. }
  367. }
  368. }
  369. </style>