yuyu
2023-08-08 0d452c10ee16e40a3ca3d176e5ebebcb4bd16a87
src/views/standardLibrary/SpecificationDetails.vue
@@ -51,7 +51,7 @@
                      <el-button size="mini" type="text" @click="showChangeMaterial(data)">编辑</el-button>
                    </div>
                    <div>
                      <el-button size="mini" type="text">删除</el-button>
                      <el-button size="mini" type="text" @click="delmaterialFormVisible=true">删除</el-button>
                    </div>
                  </div>
                  <el-button
@@ -100,7 +100,7 @@
                      <el-button size="mini" type="text" @click="showChangeProject(data)">编辑</el-button>
                    </div>
                    <div>
                      <el-button size="mini" type="text">删除</el-button>
                      <el-button size="mini" type="text" @click="delProductFormVisible = true">删除</el-button>
                    </div>
                  </div>
                  <el-button
@@ -143,14 +143,10 @@
              <span />
              <div>测试标准</div>
            </div>
            <!-- <div class="tips-btn">
              <span><i class="el-icon-edit" />操作:</span>
              <el-button type="text">编辑</el-button>
            </div> -->
          </div>
          <div class="message">
            <div class="message-item">
              <el-tag type="primary"><i class="el-icon-info" :style="{marginRight:'4px', color:'#409EFF'}"/>单位:欧姆</el-tag>
              <el-tag type="primary"><i class="el-icon-info" :style="{marginRight:'4px', color:'#409EFF'}" />单位:欧姆</el-tag>
            </div>
            <div class="message-item">
              <span><i class="el-icon-edit" />招标人员要求:{{ detailInfo.required }}</span>
@@ -162,7 +158,7 @@
      </div>
    </div>
    <!-- 添加以及修改的模态框 -->
    <el-dialog title="添加物料" :visible.sync="materialFormVisible">
    <el-dialog title="添加物料" :visible.sync="materialFormVisible" width="35%">
      <el-form :model="addMaterialForm">
        <el-row :gutter="20">
          <el-col :span="12">
@@ -218,7 +214,7 @@
        <el-button @click="dialogFormVisible = false">取 消</el-button>
      </div>
    </el-dialog>
    <el-dialog title="添加子项目" :visible.sync="projectFormVisible">
    <el-dialog title="添加子项目" :visible.sync="projectFormVisible" width="35%">
      <el-form :model="addProjectForm">
        <el-row :gutter="20">
          <el-col :span="12">
@@ -294,7 +290,7 @@
        <el-button @click="projectFormVisible = false">取 消</el-button>
      </div>
    </el-dialog>
    <el-dialog title="修改物料" :visible.sync="changeMaterialFormVisible">
    <el-dialog title="修改物料" :visible.sync="changeMaterialFormVisible" width="35%">
      <el-form :model="changeMaterialForm">
        <el-row :gutter="20">
          <el-col :span="12">
@@ -338,7 +334,7 @@
        <el-button @click="changeMaterialFormVisible = false">取 消</el-button>
      </div>
    </el-dialog>
    <el-dialog title="修改子项目" :visible.sync="changeProjectFormVisible">
    <el-dialog title="修改子项目" :visible.sync="changeProjectFormVisible" width="35%">
      <el-form :model="changeProjectForm">
        <el-row :gutter="20">
          <el-col :span="12">
@@ -398,11 +394,33 @@
        <el-button @click="projectFormVisible = false">取 消</el-button>
      </div>
    </el-dialog>
    <el-dialog
      title="提示"
      :visible.sync="delmaterialFormVisible"
      width="30%"
    >
      <span>确认删除该物料吗?</span>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="deleteMaterial">确 定</el-button>
        <el-button @click="delmaterialFormVisible = false">取 消</el-button>
      </span>
    </el-dialog>
    <el-dialog
      title="提示"
      :visible.sync="delProductFormVisible"
      width="30%"
    >
      <span>确认删除该子项目吗?</span>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="deleleProduct">确 定</el-button>
        <el-button @click="delProductFormVisible = false">取 消</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import { getMaterialList, getProductList, getProductProductId, addMaterial, addProduct, getMaterialDetail, updateMaterial, updateProduct } from '@/api/standardLibrary'
import { getMaterialList, getProductProductId, addMaterial, addProduct, getMaterialDetail, updateMaterial, updateProduct, deleteMaterial, deleteProduct } from '@/api/standardLibrary'
export default {
  name: 'SpecificationDetail',
  data() {
@@ -427,14 +445,18 @@
      materialTreeDefault: [],
      projectTreeDefault: [],
      materialFormVisible: false,
      delmaterialFormVisible: false,
      changeMaterialFormVisible: false,
      projectFormVisible: false,
      changeProjectFormVisible: false,
      delProductFormVisible: false,
      addMaterialForm: {},
      changeMaterialForm: {},
      addProjectForm: {},
      changeProjectForm: {},
      fatherOpetions: []
      fatherOpetions: [],
      materialId: '',
      productId: ''
    }
  },
  // 为了选中第一层级下的第一个节点
@@ -494,34 +516,19 @@
      this.materialTreeDefault = [this.materialTree[0].id]
      console.log(this.materialTree, this.materialTreeDefault)
    },
    // 获取项目tree
    async getProjectTreeData(data) {
      //
      const { data: projectArr } = await getProductList({ materialId: data.id })
      // console.log(projectArr)
      projectArr.map((item, index) => {
        item.label = item.father
        item.id = index
        item.children = item.sonProduct.map(item => ({ ...item, label: item.name }))
      })
      this.projectTree = projectArr
      // 项目中默认选中的子项目
      console.log(this.projectTree)
      this.fatherOpetions = this.projectTree.map(item => ({ id: item.id, label: item.label }))
      console.log(this.fatherOpetions)
      this.projectTreeDefault = [this.projectTree[0]?.children[0]?.id]
    },
    // 物料库的节点点击
    materialTreeClick(data, node, element) {
      // 点击物料节点,查询对应的项目tree数据
      console.log(data)
      this.getProjectTreeData(data)
      // 得到物料Id
      this.materialId = data.id
    },
    // 项目库的节点点击
    async projectTreeClick(data, node, element) {
      // 先判断点击的是父节点还是子节点
      if (('children' in data)) return
      console.log('子项目节点', data)
      this.productId = data.id
      //
      const { data: detailInfo } = await getProductProductId({ productId: data.id })
      // console.log('详情信息', detailInfo)
@@ -585,6 +592,15 @@
      this.changeProjectForm.name = data.name
      // console.log('修改后', this.changeMaterialForm)
      this.changeProjectFormVisible = true
    },
    async deleteMaterial() {
      await deleteMaterial({ materialId: this.materialId })
      this.delmaterialFormVisible = false
    },
    async deleleProduct() {
      // console.log('productId', this.productId)
      await deleteProduct({ productId: this.productId })
      this.delProductFormVisible = false
    }
  }
}