parking-order.js 6.4 KB

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