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.

223 line
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. 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. // wx.showModal({
  96. // title: '错误',
  97. // content: '您暂未录入指纹信息,请录入后重试',
  98. // showCancel: false
  99. // })
  100. that.gotoPayMoney();
  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. that.gotoPayMoney();
  123. }
  124. })
  125. },
  126. gotonewcard: function() {
  127. wx.navigateTo({
  128. url: '/pages/discountCardList/discountCardList'
  129. })
  130. this.setData({
  131. showModel: false
  132. })
  133. },
  134. getList() {
  135. var that = this;
  136. var data = {
  137. pageNum: 1,
  138. pageSize: 100,
  139. couponType: "7",
  140. couponOrderStatus: 4
  141. }
  142. Http.get({
  143. url: config.api.cardorderList,
  144. data: data
  145. })
  146. .then(res => {
  147. console.log(res)
  148. if (res.code == 200) {
  149. res.data.list.map(file => {
  150. file.merchantVoList.map(files => {
  151. console.log(files.id)
  152. if (files.id == that.data.merChant.merchant_id) {
  153. file.flag = true
  154. }
  155. })
  156. })
  157. that.setData({
  158. showPage: true,
  159. cardList: res.data.list
  160. })
  161. }
  162. })
  163. .catch(err => {
  164. wx.showModal({
  165. title: '提示',
  166. content: err.errMsg,
  167. showCancel: false
  168. })
  169. })
  170. },
  171. check: function(e) {
  172. let ids = e.currentTarget.dataset.id;
  173. this.setData({
  174. ids: ids,
  175. cardId: ids,
  176. remainingAmount: e.currentTarget.dataset.remainingamount
  177. })
  178. },
  179. showModel: function() {
  180. this.setData({
  181. showModel: false
  182. })
  183. },
  184. /**
  185. * 生命周期函数--监听页面隐藏
  186. */
  187. onHide: function() {
  188. },
  189. /**
  190. * 生命周期函数--监听页面卸载
  191. */
  192. onUnload: function() {
  193. },
  194. /**
  195. * 页面相关事件处理函数--监听用户下拉动作
  196. */
  197. onPullDownRefresh: function() {
  198. },
  199. /**
  200. * 页面上拉触底事件的处理函数
  201. */
  202. onReachBottom: function() {
  203. },
  204. /**
  205. * 用户点击右上角分享
  206. */
  207. onShareAppMessage: function() {
  208. }
  209. })