1
wwl
2025-04-02 ba9feade5bf2759e64815e72e2b247d9a8b9c27e
src/views/system/comp/index.vue
@@ -1,5 +1,45 @@
<template>
  <div class="app-container">
    <el-dialog title="选择套餐" :visible.sync="taocan" width="70%" height="700px" :close-on-click-modal="false">
  <el-form :model="queryParam" ref="queryForm" size="small" :inline="true" label-width="auto">
    <el-form-item label="套餐名称" prop="pacName">
      <el-input
        v-model="queryParam.pacName"
        placeholder="请输入套餐名称"
        clearable
        @keyup.enter.native="handle"
        style="width: 200px"
      />
    </el-form-item>
    <el-form-item>
      <el-button
        type="primary"
        icon="el-icon-search"
        size="mini"
        @click="handle"
      >搜索</el-button>
    </el-form-item>
  </el-form>
  <el-table
    v-loading="loading"
    element-loading-text="正在加载中..."
    element-loading-spinner="el-icon-loading"
    border
    :data="newpacName1"
    @selection-change="handleSelectionChange1"
    height="450px"
    ref="tb"
  >
    <el-table-column type="selection" width="40px" align="center" label="选择" />
    <el-table-column label="套餐名称" align="center" prop="pacName" width="120px" />
    <el-table-column label="套餐价格" align="center" prop="price" width="120px" />
    <el-table-column label="套餐明细" align="center" prop="allProName" :show-overflow-tooltip="true" />
  </el-table>
  <span slot="footer" class="dialog-footer">
    <el-button @click="cancel1">取 消</el-button>
    <el-button type="primary" @click="submit">确 定</el-button>
  </span>
</el-dialog>
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px"
      @submit.native.prevent>
      <el-form-item label="单位名称" prop="cnName">
@@ -289,8 +329,10 @@
                </template>
              </el-table-column>
            </el-table>
            <div style="font-size: 16px;margin-top: 10px;">当前项目条数:<span style="font-weight: 700;">{{ OnenewpacName.length }}</span>条</div>
            <div style="font-size: 16px;margin-top: 10px;">当前项目条数:<span style="font-weight: 700;">{{
              OnenewpacName.length
            }}</span>条</div>
          </el-col>
          <el-col :span="2" :xs="24">
            <div style="margin: 240% 16%">
@@ -300,6 +342,9 @@
          <el-col :span="8" :xs="24">
            <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
              label-width="68px" @submit.native.prevent>
              <el-form-item>
                <el-button type="primary" @click="Package" size="mini" style="margin-right: 20px">选择套餐</el-button>
              </el-form-item>
              <el-form-item label="项目名称" prop="proName">
                <el-input ref="inputName" v-model="queryParams.proName" placeholder="请输入项目名称" clearable
                  @keyup.enter.native="handleSearchFor" style="width: 140px" />
@@ -370,8 +415,10 @@
                </template>
              </el-table-column>
            </el-table>
            <div style="font-size: 16px;margin-top: 10px;">当前项目条数:<span style="font-weight: 700;">{{ OnenewpacName.length }}</span>条</div>
            <div style="font-size: 16px;margin-top: 10px;">当前项目条数:<span style="font-weight: 700;">{{
              OnenewpacName.length
            }}</span>条</div>
          </el-col>
          <el-col :span="2" :xs="24">
            <div style="margin: 240% 16%" class="btntoleft">
@@ -386,6 +433,10 @@
          <el-col :span="7" :xs="24">
            <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
              label-width="68px" @submit.native.prevent>
              <el-form-item>
                <el-button type="primary" @click="Package" size="mini" style="margin-right: 20px">选择套餐</el-button>
              </el-form-item>
              <el-form-item label="项目名称" prop="proName">
                <el-input ref="inputName" v-model="queryParams.proName" placeholder="请输入项目名称" clearable
                  @keyup.enter.native="handleSearchFor" style="width: 140px" />
@@ -459,8 +510,10 @@
                </template>
              </el-table-column>
            </el-table>
            <div style="font-size: 16px;margin-top: 10px;">当前项目条数:<span style="font-weight: 700;">{{ OnenewpacName.length }}</span>条</div>
            <div style="font-size: 16px;margin-top: 10px;">当前项目条数:<span style="font-weight: 700;">{{
              OnenewpacName.length
            }}</span>条</div>
          </el-col>
          <el-col :span="2" :xs="24">
            <div style="margin: 240% 16%">
@@ -472,6 +525,9 @@
          <el-col :span="8" :xs="24">
            <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
              label-width="68px" @submit.native.prevent>
              <el-form-item>
                <el-button type="primary" @click="Package" size="mini" style="margin-right: 20px">选择套餐</el-button>
              </el-form-item>
              <el-form-item label="项目名称" prop="proName">
                <el-input ref="inputName" v-model="queryParams.proName" placeholder="请输入项目名称" clearable
                  @keyup.enter.native="handleSearchFor" style="width: 140px" />
@@ -582,8 +638,9 @@
  getPackageList,
  delegrouping,
  getDetails,
} from "@/api/system/comp";
import { deptTreeSelect, projectGetList, getconfigKey } from "@/api/system/tijian";
import { deptTreeSelect, projectGetList, getconfigKey,} from "@/api/system/tijian";
import { getInfo } from "@/api/login";
export default {
  name: "Comp",
@@ -605,6 +662,15 @@
      }
    };
    return {
      newpacName1: [],
      taocan: false,
      queryParam: {
        pageNum: 1,
        pageSize: 10,
        pacName: null,
        pacRemark: null,
      },
      // 遮罩层
      loading: true,
      Treedata: [],
@@ -737,6 +803,71 @@
    this.getList();
  },
  methods: {
    handleSelectionChange1(selection) {
  // 实现单选逻辑
  if (selection.length > 1) {
    const lastSelected = selection[selection.length - 1];
    this.$refs.tb.clearSelection();
    this.$refs.tb.toggleRowSelection(lastSelected, true);
    this.selectedPackage = lastSelected;
  } else if (selection.length === 1) {
    this.selectedPackage = selection[0];
  } else {
    this.selectedPackage = null;
  }
},
submit() {
  if (!this.selectedPackage) {
    this.$modal.msgError("请先选择一个套餐");
    return;
  }
  // 清空左侧表格
  this.OnenewpacName = [];
  // 获取选中的套餐项目列表
  const newProjects = this.selectedPackage.tjProjectList || [];
  // 将选中的套餐项目添加到左侧表格
  this.loading = true;
  newProjects.forEach(project => {
    // 为每个项目设置默认折扣和现价
    this.$set(project, 'limits', 10); // 默认折扣 10(即原价)
    this.$set(project, 'ysPrice', project.proPrice); // 现价初始化为原价
    this.OnenewpacName.push(project);
  });
  // 更新总价和现价
  this.queryParams.price = this.OnenewpacName.reduce((sum, item) => {
    return sum + (item.proPrice || 0);
  }, 0);
  this.queryParams.xianprice = this.OnenewpacName.reduce((sum, item) => {
    return sum + (item.ysPrice || 0);
  }, 0);
  // 更新优惠值
  this.youhui = this.queryParams.price > 0
    ? (Math.floor((this.queryParams.xianprice / this.queryParams.price) * 100) / 100) * 10
    : 0;
  // 关闭对话框
  this.taocan = false;
  this.loading = false;
  this.$modal.msgSuccess("添加成功");
},
    cancel1() {
      this.taocan = false;
    },
    Package() {
      this.taocan = true;
      deptTreeSelect(this.forms.sex).then((res) => {
        if (res.rows) {
          this.newpacName1 = res.rows
        }
      });
    },
    handleManualChange(row) {
      console.log("这是主动出发的");
      this.updateProPrice(row);
@@ -985,49 +1116,49 @@
    },
    numberChangeXianPrice(currentValue, oldValue) {
  // 如果现价没有变化,直接返回
  if (this.queryParams.xianprice === this.lastXianPrice || !this.queryParams.xianprice) {
    return;
  }
  this.$confirm("确定修改所有子项的折扣吗?", "提示", {
    confirmButtonText: "确定",
    cancelButtonText: "取消",
    type: "warning",
  })
    .then(() => {
      // 确保修改折扣的值
      this.youhui = currentValue;
      let totalYsprice = new Big(0); // 初始化总 ysprice
      // 遍历每个项目,更新每个子项的价格
      this.OnenewpacName.forEach((item) => {
        item.limits = this.youhui;
        const proPrice = new Big(item.proPrice);
        const limits = new Big(item.limits);
        const result = proPrice.times(limits.div(10));  // ordPrice * (discount / 10)
        item.ysPrice = result.toNumber();
        totalYsprice = totalYsprice.plus(new Big(item.ysPrice));
      });
      // 如果总的 ysPrice 和查询参数中的 xianprice 不一致,进行调整
      if (!totalYsprice.eq(this.queryParams.xianprice)) {
        const diff = new Big(this.queryParams.xianprice).minus(totalYsprice);
        // 如果 OnenewpacName 数组不为空,调整最后一项的 ysPrice
        if (this.OnenewpacName.length > 0) {
          const lastItem = this.OnenewpacName[this.OnenewpacName.length - 1];
          const newYsPrice = new Big(lastItem.ysPrice).plus(diff).toNumber();
          // 使用 $set 确保响应性更新
          this.$set(this.OnenewpacName[this.OnenewpacName.length - 1], 'ysPrice', newYsPrice);
        }
      // 如果现价没有变化,直接返回
      if (this.queryParams.xianprice === this.lastXianPrice || !this.queryParams.xianprice) {
        return;
      }
      // 更新 lastXianPrice 以便下次比较
      this.lastXianPrice = this.queryParams.xianprice;
    })
    .catch(() => {
      // 如果取消修改,恢复原有的优惠值
      this.youhui = oldValue;
    });
},
      this.$confirm("确定修改所有子项的折扣吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          // 确保修改折扣的值
          this.youhui = currentValue;
          let totalYsprice = new Big(0); // 初始化总 ysprice
          // 遍历每个项目,更新每个子项的价格
          this.OnenewpacName.forEach((item) => {
            item.limits = this.youhui;
            const proPrice = new Big(item.proPrice);
            const limits = new Big(item.limits);
            const result = proPrice.times(limits.div(10));  // ordPrice * (discount / 10)
            item.ysPrice = result.toNumber();
            totalYsprice = totalYsprice.plus(new Big(item.ysPrice));
          });
          // 如果总的 ysPrice 和查询参数中的 xianprice 不一致,进行调整
          if (!totalYsprice.eq(this.queryParams.xianprice)) {
            const diff = new Big(this.queryParams.xianprice).minus(totalYsprice);
            // 如果 OnenewpacName 数组不为空,调整最后一项的 ysPrice
            if (this.OnenewpacName.length > 0) {
              const lastItem = this.OnenewpacName[this.OnenewpacName.length - 1];
              const newYsPrice = new Big(lastItem.ysPrice).plus(diff).toNumber();
              // 使用 $set 确保响应性更新
              this.$set(this.OnenewpacName[this.OnenewpacName.length - 1], 'ysPrice', newYsPrice);
            }
          }
          // 更新 lastXianPrice 以便下次比较
          this.lastXianPrice = this.queryParams.xianprice;
        })
        .catch(() => {
          // 如果取消修改,恢复原有的优惠值
          this.youhui = oldValue;
        });
    },
    changegroupingName() {