123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291 |
- const {
- default: api
- } = require("../../js/api");
- const util = require('../../utils/util.js')
- Page({
-
- data: {
- date: '',
- startDate: '',
- endDate: '',
- pageNum:1,
- pageSize:5,
- isHaveOrder:true,
- paymentMode: -1,
-
- statusValue: [{
- paymentMode: "0",
- authorizationStatus: 0,
- orderStatus: 0,
- status: '未支付',
- statusColor: '#ff8d1a'
- },
- {
- paymentMode: "0",
- authorizationStatus: 0,
- orderStatus: 1,
- status: '已完成',
- statusColor: '#a6a6a6'
- },
- {
- paymentMode: "0",
- authorizationStatus: 0,
- orderStatus: 5,
- status: '已完成',
- statusColor: '#a6a6a6'
- },
- {
- paymentMode: "1",
- authorizationStatus: 0,
- orderStatus: 1,
- status: '已失效',
- statusColor: '#a6a6a6'
- },
- {
- paymentMode: "1",
- authorizationStatus: 1,
- orderStatus: 1,
- status: '已授权',
- statusColor: '#b1db5a'
- },
- {
- paymentMode: "1",
- authorizationStatus: 0,
- orderStatus: 2,
- status: '已完成',
- statusColor: '#a6a6a6'
- },
- {
- paymentMode: "1",
- authorizationStatus: 0,
- orderStatus: 3,
- status: '已完成',
- statusColor: '#a6a6a6'
- },
- {
- paymentMode: "1",
- authorizationStatus: 0,
- orderStatus: 5,
- status: '已完成',
- statusColor: '#a6a6a6'
- },
- ],
- orders: []
- },
-
- getNowDate() {
- const date = new Date();
- const year = date.getFullYear();
- const month = String(date.getMonth() + 1).padStart(2, '0');
- const day = String(date.getDate()).padStart(2, '0');
- return `${year}-${month}-${day}`;
- },
-
- getLastMouthDate() {
- const currentDate = new Date();
- const year = currentDate.getFullYear();
- const month = currentDate.getMonth();
- const day = currentDate.getDate();
-
- const oneMonthAgoDate = new Date(year, month - 1, day);
-
-
-
- const formattedDate = `${oneMonthAgoDate.getFullYear()}-${String(oneMonthAgoDate.getMonth() + 1).padStart(2, '0')}-${String(oneMonthAgoDate.getDate()).padStart(2, '0')}`;
- return formattedDate;
- },
-
- startCountdow() {
- this.timer = setInterval(() => {
- const countDownZeroOrders = []
- const orders = this.data.orders.map(order => {
- if (order.countdown && order.countdown != '0') {
- const currentCountDown = (Number(order.countdown) - 1);
- order.countdown = currentCountDown.toString();
- if (currentCountDown <= 0) countDownZeroOrders.push(order)
- }
- return order
- })
- this.setData({
- orders: orders
- })
- this.toUnAnthorization(countDownZeroOrders)
- }, 1000);
- },
-
- endCountDown() {
- if (this.timer) {
- clearInterval(this.timer)
- this.timer = null
- }
- },
-
- toUnAnthorization(orders) {
- console.log(orders)
- },
-
- onLoad(options) {
- const today = this.getNowDate();
- const lastMouthDay = this.getLastMouthDate();
- this.setData({
- date: today,
- paymentMode: options.paymentMode,
- startDate: today,
- endDate: lastMouthDay
- });
- console.log("历史页当前data",this.data)
- this.getOrder();
-
- },
-
- onReady() {
- },
-
- onShow() {
- },
-
- onHide() {
- },
-
- onUnload() {
- this.endCountDown()
- },
-
- onPullDownRefresh() {
- },
-
- onReachBottom() {
- if(!this.data.isHaveOrder) return;
- var page = this.data.pageNum + 1;
- this.setData({
- pageNum:page
- })
- this.getOrder()
- },
-
- onShareAppMessage() {
- },
-
- bindDateChange(date) {
- this.setData({
- date: date.detail.value,
- orders:[]
- });
- console.log(date)
- this.getOrder()
- },
-
- onOrderButtonClick1(event) {
- console.log(event)
- },
-
- onOrderButtonClick2(event) {
- console.log(event)
- },
-
- getOrder() {
- const that = this;
- api.request_WXFindOrders(this.data.date, this.data.pageNum, this.data.pageSize).then(res => {
-
- console.log("获取历史订单", res)
- const datas = res.data.data;
- if(datas.length <= 0) {
- that.data.isHaveOrder = false;
- return
- }
- var getOrders = datas.map(order => {
- var times = [order.authorizationTime, order.createTime, order.fuelItemTransactionEndTime, order.transactionTime];
- var timeFormate = times.find(t => t != undefined && t != null && t != '');
- var time = util.formatDateNotSecond(timeFormate);
- var volume = (order.originalQty != null && order.originalQty != undefined) ? order.originalQty : order.qty
- var status = that.data.statusValue.find(state =>
- state.paymentMode == this.data.paymentMode &&
- state.authorizationStatus == order.authorizationStatus &&
- state.orderStatus == order.orderStatus
- )
- var stute = '';
- var stateColor = '';
- var bt2 = ''
- if (status != undefined) {
- stute = status.status
- stateColor = status.statusColor
- }
- if(stute == '未支付') bt2 = '重新支付';
- return {
- order: {
- status: stute,
- statusColor: stateColor,
- oilName: order.productName,
- nozzle: order.nozzleId,
- volume: volume,
- amount: order.originalAmount,
- payAmount: order.actualPaymentAmount,
- discount: order.originalAmount - order.actualPaymentAmount,
- orderId: order.id,
- time: time
- },
- bottonText2: bt2
- }
- })
- var orderList = [...this.data.orders,...getOrders]
- this.setData({
- orders: orderList
- })
- console.log("转换后的订单", this.data.orders)
- }).catch(err => {
- console.log("获取历史订单失败", err)
- })
- }
- })
|