| | |
| | | import deepClone from "@/utils/deepClone" |
| | | import { ElMessage, ElMessageBox} from "element-plus" |
| | | const { t } = useI18n() |
| | | |
| | | const emit = defineEmits(['closeDialog']) |
| | | let produceList = ref([]) |
| | | let props = defineProps({ |
| | | productName:null, |
| | |
| | | |
| | | gridDataByProduct: { type: Object, default: () => ({}) } |
| | | }) |
| | | |
| | | |
| | | |
| | | const xGrid = ref() |
| | | const xGridByProduct = ref() |
| | | const activeProduct = ref('') // 当前选中的产品名 |
| | | let materialType = ref(1) |
| | | |
| | | //关闭弹窗 |
| | | const closeDialog = () => { |
| | | emit('closeDialog') |
| | | } |
| | | |
| | | const value = ref('') |
| | | const options = [ |
| | |
| | | }) |
| | | |
| | | getWorks() |
| | | |
| | | getDetails(); |
| | | editProductBOM(); |
| | | }else{ |
| | | ElMessage.warning(res.msg) |
| | | } |
| | |
| | | } |
| | | |
| | | |
| | | const getDetails = () => { |
| | | } |
| | | |
| | | //拆分每个产品 |
| | | const productList = computed(() => { |
| | | const raw = (props.productName ?? '').toString().trim() |
| | |
| | | } |
| | | |
| | | const saveProductBOM = () => { |
| | | gridOptionsByProduct.loading=true |
| | | productList.value.forEach((name, index) => { |
| | | const rows = gridDataMapByProduct[index] || [] |
| | | const seq = index + 1 |
| | |
| | | row.produceId = props.produceId |
| | | }) |
| | | }) |
| | | console.log(gridDataMapByProduct) |
| | | request.post(`/BomData/saveProductBOM`,gridDataMapByProduct).then((res) => { |
| | | if(res.code==200){ |
| | | ElMessage.success(t('basicData.msg.saveSuccess')) |
| | | gridOptionsByProduct.loading=false |
| | | emit('closeDialog') |
| | | }}) |
| | | } |
| | | |
| | | const editProductBOM = () => { |
| | | request.post(`/BomData/editProductBOM/${props.produceId}`).then((res) => { |
| | | if (res.code == 200 ) { |
| | | // 初始化清空 |
| | | productList.value.forEach((_, index) => { |
| | | gridDataMapByProduct[index + 1] = [] |
| | | }) |
| | | // 遍历后端返回的数据 |
| | | res.data.data.forEach(item => { |
| | | const layer = item.product_layer - 1 // 例如 1, 2, 3 |
| | | if (!gridDataMapByProduct[layer]) { |
| | | gridDataMapByProduct[layer] = [] |
| | | } |
| | | |
| | | const plainItem = JSON.parse(JSON.stringify(item)) |
| | | gridDataMapByProduct[layer].push(plainItem) |
| | | }) |
| | | |
| | | // 默认选择第一层 |
| | | activeProductIndex.value = 0 |
| | | xGridByProduct.value.loadData(gridDataMapByProduct[0]) |
| | | } |
| | | }) |
| | | } |
| | | </script> |
| | | |
| | | <template> |