wanshenmean
2026-02-09 ae9517420d848e215a9eb807270d5ef6fbe92ae9
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
<template>
  <div class="location-page">
    <a-card>
      <a-space style="margin-bottom: 16px">
        <a-button type="primary" @click="handleAdd">
          <template #icon><plus-outlined /></template>
          新增货位
        </a-button>
        <a-input-search
          v-model:value="searchText"
          placeholder="搜索货位编码"
          style="width: 200px"
          @search="handleSearch"
        />
      </a-space>
 
      <a-table
        :columns="columns"
        :data-source="dataSource"
        :loading="loading"
        :pagination="pagination"
        @change="handleTableChange"
        row-key="Id"
      >
        <template #bodyCell="{ column, record }">
          <template v-if="column.key === 'LocationStatus'">
            <a-tag :color="record.LocationStatus === 1 ? 'green' : 'orange'">
              {{ record.LocationStatus === 1 ? '空闲' : '占用' }}
            </a-tag>
          </template>
          <template v-else-if="column.key === 'Enable'">
            <a-tag :color="record.Enable === 1 ? 'green' : 'red'">
              {{ record.Enable === 1 ? '启用' : '禁用' }}
            </a-tag>
          </template>
          <template v-else-if="column.key === 'action'">
            <a-space>
              <a @click="handleEdit(record)">编辑</a>
              <a-divider type="vertical" />
              <a-popconfirm title="确定要删除吗?" @confirm="handleDelete(record)">
                <a style="color: red">删除</a>
              </a-popconfirm>
            </a-space>
          </template>
        </template>
      </a-table>
    </a-card>
 
    <a-modal
      v-model:open="modalVisible"
      :title="modalTitle"
      @ok="handleModalOk"
      @cancel="handleModalCancel"
    >
      <a-form
        ref="formRef"
        :model="formState"
        :rules="rules"
        :label-col="{ span: 6 }"
        :wrapper-col="{ span: 16 }"
      >
        <a-form-item label="货位编码" name="LocationCode">
          <a-input v-model:value="formState.LocationCode" />
        </a-form-item>
        <a-form-item label="货位名称" name="LocationName">
          <a-input v-model:value="formState.LocationName" />
        </a-form-item>
        <a-form-item label="仓库编码" name="WarehouseCode">
          <a-input v-model:value="formState.WarehouseCode" />
        </a-form-item>
        <a-form-item label="货位类型" name="LocationType">
          <a-input v-model:value="formState.LocationType" />
        </a-form-item>
        <a-form-item label="状态" name="Enable">
          <a-select v-model:value="formState.Enable">
            <a-select-option :value="1">启用</a-select-option>
            <a-select-option :value="0">禁用</a-select-option>
          </a-select>
        </a-form-item>
      </a-form>
    </a-modal>
  </div>
</template>
 
<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue';
import { message } from 'ant-design-vue';
import { PlusOutlined } from '@ant-design/icons-vue';
import {
  getLocationList,
  addLocation,
  updateLocation,
  deleteLocation,
} from '../../../api/basic';
import type { LocationInfo } from '../../../types/common';
 
const columns = [
  { title: '货位编码', dataIndex: 'LocationCode', key: 'LocationCode' },
  { title: '货位名称', dataIndex: 'LocationName', key: 'LocationName' },
  { title: '仓库编码', dataIndex: 'WarehouseCode', key: 'WarehouseCode' },
  { title: '货位类型', dataIndex: 'LocationType', key: 'LocationType' },
  { title: '货位状态', dataIndex: 'LocationStatus', key: 'LocationStatus' },
  { title: '状态', dataIndex: 'Enable', key: 'Enable' },
  { title: '创建时间', dataIndex: 'CreateDate', key: 'CreateDate' },
  { title: '操作', key: 'action', width: 150 },
];
 
const dataSource = ref<LocationInfo[]>([]);
const loading = ref(false);
const searchText = ref('');
const pagination = reactive({
  current: 1,
  pageSize: 20,
  total: 0,
  showSizeChanger: true,
  showTotal: (total: number) => `共 ${total} 条`,
});
 
const modalVisible = ref(false);
const modalTitle = ref('新增货位');
const formRef = ref();
const formState = reactive<Partial<LocationInfo>>({
  LocationCode: '',
  LocationName: '',
  WarehouseCode: '',
  LocationType: '',
  Enable: 1,
});
 
const rules = {
  LocationCode: [{ required: true, message: '请输入货位编码', trigger: 'blur' }],
  LocationName: [{ required: true, message: '请输入货位名称', trigger: 'blur' }],
  WarehouseCode: [{ required: true, message: '请输入仓库编码', trigger: 'blur' }],
};
 
onMounted(() => {
  fetchData();
});
 
async function fetchData() {
  loading.value = true;
  try {
    const res = await getLocationList({
      page: pagination.current,
      rows: pagination.pageSize,
      sort: 'CreateDate',
      order: 'desc',
      wheres: searchText.value
        ? [{ name: 'LocationCode', value: searchText.value, displayType: 'like' }]
        : [],
    });
    if (res.status && res.data) {
      dataSource.value = res.data.rows || [];
      pagination.total = res.data.total || 0;
    }
  } catch (error) {
    console.error('Fetch data error:', error);
  } finally {
    loading.value = false;
  }
}
 
function handleTableChange(pag: any) {
  pagination.current = pag.current;
  pagination.pageSize = pag.pageSize;
  fetchData();
}
 
function handleSearch() {
  pagination.current = 1;
  fetchData();
}
 
function handleAdd() {
  modalTitle.value = '新增货位';
  Object.assign(formState, {
    Id: undefined,
    LocationCode: '',
    LocationName: '',
    WarehouseCode: '',
    LocationType: '',
    Enable: 1,
  });
  modalVisible.value = true;
}
 
function handleEdit(record: LocationInfo) {
  modalTitle.value = '编辑货位';
  Object.assign(formState, record);
  modalVisible.value = true;
}
 
async function handleModalOk() {
  try {
    await formRef.value.validate();
    const api = formState.Id ? updateLocation : addLocation;
    const res = await api(formState);
    if (res.status) {
      message.success(formState.Id ? '更新成功' : '新增成功');
      modalVisible.value = false;
      fetchData();
    }
  } catch (error) {
    console.error('Save error:', error);
  }
}
 
function handleModalCancel() {
  modalVisible.value = false;
  formRef.value?.resetFields();
}
 
async function handleDelete(record: LocationInfo) {
  try {
    const res = await deleteLocation([record.Id]);
    if (res.status) {
      message.success('删除成功');
      fetchData();
    }
  } catch (error) {
    console.error('Delete error:', error);
  }
}
</script>
 
<style scoped>
.location-page {
  padding: 0;
}
</style>