222 lines
5.5 KiB
TypeScript
222 lines
5.5 KiB
TypeScript
// utils/app.ts.ts
|
|
import { getMonthDay } from '../../utils/util'
|
|
import { getCardBoardOrderDeliveryList } from '../../api/index'
|
|
import { getAppInstance } from '../../utils/app';
|
|
const app = getAppInstance();
|
|
|
|
// const userInfo = wx.getStorageSync('userInfo');
|
|
// const devicecode = wx.getStorageSync('devicecode');
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
date_field: '',
|
|
s_date: '',
|
|
e_date: '',
|
|
search_input_focus: false,
|
|
customerId: 0,
|
|
searchTxt: '',
|
|
sDateVisible: false,
|
|
startDate: '',
|
|
list: [],
|
|
showCount: true,
|
|
totalData: {},
|
|
customerList: [],
|
|
pageNumber: 1, // 当前页码
|
|
pageSize: 20, // 每页数量
|
|
hasMore: true, // 是否还有更多数据
|
|
loading: false, // 是否正在加载(防止重复请求)
|
|
isCust: false //是否为客户账号,限制仅可查看本身的订单
|
|
},
|
|
hideCount() {
|
|
this.setData({
|
|
showCount: false
|
|
})
|
|
},
|
|
showCount() {
|
|
this.setData({
|
|
showCount: true
|
|
})
|
|
},
|
|
// 触底事件
|
|
onScrollToLower() {
|
|
// 防止重复加载 & 无更多数据
|
|
if (this.data.loading || !this.data.hasMore) return
|
|
|
|
this.setData({ loading: true,pageNumber: this.data.pageNumber + 1 })
|
|
wx.nextTick(() => {
|
|
this.getOrderList(true);
|
|
})
|
|
},
|
|
// 跳转订单详情
|
|
toOrderDetail(e) {
|
|
const id = e.currentTarget.dataset.id;
|
|
wx.navigateTo({
|
|
url: `/pages/cardBoardOrderDeliveryDetail/cardBoardOrderDeliveryDetail?id=${id}`
|
|
})
|
|
},
|
|
// 日期相关
|
|
showPicker(e) {
|
|
const field = e.currentTarget.dataset.field;
|
|
this.setData({ sDateVisible: true, date_field: field });
|
|
},
|
|
onCancel() {
|
|
this.setData({ sDateVisible: false });
|
|
},
|
|
// 选择日期
|
|
onConfirm(e) {
|
|
const { value } = e.detail;
|
|
this.setData({ [this.data.date_field]: value,sDateVisible: false });
|
|
this.getOrderList(false);
|
|
},
|
|
// 关键词搜索
|
|
handleSearchTxtChange(e) {
|
|
const { value } = e.detail;
|
|
this.setData({ searchTxt: value });
|
|
},
|
|
// 切换客户
|
|
onCustChange(e) {
|
|
this.setData({
|
|
customerId: e.detail.value,
|
|
});
|
|
this.getOrderList(false);
|
|
},
|
|
// 搜索输入框焦点事件
|
|
inputFocus() {
|
|
this.setData({
|
|
search_input_focus: true
|
|
})
|
|
},
|
|
inputBlur() {
|
|
this.setData({
|
|
search_input_focus: false
|
|
})
|
|
},
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad() {
|
|
const days = getMonthDay();
|
|
const userInfo = wx.getStorageSync('userInfo');
|
|
this.setData({
|
|
s_date: days[0],
|
|
e_date: days[1],
|
|
customerId: userInfo.custid?userInfo.custid:0,
|
|
customerList: app.globalData.customerList,
|
|
date_field: 's_date',
|
|
isCust: userInfo.custid?true:false,
|
|
})
|
|
this.getOrderList(false);
|
|
|
|
},
|
|
|
|
async getOrderList(isLoadMore: Boolean) {
|
|
try {
|
|
wx.showLoading({ title: '加载中' });
|
|
const { searchTxt, pageNumber, pageSize, s_date, e_date, customerId }= this.data;
|
|
const filterStr = {};
|
|
if (s_date || e_date) {
|
|
filterStr.createtime = [(s_date?'#>=#' + s_date:''),(e_date?'#<=#' + e_date:'')]
|
|
}
|
|
if (customerId) {
|
|
filterStr.custid = '#IN#' + customerId;
|
|
}
|
|
const params = {
|
|
pageNumber,
|
|
pageSize,
|
|
searchTxt,
|
|
screenStr: JSON.stringify(filterStr)
|
|
};
|
|
const res = await getCardBoardOrderDeliveryList(params).catch( () => {});
|
|
if (res.statusCode === 200) {
|
|
const dataList = res.data.list.map( item => {
|
|
item.createtime = item.createtime.replace('T', ' ');
|
|
if (item.custcode) {
|
|
const obj = app.globalData.customerList.find( item2 => item2.code == item.custcode);
|
|
item.customName = obj?obj.name:'';
|
|
}
|
|
if (item.listDetail) {
|
|
item.totalSquaNum = item.listDetail.reduce((total,obj) => total + ((obj.wide * obj.long / 10000) * obj.num),0)?.toFixed(2);
|
|
}
|
|
if (item.delitime) {
|
|
item.delitime = item.delitime.split('T').join(' ');
|
|
}
|
|
|
|
return item;
|
|
})
|
|
let totalData = res.data.totalData;
|
|
for (const key in totalData) {
|
|
const val = totalData[key];
|
|
// 是数字 且 不是整数(有小数点)
|
|
if (typeof val === 'number' && !Number.isInteger(val)) {
|
|
totalData[key] = val.toFixed(2); // 字符串类型,如 "3.14"
|
|
}
|
|
}
|
|
this.setData({
|
|
hasMore: this.data.list.length + this.data.pageSize >= res.data.searchListResourceParamaters.total?false:true,
|
|
loading: false,
|
|
list: isLoadMore == true?[...this.data.list,...dataList]: dataList,
|
|
totalData: res.data.totalData || {}
|
|
});
|
|
} else {
|
|
wx.showToast({ title: '数据加载失败', icon: 'none' });
|
|
}
|
|
} catch (err) {
|
|
console.error(err);
|
|
wx.showToast({ title: '系统错误', icon: 'none' });
|
|
} finally {
|
|
wx.hideLoading();
|
|
}
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
*/
|
|
onReady() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
onShow() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面隐藏
|
|
*/
|
|
onHide() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面卸载
|
|
*/
|
|
onUnload() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
*/
|
|
onPullDownRefresh() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面上拉触底事件的处理函数
|
|
*/
|
|
onReachBottom() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 用户点击右上角分享
|
|
*/
|
|
onShareAppMessage() {
|
|
|
|
}
|
|
}) |