XiaoRuby
2023-08-28 8231542d77a49f80a49434be6ca8bfb3ae9e1efe
src/views/standardLibrary/index.vue
@@ -25,16 +25,22 @@
        <div class="table-header">
          <div class="serve-btn">
            <span class="tipMsg">{{ msg !== "" ? msg : "" }}</span>
            <el-select v-model="versionValue" @change="changeSelect" clearable placeholder="请选择版本号">
            <el-select
              v-model="versionValue"
              @change="changeSelect"
              placeholder="请选择版本号"
            >
              <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value"
                >
              >
              </el-option>
            </el-select>
            <el-button type="primary" @click="addVersionFun">新增版本号</el-button>
            <el-button type="primary" @click="addVersionFun"
              >新增版本号</el-button
            >
            <el-button
              type="primary"
              icon="el-icon-plus"
@@ -54,13 +60,14 @@
          <el-table
            :data="tableData"
            style="width: 100%; margin-bottom: 20px"
            row-key="name"
            row-key="id"
            border
            height="calc(100vh - 250px)"
            default-expand-all
            ref="multipleTable"
            @select="selectTr"
            @select-all="selectAll"
            @selection-change="handleSelectionChange"
            :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
          >
            <el-table-column type="selection" label="序号"> </el-table-column>
@@ -171,15 +178,15 @@
  deleteListApi,
  blurUpdateApi,
  getVersion,
  addVersion
  addVersion,
} from "@/api/standardLibrary";
import { selectproductModelApi } from "@/api/basicData/index";
export default {
  data() {
    return {
      options:[],
      versionValue: '',
      options: [],
      versionValue: "",
      deleteList: [],
      msg: "",
      isAllSelect: false,
@@ -212,47 +219,49 @@
  created() {
    this.getStandardTree();
  },
  mounted(){
  },
  mounted() {},
  methods: {
    async initSelect(){
        this.options = [];
        this.versionValue = "";
        const response = await getVersion({"specificationsId":this.selectData.id});
        if(response.code===200 && response.data.length>0){
          this.getTableByClick(this.selectData,response.data[0])
          for(let i=0;i<response.data.length;i++){
            this.options.push({
              value: response.data[i],
              label: "V" + response.data[i]
            })
            this.versionValue = response.data[0];
          }
        }
    },
    changeSelect(){
      this.tableData = [];
      this.getTableByClick(this.selectData,this.versionValue);
    },
    async insertVersion(){
      const resp = await addVersion({"specificationsId":this.selectData.id});
      if(resp.code===200){
        this.initSelect();
        this.$message({
            type: 'success',
            message: resp.message
    async initSelect() {
      this.options = [];
      this.versionValue = "";
      const response = await getVersion({
        specificationsId: this.selectData.id,
      });
      if (response.code === 200 && response.data.length > 0) {
        this.getTableByClick(this.selectData, response.data[0]);
        for (let i = 0; i < response.data.length; i++) {
          this.options.push({
            value: response.data[i],
            label: "V" + response.data[i],
          });
          this.versionValue = response.data[0];
        }
      }
    },
     addVersionFun() {
        this.$confirm('确认添加新的版本号吗?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
    changeSelect() {
      this.tableData = [];
      this.getTableByClick(this.selectData, this.versionValue);
    },
    async insertVersion() {
      const resp = await addVersion({ specificationsId: this.selectData.id });
      if (resp.code === 200) {
        this.initSelect();
        this.$message({
          type: "success",
          message: resp.message,
        });
      }
    },
    addVersionFun() {
      this.$confirm("确认添加新的版本号吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.insertVersion();
        }).catch(() => {});
        })
        .catch(() => {});
    },
    filterNode(value, data) {
      if (!value) return true;
@@ -307,7 +316,7 @@
        this.getParentData(node.parent, node.data.name);
        // 存下选中节点
        this.selectData = data;
        this.getTableByClick(data,this.versionValue);
        this.getTableByClick(data, this.versionValue);
        this.initSelect();
      }
      if (!("children" in data)) {
@@ -323,10 +332,10 @@
        this.getParentData(node.parent, this.msg);
      }
    },
    async getTableByClick(data,versionVal) {
    async getTableByClick(data, versionVal) {
      await getProductList({
        specificationsId: data.id,
        version: versionVal
        version: versionVal,
      }).then((res) => {
        res.data.forEach((i) => {
          if (i.name === undefined) {
@@ -348,10 +357,9 @@
      this.$router.push(`/standardLibrary/SpecificationDetails/${row.id}`);
    },
    renderContent(h, { node, data, store }) {
      // console.log('data', data)
      // console.log('node', node)
      // 判断是否是父节点或文件夹
      const isFolder = "children" in data;
      console.log(`output->data`, isFolder);
      return (
        <span class="tree-node">
          {isFolder ? (
@@ -402,13 +410,12 @@
        this.$message.error("添加失败");
      }
      console.log(res);
      this.$message.success("添加成功");
      this.addTreeForm = {
        addTypeArr: [],
      };
      this.getStandardTree();
      this.getTableByClick(this.selectData,this.versionValue);
      this.getTableByClick(this.selectData, this.versionValue);
    },
    changeCascader(data) {
      this.addTreeForm.addTypeArr = data;
@@ -457,20 +464,6 @@
      this.isAllSelect = !this.isAllSelect;
      let data = this.tableData;
      this.toggleSelect(data, this.isAllSelect, "all");
      // 自定义
      if (this.isAllSelect) {
        val.forEach((i) => {
          if (i.id !== undefined) {
            this.deleteList.push(i.id);
          } else {
            i.children.forEach((c) => {
              this.deleteList.push(c.id);
            });
          }
        });
      } else {
        this.deleteList.splice(0, this.deleteList.length);
      }
    },
    //选择某行
    selectTr(selection, row) {
@@ -479,33 +472,6 @@
        this.isAllSelect = row.isChecked;
        this.toggleSelect(row, row.isChecked, "tr");
      });
      if (row.isChecked === true) {
        if (row.children !== undefined) {
          row.children.forEach((i) => {
            this.deleteList.push(i.id);
          });
        } else {
          this.deleteList.push(row.id);
        }
      } else if (row.isChecked === false) {
        if (row.children !== undefined) {
          row.children.forEach((i) => {
            this.deleteList.findIndex((c, index) => {
              if (c === i.id) {
                this.deleteList.splice(index, 1);
                return;
              }
            });
          });
        }
        this.deleteList.findIndex((c, index) => {
          if (c === row.id) {
            this.deleteList.splice(index, 1);
            return;
          }
        });
      }
    },
    //递归子级
    toggleSelect(data, flag, type) {
@@ -539,6 +505,15 @@
        }
      });
    },
    handleSelectionChange(val) {
      this.deleteList = [];
      val.forEach((v) => {
        if (v.id !== undefined) {
          this.deleteList.push(v.id);
        }
      });
      console.log(`output->this.deleteList`, this.deleteList);
    },
    // 表格树全部选中配置  结束
    deleteListClick() {
      deleteListApi(this.deleteList).then((res) => {
@@ -546,7 +521,7 @@
          message: res.message,
          type: "success",
        });
        this.getTableByClick(this.selectData,this.versionValue);
        this.getTableByClick(this.selectData, this.versionValue);
      });
    },
    async requiredOnfocus(scope) {
@@ -561,7 +536,7 @@
          message: res.message,
          type: "success",
        });
        this.getTableByClick(this.selectData,this.versionValue);
        this.getTableByClick(this.selectData, this.versionValue);
      });
    },
  },
@@ -697,8 +672,8 @@
  width: 100%;
  padding-bottom: 6px;
  text-align: right;
  .el-select{
    margin-right:20px;
  .el-select {
    margin-right: 10px;
  }
}
.tipMsg {