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.

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