zouyu
2023-12-11 41e0df8413624e6034c967f3afae30da59370879
src/views/technology/completeproductstructure/completeproductstructure-form.vue
@@ -25,17 +25,17 @@
          <el-row>
            <el-col :span="24">
              <el-form-item label="BOM编号">
                <el-input v-model="treeForm.number" placeholder="BOM编号">
                <el-input v-model="treeForm.number" disabled placeholder="BOM编号">
                </el-input>
              </el-form-item>
              <el-form-item label="零件号" prop="partNo">
                <el-input v-model="treeForm.partNo" placeholder="零件" readonly>
                  <el-button
                <el-input v-model="treeForm.partNo" placeholder="零件" disabled>
                  <!-- <el-button
                    slot="append"
                    icon="el-icon-search"
                    @click="showProductStructure = true"
                  ></el-button>
                  ></el-button> -->
                </el-input>
              </el-form-item>
@@ -75,32 +75,26 @@
                </el-input>
              </el-form-item>
              <el-form-item label="替代号" prop="alternativeNo">
              <!-- <el-form-item label="替代号" prop="alternativeNo">
                <el-input
                  v-model="treeForm.alternativeNo"
                  placeholder="替代号"
                  disabled
                >
                </el-input>
              </el-form-item>
              </el-form-item> -->
              <el-form-item label="替代描述" prop="alternativeDesc">
              <!-- <el-form-item label="替代描述" prop="alternativeDesc">
                <el-input
                  v-model="treeForm.alternativeDesc"
                  placeholder="替代描述"
                  disabled
                >
                </el-input>
              </el-form-item>
              </el-form-item> -->
              <el-form-item label="绝缘颜色">
                <el-input
                  v-model="treeForm.insulationColor"
                  placeholder="绝缘颜色"
                >
                </el-input>
              </el-form-item>
              <el-form-item label="护套颜色">
              <!--   -->
              <!-- <el-form-item label="护套颜色">
                <el-input v-model="treeForm.sheathColor" placeholder="护套颜色">
                </el-input>
              </el-form-item>
@@ -110,15 +104,33 @@
                  placeholder="特性1"
                >
                </el-input>
              </el-form-item>
              </el-form-item> -->
            </el-col>
          </el-row>
        </el-form>
      </div>
      <div class="completeProductStructure-detail">
        <div class="completeProductStructure-design">
          <div class="completeProductStructure-design-title">构建BOM</div>
          <div class="completeProductStructure-design-title">BOM</div>
          <el-table
            class="tree-select-table"
            ref="tableRef"
            :data="tableData"
            style="width: 100%;"
            row-key="id"
            border
            height="720"
            default-expand-all
            @expand-change="expandChange"
            :row-class-name="tableRowClassName"
          >
            <el-table-column label="零件编号" prop="partNo"></el-table-column>
            <el-table-column label="零件名称" prop="partName"></el-table-column>
            <el-table-column label="单位" prop="unit"></el-table-column>
            <el-table-column label="数量" prop="qpa"></el-table-column>
            <!-- <el-table-column label="盘数" prop="discNum"></el-table-column> -->
          </el-table>
          <!-- <el-table
            class="tree-select-table"
            ref="tableRef"
            :data="tableData"
@@ -155,10 +167,10 @@
            </el-table-column>
            <el-table-column prop="operationName" label="消耗工序">
            </el-table-column>
          </el-table>
          </el-table> -->
        </div>
        <div class="completeProductStructure-queryPreview"></div>
        <div class="completeProductStructure-preview">
        <!-- <div class="completeProductStructure-queryPreview"></div> -->
        <!-- <div class="completeProductStructure-preview">
          <div class="completeProductStructure-preview-title">结果预览</div>
          <el-table
            :data="preViewData"
@@ -200,7 +212,7 @@
            <el-table-column prop="operationName" label="消耗工序">
            </el-table-column>
          </el-table>
        </div>
        </div> -->
      </div>
    </div>
    <productStructureDialog
@@ -221,7 +233,8 @@
  getPartAllStructureExt,
  addObj,
  getObj,
  putObj
  putObj,
  updateObj
} from '@/api/technology/completeproductstructure'
import { remote } from '@/api/admin/dict'
import productStructureDialog from '@/views/common/productstructure.vue'
@@ -281,7 +294,6 @@
  },
  computed: {
    editable: function() {
      console.log()
      if (!this.dataForm.id) {
        return true
      }
@@ -322,27 +334,11 @@
      if (this.dataForm.id) {
        getObj(this.dataForm.id).then((response) => {
          var resultData = response.data.data
          this.treeForm.partId = resultData.partId
          this.treeForm.partNo = resultData.partNo
          this.treeForm.partName = resultData.partName
          this.treeForm.number = resultData.number
          this.treeForm.insulationColor = resultData.insulationColor
          this.treeForm.sheathColor = resultData.sheathColor
          this.treeForm.characteristicOne = resultData.characteristicOne
          this.treeForm.version = resultData.version
          this.treeForm.alternativeNo = resultData.alternativeNo
          this.treeForm.alternativeDesc = resultData.alternativeDesc
          this.treeForm.bomTypeDb = resultData.bomTypeDb
          this.treeForm = resultData
          this.dataForm.state = resultData.state
          this.preViewData = []
          this.preViewData.push(resultData.tree)
          this.tableData = []
          getPartAllStructureExt(this.treeForm).then((res) => {
            const result = res.data
            if (result.code === 0) {
              this.tableData.push(result.data)
            }
          })
          this.tableData = resultData.bomComponentVOS
        })
      } else {
        this.initDefaultForm()
@@ -395,110 +391,119 @@
      }
    },
    dataFormSubmit() {
      const mapTree = (org) => {
        const haveChildren =
          Array.isArray(org.children) && org.children.length > 0
        return {
          checked: org.checked,
          compId: org.compId,
          discNum: org.discNum || 1,
          expand: org.expand,
          id: org.id,
          operationId: org.operationId,
          operationName: org.operationName,
          operationNo: org.operationNo,
          originalQpa: org.originalQpa,
          parentId: org.parentId,
          partId: org.partId,
          partName: org.partName,
          partNo: org.partNo,
          version: org.version,
          alternativeNo: org.alternativeNo,
          alternativeDesc: org.alternativeDesc,
          qpa: org.qpa,
          structureId: org.structureId,
          unit: org.unit,
          color: org.color,
          planningMethod: org.planningMethod,
          children: haveChildren ? org.children.map((i) => mapTree(i)) : []
        }
      let data = this.treeForm
      if(data.id != null){
        updateObj(data).then(res=>{
          this.$message.success("保存成功")
        }).catch(error=>{
          this.$message.error("保存失败")
        })
      }
      // const mapTree = (org) => {
      //   const haveChildren =
      //     Array.isArray(org.children) && org.children.length > 0
      //   return {
      //     checked: org.checked,
      //     compId: org.compId,
      //     discNum: org.discNum || 1,
      //     expand: org.expand,
      //     id: org.id,
      //     operationId: org.operationId,
      //     operationName: org.operationName,
      //     operationNo: org.operationNo,
      //     originalQpa: org.originalQpa,
      //     parentId: org.parentId,
      //     partId: org.partId,
      //     partName: org.partName,
      //     partNo: org.partNo,
      //     version: org.version,
      //     alternativeNo: org.alternativeNo,
      //     alternativeDesc: org.alternativeDesc,
      //     qpa: org.qpa,
      //     structureId: org.structureId,
      //     unit: org.unit,
      //     color: org.color,
      //     planningMethod: org.planningMethod,
      //     children: haveChildren ? org.children.map((i) => mapTree(i)) : []
      //   }
      // }
      this.isSubmit = true
      this.generateStructure()
      if (this.preViewData != null && this.preViewData.length > 0) {
        if (this.preViewData.length === 1) {
          if (this.dataForm.id) {
            var updateObj = {}
            updateObj.id = this.dataForm.id
            updateObj.partId = this.treeForm.partId
            updateObj.number = this.treeForm.number
            updateObj.insulationColor = this.treeForm.insulationColor
            updateObj.sheathColor = this.treeForm.sheathColor
            updateObj.characteristicOne = this.treeForm.characteristicOne
            updateObj.version = this.treeForm.version
            updateObj.alternativeNo = this.treeForm.alternativeNo
            updateObj.alternativeDesc = this.treeForm.alternativeDesc
            updateObj.bomTypeDb = this.treeForm.bomTypeDb
      // this.isSubmit = true
      // this.generateStructure()
      // if (this.preViewData != null && this.preViewData.length > 0) {
      //   if (this.preViewData.length === 1) {
      //     if (this.dataForm.id) {
      //       var updateObj = {}
      //       updateObj.id = this.dataForm.id
      //       updateObj.partId = this.treeForm.partId
      //       updateObj.number = this.treeForm.number
      //       updateObj.insulationColor = this.treeForm.insulationColor
      //       updateObj.sheathColor = this.treeForm.sheathColor
      //       updateObj.characteristicOne = this.treeForm.characteristicOne
      //       updateObj.version = this.treeForm.version
      //       updateObj.alternativeNo = this.treeForm.alternativeNo
      //       updateObj.alternativeDesc = this.treeForm.alternativeDesc
      //       updateObj.bomTypeDb = this.treeForm.bomTypeDb
            // const tree = this.preViewData[0];
            const gxqTree = this.preViewData.map((org) => mapTree(org))
            // this.setDefaultDiscNum(gxqTree);
            updateObj.tree = gxqTree[0]
            putObj(updateObj)
              .then((response) => {
                var data = response.data
                if (data.code === 0) {
                  this.$message.success('修改成功')
                } else {
                  this.$message.error('修改失败')
                }
                this.isSubmit = false
              })
              .catch((error) => {
                this.isSubmit = false
                console.log(error)
              })
          } else {
            var newObj = {}
            newObj.id = null
            newObj.partId = this.treeForm.partId
            newObj.number = this.treeForm.number
            newObj.insulationColor = this.treeForm.insulationColor
            newObj.sheathColor = this.treeForm.sheathColor
            newObj.characteristicOne = this.treeForm.characteristicOne
            newObj.version = this.treeForm.version
            newObj.alternativeNo = this.treeForm.alternativeNo
            newObj.alternativeDesc = this.treeForm.alternativeDesc
            newObj.bomTypeDb = this.treeForm.bomTypeDb
            const gxqTree = this.preViewData.map((org) => mapTree(org))
      //       // const tree = this.preViewData[0];
      //       const gxqTree = this.preViewData.map((org) => mapTree(org))
      //       // this.setDefaultDiscNum(gxqTree);
      //       updateObj.tree = gxqTree[0]
      //       putObj(updateObj)
      //         .then((response) => {
      //           var data = response.data
      //           if (data.code === 0) {
      //             this.$message.success('修改成功')
      //           } else {
      //             this.$message.error('修改失败')
      //           }
      //           this.isSubmit = false
      //         })
      //         .catch((error) => {
      //           this.isSubmit = false
      //           console.log(error)
      //         })
      //     } else {
      //       var newObj = {}
      //       newObj.id = null
      //       newObj.partId = this.treeForm.partId
      //       newObj.number = this.treeForm.number
      //       newObj.insulationColor = this.treeForm.insulationColor
      //       newObj.sheathColor = this.treeForm.sheathColor
      //       newObj.characteristicOne = this.treeForm.characteristicOne
      //       newObj.version = this.treeForm.version
      //       newObj.alternativeNo = this.treeForm.alternativeNo
      //       newObj.alternativeDesc = this.treeForm.alternativeDesc
      //       newObj.bomTypeDb = this.treeForm.bomTypeDb
      //       const gxqTree = this.preViewData.map((org) => mapTree(org))
            newObj.tree = gxqTree[0]
            addObj(newObj)
              .then((response) => {
                var data = response.data
                if (data.code === 0) {
                  this.dataForm.id = data.data.id
                  this.treeForm.number = data.data.number
                  this.$message.success('保存成功')
                } else {
                  this.$message.error('保存失败')
                }
                this.isSubmit = false
              })
              .catch((error) => {
                this.isSubmit = false
                console.log(error)
              })
          }
        } else {
          this.isSubmit = false
          this.$message.error('存在多个根节点,无法进行保存')
        }
      } else {
        this.isSubmit = false
        this.$message.error('请先构建BOM,再进行保存')
      }
      //       newObj.tree = gxqTree[0]
      //       addObj(newObj)
      //         .then((response) => {
      //           var data = response.data
      //           if (data.code === 0) {
      //             this.dataForm.id = data.data.id
      //             this.treeForm.number = data.data.number
      //             this.$message.success('保存成功')
      //           } else {
      //             this.$message.error('保存失败')
      //           }
      //           this.isSubmit = false
      //         })
      //         .catch((error) => {
      //           this.isSubmit = false
      //           console.log(error)
      //         })
      //     }
      //   } else {
      //     this.isSubmit = false
      //     this.$message.error('存在多个根节点,无法进行保存')
      //   }
      // } else {
      //   this.isSubmit = false
      //   this.$message.error('请先构建BOM,再进行保存')
      // }
    },
    // 生成最终的结构
    generateStructure() {
@@ -924,19 +929,19 @@
      }
    },
    bomTypeDbChange(e) {
      if (e) {
        this.before = this.treeForm.bomTypeDb
      } else {
        if (this.before !== this.treeForm.bomTypeDb) {
          this.treeForm.partId = null
          this.treeForm.partNo = null
          this.treeForm.partName = null
          this.treeForm.version = null
          this.treeForm.alternativeNo = null
          this.treeForm.alternativeDesc = null
          this.tableData = []
        }
      }
      // if (e) {
      //   this.before = this.treeForm.bomTypeDb
      // } else {
      //   if (this.before !== this.treeForm.bomTypeDb) {
      //     this.treeForm.partId = null
      //     this.treeForm.partNo = null
      //     this.treeForm.partName = null
      //     this.treeForm.version = null
      //     this.treeForm.alternativeNo = null
      //     this.treeForm.alternativeDesc = null
      //     this.tableData = []
      //   }
      // }
    },
    // table设置行样式
    tableRowClassName({ row, rowIndex }) {
@@ -989,7 +994,7 @@
.completeProductStructure-design {
  float: left;
  width: 48%;
  width: 100%;
  height: 800px;
  padding: 10px 20px;
  border: 1px solid #ddd;
@@ -1026,7 +1031,7 @@
  color: #006eff;
}
.forbid-row .cell {
  color: #c0c4cc;
  color: #000;
}
.tree-select-table th.gutter {