parking-order.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. // components/parking-order.js
  2. Component({
  3. /**
  4. * 组件的属性列表
  5. */
  6. properties: {
  7. occupyOrder:{
  8. type: Array,
  9. value: []
  10. },
  11. showPopup:{
  12. type: Boolean,
  13. value: false
  14. }
  15. },
  16. lifetimes:{
  17. attached(){
  18. console.log("加载占位中订单组件");
  19. // this.loadOccupyOrder();
  20. // 页面加载时显示弹窗
  21. let isLogin = wx.getStorageSync('isLogin');
  22. if (isLogin) {
  23. this.loadOccupyOrder().then(data => {
  24. this.fetchData();
  25. })
  26. .catch(error => {
  27. console.error("数据加载失败", error);
  28. });
  29. }
  30. },
  31. detached: function() {
  32. // 在组件实例被从页面节点树移除时执行
  33. this.stopPolling();
  34. },
  35. },
  36. pageLifetimes:{
  37. // 组件所在页面的生命周期函数
  38. show: function () {
  39. if (this.data.pollingInterval) {
  40. this.stopPolling();
  41. }
  42. const executePolling = () => {
  43. console.log("执行定时器");
  44. this.loadOccupyOrder().then(data => {
  45. console.log("hhhh", data);
  46. if (data.code === 500) {
  47. // 无占位费订单
  48. this.stopPolling();
  49. return;
  50. }
  51. this.fetchData();
  52. });
  53. };
  54. // 立即执行一次
  55. executePolling();
  56. // 设置定时器
  57. this.data.pollingInterval = setInterval(executePolling, 30000);
  58. },
  59. hide: function() {
  60. // 页面被隐藏
  61. this.stopPolling();
  62. },
  63. },
  64. /**
  65. * 组件的初始数据
  66. */
  67. data: {
  68. showPopup: false,
  69. occupyFeeOrderList:[],
  70. pollingInterval: null, // 定时器,
  71. costCycleFee:0
  72. },
  73. /**
  74. * 组件的方法列表
  75. */
  76. methods: {
  77. fetchData() {
  78. let that = this;
  79. let occupyFeeOrder = that.data.occupyFeeOrderList[0];
  80. console.log("occupyFeeOrder",occupyFeeOrder);
  81. // 如果 occupyFeeOrder 不存在,直接返回
  82. if (!occupyFeeOrder) {
  83. console.warn("occupyFeeOrder 不存在,跳过本次轮询");
  84. return;
  85. }
  86. wx.request({
  87. url: 'https://jqcs.pjnes.com/cloud/occupyfee/evcs/occupyfee/template',
  88. data: occupyFeeOrder.orderId,
  89. method: 'POST',
  90. success(res) {
  91. that.calculate(occupyFeeOrder, res.data);
  92. }
  93. });
  94. },
  95. calculate(occupyFeeOrder,data) {
  96. // let { occupyBeginTime ="" ,occupyTime =""} = occupyFeeOrder;
  97. // 将时间字符串转换为 Date 对象
  98. // occupyBeginTime = new Date(occupyBeginTime.replace(/-/g, "/")); // 替换为兼容 iOS 的格式
  99. // let currentTime = new Date();
  100. // 计算时间差(分)
  101. // let minutesDifference = Math.floor((currentTime - occupyBeginTime) / (1000 * 60));
  102. let minutesDifference = data.params.occupyTime;
  103. let freeTime = Number(data.freeTime) || 0;
  104. console.log("免费时长:",freeTime);
  105. console.log("封顶费用:", data.maxFee);
  106. console.log("data:", data);
  107. console.log("分钟:", minutesDifference);
  108. if (minutesDifference >= freeTime +1) {
  109. let cycle =((Math.floor(minutesDifference / data.costCycle))* data.costCycleFee).toFixed(2)
  110. let max = data.maxFee
  111. if (cycle <= max || max == null ) {
  112. console.log("未达到最大时长",cycle);
  113. // let Nocycle = Math.floor(minutesDifference / data.costCycle)
  114. // occupyFeeOrder.occupyFee = (Nocycle * data.costCycleFee).toFixed(2);
  115. occupyFeeOrder.occupyFee = cycle
  116. occupyFeeOrder.occupyTime = minutesDifference;
  117. } else {
  118. console.log("达到最大时长");
  119. // let cycle = Math.floor(data.maxFee / data.costCycle)
  120. // occupyFeeOrder.occupyFee = (cycle * data.costCycleFee).toFixed(2);
  121. occupyFeeOrder.occupyFee = data.maxFee
  122. occupyFeeOrder.occupyTime =minutesDifference;
  123. }
  124. } else {
  125. console.log("处于免费时长");
  126. occupyFeeOrder.occupyFee = 0.00;
  127. occupyFeeOrder.occupyTime = minutesDifference;
  128. }
  129. console.log("触发定时器",occupyFeeOrder);
  130. // 根据返回的结果去调用微服务查询模版信息接口,根据模版信息 重新动态计算占位费模版
  131. this.setData({
  132. "occupyFeeOrderList[0]": occupyFeeOrder
  133. });
  134. },
  135. // Stop polling
  136. stopPolling: function() {
  137. if (this.data.pollingInterval) {
  138. console.log('清除占位中定时器');
  139. clearInterval(this.data.pollingInterval);
  140. this.data.pollingInterval = null;
  141. }
  142. },
  143. loadOccupyOrder() {
  144. let that = this;
  145. return new Promise((resolve, reject) => {
  146. wx.request({
  147. url: getApp().globalData.postHeadAgreement + '/restapi/wechat/queryOccupyFeeOrder',
  148. data: {
  149. userId: wx.getStorageSync('userInfo').userId,
  150. searchIndex: 2,
  151. pagenum: this.data.pagenum++,
  152. pagesize: 10,
  153. },
  154. method: 'POST',
  155. success(res) {
  156. console.log("占位费", res);
  157. if (res.data.result) {
  158. let { rows: occupyFeeOrderList } = res.data.result;
  159. that.setData({
  160. occupyFeeOrderList: occupyFeeOrderList,
  161. });
  162. resolve(res.data.result);
  163. } else {
  164. resolve(res.data);
  165. }
  166. },
  167. fail(err) {
  168. reject(err);
  169. }
  170. });
  171. });
  172. },
  173. handleConfirm() {
  174. // 点击确认按钮
  175. this.setData({
  176. showPopup: false
  177. });
  178. },
  179. handleContact() {
  180. // 联系客服
  181. // wx.makePhoneCall({
  182. // phoneNumber: '4009608068' // 替换为实际的客服电话
  183. // });
  184. wx.showModal({
  185. title: '提示',
  186. confirmColor: '#00AADD',
  187. confirmText: '联系客服',
  188. content: '若对当前占位费订单有疑问,请拨打客服电话4009608068,工作时间:08:00-17:00',
  189. complete: (res) => {
  190. // 可以在这里添加回调逻辑
  191. if (res.confirm) {
  192. wx.makePhoneCall({
  193. phoneNumber: '4009608068' // 替换为实际的客服电话
  194. });
  195. console.log('用户点击了确认按钮');
  196. }else{
  197. console.log('用户点击了取消按钮');
  198. }
  199. }
  200. });
  201. },
  202. }
  203. })