lijijiaofei.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. Page({
  2. data: {
  3. images: {
  4. logo: '',
  5. background: '',
  6. card: '',
  7. tzd: "",
  8. phone: "",
  9. yl: "",
  10. jcsfcjtzd: ""
  11. },
  12. userInfo: {
  13. name: '王源',
  14. phone: '32018545245104',
  15. address: '徐州市丰县***楼102室'
  16. },
  17. amount: 73.28, //应缴金额
  18. actualAmount: 73.28,
  19. balance: 0, // 余额
  20. quickAmounts: [10, 30, 50, 100, 200, 500],
  21. waterUsage: {
  22. lastReading: 2000,
  23. currentReading: 2050,
  24. nextReading: 3020,
  25. usage: 87
  26. },
  27. showKeyboard: false,
  28. selectedAmount: null,
  29. customAmount: '',
  30. inputFocus: false,
  31. },
  32. onLoad() {
  33. this.setData({
  34. images: {
  35. logo:'/static_file/logo.png',
  36. background:'/static_file/background.png',
  37. card:'/static_file/card.png',
  38. tzd:'/static_file/backgrountzdd.png',
  39. phone:'/static_file/phone.png',
  40. yl:'/static_file/background.yl',
  41. jcsfcjtzd:'/static_file/jcsfcjtzd.png',
  42. kapiantubiao:'/static_file/kapiantubiao.png'
  43. }
  44. })
  45. // 获取状态栏高度
  46. const systemInfo = wx.getSystemInfoSync();
  47. this.setData({
  48. statusBarHeight: systemInfo.statusBarHeight
  49. });
  50. this.fetchPaymentData();
  51. },
  52. // 选择快捷金额
  53. selectAmount: function(e) {
  54. const amount = e.currentTarget.dataset.amount;
  55. this.setData({
  56. amount: parseFloat(amount),
  57. selectedAmount: parseFloat(amount),
  58. customAmount: '' // 清空自定义金额
  59. });
  60. },
  61. // 立即缴费
  62. payNow: function() {
  63. wx.showLoading({
  64. title: '处理中',
  65. });
  66. // 模拟支付
  67. setTimeout(() => {
  68. wx.hideLoading();
  69. wx.showToast({
  70. title: '缴费成功',
  71. icon: 'success',
  72. duration: 2000,
  73. success: () => {
  74. // 支付成功后返回首页
  75. setTimeout(() => {
  76. wx.navigateBack();
  77. }, 2000);
  78. }
  79. });
  80. }, 1500);
  81. },
  82. // 返回上一页
  83. goBack: function() {
  84. wx.navigateBack();
  85. },
  86. // 切换到首页
  87. goToHome: function() {
  88. wx.switchTab({
  89. url: '/pages/homepage/homepage',
  90. });
  91. },
  92. // 切换到我的页面
  93. goToMine: function() {
  94. wx.switchTab({
  95. url: '/pages/mine/mine',
  96. });
  97. },
  98. // 添加切换水表的方法
  99. switchMeter: function() {
  100. wx.navigateTo({
  101. url: '/pages/switchMeter/switchMeter',
  102. })
  103. },
  104. navigateToHome() {
  105. wx.switchTab({
  106. url: '/pages/index/index'
  107. })
  108. },
  109. navigateToMine() {
  110. wx.switchTab({
  111. url: '/pages/mine/mine'
  112. })
  113. },
  114. // 显示键盘 - 使用微信内置键盘
  115. showCustomAmountInput: function() {
  116. // 使用微信内置的输入框
  117. wx.showModal({
  118. title: '请输入金额',
  119. placeholderText: '请输入缴费金额',
  120. editable: true,
  121. success: (res) => {
  122. if (res.confirm && res.content) {
  123. // 验证输入是否为有效数字
  124. const inputAmount = parseFloat(res.content);
  125. if (!isNaN(inputAmount) && inputAmount > 0) {
  126. this.setData({
  127. amount: inputAmount
  128. });
  129. } else {
  130. wx.showToast({
  131. title: '请输入有效金额',
  132. icon: 'none'
  133. });
  134. }
  135. }
  136. }
  137. });
  138. },
  139. // 输入数字
  140. inputNumber: function(e) {
  141. const number = e.currentTarget.dataset.number;
  142. let amount = this.data.amount;
  143. // 处理小数点
  144. if (number === '.' && amount.includes('.')) {
  145. return;
  146. }
  147. // 限制小数点后两位
  148. if (amount.includes('.') && amount.split('.')[1].length >= 2 && number !== '.') {
  149. return;
  150. }
  151. // 更新金额
  152. this.setData({
  153. amount: amount === '0' ? number : amount + number
  154. });
  155. },
  156. // 删除数字
  157. deleteNumber: function() {
  158. let amount = this.data.amount;
  159. if (amount.length <= 1) {
  160. this.setData({
  161. amount: '0'
  162. });
  163. } else {
  164. this.setData({
  165. amount: amount.substring(0, amount.length - 1)
  166. });
  167. }
  168. },
  169. // 确认输入
  170. confirmInput: function() {
  171. this.setData({
  172. showKeyboard: false
  173. });
  174. },
  175. // 添加自定义金额输入处理函数
  176. onCustomAmountInput: function(e) {
  177. let value = e.detail.value;
  178. // 限制只能输入小数点后两位
  179. if (value.indexOf('.') !== -1) {
  180. const parts = value.split('.');
  181. if (parts[1].length > 2) {
  182. value = parts[0] + '.' + parts[1].substring(0, 2);
  183. }
  184. }
  185. // 验证输入是否为有效数字
  186. if (value) {
  187. const inputAmount = parseFloat(value);
  188. if (!isNaN(inputAmount) && inputAmount >= 0) {
  189. // 更新实缴金额和自定义金额
  190. this.setData({
  191. amount: inputAmount,
  192. customAmount: value,
  193. selectedAmount: null // 取消快捷金额的选中状态
  194. });
  195. } else {
  196. this.setData({
  197. customAmount: value
  198. });
  199. }
  200. } else {
  201. // 输入框为空时
  202. this.setData({
  203. customAmount: '',
  204. amount: 0
  205. });
  206. }
  207. },
  208. // 输入框获得焦点
  209. onInputFocus: function() {
  210. this.setData({
  211. inputFocus: true,
  212. selectedAmount: null // 取消快捷金额的选中状态
  213. });
  214. },
  215. // 输入框失去焦点
  216. onInputBlur: function() {
  217. this.setData({
  218. inputFocus: false
  219. });
  220. },
  221. // 从接口获取支付数据
  222. fetchPaymentData: function() {
  223. // 这里是模拟数据,实际应用中应该调用真实接口
  224. // wx.request({
  225. // url: 'your-api-endpoint',
  226. // success: (res) => {
  227. // this.setData({
  228. // amountDue: res.data.amountDue,
  229. // balance: res.data.balance
  230. // });
  231. // }
  232. // });
  233. // this.setData({
  234. // amountDue: 150.00,
  235. // balance: 200.50
  236. // });
  237. },
  238. })