historyOrder.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. const {
  2. default: api
  3. } = require("../../js/api");
  4. const util = require('../../utils/util.js')
  5. // pages/historyOrderAfter/historyOrderAfter.js
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. date: '',
  12. startDate: '',
  13. endDate: '',
  14. pageNum:1,//查询页码
  15. pageSize:5,//页数
  16. isHaveOrder:true,//是否还有订单
  17. paymentMode: -1,
  18. /** 根据当前模式(后支付:0或预支付:1)+ 授权状态(未授权:0;已授权:1)
  19. * + 订单状态(0:未支付; 1:已支付; 2:订单全额退款;3:订单部分退款;5:已完成)
  20. * 获取订单状态及颜色 */
  21. statusValue: [{
  22. paymentMode: "0",
  23. authorizationStatus: 0,
  24. orderStatus: 0,
  25. status: '未支付',
  26. statusColor: '#ff8d1a'
  27. },
  28. {
  29. paymentMode: "0",
  30. authorizationStatus: 0,
  31. orderStatus: 1,
  32. status: '已完成',
  33. statusColor: '#a6a6a6'
  34. },
  35. {
  36. paymentMode: "0",
  37. authorizationStatus: 0,
  38. orderStatus: 5,
  39. status: '已完成',
  40. statusColor: '#a6a6a6'
  41. },
  42. {
  43. paymentMode: "1",
  44. authorizationStatus: 0,
  45. orderStatus: 1,
  46. status: '已失效',
  47. statusColor: '#a6a6a6'
  48. },
  49. {
  50. paymentMode: "1",
  51. authorizationStatus: 1,
  52. orderStatus: 1,
  53. status: '已授权',
  54. statusColor: '#b1db5a'
  55. },
  56. {
  57. paymentMode: "1",
  58. authorizationStatus: 0,
  59. orderStatus: 2,
  60. status: '已完成',
  61. statusColor: '#a6a6a6'
  62. },
  63. {
  64. paymentMode: "1",
  65. authorizationStatus: 0,
  66. orderStatus: 3,
  67. status: '已完成',
  68. statusColor: '#a6a6a6'
  69. },
  70. {
  71. paymentMode: "1",
  72. authorizationStatus: 0,
  73. orderStatus: 5,
  74. status: '已完成',
  75. statusColor: '#a6a6a6'
  76. },
  77. ],
  78. orders: []
  79. },
  80. /** 获取当前日期 */
  81. getNowDate() {
  82. const date = new Date(); // 获取当前日期
  83. const year = date.getFullYear(); // 获取年份
  84. const month = String(date.getMonth() + 1).padStart(2, '0'); // 获取月份,补零
  85. const day = String(date.getDate()).padStart(2, '0'); // 获取日期,补零
  86. return `${year}-${month}-${day}`; // 拼接成 yyyy-MM-dd 格式
  87. },
  88. /** 获取上个月日期 */
  89. getLastMouthDate() {
  90. const currentDate = new Date(); // 获取当前日期
  91. const year = currentDate.getFullYear(); // 当前年份
  92. const month = currentDate.getMonth(); // 当前月份(0-11)
  93. const day = currentDate.getDate(); // 当前日期
  94. // 计算一个月前的日期
  95. const oneMonthAgoDate = new Date(year, month - 1, day);
  96. // 处理跨年问题(如果当前月份是 1 月,month - 1 会是 0,即上一年的 12 月)
  97. // 无需额外处理,Date 对象会自动处理
  98. // 格式化日期为 YYYY-MM-DD
  99. const formattedDate = `${oneMonthAgoDate.getFullYear()}-${String(oneMonthAgoDate.getMonth() + 1).padStart(2, '0')}-${String(oneMonthAgoDate.getDate()).padStart(2, '0')}`;
  100. return formattedDate;
  101. },
  102. /** 计算倒计时,倒计时结束后发起取消授权 */
  103. startCountdow() {
  104. this.timer = setInterval(() => {
  105. const countDownZeroOrders = []
  106. const orders = this.data.orders.map(order => {
  107. if (order.countdown && order.countdown != '0') {
  108. const currentCountDown = (Number(order.countdown) - 1);
  109. order.countdown = currentCountDown.toString();
  110. if (currentCountDown <= 0) countDownZeroOrders.push(order)
  111. }
  112. return order
  113. })
  114. this.setData({
  115. orders: orders
  116. })
  117. this.toUnAnthorization(countDownZeroOrders)
  118. }, 1000);
  119. },
  120. /** 结束倒计时 */
  121. endCountDown() {
  122. if (this.timer) {
  123. clearInterval(this.timer)
  124. this.timer = null
  125. }
  126. },
  127. /** 发送取消授权 */
  128. toUnAnthorization(orders) {
  129. console.log(orders)
  130. },
  131. /**
  132. * 生命周期函数--监听页面加载
  133. */
  134. onLoad(options) {
  135. const today = this.getNowDate();
  136. const lastMouthDay = this.getLastMouthDate();
  137. this.setData({
  138. date: today,
  139. paymentMode: options.paymentMode,
  140. startDate: today,
  141. endDate: lastMouthDay
  142. });
  143. console.log("历史页当前data",this.data)
  144. this.getOrder();
  145. // this.startCountdow();
  146. },
  147. /**
  148. * 生命周期函数--监听页面初次渲染完成
  149. */
  150. onReady() {
  151. },
  152. /**
  153. * 生命周期函数--监听页面显示
  154. */
  155. onShow() {
  156. },
  157. /**
  158. * 生命周期函数--监听页面隐藏
  159. */
  160. onHide() {
  161. },
  162. /**
  163. * 生命周期函数--监听页面卸载
  164. */
  165. onUnload() {
  166. this.endCountDown()
  167. },
  168. /**
  169. * 页面相关事件处理函数--监听用户下拉动作
  170. */
  171. onPullDownRefresh() {
  172. },
  173. /**
  174. * 页面上拉触底事件的处理函数
  175. */
  176. onReachBottom() {
  177. if(!this.data.isHaveOrder) return;
  178. var page = this.data.pageNum + 1;
  179. this.setData({
  180. pageNum:page
  181. })
  182. this.getOrder()
  183. },
  184. /**
  185. * 用户点击右上角分享
  186. */
  187. onShareAppMessage() {
  188. },
  189. /** 日期选择器选择时间 */
  190. bindDateChange(date) {
  191. this.setData({
  192. date: date.detail.value,
  193. orders:[]
  194. });
  195. console.log(date)
  196. this.getOrder()
  197. },
  198. /** 组件按钮一点击事件 */
  199. onOrderButtonClick1(event) {
  200. console.log(event)
  201. },
  202. /** 组件按钮二点击事件 */
  203. onOrderButtonClick2(event) {
  204. console.log(event)
  205. },
  206. /** 获取订单 */
  207. getOrder() {
  208. const that = this;
  209. api.request_WXFindOrders(this.data.date, this.data.pageNum, this.data.pageSize).then(res => {
  210. // api.request_WXFindOrders(this.data.date, 3, 5).then(res => {
  211. console.log("获取历史订单", res)
  212. const datas = res.data.data;
  213. if(datas.length <= 0) {
  214. that.data.isHaveOrder = false;
  215. return
  216. }
  217. var getOrders = datas.map(order => {
  218. var times = [order.authorizationTime, order.createTime, order.fuelItemTransactionEndTime, order.transactionTime];
  219. var timeFormate = times.find(t => t != undefined && t != null && t != '');
  220. var time = util.formatDateNotSecond(timeFormate);
  221. var volume = (order.originalQty != null && order.originalQty != undefined) ? order.originalQty : order.qty
  222. var status = that.data.statusValue.find(state =>
  223. state.paymentMode == this.data.paymentMode &&
  224. state.authorizationStatus == order.authorizationStatus &&
  225. state.orderStatus == order.orderStatus
  226. )
  227. var stute = '';
  228. var stateColor = '';
  229. var bt2 = ''
  230. if (status != undefined) {
  231. stute = status.status
  232. stateColor = status.statusColor
  233. }
  234. if(stute == '未支付') bt2 = '重新支付';
  235. return {
  236. order: {
  237. status: stute,
  238. statusColor: stateColor,
  239. oilName: order.productName,
  240. nozzle: order.nozzleId,
  241. volume: volume,
  242. amount: order.originalAmount,
  243. payAmount: order.actualPaymentAmount,
  244. discount: order.originalAmount - order.actualPaymentAmount,
  245. orderId: order.id,
  246. time: time
  247. },
  248. bottonText2: bt2
  249. }
  250. })
  251. var orderList = [...this.data.orders,...getOrders]
  252. this.setData({
  253. orders: orderList
  254. })
  255. console.log("转换后的订单", this.data.orders)
  256. }).catch(err => {
  257. console.log("获取历史订单失败", err)
  258. })
  259. }
  260. })