dialog-turnoverApplication.vue 8.8 KB

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