dialog-turnoverApplication.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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 == turnoverTypeChecked }"
  8. @click="selectTurnoverType(item)"><text class="label">{{item.dictLabel}}</text></view>
  9. </view>
  10. <view v-if="curDayworkItem.turnoverType == '2'" class="list-title">
  11. <text class="label">请选择周转位置</text>
  12. </view>
  13. <view class="uni-row">
  14. <view v-if="curDayworkItem.turnoverType == '2'" v-for="(item,index) in turnoverArea" class="btn">
  15. <view :class="{ 'middle-btn': true, 'active': item == turnoverDoorChecked }"
  16. @click="selectTurnoverDoor(item)"><text class="label">{{item.dictLabel}}</text></view>
  17. </view>
  18. </view>
  19. <view v-if="curDayworkItem.turnoverType == '2'" class="" style="margin: 0 20rpx 20rpx 0;width: 96%;">
  20. <uni-section title="请选择周转工段" title-font-size="32rpx" style="margin: 0 0 0 -16rpx;">
  21. <uni-data-select v-model="curDayworkItem.deptId" :localdata="deptList" @change="handleChange"
  22. style="margin: 0 0 0 16rpx;outline: 2rpx solid #999999;border-radius: 10rpx;"></uni-data-select>
  23. </uni-section>
  24. </view>
  25. </view>
  26. <view class="add-btn-container uni-row">
  27. <button type="default" class="btn" @click="handleConfirm">确认</button>
  28. </view>
  29. </dialog-base>
  30. </template>
  31. <script setup>
  32. import {
  33. ref,
  34. getCurrentInstance,
  35. onMounted
  36. } from 'vue'
  37. import {
  38. onLoad
  39. } from '@dcloudio/uni-app'
  40. import {
  41. getDictInfoByType
  42. } from '@/api/dict/dict.js'
  43. import {
  44. getDayWorkItemList,
  45. saveDayWorkItem
  46. } from '@/api/business/dayWorkItem.js'
  47. import {
  48. getDeptList
  49. } from '@/api/dept/dept.js'
  50. import {
  51. store
  52. } from '@/store/index.js'
  53. import {
  54. timestampToTime
  55. } from '@/utils/common.js'
  56. const baseDialog = ref(null)
  57. const turnoverTypeChecked = ref({})
  58. const turnoverDoorChecked = ref({})
  59. const turnoverType = ref([])
  60. const turnoverArea = ref([])
  61. const curDayworkItem = ref({})
  62. const dayworkInfo = ref(null)
  63. const deptList = ref([]) // 工段列表
  64. // const emit = defineEmits('confirm') // 自定义调用父组件方法
  65. onLoad(() => {
  66. })
  67. function open(data) {
  68. dayworkInfo.value = data;
  69. baseDialog.value.open()
  70. init();
  71. }
  72. defineExpose({
  73. open
  74. })
  75. function close() {
  76. baseDialog.value.close()
  77. }
  78. function init() {
  79. getDictInfoByType('daywork_turnover_type').then(res => {
  80. turnoverType.value = res.data;
  81. getDictInfoByType('daywork_turnover_area').then(res => {
  82. turnoverArea.value = res.data;
  83. })
  84. })
  85. getDayWorkItemList({
  86. dayworkId: dayworkInfo.value.id,
  87. userId: store.userInfo.userId
  88. }).then(res => {
  89. console.log(res.rows[0])
  90. curDayworkItem.value = res.rows[0];
  91. })
  92. getDeptList({
  93. isWorkSection: 1
  94. }).then(res => {
  95. console.log(res.data)
  96. for (var i = 0; i < res.data.length; i++) {
  97. deptList.value[i] = {
  98. text: res.data[i].deptName,
  99. value: res.data[i].deptId,
  100. data: res.data[i]
  101. }
  102. }
  103. })
  104. }
  105. function selectTurnoverType(item) {
  106. turnoverTypeChecked.value = item;
  107. curDayworkItem.value.turnoverType = item.dictValue;
  108. }
  109. function selectTurnoverDoor(item) {
  110. turnoverDoorChecked.value = item;
  111. curDayworkItem.value.turnoverArea = item.dictValue;
  112. }
  113. function handleValidate(data) {
  114. console.log(data)
  115. if(data.turnoverType == '1'){
  116. return true;
  117. }else{
  118. if (data.turnoverType === "0" || data.turnoverArea === "" || data.deptId === "0") {
  119. return false;
  120. } else {
  121. return true;
  122. }
  123. }
  124. }
  125. function handleConfirm() {
  126. curDayworkItem.value.id = null;
  127. curDayworkItem.value.status = '4';
  128. curDayworkItem.value.startTime = timestampToTime(new Date());
  129. curDayworkItem.value.technologicalProcessId = dayworkInfo.value.technologicalProcessId;
  130. if (!store.tenantId) {
  131. curDayworkItem.value.tenantId = store.userInfo.tenantId;
  132. } else {
  133. curDayworkItem.value.tenantId = store.tenantId;
  134. }
  135. console.log(deptList.value)
  136. // 设置周转下一个车间名
  137. for (let i = 0; i < deptList.value.length; i++) {
  138. if (deptList.value[i].value == curDayworkItem.value.deptId) {
  139. curDayworkItem.value.deptName = deptList.value[i].text;
  140. }
  141. }
  142. console.log(curDayworkItem.value);
  143. if (!handleValidate(curDayworkItem.value)) {
  144. uni.showToast({
  145. icon: "error",
  146. title: '请选择完整信息',
  147. duration: 2000
  148. });
  149. } else {
  150. saveDayWorkItem(curDayworkItem.value).then(res => {
  151. if (res.code === 200) {
  152. uni.showToast({
  153. icon: 'success',
  154. title: '操作成功',
  155. duration: 2000
  156. });
  157. close();
  158. } else {
  159. uni.showToast({
  160. icon: 'error',
  161. title: '操作失败',
  162. duration: 2000
  163. });
  164. close();
  165. }
  166. })
  167. }
  168. // emit('confirm');
  169. uni.$emit('dayworkItemUpdate');
  170. }
  171. function handleChange() {
  172. console.log(curDayworkItem.value)
  173. }
  174. </script>
  175. <style lang="scss">
  176. .dialog-body {
  177. .list-container {
  178. width: 100%;
  179. .list-title {
  180. margin-top: 24rpx;
  181. .label {
  182. font-size: 32rpx;
  183. }
  184. }
  185. .btn {
  186. margin-top: 24rpx;
  187. .middle-btn {
  188. margin-right: 32rpx;
  189. align-items: center;
  190. justify-content: center;
  191. padding-left: 0;
  192. height: 80rpx;
  193. width: 220rpx;
  194. border-radius: 8rpx;
  195. background-color: #FFFFFF;
  196. border: 1px solid #999999;
  197. background-color: #FFFFFF;
  198. }
  199. .label {
  200. font-size: 24rpx;
  201. color: #000000;
  202. }
  203. .active {
  204. border-color: #1684fc;
  205. background-color: rgb(236, 245, 255);
  206. .label {
  207. color: #1684fc;
  208. }
  209. }
  210. }
  211. }
  212. .add-btn-container {
  213. margin-top: 32rpx;
  214. .btn {
  215. flex: 1;
  216. background-color: rgb(255, 121, 1);
  217. color: #FFFFFF;
  218. }
  219. }
  220. }
  221. </style>