dialog-turnoverApplicationAll.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  1. <template>
  2. <dialog-base ref="baseDialog" title="周转申请" @close="close">
  3. <view class="list-container">
  4. <view><text style="margin: 0 0 0 5rpx;">请选择周转类型</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"
  9. style="font-size: 30rpx;">{{item.dictLabel}}</text></view>
  10. </view>
  11. <view class="" style="margin: 0 20rpx 20rpx 0;width: 88%;">
  12. <uni-section title="请选择下序工段" title-font-size="32rpx" style="margin: 0 0 0 -16rpx;"
  13. v-if="curDayworkItem.turnoverType == '1'">
  14. <uni-data-select v-model="curDayworkItem.deptId" :localdata="insideDepts"
  15. @change="handleChangeInside" :clear="false"
  16. style="margin: 0 0 0 16rpx;outline: 2rpx solid #999999;border-radius: 10rpx;"></uni-data-select>
  17. </uni-section>
  18. <uni-section title="请选择下序工段" title-font-size="32rpx" style="margin: 0 0 0 -16rpx;"
  19. v-if="curDayworkItem.turnoverType == '2'">
  20. <uni-data-select v-model="curDayworkItem.deptId" :localdata="outsideDepts"
  21. @change="handleChangeOutside" :clear="false"
  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. <text style=" margin: 0 0 0 5rpx;">请选择您摆放位置</text>
  27. </view>
  28. <view class="turnArea uni-row" v-if="curDayworkItem.turnoverType == '1'">
  29. <view v-for="(item,index) in turnAreaList" class="btn">
  30. <view :class="{ 'middle-btn': true, 'active': handleTurnoverDoor(item) }"
  31. @click="selectTurnoverDoor(item)"><text class="label"
  32. style="font-size: 30rpx;">{{item.code}}</text></view>
  33. </view>
  34. </view>
  35. <view class="turnArea uni-row" v-if="curDayworkItem.turnoverType == '2'">
  36. <view v-for="(item,index) in turnoverArea" class="btn">
  37. <view :class="{ 'middle-btn': true, 'active': handleTurnoverDoor(item) }"
  38. @click="selectTurnoverDoorOutside(item)"><text class="label"
  39. style="font-size: 30rpx;">{{item.code}}</text></view>
  40. </view>
  41. </view>
  42. <view class="turnArea uni-row" v-if="curDayworkItem.turnoverType == '3'">
  43. <view v-for="(item,index) in turnoverArea" class="btn">
  44. <view :class="{ 'middle-btn': true, 'active': handleTurnoverDoor(item) }"
  45. @click="selectTurnoverOutsource(item)"><text class="label"
  46. style="font-size: 30rpx;">{{item.code}}</text></view>
  47. </view>
  48. </view>
  49. </view>
  50. <view class="add-btn-container uni-row">
  51. <button type="default" class="btn" @click="handleConfirm">确认</button>
  52. </view>
  53. </dialog-base>
  54. </template>
  55. <script setup>
  56. import {
  57. ref,
  58. getCurrentInstance
  59. } from 'vue'
  60. import {
  61. onLoad
  62. } from '@dcloudio/uni-app'
  63. import {
  64. getDictInfoByType
  65. } from '@/api/dict/dict.js'
  66. import {
  67. getTurnoverByWorkshop,
  68. getOutsourceTurnoverByWorkshop
  69. } from '@/api/business/workshop.js'
  70. import {
  71. getDayWorkItemList,
  72. saveDayWorkItem,
  73. // turnover,
  74. turnoverOutsource
  75. } from '@/api/business/dayWorkItem.js'
  76. import {
  77. getTurnoverListByDeptId,
  78. } from '@/api/business/turnover.js'
  79. import {
  80. getAllDeptList,
  81. turnoverAll,
  82. turnoverOutsourceAll
  83. } from '@/api/business/switchDept.js'
  84. import {
  85. store
  86. } from '@/store/index.js'
  87. import {
  88. timestampToTime
  89. } from '@/utils/common.js'
  90. const baseDialog = ref(null)
  91. const turnoverDoorChecked = ref([])
  92. const turnoverType = ref([])
  93. const outTurnArea = ref([])
  94. const turnoverArea = ref([])
  95. const selection = ref([])
  96. const curDayworkItem = ref({
  97. turnoverType: 1
  98. })
  99. const dayworkInfo = ref(null)
  100. const deptList = ref([]) // 工段列表
  101. const insideDepts = ref([]) // 车间内工段
  102. const outsideDepts = ref([]) // 车间外工段
  103. const turnAreaList = ref([]) // 周转区列表
  104. const emit = defineEmits(['reflushDaywork']) // 自定义调用父组件方法
  105. onLoad(() => {
  106. })
  107. function open(data) {
  108. resetPage();
  109. curDayworkItem.value = {
  110. trunoverType: 1,
  111. ids: data.map(e => e.id)
  112. }
  113. init();
  114. baseDialog.value.open();
  115. }
  116. defineExpose({
  117. open
  118. })
  119. function close() {
  120. // emit('close');
  121. // baseDialog.value.close()
  122. turnAreaList.value = [];
  123. // console.log('some')
  124. }
  125. function resetPage() {
  126. turnoverDoorChecked.value = []
  127. turnoverType.value = []
  128. turnoverArea.value = []
  129. selection.value = []
  130. curDayworkItem.value = {
  131. turnoverType: 1
  132. }
  133. deptList.value = []
  134. insideDepts.value = []
  135. outsideDepts.value = []
  136. turnAreaList.value = []
  137. }
  138. function init() {
  139. getDictInfoByType('daywork_turnover_type').then(res => {
  140. turnoverType.value = res.data;
  141. getTurnoverByWorkshop({
  142. deptId: store.curDeptDetails.deptId
  143. }).then(res => {
  144. turnoverArea.value = res.data;
  145. })
  146. })
  147. getOutsourceTurnoverByWorkshop({
  148. deptCode: '170000'
  149. }).then(response => {
  150. outTurnArea.value = response.data
  151. })
  152. getAllDeptList().then(res => {
  153. for (let i = 0; i < res.data.length; i++) {
  154. deptList.value = res.data;
  155. if (store.curDeptDetails.workshopId == res.data[i].workshopId) {
  156. insideDepts.value.push({
  157. text: res.data[i].deptName,
  158. value: res.data[i].deptId,
  159. data: res.data[i]
  160. })
  161. } else {
  162. outsideDepts.value.push({
  163. text: res.data[i].deptName,
  164. value: res.data[i].deptId,
  165. data: res.data[i]
  166. })
  167. }
  168. }
  169. })
  170. }
  171. function selectTurnoverType(item) {
  172. curDayworkItem.value.turnoverType = item.dictValue;
  173. selection.value = []
  174. }
  175. function selectTurnoverDoor(item) {
  176. // turnoverDoorChecked.value = item;
  177. // curDayworkItem.value.turnoverArea = item.dictValue;
  178. let index = selection.value.findIndex(selectedItem => selectedItem === item);
  179. if (index > -1) {
  180. selection.value.splice(index, 1);
  181. } else {
  182. selection.value.push(item);
  183. }
  184. }
  185. function selectTurnoverDoorOutside(item) {
  186. selection.value[0] = item;
  187. }
  188. function selectTurnoverOutsource(item) {
  189. selection.value[0] = item
  190. }
  191. function handleTurnoverDoor(item) {
  192. return selection.value.includes(item);
  193. }
  194. //校验车间内车间外
  195. function handleValidate(data) {
  196. console.log(data)
  197. if (data.turnoverArea == "" || data.deptId == null || selection.value.length == 0) {
  198. return false;
  199. } else {
  200. return true;
  201. }
  202. }
  203. //校验外协
  204. function handleValidateOutsource(data) {
  205. console.log(data)
  206. if (selection.value.length == 0) {
  207. return false;
  208. } else {
  209. return true;
  210. }
  211. }
  212. function handleConfirmOutsource() {
  213. if (!handleValidateOutsource(curDayworkItem.value)) {
  214. uni.showToast({
  215. icon: "none",
  216. title: '请选择完整信息'
  217. });
  218. } else {
  219. curDayworkItem.value.id = null;
  220. curDayworkItem.value.startTime = timestampToTime(new Date());
  221. curDayworkItem.value.endTime = timestampToTime(new Date());
  222. curDayworkItem.value.status = '4';
  223. if (!store.tenantId) {
  224. curDayworkItem.value.tenantId = store.userInfo.tenantId;
  225. } else {
  226. curDayworkItem.value.tenantId = store.tenantId;
  227. }
  228. //curDayworkItem.value.turnoverArea = "外协周转";
  229. curDayworkItem.value.turnoverArea = selection.value.map((item) => {
  230. return item.code;
  231. }).join('、')
  232. /**** 此处暂时为硬编码,170000为外协部门编码,根据编码查询信息 ***/
  233. curDayworkItem.value.deptCode = 170000;
  234. turnoverOutsourceAll(curDayworkItem.value).then(res => {
  235. if (res.code === 200) {
  236. uni.showToast({
  237. icon: 'success',
  238. title: '操作成功'
  239. });
  240. baseDialog.value.close()
  241. emit('reflushDaywork');
  242. } else {
  243. uni.showToast({
  244. icon: 'none',
  245. title: '操作失败'
  246. });
  247. }
  248. })
  249. }
  250. }
  251. function handleConfirm() {
  252. if (curDayworkItem.value.turnoverType == '3') {
  253. handleConfirmOutsource();
  254. } else {
  255. //console.log(dayworkInfo.value)
  256. curDayworkItem.value.id = null;
  257. curDayworkItem.value.status = curDayworkItem.value.turnoverType == '1' ? '7' : '4';
  258. curDayworkItem.value.startTime = timestampToTime(new Date());
  259. curDayworkItem.value.endTime = timestampToTime(new Date());
  260. if (!store.tenantId) {
  261. curDayworkItem.value.tenantId = store.userInfo.tenantId;
  262. } else {
  263. curDayworkItem.value.tenantId = store.tenantId;
  264. }
  265. // 过滤出周转位置的数组,并转换成字符串
  266. const newArray = selection.value.map((item) => {
  267. if (item.code) {
  268. return item.code;
  269. } else if (item.dictLabel) {
  270. return item.dictLabel;
  271. } else {
  272. return null;
  273. }
  274. })
  275. if (curDayworkItem.value.turnoverType == '1') {
  276. curDayworkItem.value.place = newArray.join('、');
  277. curDayworkItem.value.turnoverArea = "车间内周转看place字段";
  278. } else {
  279. curDayworkItem.value.turnoverArea = newArray.join('、');
  280. }
  281. // curDayworkItem.value.dayworkId = store.dayworkInfo.id;
  282. // 设置周转下一个车间名
  283. for (let i = 0; i < deptList.value.length; i++) {
  284. if (deptList.value[i].deptId == curDayworkItem.value.deptId) {
  285. curDayworkItem.value.deptName = deptList.value[i].deptName;
  286. }
  287. }
  288. // console.log(curDayworkItem.value);
  289. // console.log(dayworkInfo.value)
  290. if (!handleValidate(curDayworkItem.value)) {
  291. uni.showToast({
  292. icon: "none",
  293. title: '请选择完整信息'
  294. });
  295. } else {
  296. turnoverAll(curDayworkItem.value).then(res => {
  297. if (res.code === 200) {
  298. uni.showToast({
  299. icon: 'success',
  300. title: '操作成功'
  301. });
  302. baseDialog.value.close()
  303. emit('reflushDaywork');
  304. } else {
  305. uni.showToast({
  306. icon: 'none',
  307. title: '操作失败'
  308. });
  309. }
  310. })
  311. }
  312. // emit('confirm');
  313. }
  314. }
  315. function handleChangeInside() {
  316. turnAreaList.value = [];
  317. selection.value = []
  318. getTurnoverListByDeptId({
  319. deptId: curDayworkItem.value.deptId,
  320. }).then(res => {
  321. for (var i = 0; i < res.data.length; i++) {
  322. if (res.data[i].status != 1) {
  323. turnAreaList.value[i] = res.data[i];
  324. }
  325. }
  326. })
  327. }
  328. function handleChangeOutside() {
  329. //console.log(curDayworkItem.value.deptId)
  330. }
  331. </script>
  332. <style lang="scss">
  333. .dialog-body {
  334. .list-container {
  335. width: 100%;
  336. .list-title {
  337. margin-top: 24rpx;
  338. .label {
  339. font-size: 32rpx;
  340. }
  341. }
  342. .turnArea {
  343. flex-wrap: wrap;
  344. height: auto;
  345. max-height: 200rpx;
  346. overflow: auto;
  347. }
  348. .btn {
  349. margin-top: 24rpx;
  350. .middle-btn {
  351. margin-right: 32rpx;
  352. align-items: center;
  353. justify-content: center;
  354. padding-left: 0;
  355. height: 80rpx;
  356. width: 220rpx;
  357. border-radius: 8rpx;
  358. background-color: #FFFFFF;
  359. border: 1px solid #999999;
  360. background-color: #FFFFFF;
  361. }
  362. .label {
  363. font-size: 24rpx;
  364. color: #000000;
  365. }
  366. .active {
  367. border-color: #1684fc;
  368. background-color: rgb(236, 245, 255);
  369. .label {
  370. color: #1684fc;
  371. }
  372. }
  373. }
  374. }
  375. .add-btn-container {
  376. margin-top: 32rpx;
  377. .btn {
  378. flex: 1;
  379. background-color: rgb(255, 121, 1);
  380. color: #FFFFFF;
  381. }
  382. }
  383. }
  384. </style>