const util = require('../../utils/util') const app = getApp() Page({ /** * 页面的初始数据 */ data: { currentTab: 0, bgColor: "linear-gradient(90deg, rgb(255, 118, 38), rgb(252, 30, 82))", navbar: [{ name: "进库" }, { name: "出库" }], searchParams: { storeId: '', pageNo: 1, pageSize: 20, storeName: '' }, params: { storeId: '', pageNo: 1, pageSize: 20, }, storeList: [], orderList: [], loadding: false, pullUpOn: true, }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.bindStoreList() this.bindOrderist() }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { this.setData({ ["searchParams.pageNo"]: 1, pullUpOn: true, loadding: false, orderList: [] }) this.bindOrderist() setTimeout(() => { wx.stopPullDownRefresh() }, 300); }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { //只是测试效果,逻辑以实际数据为准 this.setData({ loadding: true, pullUpOn: true }) var that = this this.setData({ ["searchParams.pageNo"]: that.data.searchParams.pageNo + 1 }) this.bindOrderist() }, bindStorePickerChange: function (e) { var item = this.data.storeList[e.detail.value] console.log(item) this.setData({ ['searchParams.storeId']: item.id, ['searchParams.storeName']: item.storeName, ["searchParams.pageNo"]: 1, orderList: [] }) this.bindOrderist() }, changeTab(e) { console.log(e) this.setData({ currentTab: e.detail.index, ["searchParams.pageNo"]: 1, pullUpOn: true, loadding: false, orderList: [] }) this.bindOrderist() }, bindOrderist() { var that = this if (that.data.currentTab == 0) { // that.data.params.storeId = that.data.searchParams.storeId; that.data.params.pageNo = that.data.searchParams.pageNo; that.data.params.pageSize = that.data.searchParams.pageSize; that.data.params.productName = that.data.searchParams.productName; that.data.params.orderSn = that.data.searchParams.orderSn ? that.data.searchParams.orderSn : ""; // that.data.params = Object.assign( that.data.params, that.data.searchParams) console.log(that.data.params) util.request(util.api.productOrderDetailPage, that.data.params, "GET", false, false, app.globalData.token).then((res) => { if (res.code == 200) { console.log(res) if (res.result.records.length > 0) { if (this.data.searchParams.pageNo > 1) { let list = that.data.orderList res.result.records.forEach(element => { var item = {} item.orderSn = element.orderSn item.productName = element.productName item.productNum = element.productQuantity list.push(item) }); that.setData({ orderList: list }) } else { let list = [] res.result.records.forEach(element => { var item = {} item.orderSn = element.orderSn item.productName = element.productName item.productNum = element.productQuantity list.push(item) }); that.setData({ orderList: list }) } } else { if(this.data.searchParams.pageNo<=1){ that.setData({ loadding: false, pullUpOn: false, ["searchParams.pageNo"]: that.data.searchParams.pageNo - 1, orderList: [] }) }else{ that.setData({ loadding: false, pullUpOn: false, }) } } } }).catch((res) => {}) } else { if (!that.data.searchParams.storeId) { this.setData({ orderList: [] }) return; } util.request(util.api.orderListPage, that.data.searchParams, "GET", false, false, app.globalData.token).then((res) => { if (res.code == 200) { if (res.result.records.length > 0) { if (this.data.searchParams.pageNo > 1) { let list = that.data.orderList res.result.records.forEach(element => { var item = {} item.orderSn = element.orderSn item.productName = element.productName item.productNum = 1 list.push(item) }); that.setData({ orderList: list }) } else { let list = [] res.result.records.forEach(element => { var item = {} item.orderSn = element.orderSn item.productName = element.productName item.productNum = 1 list.push(item) }); that.setData({ orderList: list }) } } else { that.setData({ loadding: false, pullUpOn: false, ["searchParams.pageNo"]: that.data.searchParams.pageNo - 1, orderList: [] }) } } }).catch((res) => {}) } }, bindStoreList() { var that = this util.request(util.api.storeList, {}, "GET", false, true, app.globalData.token).then((res) => { if (res.code == 200) { that.setData({ storeList: res.result }) } }).catch((res) => {}) }, serchOrderNo(e) { let _this = this; let dataset = e.currentTarget.dataset; let value = e.detail.value; let name = dataset.name; _this.data[name] = value; _this.setData({ [name]: _this.data[name] }); this.bindOrderist() } })