优化代码 import documentFileList delHistory history categoryList from apiFileManagementPage 页面的初始数据 data tabList tabList 切换tab的值 search false 是否进入搜索状态 historyList 历史搜索记录 dto
优化后的代码:
import { documentFileList, delHistory, history, categoryList } from '../../api/FileManagement'
Page({ /**
- 页面的初始数据 */ data: { tabList: tabList(), search: false, historyList: [], dto: { contractStatus: '', createTime: [], currentPage: 1, documentCategoryId: '', inputSearch: '', isStatus: 1, pageSize: 6, signingDeadline: [] }, list: [], total: 0, sumPage: false, show: false, },
/**
- 生命周期函数--监听页面显示 */ onShow() { this.getList() },
// 获取合同列表 async getList() { wx.showLoading({ title: '加载中', mask: true }) const { dto, list } = this.data const { data } = await documentFileList(dto) this.setData({ list: data.current === 1 ? [...data.records] : [...list, ...data.records], total: data.total, sumPage: data.pages > data.current }, () => { wx.hideLoading() }) },
// 搜索 search({ detail: { value } }) { if (!value) { wx.showToast({ title: '请输入搜索内容', icon: 'none', duration: 2000, mask: false }) return } this.setData({ 'dto.inputSearch': value, 'dto.currentPage': 1 }, this.getList) },
// 输入框聚焦时改变页面 focus() { const { dto } = this.data this.setData({ search: true, list: dto.inputSearch ? this.data.list : [], total: dto.inputSearch ? this.data.total : 0 }) wx.setNavigationBarTitle({ title: '搜索' }) this.getHistory() },
// 获取搜索历史记录 async getHistory() { const { data } = await history() this.setData({ historyList: data }) },
// 使用记录搜索 historySearch({ currentTarget: { dataset: { str } } }) { this.setData({ 'dto.inputSearch': str, 'dto.currentPage': 1 }, this.getList) },
// 取消搜索 canaelSearch() { this.setData({ search: false, 'dto.inputSearch': '', 'dto.currentPage': 1 }) wx.setNavigationBarTitle({ title: '文件管理' }) this.getList() },
// 删除搜索历史记录 async delHistory() { await delHistory() this.setData({ historyList: [] }) },
onChange({ detail: { index } }) { this.setData({ 'dto.isStatus': index + 1, 'dto.currentPage': 1, 'dto.contractStatus': null, 'dto.documentCategoryId': null, 'dto.initiateStartDate': null, 'dto.initiateEndDate': null, 'signingStartDeadline': null, 'signingEndDeadline': null, }, this.getList) },
// 打开类型筛选 openPopup() { this.setData({ show: true }) },
// 关闭类型筛选 onClose({ detail }) { // detail 子组件传过来的筛选对象 this.setData({ show: false, 'dto': { ...this.data.dto, ...detail, currentPage: 1 } }, this.getList) },
// scroll-view触底函数 scrollBottom() { const { sumPage, dto } = this.data if (sumPage) { this.setData({ 'dto.currentPage': dto.currentPage + 1 }, this.getList) return } wx.showToast({ title: '没有更多了~', icon: 'none', duration: 2000, mask: false }) } })
function tabList() { return [ { name: '全部', query: 1 }, { name: '我发起的', query: 2 }, { name: '我收到的', query: 3 }, { name: '抄送给我的', query: 4 }, { name: '即将截止', query: 5 }, ] }
原文地址: https://www.cveoy.top/t/topic/btGH 著作权归作者所有。请勿转载和采集!