Files
2025-12-19 11:20:59 +08:00

493 lines
11 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

var loadMoreView, page;
const http = require("../../utils/http");
const { qcodePay } = require("../../utils/qrPay");
const { timeStr } = require("../../utils/util.js");
const app = getApp();
const host = app.globalData.devUrl;
const max10000Reg =
/^\d\.([1-9]{1,2}|[0-9][1-9])$|^[1-9]\d{0,3}(\.\d{1,2}){0,1}$/;
const max100Reg =
/^\d\.([1-9]{1,2}|[0-9][1-9])$|^[1-9]\d{0,1}(\.\d{1,2}){0,1}$/;
Page({
/* 页面的初始数据*/
data: {
picImg: http.picImg,
system: {},
items: [],
selectedView: "article",
start: "",
end: "",
// 此页面 页面内容距最顶部的距离
height: app.globalData.height,
showInputModal: false,
moneyTotal: 0,
offersMoneyTotal: 0,
gasReceiptsTotal: 0,
money: "",
oilQuantity: "", //加油量
oilQuantityTotal: 0, //加油量统计
showOilModal: false,
price: "",
cooPrice: "", // 挂牌价
offersMoney: "",
settlementType: 1, // 1价格战 2公斤站
userType: 0, // 0 负责人 1 站员
stationName: "",
isTriggered: false,
showDateTimePick: false,
pickerConfig: {
endDate: true,
column: "second",
dateLimit: true,
initStartTime: '',
initEndTime: '',
limitStartTime: "",
limitEndTime: ""
},
startView: '',
endView: '',
totalPages: 0,
showList: true,
},
handleScrollToLower() {
loadMoreView.loadMore(page);
},
handleRefresherRefresh() {
page = 1
this.loadData(0);
},
showDateTimePick() {
this.setData({
showDateTimePick: !this.data.showDateTimePick
})
},
setPickerTime(e) {
const { startTime, endTime } = e.detail
const startView = timeStr(new Date(startTime))
const endView = timeStr(new Date(endTime))
this.setData({
start: startTime,
end: endTime,
startView,
endView
})
console.log(startView, 'startView');
console.log(endView, 'endView');
this.showDateTimePick()
this.loadData(0);
},
showModal() {
this.setData({
money: "",
showInputModal: true,
});
},
hiddenModal() {
this.setData({
money: "",
showInputModal: false,
});
},
seting() {
wx.navigateTo({
url: "/pages/wodeOil/wodeOil",
});
},
//修改油价
editPriceHandle() {
this.setData({
showOilModal: true,
});
},
closeModal() {
this.setData({
showOilModal: false,
});
},
setPrice(e) {
var price;
if (/^(\d?)+(\.\d{0,2})?$/.test(e.detail.value)) {
price = e.detail.value;
} else {
price = e.detail.value.substring(0, e.detail.value.length - 1);
}
this.setData({
price: price,
});
},
setOffersMoney(e) {
var price;
if (/^(\d?)+(\.\d{0,2})?$/.test(e.detail.value)) {
price = e.detail.value;
} else {
price = e.detail.value.substring(0, e.detail.value.length - 1);
}
this.setData({
offersMoney: price,
});
},
//提交修改油价
editOil() {
var that = this;
if (that.data.price == "") {
wx.showModal({
title: "提示",
content: "请输入挂牌价!",
showCancel: false,
});
return;
}
if (!max100Reg.test(that.data.price)) {
wx.showModal({
title: "提示",
content: "请输入0-100以内的数字",
showCancel: false,
});
return;
}
if (that.data.settlementType === 2 && that.data.offersMoney == "") {
wx.showModal({
title: "提示",
content: "请输入站点优惠价!",
showCancel: false,
});
return;
}
if (
that.data.settlementType === 2 &&
that.data.offersMoney &&
!max100Reg.test(that.data.offersMoney)
) {
wx.showModal({
title: "提示",
content: "请输入0-100以内的数字,请输入0-100以内的数字",
showCancel: false,
});
return;
}
if (+that.data.offersMoney > +that.data.price) {
wx.showModal({
title: "提示",
content: "站点优惠价不可高于挂牌价!",
showCancel: false,
});
return;
}
return new Promise((reslove, reject) => {
wx.request({
url: `${host}/api/v1/cooperation/update/price`,
method: `POST`,
header: {
"content-type": "application/x-www-form-urlencoded",
},
data: {
id: wx.getStorageSync("cooperation").id,
price: that.data.price,
offersMoney: that.data.offersMoney || 0,
},
success: function (e) {
if (e.data.code === 0) {
wx.showModal({
title: "提示",
content: "修改成功",
showCancel: false,
});
that.closeModal();
that.setData({
cooPrice: e.data.cooPrice,
price: "",
offersMoney: "",
});
reslove(e.data);
that.loadData(0);
} else {
reject(e.data);
}
},
fail: function (e) {
reject(e);
},
});
});
},
setMoney(e) {
var money;
if (/^(\d?)+(\.\d{0,2})?$/.test(e.detail.value)) {
money = e.detail.value;
} else {
money = e.detail.value.substring(0, e.detail.value.length - 1);
}
this.setData({
money,
});
},
setOilQuantity(e) {
var oilQuantity;
if (/^(\d?)+(\.\d{0,2})?$/.test(e.detail.value)) {
oilQuantity = e.detail.value;
} else {
oilQuantity = e.detail.value.substring(0, e.detail.value.length - 1);
}
this.setData({
oilQuantity,
});
},
// 扫码收钱
getMoney() {
const money = this.data.money;
const oilQuantity = this.data.oilQuantity;
if (this.data.settlementType === 1 && !money) return;
if (this.data.settlementType === 1 && money && !max10000Reg.test(money)) {
wx.showModal({
title: "提示",
content: "请输入0-10000以内的数字",
showCancel: false,
});
return;
}
if (this.data.settlementType === 2 && !oilQuantity) return;
if (
this.data.settlementType === 2 &&
oilQuantity &&
!max10000Reg.test(oilQuantity)
) {
wx.showModal({
title: "提示",
content: "请输入0-10000以内的数字",
showCancel: false,
});
return;
}
this.hiddenModal();
wx.showLoading();
wx.scanCode({
// onlyFromCamera: true,
scanType: ["qrCode"],
success: (e) => {
try {
const data = JSON.parse(e.result);
if (money) {
data.totalMoney = money;
}
if (oilQuantity) {
data.oilQuantity = oilQuantity;
}
// const nonceStr = data.nonceStr;
// const fillingTime = data.fillingTime;
// const merchantNum = data.merchantNum;
// const orderNo = data.orderNo;
data.sign = 123;
qcodePay(data)
.then((e) => {
if (e.code == "0000") {
wx.showModal({
title: "提示",
content: `收款成功`,
showCancel: false,
});
}
wx.hideLoading();
this.onPullDownRefresh();
})
.catch((e) => {
wx.hideLoading();
wx.showModal({
title: "提示",
showCancel: false,
content: e.msg ? e.msg : `未知错误,请稍后再试`,
});
});
} catch (e) {
wx.hideLoading();
wx.showModal({
title: "提示",
content: "这不是一个有效的二维码",
showCancel: false,
});
}
},
fail: (e) => {
// wx.showToast({
// title: '没有发现二维码',
// icon: 'none'
// })
wx.hideLoading();
},
});
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function () {},
onShow() {
page = 1;
var that = this;
loadMoreView = this.selectComponent("#loadMoreView");
const { settlementType, company } = wx.getStorageSync("cooperation");
const userType = wx.getStorageSync("kybUser").userType;
this.setData({
userType,
settlementType,
stationName: company,
});
wx.getSystemInfo({
success: function (res) {
that.setData({
system: res,
});
},
});
this.loadData(0);
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
page = 1;
this.setData({
start: "",
end: "",
});
this.loadData(0);
// http.weChat()
},
loadData: function (offset = 0) {
const startTime =
this.data.start ||
timeStr(
new Date(new Date().toLocaleDateString()).getTime(),
"YYYY-MM-DD hh:mm:ss"
);
this.setData({
start: startTime,
startView: timeStr(new Date(startTime)),
'pickerConfig.initStartTime': startTime
});
const endTime = this.data.end || timeStr(new Date(new Date().toLocaleDateString()).getTime() + 24 * 60 * 60 * 1000 - 1, "YYYY-MM-DD hh:mm:ss");
console.log(endTime, 'endTime');
this.setData({
end: endTime,
endView: timeStr(new Date(endTime)),
'pickerConfig.initEndTime': endTime,
'pickerConfig.limitEndTime': endTime
});
console.log(startTime, 'startTime');
console.log(this.data.startView, 'startView');
console.log(endTime, 'endTime');
console.log(this.data.endView, 'endView');
var that = this;
var uuid = wx.getStorageSync("cooperation").id;
wx.showLoading({
title: "加载中",
mask: true,
});
wx.showNavigationBarLoading();
wx.request({
url:
http.devUrl +
"/api/v1/cooperation/gas/list/trade?cooId=" +
uuid +
"&page=" +
page +
"&startTime=" +
that.data.start +
"&endTime=" +
that.data.end,
header: {
"content-type": "application/x-www-form-urlencoded",
},
success: (res) => {
var items = that.data.items
console.log(items, 'items');
let temp = res.data.data.data.records;
// if (page == 1) {
// for (var i = 0; i < temp.length; i++) {
// if (this.data.settlementType === 2) {
// temp[i].payGift = (temp[i].money - temp[i].gasReceipts).toFixed(2)
// }
// }
// wx.stopPullDownRefresh();
// } else {
// for (var i = 0; i < temp.length; i++) {
// // temp[i].created = timeStr(temp[i].created, "YYYY-MM-DD hh:mm:ss");
// if (this.data.settlementType === 2) {
// temp[i].payGift = (temp[i].money - temp[i].gasReceipts).toFixed(2)
// }
// }
// }
let newData = this.data.items;
newData = offset ? newData.concat(temp) : temp;
const settlementType = res.data.map.cooperation.settlementType
if (settlementType === 2) {
newData.forEach(item => {
item.payGift = (item.money - item.gasReceipts).toFixed(2)
})
}
var cooPrice = res.data.map.cooperation.cooPrice;
if (cooPrice == null) {
cooPrice = "--";
}
if (newData.length > 0) {
this.setData({
showList: true,
}); ''
console.log(temp, 'temptemptemptemp');
loadMoreView.loadMoreComplete(temp);
} else {
this.setData({
showList: false,
});
}
wx.hideNavigationBarLoading();
wx.hideLoading();
if (offset === 0) {
wx.stopPullDownRefresh();
}
that.setData({
items: newData,
cooperation: res.data.map.cooperation,
cooPrice: cooPrice,
moneyTotal: res.data.map.cooperation.money || 0,
gasReceiptsTotal: res.data.map.cooperation.gasReceipts || 0,
offersMoneyTotal: res.data.map.cooperation.offersMoney || 0,
oilQuantityTotal: res.data.map.cooperation.oilQuantity || 0,
isTriggered: false,
totalPages: res.data.data.data.total,
});
// loadMoreView.loadMoreComplete(temp);
},
fail: () => {
if (page != 1) {
loadMoreView.loadMoreFail();
}
},
complete: () => {
wx.hideNavigationBarLoading();
wx.hideLoading();
}
});
},
loadMoreListener: function (e) {
page += 1;
this.loadData(page);
},
clickLoadMore: function (e) {
this.loadData(page);
},
updatePrice: function () {
wx.navigateTo({
url: "../updatePrice/updatePrice",
});
},
});