C端小程序
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

210 líneas
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() {
  35. let that = this;
  36. // 卡余额充足的时候,才可以付钱
  37. if (that.data.inputValue != "" && Number(that.data.remainingAmount) >= Number(that.data.inputValue)) {
  38. Http.post({
  39. url: config.api.cardPayOrder,
  40. data: {
  41. cardId: that.data.cardid,
  42. merchantCode: that.data.merChant.merchant_id,
  43. totalFee: that.data.inputValue
  44. }
  45. })
  46. .then(res => {
  47. console.log(res);
  48. if(res.code==200){
  49. wx.navigateTo({
  50. url: `/pages/paySuccess/paySuccess?data=${JSON.stringify(res.data)}`,
  51. })
  52. }
  53. })
  54. .catch(err => {
  55. wx.showModal({
  56. title: "抱歉",
  57. content: err.message,
  58. showCancel: false
  59. })
  60. })
  61. } else if (that.data.inputValue == "") {
  62. wx.showModal({
  63. title: '抱歉',
  64. content: '请输入金额',
  65. showCancel: false
  66. })
  67. } else if (that.data.inputValue != "" && Number(that.data.remainingAmount) < Number(that.data.inputValue)) {
  68. that.setData({
  69. showModel: true
  70. })
  71. that.getList();
  72. }
  73. },
  74. // 指纹识别
  75. startAuth() {
  76. let that = this;
  77. const startSoterAuthentication = () => {
  78. wx.startSoterAuthentication({
  79. requestAuthModes: [AUTH_MODE],
  80. challenge: 'test',
  81. authContent: '请验证已有的指纹以继续',
  82. success: (res) => {
  83. that.gotoPayMoney();
  84. },
  85. fail: (err) => {
  86. }
  87. })
  88. }
  89. const checkIsEnrolled = () => {
  90. wx.checkIsSoterEnrolledInDevice({
  91. checkAuthMode: AUTH_MODE,
  92. success: (res) => {
  93. console.log(res)
  94. if (parseInt(res.isEnrolled) <= 0) {
  95. that.gotoPayMoney();
  96. return
  97. }
  98. startSoterAuthentication();
  99. },
  100. fail: (err) => {
  101. console.error(err)
  102. }
  103. })
  104. }
  105. wx.checkIsSupportSoterAuthentication({
  106. success: (res) => {
  107. console.log(res)
  108. checkIsEnrolled()
  109. },
  110. fail: (err) => {
  111. console.error(err);
  112. that.gotoPayMoney();
  113. }
  114. })
  115. },
  116. gotonewcard: function() {
  117. wx.navigateTo({
  118. url: '/pages/discountCardList/discountCardList'
  119. })
  120. this.setData({
  121. showModel: false
  122. })
  123. },
  124. getList() {
  125. var that = this;
  126. var data = {
  127. pageNum: 1,
  128. pageSize: 100,
  129. couponType: "7",
  130. couponOrderStatus: 4
  131. }
  132. Http.get({
  133. url: config.api.cardorderList,
  134. data: data
  135. })
  136. .then(res => {
  137. console.log(res)
  138. if (res.code == 200) {
  139. res.data.list.map(file => {
  140. file.merchantVoList.map(files => {
  141. if (files.id == that.data.merChant.merchant_id) {
  142. file.flag = true
  143. }
  144. })
  145. })
  146. that.setData({
  147. showPage: true,
  148. cardList: res.data.list
  149. })
  150. }
  151. })
  152. .catch(err => {
  153. wx.showModal({
  154. title: '提示',
  155. content: err.errMsg,
  156. showCancel: false
  157. })
  158. })
  159. },
  160. check: function(e) {
  161. let ids = e.currentTarget.dataset.id;
  162. this.setData({
  163. ids: ids,
  164. cardId: ids,
  165. remainingAmount: e.currentTarget.dataset.remainingamount
  166. })
  167. },
  168. showModel: function() {
  169. this.setData({
  170. showModel: false
  171. })
  172. },
  173. /**
  174. * 生命周期函数--监听页面隐藏
  175. */
  176. onHide: function() {
  177. },
  178. /**
  179. * 生命周期函数--监听页面卸载
  180. */
  181. onUnload: function() {
  182. },
  183. /**
  184. * 页面相关事件处理函数--监听用户下拉动作
  185. */
  186. onPullDownRefresh: function() {
  187. },
  188. /**
  189. * 页面上拉触底事件的处理函数
  190. */
  191. onReachBottom: function() {
  192. },
  193. /**
  194. * 用户点击右上角分享
  195. */
  196. onShareAppMessage: function() {
  197. }
  198. })