lijijiaofei.js 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. const app = getApp();
  2. Page({
  3. data: {
  4. images: {
  5. logo: '',
  6. background: '',
  7. card: '',
  8. tzd: "",
  9. phone: "",
  10. yl: "",
  11. jcsfcjtzd: ""
  12. },
  13. userInfo: {
  14. name: app.globalData.currentAccountInfo.username,
  15. id: app.globalData.currentAccountInfo.usernumber,
  16. address: app.globalData.currentAccountInfo.address
  17. },
  18. billInfo: {}, // 存储从首页传递过来的账单信息
  19. quickAmounts: [10, 30, 50, 100, 200, 500],
  20. waterUsage: {
  21. lastReading: 2000,
  22. currentReading: 2050,
  23. nextReading: 3020,
  24. usage: 87
  25. },
  26. showKeyboard: false,
  27. selectedAmount: null,
  28. customAmount: '',
  29. inputFocus: false,
  30. zdId:"",
  31. },
  32. onLoad(options) {
  33. const _this=this;
  34. wx.request({
  35. url: app.globalData.interfaceUrls.pendingBill + app.globalData.currentAccountInfo.usernumber,
  36. method: 'POST',
  37. header: {
  38. 'content-type': 'application/json',
  39. 'token': app.globalData.userWxInfo.token,
  40. 'source': "wc",
  41. '!SAAS_LOGIN_TOKEN_!': app.globalData.currentAccountInfo.dsKey
  42. },
  43. success(res) {
  44. wx.hideLoading();
  45. let apiReturnData = res.data;
  46. _this.setData({
  47. amount: apiReturnData.data.yj, // 默认实缴金额为应缴金额
  48. actualAmount: apiReturnData.data.yj, // 设置应缴金额
  49. balance: apiReturnData.data.ye, //余额
  50. zdId: apiReturnData.data.zdId // 对应的账单记录
  51. });
  52. },
  53. fail(error) {
  54. wx.hideLoading();
  55. wx.showToast({
  56. title: '数据加载失败,请稍后再试',
  57. icon: 'none',
  58. duration: 2000
  59. });
  60. }
  61. });
  62. this.setData({
  63. images: {
  64. logo:'/static_file/logo.png',
  65. background:'/static_file/background.png',
  66. card:'/static_file/card.png',
  67. tzd:'/static_file/backgrountzdd.png',
  68. phone:'/static_file/phone.png',
  69. yl:'/static_file/background.yl',
  70. jcsfcjtzd:'/static_file/jcsfcjtzd.png',
  71. kapiantubiao:'/static_file/kapiantubiao.png'
  72. }
  73. })
  74. // 获取状态栏高度
  75. const systemInfo = wx.getSystemInfoSync();
  76. this.setData({
  77. statusBarHeight: systemInfo.statusBarHeight
  78. });
  79. this.fetchPaymentData();
  80. },
  81. // 选择快捷金额
  82. selectAmount: function(e) {
  83. const amount = e.currentTarget.dataset.amount;
  84. this.setData({
  85. amount: parseFloat(amount),
  86. selectedAmount: parseFloat(amount),
  87. customAmount: '' // 清空自定义金额
  88. });
  89. },
  90. // 立即缴费
  91. payNow: function() {
  92. wx.showLoading({
  93. title: '处理中',
  94. });
  95. wx.request({
  96. url: app.globalData.interfaceUrls.prepayOrder,
  97. method: 'POST',
  98. header: {
  99. 'content-type': 'application/json',
  100. 'token': app.globalData.userWxInfo.token,
  101. 'source': "wc",
  102. '!SAAS_LOGIN_TOKEN_!': app.globalData.currentAccountInfo.dsKey
  103. },
  104. data: {
  105. openId: app.globalData.userWxInfo.openid,
  106. totalAmount: this.data.amount*100,
  107. dskey: app.globalData.currentAccountInfo.dsKey
  108. },
  109. success: res => {
  110. wx.hideLoading();
  111. console.log('预下单', res);
  112. let orderNo=res.data.data.orderNo;
  113. wx.requestPayment({
  114. timeStamp: res.data.data.paymentSign.timeStamp,
  115. nonceStr: res.data.data.paymentSign.nonceStr,
  116. package: res.data.data.paymentSign.packageVal,
  117. signType: 'RSA',
  118. paySign: res.data.data.paymentSign.paySign,
  119. success: res => {
  120. console.log('支付结果', res);
  121. this.createWeChatPayMentRecord(orderNo,this.data.amount);
  122. },
  123. fail (res) {
  124. console.log("fail",res);
  125. },
  126. complete: () => {
  127. }
  128. })
  129. }
  130. })
  131. // 模拟支付
  132. // setTimeout(() => {
  133. // wx.hideLoading();
  134. // wx.showToast({
  135. // title: '缴费成功',
  136. // icon: 'success',
  137. // duration: 2000,
  138. // success: () => {
  139. // // 支付成功后返回首页
  140. // setTimeout(() => {
  141. // wx.navigateBack();
  142. // }, 2000);
  143. // }
  144. // });
  145. // }, 1500);
  146. },
  147. // 返回上一页
  148. goBack: function() {
  149. wx.navigateBack();
  150. },
  151. // 切换到首页
  152. goToHome: function() {
  153. wx.switchTab({
  154. url: '/pages/homepage/homepage',
  155. });
  156. },
  157. // 切换到我的页面
  158. goToMine: function() {
  159. wx.switchTab({
  160. url: '/pages/mine/mine',
  161. });
  162. },
  163. // 添加切换水表的方法
  164. switchMeter: function() {
  165. wx.navigateTo({
  166. url: '/pages/switchMeter/switchMeter',
  167. })
  168. },
  169. navigateToHome() {
  170. wx.switchTab({
  171. url: '/pages/index/index'
  172. })
  173. },
  174. navigateToMine() {
  175. wx.switchTab({
  176. url: '/pages/mine/mine'
  177. })
  178. },
  179. // 显示键盘 - 使用微信内置键盘
  180. showCustomAmountInput: function() {
  181. // 使用微信内置的输入框
  182. wx.showModal({
  183. title: '请输入金额',
  184. placeholderText: '请输入缴费金额',
  185. editable: true,
  186. success: (res) => {
  187. if (res.confirm && res.content) {
  188. // 验证输入是否为有效数字
  189. const inputAmount = parseFloat(res.content);
  190. if (!isNaN(inputAmount) && inputAmount > 0) {
  191. this.setData({
  192. amount: inputAmount
  193. });
  194. } else {
  195. wx.showToast({
  196. title: '请输入有效金额',
  197. icon: 'none'
  198. });
  199. }
  200. }
  201. }
  202. });
  203. },
  204. // 输入数字
  205. inputNumber: function(e) {
  206. const number = e.currentTarget.dataset.number;
  207. let amount = this.data.amount;
  208. // 处理小数点
  209. if (number === '.' && amount.includes('.')) {
  210. return;
  211. }
  212. // 限制小数点后两位
  213. if (amount.includes('.') && amount.split('.')[1].length >= 2 && number !== '.') {
  214. return;
  215. }
  216. // 更新金额
  217. this.setData({
  218. amount: amount === '0' ? number : amount + number
  219. });
  220. },
  221. // 删除数字
  222. deleteNumber: function() {
  223. let amount = this.data.amount;
  224. if (amount.length <= 1) {
  225. this.setData({
  226. amount: '0'
  227. });
  228. } else {
  229. this.setData({
  230. amount: amount.substring(0, amount.length - 1)
  231. });
  232. }
  233. },
  234. // 确认输入
  235. confirmInput: function() {
  236. this.setData({
  237. showKeyboard: false
  238. });
  239. },
  240. // 添加自定义金额输入处理函数
  241. onCustomAmountInput: function(e) {
  242. let value = e.detail.value;
  243. // 只允许数字和小数点,且小数点后最多两位
  244. if (value) {
  245. // 移除非数字和小数点字符
  246. value = value.replace(/[^\d.]/g, '');
  247. // 确保只有一个小数点
  248. const parts = value.split('.');
  249. if (parts.length > 2) {
  250. value = parts[0] + '.' + parts.slice(1).join('');
  251. }
  252. // 限制小数点后最多两位
  253. if (parts.length === 2 && parts[1].length > 2) {
  254. value = parts[0] + '.' + parts[1].substring(0, 2);
  255. }
  256. // 限制总长度小于8位(包含小数点)
  257. if (value.length > 7) {
  258. value = value.substring(0, 7);
  259. }
  260. }
  261. this.setData({
  262. customAmount: value,
  263. selectedAmount: 0, // 清除其他金额选择
  264. amount: value || '0.00' // 更新显示金额
  265. });
  266. },
  267. // 输入框获得焦点
  268. onInputFocus: function() {
  269. this.setData({
  270. inputFocus: true,
  271. selectedAmount: null // 取消快捷金额的选中状态
  272. });
  273. },
  274. // 输入框失去焦点
  275. onInputBlur: function() {
  276. this.setData({
  277. inputFocus: false
  278. });
  279. },
  280. // 创建微信付款记录
  281. createWeChatPayMentRecord:function(orderNo,paymentAmount){
  282. wx.request({
  283. url: app.globalData.interfaceUrls.createPaymentRecord,
  284. method: 'POST',
  285. header: {
  286. 'content-type': 'application/json',
  287. 'token': app.globalData.userWxInfo.token,
  288. 'source': "wc",
  289. '!SAAS_LOGIN_TOKEN_!': app.globalData.currentAccountInfo.dsKey
  290. },
  291. data: {
  292. orderNo: orderNo,
  293. paymentAmount: paymentAmount,
  294. zdId: this.data.zdId,
  295. userNumber: app.globalData.currentAccountInfo.usernumber,
  296. dsKey: app.globalData.currentAccountInfo.dsKey
  297. },
  298. success(res) {
  299. wx.hideLoading();
  300. wx.navigateTo({
  301. url: '/pages/jiaofeiSuccess/jiaofeiSuccess',
  302. });
  303. },
  304. fail(error) {
  305. wx.hideLoading();
  306. wx.showToast({
  307. title: '数据加载失败,请稍后再试',
  308. icon: 'none',
  309. duration: 2000
  310. });
  311. }
  312. });
  313. },
  314. // 从接口获取支付数据
  315. fetchPaymentData: function() {
  316. // 这里是模拟数据,实际应用中应该调用真实接口
  317. // wx.request({
  318. // url: 'your-api-endpoint',
  319. // success: (res) => {
  320. // this.setData({
  321. // amountDue: res.data.amountDue,
  322. // balance: res.data.balance
  323. // });
  324. // }
  325. // });
  326. // this.setData({
  327. // amountDue: 150.00,
  328. // balance: 200.50
  329. // });
  330. },
  331. })