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.

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