dialog-turnoverApplication.vue 7.7 KB

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