wankeda
2025-03-01 1824228ee4f0f25383d1c9e9fea684dfc8a460bc
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
<template>
  <vol-box
    :lazy="true"
    v-model="model"
    title="选择物料编号"
    :width="200"
    :padding="0"
  >
    <div>
      <div>
        <!-- 搜索配置 -->
        <div class="search-form">
          <label>物料编号:</label>
          <el-input style="width: 100px" 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,
      showDetialBox: false,
      MaterialCode:null,
      selection:null,
      tableData: [],
      filteredData: [],
      tableColumns: [
        {
          prop: "materielCode",
          title: "物料编号",
          type: "string",
        },
      ],
    };
  },
  watch: {
    MaterialCode(newVal) {
      this.filterLocalData(newVal);
    }
  },
  methods: {
    open(val) {
      //打开主表选择数据
      this.model = true;
      this.wareId=val;
      this.getData();
    },
    filterLocalData(code) {
      if (code) {
        this.filteredData = this.tableData.filter((item) => {
            return item.materielCode.includes(code);
        });
        console.log(this.filteredData.length);
        console.log(this.tableData.length);
      } else {
        this.filteredData = [...this.tableData]; // 重置为完整数据
      }
    },
    handleSelectionChange(val) {
        this.selection = val;
        if (this.selection.length > 1) {
            this.$message.error("仅选择一条数据");
            // 清空选中的第一条数据
            this.$refs.singleTable.clearSelection();
        }
        console.log(this.selection);
    },
    getData() {
      this.http
        .post(
          "/api/PurchaseOrderDetail/GetPurchaseOrderDetailMaterielCode?warehouseId=" + this.wareId,
          null,
          "查询中"
        )
        .then((x) => {
          this.tableData=x.data.map((i) => ({
            "materielCode":i
          }))
          this.filteredData=x.data.map((i) => ({
            "materielCode":i
          }))
        });
    },
    onSelect() {
      if (!this.selection) {
        return this.$message.error("请选择数据");
      }
      this.$emit("parentCall", ($parent) => {
        //如:回写编辑表单数据
        $parent.editFormFields.materielCode = this.selection[0].materielCode;
        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>