import { userPageList, userDelete } from "../../utils/api/api"; Page({ data: { isSearch: false,//是否搜索 userList: [], searchData: { data: { certName: "", certNo: "", vid: "" }, pageNum: 1, pageSize: 8, }, total: 0, isLoading: false, }, getVid(e) { this.setData({ 'searchData.data.vid': e.detail.value }) }, getUserName(e) { this.setData({ 'searchData.data.certName': e.detail.value }) }, getCardID(e) { this.setData({ 'searchData.data.certNo': e.detail.value }) }, // 获取列表 fetchData() { my.showLoading({ content: '加载中', }) this.setData({ isLoading: true }) userPageList(this.data.searchData).then(res => { my.hideLoading() this.setData({ userList: [...this.data.userList, ...res.data.records], total: res.data.total, 'searchData.pageNum': this.data.searchData.pageNum + 1 }) }).catch(error => { // 请求出错时隐藏加载提示,并处理错误 my.hideLoading(); }) .finally(() => { // 无论请求成功或失败,都需要将 isLoading 设为 false this.setData({ isLoading: false }); my.hideLoading(); }); }, // 清空 handleClear() { this.setData({ 'searchData.data.vid': '', 'searchData.data.certName': '', 'searchData.data.certNo': '', userList: [], 'searchData.pageNum': 1, }) this.fetchData() }, // 搜索 handleSearch() { this.setData({ userList: [], 'searchData.pageNum': 1, }) this.fetchData() }, // 点击查询 openSearch() { this.setData({ isSearch: true }) }, // 关闭查询 closeSearch() { this.setData({ isSearch: false }) }, // 出库 outStorage(e) { let vid = e.currentTarget.dataset.item let that = this my.showModal({ title: "", content: "确定要出库吗?", complete: res => { if (res.confirm) { userDelete({ vidList: [vid], token: 'ab051195190b4623ea62f636ae747f53', }).then(res => { my.showToast({ content: "出库成功", type: "success", duration: 1000, //显示透明蒙层,防止触摸穿透 mask: true, success: function () { that.setData({ userList: [], 'searchData.pageNum': 1, }) that.fetchData() } }); }); } else { my.showToast({ content: "出库失败", type: "fail", duration: 1000, //显示透明蒙层,防止触摸穿透 mask: true, }); } } }); }, onShow() { this.setData({ userList: [], 'searchData.pageNum': 1, }) this.fetchData() }, onReachBottom() { const { total, searchData: { pageNum, pageSize } } = this.data if (total <= (pageNum - 1) * pageSize) { return my.showToast({ content: '没有更多了', type: 'none' }) } if (this.data.isLoading) return this.fetchData() }, });