C端小程序
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.

166 line
3.7 KiB

  1. const util = require("../../utils/util.js");
  2. const config = require("../../config/config.js");
  3. const Http = require("../../utils/HttpBasics");
  4. const AUTH_MODE = 'fingerPrint';
  5. let app = getApp();
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. merChant: {},
  12. focus: true,
  13. inputValue: ''
  14. },
  15. /**
  16. * 生命周期函数--监听页面加载
  17. */
  18. onLoad: function(options) {
  19. let that = this;
  20. that.setData({
  21. merChant: JSON.parse(options.merChant),
  22. cardid: options.cardid,
  23. remainingAmount: options.remainingAmount
  24. })
  25. console.log(that.data.remainingAmount)
  26. console.log("------------------remainingAmount-------------------")
  27. },
  28. bindKeyInput(e) {
  29. console.log(e)
  30. this.setData({
  31. inputValue: e.detail.value
  32. })
  33. },
  34. gotoPayMoney: function() {
  35. let that = this;
  36. Http.post({
  37. url: config.api.cardPayOrder,
  38. data: {
  39. cardId: that.data.cardid,
  40. merchantCode: that.data.merChant.merchant_id,
  41. totalFee: that.data.inputValue
  42. }
  43. })
  44. .then(res => {
  45. console.log(res);
  46. wx.navigateTo({
  47. url: '/pages/paySuccess/paySuccess',
  48. })
  49. })
  50. .catch(err => {
  51. wx.showModal({
  52. title: "抱歉",
  53. content: err.message,
  54. showCancel: false
  55. })
  56. })
  57. },
  58. // 指纹识别
  59. startAuth() {
  60. let that = this;
  61. // 卡余额充足的时候,才可以付钱
  62. if (that.data.inputValue != "" && that.data.remainingAmount >= that.data.inputValue) {
  63. const startSoterAuthentication = () => {
  64. wx.startSoterAuthentication({
  65. requestAuthModes: [AUTH_MODE],
  66. challenge: 'test',
  67. authContent: '小程序支付',
  68. success: (res) => {
  69. this.gotoPayMoney();
  70. },
  71. fail: (err) => {
  72. }
  73. })
  74. }
  75. const checkIsEnrolled = () => {
  76. wx.checkIsSoterEnrolledInDevice({
  77. checkAuthMode: AUTH_MODE,
  78. success: (res) => {
  79. console.log(res)
  80. if (parseInt(res.isEnrolled) <= 0) {
  81. wx.showModal({
  82. title: '错误',
  83. content: '您暂未录入指纹信息,请录入后重试',
  84. showCancel: false
  85. })
  86. return
  87. }
  88. startSoterAuthentication();
  89. },
  90. fail: (err) => {
  91. console.error(err)
  92. }
  93. })
  94. }
  95. wx.checkIsSupportSoterAuthentication({
  96. success: (res) => {
  97. console.log(res)
  98. checkIsEnrolled()
  99. },
  100. fail: (err) => {
  101. console.error(err);
  102. wx.showModal({
  103. title: '错误',
  104. content: '您的设备不支持指纹识别',
  105. showCancel: false
  106. })
  107. }
  108. })
  109. } else if (that.data.inputValue == ""){
  110. wx.showModal({
  111. title: '抱歉',
  112. content: '请输入金额',
  113. showCancel: false
  114. })
  115. } else if (that.data.inputValue != ""&&that.data.remainingAmount < that.data.inputValue){
  116. wx.showModal({
  117. title: '抱歉',
  118. content: '余额不足',
  119. showCancel:false
  120. })
  121. }
  122. },
  123. /**
  124. * 生命周期函数--监听页面显示
  125. */
  126. onShow: function() {
  127. },
  128. /**
  129. * 生命周期函数--监听页面隐藏
  130. */
  131. onHide: function() {
  132. },
  133. /**
  134. * 生命周期函数--监听页面卸载
  135. */
  136. onUnload: function() {
  137. },
  138. /**
  139. * 页面相关事件处理函数--监听用户下拉动作
  140. */
  141. onPullDownRefresh: function() {
  142. },
  143. /**
  144. * 页面上拉触底事件的处理函数
  145. */
  146. onReachBottom: function() {
  147. },
  148. /**
  149. * 用户点击右上角分享
  150. */
  151. onShareAppMessage: function() {
  152. }
  153. })