|
|
@@ -1,25 +1,184 @@
|
|
|
+const _Http = getApp().globalData.http;
|
|
|
+
|
|
|
Page({
|
|
|
data: {
|
|
|
- warehouseList: []
|
|
|
+ list: [],
|
|
|
+ loading: false,
|
|
|
+ showModal: false,
|
|
|
+ isEdit: false,
|
|
|
+ formData: {
|
|
|
+ sys_enterprise_stockid: 0,
|
|
|
+ stockno: '',
|
|
|
+ stockname: '',
|
|
|
+ isused: '1'
|
|
|
+ },
|
|
|
+ content: {
|
|
|
+ nocache: true,
|
|
|
+ pageNumber: 1,
|
|
|
+ pageSize: 20,
|
|
|
+ pageTotal: 1,
|
|
|
+ total: null
|
|
|
+ }
|
|
|
},
|
|
|
onLoad() {
|
|
|
- this.getWarehouseList();
|
|
|
- },
|
|
|
- getWarehouseList() {
|
|
|
- // 模拟获取仓库列表数据
|
|
|
- const mockData = [
|
|
|
- { id: 1, name: '仓库1', location: '位置1', capacity: '1000' },
|
|
|
- { id: 2, name: '仓库2', location: '位置2', capacity: '2000' },
|
|
|
- { id: 3, name: '仓库3', location: '位置3', capacity: '3000' }
|
|
|
- ];
|
|
|
+ this.getList(true);
|
|
|
+ },
|
|
|
+ onSearch(e) {
|
|
|
+ const keyword = e.detail.value || "";
|
|
|
this.setData({
|
|
|
- warehouseList: mockData
|
|
|
+ "content.pageNumber": 1,
|
|
|
+ "content.where": {
|
|
|
+ condition: keyword
|
|
|
+ }
|
|
|
});
|
|
|
+ this.getList(true);
|
|
|
+ },
|
|
|
+ getList(init) {
|
|
|
+ if (this.data.loading) return;
|
|
|
+ if (init.detail != undefined) init = init.detail;
|
|
|
+ let content = this.data.content;
|
|
|
+ if (init) {
|
|
|
+ content.pageNumber = 1;
|
|
|
+ }
|
|
|
+ this.setData({ loading: true });
|
|
|
+ _Http.basic({
|
|
|
+ "id": "2026031714375701",
|
|
|
+ content
|
|
|
+ }).then(res => {
|
|
|
+ this.setData({ loading: false });
|
|
|
+ console.log("仓库列表", res)
|
|
|
+ this.selectComponent('#ListBox').RefreshToComplete();
|
|
|
+ if (res.code != 1) return wx.showToast({
|
|
|
+ title: res.msg,
|
|
|
+ icon: "none"
|
|
|
+ })
|
|
|
+ this.setData({
|
|
|
+ list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
|
|
|
+ "content.pageNumber": res.pageNumber + 1,
|
|
|
+ "content.pageSize": res.pageSize,
|
|
|
+ "content.pageTotal": res.pageTotal,
|
|
|
+ "content.total": res.total
|
|
|
+ })
|
|
|
+ })
|
|
|
},
|
|
|
- goToDetail(e) {
|
|
|
+ deleteWarehouse(e) {
|
|
|
const id = e.currentTarget.dataset.id;
|
|
|
- wx.navigateTo({
|
|
|
- url: `./detail?id=${id}`
|
|
|
+ wx.showModal({
|
|
|
+ title: '确认删除',
|
|
|
+ content: '确定要删除这个仓库吗?',
|
|
|
+ success: (res) => {
|
|
|
+ if (res.confirm) {
|
|
|
+ // 调用API删除仓库
|
|
|
+ _Http.basic({
|
|
|
+ "id": "2026031714454901",
|
|
|
+ content: {
|
|
|
+ sys_enterprise_stockid: id
|
|
|
+ }
|
|
|
+ }).then(res => {
|
|
|
+ console.log("删除仓库", res)
|
|
|
+ if (res.code != 1) {
|
|
|
+ return wx.showToast({
|
|
|
+ title: res.msg,
|
|
|
+ icon: "none"
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ // 删除成功,刷新列表
|
|
|
+ wx.showToast({ title: '删除成功', icon: 'success' });
|
|
|
+ this.getList(true);
|
|
|
+ }).catch(() => {
|
|
|
+ wx.showToast({ title: '网络错误', icon: 'none' });
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ addWarehouse() {
|
|
|
+ // 重置表单数据
|
|
|
+ this.initFormData();
|
|
|
+ this.setData({
|
|
|
+ showModal: true,
|
|
|
+ isEdit: false
|
|
|
+ });
|
|
|
+ },
|
|
|
+ editWarehouse(e) {
|
|
|
+ const id = e.currentTarget.dataset.id;
|
|
|
+ // 查找要编辑的仓库数据
|
|
|
+ const warehouse = this.data.list.find(item => item.sys_enterprise_stockid == id);
|
|
|
+ if (warehouse) {
|
|
|
+ this.setData({
|
|
|
+ showModal: true,
|
|
|
+ isEdit: true,
|
|
|
+ formData: {
|
|
|
+ sys_enterprise_stockid: warehouse.sys_enterprise_stockid,
|
|
|
+ stockno: warehouse.stockno || '',
|
|
|
+ stockname: warehouse.stockname || '',
|
|
|
+ isused: warehouse.isused.toString()
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ closeModal() {
|
|
|
+ this.setData({ showModal: false });
|
|
|
+ // 关闭后初始化表单
|
|
|
+ this.initFormData();
|
|
|
+ },
|
|
|
+ initFormData() {
|
|
|
+ this.setData({
|
|
|
+ formData: {
|
|
|
+ sys_enterprise_stockid: 0,
|
|
|
+ stockno: '',
|
|
|
+ stockname: '',
|
|
|
+ isused: '1'
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ handleInput(e) {
|
|
|
+ const field = e.currentTarget.dataset.field;
|
|
|
+ const value = e.detail;
|
|
|
+ this.setData({
|
|
|
+ [`formData.${field}`]: value
|
|
|
});
|
|
|
+ },
|
|
|
+ handleRadioChange(e) {
|
|
|
+ this.setData({
|
|
|
+ 'formData.isused': e.detail
|
|
|
+ });
|
|
|
+ },
|
|
|
+ saveWarehouse() {
|
|
|
+ const { stockno, stockname } = this.data.formData;
|
|
|
+
|
|
|
+ // 验证必填字段
|
|
|
+ if (!stockno) {
|
|
|
+ return wx.showToast({ title: '请输入仓库编码', icon: 'none' });
|
|
|
+ }
|
|
|
+ if (!stockname) {
|
|
|
+ return wx.showToast({ title: '请输入仓库名称', icon: 'none' });
|
|
|
+ }
|
|
|
+
|
|
|
+ // 调用API保存仓库
|
|
|
+ _Http.basic({
|
|
|
+ "id": "2026031714422501",
|
|
|
+ content: {
|
|
|
+ ...this.data.formData,
|
|
|
+ isused: parseInt(this.data.formData.isused)
|
|
|
+ }
|
|
|
+ }).then(res => {
|
|
|
+ console.log("保存仓库", res)
|
|
|
+ if (res.code != 1) {
|
|
|
+ return wx.showToast({
|
|
|
+ title: res.msg,
|
|
|
+ icon: "none"
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ // 保存成功,关闭模态框并刷新列表
|
|
|
+ wx.showToast({ title: '保存成功', icon: 'success' });
|
|
|
+ this.setData({ showModal: false });
|
|
|
+ this.initFormData();
|
|
|
+ this.getList(true);
|
|
|
+ }).catch(() => {
|
|
|
+ wx.showToast({ title: '网络错误', icon: 'none' });
|
|
|
+ })
|
|
|
}
|
|
|
});
|