C端小程序
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

223 řádky
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. console.log(options.remainingAmount)
  22. let that = this;
  23. that.setData({
  24. merChant: JSON.parse(options.merChant),
  25. cardid: options.cardid,
  26. remainingAmount: options.remainingAmount
  27. })
  28. },
  29. bindKeyInput(e) {
  30. console.log(e)
  31. this.setData({
  32. inputValue: e.detail.value
  33. })
  34. },
  35. gotoPayMoney: function() {
  36. let that = this;
  37. // 卡余额充足的时候,才可以付钱
  38. console.log(Number(that.data.remainingAmount) >= Number(that.data.inputValue))
  39. if (that.data.inputValue != "" && Number(that.data.remainingAmount) >= Number(that.data.inputValue)) {
  40. Http.post({
  41. url: config.api.cardPayOrder,
  42. data: {
  43. cardId: that.data.cardid,
  44. merchantCode: that.data.merChant.merchant_id,
  45. totalFee: that.data.inputValue
  46. }
  47. })
  48. .then(res => {
  49. console.log(res);
  50. if(res.code==200){
  51. wx.navigateTo({
  52. url: '/pages/paySuccess/paySuccess',
  53. })
  54. }
  55. })
  56. .catch(err => {
  57. wx.showModal({
  58. title: "抱歉",
  59. content: err.message,
  60. showCancel: false
  61. })
  62. })
  63. } else if (that.data.inputValue == "") {
  64. wx.showModal({
  65. title: '抱歉',
  66. content: '请输入金额',
  67. showCancel: false
  68. })
  69. } else if (that.data.inputValue != "" && Number(that.data.remainingAmount) < Number(that.data.inputValue)) {
  70. that.setData({
  71. showModel: true
  72. })
  73. that.getList();
  74. }
  75. },
  76. // 指纹识别
  77. startAuth() {
  78. let that = this;
  79. const startSoterAuthentication = () => {
  80. wx.startSoterAuthentication({
  81. requestAuthModes: [AUTH_MODE],
  82. challenge: 'test',
  83. authContent: '请验证已有的指纹以继续',
  84. success: (res) => {
  85. that.gotoPayMoney();
  86. },
  87. fail: (err) => {
  88. }
  89. })
  90. }
  91. const checkIsEnrolled = () => {
  92. wx.checkIsSoterEnrolledInDevice({
  93. checkAuthMode: AUTH_MODE,
  94. success: (res) => {
  95. console.log(res)
  96. if (parseInt(res.isEnrolled) <= 0) {
  97. wx.showModal({
  98. title: '错误',
  99. content: '您暂未录入指纹信息,请录入后重试',
  100. showCancel: false
  101. })
  102. return
  103. }
  104. startSoterAuthentication();
  105. },
  106. fail: (err) => {
  107. console.error(err)
  108. }
  109. })
  110. }
  111. wx.checkIsSupportSoterAuthentication({
  112. success: (res) => {
  113. console.log(res)
  114. checkIsEnrolled()
  115. },
  116. fail: (err) => {
  117. console.error(err);
  118. wx.showModal({
  119. title: '抱歉',
  120. content: '您的设备不支持指纹识别',
  121. showCancel: false
  122. })
  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. })