| | |
| | | const dialogVisibleProcess = ref(false) |
| | | let roleList = ref([]) |
| | | //工序 |
| | | const processValue = ref() |
| | | const processValue = ref([]) |
| | | let userRole= ref({ |
| | | userId:'', |
| | | roles:[] |
| | |
| | | arr.forEach(item=>{ |
| | | let bValues = item.userRoleList.map(item => item.role); |
| | | item.role = bValues.join(',') |
| | | // 核心:处理工序列显示(转为切割,磨边格式) |
| | | item.address = formatProcessForTable(item.address) |
| | | }) |
| | | gridOptions.data = res.data.users[0] |
| | | roleList.value = res.data.role[0] |
| | | }) |
| | | |
| | | }) |
| | | |
| | | // 工具函数:统一处理工序数据为逗号分隔字符串(适配表格显示) |
| | | const formatProcessForTable = (processData) => { |
| | | if (!processData) return '' |
| | | |
| | | // 步骤1:处理JSON字符串(如 "\"[\"切割\",\"磨边\"]\"") |
| | | let str = String(processData).trim() |
| | | if (str.startsWith('"') && str.endsWith('"')) { |
| | | str = str.slice(1, -1) |
| | | } |
| | | |
| | | // 步骤2:尝试解析为数组 |
| | | try { |
| | | const arr = JSON.parse(str) |
| | | if (Array.isArray(arr)) { |
| | | return arr.join(',') // 中文逗号分隔,如需英文逗号改为 ',' |
| | | } |
| | | } catch (e) { |
| | | // 解析失败,直接使用原字符串(如已为"切割,磨边") |
| | | return str.replace(/[,,]/g, ',') // 统一为中文逗号 |
| | | } |
| | | |
| | | // 兜底:非数组格式直接返回 |
| | | return str |
| | | } |
| | | |
| | | const getTableRow = (row,type) => { |
| | | switch (type) { |
| | |
| | | case 'editProcess': { |
| | | dialogVisibleProcess.value = true |
| | | processRow.value.userId = row.id |
| | | // 清空之前选择的工序 |
| | | processValue.value = [] |
| | | |
| | | processValue.value = row.address ? row.address.split(',').filter(item => item.trim()) : [] |
| | | break |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | const handleClose = (done) => { |
| | | userRole.value.roles = [] |
| | |
| | | } |
| | | |
| | | const updateProcess = () => { |
| | | let userId=processRow.value.userId |
| | | if (processValue.value!=null){ |
| | | request.post(`userInfo/updateProcess/${userId}/${processValue.value}`).then(res=>{ |
| | | if(res.code==200 && res.data===true){ |
| | | ElMessage.success(t('basicData.msg.saveSuccess')) |
| | | router.push({path:'/main/user/userList',query:{random:Math.random()}}) |
| | | } |
| | | const userId = processRow.value.userId |
| | | // 检查是否选择了工序 |
| | | let processStr="" |
| | | if (processValue.value && processValue.value.length > 0) { |
| | | // 将选中的工序数组转为字符串(根据后端需求调整格式) |
| | | processStr = JSON.stringify(processValue.value) |
| | | |
| | | }) |
| | | dialogVisible.value = false |
| | | }else { |
| | | ElMessage.warning(t('report.pleaseSelectAProcessFirst')) |
| | | } |
| | | |
| | | try { |
| | | request.post(`userInfo/updateProcess/${userId}`,{processList: processStr}).then(res => { |
| | | if (res.code == 200 && res.data === true) { |
| | | ElMessage.success(t('basicData.msg.saveSuccess')) |
| | | router.push({ path: '/main/user/userList', query: { random: Math.random() } }) |
| | | // 关闭工序弹窗 |
| | | dialogVisibleProcess.value = false |
| | | } |
| | | }) |
| | | }catch (err) { |
| | | // 捕获网络错误、接口报错等所有异常 |
| | | console.error('初始化工序失败:', err); |
| | | ElMessage.error('初始化数据失败,请刷新重试'); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | width="30%" |
| | | :before-close="handleClose" |
| | | > |
| | | <el-select v-model="processValue" clearable :placeholder="$t('reportingWorks.selectProcess')" default-value="default_city" style="width: 120px"> |
| | | <el-option |
| | | v-for="item in processRow['process']" |
| | | :key="item.id" |
| | | :label="item.basic_name" |
| | | :value="item.basic_name" |
| | | /> |
| | | </el-select> |
| | | <div class="process-checkbox-group"> |
| | | <el-checkbox-group |
| | | v-model="processValue" |
| | | class="checkbox-group" |
| | | > |
| | | <el-checkbox |
| | | v-for="item in processRow.process" |
| | | :key="item.id" |
| | | :label="item.basic_name" |
| | | class="checkbox-item" |
| | | > |
| | | {{ item.basic_name }} |
| | | </el-checkbox> |
| | | </el-checkbox-group> |
| | | </div> |
| | | <template #footer> |
| | | <span class="dialog-footer"> |
| | | <el-button @click="dialogVisibleProcess = false">{{ $t('basicData.cancelButtonText') }}</el-button> |