You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
912 lines
37 KiB
912 lines
37 KiB
// 打样跟踪页 mixin:事业部进度设置、默认进度设置、工序分类配置弹窗及工序拖拽排序
|
|
import {
|
|
queryProofTrackingBuProcessConfig,
|
|
queryProofTrackingProcessCategories,
|
|
deleteProofTrackingProcessColumnsManage,
|
|
queryProofTrackingProcessColumnsManage,
|
|
saveProofTrackingBuProcessConfig,
|
|
saveProofTrackingProcessCategoriesManage,
|
|
saveProofTrackingProcessColumnsManage
|
|
} from '@/api/sampleTracking/sampleTracking'
|
|
import Sortable from 'sortablejs'
|
|
import { DEFAULT_PROCESS_COLUMNS } from '../constants'
|
|
|
|
export default {
|
|
methods: {
|
|
queryBuProcessConfig () {
|
|
const inData = {
|
|
site: this.$store.state.user.site,
|
|
userName: this.$store.state.user.name
|
|
}
|
|
return queryProofTrackingBuProcessConfig(inData).then(({ data }) => {
|
|
if (!(data && data.code === 0)) {
|
|
this.$message.error((data && data.msg) || '加载事业部进度展示配置失败')
|
|
return
|
|
}
|
|
const rows = data.rows || []
|
|
const nextMap = {}
|
|
const processLabelMap = {}
|
|
rows.forEach(item => {
|
|
if (item && item.processLabelMap && typeof item.processLabelMap === 'object') {
|
|
Object.keys(item.processLabelMap).forEach(rawCode => {
|
|
const code = rawCode == null ? '' : String(rawCode).trim()
|
|
const label = item.processLabelMap[rawCode] == null ? '' : String(item.processLabelMap[rawCode]).trim()
|
|
if (!code || !label) {
|
|
return
|
|
}
|
|
processLabelMap[code] = label
|
|
})
|
|
}
|
|
const buNo = this.normalizeBuNo(item && item.buNo ? item.buNo : '', this.$store.state.user.site)
|
|
if (!buNo) {
|
|
return
|
|
}
|
|
const processOrderCodes = this.getValidProcessOrderCodes(item.processOrderCodes)
|
|
const processCodes = this.getValidProcessCodes(item.processCodes, processOrderCodes)
|
|
const showAll = item && item.showAll === true
|
|
? true
|
|
: processCodes.length >= processOrderCodes.length
|
|
const selectedCodeMap = {}
|
|
processCodes.forEach(code => {
|
|
selectedCodeMap[code] = true
|
|
})
|
|
const processCategoryMap = {}
|
|
const sourceCategoryMap = item && item.processCategoryMap && typeof item.processCategoryMap === 'object'
|
|
? item.processCategoryMap
|
|
: {}
|
|
const processCategoryNameMap = {}
|
|
const sourceCategoryNameMap = item && item.processCategoryNameMap && typeof item.processCategoryNameMap === 'object'
|
|
? item.processCategoryNameMap
|
|
: {}
|
|
Object.keys(sourceCategoryNameMap).forEach(rawCategoryCode => {
|
|
const categoryCode = rawCategoryCode == null ? '' : String(rawCategoryCode).trim()
|
|
const categoryName = sourceCategoryNameMap[rawCategoryCode] == null
|
|
? ''
|
|
: String(sourceCategoryNameMap[rawCategoryCode]).trim()
|
|
if (!categoryCode || !categoryName) {
|
|
return
|
|
}
|
|
processCategoryNameMap[categoryCode] = categoryName
|
|
processCategoryNameMap[categoryCode.toLowerCase()] = categoryName
|
|
})
|
|
processOrderCodes.forEach(code => {
|
|
if (!code) {
|
|
return
|
|
}
|
|
const directVal = sourceCategoryMap[code]
|
|
if (directVal != null) {
|
|
processCategoryMap[code] = String(directVal).trim()
|
|
return
|
|
}
|
|
const lowerCode = String(code).trim().toLowerCase()
|
|
const matchedKey = Object.keys(sourceCategoryMap).find(rawCode => {
|
|
return String(rawCode).trim().toLowerCase() === lowerCode
|
|
})
|
|
processCategoryMap[code] = matchedKey ? String(sourceCategoryMap[matchedKey] || '').trim() : ''
|
|
})
|
|
nextMap[buNo] = {
|
|
showAll: showAll,
|
|
processOrderCodes: processOrderCodes,
|
|
processCodes: showAll ? processOrderCodes.slice() : processOrderCodes.filter(code => selectedCodeMap[code]),
|
|
processCategoryMap: processCategoryMap,
|
|
processCategoryNameMap: processCategoryNameMap
|
|
}
|
|
})
|
|
this.mergeProcessCodeLabelMapByObject(processLabelMap)
|
|
this.buProcessConfigMap = nextMap
|
|
this.ensureBuProcessConfigRows()
|
|
this.loadAllBuProcessCategoryOptions(this.buProcessConfigRows, true)
|
|
this.refreshTrackingTableLayout()
|
|
}).catch(() => {
|
|
this.$message.error('加载事业部进度展示配置异常')
|
|
})
|
|
},
|
|
ensureBuProcessConfigRows () {
|
|
const allCodes = this.getAllProcessCodes()
|
|
const builtinCodeMap = {}
|
|
DEFAULT_PROCESS_COLUMNS.forEach(item => {
|
|
if (item && item.code) {
|
|
builtinCodeMap[item.code] = true
|
|
}
|
|
})
|
|
const defaultSelectedCodes = allCodes.filter(code => !!builtinCodeMap[code])
|
|
const rows = []
|
|
const usedBuMap = {}
|
|
const appendRow = (buNo, buDesc, site) => {
|
|
const key = this.normalizeBuNo(buNo, site || this.$store.state.user.site)
|
|
if (!key || usedBuMap[key]) {
|
|
return
|
|
}
|
|
usedBuMap[key] = true
|
|
const cfg = this.buProcessConfigMap[key]
|
|
const row = {
|
|
buNo: key,
|
|
buDesc: buDesc || key,
|
|
processOrderCodes: allCodes.slice(),
|
|
// 新增默认工序默认不勾选:仅预勾选系统内置工序,自定义新增项需事业部手工勾选。
|
|
processCodes: (defaultSelectedCodes.length > 0 ? defaultSelectedCodes : allCodes).slice(),
|
|
processCategoryMap: {}
|
|
}
|
|
if (cfg) {
|
|
const validOrderCodes = this.getValidProcessOrderCodes(cfg.processOrderCodes)
|
|
row.processOrderCodes = validOrderCodes
|
|
const validCodes = this.getValidProcessCodes(cfg.processCodes, validOrderCodes)
|
|
if (validCodes.length > 0) {
|
|
const selectedCodeMap = {}
|
|
validCodes.forEach(code => {
|
|
selectedCodeMap[code] = true
|
|
})
|
|
row.processCodes = validOrderCodes.filter(code => selectedCodeMap[code])
|
|
} else {
|
|
const defaultSelectedCodeMap = {}
|
|
row.processCodes.forEach(code => {
|
|
defaultSelectedCodeMap[code] = true
|
|
})
|
|
row.processCodes = validOrderCodes.filter(code => defaultSelectedCodeMap[code])
|
|
}
|
|
row.processCategoryMap = cfg.processCategoryMap && typeof cfg.processCategoryMap === 'object'
|
|
? Object.assign({}, cfg.processCategoryMap)
|
|
: {}
|
|
}
|
|
row.processCategoryMap = this.normalizeProcessCategoryMapForRow(row)
|
|
rows.push(row)
|
|
}
|
|
this.userBuList.forEach(item => {
|
|
if (!item || !item.buNo) {
|
|
return
|
|
}
|
|
appendRow(item.buNo, item.buDesc || this.normalizeBuNo(item.buNo, this.$store.state.user.site), this.$store.state.user.site)
|
|
})
|
|
Object.keys(this.buProcessConfigMap).forEach(buNo => {
|
|
appendRow(buNo, buNo, this.$store.state.user.site)
|
|
})
|
|
this.buProcessConfigRows = rows
|
|
},
|
|
openBuProcessConfigDialog () {
|
|
if (this.buProcessConfigLoading) {
|
|
return
|
|
}
|
|
this.buProcessConfigLoading = true
|
|
this.processOrderDragState = {
|
|
buNo: '',
|
|
fromIndex: -1
|
|
}
|
|
// 每次打开都强制拉取后端最新配置,避免必须整页刷新才能看到变更。
|
|
Promise.all([
|
|
this.queryProcessColumns(),
|
|
this.queryBuProcessConfig()
|
|
]).finally(() => {
|
|
this.ensureBuProcessConfigRows()
|
|
this.buProcessConfigDialogVisible = true
|
|
this.loadAllBuProcessCategoryOptions(this.buProcessConfigRows, false).finally(() => {
|
|
this.buProcessConfigLoading = false
|
|
})
|
|
})
|
|
},
|
|
buildDefaultProcessConfigRow (item) {
|
|
const parsedSortNo = parseInt(item && item.sortNo, 10)
|
|
const activeFlag = item && item.activeFlag ? String(item.activeFlag).trim().toUpperCase() : 'Y'
|
|
const code = item && item.code ? String(item.code).trim() : ''
|
|
return {
|
|
_rowKey: `default_process_${Date.now()}_${this.defaultProcessConfigRowSeed++}`,
|
|
// 记录后端原始编码,删除时可避免“修改了编码但尚未保存”导致删不到原记录。
|
|
_persistedCode: code,
|
|
sortNo: Number.isNaN(parsedSortNo) || parsedSortNo <= 0 ? this.getNextDefaultProcessSortNo() : parsedSortNo,
|
|
code: code,
|
|
label: item && item.label ? String(item.label).trim() : '',
|
|
activeFlag: activeFlag === 'N' ? 'N' : 'Y'
|
|
}
|
|
},
|
|
getNextDefaultProcessSortNo () {
|
|
if (!Array.isArray(this.defaultProcessConfigRows) || this.defaultProcessConfigRows.length === 0) {
|
|
return 10
|
|
}
|
|
let maxSortNo = 0
|
|
this.defaultProcessConfigRows.forEach(row => {
|
|
const parsedSortNo = parseInt(row && row.sortNo, 10)
|
|
if (!Number.isNaN(parsedSortNo) && parsedSortNo > maxSortNo) {
|
|
maxSortNo = parsedSortNo
|
|
}
|
|
})
|
|
return maxSortNo > 0 ? maxSortNo + 10 : (this.defaultProcessConfigRows.length + 1) * 10
|
|
},
|
|
resetDefaultProcessConfigSortNoByOrder () {
|
|
if (!Array.isArray(this.defaultProcessConfigRows)) {
|
|
return
|
|
}
|
|
this.defaultProcessConfigRows.forEach((row, index) => {
|
|
if (!row) {
|
|
return
|
|
}
|
|
this.$set(row, 'sortNo', (index + 1) * 10)
|
|
})
|
|
},
|
|
clearDefaultProcessConfigSelection () {
|
|
this.defaultProcessConfigSelectionRows = []
|
|
this.$nextTick(() => {
|
|
const tableRef = this.$refs.defaultProcessConfigTable
|
|
if (tableRef && tableRef.clearSelection) {
|
|
tableRef.clearSelection()
|
|
}
|
|
})
|
|
},
|
|
destroyDefaultProcessConfigSortable () {
|
|
if (this.defaultProcessConfigSortable && typeof this.defaultProcessConfigSortable.destroy === 'function') {
|
|
this.defaultProcessConfigSortable.destroy()
|
|
}
|
|
this.defaultProcessConfigSortable = null
|
|
},
|
|
initDefaultProcessConfigSortable () {
|
|
this.$nextTick(() => {
|
|
this.destroyDefaultProcessConfigSortable()
|
|
if (!this.defaultProcessConfigDialogVisible || !Array.isArray(this.defaultProcessConfigRows) || this.defaultProcessConfigRows.length === 0) {
|
|
return
|
|
}
|
|
const tableRef = this.$refs.defaultProcessConfigTable
|
|
const tableBody = tableRef && tableRef.$el
|
|
? tableRef.$el.querySelector('.el-table__body-wrapper tbody')
|
|
: null
|
|
if (!tableBody) {
|
|
return
|
|
}
|
|
this.defaultProcessConfigSortable = Sortable.create(tableBody, {
|
|
animation: 150,
|
|
// 整行可拖拽,避免必须精确悬浮到小图标才能排序。
|
|
handle: 'tr',
|
|
draggable: 'tr',
|
|
ghostClass: 'default-process-sortable-ghost',
|
|
chosenClass: 'default-process-sortable-chosen',
|
|
dragClass: 'default-process-sortable-drag',
|
|
onEnd: (evt) => {
|
|
const oldIndex = evt && typeof evt.oldIndex === 'number' ? evt.oldIndex : -1
|
|
const newIndex = evt && typeof evt.newIndex === 'number' ? evt.newIndex : -1
|
|
if (oldIndex < 0 || newIndex < 0 || oldIndex === newIndex) {
|
|
return
|
|
}
|
|
const movedRow = this.defaultProcessConfigRows.splice(oldIndex, 1)[0]
|
|
this.defaultProcessConfigRows.splice(newIndex, 0, movedRow)
|
|
this.resetDefaultProcessConfigSortNoByOrder()
|
|
this.clearDefaultProcessConfigSelection()
|
|
}
|
|
})
|
|
})
|
|
},
|
|
handleDefaultProcessConfigDialogClosed () {
|
|
this.defaultProcessConfigDeleteLoading = false
|
|
this.clearDefaultProcessConfigSelection()
|
|
this.destroyDefaultProcessConfigSortable()
|
|
},
|
|
handleDefaultProcessConfigSelectionChange (rows) {
|
|
this.defaultProcessConfigSelectionRows = Array.isArray(rows) ? rows : []
|
|
},
|
|
normalizeDefaultProcessFieldBaseByCode (code) {
|
|
const rawCode = code == null ? '' : String(code).trim()
|
|
if (!rawCode) {
|
|
return ''
|
|
}
|
|
if (/^[A-Za-z_][A-Za-z0-9_]*$/.test(rawCode)) {
|
|
return rawCode
|
|
}
|
|
const parts = rawCode.split(/[^A-Za-z0-9]+/).filter(item => !!item)
|
|
if (parts.length === 0) {
|
|
return ''
|
|
}
|
|
const firstPart = parts[0].toLowerCase()
|
|
const remained = parts.slice(1).map(item => {
|
|
const lower = item.toLowerCase()
|
|
return `${lower.charAt(0).toUpperCase()}${lower.substring(1)}`
|
|
}).join('')
|
|
let fieldBase = `${firstPart}${remained}`
|
|
if (/^[0-9]/.test(fieldBase)) {
|
|
fieldBase = `p${fieldBase}`
|
|
}
|
|
return fieldBase
|
|
},
|
|
buildDefaultProcessFieldsByCode (code) {
|
|
const fieldBase = this.normalizeDefaultProcessFieldBaseByCode(code)
|
|
if (!fieldBase) {
|
|
return {
|
|
planField: '',
|
|
actualField: '',
|
|
statusField: ''
|
|
}
|
|
}
|
|
return {
|
|
planField: `${fieldBase}PlanDate`,
|
|
actualField: `${fieldBase}ActualDate`,
|
|
statusField: `${fieldBase}Status`
|
|
}
|
|
},
|
|
queryDefaultProcessConfig () {
|
|
const inData = {
|
|
site: '*',
|
|
buNo: '*',
|
|
userName: this.$store.state.user.name
|
|
}
|
|
return queryProofTrackingProcessColumnsManage(inData).then(({ data }) => {
|
|
if (!(data && data.code === 0)) {
|
|
this.$message.error((data && data.msg) || '加载默认工序配置失败')
|
|
this.defaultProcessConfigRows = []
|
|
this.defaultProcessConfigSelectionRows = []
|
|
return []
|
|
}
|
|
const rows = Array.isArray(data.rows) ? data.rows : []
|
|
const sortedRows = rows
|
|
.map((item, index) => {
|
|
const parsedSortNo = parseInt(item && item.sortNo, 10)
|
|
return {
|
|
sourceIndex: index,
|
|
sortNo: Number.isNaN(parsedSortNo) ? Number.MAX_SAFE_INTEGER : parsedSortNo,
|
|
item: item
|
|
}
|
|
})
|
|
.sort((a, b) => {
|
|
if (a.sortNo !== b.sortNo) {
|
|
return a.sortNo - b.sortNo
|
|
}
|
|
return a.sourceIndex - b.sourceIndex
|
|
})
|
|
this.defaultProcessConfigRows = sortedRows.map(({ item }) => this.buildDefaultProcessConfigRow(item))
|
|
this.resetDefaultProcessConfigSortNoByOrder()
|
|
this.clearDefaultProcessConfigSelection()
|
|
this.initDefaultProcessConfigSortable()
|
|
return this.defaultProcessConfigRows
|
|
}).catch(() => {
|
|
this.$message.error('加载默认工序配置异常')
|
|
this.defaultProcessConfigRows = []
|
|
this.defaultProcessConfigSelectionRows = []
|
|
this.destroyDefaultProcessConfigSortable()
|
|
return []
|
|
})
|
|
},
|
|
openDefaultProcessConfigDialog () {
|
|
this.defaultProcessConfigDeleteLoading = false
|
|
this.defaultProcessConfigDialogVisible = true
|
|
this.queryDefaultProcessConfig()
|
|
},
|
|
buildProcessCategoryRow (item) {
|
|
const parsedSortNo = parseInt(item && item.sortNo, 10)
|
|
const categoryCode = item && item.categoryCode ? String(item.categoryCode).trim() : ''
|
|
return {
|
|
_rowKey: `process_category_${Date.now()}_${this.processCategoryRowSeed++}`,
|
|
_persistedCode: categoryCode,
|
|
sortNo: Number.isNaN(parsedSortNo) || parsedSortNo <= 0 ? (this.processCategoryRows.length + 1) * 10 : parsedSortNo,
|
|
categoryCode: categoryCode,
|
|
categoryName: item && item.categoryName ? String(item.categoryName).trim() : ''
|
|
}
|
|
},
|
|
queryProcessCategoryConfig (buNo, silent = false) {
|
|
const normalizedBuNo = this.normalizeBuNo(buNo, this.$store.state.user.site)
|
|
if (!normalizedBuNo) {
|
|
return Promise.resolve([])
|
|
}
|
|
const inData = {
|
|
site: this.$store.state.user.site,
|
|
buNo: normalizedBuNo,
|
|
userName: this.$store.state.user.name
|
|
}
|
|
return queryProofTrackingProcessCategories(inData).then(({ data }) => {
|
|
if (!(data && data.code === 0)) {
|
|
if (!silent) {
|
|
this.$message.error((data && data.msg) || '加载工序分类失败')
|
|
}
|
|
this.processCategoryRows = []
|
|
this.processCategorySelectionRows = []
|
|
this.$set(this.buProcessCategoryOptionsMap, normalizedBuNo, [])
|
|
if (this.buProcessConfigMap && this.buProcessConfigMap[normalizedBuNo]) {
|
|
this.$set(this.buProcessConfigMap, normalizedBuNo, Object.assign({}, this.buProcessConfigMap[normalizedBuNo], {
|
|
processCategoryNameMap: {}
|
|
}))
|
|
}
|
|
return []
|
|
}
|
|
const rows = Array.isArray(data.rows) ? data.rows : []
|
|
const categoryOptions = this.buildProcessCategoryOptionsByRows(rows)
|
|
this.$set(this.buProcessCategoryOptionsMap, normalizedBuNo, categoryOptions)
|
|
if (this.buProcessConfigMap && this.buProcessConfigMap[normalizedBuNo]) {
|
|
const processCategoryNameMap = {}
|
|
categoryOptions.forEach(item => {
|
|
const categoryCode = item && item.categoryCode ? String(item.categoryCode).trim() : ''
|
|
const categoryName = item && item.categoryName ? String(item.categoryName).trim() : ''
|
|
if (!categoryCode || !categoryName) {
|
|
return
|
|
}
|
|
processCategoryNameMap[categoryCode] = categoryName
|
|
processCategoryNameMap[categoryCode.toLowerCase()] = categoryName
|
|
})
|
|
this.$set(this.buProcessConfigMap, normalizedBuNo, Object.assign({}, this.buProcessConfigMap[normalizedBuNo], {
|
|
processCategoryNameMap: processCategoryNameMap
|
|
}))
|
|
}
|
|
const sortedRows = rows
|
|
.map((item, index) => {
|
|
const parsedSortNo = parseInt(item && item.sortNo, 10)
|
|
return {
|
|
sourceIndex: index,
|
|
sortNo: Number.isNaN(parsedSortNo) ? Number.MAX_SAFE_INTEGER : parsedSortNo,
|
|
item: item
|
|
}
|
|
})
|
|
.sort((a, b) => {
|
|
if (a.sortNo !== b.sortNo) {
|
|
return a.sortNo - b.sortNo
|
|
}
|
|
return a.sourceIndex - b.sourceIndex
|
|
})
|
|
this.processCategoryRows = sortedRows.map(({ item }) => this.buildProcessCategoryRow(item))
|
|
this.processCategorySelectionRows = []
|
|
return this.processCategoryRows
|
|
}).catch(() => {
|
|
if (!silent) {
|
|
this.$message.error('加载工序分类异常')
|
|
}
|
|
this.processCategoryRows = []
|
|
this.processCategorySelectionRows = []
|
|
this.$set(this.buProcessCategoryOptionsMap, normalizedBuNo, [])
|
|
if (this.buProcessConfigMap && this.buProcessConfigMap[normalizedBuNo]) {
|
|
this.$set(this.buProcessConfigMap, normalizedBuNo, Object.assign({}, this.buProcessConfigMap[normalizedBuNo], {
|
|
processCategoryNameMap: {}
|
|
}))
|
|
}
|
|
return []
|
|
})
|
|
},
|
|
openProcessCategoryDialog (row) {
|
|
const buNo = this.normalizeBuNo(row && row.buNo ? row.buNo : '', this.$store.state.user.site)
|
|
if (!buNo) {
|
|
this.$message.warning('请在事业部进度设置中指定事业部后再维护分类')
|
|
return
|
|
}
|
|
this.processCategoryDialogBuNo = buNo
|
|
this.processCategoryDialogBuDesc = row && row.buDesc ? row.buDesc : buNo
|
|
this.processCategoryDialogVisible = true
|
|
this.processCategorySaveLoading = false
|
|
this.queryProcessCategoryConfig(buNo)
|
|
},
|
|
handleProcessCategoryDialogClosed () {
|
|
this.processCategoryRows = []
|
|
this.processCategorySelectionRows = []
|
|
this.processCategoryDialogBuNo = ''
|
|
this.processCategoryDialogBuDesc = ''
|
|
this.processCategorySaveLoading = false
|
|
},
|
|
handleProcessCategorySelectionChange (rows) {
|
|
this.processCategorySelectionRows = Array.isArray(rows) ? rows : []
|
|
},
|
|
addProcessCategoryRow () {
|
|
this.processCategoryRows.push(this.buildProcessCategoryRow({
|
|
sortNo: (this.processCategoryRows.length + 1) * 10
|
|
}))
|
|
},
|
|
deleteProcessCategoryRows () {
|
|
if (!Array.isArray(this.processCategorySelectionRows) || this.processCategorySelectionRows.length === 0) {
|
|
this.$message.warning('请先勾选要删除的分类')
|
|
return
|
|
}
|
|
const selectedRows = this.processCategorySelectionRows.slice()
|
|
this.$confirm(`确认删除选中的 ${selectedRows.length} 条分类吗?`, '提示', {
|
|
confirmButtonText: '确定',
|
|
cancelButtonText: '取消',
|
|
type: 'warning'
|
|
}).then(() => {
|
|
const selectedKeyMap = {}
|
|
selectedRows.forEach(item => {
|
|
if (item && item._rowKey) {
|
|
selectedKeyMap[item._rowKey] = true
|
|
}
|
|
})
|
|
const nextRows = this.processCategoryRows.filter(item => !(item && selectedKeyMap[item._rowKey]))
|
|
const submitRows = this.normalizeProcessCategoryRowsForSave(nextRows)
|
|
if (!submitRows) {
|
|
return
|
|
}
|
|
const inData = {
|
|
site: this.$store.state.user.site,
|
|
buNo: this.processCategoryDialogBuNo,
|
|
updateBy: this.$store.state.user.name,
|
|
rows: submitRows
|
|
}
|
|
this.processCategorySaveLoading = true
|
|
saveProofTrackingProcessCategoriesManage(inData).then(({ data }) => {
|
|
if (!(data && data.code === 0)) {
|
|
this.$message.error((data && data.msg) || '删除工序分类失败')
|
|
return
|
|
}
|
|
this.handleProcessCategoryConfigSaved(data.msg || '删除成功')
|
|
}).catch(() => {
|
|
this.$message.error('删除工序分类异常')
|
|
}).finally(() => {
|
|
this.processCategorySaveLoading = false
|
|
})
|
|
}).catch(() => {
|
|
// 用户取消删除时无需额外提示。
|
|
})
|
|
},
|
|
normalizeProcessCategoryRowsForSave (sourceRowsInput) {
|
|
const sourceRows = Array.isArray(sourceRowsInput)
|
|
? sourceRowsInput
|
|
: (Array.isArray(this.processCategoryRows) ? this.processCategoryRows : [])
|
|
const normalizedRows = []
|
|
const usedNameMap = {}
|
|
for (let i = 0; i < sourceRows.length; i++) {
|
|
const row = sourceRows[i] || {}
|
|
const rowNo = i + 1
|
|
const categoryCode = row.categoryCode == null ? '' : String(row.categoryCode).trim()
|
|
const categoryName = row.categoryName == null ? '' : String(row.categoryName).trim()
|
|
if (!categoryName) {
|
|
this.$message.warning(`第${rowNo}行的分类名称不能为空`)
|
|
return null
|
|
}
|
|
const nameKey = categoryName.toLowerCase()
|
|
if (usedNameMap[nameKey]) {
|
|
this.$message.warning(`分类名称【${categoryName}】重复,请检查`)
|
|
return null
|
|
}
|
|
usedNameMap[nameKey] = true
|
|
normalizedRows.push({
|
|
// 旧分类携带隐藏编码回传,便于后端识别“保留/新增/删除”并做使用校验。
|
|
categoryCode: categoryCode || null,
|
|
categoryName: categoryName,
|
|
sortNo: rowNo * 10
|
|
})
|
|
}
|
|
return normalizedRows
|
|
},
|
|
handleProcessCategoryConfigSaved (successMsg) {
|
|
this.$message.success(successMsg || '工序分类已保存')
|
|
this.queryProcessCategoryConfig(this.processCategoryDialogBuNo, true).then(() => {
|
|
const buNo = this.processCategoryDialogBuNo
|
|
const validCategoryCodeMap = {}
|
|
this.getProcessCategoryOptionsByBuNo(buNo).forEach(item => {
|
|
if (item && item.categoryCode) {
|
|
validCategoryCodeMap[String(item.categoryCode).trim()] = true
|
|
}
|
|
})
|
|
this.buProcessConfigRows.forEach(configRow => {
|
|
const rowBuNo = this.normalizeBuNo(configRow && configRow.buNo ? configRow.buNo : '', this.$store.state.user.site)
|
|
if (!rowBuNo || rowBuNo !== buNo) {
|
|
return
|
|
}
|
|
const nextCategoryMap = this.normalizeProcessCategoryMapForRow(configRow)
|
|
Object.keys(nextCategoryMap).forEach(processCode => {
|
|
const categoryCode = nextCategoryMap[processCode]
|
|
if (!categoryCode || validCategoryCodeMap[categoryCode]) {
|
|
return
|
|
}
|
|
nextCategoryMap[processCode] = ''
|
|
})
|
|
this.$set(configRow, 'processCategoryMap', nextCategoryMap)
|
|
})
|
|
this.queryProcessColumns().then(() => {
|
|
this.refreshTrackingTableLayout()
|
|
})
|
|
})
|
|
},
|
|
saveProcessCategoryConfig () {
|
|
const submitRows = this.normalizeProcessCategoryRowsForSave()
|
|
if (!submitRows) {
|
|
return
|
|
}
|
|
const inData = {
|
|
site: this.$store.state.user.site,
|
|
buNo: this.processCategoryDialogBuNo,
|
|
updateBy: this.$store.state.user.name,
|
|
rows: submitRows
|
|
}
|
|
this.processCategorySaveLoading = true
|
|
saveProofTrackingProcessCategoriesManage(inData).then(({ data }) => {
|
|
if (!(data && data.code === 0)) {
|
|
this.$message.error((data && data.msg) || '工序分类保存失败')
|
|
return
|
|
}
|
|
this.handleProcessCategoryConfigSaved(data.msg || '工序分类已保存')
|
|
}).catch(() => {
|
|
this.$message.error('工序分类保存异常')
|
|
}).finally(() => {
|
|
this.processCategorySaveLoading = false
|
|
})
|
|
},
|
|
addDefaultProcessConfigRow () {
|
|
this.defaultProcessConfigRows.push(this.buildDefaultProcessConfigRow({
|
|
sortNo: this.getNextDefaultProcessSortNo(),
|
|
activeFlag: 'Y'
|
|
}))
|
|
this.resetDefaultProcessConfigSortNoByOrder()
|
|
this.initDefaultProcessConfigSortable()
|
|
},
|
|
deleteDefaultProcessConfigRow () {
|
|
if (!this.defaultProcessConfigSelectionRows || this.defaultProcessConfigSelectionRows.length === 0) {
|
|
this.$message.warning('请先勾选要删除的行')
|
|
return
|
|
}
|
|
const selectedRows = this.defaultProcessConfigSelectionRows.slice()
|
|
this.$confirm(`确认删除选中的 ${selectedRows.length} 条默认工序吗?`, '提示', {
|
|
confirmButtonText: '确定',
|
|
cancelButtonText: '取消',
|
|
type: 'warning'
|
|
}).then(() => {
|
|
const selectedKeyMap = {}
|
|
const persistedCodeMap = {}
|
|
selectedRows.forEach(item => {
|
|
if (item && item._rowKey) {
|
|
selectedKeyMap[item._rowKey] = true
|
|
}
|
|
const persistedCode = item && item._persistedCode ? String(item._persistedCode).trim() : ''
|
|
const persistedCodeKey = persistedCode.toLowerCase()
|
|
if (persistedCode && !persistedCodeMap[persistedCodeKey]) {
|
|
persistedCodeMap[persistedCodeKey] = persistedCode
|
|
}
|
|
})
|
|
const nextRows = this.defaultProcessConfigRows.filter(row => {
|
|
return !(row && row._rowKey && selectedKeyMap[row._rowKey])
|
|
})
|
|
const applyDeletedRowsToUi = () => {
|
|
this.defaultProcessConfigRows = nextRows
|
|
this.resetDefaultProcessConfigSortNoByOrder()
|
|
this.clearDefaultProcessConfigSelection()
|
|
this.initDefaultProcessConfigSortable()
|
|
}
|
|
const persistedCodes = Object.keys(persistedCodeMap).map(key => persistedCodeMap[key])
|
|
if (persistedCodes.length === 0) {
|
|
applyDeletedRowsToUi()
|
|
this.$message.success('删除成功')
|
|
return
|
|
}
|
|
const inData = {
|
|
site: '*',
|
|
buNo: '*',
|
|
updateBy: this.$store.state.user.name,
|
|
processCodes: persistedCodes
|
|
}
|
|
this.defaultProcessConfigDeleteLoading = true
|
|
deleteProofTrackingProcessColumnsManage(inData).then(({ data }) => {
|
|
if (!(data && data.code === 0)) {
|
|
this.$message.error((data && data.msg) || '删除默认工序失败')
|
|
return
|
|
}
|
|
applyDeletedRowsToUi()
|
|
this.$message.success(data.msg || '删除成功')
|
|
// 删除动作实时落库后立即刷新主列表列定义,避免页面继续展示已删工序。
|
|
this.queryProcessColumns().then(() => {
|
|
this.queryBuProcessConfig()
|
|
this.getDataList()
|
|
this.refreshTrackingTableLayout()
|
|
})
|
|
}).catch(() => {
|
|
this.$message.error('删除默认工序异常')
|
|
}).finally(() => {
|
|
this.defaultProcessConfigDeleteLoading = false
|
|
})
|
|
}).catch(() => {
|
|
// 用户取消删除时无需额外提示。
|
|
})
|
|
},
|
|
normalizeDefaultProcessConfigRowsForSave () {
|
|
const sourceRows = Array.isArray(this.defaultProcessConfigRows) ? this.defaultProcessConfigRows : []
|
|
const normalizedRows = []
|
|
const usedCodeMap = {}
|
|
for (let i = 0; i < sourceRows.length; i++) {
|
|
const row = sourceRows[i] || {}
|
|
const rowNo = i + 1
|
|
const code = row.code == null ? '' : String(row.code).trim()
|
|
const codeKey = code.toLowerCase()
|
|
const label = row.label == null ? '' : String(row.label).trim()
|
|
if (!code) {
|
|
this.$message.warning(`第${rowNo}行的工序编码不能为空`)
|
|
return null
|
|
}
|
|
if (usedCodeMap[codeKey]) {
|
|
this.$message.warning(`工序编码【${code}】重复,请检查`)
|
|
return null
|
|
}
|
|
if (!label) {
|
|
this.$message.warning(`第${rowNo}行的工序名称不能为空`)
|
|
return null
|
|
}
|
|
const fieldData = this.buildDefaultProcessFieldsByCode(code)
|
|
if (!fieldData.planField || !fieldData.actualField || !fieldData.statusField) {
|
|
this.$message.warning(`第${rowNo}行的工序编码格式无法生成字段,请调整编码`)
|
|
return null
|
|
}
|
|
usedCodeMap[codeKey] = true
|
|
normalizedRows.push({
|
|
code: code,
|
|
label: label,
|
|
planField: fieldData.planField,
|
|
actualField: fieldData.actualField,
|
|
statusField: fieldData.statusField,
|
|
// 用户要求:默认进度设置不维护工序分类。
|
|
processCategoryCode: null,
|
|
sortNo: rowNo * 10,
|
|
activeFlag: String(row.activeFlag || 'Y').toUpperCase() === 'N' ? 'N' : 'Y'
|
|
})
|
|
}
|
|
return normalizedRows
|
|
},
|
|
saveDefaultProcessConfig () {
|
|
const submitRows = this.normalizeDefaultProcessConfigRowsForSave()
|
|
if (!submitRows) {
|
|
return
|
|
}
|
|
const executeSave = () => {
|
|
const inData = {
|
|
site: '*',
|
|
buNo: '*',
|
|
updateBy: this.$store.state.user.name,
|
|
rows: submitRows
|
|
}
|
|
saveProofTrackingProcessColumnsManage(inData).then(({ data }) => {
|
|
if (!(data && data.code === 0)) {
|
|
this.$message.error((data && data.msg) || '默认工序配置保存失败')
|
|
return
|
|
}
|
|
this.$message.success(data.msg || '默认工序配置已保存')
|
|
this.queryDefaultProcessConfig()
|
|
// 保存后刷新页面列定义,确保新增/删除工序立即反映到主表列。
|
|
this.queryProcessColumns().then(() => {
|
|
this.queryBuProcessConfig()
|
|
this.getDataList()
|
|
this.refreshTrackingTableLayout()
|
|
})
|
|
}).catch(() => {
|
|
this.$message.error('默认工序配置保存异常')
|
|
})
|
|
}
|
|
if (submitRows.length === 0) {
|
|
this.$confirm('当前将清空默认工序配置,保存后页面会回退到系统兜底配置,是否继续?', '提示', {
|
|
confirmButtonText: '确定',
|
|
cancelButtonText: '取消',
|
|
type: 'warning'
|
|
}).then(() => {
|
|
executeSave()
|
|
}).catch(() => {
|
|
// 用户取消清空时无需额外提示。
|
|
})
|
|
return
|
|
}
|
|
executeSave()
|
|
},
|
|
handleBuProcessCodesChange (row) {
|
|
if (!row) {
|
|
return
|
|
}
|
|
const validOrderCodes = this.getValidProcessOrderCodes(row.processOrderCodes)
|
|
const validCodes = this.getValidProcessCodes(row.processCodes, validOrderCodes)
|
|
const selectedCodeMap = {}
|
|
validCodes.forEach(code => {
|
|
selectedCodeMap[code] = true
|
|
})
|
|
row.processOrderCodes = validOrderCodes
|
|
row.processCodes = validOrderCodes.filter(code => selectedCodeMap[code])
|
|
row.processCategoryMap = this.normalizeProcessCategoryMapForRow(row)
|
|
},
|
|
isProcessOrderDraggingItem (row, index) {
|
|
if (!row || index == null) {
|
|
return false
|
|
}
|
|
return this.processOrderDragState.buNo === row.buNo && this.processOrderDragState.fromIndex === index
|
|
},
|
|
handleProcessOrderDragStart (row, index, event) {
|
|
if (!row || index == null || index < 0) {
|
|
return
|
|
}
|
|
this.processOrderDragState = {
|
|
buNo: row.buNo || '',
|
|
fromIndex: index
|
|
}
|
|
if (event && event.dataTransfer) {
|
|
event.dataTransfer.effectAllowed = 'move'
|
|
}
|
|
},
|
|
handleProcessOrderDrop (row, targetIndex, event) {
|
|
if (event && event.dataTransfer) {
|
|
event.dataTransfer.dropEffect = 'move'
|
|
}
|
|
if (!row || targetIndex == null || targetIndex < 0) {
|
|
this.handleProcessOrderDragEnd()
|
|
return
|
|
}
|
|
const dragBuNo = this.processOrderDragState.buNo
|
|
const fromIndex = Number(this.processOrderDragState.fromIndex)
|
|
if (!dragBuNo || dragBuNo !== row.buNo || Number.isNaN(fromIndex) || fromIndex < 0) {
|
|
this.handleProcessOrderDragEnd()
|
|
return
|
|
}
|
|
const validOrderCodes = this.getValidProcessOrderCodes(row.processOrderCodes)
|
|
if (fromIndex >= validOrderCodes.length || targetIndex >= validOrderCodes.length) {
|
|
this.handleProcessOrderDragEnd()
|
|
return
|
|
}
|
|
if (fromIndex === targetIndex) {
|
|
this.handleProcessOrderDragEnd()
|
|
return
|
|
}
|
|
const movedCode = validOrderCodes.splice(fromIndex, 1)[0]
|
|
const insertIndex = targetIndex
|
|
validOrderCodes.splice(insertIndex, 0, movedCode)
|
|
row.processOrderCodes = validOrderCodes
|
|
this.handleBuProcessCodesChange(row)
|
|
this.handleProcessOrderDragEnd()
|
|
},
|
|
handleProcessOrderDragEnd () {
|
|
this.processOrderDragState = {
|
|
buNo: '',
|
|
fromIndex: -1
|
|
}
|
|
},
|
|
saveBuProcessConfig () {
|
|
if (!this.buProcessConfigRows || this.buProcessConfigRows.length === 0) {
|
|
this.$message.warning('暂无可配置的事业部')
|
|
return
|
|
}
|
|
const nextMap = {}
|
|
const submitRows = []
|
|
for (let i = 0; i < this.buProcessConfigRows.length; i++) {
|
|
const row = this.buProcessConfigRows[i]
|
|
const buNo = this.normalizeBuNo(row && row.buNo ? row.buNo : '', this.$store.state.user.site)
|
|
if (!buNo) {
|
|
continue
|
|
}
|
|
const validOrderCodes = this.getValidProcessOrderCodes(row.processOrderCodes)
|
|
const selectedCodeMap = {}
|
|
this.getValidProcessCodes(row.processCodes, validOrderCodes).forEach(code => {
|
|
selectedCodeMap[code] = true
|
|
})
|
|
const validCodes = validOrderCodes.filter(code => selectedCodeMap[code])
|
|
if (validCodes.length === 0) {
|
|
this.$message.warning(`事业部【${row.buDesc || buNo}】至少需要选择一个可见进度`)
|
|
return
|
|
}
|
|
const processCategoryMap = this.normalizeProcessCategoryMapForRow(Object.assign({}, row, {
|
|
processOrderCodes: validOrderCodes
|
|
}))
|
|
const processCategoryNameMap = {}
|
|
this.getProcessCategoryOptionsByBuNo(buNo).forEach(item => {
|
|
const categoryCode = item && item.categoryCode ? String(item.categoryCode).trim() : ''
|
|
const categoryName = item && item.categoryName ? String(item.categoryName).trim() : ''
|
|
if (!categoryCode || !categoryName) {
|
|
return
|
|
}
|
|
processCategoryNameMap[categoryCode] = categoryName
|
|
processCategoryNameMap[categoryCode.toLowerCase()] = categoryName
|
|
})
|
|
const showAll = validCodes.length >= validOrderCodes.length
|
|
nextMap[buNo] = {
|
|
showAll: showAll,
|
|
processOrderCodes: validOrderCodes,
|
|
processCodes: showAll ? validOrderCodes.slice() : validCodes,
|
|
processCategoryMap: processCategoryMap,
|
|
processCategoryNameMap: processCategoryNameMap
|
|
}
|
|
submitRows.push({
|
|
buNo: buNo,
|
|
showAll: showAll,
|
|
processCodes: validCodes,
|
|
processOrderCodes: validOrderCodes,
|
|
processCategoryMap: processCategoryMap
|
|
})
|
|
}
|
|
const inData = {
|
|
site: this.$store.state.user.site,
|
|
updateBy: this.$store.state.user.name,
|
|
rows: submitRows
|
|
}
|
|
saveProofTrackingBuProcessConfig(inData).then(({ data }) => {
|
|
if (!(data && data.code === 0)) {
|
|
this.$message.error((data && data.msg) || '事业部进度展示设置保存失败')
|
|
return
|
|
}
|
|
this.buProcessConfigMap = nextMap
|
|
this.ensureBuProcessConfigRows()
|
|
this.$message.success(data.msg || '事业部进度展示设置已保存')
|
|
// 保存后重新拉取工序列和列表,确保页面立即按最新可见性与顺序刷新。
|
|
this.queryProcessColumns().then(() => {
|
|
this.getDataList()
|
|
this.refreshTrackingTableLayout()
|
|
})
|
|
}).catch(() => {
|
|
this.$message.error('事业部进度展示设置保存异常')
|
|
})
|
|
}
|
|
}
|
|
}
|