lkk
3 天以前 33de1cf5576373b99dc2a6ed4be097f4d6ad0892
src/views/system/package/index.vue
@@ -118,8 +118,12 @@
        <el-form-item label="折扣">
          <el-input-number style="width: 150px" v-model="youhui" :precision="2" :step="0.1" :max="10" :min="0.1" @change="debounceNumberChange" :debounce="3000"></el-input-number>
        </el-form-item>
        <el-form-item label="现价" prop="xianprice">
        <!-- <el-form-item label="现价" prop="xianprice">
          <el-input v-model="form.xianprice" placeholder="现价" clearable style="width: 140px" @input="changeXianjia" @blur="numberChangeXianPrice(youhui, youhui)" type="number" :debounce="3000" min="0"/>
        </el-form-item> -->
        <el-form-item label="现价" prop="xianprice">
          <el-input v-model="form.xianprice" placeholder="现价" clearable style="width: 140px" @input="changeXianjia"
            type="number" :debounce="3000" min="0"/>
        </el-form-item>
        <el-form-item label="关键字" prop="keywords">
          <el-select multiple v-model="form.keywords" placeholder="请选择关键字" style="width: 160px" @change="sel" filterable clearable>
@@ -147,7 +151,7 @@
      <el-row style="display: flex; width: 1300px">
        <el-col>
          <div style="text-align: center; margin-bottom: 10px; margin-top: 10px">项目列表</div>
          <el-input placeholder="输入关键字进行过滤" v-model="filterText" @input="debounceFilter" clearable />
          <el-input placeholder="输入关键字进行过滤" v-model="queryParams1.nr" @input="handleFilterInput" clearable />
          <div class="tab3" style="height: 365px">
            <el-tree
              class="filter-tree"
@@ -158,6 +162,7 @@
              node-key="proId"
              @check-change="handleCurrentChecked"
              :default-checked-keys="checkedkey"
              :filter-node-method="filterNode"
              ref="tree"
              :render-content="renderContent"
            >
@@ -291,6 +296,7 @@
        page: 1,
        pageSize: 30,
        nr: "",
        xb: "",
      },
      form: {
        xianprice: null,
@@ -315,11 +321,12 @@
    this.getCategory();
  },
  methods: {
    debounceFilter() {
      clearTimeout(this.debounceTimer);
      this.debounceTimer = setTimeout(() => {
        this.filterTree();
      }, 600);
    handleFilterInput() {
      this.queryParams1.page = 1;
      this.getDataList();
      this.$nextTick(() => {
        this.$refs.tree.setCheckedKeys(this.checkedNodes);
      });
    },
    filterTree() {
      if (!this.filterText) {
@@ -328,6 +335,15 @@
      }
      const filterTextLower = this.filterText.toLowerCase();
      this.filteredTreeData = this.filterNodes(this.originalTreeData, filterTextLower);
    },
    filterNode(value, data) {
      if (!value) return true;
      console.log(value, 6666);
      return (
        data.proName.indexOf(value) !== -1 ||
        (data.proEngName && data.proEngName.indexOf(value) !== -1)
      );
    },
    filterNodes(nodes, filterText) {
      return nodes.filter(node => {
@@ -413,9 +429,30 @@
        this.keywordList = response.rows;
      });
    },
    sel(val) {
    /* sel(val) {
      let id = val;
      this.keys = id.join(",");
    }, */
    sel(val) {
      const maleId = "4"; // “男”的 ID
      const femaleId = "5"; // “女”的 ID
      let selectedIds = [...val]; // 复制当前选中的 ID 数组
      // 实现“男”和“女”互斥逻辑
      if (selectedIds.includes(maleId) && selectedIds.includes(femaleId)) {
        selectedIds = selectedIds.slice(-1); // 保留最后选中的一个
        this.$message.warning("“男”和“女”关键字互斥,只能选择一个!");
      }
      // 更新 form.keywords 和 keys
      this.form.keywords = selectedIds;
      this.keys = selectedIds.join(",");
      // 调用 getDataList,传递所有选中的关键字 ID(逗号分隔)
      // this.getDataList({ xb: this.keys });
      this.queryParams1.xb = this.keys; // 👈 更新查询参数
      this.queryParams1.page = 1; // 👈 切换条件时重置页码
      this.getDataList(); // 不需要再传参了
    },
    getCategory() {
      this.loading = true;
@@ -661,9 +698,10 @@
        </span>
      );
    },
    getDataList() {
    getDataList(params = {}) {
      this.loading = true;
      search(this.queryParams1).then((response) => {
      const query = { ...this.queryParams1, ...params };
      search(query).then((response) => {
        this.Treedata = response.data.list;
        this.total1 = response.data.total;
        this.pics = this.DataList.reduce((total, item) => total + item.priceOrd, 0);
@@ -672,8 +710,8 @@
        this.$nextTick(() => {
          this.$refs.tree.setCheckedKeys(this.checkedNodes);
          this.initializing = false;
          this.loading = false;
        });
        this.loading = false;
      }).catch(() => {
        this.loading = false;
      });
@@ -777,7 +815,7 @@
      this.DataList = this.DataList.filter((item) => item.proParentId !== row.proParentId);
      this.TotalPrice1 = this.DataList.reduce((sum, item) => sum + item.priceOrd, 0);
    },
    submitForm() {
    /* submitForm() {
      this.form.limits = this.youhui;
      this.form.price = this.pics;
      this.form.priceNow = this.form.xianprice;
@@ -813,6 +851,85 @@
        this.open = false;
        this.getList();
      });
    }, */
    submitForm() {
      // 检查现价是否发生变化
      if (this.form.xianprice !== this.lastXianPrice) {
        this.$confirm("确定修改所有子项的折扣吗?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }).then(() => {
          // 更新所有子项的折扣
          this.youhui = (Math.floor((this.form.xianprice / this.pics) * 100) / 100) * 10;
          let totalYsprice = new Big(0);
          this.DataList.forEach((item) => {
            item.limits = this.youhui;
            const ordPrice = new Big(item.priceOrd);
            const discount = new Big(item.limits);
            const result = ordPrice.times(discount.div(10));
            item.priceNow = result.toNumber();
            totalYsprice = totalYsprice.plus(new Big(item.priceNow));
          });
          if (!totalYsprice.eq(this.form.xianprice)) {
            const diff = new Big(this.form.xianprice).minus(totalYsprice);
            if (this.DataList.length > 0) {
              const lastItem = this.DataList[this.DataList.length - 1];
              const newYsPrice = new Big(lastItem.priceNow).plus(diff).toNumber();
              this.$set(this.DataList[this.DataList.length - 1], "priceNow", newYsPrice);
            }
          }
          // 保存数据
          return this.saveData();
        }).catch(() => {
          // 用户取消操作,恢复原来的现价
          this.form.xianprice = this.lastXianPrice;
        });
      } else {
        // 现价没有变化,直接保存
        this.saveData();
      }
    },
     // 新增一个方法处理保存逻辑
     saveData() {
      this.form.limits = this.youhui;
      this.form.price = this.pics;
      this.form.priceNow = this.form.xianprice;
      if (this.keys) {
        this.form.keywords = this.keys;
      }
      let packageProjects = [];
      this.DataList.forEach((item) => {
        packageProjects.push({
          proName: item.proName,
          proId: item.proId,
          priceNow: item.priceNow,
          limits: item.limits,
          priceOrd: item.priceOrd,
        });
      });
      let data = {
        pacName: this.form.pacName,
        limits: this.form.limits,
        pacStatus: this.form.pacStatus,
        packageProjects: packageProjects,
        newPrice: this.form.xianprice,
        price: this.pics,
        pacId: this.form.pacId || null,
        isOnSale: this.form.isOnSale,
        sort: this.form.sort,
        retailPrice: this.form.retailPrice,
        tjCategory: this.form.tjCategory,
        pacRemark: this.form.pacRemark,
        detail: this.form.detail,
      };
      return saveOreditTjPacNew(data).then((res) => {
        this.open = false;
        this.getList();
      });
    },
    handleDelete(row) {
      const pacIds = row.pacId || this.ids;