wangxinhui
2025-06-05 30eb20ab1384b221801bbcff50ce6d05923dcd84
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<template>
    <vol-box
      :lazy="true"
      v-model="model"
      title="选择物料规格"
      :width="280"
      :padding="0"
    >
      <div>
        <div>
          <!-- 搜索配置 -->
          <div class="search-form">
            <label>物料规格:</label>
            <el-input style="width: 160px" v-model="MaterialCode"></el-input>
          </div>
          <el-table
            ref="singleTable"
            :data="filteredData"
            style="width: 100%; height: 100%"
            highlight-current-row
            height="500px"
            @selection-change="handleSelectionChange"
          >
            >
            <el-table-column type="selection" width="55"> </el-table-column>
            <el-table-column
              v-for="(item, index) in tableColumns.filter((x) => !x.hidden)"
              :key="index"
              :prop="item.prop"
              :label="item.title"
              align="center"
            >
            </el-table-column>
          </el-table>
        </div>
      </div>
      <template #footer>
        <div><el-button type="primary" @click="onSelect">确认</el-button></div>
      </template>
    </vol-box>
  </template>
  <script>
  import VolBox from "@/components/basic/VolBox.vue";
  
  /******注意:如果出现提示没有权限的问题,见后台开发文档上的【重写后台权限】*****/
  
  //这里使用的vue2语法,也可以写成vue3语法
  export default {
    components: {
      "vol-box": VolBox,
    },
    methods: {},
    data() {
      return {
        model: false, //弹出框
        wareId: null,
        materielSpec:null,
        showDetialBox: false,
        MaterialCode:null,
        selection:null,
        tableData: [],
        filteredData: [],
        tableColumns: [
          {
            prop: "materielSpec",
            title: "物料规格",
            type: "string",
          },
        ],
      };
    },
    watch: {
      MaterialCode(newVal) {
        this.filterLocalData(newVal);
      }
    },
    methods: {
      open(purchaseOrderNo, materielCode) { // 重命名参数,语义更清晰
    this.model = true;
    this.purchaseOrderNo = purchaseOrderNo; // 存储采购单号
    this.materielCode = materielCode; // 存储物料编号
    this.getData(); // 调用获取数据方法
  },
      filterLocalData(code) {
        if (code) {
          this.filteredData = this.tableData.filter((item) => {
              return item.materielSpec.includes(code);
          });
          console.log(this.filteredData.length);
          console.log(this.tableData.length);
        } else {
          this.filteredData = [...this.tableData]; // 重置为完整数据
        }
      },
      handleSelectionChange(val,val2) {
          this.selection = val;
          this.selection1 = val2;
          if (this.selection.length > 1) {
              this.$message.error("仅选择一条数据");
              // 清空选中的第一条数据
              this.$refs.singleTable.clearSelection();
          }
          if (this.selection1.length > 1) {
              this.$message.error("仅选择一条数据");
              // 清空选中的第一条数据
              this.$refs.singleTable.clearSelection();
          }
          console.log(this.selection);
      },
      getData() {
    const url = `/api/PurchaseOrderDetail/GetOrderMaterielSpec?` +
      `purchaseOrderNo=${encodeURIComponent(this.purchaseOrderNo)}&` +
      `materielCode=${encodeURIComponent(this.materielCode)}`;
 
    this.http.post(url, null, "查询中")
      .then((x) => {
        if (!x.status) {
          return this.$error(x.message);
        }
        this.tableData = x.data.map((item) => ({
          materielSpec: item // 假设接口返回的规格直接是字符串
        }));
        this.filteredData = [...this.tableData]; // 重置过滤数据
      })
      .catch((error) => {
        console.error("接口请求失败:", error);
        this.$message.error("获取物料规格失败,请重试");
      });
  },
      onSelect() {
        if (!this.selection) {
          return this.$message.error("请选择数据");
        }
        this.$emit("parentCall", ($parent) => {
          //如:回写编辑表单数据
          $parent.editFormFields.materielSpec = this.selection[0].materielSpec;
          this.model = false;
        });
        this.MaterialCode = null;
        this.tableData = [];
        this.filteredData = [];
      },
    },
  };
  </script>
  <style lang="less" scoped>
  .search-form {
    display: flex;
    padding: 10px;
    line-height: 34px;
    button {
      margin-left: 10px;
    }
  }
  </style>