Browse Source

班组失去焦点校验

hella_online_20240829
zhang_li 4 months ago
parent
commit
303cbbc58f
  1. 267
      src/views/wms/basicDataManage/orderManage/team/teamForm.vue

267
src/views/wms/basicDataManage/orderManage/team/teamForm.vue

@ -35,7 +35,12 @@
<el-col :span="12"> <el-col :span="12">
<el-form-item label="负责人" prop="teamMonitorName"> <el-form-item label="负责人" prop="teamMonitorName">
<div class="input-with-button"> <div class="input-with-button">
<el-input v-model="formData.teamMonitorName" placeholder="请选择负责人" :style="{ width: '35%' }"/> <el-input
v-model="formData.teamMonitorName"
placeholder="请选择负责人"
:style="{ width: '35%' }"
@blur="addUserBlur('teamMonitorName', formData.teamMonitorName)"
/>
<el-button :icon="Search" @click="addMonitor" /> <el-button :icon="Search" @click="addMonitor" />
</div> </div>
</el-form-item> </el-form-item>
@ -45,7 +50,12 @@
<el-col :span="12"> <el-col :span="12">
<el-form-item label="车间代码" prop="workshopCode"> <el-form-item label="车间代码" prop="workshopCode">
<div class="input-with-button"> <div class="input-with-button">
<el-input v-model="formData.workshopCode" placeholder="请选择车间代码" :style="{ width: '35%' }"/> <el-input
v-model="formData.workshopCode"
placeholder="请选择车间代码"
:style="{ width: '35%' }"
@blur="addWorkshopCodeBlur('workshopCode', formData.workshopCode)"
/>
<el-button :icon="Search" @click="addWorkShop" /> <el-button :icon="Search" @click="addWorkShop" />
</div> </div>
</el-form-item> </el-form-item>
@ -53,7 +63,12 @@
<el-col :span="12"> <el-col :span="12">
<el-form-item label="产线代码" prop="productionLineCode"> <el-form-item label="产线代码" prop="productionLineCode">
<div class="input-with-button"> <div class="input-with-button">
<el-input v-model="formData.productionLineCode" placeholder="请选择产线代码" :style="{ width: '35%' }"/> <el-input
v-model="formData.productionLineCode"
placeholder="请选择产线代码"
:style="{ width: '35%' }"
@blur="addProductionLineBlur('productionLineCode', formData.productionLineCode)"
/>
<el-button :icon="Search" @click="addProductionLine" /> <el-button :icon="Search" @click="addProductionLine" />
</div> </div>
</el-form-item> </el-form-item>
@ -68,7 +83,7 @@
placeholder="请选择生效时间" placeholder="请选择生效时间"
format="YYYY-MM-DD HH:mm:ss" format="YYYY-MM-DD HH:mm:ss"
value-format="x" value-format="x"
style="width: 100%;" style="width: 100%"
/> />
</el-form-item> </el-form-item>
</el-col> </el-col>
@ -80,7 +95,7 @@
placeholder="请选择失效时间" placeholder="请选择失效时间"
format="YYYY-MM-DD HH:mm:ss" format="YYYY-MM-DD HH:mm:ss"
value-format="x" value-format="x"
style="width: 100%;" style="width: 100%"
/> />
</el-form-item> </el-form-item>
</el-col> </el-col>
@ -89,8 +104,13 @@
<el-col :span="24"> <el-col :span="24">
<el-form-item label="班组成员"> <el-form-item label="班组成员">
<div class="tag-container flex gap-2"> <div class="tag-container flex gap-2">
<el-tag v-for="ent in tags" :key="ent.username" closable :disable-transitions="false" <el-tag
@close="handleClose(ent.username)"> v-for="ent in tags"
:key="ent.username"
closable
:disable-transitions="false"
@close="handleClose(ent.username)"
>
{{ ent.nickname }} {{ ent.nickname }}
</el-tag> </el-tag>
<el-input <el-input
@ -128,22 +148,22 @@
<!--添加班组人员弹窗--> <!--添加班组人员弹窗-->
<SearchTable ref="searchTableRef" @searchTableSuccess="searchTableSuccess" /> <SearchTable ref="searchTableRef" @searchTableSuccess="searchTableSuccess" />
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { DICT_TYPE, getStrDictOptions } from '@/utils/dict' import { DICT_TYPE, getStrDictOptions } from '@/utils/dict'
import * as TeamApi from '@/api/wms/team' import * as TeamApi from '@/api/wms/team'
import request from "@/config/axios"; import request from '@/config/axios'
import { SearchTable } from '@/components/SearchTable' import { SearchTable } from '@/components/SearchTable'
import {searchUser} from "@/views/wms/basicDataManage/orderManage/team/team.data"; import { searchUser } from '@/views/wms/basicDataManage/orderManage/team/team.data'
import * as UserApi from "@/api/system/user"; import * as UserApi from '@/api/system/user'
import {validateYS} from "@/utils/validator"; import { validateYS } from '@/utils/validator'
import { Search } from '@element-plus/icons-vue' import { Search } from '@element-plus/icons-vue'
import * as WorkshopApi from "@/api/wms/workshop"; import * as WorkshopApi from '@/api/wms/workshop'
import {Workshop} from "@/views/wms/basicDataManage/factoryModeling/workshop/workshop.data"; import { Workshop } from '@/views/wms/basicDataManage/factoryModeling/workshop/workshop.data'
import * as ProductionlineApi from '@/api/wms/productionline' import * as ProductionlineApi from '@/api/wms/productionline'
import { Productionline } from "@/views/wms/basicDataManage/factoryModeling/productionline/productionline.data"; import { Productionline } from '@/views/wms/basicDataManage/factoryModeling/productionline/productionline.data'
import {ElInput} from "element-plus"; import { ElInput } from 'element-plus'
import { FormBlur } from '@/api/wms/business/inputBlur'
defineOptions({ name: 'TeamForm' }) defineOptions({ name: 'TeamForm' })
@ -188,32 +208,30 @@ const formRules = reactive({
{ required: true, message: '班组名称不能为空', trigger: 'blur' }, { required: true, message: '班组名称不能为空', trigger: 'blur' },
{ max: 50, message: '不得超过50个字符', trigger: 'blur' } { max: 50, message: '不得超过50个字符', trigger: 'blur' }
], ],
remark: [ remark: [{ max: 50, message: '不得超过50个字符', trigger: 'blur' }],
{ max: 50, message: '不得超过50个字符', trigger: 'blur' }
],
teamGroup: [{ required: true, message: '班组类别不能为空', trigger: 'change' }], teamGroup: [{ required: true, message: '班组类别不能为空', trigger: 'change' }],
workshopCode: [{ required: true, message: '请选择车间代码', trigger: 'blur' },], workshopCode: [{ required: true, message: '请选择车间代码', trigger: 'blur' }],
productionLineCode: [{ required: true, message: '请选择产线代码', trigger: 'blur' },], productionLineCode: [{ required: true, message: '请选择产线代码', trigger: 'blur' }],
teamMonitorName: [{ required: true, message: '请选择负责人', trigger: 'blur' },], teamMonitorName: [{ required: true, message: '请选择负责人', trigger: 'blur' }]
}) })
const basicFormRef = ref() // Ref const basicFormRef = ref() // Ref
const handleClose = (username: string) => { const handleClose = (username: string) => {
const index = tags.value.findIndex(tag => tag.username === username); const index = tags.value.findIndex((tag) => tag.username === username)
if (index !== -1) { if (index !== -1) {
tags.value.splice(index, 1); tags.value.splice(index, 1)
} }
} }
/** 弹窗相关参数 */ /** 弹窗相关参数 */
const searchTableRef = ref(); const searchTableRef = ref()
const _searchTableTitle = ref(); const _searchTableTitle = ref()
const _searchTableAllSchemas = ref(); const _searchTableAllSchemas = ref()
const _searchTablePage = ref(); const _searchTablePage = ref()
const _formField = ref(); const _formField = ref()
const _searchField = ref(); const _searchField = ref()
const _multiple = ref(); const _multiple = ref()
const _type = ref(); const _type = ref()
const _row = ref(); const _row = ref()
const _searchCondition = ref({}) const _searchCondition = ref({})
const addMonitor = () => { const addMonitor = () => {
@ -229,7 +247,7 @@ const addUserCommon = (multiple,field) => {
_searchCondition.value = {} _searchCondition.value = {}
const filters: any[] = [] const filters: any[] = []
filters.push({ filters.push({
action: "==", action: '==',
column: 'userType', column: 'userType',
value: 'WORKER' value: 'WORKER'
}) })
@ -244,13 +262,40 @@ const addUserCommon = (multiple,field) => {
_searchTableAllSchemas.value = searchUser.allSchemas _searchTableAllSchemas.value = searchUser.allSchemas
openCommon() openCommon()
} }
//
const addUserBlur = async (field, e) => {
_searchCondition.value = {}
const filters: any[] = []
filters.push(
{
action: '==',
column: 'userType',
value: 'WORKER'
},
{
action: '==',
column: 'username',
value: e
}
)
//
_searchCondition.value.isSearch = true
_searchCondition.value.filters = filters
_searchTableTitle.value = '选择人员'
_multiple.value = false
_formField.value = field
_searchField.value = field
_searchTablePage.value = UserApi.getUserPage
_searchTableAllSchemas.value = searchUser.allSchemas
getBlurFun(field, e)
}
/** 选择车间弹窗 */ /** 选择车间弹窗 */
const addWorkShop = () => { const addWorkShop = () => {
_searchCondition.value = {} _searchCondition.value = {}
const filters: any[] = [] const filters: any[] = []
filters.push({ filters.push({
action: "==", action: '==',
column: 'available', column: 'available',
value: 'TRUE' value: 'TRUE'
}) })
@ -265,23 +310,84 @@ const addWorkShop = () => {
_searchTableAllSchemas.value = Workshop.allSchemas _searchTableAllSchemas.value = Workshop.allSchemas
openCommon() openCommon()
} }
//
const addWorkshopCodeBlur = (field, e) => {
_searchCondition.value = {}
const filters: any[] = []
filters.push({
action: '==',
column: 'available',
value: 'TRUE'
},{
action: '==',
column: 'code',
value: e
})
//
_searchCondition.value.isSearch = true
_searchCondition.value.filters = filters
_searchTableTitle.value = '选择车间'
_multiple.value = false
_formField.value = 'workshop'
_searchField.value = 'workshop'
_searchTablePage.value = WorkshopApi.getWorkshopPage
_searchTableAllSchemas.value = Workshop.allSchemas
formData.value.productionLineCode = ''
getBlurFun(field, e)
}
/** 选择产线弹窗 */ /** 选择产线弹窗 */
const addProductionLine = () => { const addProductionLine = () => {
if (formData.value.workshopCode == '' || formData.value.workshopCode == null) { if (formData.value.workshopCode == '' || formData.value.workshopCode == null) {
message.warning('请先选择车间代码'); message.warning('请先选择车间代码')
return return
} }
_searchCondition.value = {} _searchCondition.value = {}
const filters: any[] = [] const filters: any[] = []
filters.push({ filters.push(
action: "==", {
action: '==',
column: 'available',
value: 'TRUE'
},
{
action: '==',
column: 'workshopCode',
value: formData.value.workshopCode
}
)
//
_searchCondition.value.isSearch = true
_searchCondition.value.filters = filters
_searchTableTitle.value = '选择产线'
_multiple.value = false
_formField.value = 'productionLine'
_searchField.value = 'productionLine'
_searchTablePage.value = ProductionlineApi.getProductionlinePage
_searchTableAllSchemas.value = Productionline.allSchemas
openCommon()
}
// 线
const addProductionLineBlur = (field, e) => {
_searchCondition.value = {}
if (formData.value.workshopCode == '' || formData.value.workshopCode == null) {
message.warning('请先选择车间代码')
return
}
_searchCondition.value = {}
const filters: any[] = []
filters.push(
{
action: '==',
column: 'available', column: 'available',
value: 'TRUE' value: 'TRUE'
}, { }, {
action: "==", action: '==',
column: 'workshopCode', column: 'workshopCode',
value: formData.value.workshopCode value: formData.value.workshopCode
},{
action: '==',
column: 'code',
value: e
}) })
// //
_searchCondition.value.isSearch = true _searchCondition.value.isSearch = true
@ -292,9 +398,8 @@ const addProductionLine = () => {
_searchField.value = 'productionLine' _searchField.value = 'productionLine'
_searchTablePage.value = ProductionlineApi.getProductionlinePage _searchTablePage.value = ProductionlineApi.getProductionlinePage
_searchTableAllSchemas.value = Productionline.allSchemas _searchTableAllSchemas.value = Productionline.allSchemas
openCommon() getBlurFun(field, e)
} }
/** 弹窗选择之后 回调函数 */ /** 弹窗选择之后 回调函数 */
const searchTableSuccess = (formField, searchField, val, formRef, type, row) => { const searchTableSuccess = (formField, searchField, val, formRef, type, row) => {
nextTick?.(() => { nextTick?.(() => {
@ -305,27 +410,24 @@ const searchTableSuccess = (formField, searchField, val, formRef, type, row ) =>
} }
formData.value.workshopCode = val[0].code formData.value.workshopCode = val[0].code
formData.value.workshopName = val[0].name formData.value.workshopName = val[0].name
} } else if (formField === 'productionLine') {
else if (formField === 'productionLine'){
formData.value.productionLineCode = val[0].code formData.value.productionLineCode = val[0].code
formData.value.productionLineName = val[0].name formData.value.productionLineName = val[0].name
} } else if (formField === 'monitor') {
else if (formField === 'monitor'){
formData.value.teamMonitorCode = val[0].username formData.value.teamMonitorCode = val[0].username
formData.value.teamMonitorName = val[0].nickname formData.value.teamMonitorName = val[0].nickname
} } else {
else { val.forEach((item) => {
val.forEach(item => { const isExist = tags.value.some((tag) => tag.username === item.username)
const isExist = tags.value.some(tag => tag.username === item.username);
if (!isExist) { if (!isExist) {
const newUser = {}; const newUser = {}
if (formField === 'username') { if (formField === 'username') {
newUser['username'] = item.username; newUser['username'] = item.username
newUser['nickname'] = item.nickname; newUser['nickname'] = item.nickname
} }
tags.value.push(newUser); tags.value.push(newUser)
} }
}); })
} }
}) })
} }
@ -343,6 +445,46 @@ const openCommon = () => {
_searchCondition.value _searchCondition.value
) )
} }
//
const getBlurFun = async (field, val) => {
let obj = {
by: 'ASC',
pageNo: 1,
pageSize: 20
}
const params = {
isSearch: _searchCondition.value.isSearch,
filters: _searchCondition.value.filters,
...obj
}
if (!_multiple.value && val.indexOf(',') > -1) {
message.alert('该输入框只能输入一条数据')
formData.value[field] = ''
return
}
await _searchTablePage.value(params).then((res) => {
let arr1 = val.split(',')
let list = ref([])
list.value = res?.list?.length > 0 ? res.list.slice(0, 1) : []
if (list.value?.length == 0) {
message.alert('暂无数据')
formData.value[field] = ''
return
}
if (arr1.length != list.value.length) {
let arr2 = list.value.map((item) => item[field])
let str = [
...arr1.filter((item) => !arr2.includes(item)),
...arr2.filter((item) => !arr1.includes(item))
].join(',')
message.alert('代码' + str + '没有找到对应数据')
formData.value[field] = ''
return
}
// callback(list.value)
})
}
/** 初始化弹窗 */ /** 初始化弹窗 */
const open = async (type: string, row?: object) => { const open = async (type: string, row?: object) => {
dialogVisible.value = true dialogVisible.value = true
@ -351,18 +493,17 @@ const open = async (type: string, row?: object) => {
resetForm() resetForm()
// //
if (row) { if (row) {
isDisabled.value = true; isDisabled.value = true
formLoading.value = true formLoading.value = true
try { try {
formData.value = await request.get({ url: `/wms/team/get?id=` + row.id }); formData.value = await request.get({ url: `/wms/team/get?id=` + row.id })
tags.value = JSON.parse(formData.value.members) tags.value = JSON.parse(formData.value.members)
} finally { } finally {
formLoading.value = false formLoading.value = false
} }
} } else {
else { isDisabled.value = false
isDisabled.value = false; tags.value = []
tags.value=[];
} }
} }
defineExpose({ open }) // open defineExpose({ open }) // open
@ -375,7 +516,7 @@ const submitForm = async () => {
const valid = await basicFormRef.value.validate() const valid = await basicFormRef.value.validate()
if (!valid) return if (!valid) return
if (tags.value.length > 15) { if (tags.value.length > 15) {
message.warning('班组成员最多15人'); message.warning('班组成员最多15人')
return return
} }
// //
@ -419,7 +560,6 @@ const resetForm = () => {
} }
basicFormRef.value?.resetFields() basicFormRef.value?.resetFields()
} }
</script> </script>
<style scoped> <style scoped>
@ -443,5 +583,4 @@ const resetForm = () => {
flex: 1; flex: 1;
/*margin-right: 10px;*/ /*margin-right: 10px;*/
} }
</style> </style>

Loading…
Cancel
Save