123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316 |
- <template>
- <dialog-base ref="baseDialog" title="周转申请">
- <view class="list-container">
- <view class="list-title"><text class="label">请选择周转类型</text></view>
- <view class="btn uni-row">
- <view v-for="(item,index) in turnoverType"
- :class="{ 'middle-btn': true, 'active': item.dictValue == curDayworkItem.turnoverType }"
- @click="selectTurnoverType(item)"><text class="label">{{item.dictLabel}}</text></view>
- </view>
- <view class="" style="margin: 0 20rpx 20rpx 0;width: 88%;">
- <uni-section title="请选择下序工段" title-font-size="32rpx" style="margin: 0 0 0 -16rpx;">
- <uni-data-select v-model="curDayworkItem.deptId" :localdata="deptList" @change="handleChange"
- :clear="false"
- style="margin: 0 0 0 16rpx;outline: 2rpx solid #999999;border-radius: 10rpx;"></uni-data-select>
- </uni-section>
- </view>
- <view class="list-title">
- <text class="label">请选择您摆放位置</text>
- </view>
- <view class="turnArea uni-row" v-if="curDayworkItem.turnoverType == '1'">
- <view v-for="(item,index) in turnAreaList" class="btn">
- <view :class="{ 'middle-btn': true, 'active': handleTurnoverDoor(item) }"
- @click="selectTurnoverDoor(item)"><text class="label">{{item.code}}</text></view>
- </view>
- </view>
- <view class="turnArea uni-row" v-if="curDayworkItem.turnoverType == '2'">
- <view v-for="(item,index) in turnoverArea" class="btn">
- <view :class="{ 'middle-btn': true, 'active': handleTurnoverDoor(item) }"
- @click="selectTurnoverDoor(item)"><text class="label">{{item.dictLabel}}</text></view>
- </view>
- </view>
- </view>
- <view class="add-btn-container uni-row">
- <button type="default" class="btn" @click="handleConfirm">确认</button>
- </view>
- </dialog-base>
- </template>
- <script setup>
- import {
- ref,
- getCurrentInstance
- } from 'vue'
- import {
- onLoad
- } from '@dcloudio/uni-app'
- import {
- getDictInfoByType
- } from '@/api/dict/dict.js'
- import {
- getDayWorkItemList,
- saveDayWorkItem
- } from '@/api/business/dayWorkItem.js'
- import {
- getDeptList
- } from '@/api/dept/dept.js'
- import {
- getTurnoverListByDeptId
- } from '@/api/business/turnover.js'
- import {
- store
- } from '@/store/index.js'
- import {
- timestampToTime
- } from '@/utils/common.js'
- const baseDialog = ref(null)
- const turnoverDoorChecked = ref([])
- const turnoverType = ref([])
- const turnoverArea = ref([])
- const selection = ref([])
- const curDayworkItem = ref({
- turnoverType: 1
- })
- const dayworkInfo = ref(null)
- const deptList = ref([]) // 工段列表
- const turnAreaList = ref([]) // 周转区列表
- // const emit = defineEmits('confirm') // 自定义调用父组件方法
- onLoad(() => {
- })
- function open(data) {
- resetPage();
- dayworkInfo.value = data;
- console.log(dayworkInfo.value)
- baseDialog.value.open();
- init();
- }
- defineExpose({
- open
- })
- function close() {
- baseDialog.value.close()
- turnAreaList.value = [];
- }
- function resetPage() {
- turnoverDoorChecked.value = []
- turnoverType.value = []
- turnoverArea.value = []
- selection.value = []
- curDayworkItem.value = {
- turnoverType: 1
- }
- deptList.value = []
- turnAreaList.value = []
- }
- function init() {
- getDictInfoByType('daywork_turnover_type').then(res => {
- turnoverType.value = res.data;
- getDictInfoByType('workshop_turnover_area').then(res => {
- turnoverArea.value = res.data;
- })
- })
- getDayWorkItemList({
- dayworkId: dayworkInfo.value.id,
- userId: store.userInfo.userId
- }).then(res => {
- console.log(res.rows[0])
- curDayworkItem.value = {
- ...res.rows[0],
- turnoverType: 1
- };
- })
- getDeptList({
- isWorkSection: 1,
- tenantId: store.tenantId
- }).then(res => {
- console.log(res.data)
- for (let i = 0; i < res.data.length; i++) {
- deptList.value[i] = {
- text: res.data[i].deptName,
- value: res.data[i].deptId,
- data: res.data[i]
- }
- }
- })
- }
- function selectTurnoverType(item) {
- curDayworkItem.value.turnoverType = item.dictValue;
- selection.value = []
- }
- function selectTurnoverDoor(item) {
- // turnoverDoorChecked.value = item;
- // curDayworkItem.value.turnoverArea = item.dictValue;
- let index = selection.value.findIndex(selectedItem => selectedItem === item);
- if (index > -1) {
- selection.value.splice(index, 1);
- } else {
- selection.value.push(item);
- }
- }
- function handleTurnoverDoor(item) {
- return selection.value.includes(item);
- }
- function handleValidate(data) {
- console.log(data)
- if (data.turnoverArea == "" || data.deptId == null || selection.value.length == 0) {
- return false;
- } else {
- return true;
- }
- }
- function handleConfirm() {
- curDayworkItem.value.id = null;
- curDayworkItem.value.status = curDayworkItem.value.turnoverType == '1' ? '7' : '4';
- curDayworkItem.value.startTime = timestampToTime(new Date());
- curDayworkItem.value.endTime = timestampToTime(new Date());
- curDayworkItem.value.technologicalProcessId = dayworkInfo.value.technologicalProcessId;
- curDayworkItem.value.dayworkId = dayworkInfo.value.id;
- curDayworkItem.value.productionPlanDetailId = dayworkInfo.value.productionPlanDetailId;
- if (!store.tenantId) {
- curDayworkItem.value.tenantId = store.userInfo.tenantId;
- } else {
- curDayworkItem.value.tenantId = store.tenantId;
- }
- // 过滤出周转位置的数组,并转换成字符串
- const newArray = selection.value.map((item) => {
- if (item.code) {
- return item.code;
- } else if (item.dictLabel) {
- return item.dictLabel;
- } else {
- return null;
- }
- })
- if(curDayworkItem.value.turnoverType == '1'){
- curDayworkItem.value.place = newArray.join('、');
- curDayworkItem.value.turnoverArea = "车间内周转看place字段";
- }else{
- curDayworkItem.value.turnoverArea = newArray.join('、');
- }
- // curDayworkItem.value.dayworkId = store.dayworkInfo.id;
- // 设置周转下一个车间名
- for (let i = 0; i < deptList.value.length; i++) {
- if (deptList.value[i].value == curDayworkItem.value.deptId) {
- curDayworkItem.value.deptName = deptList.value[i].text;
- }
- }
- console.log(curDayworkItem.value);
- console.log(dayworkInfo.value)
- if (!handleValidate(curDayworkItem.value)) {
- uni.showToast({
- icon: "error",
- title: '请选择完整信息'
- });
- } else {
- close();
- saveDayWorkItem(curDayworkItem.value).then(res => {
- if (res.code === 200) {
- uni.showToast({
- icon: 'success',
- title: '操作成功'
- });
- uni.$emit('bathReportingReflush');
- } else {
- uni.showToast({
- icon: 'error',
- title: '操作失败'
- });
- }
- })
- }
- // emit('confirm');
- }
- function handleChange() {
- turnAreaList.value = [];
- selection.value = []
- getTurnoverListByDeptId({
- deptId: curDayworkItem.value.deptId,
- }).then(res => {
- for (var i = 0; i < res.data.length; i++) {
- if (res.data[i].status == 0) {
- turnAreaList.value[i] = res.data[i];
- }
- }
- })
- }
- </script>
- <style lang="scss">
- .dialog-body {
- .list-container {
- width: 100%;
- .list-title {
- margin-top: 24rpx;
- .label {
- font-size: 32rpx;
- }
- }
- .turnArea {
- flex-wrap: wrap;
- height: auto;
- max-height: 200rpx;
- overflow: auto;
- }
- .btn {
- margin-top: 24rpx;
- .middle-btn {
- margin-right: 32rpx;
- align-items: center;
- justify-content: center;
- padding-left: 0;
- height: 80rpx;
- width: 220rpx;
- border-radius: 8rpx;
- background-color: #FFFFFF;
- border: 1px solid #999999;
- background-color: #FFFFFF;
- }
- .label {
- font-size: 24rpx;
- color: #000000;
- }
- .active {
- border-color: #1684fc;
- background-color: rgb(236, 245, 255);
- .label {
- color: #1684fc;
- }
- }
- }
- }
- .add-btn-container {
- margin-top: 32rpx;
- .btn {
- flex: 1;
- background-color: rgb(255, 121, 1);
- color: #FFFFFF;
- }
- }
- }
- </style>
|