1
wwl
2025-06-10 cee2eca9c3e40b48c40a8fe80f938a777f03d463
src/components/Packagese/index.vue
@@ -1,129 +1,236 @@
<template>
    <div>
        <el-dialog :title="title" :visible.sync="open" width="1200px" append-to-body>
            <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="68px">
                <el-form-item label="编码" prop="pacCode">
                    <el-input v-model="queryParams.pacCode" placeholder="请输入编码" clearable
                        @keyup.enter.native="handleQuery" style="width: 120px;" />
                </el-form-item>
                <el-form-item label="名称" prop="pacName">
                    <el-input v-model="queryParams.pacName" placeholder="请输入名称" clearable
                        @keyup.enter.native="handleQuery" style="width: 130px;" />
                </el-form-item>
                <el-form-item label="内容" prop="pacRemark">
                    <el-input v-model="queryParams.pacRemark" placeholder="请输入内容" clearable
                        @keyup.enter.native="handleQuery" style="width: 130px;" />
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                </el-form-item>
            </el-form>
            <el-table :data="dataList" ref="elTable" v-loading="loading" @selection-change="handleSelectionChange" border
                height="320px">
                <el-table-column type="selection" width="40" align="center" />
                <el-table-column label="序号"  prop="xh" align="center" />
                <el-table-column label="编码" align="center" prop="pacCode" />
                <el-table-column label="名称" align="center" prop="pacName" width="100px" />
                <el-table-column label="拼音码" align="center" prop="detail" width="100px" />
                <el-table-column label="内容" align="center" prop="pacRemark" />
                <el-table-column label="备注" align="center" prop="price" />
            </el-table>
            <span slot="footer" class="dialog-footer">
                <el-button @click="open = false">取 消</el-button>
                <el-button type="primary" @click="handleOk">确 定</el-button>
            </span>
        </el-dialog>
  <div>
    <el-dialog
      :title="title"
      :visible.sync="open"
      width="1200px"
      append-to-body
    >
      <el-form
        :model="queryParams"
        ref="queryForm"
        size="small"
        :inline="true"
        label-width="68px"
      >
        <el-form-item label="编码" prop="pid">
          <el-input
            v-model="queryParams.pid"
            placeholder="请输入编码"
            clearable
            @keyup.enter.native="handleQuery"
            style="width: 120px"
          />
        </el-form-item>
        <el-form-item label="名称" prop="pname">
          <el-input
            v-model="queryParams.pname"
            placeholder="请输入名称"
            clearable
            @keyup.enter.native="handleQuery"
            style="width: 130px"
          />
        </el-form-item>
        <el-form-item label="内容" prop="pym">
          <el-input
            v-model="queryParams.pym"
            placeholder="请输入内容"
            clearable
            @keyup.enter.native="handleQuery"
            style="width: 130px"
          />
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            icon="el-icon-search"
            size="mini"
            @click="handleQuery"
            >搜索</el-button
          >
        </el-form-item>
      </el-form>
      <el-table
        :data="dataList"
        ref="elTable"
        v-loading="loading"
        @selection-change="handleSelectionChange"
        border
        height="320px"
      >
        <el-table-column type="selection" width="40" align="center" />
        <el-table-column label="序号" prop="xh" align="center" />
        <el-table-column label="编码" align="center" prop="pacCode" />
        <el-table-column
          label="名称"
          align="center"
          prop="pacName"
          width="100px"
        />
        <el-table-column
          label="拼音码"
          align="center"
          prop="detail"
          width="100px"
        />
        <el-table-column label="内容" align="center" prop="pacRemark" />
        <el-table-column label="备注" align="center" prop="price" />
      </el-table>
    </div>
      <div class="pag">
        <div class="pag1">
          <pagination
            v-show="total > 0"
            :total="total"
            :page.sync="queryParams.page"
            :limit.sync="queryParams.pageSize"
            @pagination="getAllList"
          />
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="open = false">取 消</el-button>
        <el-button type="primary" @click="handleOk">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import {
  getTjHyBgList,
} from "@/api/hosp/project";
import { getTjHyBgList } from "@/api/hosp/project";
export default {
    name: 'Packagese',
    // props: {
    //     row: {
    //         type: Object,
    //     }
    // },
    data() {
        return {
            open: false,
            openone:false,
            // 弹出层标题
            title: "",
            dataList: [],
            // 遮罩层
            loading: false,
            form: {
                desc: ""
            },
            queryParams: {
                pacCode: "",
                pacName: "",
                pacRemark: "",
            },
            list: [],
            fList: {}
        };
  name: "Packagese",
  props: {
    selectedId: {
      type: String,
      default: "",  // 父组件传递的选中ID
    },
    watch: {
        // 'row'(val, newVla) {
        //     console.log(val,newVla)
        //     this.fList = val
        //     console.log(this.fList);
        // }
    },
    mounted() {
        // this.getList()
    },
    created() {
        // this.getList()
    },
    methods: {
        getAllList(){
            this.openone = true
            getTjHyBgList(this.queryParams).then(res => {
                this.dataList = res.data
            })
        },
        getList() {
            this.openone = false
            Packagestlist(this.queryParams).then(res => {
                this.dataList = res.rows
            })
        },
        handleQuery() {
            // if(this.openone == false){
            //     this.getList()
            // }else  if(this.openone == true){
                this.getAllList()
            // }
        },
        handleSelectionChange(selection) {
            if (selection.length > 1) {
                this.$refs.elTable.clearSelection(); // 清空所有选择
                this.$refs.elTable.toggleRowSelection(selection.pop()); // 设置选择项
            }
            this.list = selection;
            console.log(this.list)
        },
        handleOk() {
            this.open = false
            if (this.list.length == 1) {
                this.$emit('add',this.list);
            }
        }
    }
}
</script>
  },
  data() {
    return {
      open: false,
      title: "",
      dataList: [],
      loading: false,
      queryParams: {
        pid: "",
        pname: "",
        pym: "",
        checktype: "deptdict",
        page: 1,
        pageSize: 10,
      },
      total: 0,
      list: [],
    };
  },
  
<style scoped></style>
  watch: {
    // 监听父组件传递的 selectedId
    selectedId(newVal) {
      // 如果 selectedId 为空,清空所有选中的项
      if (!newVal) {
        this.clearSelection();
      } else {
        this.handleSelectionEcho(newVal);
      }
    },
  },
  methods: {
    // 获取数据
    getAllList() {
      this.loading = true;
      getTjHyBgList(this.queryParams).then((res) => {
        this.dataList = res.data.list;
        this.total = res.data.total;
        this.loading = false;
        // 在获取数据后回显选中项
        this.handleSelectionEcho(this.selectedId);
      });
    },
    // 根据 selectedId 查找对应的项并回显选择
    handleSelectionEcho(selectedId) {
      if (this.dataList.length > 0 && selectedId) {
        const selectedItem = this.dataList.find(
          (item) => item.pacCode === selectedId
        );
        if (selectedItem) {
          this.$nextTick(() => {
            this.$refs.elTable.clearSelection();  // 清除之前的选择
            this.$refs.elTable.toggleRowSelection(selectedItem, true); // 选中对应项
            this.list = [selectedItem];  // 设置选中的项
          });
        }
      }
    },
    // 清空所有选中的项
    clearSelection() {
      this.$nextTick(() => {
        this.$refs.elTable.clearSelection();  // 清空所有选中的项
        this.list = [];  // 清空选中的列表
      });
    },
    // 处理选择变化
    handleSelectionChange(selection) {
      if (selection.length > 1) {
        // 如果选择了多行,保留最后一行
        this.$refs.elTable.clearSelection();  // 清空所有选择
        this.$refs.elTable.toggleRowSelection(selection[selection.length - 1]);  // 重新选择最后一项
      }
      // 获取最后选择的行
      this.list = [selection[selection.length - 1]];
    },
    // 确定选择
    handleOk() {
      this.open = false;
      this.queryParams = {
        pid: "",
        pname: "",
        pym: "",
        checktype: "deptdict",
        page: 1,
        pageSize: 10,
      };
      if (this.list.length > 0) {
        const pac = [
          {
            pacCode: this.list[this.list.length - 1].pacCode,
            pacName: this.list[this.list.length - 1].pacName,
          },
        ];
        this.$emit("add", pac);
      } else {
        this.$message.warning("请选择一个项目");
      }
    },
    // 触发查询
    handleQuery() {
      this.getAllList();
    },
  },
};
</script>
<style scoped>
.pag {
  width: 100%;
  display: flex;
  justify-content: center;
}
.pag1 {
  width: 60%;
}
</style>