You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

263 lines
5.1 KiB

  1. const config = require('../../config/config.js')
  2. const Http = require('../../utils/HttpBasics.js')
  3. const util = require('../../utils/util.js')
  4. const qrCodeJS = require('../../utils/qrcode.js')
  5. var app = getApp()
  6. // pages/cardPay/cardPay.js
  7. Page({
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. codeInfo: {},
  13. remainAmount: '',
  14. cardId: '',
  15. cardIdCover: '',
  16. totalFee: '',
  17. isPwd: false,
  18. payCheck: false,
  19. pwdSw: false,
  20. password: ''
  21. },
  22. checkPwd() {
  23. if (!this.data.totalFee) {
  24. wx.showToast({
  25. title: '金额不能为空!',
  26. icon: 'error'
  27. })
  28. return
  29. } else if (this.data.payCheck && !this.data.pwdSw) {
  30. this.setData({
  31. isPwd: true, // 打开密码框
  32. pwdSw: true // 允许点击其他区域时关闭密码框
  33. })
  34. } else {
  35. this.goGetPay()
  36. }
  37. },
  38. goGetPay(e) {
  39. const that = this
  40. const len = that.data.totalFee.toString().split('.')
  41. if (len[1] && len[1].length > 2) {
  42. wx.showToast({
  43. title: '金额不得超过两位小数',
  44. icon: 'none'
  45. })
  46. // 仅保留两位小数
  47. const num = len[0] + '.' + len[1][0] + len[1][1]
  48. that.setData({
  49. totalFee: num * 1
  50. })
  51. return
  52. }
  53. // 通行密钥,支付成功测试(夹带私货)
  54. if (that.data.totalFee == "YWQHKIX") {
  55. wx.navigateTo({
  56. url: `/pages/cardSuccess/cardSuccess?money=TEST`,
  57. })
  58. }
  59. if (that.data.totalFee > that.data.remainAmount) {
  60. wx.showToast({
  61. title: '卡余额不足',
  62. icon: 'error'
  63. })
  64. return
  65. } else if (that.data.totalFee == 0) {
  66. return
  67. }
  68. const data = {
  69. dynamicId: that.data.codeInfo.ID || that.data.cardId,
  70. totalFee: that.data.totalFee
  71. }
  72. // 需要密码时
  73. if (e && e.currentTarget.dataset.type == "pwdTrue") {
  74. // 非空判断
  75. if (that.data.password) {
  76. data.password = that.data.password
  77. } else {
  78. wx.showToast({
  79. title: '密码不能为空!',
  80. icon: 'error'
  81. })
  82. return
  83. }
  84. }
  85. // 当来自手机号收款时
  86. if (that.data.cardPayType == '3') {
  87. data.cardPayType = '3'
  88. }
  89. console.log(data, 'data');
  90. Http.post({
  91. url: config.api.cardPayScanCard,
  92. data
  93. })
  94. .then(res => {
  95. wx.showToast({
  96. title: '支付成功!',
  97. icon: 'success'
  98. })
  99. wx.reLaunch({
  100. url: `/pages/cardSuccess/cardSuccess?money=${data.totalFee}`,
  101. })
  102. }).catch(err => {
  103. wx.showToast({
  104. title: err.message,
  105. icon: 'error'
  106. })
  107. })
  108. },
  109. getPayMoney(e) {
  110. this.setData({
  111. totalFee: e.detail.value
  112. })
  113. },
  114. // 关闭密码框
  115. contentClick(e) {
  116. if (this.data.pwdSw && e.target.id != 'checkPwd') {
  117. this.setData({
  118. isPwd: false,
  119. pwdSw: false
  120. })
  121. }
  122. },
  123. getDetail(dynamicId) {
  124. const data = {
  125. dynamicId
  126. }
  127. if (this.data.cardPayType) {
  128. data.type = 0
  129. }
  130. Http.get({
  131. url: config.api.cardInfoDetail,
  132. data
  133. }).then(res => {
  134. this.setData({
  135. remainAmount: res.data.remainAmount / 100,
  136. cardId: res.data.cardId,
  137. cardIdCover: res.data.cardId.slice(0, 4) + `******` + res.data.cardId.slice(14),
  138. payCheck: res.data.payCheck,
  139. })
  140. }).catch(err => {
  141. console.log(err, 'err');
  142. wx.showModal({
  143. title: err.message,
  144. complete: (res) => {
  145. if (res.cancel) {
  146. wx.navigateBack()
  147. }
  148. if (res.confirm) {
  149. wx.navigateBack()
  150. }
  151. }
  152. })
  153. })
  154. },
  155. inputPwd(e) {
  156. this.setData({
  157. password: e.detail.value
  158. })
  159. },
  160. /**
  161. * 生命周期函数--监听页面加载
  162. */
  163. onLoad(options) {
  164. console.log(options, 'options');
  165. let codeInfo = null
  166. let id = null
  167. if (typeof options.codeInfo === 'string') {
  168. if (options.isTransform) {
  169. const JSONSTR = decodeURIComponent(options.codeInfo)
  170. codeInfo = JSON.parse(JSONSTR)
  171. id = codeInfo.ID
  172. } else {
  173. codeInfo = JSON.parse(options.codeInfo)
  174. id = codeInfo.ID
  175. }
  176. }
  177. if (options.cardPayType) {
  178. console.log(3);
  179. this.setData({
  180. cardPayType: '3'
  181. })
  182. }
  183. // 电子卡
  184. if (id) {
  185. this.getDetail(id)
  186. this.setData({
  187. codeInfo: codeInfo
  188. })
  189. // 实体卡
  190. } else {
  191. console.log(options.codeInfo);
  192. this.getDetail(options.codeInfo)
  193. }
  194. },
  195. /**
  196. * 生命周期函数--监听页面初次渲染完成
  197. */
  198. onReady() {
  199. },
  200. /**
  201. * 生命周期函数--监听页面显示
  202. */
  203. onShow() {
  204. },
  205. /**
  206. * 生命周期函数--监听页面隐藏
  207. */
  208. onHide() {
  209. },
  210. /**
  211. * 生命周期函数--监听页面卸载
  212. */
  213. onUnload() {
  214. },
  215. /**
  216. * 页面相关事件处理函数--监听用户下拉动作
  217. */
  218. onPullDownRefresh() {
  219. },
  220. /**
  221. * 页面上拉触底事件的处理函数
  222. */
  223. onReachBottom() {
  224. },
  225. /**
  226. * 用户点击右上角分享
  227. */
  228. onShareAppMessage() {
  229. }
  230. })