dialog-turnoverApplication.vue 8.9 KB

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