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.

188 lines
4.5 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. cardList: [],
  15. showModel: false,
  16. },
  17. /**
  18. * 生命周期函数--监听页面加载
  19. */
  20. onLoad: function (options) {
  21. let that = this;
  22. that.setData({
  23. merChant: JSON.parse(options.merChant),
  24. cardid: options.cardid,
  25. remainingAmount: options.remainingAmount
  26. })
  27. },
  28. bindKeyInput(e) {
  29. console.log(e)
  30. this.setData({
  31. inputValue: e.detail.value
  32. })
  33. },
  34. gotoPayMoney: function (flags) {
  35. let that = this;
  36. const startSoterAuthentication = () => {
  37. wx.startSoterAuthentication({
  38. requestAuthModes: [AUTH_MODE],
  39. challenge: 'test',
  40. authContent: '请验证已有的指纹以继续',
  41. success: (res) => {
  42. that.gotoPay()
  43. },
  44. fail: (err) => {
  45. }
  46. })
  47. }
  48. const checkIsEnrolled = () => {
  49. wx.checkIsSoterEnrolledInDevice({
  50. checkAuthMode: AUTH_MODE,
  51. success: (res) => {
  52. console.log(res)
  53. if (parseInt(res.isEnrolled) <= 0) {
  54. that.gotoPay();
  55. return
  56. }
  57. startSoterAuthentication();
  58. },
  59. fail: (err) => {
  60. console.error(err)
  61. }
  62. })
  63. }
  64. wx.checkIsSupportSoterAuthentication({
  65. success: (res) => {
  66. console.log(res)
  67. if(res.supportMode == []){
  68. that.gotoPay();
  69. }else if(res.supportMode == ['fingerPrint']){
  70. checkIsEnrolled()
  71. }else if(res.supportMode = ['fingerPrint', 'facial'] ){
  72. that.gotoPay();
  73. }
  74. },
  75. fail: (err) => {
  76. console.error(err);
  77. that.gotoPay();
  78. }
  79. })
  80. },
  81. gotoPay: function () {
  82. let that = this;
  83. Http.post({
  84. url: config.api.cardPayOrder,
  85. data: {
  86. cardId: that.data.cardid,
  87. merchantCode: that.data.merChant.merchant_id,
  88. totalFee: that.data.inputValue
  89. }
  90. })
  91. .then(res => {
  92. if (res.code == 200) {
  93. that.setData({
  94. showModel: false
  95. })
  96. wx.navigateTo({
  97. url: `/pages/paySuccess/paySuccess?data=${JSON.stringify(res.data)}`,
  98. })
  99. }
  100. })
  101. .catch(err => {
  102. wx.showModal({
  103. title: "抱歉",
  104. content: err.message,
  105. showCancel: false
  106. })
  107. })
  108. },
  109. // 指纹识别
  110. startAuth(e) {
  111. let that = this;
  112. if (e) {
  113. if (e.currentTarget.dataset.flags == 'check') {
  114. that.setData({
  115. ids: e.currentTarget.dataset.id,
  116. cardid: e.currentTarget.dataset.id,
  117. remainingAmount: e.currentTarget.dataset.remainingamount,
  118. })
  119. }
  120. }
  121. if (that.data.inputValue == "" || that.data.inputValue == 0) {
  122. wx.showModal({
  123. title: '抱歉',
  124. content: '请输入金额',
  125. showCancel: false
  126. })
  127. } else if (that.data.inputValue != "" && Number(that.data.remainingAmount) < Number(that.data.inputValue)) {
  128. that.setData({
  129. showModel: true
  130. })
  131. that.getList('notenogth');
  132. } else if (that.data.inputValue != "" && Number(that.data.remainingAmount) >= Number(that.data.inputValue)) {
  133. that.gotoPayMoney();
  134. }
  135. },
  136. gotonewcard: function () {
  137. wx.navigateTo({
  138. url: '/pages/discountCardList/discountCardList'
  139. })
  140. this.setData({
  141. showModel: false
  142. })
  143. },
  144. getList() {
  145. var that = this;
  146. var data = {
  147. pageNum: 1,
  148. pageSize: 100,
  149. couponType: "7",
  150. couponOrderStatus: 4
  151. }
  152. Http.get({
  153. url: config.api.cardorderList,
  154. data: data
  155. })
  156. .then(res => {
  157. console.log(res)
  158. if (res.code == 200) {
  159. res.data.list.map(file => {
  160. file.merchantVoList.map(files => {
  161. if (files.id == that.data.merChant.merchant_id) {
  162. file.flag = true
  163. }
  164. })
  165. })
  166. that.setData({
  167. showPage: true,
  168. cardList: res.data.list
  169. })
  170. }
  171. })
  172. .catch(err => {
  173. wx.showModal({
  174. title: '提示',
  175. content: err.errMsg,
  176. showCancel: false
  177. })
  178. })
  179. },
  180. showModel: function () {
  181. this.setData({
  182. showModel: false
  183. })
  184. },
  185. })