dialog-turnoverApplication.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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. baseDialog.value.open();
  83. init();
  84. }
  85. defineExpose({
  86. open
  87. })
  88. function close() {
  89. baseDialog.value.close()
  90. turnAreaList.value = [];
  91. }
  92. function resetPage() {
  93. turnoverDoorChecked.value = []
  94. turnoverType.value = []
  95. turnoverArea.value = []
  96. selection.value = []
  97. curDayworkItem.value = {
  98. turnoverType: 1
  99. }
  100. deptList.value = []
  101. turnAreaList.value = []
  102. }
  103. function init() {
  104. getDictInfoByType('daywork_turnover_type').then(res => {
  105. turnoverType.value = res.data;
  106. getDictInfoByType('workshop_turnover_area').then(res => {
  107. turnoverArea.value = res.data;
  108. })
  109. })
  110. getDayWorkItemList({
  111. dayworkId: dayworkInfo.value.id,
  112. userId: store.userInfo.userId
  113. }).then(res => {
  114. console.log(res.rows[0])
  115. curDayworkItem.value = {
  116. ...res.rows[0],
  117. turnoverType: 1
  118. };
  119. })
  120. getDeptList({
  121. isWorkSection: 1,
  122. tenantId: store.tenantId
  123. }).then(res => {
  124. console.log(res.data)
  125. for (let i = 0; i < res.data.length; i++) {
  126. deptList.value[i] = {
  127. text: res.data[i].deptName,
  128. value: res.data[i].deptId,
  129. data: res.data[i]
  130. }
  131. }
  132. })
  133. }
  134. function selectTurnoverType(item) {
  135. curDayworkItem.value.turnoverType = item.dictValue;
  136. selection.value = []
  137. }
  138. function selectTurnoverDoor(item) {
  139. // turnoverDoorChecked.value = item;
  140. // curDayworkItem.value.turnoverArea = item.dictValue;
  141. let index = selection.value.findIndex(selectedItem => selectedItem === item);
  142. if (index > -1) {
  143. selection.value.splice(index, 1);
  144. } else {
  145. selection.value.push(item);
  146. }
  147. }
  148. function handleTurnoverDoor(item) {
  149. return selection.value.includes(item);
  150. }
  151. function handleValidate(data) {
  152. console.log(data)
  153. if (data.turnoverArea == "" || data.deptId == null || selection.value.length == 0) {
  154. return false;
  155. } else {
  156. return true;
  157. }
  158. }
  159. function handleConfirm() {
  160. curDayworkItem.value.id = null;
  161. curDayworkItem.value.status = curDayworkItem.value.turnoverType == '1' ? '7' : '4';
  162. curDayworkItem.value.startTime = timestampToTime(new Date());
  163. curDayworkItem.value.technologicalProcessId = dayworkInfo.value.technologicalProcessId;
  164. if (!store.tenantId) {
  165. curDayworkItem.value.tenantId = store.userInfo.tenantId;
  166. } else {
  167. curDayworkItem.value.tenantId = store.tenantId;
  168. }
  169. // 过滤出周转位置的数组,并转换成字符串
  170. const newArray = selection.value.map((item) => {
  171. if (item.code) {
  172. return item.code;
  173. } else if (item.dictLabel) {
  174. return item.dictLabel;
  175. } else {
  176. return null;
  177. }
  178. })
  179. curDayworkItem.value.turnoverArea = newArray.join('、');
  180. // curDayworkItem.value.dayworkId = store.dayworkInfo.id;
  181. // 设置周转下一个车间名
  182. for (let i = 0; i < deptList.value.length; i++) {
  183. if (deptList.value[i].value == curDayworkItem.value.deptId) {
  184. curDayworkItem.value.deptName = deptList.value[i].text;
  185. }
  186. }
  187. console.log(curDayworkItem.value);
  188. console.log(dayworkInfo.value)
  189. if (!handleValidate(curDayworkItem.value)) {
  190. uni.showToast({
  191. icon: "error",
  192. title: '请选择完整信息'
  193. });
  194. } else {
  195. close();
  196. saveDayWorkItem(curDayworkItem.value).then(res => {
  197. if (res.code === 200) {
  198. uni.showToast({
  199. icon: 'success',
  200. title: '操作成功'
  201. });
  202. uni.$emit('dayworkItemUpdate');
  203. } else {
  204. uni.showToast({
  205. icon: 'error',
  206. title: '操作失败'
  207. });
  208. }
  209. })
  210. }
  211. // emit('confirm');
  212. }
  213. function handleChange() {
  214. turnAreaList.value = [];
  215. selection.value = []
  216. getTurnoverListByDeptId({
  217. deptId: curDayworkItem.value.deptId,
  218. }).then(res => {
  219. for (var i = 0; i < res.data.length; i++) {
  220. if (res.data[i].status == 0) {
  221. turnAreaList.value[i] = res.data[i];
  222. }
  223. }
  224. })
  225. }
  226. </script>
  227. <style lang="scss">
  228. .dialog-body {
  229. .list-container {
  230. width: 100%;
  231. .list-title {
  232. margin-top: 24rpx;
  233. .label {
  234. font-size: 32rpx;
  235. }
  236. }
  237. .turnArea {
  238. flex-wrap: wrap;
  239. height: auto;
  240. max-height: 200rpx;
  241. overflow: auto;
  242. }
  243. .btn {
  244. margin-top: 24rpx;
  245. .middle-btn {
  246. margin-right: 32rpx;
  247. align-items: center;
  248. justify-content: center;
  249. padding-left: 0;
  250. height: 80rpx;
  251. width: 220rpx;
  252. border-radius: 8rpx;
  253. background-color: #FFFFFF;
  254. border: 1px solid #999999;
  255. background-color: #FFFFFF;
  256. }
  257. .label {
  258. font-size: 24rpx;
  259. color: #000000;
  260. }
  261. .active {
  262. border-color: #1684fc;
  263. background-color: rgb(236, 245, 255);
  264. .label {
  265. color: #1684fc;
  266. }
  267. }
  268. }
  269. }
  270. .add-btn-container {
  271. margin-top: 32rpx;
  272. .btn {
  273. flex: 1;
  274. background-color: rgb(255, 121, 1);
  275. color: #FFFFFF;
  276. }
  277. }
  278. }
  279. </style>