| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- const _Http = getApp().globalData.http;
- Page({
- data: {
- 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.getList(true);
- },
- onSearch(e) {
- const keyword = e.detail.value || "";
- this.setData({
- "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
- })
- })
- },
- deleteWarehouse(e) {
- const id = e.currentTarget.dataset.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' });
- })
- }
- });
|