wwl
2025-01-09 57a75e1b470992697b4263601aa8361fdf5790c7
src/views/system/package/index.vue
@@ -301,8 +301,9 @@
    <el-dialog
      :title="title"
      :visible.sync="open"
      width="1100px"
      width="1500px"
      append-to-body
      :close-on-click-modal="false"
    >
      <el-form
        ref="form"
@@ -424,12 +425,49 @@
            style="width: 150px"
          />
        </el-form-item>
        <el-form-item label="原价" prop="counterPrice">
        <el-form-item label="原价" prop="pics">
          <el-input
            v-model="form.counterPrice"
            v-model="pics"
            placeholder="请输入原价"
            style="width: 150px"
          />
        </el-form-item>
        <el-form-item label="折扣">
          <el-input-number
            ref="inputNumber"
            style="width: 150px"
            v-model="youhui"
            :precision="2"
            :step="0.1"
            :max="10"
            :min="1"
            @change="numberChange"
          ></el-input-number>
        </el-form-item>
        <el-form-item label="优惠价">
          <el-input
            ref="inputName"
            v-model="form.xianprice"
            placeholder="优惠价"
            clearable
            style="width: 140px"
          />
        </el-form-item>
        <el-form-item label="体检类别" prop="tjCategory">
          <el-select
            v-model="form.tjCategory"
            placeholder="请选择体检类别"
            style="width: 150px"
            filterable
            clearable
          >
            <el-option
              v-for="dict in dict.type.dict_tjtype"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <div v-if="!isCollapsed" style="display: flex">
@@ -498,8 +536,8 @@
        </el-table-column>
      </el-table> -->
      <el-row :gutter="20">
        <el-col :span="6">
      <el-row :gutter="11">
        <el-col :span="11">
          <div
            style="text-align: center; margin-bottom: 10px; margin-top: 10px"
          >
@@ -519,11 +557,12 @@
              :default-checked-keys="checkedkey"
              :filter-node-method="filterNode"
              ref="tree"
              :render-content="renderContent"
            >
            </el-tree>
          </div>
        </el-col>
        <el-col :span="6">
        <!--  <el-col :span="6">
          <div
            style="text-align: center; margin-bottom: 10px; margin-top: 10px"
          >
@@ -541,30 +580,55 @@
              @check-change="handleCurrentChecked1"
              :default-checked-keys="checkedListkey"
              ref="trees"
              :render-content="renderContent"
            >
            </el-tree>
          </div>
        </el-col>
        </el-col> -->
        <el-col :span="11">
          <div class="grid-content bg-purple">
            <div
              style="text-align: center; margin-bottom: 10px; margin-top: 10px"
              style="
                text-align: center;
                margin-bottom: 10px;
                margin-top: 10px;
                margin-left: 16%;
              "
            >
              已选项目列表
            </div>
            <el-table
              :data="DataList"
              border
              style="width: 100%"
              style="width: 80%; margin-left: 18%"
              height="400"
              :span-method="objectSpanMethod"
            >
              <el-table-column prop="propinName" label="检查项目">
              <el-table-column prop="proName" label="检查项目">
              </el-table-column>
              <el-table-column prop="proName" label="明细项目" width="260px">
              <el-table-column prop="proPrice" label="原价" align="center">
              </el-table-column>
              <el-table-column prop="proPrice" label="原价" width="56px">
              <el-table-column label="折扣">
                <template slot-scope="scope">
                  <!-- 只输入纯数字折扣 -->
                  <el-input
                    v-model.number="scope.row.limits"
                    @input="calculateDiscount(scope.row)"
                    placeholder="输入折扣"
                    size="small"
                    type="number"
                    min="0"
                    step="0.1"
                    max="10"
                  >
                  </el-input>
                </template>
              </el-table-column>
              <el-table-column prop="priceNow" label="优惠价" align="center">
              </el-table-column>
              <!-- <el-table-column prop="proName" label="明细项目" width="260px">
              </el-table-column> -->
              <!-- <el-table-column
                label="操作"
@@ -584,6 +648,7 @@
                </template> 
              </el-table-column>-->
            </el-table>
            <!-- <h3 style="font-weight: 600">合计:{{ pics }}元</h3> -->
          </div>
        </el-col>
      </el-row>
@@ -632,15 +697,16 @@
  getAllList,
  updateProject,
  getPacTjProjectList,
  saveOreditTjPacNew,
} from "@/api/system/package";
import { Message } from "element-ui";
import Big from "big.js";
export default {
  name: "Package",
  dicts: ["sys_normal_disable", "sys_yes_no"],
  dicts: ["sys_normal_disable", "sys_yes_no", "dict_tjtype"],
  components: { Packages },
  data() {
    let checkPhoneNum = (rule, value, callback) => {
      console.log(value);
      let patter = new RegExp(/^1\s*[3456789]\s*(\d\s*){9}$/);
      if (value == "" && value == undefined && !value) {
        return callback("");
@@ -651,10 +717,12 @@
      }
    };
    return {
      pics: 0,
      filterText: "",
      DataList: [],
      list1: true,
      activeName: "1",
      num: 1,
      checkedObj: {},
      dataObj: {},
      Treedata: [],
@@ -696,6 +764,7 @@
      newproName: [],
      // 所有体检项目·
      allList: [],
      treeList: [],
      // 所有套餐数据
      // allpackage:[],
      // 弹出层标题
@@ -712,8 +781,13 @@
        pacRemark: null,
      },
      // 表单参数
      form: {},
      form: {
        xianprice: null, // 优惠价
        counterPrice: null, //原价
        limits: 10,
      },
      forms: {},
      youhui: 10,
      // 表单校验
      rules: {
        deleted: [
@@ -749,6 +823,7 @@
      this.$refs.tree.filter(val);
    },
  },
  created() {
    this.getList();
    this.getKeyword();
@@ -760,7 +835,12 @@
    },
    filterNode(value, data) {
      if (!value) return true;
      return data.proName.indexOf(value) !== -1;
      // return data.proName.indexOf(value) !== -1;
      if (data.proName.indexOf(value) !== -1) {
        return data.proName.indexOf(value) !== -1;
      } else {
        return data.proEngName.indexOf(value) !== -1;
      }
    },
    /** 查询体检套餐列表 */
    getList() {
@@ -794,7 +874,6 @@
      });
    },
    sel(val) {
      console.log(val);
      let id = val;
      this.keys = "";
      id.forEach((item) => {
@@ -808,9 +887,7 @@
        this.categoryList = response.rows;
      });
    },
    shangpin(vals) {
      console.log(vals);
    },
    shangpin(vals) {},
    // 取消按钮
    cancel() {
      this.open = false;
@@ -876,6 +953,8 @@
      this.open = true;
      this.title = "体检套餐信息维护";
      this.DataList = [];
      this.checkedkey = [];
      this.checkedListkey = [];
      this.getDataList();
      // getAllList().then((response) => {
      //   this.allList = response.data;
@@ -928,9 +1007,10 @@
      // });
      getPacInFo(this.forms.pacId).then((response) => {
        this.form = response.data;
        this.form.keywords=this.form.keywords.slice(0, -1);
        this.form.keywords = this.form.keywords.slice(0, -1);
        this.form.keywords = this.form.keywords.split(",");
        this.DataList = [];
        // this.pics = 0;
        this.checkedkey = [];
        this.checkedListkey = [];
        this.getDataList();
@@ -942,7 +1022,7 @@
      this.open = true;
      getPacInFo(row.pacId).then((response) => {
        this.form = response.data;
        this.form.keywords=this.form.keywords.slice(0, -1);
        this.form.keywords = this.form.keywords.slice(0, -1);
        this.form.keywords = this.form.keywords.split(",");
        this.DataList = [];
        this.checkedkey = [];
@@ -1029,9 +1109,56 @@
      return this.form.tjProjectList;
    },
    //  // 默认接受四个值 { 当前行的值, 当前列的值, 行的下标, 列的下标 }
    numberChange(currentValue, oldValue) {
      this.$confirm("确定修改所有子项的折扣吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.youhui = currentValue;
          /*    if (this.youhui < 10) {
            this.youhui = 10;
            // this.$modal.msgError(`该人员最高优惠权限为${this.getInfodis}折`);
          } */
          this.DataList.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));
            item.priceNow = result.toNumber();
            this.form.xianprice = this.DataList.reduce((sum, item) => {
              return sum.plus(new Big(item.priceNow || "0"));
            }, new Big(0));
          });
        })
        .catch(() => {
          this.youhui = oldValue;
        });
    },
    updateProPrice(row) {
      const proPrice = new Big(row.proPrice);
      const limits = new Big(row.limits);
      const result = proPrice.times(limits.div(10)); // ordPrice * (discount / 10)
      row.priceNow = result.toNumber();
      this.form.xianprice = this.DataList.reduce((sum, item) => {
        return sum.plus(new Big(item.priceNow || "0"));
      }, new Big(0)).toNumber();
      this.youhui =
        (Math.floor((this.form.xianprice / this.pics) * 100) / 100) * 10;
    },
    calculateDiscount(row) {
      if (row.limits > 10) {
        row.limits = 10; // 强制将值设置为最大值
      } else if (row.limits < 0) {
        row.limits = 0; // 强制将值设置为最小值
      }
      this.updateProPrice(row); // 更新价格或其他逻辑
    },
    // 默认接受四个值 { 当前行的值, 当前列的值, 行的下标, 列的下标 }
    objectSpanMethod({ row, column, rowIndex, columnIndex }) {
      // console.log(row, column, rowIndex, columnIndex);
      let fields = ["propinName"];
      let cellValue = row[column.property];
      if (cellValue && fields.includes(column.property)) {
@@ -1050,7 +1177,14 @@
        }
      }
    },
    renderContent(h, { node, data, store }) {
      return (
        <span class="custom-tree-node">
          <span>{node.label}</span>
          <span>({data.proPrice}元)</span>
        </span>
      );
    },
    getDataList() {
      this.loading = true;
      getProParentIdDxList().then((response) => {
@@ -1060,7 +1194,19 @@
            this.Treedata.forEach((item1) => {
              if (item.proId == item1.proId) {
                this.checkedkey.push(item1.proId);
                let proId = item1.proId;
                this.DataList.push(item1);
                this.DataList.forEach((item1) => {
                  item1.limits = 10;
                  if (item1.limits > 10) {
                    item1.limits = 10; // 强制将值设置为最大值
                  } else if (item1.limits < 0) {
                    item1.limits = 0; // 强制将值设置为最小值
                  }
                  this.updateProPrice(item1); // 更新价格或其他逻辑
                });
                /* let proId = item1.proId;
                getProSonDxList(proId).then((res) => {
                  this.TreedataList = res.data.list;
                  this.TreedataList.forEach((item2) => {
@@ -1074,16 +1220,29 @@
                          item.propinPrice = item1.proPrice;
                        }
                      });
                      this.pics = 0;
                      this.DataList.forEach((item) => {
                        this.pics += item.proPrice;
                      });
                    }
                  });
                });
                }); */
              }
            });
          });
        } else {
          this.checkedkey.push(this.Treedata[0].proId);
          let proId = this.Treedata[0].proId;
          getProSonDxList(proId).then((res) => {
          this.TreedataList = this.Treedata.filter(
            (item) => item.proId == proId
          );
          // 将第一个项目添加到 DataList
          this.TreedataList.forEach((item) => {
            this.checkedListkey.push(item.proId);
            this.DataList.push(item);
          });
          /*  getProSonDxList(proId).then((res) => {
            this.TreedataList = res.data.list;
            this.TreedataList.forEach((item) => {
              item.disabled = true;
@@ -1093,14 +1252,65 @@
                item.propinName = this.Treedata[0].proName;
                item.propinPrice = this.Treedata[0].proPrice;
              });
              this.pics = 0;
              this.DataList.forEach((item) => {
                this.pics += item.proPrice;
              });
            });
          });
          }); */
        }
        this.pics = this.DataList.reduce(
          (total, item) => total + item.proPrice,
          0
        );
        this.loading = false;
      });
    },
    handleCurrentChecked(data, checked, checkedNodes) {
      console.log(data, checked);
      this.dataObj = data;
      this.checkedObj = checked;
      if (checked == true) {
        // 将选中的项目添加到 DataList
        this.checkedListkey.push(data.proId);
        this.DataList.push({
          proId: data.proId,
          proName: data.proName,
          proPrice: data.proPrice, // 原价
          limits: 10, // 默认折扣(100%)
          priceNow: data.proPrice, // 默认优惠价与原价相同
        });
        // 重新计算总价
        this.pics = 0;
        this.TotalPrice1 = 0;
        this.DataList.forEach((item) => {
          this.pics += item.proPrice;
          this.form.counterPrice += item.proPrice;
          this.TotalPrice1 += item.proPrice; // 可以根据需要改成优惠价 `priceNow`
        });
      } else if (checked == false) {
        // 从 DataList 中移除取消选中的项目
        let index = this.DataList.findIndex(
          (item) => item.proId === data.proId
        );
        if (index !== -1) {
          this.DataList.splice(index, 1);
        }
        // 重新计算总价
        this.pics = 0;
        this.TotalPrice1 = 0;
        this.DataList.forEach((item) => {
          this.pics += item.proPrice;
          this.form.counterPrice += item.proPrice;
          this.TotalPrice1 += item.proPrice; // 可以根据需要改成优惠价 `priceNow`
        });
      }
    },
    /* handleCurrentChecked(data, checked, checkedNodes) {
      this.dataObj = data;
      this.checkedObj = checked;
      if (checked == true) {
@@ -1113,7 +1323,9 @@
            this.checkedListkey.push(item.proId);
            this.DataList.push(item);
            this.spliceData();
            this.pics = 0;
            this.DataList.forEach((item1) => {
              this.pics += item1.proPrice;
              if (item1.proParentId == data.proId) {
                item1.propinName = data.proName;
                item1.propinPrice = this.dataObj.proPrice;
@@ -1121,10 +1333,12 @@
            });
          });
          this.TotalPrice1 = 0;
          this.pics = 0;
          if (this.DataList.length != 0) {
            this.list1 = false;
            this.DataList.forEach((item) => {
              this.TotalPrice1 = item.proPrice + this.TotalPrice1;
              this.pics += item.proPrice;
            });
          }
        });
@@ -1136,15 +1350,18 @@
            item.disabled = true;
          });
          this.checkedListkey = [];
          console.log(this.TreedataList.length);
          this.DataList.forEach((item, index) => {
            if (item.proParentId == this.dataObj.proId) {
              this.DataList.splice(index, this.TreedataList.length);
            }
          });
          this.pics = 0;
          this.DataList.forEach((item, index) => {
            this.pics += item.proPrice;
          });
        });
      }
    },
    }, */
    spliceData() {
      for (var i = 0; i < this.DataList.length; i++) {
@@ -1166,14 +1383,18 @@
          if (item.proId == data.proId) {
            this.DataList.splice(index, 1);
            this.TotalPrice1 = 0;
            this.pics = 0;
            this.DataList.forEach((item1) => {
              this.TotalPrice1 = item1.proPrice + this.TotalPrice1;
              this.pics += item1.proPrice;
              // this.TotalPrice1 = item1.proPrice + this.TotalPrice1;
            });
          }
        });
      } else if (checked == true) {
        this.DataList.push(data);
        this.pics = 0;
        this.DataList.forEach((item1) => {
          this.pics += item1.proPrice;
          if (item1.proParentId == this.dataObj.proId) {
            item1.propinName = this.dataObj.proName;
            item1.propinPrice = this.dataObj.proPrice;
@@ -1181,8 +1402,10 @@
        });
        this.spliceData();
        this.TotalPrice1 = 0;
        this.pics = 0;
        this.DataList.forEach((item1) => {
          this.TotalPrice1 = item1.proPrice + this.TotalPrice1;
          // this.TotalPrice1 = item1.proPrice + this.TotalPrice1;
          this.pics += item1.proPrice;
        });
      }
    },
@@ -1204,10 +1427,67 @@
    /** 提交按钮 */
    submitForm() {
      console.log(this.form, 999);
      this.form.limits = this.youhui;
      this.form.price = this.pics;
      this.form.priceNow = this.queryParams.xianprice;
      if (this.keys) {
        this.form.keywords = this.keys; // 如果有 this.keys,则直接赋值
      } else {
        this.form.keywords = this.form.keywords.toString(); // 如果没有,则将 this.form.keywords 转成字符串
      }
      let packageProjects = []; // 定义一个空数组
      this.DataList.forEach((item) => {
        packageProjects.push({
          proName: item.proName,
          proId: item.proId,
          priceNow: item.priceNow,
          limits: item.limits,
          priceOrd: item.proPrice,
        });
      });
      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,
        keywords: this.form.keywords,
        sort: this.form.sort,
        retailPrice: this.form.retailPrice,
        tjCategory: this.form.tjCategory,
        pacRemark: this.form.pacRemark,
        detail: this.form.detail,
      };
      saveOreditTjPacNew(data).then((res) => {
        console.log(res, 555);
        this.open = false;
        this.getList();
      });
    },
    /* submitForm() {
      if (this.form.pacName) {
        this.form.tjProjectList = [];
        if (this.DataList.length != 0) {
          this.DataList.forEach((item) => {
          this.treeList = JSON.parse(JSON.stringify(this.DataList));
          for (var i = 0; i < this.treeList.length; i++) {
            for (var j = i + 1; j < this.treeList.length; j++) {
              if (
                this.treeList[i].proParentId == this.treeList[j].proParentId
              ) {
                this.treeList.splice(j, 1);
                j--;
              }
            }
          }
          this.treeList.forEach((item) => {
            this.form.tjProjectList.push({
              // id: 0,
              proName: item.propinName,
@@ -1226,12 +1506,12 @@
              // } else {
              //   this.form.pacStatus = 1;
              // }
              if(this.keys){
              if (this.keys) {
                this.form.keywords = this.keys;
              }else{
              } else {
                this.form.keywords = this.form.keywords.toString();
              }
              updatePackage(this.form).then((response) => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
@@ -1244,7 +1524,6 @@
              // } else {
              //   this.form.pacStatus = 1;
              // }
              // console.log(this.form.tjProjectList);
              // return;
              addPackage(this.form).then((response) => {
                this.$modal.msgSuccess("新增成功");
@@ -1257,7 +1536,7 @@
      } else {
        Message.warning("请先填写套餐名称");
      }
    },
    }, */
    /** 删除按钮操作 */
    handleDelete(row) {
      const pacIds = row.pacId || this.ids;
@@ -1385,4 +1664,12 @@
  overflow-y: auto;
  border: 1px solid #d9d9d9;
}
/* .custom-tree-node {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 14px;
    padding-right: 8px;
  } */
</style>