dialog-turnoverApplicationAll.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. <template>
  2. <dialog-base ref="baseDialog" title="周转申请">
  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. dayworkInfo.value = data;
  110. init();
  111. baseDialog.value.open();
  112. }
  113. defineExpose({
  114. open
  115. })
  116. function close() {
  117. baseDialog.value.close()
  118. turnAreaList.value = [];
  119. }
  120. function resetPage() {
  121. turnoverDoorChecked.value = []
  122. turnoverType.value = []
  123. turnoverArea.value = []
  124. selection.value = []
  125. curDayworkItem.value = {
  126. turnoverType: 1
  127. }
  128. deptList.value = []
  129. insideDepts.value = []
  130. outsideDepts.value = []
  131. turnAreaList.value = []
  132. }
  133. function init() {
  134. getDictInfoByType('daywork_turnover_type').then(res => {
  135. turnoverType.value = res.data;
  136. getTurnoverByWorkshop({
  137. deptId: store.curDeptDetails.deptId
  138. }).then(res => {
  139. turnoverArea.value = res.data;
  140. })
  141. })
  142. getOutsourceTurnoverByWorkshop({
  143. deptCode: '170000'
  144. }).then(response => {
  145. outTurnArea.value = response.data
  146. })
  147. getAllDeptList().then(res => {
  148. for (let i = 0; i < res.data.length; i++) {
  149. deptList.value = res.data;
  150. if (store.curDeptDetails.workshopId == res.data[i].workshopId) {
  151. insideDepts.value.push({
  152. text: res.data[i].deptName,
  153. value: res.data[i].deptId,
  154. data: res.data[i]
  155. })
  156. } else {
  157. outsideDepts.value.push({
  158. text: res.data[i].deptName,
  159. value: res.data[i].deptId,
  160. data: res.data[i]
  161. })
  162. }
  163. }
  164. })
  165. }
  166. function selectTurnoverType(item) {
  167. curDayworkItem.value.turnoverType = item.dictValue;
  168. selection.value = []
  169. }
  170. function selectTurnoverDoor(item) {
  171. // turnoverDoorChecked.value = item;
  172. // curDayworkItem.value.turnoverArea = item.dictValue;
  173. let index = selection.value.findIndex(selectedItem => selectedItem === item);
  174. if (index > -1) {
  175. selection.value.splice(index, 1);
  176. } else {
  177. selection.value.push(item);
  178. }
  179. }
  180. function selectTurnoverDoorOutside(item) {
  181. selection.value[0] = item;
  182. }
  183. function selectTurnoverOutsource(item) {
  184. selection.value[0] = item
  185. }
  186. function handleTurnoverDoor(item) {
  187. return selection.value.includes(item);
  188. }
  189. //校验车间内车间外
  190. function handleValidate(data) {
  191. console.log(data)
  192. if (data.turnoverArea == "" || data.deptId == null || selection.value.length == 0) {
  193. return false;
  194. } else {
  195. return true;
  196. }
  197. }
  198. //校验外协
  199. function handleValidateOutsource(data) {
  200. console.log(data)
  201. if (selection.value.length == 0) {
  202. return false;
  203. } else {
  204. return true;
  205. }
  206. }
  207. function handleConfirmOutsource() {
  208. if (!handleValidateOutsource(curDayworkItem.value)) {
  209. uni.showToast({
  210. icon: "none",
  211. title: '请选择完整信息'
  212. });
  213. } else {
  214. curDayworkItem.value.id = null;
  215. curDayworkItem.value.startTime = timestampToTime(new Date());
  216. curDayworkItem.value.endTime = timestampToTime(new Date());
  217. curDayworkItem.value.technologicalProcessId = dayworkInfo.value.technologicalProcessId;
  218. curDayworkItem.value.dayworkId = dayworkInfo.value.id;
  219. curDayworkItem.value.productionPlanDetailId = dayworkInfo.value.productionPlanDetailId;
  220. curDayworkItem.value.status = '4';
  221. if (!store.tenantId) {
  222. curDayworkItem.value.tenantId = store.userInfo.tenantId;
  223. } else {
  224. curDayworkItem.value.tenantId = store.tenantId;
  225. }
  226. //curDayworkItem.value.turnoverArea = "外协周转";
  227. curDayworkItem.value.turnoverArea = selection.value.map((item) => {
  228. return item.code;
  229. }).join('、')
  230. /**** 此处暂时为硬编码,170000为外协部门编码,根据编码查询信息 ***/
  231. curDayworkItem.value.deptCode = 170000;
  232. close();
  233. turnoverOutsource(curDayworkItem.value).then(res => {
  234. if (res.code === 200) {
  235. uni.showToast({
  236. icon: 'success',
  237. title: '操作成功'
  238. });
  239. emit('reflushDaywork');
  240. } else {
  241. uni.showToast({
  242. icon: 'none',
  243. title: '操作失败'
  244. });
  245. }
  246. })
  247. }
  248. }
  249. function handleConfirm() {
  250. if (curDayworkItem.value.turnoverType == '3') {
  251. handleConfirmOutsource();
  252. } else {
  253. //console.log(dayworkInfo.value)
  254. curDayworkItem.value.id = null;
  255. curDayworkItem.value.status = curDayworkItem.value.turnoverType == '1' ? '7' : '4';
  256. curDayworkItem.value.startTime = timestampToTime(new Date());
  257. curDayworkItem.value.endTime = timestampToTime(new Date());
  258. curDayworkItem.value.technologicalProcessId = dayworkInfo.value.technologicalProcessId;
  259. curDayworkItem.value.dayworkId = dayworkInfo.value.id;
  260. curDayworkItem.value.productionPlanDetailId = dayworkInfo.value.productionPlanDetailId;
  261. if (!store.tenantId) {
  262. curDayworkItem.value.tenantId = store.userInfo.tenantId;
  263. } else {
  264. curDayworkItem.value.tenantId = store.tenantId;
  265. }
  266. // 过滤出周转位置的数组,并转换成字符串
  267. const newArray = selection.value.map((item) => {
  268. if (item.code) {
  269. return item.code;
  270. } else if (item.dictLabel) {
  271. return item.dictLabel;
  272. } else {
  273. return null;
  274. }
  275. })
  276. if (curDayworkItem.value.turnoverType == '1') {
  277. curDayworkItem.value.place = newArray.join('、');
  278. curDayworkItem.value.turnoverArea = "车间内周转看place字段";
  279. } else {
  280. curDayworkItem.value.turnoverArea = newArray.join('、');
  281. }
  282. // curDayworkItem.value.dayworkId = store.dayworkInfo.id;
  283. // 设置周转下一个车间名
  284. for (let i = 0; i < deptList.value.length; i++) {
  285. if (deptList.value[i].deptId == curDayworkItem.value.deptId) {
  286. curDayworkItem.value.deptName = deptList.value[i].deptName;
  287. }
  288. }
  289. // console.log(curDayworkItem.value);
  290. // console.log(dayworkInfo.value)
  291. if (!handleValidate(curDayworkItem.value)) {
  292. uni.showToast({
  293. icon: "none",
  294. title: '请选择完整信息'
  295. });
  296. } else {
  297. close();
  298. turnoverAll(curDayworkItem.value).then(res => {
  299. if (res.code === 200) {
  300. uni.showToast({
  301. icon: 'success',
  302. title: '操作成功'
  303. });
  304. emit('reflushDaywork');
  305. } else {
  306. uni.showToast({
  307. icon: 'none',
  308. title: '操作失败'
  309. });
  310. }
  311. })
  312. }
  313. // emit('confirm');
  314. }
  315. }
  316. function handleChangeInside() {
  317. turnAreaList.value = [];
  318. selection.value = []
  319. getTurnoverListByDeptId({
  320. deptId: curDayworkItem.value.deptId,
  321. }).then(res => {
  322. for (var i = 0; i < res.data.length; i++) {
  323. if (res.data[i].status != 1) {
  324. turnAreaList.value[i] = res.data[i];
  325. }
  326. }
  327. })
  328. }
  329. function handleChangeOutside() {
  330. //console.log(curDayworkItem.value.deptId)
  331. }
  332. </script>
  333. <style lang="scss">
  334. .dialog-body {
  335. .list-container {
  336. width: 100%;
  337. .list-title {
  338. margin-top: 24rpx;
  339. .label {
  340. font-size: 32rpx;
  341. }
  342. }
  343. .turnArea {
  344. flex-wrap: wrap;
  345. height: auto;
  346. max-height: 200rpx;
  347. overflow: auto;
  348. }
  349. .btn {
  350. margin-top: 24rpx;
  351. .middle-btn {
  352. margin-right: 32rpx;
  353. align-items: center;
  354. justify-content: center;
  355. padding-left: 0;
  356. height: 80rpx;
  357. width: 220rpx;
  358. border-radius: 8rpx;
  359. background-color: #FFFFFF;
  360. border: 1px solid #999999;
  361. background-color: #FFFFFF;
  362. }
  363. .label {
  364. font-size: 24rpx;
  365. color: #000000;
  366. }
  367. .active {
  368. border-color: #1684fc;
  369. background-color: rgb(236, 245, 255);
  370. .label {
  371. color: #1684fc;
  372. }
  373. }
  374. }
  375. }
  376. .add-btn-container {
  377. margin-top: 32rpx;
  378. .btn {
  379. flex: 1;
  380. background-color: rgb(255, 121, 1);
  381. color: #FFFFFF;
  382. }
  383. }
  384. }
  385. </style>