nantai-erp-wechat-mobile/dispatcher/pages/record/supplier/supplier.js
2024-10-31 21:29:57 +08:00

143 lines
2.8 KiB
JavaScript

const app = getApp()
Page({
/**
* 页面的初始数据
*/
data: {
boundingSize: wx.getMenuButtonBoundingClientRect(),
supplierList: [],
currentPage: 1,
isLastPage: false,
supplierName: ''
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
this.getSupplierList()
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
// 获取列表
getSupplierList: function (supplierName = '', page = 1) {
const url = `/mobile/get_data`
app.AppService.appRequest(url, 'POST', {
page: page,
page_len: app.globalData.pageLen,
supplier_name: supplierName || this.data.supplierName,
data_type: 'data-02'
}, (res) => {
const lastSupplierList = this.data.supplierList || []
let supplierList = res.data.result || []
const len = supplierList.length
// 不是第一页
if (page > 1) {
// 有下一页
if (len > 0) {
supplierList = lastSupplierList.concat(supplierList)
this.setData({
isLastPage: false
})
} else {
supplierList = lastSupplierList
this.setData({
isLastPage: true
})
}
}
this.setData({
supplierList,
currentPage: page,
})
})
},
// 滚动到底部获取更多
getMoreList: function () {
const supplierName = this.data.supplierName || ''
if (!this.data.isLastPage) {
this.getSupplierList(supplierName, this.data.currentPage + 1)
}
},
// 选择供应商
selectSupplier: function (e) {
const id = e.currentTarget.dataset.id
const item = e.currentTarget.dataset.item
let pages = getCurrentPages() // 获取页面栈
let currPage = pages[pages.length - 1] // 当前页面
let prevPage = pages[pages.length - 2] // 上一个页面
console.log(id)
prevPage.setData({
supplierId: id,
supplierDetail: item
})
wx.navigateBack()
},
// 监听搜索输入
listenSearch: function (e) {
this.getSupplierList(e.detail.value)
},
// 输入失去焦点才setData
searchBlur: function (e) {
this.setData({
supplierName: e.detail.value
})
},
// 跳转页面
navigateTo: function (e) {
const url = e.currentTarget.dataset.url
wx.navigateTo({
url: url,
})
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
})